From 636bfe846648b77dfcaed8d46e2d5963b0bc3348 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 15 Jun 2010 16:51:38 +0300 Subject: [PATCH] big refactoring thanks to proper jarjar built from source with asm 3.3 allowing to jarjar guice and others, includes package relocations --- .idea/libraries/jackson.xml | 11 - .idea/libraries/joda_time.xml | 11 - .idea/libraries/netty.xml | 11 - .idea/modules/elasticsearch.iml | 23 +- build.gradle | 9 +- .../index/engine/SimpleEngineBenchmark.java | 8 +- .../index/store/SimpleStoreBenchmark.java | 6 +- .../memory/SimpleMemoryMonitorBenchmark.java | 8 +- .../benchmark/stress/NodesStressTest.java | 8 +- .../versioned/VersionedMapBenchmark.java | 8 +- modules/elasticsearch/build.gradle | 57 +- .../vectorhighlight/CustomFieldQuery.java | 4 +- .../org/elasticsearch/ExceptionsHelper.java | 4 +- .../action/TransportActionModule.java | 2 +- .../cluster/health/ClusterHealthResponse.java | 6 +- .../cluster/health/ClusterIndexHealth.java | 4 +- .../health/TransportClusterHealthAction.java | 4 +- .../admin/cluster/node/info/NodeInfo.java | 6 +- .../node/info/TransportNodesInfoAction.java | 6 +- .../restart/TransportNodesRestartAction.java | 6 +- .../TransportNodesShutdownAction.java | 6 +- .../node/stats/TransportNodesStatsAction.java | 6 +- .../TransportBroadcastPingAction.java | 6 +- .../TransportIndexReplicationPingAction.java | 4 +- .../TransportReplicationPingAction.java | 4 +- .../TransportShardReplicationPingAction.java | 4 +- .../single/TransportSinglePingAction.java | 4 +- .../state/TransportClusterStateAction.java | 4 +- .../indices/alias/IndicesAliasesRequest.java | 2 +- .../alias/TransportIndicesAliasesAction.java | 4 +- .../TransportClearIndicesCacheAction.java | 6 +- .../indices/create/CreateIndexRequest.java | 20 +- .../create/TransportCreateIndexAction.java | 4 +- .../delete/TransportDeleteIndexAction.java | 4 +- .../indices/flush/TransportFlushAction.java | 6 +- .../TransportGatewaySnapshotAction.java | 4 +- .../TransportIndexGatewaySnapshotAction.java | 4 +- .../TransportShardGatewaySnapshotAction.java | 4 +- .../mapping/put/PutMappingRequest.java | 8 +- .../put/TransportPutMappingAction.java | 4 +- .../optimize/TransportOptimizeAction.java | 6 +- .../refresh/TransportRefreshAction.java | 6 +- .../indices/status/IndexShardStatus.java | 2 +- .../admin/indices/status/IndexStatus.java | 6 +- .../indices/status/IndicesStatusResponse.java | 10 +- .../status/TransportIndicesStatusAction.java | 6 +- .../action/count/CountRequest.java | 8 +- .../action/count/TransportCountAction.java | 6 +- .../action/delete/TransportDeleteAction.java | 4 +- .../deletebyquery/DeleteByQueryRequest.java | 8 +- .../deletebyquery/DeleteByQueryResponse.java | 2 +- .../TransportDeleteByQueryAction.java | 4 +- .../TransportIndexDeleteByQueryAction.java | 4 +- .../TransportShardDeleteByQueryAction.java | 4 +- .../elasticsearch/action/get/GetResponse.java | 10 +- .../action/get/TransportGetAction.java | 8 +- .../action/index/IndexRequest.java | 14 +- .../action/index/TransportIndexAction.java | 4 +- .../action/mlt/MoreLikeThisRequest.java | 8 +- .../mlt/TransportMoreLikeThisAction.java | 6 +- .../action/search/SearchRequest.java | 8 +- .../action/search/SearchResponse.java | 4 +- .../action/search/TransportSearchAction.java | 4 +- .../search/TransportSearchScrollAction.java | 4 +- ...TransportSearchDfsQueryAndFetchAction.java | 4 +- ...ransportSearchDfsQueryThenFetchAction.java | 6 +- .../TransportSearchQueryAndFetchAction.java | 4 +- .../TransportSearchQueryThenFetchAction.java | 6 +- ...nsportSearchScrollQueryAndFetchAction.java | 6 +- ...sportSearchScrollQueryThenFetchAction.java | 8 +- .../type/TransportSearchTypeAction.java | 4 +- .../AbstractListenableActionFuture.java | 2 +- .../action/support/BaseAction.java | 4 +- .../broadcast/BroadcastOperationResponse.java | 2 +- .../TransportBroadcastOperationAction.java | 6 +- .../TransportMasterNodeOperationAction.java | 2 +- .../support/nodes/NodesOperationResponse.java | 2 +- .../nodes/TransportNodesOperationAction.java | 4 +- ...nsportIndexReplicationOperationAction.java | 4 +- ...portIndicesReplicationOperationAction.java | 4 +- ...nsportShardReplicationOperationAction.java | 2 +- .../TransportSingleOperationAction.java | 2 +- .../action/terms/FieldTermsFreq.java | 4 +- .../action/terms/ShardTermsResponse.java | 6 +- .../elasticsearch/action/terms/TermFreq.java | 2 +- .../action/terms/TermsResponse.java | 2 +- .../action/terms/TransportTermsAction.java | 12 +- .../elasticsearch/bootstrap/Bootstrap.java | 18 +- .../org/elasticsearch/cache/NodeCache.java | 6 +- .../elasticsearch/cache/NodeCacheModule.java | 2 +- .../org/elasticsearch/client/Requests.java | 2 +- .../create/CreateIndexRequestBuilder.java | 4 +- .../mapping/put/PutMappingRequestBuilder.java | 2 +- .../DeleteByQueryRequestBuilder.java | 2 +- .../action/index/IndexRequestBuilder.java | 6 +- .../client/node/NodeAdminClient.java | 6 +- .../elasticsearch/client/node/NodeClient.java | 4 +- .../client/node/NodeClientModule.java | 2 +- .../client/node/NodeClusterAdminClient.java | 4 +- .../client/node/NodeIndicesAdminClient.java | 4 +- .../transport/ClientTransportModule.java | 2 +- .../client/transport/TransportClient.java | 24 +- .../TransportClientClusterModule.java | 8 +- .../TransportClientClusterService.java | 6 +- .../TransportClientNodesService.java | 10 +- .../action/ClientTransportActionModule.java | 2 +- .../ClientTransportClusterHealthAction.java | 4 +- .../info/ClientTransportNodesInfoAction.java | 4 +- .../ClientTransportNodesRestartAction.java | 4 +- .../ClientTransportNodesShutdownAction.java | 4 +- .../ClientTransportNodesStatsAction.java | 4 +- .../ClientTransportBroadcastPingAction.java | 4 +- .../ClientTransportReplicationPingAction.java | 4 +- .../ClientTransportSinglePingAction.java | 4 +- .../ClientTransportClusterStateAction.java | 4 +- .../ClientTransportIndicesAliasesAction.java | 4 +- ...lientTransportClearIndicesCacheAction.java | 4 +- .../ClientTransportCreateIndexAction.java | 4 +- .../ClientTransportDeleteIndexAction.java | 4 +- .../flush/ClientTransportFlushAction.java | 4 +- .../ClientTransportGatewaySnapshotAction.java | 4 +- .../ClientTransportPutMappingAction.java | 4 +- .../ClientTransportOptimizeAction.java | 4 +- .../refresh/ClientTransportRefreshAction.java | 4 +- .../ClientTransportIndicesStatusAction.java | 4 +- .../count/ClientTransportCountAction.java | 4 +- .../delete/ClientTransportDeleteAction.java | 4 +- .../ClientTransportDeleteByQueryAction.java | 4 +- .../action/get/ClientTransportGetAction.java | 4 +- .../index/ClientTransportIndexAction.java | 4 +- .../ClientTransportMoreLikeThisAction.java | 4 +- .../search/ClientTransportSearchAction.java | 4 +- .../ClientTransportSearchScrollAction.java | 4 +- .../support/BaseClientTransportAction.java | 4 +- .../terms/ClientTransportTermsAction.java | 4 +- .../support/InternalTransportAdminClient.java | 6 +- .../support/InternalTransportClient.java | 4 +- .../InternalTransportClusterAdminClient.java | 4 +- .../InternalTransportIndicesAdminClient.java | 4 +- .../elasticsearch/cluster/ClusterModule.java | 4 +- .../elasticsearch/cluster/ClusterName.java | 2 +- .../cluster/ClusterNameModule.java | 4 +- .../elasticsearch/cluster/ClusterService.java | 2 +- .../elasticsearch/cluster/ClusterState.java | 2 +- .../action/index/MappingUpdatedAction.java | 4 +- .../action/index/NodeIndexCreatedAction.java | 6 +- .../action/index/NodeIndexDeletedAction.java | 6 +- .../index/NodeMappingCreatedAction.java | 6 +- .../action/shard/ShardStateAction.java | 8 +- .../cluster/metadata/IndexMetaData.java | 20 +- .../cluster/metadata/MetaData.java | 24 +- .../cluster/metadata/MetaDataService.java | 16 +- .../cluster/node/DiscoveryNode.java | 14 +- .../cluster/node/DiscoveryNodes.java | 12 +- .../routing/ImmutableShardRouting.java | 2 +- .../cluster/routing/IndexRoutingTable.java | 6 +- .../routing/IndexShardRoutingTable.java | 8 +- .../cluster/routing/RoutingNode.java | 2 +- .../cluster/routing/RoutingNodes.java | 4 +- .../cluster/routing/RoutingService.java | 6 +- .../cluster/routing/RoutingTable.java | 8 +- .../routing/RoutingTableValidation.java | 10 +- .../DefaultShardsRoutingStrategy.java | 2 +- .../service/InternalClusterService.java | 6 +- .../component/AbstractComponent.java | 8 +- .../component/AbstractLifecycleComponent.java | 4 +- .../component/CloseableComponent.java | 2 +- .../component/CloseableIndexComponent.java | 2 +- .../{util => common}/component/Lifecycle.java | 2 +- .../component/LifecycleComponent.java | 2 +- .../component/LifecycleListener.java | 2 +- .../http/client}/HttpClientModule.java | 4 +- .../http/client}/HttpClientService.java | 9 +- .../http/client}/HttpDownloadHelper.java | 2 +- .../guice => common/inject}/Injectors.java | 11 +- .../inject}/ModulesFactory.java | 5 +- .../joda/FormatDateTimeFormatter.java | 6 +- .../{util => common}/joda/Joda.java | 6 +- .../{util => common}/logging/ESLogger.java | 2 +- .../logging/ESLoggerFactory.java | 8 +- .../{util => common}/logging/Loggers.java | 10 +- .../logging/jdk/JdkESLogger.java | 4 +- .../logging/jdk/JdkESLoggerFactory.java | 6 +- .../logging/log4j/ConsoleAppender.java | 4 +- .../logging/log4j/JLinePatternLayout.java | 2 +- .../logging/log4j/Log4jESLogger.java | 4 +- .../logging/log4j/Log4jESLoggerFactory.java | 6 +- .../logging/log4j/LogConfigurator.java | 14 +- .../logging/slf4j/Slf4jESLogger.java | 4 +- .../logging/slf4j/Slf4jESLoggerFactory.java | 6 +- .../logging/support/AbstractESLogger.java | 4 +- .../logging/support/LoggerMessageFormat.java | 2 +- .../{util => common}/lucene/Directories.java | 2 +- .../lucene/DocumentBuilder.java | 2 +- .../{util => common}/lucene/FieldBuilder.java | 2 +- .../lucene/IndexCommitDelegate.java | 2 +- .../{util => common}/lucene/IndexWriters.java | 6 +- .../lucene/LoggerInfoStream.java | 6 +- .../{util => common}/lucene/Lucene.java | 4 +- .../lucene/MultiCollector.java | 2 +- .../lucene/ReaderSearcherHolder.java | 2 +- .../lucene/all/AllEntries.java | 6 +- .../{util => common}/lucene/all/AllField.java | 2 +- .../lucene/all/AllTermQuery.java | 2 +- .../lucene/all/AllTokenStream.java | 2 +- .../analysis/CharSequenceTermAttribute.java | 2 +- .../lucene/docset/AndDocSet.java | 2 +- .../lucene/docset/DocIdSetCollector.java | 2 +- .../lucene/docset/DocSet.java | 2 +- .../lucene/docset/DocSets.java | 2 +- .../lucene/docset/NotDocSet.java | 2 +- .../lucene/docset/OpenBitDocSet.java | 2 +- .../lucene/docset/OrDocSet.java | 2 +- .../lucene/search/AndFilter.java | 10 +- .../lucene/search/MoreLikeThisQuery.java | 2 +- .../lucene/search/NoopCollector.java | 2 +- .../lucene/search/NotFilter.java | 6 +- .../lucene/search/OrFilter.java | 10 +- .../lucene/search/Queries.java | 2 +- .../lucene/search/TermFilter.java | 2 +- .../search/function/BoostScoreFunction.java | 2 +- .../search/function/FunctionScoreQuery.java | 2 +- .../lucene/search/function/ScoreFunction.java | 2 +- .../lucene/store/InputStreamIndexInput.java | 2 +- .../lucene/store/SwitchDirectory.java | 4 +- .../ThreadSafeInputStreamIndexInput.java | 2 +- .../versioned/ConcurrentVersionedMap.java | 2 +- .../versioned/ConcurrentVersionedMapLong.java | 2 +- .../lucene/versioned/NativeVersionedMap.java | 4 +- .../versioned/VersionedIndexReader.java | 2 +- .../lucene/versioned/VersionedMap.java | 2 +- .../netty/OpenChannelsHandler.java | 4 +- .../network/NetworkModule.java | 4 +- .../network/NetworkService.java | 10 +- .../network/NetworkUtils.java | 6 +- .../{util => common}/path/PathTrie.java | 4 +- .../settings/ImmutableSettings.java | 8 +- .../settings/NoClassSettingsException.java | 2 +- .../{util => common}/settings/Settings.java | 2 +- .../settings/SettingsException.java | 2 +- .../settings/SettingsFilter.java | 6 +- .../settings/SettingsModule.java | 4 +- .../settings/loader/JsonSettingsLoader.java | 12 +- .../loader/PropertiesSettingsLoader.java | 4 +- .../settings/loader/SettingsLoader.java | 2 +- .../loader/SettingsLoaderFactory.java | 2 +- .../settings/loader/YamlSettingsLoader.java | 8 +- .../settings/loader/package-info.java | 2 +- .../settings/package-info.java | 2 +- .../timer/HashedWheelTimer.java | 4 +- .../{util => common}/timer/Timeout.java | 2 +- .../{util => common}/timer/Timer.java | 2 +- .../{util => common}/timer/TimerTask.java | 2 +- .../transport/BoundTransportAddress.java | 2 +- .../transport/DummyTransportAddress.java | 2 +- .../transport/InetSocketTransportAddress.java | 2 +- .../transport/LocalTransportAddress.java | 2 +- .../transport/NetworkExceptionHelper.java | 2 +- .../transport/PortsRange.java | 4 +- .../transport/TransportAddress.java | 2 +- .../TransportAddressSerializers.java | 12 +- .../trove/ExtTIntArrayList.java | 4 +- .../trove/ExtTIntIntHashMap.java | 5 +- .../trove/ExtTObjectFloatHashMap.java | 5 +- .../trove/ExtTObjectIntHasMap.java | 5 +- .../{util => common}/xcontent/ToXContent.java | 6 +- .../{util => common}/xcontent/XContent.java | 2 +- .../xcontent/XContentFactory.java | 18 +- .../xcontent/XContentGenerator.java | 2 +- .../xcontent/XContentParser.java | 2 +- .../xcontent/XContentType.java | 4 +- .../builder/BinaryXContentBuilder.java | 4 +- .../xcontent/builder/TextXContentBuilder.java | 4 +- .../xcontent/builder/XContentBuilder.java | 16 +- .../xcontent/json/JsonXContent.java | 22 +- .../xcontent/json/JsonXContentGenerator.java | 8 +- .../xcontent/json/JsonXContentParser.java | 10 +- .../support/AbstractXContentGenerator.java | 4 +- .../support/AbstractXContentParser.java | 4 +- .../support/XContentMapConverter.java | 8 +- .../xcontent/support/XContentMapValues.java | 2 +- .../xcontent/xson/XsonType.java | 2 +- .../xcontent/xson/XsonXContent.java | 12 +- .../xcontent/xson/XsonXContentGenerator.java | 8 +- .../xcontent/xson/XsonXContentParser.java | 6 +- .../elasticsearch/discovery/Discovery.java | 2 +- .../discovery/DiscoveryModule.java | 8 +- .../discovery/DiscoveryService.java | 6 +- .../discovery/local/LocalDiscovery.java | 8 +- .../discovery/local/LocalDiscoveryModule.java | 2 +- .../discovery/zen/ZenDiscovery.java | 8 +- .../discovery/zen/ZenDiscoveryModule.java | 2 +- .../zen/elect/ElectMasterService.java | 6 +- .../zen/fd/MasterFaultDetection.java | 4 +- .../discovery/zen/fd/NodesFaultDetection.java | 4 +- .../zen/membership/MembershipAction.java | 4 +- .../discovery/zen/ping/ZenPing.java | 2 +- .../discovery/zen/ping/ZenPingService.java | 10 +- .../zen/ping/multicast/MulticastZenPing.java | 8 +- .../zen/ping/unicast/UnicastZenPing.java | 12 +- .../publish/PublishClusterStateAction.java | 4 +- .../org/elasticsearch/env/Environment.java | 5 +- .../elasticsearch/env/EnvironmentModule.java | 2 +- .../org/elasticsearch/gateway/Gateway.java | 4 +- .../elasticsearch/gateway/GatewayModule.java | 6 +- .../elasticsearch/gateway/GatewayService.java | 6 +- .../elasticsearch/gateway/fs/FsGateway.java | 18 +- .../gateway/fs/FsGatewayModule.java | 2 +- .../gateway/none/NoneGateway.java | 8 +- .../gateway/none/NoneGatewayModule.java | 2 +- .../org/elasticsearch/http/HttpServer.java | 8 +- .../elasticsearch/http/HttpServerModule.java | 8 +- .../http/HttpServerTransport.java | 4 +- .../http/netty/HttpRequestHandler.java | 6 +- .../http/netty/NettyHttpChannel.java | 18 +- .../http/netty/NettyHttpRequest.java | 8 +- .../http/netty/NettyHttpServerTransport.java | 42 +- .../netty/NettyHttpServerTransportModule.java | 2 +- .../index/AbstractIndexComponent.java | 6 +- .../org/elasticsearch/index/IndexModule.java | 2 +- .../elasticsearch/index/IndexNameModule.java | 2 +- .../index/IndexServiceManagement.java | 6 +- .../org/elasticsearch/index/LocalNodeId.java | 2 +- .../index/LocalNodeIdModule.java | 2 +- .../ASCIIFoldingTokenFilterFactory.java | 6 +- .../AbstractIndexAnalyzerProvider.java | 2 +- .../analysis/AbstractTokenFilterFactory.java | 2 +- .../analysis/AbstractTokenizerFactory.java | 2 +- .../index/analysis/AnalysisModule.java | 12 +- .../index/analysis/AnalysisService.java | 12 +- .../index/analysis/AnalyzerProvider.java | 2 +- .../analysis/AnalyzerProviderFactory.java | 2 +- .../analysis/ArabicAnalyzerProvider.java | 12 +- .../ArabicStemTokenFilterFactory.java | 6 +- .../analysis/BrazilianAnalyzerProvider.java | 12 +- .../BrazilianStemTokenFilterFactory.java | 10 +- .../analysis/ChineseAnalyzerProvider.java | 6 +- .../index/analysis/CjkAnalyzerProvider.java | 12 +- .../analysis/CustomAnalyzerProvider.java | 10 +- .../index/analysis/CzechAnalyzerProvider.java | 12 +- .../index/analysis/DutchAnalyzerProvider.java | 12 +- .../analysis/DutchStemTokenFilterFactory.java | 10 +- .../analysis/EdgeNGramTokenFilterFactory.java | 6 +- .../analysis/EdgeNGramTokenizerFactory.java | 6 +- .../index/analysis/FieldNameAnalyzer.java | 2 +- .../analysis/FrenchAnalyzerProvider.java | 12 +- .../FrenchStemTokenFilterFactory.java | 10 +- .../analysis/GermanAnalyzerProvider.java | 12 +- .../GermanStemTokenFilterFactory.java | 10 +- .../index/analysis/GreekAnalyzerProvider.java | 12 +- .../analysis/KeywordAnalyzerProvider.java | 6 +- .../analysis/KeywordTokenizerFactory.java | 6 +- .../analysis/LengthTokenFilterFactory.java | 6 +- .../analysis/LetterTokenizerFactory.java | 6 +- .../analysis/LowerCaseTokenFilterFactory.java | 6 +- .../analysis/LowerCaseTokenizerFactory.java | 6 +- .../analysis/NGramTokenFilterFactory.java | 6 +- .../index/analysis/NGramTokenizerFactory.java | 6 +- .../index/analysis/NumericDateAnalyzer.java | 2 +- .../index/analysis/NumericDateTokenizer.java | 2 +- .../analysis/PersianAnalyzerProvider.java | 12 +- .../PorterStemTokenFilterFactory.java | 6 +- .../PreBuiltAnalyzerProviderFactory.java | 2 +- .../analysis/RussianAnalyzerProvider.java | 12 +- .../RussianStemTokenFilterFactory.java | 6 +- .../analysis/ShingleTokenFilterFactory.java | 6 +- .../analysis/SimpleAnalyzerProvider.java | 6 +- .../analysis/StandardAnalyzerProvider.java | 12 +- .../analysis/StandardTokenFilterFactory.java | 6 +- .../analysis/StandardTokenizerFactory.java | 8 +- .../index/analysis/StopAnalyzerProvider.java | 12 +- .../analysis/StopTokenFilterFactory.java | 10 +- .../index/analysis/ThaiAnalyzerProvider.java | 8 +- .../analysis/TokenFilterFactoryFactory.java | 2 +- .../analysis/TokenizerFactoryFactory.java | 2 +- .../analysis/WhitespaceAnalyzerProvider.java | 6 +- .../analysis/WhitespaceTokenizerFactory.java | 6 +- .../elasticsearch/index/cache/IndexCache.java | 6 +- .../index/cache/IndexCacheModule.java | 4 +- .../cache/field/data/FieldDataCache.java | 2 +- .../field/data/FieldDataCacheModule.java | 6 +- .../field/data/none/NoneFieldDataCache.java | 4 +- .../field/data/soft/SoftFieldDataCache.java | 6 +- .../AbstractConcurrentMapFieldDataCache.java | 2 +- .../field/data/weak/WeakFieldDataCache.java | 6 +- .../index/cache/filter/FilterCache.java | 2 +- .../index/cache/filter/FilterCacheModule.java | 6 +- .../cache/filter/none/NoneFilterCache.java | 4 +- .../cache/filter/soft/SoftFilterCache.java | 8 +- .../AbstractConcurrentMapFilterCache.java | 6 +- .../cache/filter/weak/WeakFilterCache.java | 8 +- .../deletionpolicy/DeletionPolicyModule.java | 6 +- .../KeepLastNDeletionPolicy.java | 4 +- .../KeepOnlyLastDeletionPolicy.java | 4 +- .../SnapshotDeletionPolicy.java | 4 +- .../deletionpolicy/SnapshotIndexCommit.java | 2 +- .../elasticsearch/index/engine/Engine.java | 2 +- .../index/engine/EngineModule.java | 6 +- .../index/engine/IndexEngineModule.java | 8 +- .../index/engine/robin/RobinEngine.java | 10 +- .../index/engine/robin/RobinEngineModule.java | 2 +- .../index/engine/robin/RobinIndexEngine.java | 6 +- .../engine/robin/RobinIndexEngineModule.java | 2 +- .../field/data/doubles/DoubleFieldData.java | 2 +- .../field/data/floats/FloatFieldData.java | 2 +- .../index/field/data/ints/IntFieldData.java | 2 +- .../field/data/longs/LongDocFieldData.java | 2 +- .../index/field/data/longs/LongFieldData.java | 4 +- .../data/longs/MultiValueLongFieldData.java | 2 +- .../data/longs/SingleValueLongFieldData.java | 2 +- .../field/data/shorts/ShortFieldData.java | 2 +- .../field/data/support/FieldDataLoader.java | 2 +- .../index/gateway/IndexGateway.java | 2 +- .../index/gateway/IndexGatewayModule.java | 6 +- .../index/gateway/IndexShardGateway.java | 2 +- .../gateway/IndexShardGatewayModule.java | 2 +- .../gateway/IndexShardGatewayService.java | 6 +- .../index/gateway/fs/FsIndexGateway.java | 4 +- .../gateway/fs/FsIndexGatewayModule.java | 2 +- .../index/gateway/fs/FsIndexShardGateway.java | 8 +- .../index/gateway/none/NoneIndexGateway.java | 4 +- .../gateway/none/NoneIndexGatewayModule.java | 2 +- .../gateway/none/NoneIndexShardGateway.java | 4 +- .../index/mapper/DocumentFieldMappers.java | 12 +- .../index/mapper/FieldMappers.java | 6 +- .../index/mapper/MapperService.java | 8 +- .../index/mapper/MapperServiceModule.java | 2 +- .../index/mapper/xcontent/MergeContext.java | 2 +- .../index/mapper/xcontent/ParseContext.java | 4 +- .../xcontent/XContentAllFieldMapper.java | 8 +- .../xcontent/XContentBinaryFieldMapper.java | 4 +- .../xcontent/XContentBooleanFieldMapper.java | 8 +- .../xcontent/XContentBoostFieldMapper.java | 4 +- .../xcontent/XContentDateFieldMapper.java | 8 +- .../xcontent/XContentDocumentMapper.java | 12 +- .../XContentDocumentMapperParser.java | 8 +- .../xcontent/XContentDoubleFieldMapper.java | 6 +- .../mapper/xcontent/XContentFieldMapper.java | 4 +- .../xcontent/XContentFloatFieldMapper.java | 6 +- .../xcontent/XContentIdFieldMapper.java | 4 +- .../xcontent/XContentIntegerFieldMapper.java | 6 +- .../xcontent/XContentLongFieldMapper.java | 6 +- .../index/mapper/xcontent/XContentMapper.java | 2 +- .../xcontent/XContentMultiFieldMapper.java | 6 +- .../xcontent/XContentNumberFieldMapper.java | 4 +- .../mapper/xcontent/XContentObjectMapper.java | 16 +- .../xcontent/XContentShortFieldMapper.java | 6 +- .../xcontent/XContentSourceFieldMapper.java | 4 +- .../xcontent/XContentStringFieldMapper.java | 4 +- .../xcontent/XContentTypeFieldMapper.java | 4 +- .../mapper/xcontent/XContentTypeParser.java | 2 +- .../mapper/xcontent/XContentTypeParsers.java | 6 +- .../xcontent/XContentUidFieldMapper.java | 4 +- .../BalancedSegmentMergePolicyProvider.java | 2 +- .../LogByteSizeMergePolicyProvider.java | 2 +- .../policy/LogDocMergePolicyProvider.java | 2 +- .../index/merge/policy/MergeFactor.java | 2 +- .../index/merge/policy/MergePolicyModule.java | 4 +- .../ConcurrentMergeSchedulerProvider.java | 4 +- .../merge/scheduler/MergeSchedulerModule.java | 4 +- .../SerialMergeSchedulerProvider.java | 4 +- .../index/query/IndexQueryParserFactory.java | 2 +- .../index/query/IndexQueryParserModule.java | 12 +- .../index/query/IndexQueryParserService.java | 10 +- .../index/query/QueryBuilder.java | 2 +- .../query/support/MapperQueryParser.java | 4 +- .../support/MultiFieldMapperQueryParser.java | 2 +- .../index/query/support/QueryParsers.java | 2 +- .../query/xcontent/AndFilterBuilder.java | 4 +- .../index/query/xcontent/AndFilterParser.java | 10 +- .../query/xcontent/BaseFilterBuilder.java | 2 +- .../query/xcontent/BaseQueryBuilder.java | 8 +- .../query/xcontent/BoolFilterBuilder.java | 2 +- .../query/xcontent/BoolFilterParser.java | 8 +- .../query/xcontent/BoolQueryBuilder.java | 2 +- .../index/query/xcontent/BoolQueryParser.java | 10 +- .../xcontent/ConstantScoreQueryBuilder.java | 2 +- .../xcontent/ConstantScoreQueryParser.java | 6 +- .../CustomBoostFactorQueryBuilder.java | 2 +- .../CustomBoostFactorQueryParser.java | 10 +- .../xcontent/CustomScoreQueryBuilder.java | 4 +- .../xcontent/CustomScoreQueryParser.java | 10 +- .../query/xcontent/DisMaxQueryBuilder.java | 4 +- .../query/xcontent/DisMaxQueryParser.java | 8 +- .../query/xcontent/FieldQueryBuilder.java | 2 +- .../query/xcontent/FieldQueryParser.java | 8 +- .../query/xcontent/FilteredQueryBuilder.java | 2 +- .../query/xcontent/FilteredQueryParser.java | 6 +- .../FuzzyLikeThisFieldQueryBuilder.java | 2 +- .../FuzzyLikeThisFieldQueryParser.java | 4 +- .../xcontent/FuzzyLikeThisQueryBuilder.java | 2 +- .../xcontent/FuzzyLikeThisQueryParser.java | 6 +- .../query/xcontent/FuzzyQueryBuilder.java | 2 +- .../query/xcontent/FuzzyQueryParser.java | 4 +- .../query/xcontent/MatchAllQueryBuilder.java | 2 +- .../query/xcontent/MatchAllQueryParser.java | 6 +- .../MoreLikeThisFieldQueryBuilder.java | 2 +- .../MoreLikeThisFieldQueryParser.java | 8 +- .../xcontent/MoreLikeThisQueryBuilder.java | 2 +- .../xcontent/MoreLikeThisQueryParser.java | 10 +- .../query/xcontent/NotFilterBuilder.java | 2 +- .../index/query/xcontent/NotFilterParser.java | 8 +- .../index/query/xcontent/OrFilterBuilder.java | 4 +- .../index/query/xcontent/OrFilterParser.java | 10 +- .../query/xcontent/PrefixFilterBuilder.java | 2 +- .../query/xcontent/PrefixFilterParser.java | 6 +- .../query/xcontent/PrefixQueryBuilder.java | 2 +- .../query/xcontent/PrefixQueryParser.java | 6 +- .../query/xcontent/QueryFilterBuilder.java | 2 +- .../query/xcontent/QueryFilterParser.java | 6 +- .../query/xcontent/QueryParseContext.java | 2 +- .../xcontent/QueryStringQueryBuilder.java | 6 +- .../xcontent/QueryStringQueryParser.java | 12 +- .../query/xcontent/RangeFilterBuilder.java | 2 +- .../query/xcontent/RangeFilterParser.java | 6 +- .../query/xcontent/RangeQueryBuilder.java | 2 +- .../query/xcontent/RangeQueryParser.java | 6 +- .../query/xcontent/SpanFirstQueryBuilder.java | 2 +- .../query/xcontent/SpanFirstQueryParser.java | 6 +- .../query/xcontent/SpanNearQueryBuilder.java | 2 +- .../query/xcontent/SpanNearQueryParser.java | 8 +- .../query/xcontent/SpanNotQueryBuilder.java | 2 +- .../query/xcontent/SpanNotQueryParser.java | 6 +- .../query/xcontent/SpanOrQueryBuilder.java | 2 +- .../query/xcontent/SpanOrQueryParser.java | 8 +- .../query/xcontent/SpanTermQueryBuilder.java | 2 +- .../query/xcontent/SpanTermQueryParser.java | 6 +- .../query/xcontent/TermFilterBuilder.java | 2 +- .../query/xcontent/TermFilterParser.java | 8 +- .../query/xcontent/TermQueryBuilder.java | 2 +- .../index/query/xcontent/TermQueryParser.java | 6 +- .../query/xcontent/TermsFilterBuilder.java | 2 +- .../query/xcontent/TermsFilterParser.java | 6 +- .../query/xcontent/WildcardQueryBuilder.java | 2 +- .../query/xcontent/WildcardQueryParser.java | 6 +- .../query/xcontent/XContentFilterBuilder.java | 2 +- .../xcontent/XContentFilterParserFactory.java | 2 +- .../xcontent/XContentIndexQueryParser.java | 14 +- .../query/xcontent/XContentQueryBuilder.java | 2 +- .../xcontent/XContentQueryParserFactory.java | 2 +- .../xcontent/XContentQueryParserRegistry.java | 6 +- .../index/routing/OperationRoutingModule.java | 6 +- .../routing/plain/PlainOperationRouting.java | 4 +- .../plain/PlainOperationRoutingModule.java | 2 +- .../index/service/IndexService.java | 4 +- .../index/service/InternalIndexService.java | 22 +- .../index/settings/IndexSettings.java | 2 +- .../index/settings/IndexSettingsModule.java | 4 +- .../shard/AbstractIndexShardComponent.java | 6 +- .../index/shard/IndexShardComponent.java | 2 +- .../index/shard/IndexShardManagement.java | 6 +- .../index/shard/IndexShardModule.java | 2 +- .../index/shard/recovery/RecoveryAction.java | 6 +- .../index/shard/service/IndexShard.java | 2 +- .../shard/service/InternalIndexShard.java | 8 +- .../AbstractSimilarityProvider.java | 2 +- .../similarity/DefaultSimilarityProvider.java | 6 +- .../index/similarity/SimilarityModule.java | 10 +- .../index/similarity/SimilarityProvider.java | 2 +- .../similarity/SimilarityProviderFactory.java | 2 +- .../index/similarity/SimilarityService.java | 10 +- .../index/store/StoreManagement.java | 2 +- .../index/store/StoreModule.java | 8 +- .../index/store/fs/AbstractFsStore.java | 8 +- .../index/store/fs/MmapFsStore.java | 6 +- .../index/store/fs/MmapFsStoreModule.java | 2 +- .../index/store/fs/NioFsStore.java | 6 +- .../index/store/fs/NioFsStoreModule.java | 2 +- .../index/store/fs/SimpleFsStore.java | 6 +- .../index/store/fs/SimpleFsStoreModule.java | 2 +- .../index/store/memory/ByteBufferStore.java | 4 +- .../index/store/memory/HeapStore.java | 4 +- .../index/store/memory/MemoryStoreModule.java | 4 +- .../index/store/ram/RamStore.java | 4 +- .../index/store/ram/RamStoreModule.java | 2 +- .../index/store/support/AbstractStore.java | 4 +- .../index/translog/TranslogModule.java | 6 +- .../index/translog/memory/MemorySnapshot.java | 2 +- .../index/translog/memory/MemoryTranslog.java | 4 +- .../indices/IndicesMemoryCleaner.java | 8 +- .../elasticsearch/indices/IndicesModule.java | 4 +- .../elasticsearch/indices/IndicesService.java | 4 +- .../indices/InternalIndicesLifecycle.java | 6 +- .../indices/InternalIndicesService.java | 24 +- .../analysis/IndicesAnalysisService.java | 10 +- .../cluster/IndicesClusterStateService.java | 10 +- .../recovery/throttler/RecoveryThrottler.java | 6 +- .../elasticsearch/jmx/JmxClusterService.java | 4 +- .../java/org/elasticsearch/jmx/JmxModule.java | 16 +- .../org/elasticsearch/jmx/JmxService.java | 8 +- .../org/elasticsearch/jmx/ResourceDMBean.java | 6 +- .../jmx/action/GetJmxServiceUrlAction.java | 6 +- .../elasticsearch/monitor/MonitorModule.java | 10 +- .../elasticsearch/monitor/MonitorService.java | 6 +- .../monitor/dump/AbstractDump.java | 2 +- .../monitor/dump/DumpContributorFactory.java | 2 +- .../monitor/dump/DumpMonitorService.java | 10 +- .../monitor/dump/SimpleDumpGenerator.java | 2 +- .../dump/cluster/ClusterDumpContributor.java | 6 +- .../dump/heap/HeapDumpContributor.java | 6 +- .../dump/summary/SummaryDumpContributor.java | 6 +- .../dump/thread/ThreadDumpContributor.java | 6 +- .../monitor/jvm/DeadlockAnalyzer.java | 4 +- .../elasticsearch/monitor/jvm/JvmInfo.java | 4 +- .../monitor/jvm/JvmMonitorService.java | 8 +- .../elasticsearch/monitor/jvm/JvmService.java | 6 +- .../elasticsearch/monitor/jvm/JvmStats.java | 8 +- .../monitor/memory/MemoryMonitor.java | 2 +- .../monitor/memory/MemoryMonitorService.java | 6 +- .../memory/alpha/AlphaMemoryMonitor.java | 6 +- .../monitor/network/JmxNetworkProbe.java | 6 +- .../monitor/network/NetworkInfo.java | 4 +- .../monitor/network/NetworkService.java | 6 +- .../monitor/network/NetworkStats.java | 4 +- .../monitor/network/SigarNetworkProbe.java | 6 +- .../elasticsearch/monitor/os/JmxOsProbe.java | 6 +- .../org/elasticsearch/monitor/os/OsInfo.java | 4 +- .../elasticsearch/monitor/os/OsService.java | 6 +- .../org/elasticsearch/monitor/os/OsStats.java | 4 +- .../monitor/os/SigarOsProbe.java | 6 +- .../monitor/process/JmxProcessProbe.java | 6 +- .../monitor/process/ProcessInfo.java | 4 +- .../monitor/process/ProcessService.java | 6 +- .../monitor/process/ProcessStats.java | 4 +- .../monitor/process/SigarProcessProbe.java | 6 +- .../monitor/sigar/SigarService.java | 6 +- .../java/org/elasticsearch/node/Node.java | 2 +- .../org/elasticsearch/node/NodeBuilder.java | 4 +- .../node/internal/InternalNode.java | 30 +- .../internal/InternalSettingsPerparer.java | 6 +- .../node/internal/NodeModule.java | 2 +- .../elasticsearch/plugins/AbstractPlugin.java | 8 +- .../plugins/IndicesPluginsModule.java | 8 +- .../org/elasticsearch/plugins/Plugin.java | 6 +- .../elasticsearch/plugins/PluginManager.java | 6 +- .../elasticsearch/plugins/PluginsModule.java | 8 +- .../elasticsearch/plugins/PluginsService.java | 20 +- .../plugins/ShardsPluginsModule.java | 8 +- .../elasticsearch/rest/BaseRestHandler.java | 4 +- .../elasticsearch/rest/RestController.java | 8 +- .../org/elasticsearch/rest/RestModule.java | 4 +- .../org/elasticsearch/rest/RestRequest.java | 2 +- .../rest/XContentRestResponse.java | 2 +- .../rest/XContentThrowableRestResponse.java | 2 +- .../rest/action/RestActionModule.java | 2 +- .../health/RestClusterHealthAction.java | 6 +- .../node/info/RestNodesInfoAction.java | 8 +- .../node/restart/RestNodesRestartAction.java | 6 +- .../shutdown/RestNodesShutdownAction.java | 6 +- .../node/stats/RestNodesStatsAction.java | 6 +- .../broadcast/RestBroadcastPingAction.java | 6 +- .../RestReplicationPingAction.java | 6 +- .../ping/single/RestSinglePingAction.java | 6 +- .../cluster/state/RestClusterStateAction.java | 8 +- .../alias/RestIndicesAliasesAction.java | 10 +- .../clear/RestClearIndicesCacheAction.java | 6 +- .../indices/create/RestCreateIndexAction.java | 10 +- .../indices/delete/RestDeleteIndexAction.java | 6 +- .../admin/indices/flush/RestFlushAction.java | 6 +- .../snapshot/RestGatewaySnapshotAction.java | 6 +- .../mapping/put/RestPutMappingAction.java | 6 +- .../indices/optimize/RestOptimizeAction.java | 6 +- .../indices/refresh/RestRefreshAction.java | 6 +- .../status/RestIndicesStatusAction.java | 8 +- .../rest/action/count/RestCountAction.java | 6 +- .../rest/action/delete/RestDeleteAction.java | 6 +- .../RestDeleteByQueryAction.java | 6 +- .../rest/action/get/RestGetAction.java | 8 +- .../rest/action/index/RestIndexAction.java | 6 +- .../rest/action/main/RestMainAction.java | 12 +- .../action/mlt/RestMoreLikeThisAction.java | 6 +- .../rest/action/search/RestSearchAction.java | 6 +- .../action/search/RestSearchScrollAction.java | 6 +- .../rest/action/support/RestActions.java | 2 +- .../action/support/RestXContentBuilder.java | 8 +- .../rest/action/terms/RestTermsAction.java | 6 +- .../elasticsearch/script/ScriptModule.java | 2 +- .../elasticsearch/script/ScriptService.java | 12 +- .../org/elasticsearch/search/SearchHit.java | 2 +- .../org/elasticsearch/search/SearchHits.java | 2 +- .../elasticsearch/search/SearchModule.java | 2 +- .../search/SearchParseElement.java | 2 +- .../elasticsearch/search/SearchService.java | 16 +- .../action/SearchServiceTransportAction.java | 8 +- .../search/builder/SearchSourceBuilder.java | 18 +- .../builder/SearchSourceFacetsBuilder.java | 6 +- .../builder/SearchSourceHighlightBuilder.java | 6 +- .../controller/SearchPhaseController.java | 10 +- .../search/dfs/AggregatedDfs.java | 4 +- .../elasticsearch/search/dfs/DfsPhase.java | 4 +- .../search/facets/FacetsParseElement.java | 6 +- .../search/facets/FacetsPhase.java | 10 +- .../collector/FacetCollectorParser.java | 2 +- .../histogram/HistogramFacetCollector.java | 4 +- .../HistogramFacetCollectorParser.java | 2 +- .../histogram/InternalHistogramFacet.java | 12 +- .../KeyValueHistogramFacetCollector.java | 4 +- .../search/facets/internal/InternalFacet.java | 2 +- .../facets/internal/InternalFacets.java | 12 +- .../facets/query/InternalQueryFacet.java | 2 +- .../facets/query/QueryFacetCollector.java | 4 +- .../query/QueryFacetCollectorParser.java | 2 +- .../statistical/InternalStatisticalFacet.java | 2 +- .../StatisticalFacetCollectorParser.java | 2 +- .../support/AbstractFacetCollector.java | 4 +- .../facets/terms/InternalTermsFacet.java | 8 +- .../facets/terms/TermsFacetCollector.java | 6 +- .../terms/TermsFacetCollectorParser.java | 2 +- .../search/fetch/ExplainParseElement.java | 2 +- .../search/fetch/FetchPhase.java | 4 +- .../search/fetch/FetchSearchRequest.java | 2 +- .../search/fetch/FieldsParseElement.java | 4 +- .../script/ScriptFieldsParseElement.java | 4 +- .../search/highlight/HighlightPhase.java | 2 +- .../highlight/HighlighterParseElement.java | 6 +- .../search/internal/ContextIndexSearcher.java | 4 +- .../search/internal/InternalSearchHit.java | 12 +- .../internal/InternalSearchHitField.java | 2 +- .../search/internal/InternalSearchHits.java | 6 +- .../internal/InternalSearchResponse.java | 4 +- .../search/internal/SearchContext.java | 2 +- .../search/query/FromParseElement.java | 2 +- .../query/IndicesBoostParseElement.java | 2 +- .../search/query/QueryParseElement.java | 2 +- .../query/QueryParserNameParseElement.java | 2 +- .../search/query/QueryPhase.java | 10 +- .../search/query/QuerySearchResult.java | 2 +- .../search/query/SizeParseElement.java | 2 +- .../search/query/SortParseElement.java | 8 +- .../threadpool/ThreadPoolInfo.java | 4 +- .../threadpool/ThreadPoolModule.java | 8 +- .../threadpool/ThreadPoolStats.java | 4 +- .../blocking/BlockingThreadPool.java | 6 +- .../BlockingThreadPoolManagement.java | 2 +- .../blocking/BlockingThreadPoolModule.java | 2 +- .../threadpool/cached/CachedThreadPool.java | 6 +- .../cached/CachedThreadPoolManagement.java | 2 +- .../cached/CachedThreadPoolModule.java | 2 +- .../threadpool/scaling/ScalingThreadPool.java | 6 +- .../scaling/ScalingThreadPoolManagement.java | 2 +- .../scaling/ScalingThreadPoolModule.java | 2 +- .../support/AbstractThreadPool.java | 4 +- .../org/elasticsearch/timer/TimerModule.java | 2 +- .../org/elasticsearch/timer/TimerService.java | 16 +- .../transport/RemoteTransportException.java | 2 +- .../elasticsearch/transport/Transport.java | 6 +- .../transport/TransportInfo.java | 6 +- .../transport/TransportModule.java | 8 +- .../transport/TransportService.java | 16 +- .../transport/TransportServiceManagement.java | 2 +- .../transport/TransportStats.java | 4 +- .../transport/local/LocalTransport.java | 14 +- .../local/LocalTransportManagement.java | 2 +- .../transport/local/LocalTransportModule.java | 2 +- .../netty/ChannelBufferStreamInput.java | 5 +- .../netty/MessageChannelHandler.java | 6 +- .../netty/NettyInternalESLogger.java | 4 +- .../netty/NettyInternalESLoggerFactory.java | 6 +- .../transport/netty/NettyTransport.java | 50 +- .../netty/NettyTransportChannel.java | 6 +- .../netty/NettyTransportManagement.java | 2 +- .../transport/netty/NettyTransportModule.java | 2 +- .../netty/SizeHeaderFrameDecoder.java | 8 +- .../org/elasticsearch/util/MapBuilder.java | 4 +- .../java/org/elasticsearch/util/Strings.java | 4 +- .../org/elasticsearch/util/ThreadLocals.java | 4 +- .../util/ThreadRenamingRunnable.java | 4 +- .../org/elasticsearch/util/TimeValue.java | 8 +- .../util/annotations/GwtCompatible.java | 87 - .../util/annotations/GwtIncompatible.java | 51 - .../util/annotations/VisibleForTesting.java | 26 - .../base/FinalizablePhantomReference.java | 46 - .../util/base/FinalizableReference.java | 35 - .../util/base/FinalizableReferenceQueue.java | 313 --- .../util/base/FinalizableSoftReference.java | 42 - .../util/base/FinalizableWeakReference.java | 42 - .../org/elasticsearch/util/base/Function.java | 67 - .../elasticsearch/util/base/Functions.java | 284 --- .../org/elasticsearch/util/base/Joiner.java | 341 --- .../org/elasticsearch/util/base/Objects.java | 68 - .../org/elasticsearch/util/base/Platform.java | 38 - .../util/base/Preconditions.java | 403 --- .../elasticsearch/util/base/Predicate.java | 62 - .../elasticsearch/util/base/Predicates.java | 550 ----- .../org/elasticsearch/util/base/Supplier.java | 37 - .../elasticsearch/util/base/Suppliers.java | 143 -- .../util/base/internal/Finalizer.java | 207 -- .../elasticsearch/util/base/package-info.java | 20 - .../util/collect/AbstractBiMap.java | 393 --- .../util/collect/AbstractIterator.java | 165 -- .../util/collect/AbstractListMultimap.java | 85 - .../collect/AbstractMapBasedMultiset.java | 407 ---- .../util/collect/AbstractMapEntry.java | 63 - .../util/collect/AbstractMultimap.java | 1476 ----------- .../util/collect/AbstractMultiset.java | 289 --- .../util/collect/AbstractSetMultimap.java | 94 - .../collect/AbstractSortedSetMultimap.java | 73 - .../util/collect/ArrayListMultimap.java | 155 -- .../AsynchronousComputationException.java | 32 - .../org/elasticsearch/util/collect/BiMap.java | 101 - .../util/collect/ByFunctionOrdering.java | 69 - .../util/collect/ClassToInstanceMap.java | 57 - .../util/collect/Collections2.java | 286 --- .../util/collect/ComparatorOrdering.java | 74 - .../util/collect/CompoundOrdering.java | 76 - .../util/collect/ComputationException.java | 33 - .../util/collect/ConcurrentHashMultiset.java | 481 ---- .../util/collect/ConstrainedMap.java | 155 -- .../util/collect/CustomConcurrentHashMap.java | 2153 ----------------- .../util/collect/EmptyImmutableList.java | 122 - .../collect/EmptyImmutableListMultimap.java | 40 - .../util/collect/EmptyImmutableMap.java | 89 - .../util/collect/EmptyImmutableMultiset.java | 39 - .../util/collect/EmptyImmutableSet.java | 94 - .../collect/EmptyImmutableSetMultimap.java | 40 - .../util/collect/EmptyImmutableSortedSet.java | 111 - .../elasticsearch/util/collect/EnumBiMap.java | 125 - .../util/collect/EnumHashBiMap.java | 108 - .../util/collect/EnumMultiset.java | 90 - .../util/collect/ExpirationTimer.java | 26 - .../util/collect/ExplicitOrdering.java | 77 - .../util/collect/ForwardingCollection.java | 90 - .../util/collect/ForwardingConcurrentMap.java | 54 - .../util/collect/ForwardingIterator.java | 49 - .../util/collect/ForwardingList.java | 93 - .../util/collect/ForwardingListIterator.java | 61 - .../util/collect/ForwardingMap.java | 97 - .../util/collect/ForwardingMapEntry.java | 58 - .../util/collect/ForwardingMultimap.java | 121 - .../util/collect/ForwardingMultiset.java | 74 - .../util/collect/ForwardingObject.java | 75 - .../util/collect/ForwardingQueue.java | 57 - .../util/collect/ForwardingSet.java | 46 - .../util/collect/ForwardingSortedMap.java | 62 - .../util/collect/ForwardingSortedSet.java | 62 - .../elasticsearch/util/collect/HashBiMap.java | 107 - .../util/collect/HashMultimap.java | 137 -- .../util/collect/HashMultiset.java | 94 - .../elasticsearch/util/collect/Hashing.java | 59 - .../util/collect/ImmutableBiMap.java | 310 --- .../collect/ImmutableClassToInstanceMap.java | 143 -- .../util/collect/ImmutableCollection.java | 317 --- .../util/collect/ImmutableEntry.java | 46 - .../util/collect/ImmutableEnumSet.java | 121 - .../util/collect/ImmutableList.java | 505 ---- .../util/collect/ImmutableListMultimap.java | 335 --- .../util/collect/ImmutableMap.java | 380 --- .../util/collect/ImmutableMultimap.java | 509 ---- .../util/collect/ImmutableMultiset.java | 502 ---- .../util/collect/ImmutableSet.java | 529 ---- .../util/collect/ImmutableSetMultimap.java | 387 --- .../util/collect/ImmutableSortedMap.java | 686 ------ .../ImmutableSortedMapFauxverideShim.java | 117 - .../util/collect/ImmutableSortedSet.java | 671 ----- .../ImmutableSortedSetFauxverideShim.java | 152 -- .../elasticsearch/util/collect/Iterables.java | 706 ------ .../elasticsearch/util/collect/Iterators.java | 964 -------- .../util/collect/LinkedHashMultimap.java | 375 --- .../util/collect/LinkedHashMultiset.java | 102 - .../util/collect/LinkedListMultimap.java | 939 ------- .../util/collect/ListMultimap.java | 81 - .../org/elasticsearch/util/collect/Lists.java | 491 ---- .../util/collect/MapConstraint.java | 38 - .../util/collect/MapDifference.java | 108 - .../elasticsearch/util/collect/MapMaker.java | 1118 --------- .../org/elasticsearch/util/collect/Maps.java | 1317 ---------- .../elasticsearch/util/collect/Multimap.java | 261 -- .../elasticsearch/util/collect/Multimaps.java | 1216 ---------- .../elasticsearch/util/collect/Multiset.java | 398 --- .../elasticsearch/util/collect/Multisets.java | 392 --- .../collect/MutableClassToInstanceMap.java | 94 - .../util/collect/NaturalOrdering.java | 77 - .../util/collect/NullOutputException.java | 31 - .../util/collect/NullsFirstOrdering.java | 80 - .../util/collect/NullsLastOrdering.java | 80 - .../util/collect/ObjectArrays.java | 174 -- .../elasticsearch/util/collect/Ordering.java | 470 ---- .../util/collect/PeekingIterator.java | 62 - .../elasticsearch/util/collect/Platform.java | 93 - .../util/collect/RegularImmutableBiMap.java | 56 - .../util/collect/RegularImmutableList.java | 226 -- .../util/collect/RegularImmutableMap.java | 209 -- .../util/collect/RegularImmutableSet.java | 67 - .../collect/RegularImmutableSortedSet.java | 248 -- .../util/collect/ReverseNaturalOrdering.java | 85 - .../util/collect/ReverseOrdering.java | 90 - .../util/collect/Serialization.java | 249 -- .../util/collect/SetMultimap.java | 93 - .../org/elasticsearch/util/collect/Sets.java | 714 ------ .../util/collect/SingletonImmutableList.java | 118 - .../util/collect/SingletonImmutableMap.java | 150 -- .../util/collect/SingletonImmutableSet.java | 115 - .../util/collect/SortedSetMultimap.java | 95 - .../util/collect/Synchronized.java | 1358 ----------- .../util/collect/TreeMultimap.java | 200 -- .../util/collect/TreeMultiset.java | 208 -- .../util/collect/UnmodifiableIterator.java | 38 - .../util/collect/UsingToStringOrdering.java | 45 - .../util/collect/package-info.java | 187 -- .../util/concurrent/DynamicExecutors.java | 2 +- .../util/gnu/trove/Decorators.java | 478 ---- .../util/gnu/trove/HashFunctions.java | 96 - .../util/gnu/trove/PrimeFinder.java | 168 -- .../gnu/trove/SerializationProcedure.java | 715 ------ .../util/gnu/trove/TByteArrayList.java | 935 ------- .../util/gnu/trove/TByteByteHashMap.java | 650 ----- .../util/gnu/trove/TByteByteIterator.java | 154 -- .../util/gnu/trove/TByteByteProcedure.java | 49 - .../util/gnu/trove/TByteDoubleHashMap.java | 650 ----- .../util/gnu/trove/TByteDoubleIterator.java | 154 -- .../util/gnu/trove/TByteDoubleProcedure.java | 49 - .../util/gnu/trove/TByteFloatHashMap.java | 650 ----- .../util/gnu/trove/TByteFloatIterator.java | 154 -- .../util/gnu/trove/TByteFloatProcedure.java | 49 - .../util/gnu/trove/TByteFunction.java | 44 - .../util/gnu/trove/TByteHash.java | 291 --- .../util/gnu/trove/TByteHashSet.java | 373 --- .../util/gnu/trove/TByteHashingStrategy.java | 50 - .../util/gnu/trove/TByteIntHashMap.java | 650 ----- .../util/gnu/trove/TByteIntIterator.java | 154 -- .../util/gnu/trove/TByteIntProcedure.java | 49 - .../util/gnu/trove/TByteIterator.java | 59 - .../util/gnu/trove/TByteLongHashMap.java | 650 ----- .../util/gnu/trove/TByteLongIterator.java | 154 -- .../util/gnu/trove/TByteLongProcedure.java | 49 - .../util/gnu/trove/TByteObjectHashMap.java | 632 ----- .../util/gnu/trove/TByteObjectIterator.java | 154 -- .../util/gnu/trove/TByteObjectProcedure.java | 49 - .../util/gnu/trove/TByteProcedure.java | 47 - .../util/gnu/trove/TByteShortHashMap.java | 650 ----- .../util/gnu/trove/TByteShortIterator.java | 154 -- .../util/gnu/trove/TByteShortProcedure.java | 49 - .../util/gnu/trove/TByteStack.java | 124 - .../util/gnu/trove/TDoubleArrayList.java | 935 ------- .../util/gnu/trove/TDoubleByteHashMap.java | 650 ----- .../util/gnu/trove/TDoubleByteIterator.java | 154 -- .../util/gnu/trove/TDoubleByteProcedure.java | 49 - .../util/gnu/trove/TDoubleDoubleHashMap.java | 650 ----- .../util/gnu/trove/TDoubleDoubleIterator.java | 154 -- .../gnu/trove/TDoubleDoubleProcedure.java | 49 - .../util/gnu/trove/TDoubleFloatHashMap.java | 650 ----- .../util/gnu/trove/TDoubleFloatIterator.java | 154 -- .../util/gnu/trove/TDoubleFloatProcedure.java | 49 - .../util/gnu/trove/TDoubleFunction.java | 44 - .../util/gnu/trove/TDoubleHash.java | 291 --- .../util/gnu/trove/TDoubleHashSet.java | 373 --- .../gnu/trove/TDoubleHashingStrategy.java | 50 - .../util/gnu/trove/TDoubleIntHashMap.java | 650 ----- .../util/gnu/trove/TDoubleIntIterator.java | 154 -- .../util/gnu/trove/TDoubleIntProcedure.java | 49 - .../util/gnu/trove/TDoubleIterator.java | 59 - .../util/gnu/trove/TDoubleLongHashMap.java | 650 ----- .../util/gnu/trove/TDoubleLongIterator.java | 154 -- .../util/gnu/trove/TDoubleLongProcedure.java | 49 - .../util/gnu/trove/TDoubleObjectHashMap.java | 632 ----- .../util/gnu/trove/TDoubleObjectIterator.java | 154 -- .../gnu/trove/TDoubleObjectProcedure.java | 49 - .../util/gnu/trove/TDoubleProcedure.java | 47 - .../util/gnu/trove/TDoubleShortHashMap.java | 650 ----- .../util/gnu/trove/TDoubleShortIterator.java | 154 -- .../util/gnu/trove/TDoubleShortProcedure.java | 49 - .../util/gnu/trove/TDoubleStack.java | 124 - .../util/gnu/trove/TFloatArrayList.java | 935 ------- .../util/gnu/trove/TFloatByteHashMap.java | 650 ----- .../util/gnu/trove/TFloatByteIterator.java | 154 -- .../util/gnu/trove/TFloatByteProcedure.java | 49 - .../util/gnu/trove/TFloatDoubleHashMap.java | 650 ----- .../util/gnu/trove/TFloatDoubleIterator.java | 154 -- .../util/gnu/trove/TFloatDoubleProcedure.java | 49 - .../util/gnu/trove/TFloatFloatHashMap.java | 650 ----- .../util/gnu/trove/TFloatFloatIterator.java | 154 -- .../util/gnu/trove/TFloatFloatProcedure.java | 49 - .../util/gnu/trove/TFloatFunction.java | 44 - .../util/gnu/trove/TFloatHash.java | 291 --- .../util/gnu/trove/TFloatHashSet.java | 373 --- .../util/gnu/trove/TFloatHashingStrategy.java | 50 - .../util/gnu/trove/TFloatIntHashMap.java | 650 ----- .../util/gnu/trove/TFloatIntIterator.java | 154 -- .../util/gnu/trove/TFloatIntProcedure.java | 49 - .../util/gnu/trove/TFloatIterator.java | 59 - .../util/gnu/trove/TFloatLongHashMap.java | 650 ----- .../util/gnu/trove/TFloatLongIterator.java | 154 -- .../util/gnu/trove/TFloatLongProcedure.java | 49 - .../util/gnu/trove/TFloatObjectHashMap.java | 632 ----- .../util/gnu/trove/TFloatObjectIterator.java | 154 -- .../util/gnu/trove/TFloatObjectProcedure.java | 49 - .../util/gnu/trove/TFloatProcedure.java | 47 - .../util/gnu/trove/TFloatShortHashMap.java | 650 ----- .../util/gnu/trove/TFloatShortIterator.java | 154 -- .../util/gnu/trove/TFloatShortProcedure.java | 49 - .../util/gnu/trove/TFloatStack.java | 124 - .../elasticsearch/util/gnu/trove/THash.java | 419 ---- .../util/gnu/trove/THashIterator.java | 102 - .../util/gnu/trove/THashMap.java | 824 ------- .../util/gnu/trove/THashSet.java | 415 ---- .../util/gnu/trove/TIntArrayList.java | 935 ------- .../util/gnu/trove/TIntByteHashMap.java | 650 ----- .../util/gnu/trove/TIntByteIterator.java | 154 -- .../util/gnu/trove/TIntByteProcedure.java | 49 - .../util/gnu/trove/TIntDoubleHashMap.java | 650 ----- .../util/gnu/trove/TIntDoubleIterator.java | 154 -- .../util/gnu/trove/TIntDoubleProcedure.java | 49 - .../util/gnu/trove/TIntFloatHashMap.java | 650 ----- .../util/gnu/trove/TIntFloatIterator.java | 154 -- .../util/gnu/trove/TIntFloatProcedure.java | 49 - .../util/gnu/trove/TIntFunction.java | 44 - .../util/gnu/trove/TIntHash.java | 291 --- .../util/gnu/trove/TIntHashSet.java | 373 --- .../util/gnu/trove/TIntHashingStrategy.java | 50 - .../util/gnu/trove/TIntIntHashMap.java | 650 ----- .../util/gnu/trove/TIntIntIterator.java | 154 -- .../util/gnu/trove/TIntIntProcedure.java | 49 - .../util/gnu/trove/TIntIterator.java | 59 - .../util/gnu/trove/TIntLongHashMap.java | 650 ----- .../util/gnu/trove/TIntLongIterator.java | 154 -- .../util/gnu/trove/TIntLongProcedure.java | 49 - .../util/gnu/trove/TIntObjectHashMap.java | 632 ----- .../util/gnu/trove/TIntObjectIterator.java | 154 -- .../util/gnu/trove/TIntObjectProcedure.java | 49 - .../util/gnu/trove/TIntProcedure.java | 47 - .../util/gnu/trove/TIntShortHashMap.java | 650 ----- .../util/gnu/trove/TIntShortIterator.java | 154 -- .../util/gnu/trove/TIntShortProcedure.java | 49 - .../util/gnu/trove/TIntStack.java | 124 - .../util/gnu/trove/TIterator.java | 109 - .../util/gnu/trove/TLinkable.java | 66 - .../util/gnu/trove/TLinkableAdapter.java | 74 - .../util/gnu/trove/TLinkedList.java | 749 ------ .../util/gnu/trove/TLongArrayList.java | 935 ------- .../util/gnu/trove/TLongByteHashMap.java | 650 ----- .../util/gnu/trove/TLongByteIterator.java | 154 -- .../util/gnu/trove/TLongByteProcedure.java | 49 - .../util/gnu/trove/TLongDoubleHashMap.java | 650 ----- .../util/gnu/trove/TLongDoubleIterator.java | 154 -- .../util/gnu/trove/TLongDoubleProcedure.java | 49 - .../util/gnu/trove/TLongFloatHashMap.java | 650 ----- .../util/gnu/trove/TLongFloatIterator.java | 154 -- .../util/gnu/trove/TLongFloatProcedure.java | 49 - .../util/gnu/trove/TLongFunction.java | 44 - .../util/gnu/trove/TLongHash.java | 291 --- .../util/gnu/trove/TLongHashSet.java | 373 --- .../util/gnu/trove/TLongHashingStrategy.java | 50 - .../util/gnu/trove/TLongIntHashMap.java | 650 ----- .../util/gnu/trove/TLongIntIterator.java | 154 -- .../util/gnu/trove/TLongIntProcedure.java | 49 - .../util/gnu/trove/TLongIterator.java | 59 - .../util/gnu/trove/TLongLongHashMap.java | 650 ----- .../util/gnu/trove/TLongLongIterator.java | 154 -- .../util/gnu/trove/TLongLongProcedure.java | 49 - .../util/gnu/trove/TLongObjectHashMap.java | 632 ----- .../util/gnu/trove/TLongObjectIterator.java | 154 -- .../util/gnu/trove/TLongObjectProcedure.java | 49 - .../util/gnu/trove/TLongProcedure.java | 47 - .../util/gnu/trove/TLongShortHashMap.java | 650 ----- .../util/gnu/trove/TLongShortIterator.java | 154 -- .../util/gnu/trove/TLongShortProcedure.java | 49 - .../util/gnu/trove/TLongStack.java | 124 - .../util/gnu/trove/TObjectByteHashMap.java | 631 ----- .../util/gnu/trove/TObjectByteIterator.java | 168 -- .../util/gnu/trove/TObjectByteProcedure.java | 49 - .../util/gnu/trove/TObjectDoubleHashMap.java | 631 ----- .../util/gnu/trove/TObjectDoubleIterator.java | 168 -- .../gnu/trove/TObjectDoubleProcedure.java | 49 - .../util/gnu/trove/TObjectFloatHashMap.java | 631 ----- .../util/gnu/trove/TObjectFloatIterator.java | 168 -- .../util/gnu/trove/TObjectFloatProcedure.java | 49 - .../util/gnu/trove/TObjectFunction.java | 39 - .../util/gnu/trove/TObjectHash.java | 378 --- .../util/gnu/trove/TObjectHashIterator.java | 42 - .../gnu/trove/TObjectHashingStrategy.java | 59 - .../trove/TObjectIdentityHashingStrategy.java | 55 - .../util/gnu/trove/TObjectIntHashMap.java | 631 ----- .../util/gnu/trove/TObjectIntIterator.java | 168 -- .../util/gnu/trove/TObjectIntProcedure.java | 49 - .../util/gnu/trove/TObjectLongHashMap.java | 631 ----- .../util/gnu/trove/TObjectLongIterator.java | 168 -- .../util/gnu/trove/TObjectLongProcedure.java | 49 - .../gnu/trove/TObjectObjectProcedure.java | 44 - .../util/gnu/trove/TObjectProcedure.java | 43 - .../util/gnu/trove/TObjectShortHashMap.java | 631 ----- .../util/gnu/trove/TObjectShortIterator.java | 168 -- .../util/gnu/trove/TObjectShortProcedure.java | 49 - .../util/gnu/trove/TPrimitiveHash.java | 135 -- .../util/gnu/trove/TPrimitiveIterator.java | 78 - .../util/gnu/trove/TShortArrayList.java | 935 ------- .../util/gnu/trove/TShortByteHashMap.java | 650 ----- .../util/gnu/trove/TShortByteIterator.java | 154 -- .../util/gnu/trove/TShortByteProcedure.java | 49 - .../util/gnu/trove/TShortDoubleHashMap.java | 650 ----- .../util/gnu/trove/TShortDoubleIterator.java | 154 -- .../util/gnu/trove/TShortDoubleProcedure.java | 49 - .../util/gnu/trove/TShortFloatHashMap.java | 650 ----- .../util/gnu/trove/TShortFloatIterator.java | 154 -- .../util/gnu/trove/TShortFloatProcedure.java | 49 - .../util/gnu/trove/TShortFunction.java | 44 - .../util/gnu/trove/TShortHash.java | 291 --- .../util/gnu/trove/TShortHashSet.java | 373 --- .../util/gnu/trove/TShortHashingStrategy.java | 50 - .../util/gnu/trove/TShortIntHashMap.java | 650 ----- .../util/gnu/trove/TShortIntIterator.java | 154 -- .../util/gnu/trove/TShortIntProcedure.java | 49 - .../util/gnu/trove/TShortIterator.java | 59 - .../util/gnu/trove/TShortLongHashMap.java | 650 ----- .../util/gnu/trove/TShortLongIterator.java | 154 -- .../util/gnu/trove/TShortLongProcedure.java | 49 - .../util/gnu/trove/TShortObjectHashMap.java | 632 ----- .../util/gnu/trove/TShortObjectIterator.java | 154 -- .../util/gnu/trove/TShortObjectProcedure.java | 49 - .../util/gnu/trove/TShortProcedure.java | 47 - .../util/gnu/trove/TShortShortHashMap.java | 650 ----- .../util/gnu/trove/TShortShortIterator.java | 154 -- .../util/gnu/trove/TShortShortProcedure.java | 49 - .../util/gnu/trove/TShortStack.java | 124 - .../gnu/trove/ToObjectArrayProcedure.java | 43 - .../decorator/TByteByteHashMapDecorator.java | 367 --- .../TByteDoubleHashMapDecorator.java | 367 --- .../decorator/TByteFloatHashMapDecorator.java | 367 --- .../decorator/TByteHashSetDecorator.java | 249 -- .../decorator/TByteIntHashMapDecorator.java | 367 --- .../decorator/TByteLongHashMapDecorator.java | 367 --- .../TByteObjectHashMapDecorator.java | 356 --- .../decorator/TByteShortHashMapDecorator.java | 367 --- .../TDoubleByteHashMapDecorator.java | 367 --- .../TDoubleDoubleHashMapDecorator.java | 367 --- .../TDoubleFloatHashMapDecorator.java | 367 --- .../decorator/TDoubleHashSetDecorator.java | 249 -- .../decorator/TDoubleIntHashMapDecorator.java | 367 --- .../TDoubleLongHashMapDecorator.java | 367 --- .../TDoubleObjectHashMapDecorator.java | 356 --- .../TDoubleShortHashMapDecorator.java | 367 --- .../decorator/TFloatByteHashMapDecorator.java | 367 --- .../TFloatDoubleHashMapDecorator.java | 367 --- .../TFloatFloatHashMapDecorator.java | 367 --- .../decorator/TFloatHashSetDecorator.java | 249 -- .../decorator/TFloatIntHashMapDecorator.java | 367 --- .../decorator/TFloatLongHashMapDecorator.java | 367 --- .../TFloatObjectHashMapDecorator.java | 356 --- .../TFloatShortHashMapDecorator.java | 367 --- .../decorator/TIntByteHashMapDecorator.java | 367 --- .../decorator/TIntDoubleHashMapDecorator.java | 367 --- .../decorator/TIntFloatHashMapDecorator.java | 367 --- .../trove/decorator/TIntHashSetDecorator.java | 249 -- .../decorator/TIntIntHashMapDecorator.java | 367 --- .../decorator/TIntLongHashMapDecorator.java | 367 --- .../decorator/TIntObjectHashMapDecorator.java | 356 --- .../decorator/TIntShortHashMapDecorator.java | 367 --- .../decorator/TLongByteHashMapDecorator.java | 367 --- .../TLongDoubleHashMapDecorator.java | 367 --- .../decorator/TLongFloatHashMapDecorator.java | 367 --- .../decorator/TLongHashSetDecorator.java | 249 -- .../decorator/TLongIntHashMapDecorator.java | 367 --- .../decorator/TLongLongHashMapDecorator.java | 367 --- .../TLongObjectHashMapDecorator.java | 356 --- .../decorator/TLongShortHashMapDecorator.java | 367 --- .../TObjectByteHashMapDecorator.java | 367 --- .../TObjectDoubleHashMapDecorator.java | 367 --- .../TObjectFloatHashMapDecorator.java | 367 --- .../decorator/TObjectIntHashMapDecorator.java | 367 --- .../TObjectLongHashMapDecorator.java | 367 --- .../TObjectShortHashMapDecorator.java | 367 --- .../decorator/TShortByteHashMapDecorator.java | 367 --- .../TShortDoubleHashMapDecorator.java | 367 --- .../TShortFloatHashMapDecorator.java | 367 --- .../decorator/TShortHashSetDecorator.java | 249 -- .../decorator/TShortIntHashMapDecorator.java | 367 --- .../decorator/TShortLongHashMapDecorator.java | 367 --- .../TShortObjectHashMapDecorator.java | 356 --- .../TShortShortHashMapDecorator.java | 367 --- .../util/gnu/trove/decorator/package.html | 58 - .../elasticsearch/util/gnu/trove/package.html | 160 -- .../http/client/AsyncCompletionHandler.java | 92 - .../client/AsyncCompletionHandlerBase.java | 41 - .../util/http/client/AsyncHandler.java | 76 - .../util/http/client/AsyncHttpClient.java | 423 ---- .../http/client/AsyncHttpClientConfig.java | 435 ---- .../util/http/client/AsyncHttpProvider.java | 54 - .../util/http/client/ByteArrayPart.java | 53 - .../util/http/client/Cookie.java | 65 - .../util/http/client/FilePart.java | 52 - .../util/http/client/FutureImpl.java | 31 - .../util/http/client/Headers.java | 233 -- .../util/http/client/HttpContent.java | 41 - .../http/client/HttpResponseBodyPart.java | 36 - .../util/http/client/HttpResponseHeaders.java | 53 - .../util/http/client/HttpResponseStatus.java | 71 - .../http/client/MaxRedirectException.java | 40 - .../elasticsearch/util/http/client/Part.java | 24 - .../util/http/client/ProxyServer.java | 111 - .../util/http/client/Request.java | 58 - .../util/http/client/RequestBuilder.java | 124 - .../util/http/client/RequestBuilderBase.java | 358 --- .../util/http/client/RequestType.java | 25 - .../util/http/client/Response.java | 122 - .../util/http/client/StringPart.java | 38 - .../providers/NettyAsyncHttpProvider.java | 776 ------ .../client/providers/NettyAsyncResponse.java | 193 -- .../client/providers/NettyResponseFuture.java | 207 -- .../client/providers/ResponseBodyPart.java | 57 - .../client/providers/ResponseHeaders.java | 67 - .../http/client/providers/ResponseStatus.java | 71 - .../util/http/collection/Pair.java | 63 - .../http/multipart/ByteArrayPartSource.java | 73 - .../util/http/multipart/FilePart.java | 233 -- .../util/http/multipart/FilePartSource.java | 112 - .../http/multipart/MultipartEncodingUtil.java | 76 - .../multipart/MultipartRequestEntity.java | 152 -- .../util/http/multipart/Part.java | 453 ---- .../util/http/multipart/PartBase.java | 141 -- .../util/http/multipart/PartSource.java | 52 - .../util/http/multipart/RequestEntity.java | 63 - .../util/http/multipart/StringPart.java | 141 -- .../elasticsearch/util/http/package-info.java | 11 - .../org/elasticsearch/util/http/url/Url.java | 436 ---- .../util/http/util/SslUtils.java | 165 -- .../util/inject/AbstractModule.java | 239 -- .../util/inject/AbstractProcessor.java | 115 - .../org/elasticsearch/util/inject/Binder.java | 376 --- .../elasticsearch/util/inject/Binding.java | 92 - .../util/inject/BindingAnnotation.java | 40 - .../util/inject/BindingProcessor.java | 266 -- .../util/inject/BoundProviderFactory.java | 67 - .../util/inject/ConfigurationException.java | 76 - .../util/inject/ConstantFactory.java | 47 - .../util/inject/ConstructionProxy.java | 46 - .../util/inject/ConstructionProxyFactory.java | 30 - .../util/inject/ConstructorBindingImpl.java | 100 - .../util/inject/ConstructorInjector.java | 109 - .../util/inject/ConstructorInjectorStore.java | 76 - .../util/inject/ContextualCallable.java | 27 - .../util/inject/CreationException.java | 54 - .../DefaultConstructionProxyFactory.java | 68 - .../util/inject/DeferredLookups.java | 60 - .../util/inject/EncounterImpl.java | 114 - .../elasticsearch/util/inject/Exposed.java | 33 - .../util/inject/ExposedKeyFactory.java | 60 - .../util/inject/FactoryProxy.java | 65 - .../org/elasticsearch/util/inject/Guice.java | 97 - .../util/inject/ImplementedBy.java | 37 - .../util/inject/InheritingState.java | 132 - .../util/inject/Initializable.java | 33 - .../util/inject/Initializables.java | 41 - .../util/inject/Initializer.java | 157 -- .../org/elasticsearch/util/inject/Inject.java | 68 - .../inject/InjectionRequestProcessor.java | 120 - .../elasticsearch/util/inject/Injector.java | 212 -- .../util/inject/InjectorBuilder.java | 271 --- .../util/inject/InjectorImpl.java | 801 ------ .../util/inject/InjectorShell.java | 243 -- .../InternalFactoryToProviderAdapter.java | 57 - .../org/elasticsearch/util/inject/Key.java | 494 ---- .../util/inject/LookupProcessor.java | 59 - .../elasticsearch/util/inject/Lookups.java | 30 - .../util/inject/MembersInjector.java | 42 - .../util/inject/MembersInjectorImpl.java | 118 - .../util/inject/MembersInjectorStore.java | 124 - .../util/inject/MessageProcessor.java | 54 - .../org/elasticsearch/util/inject/Module.java | 43 - .../util/inject/OutOfScopeException.java | 39 - .../util/inject/PrivateBinder.java | 50 - .../util/inject/PrivateElementProcessor.java | 52 - .../util/inject/PrivateModule.java | 281 --- .../elasticsearch/util/inject/ProvidedBy.java | 37 - .../elasticsearch/util/inject/Provider.java | 56 - .../ProviderToInternalFactoryAdapter.java | 58 - .../elasticsearch/util/inject/Provides.java | 33 - .../util/inject/ProvisionException.java | 65 - .../elasticsearch/util/inject/Reflection.java | 50 - .../org/elasticsearch/util/inject/Scope.java | 59 - .../util/inject/ScopeAnnotation.java | 40 - .../util/inject/ScopeBindingProcessor.java | 61 - .../org/elasticsearch/util/inject/Scopes.java | 128 - .../util/inject/SingleFieldInjector.java | 66 - .../util/inject/SingleMemberInjector.java | 29 - .../util/inject/SingleMethodInjector.java | 87 - .../util/inject/SingleParameterInjector.java | 75 - .../elasticsearch/util/inject/Singleton.java | 33 - .../org/elasticsearch/util/inject/Stage.java | 44 - .../org/elasticsearch/util/inject/State.java | 142 -- .../inject/TypeConverterBindingProcessor.java | 174 -- .../inject/TypeListenerBindingProcessor.java | 37 - .../util/inject/TypeLiteral.java | 338 --- .../elasticsearch/util/inject/WeakKeySet.java | 46 - .../util/inject/assistedinject/Assisted.java | 41 - .../assistedinject/AssistedConstructor.java | 100 - .../inject/assistedinject/AssistedInject.java | 43 - .../assistedinject/FactoryProvider.java | 339 --- .../assistedinject/FactoryProvider2.java | 247 -- .../util/inject/assistedinject/Parameter.java | 156 -- .../assistedinject/ParameterListKey.java | 65 - .../inject/assistedinject/package-info.java | 21 - .../binder/AnnotatedBindingBuilder.java | 38 - .../AnnotatedConstantBindingBuilder.java | 38 - .../binder/AnnotatedElementBuilder.java | 38 - .../inject/binder/ConstantBindingBuilder.java | 73 - .../inject/binder/LinkedBindingBuilder.java | 70 - .../inject/binder/ScopedBindingBuilder.java | 46 - .../util/inject/binder/package-info.java | 21 - .../internal/AbstractBindingBuilder.java | 130 - .../util/inject/internal/Annotations.java | 117 - .../AsynchronousComputationException.java | 29 - .../util/inject/internal/BindingBuilder.java | 133 - .../util/inject/internal/BindingImpl.java | 119 - .../util/inject/internal/BytecodeGen.java | 231 -- .../util/inject/internal/Collections2.java | 55 - .../inject/internal/ComputationException.java | 27 - .../internal/ConstantBindingBuilderImpl.java | 127 - .../inject/internal/ConstructionContext.java | 125 - .../util/inject/internal/ErrorHandler.java | 37 - .../util/inject/internal/Errors.java | 631 ----- .../util/inject/internal/ErrorsException.java | 38 - .../util/inject/internal/ExpirationTimer.java | 26 - .../inject/internal/ExposedBindingImpl.java | 77 - .../util/inject/internal/ExposureBuilder.java | 67 - .../util/inject/internal/FailableCache.java | 59 - .../inject/internal/InstanceBindingImpl.java | 94 - .../util/inject/internal/InternalContext.java | 53 - .../util/inject/internal/InternalFactory.java | 37 - .../util/inject/internal/Join.java | 319 --- .../inject/internal/LinkedBindingImpl.java | 69 - .../internal/LinkedProviderBindingImpl.java | 73 - .../inject/internal/MatcherAndConverter.java | 56 - .../util/inject/internal/MoreTypes.java | 651 ----- .../inject/internal/NullOutputException.java | 30 - .../util/inject/internal/Nullability.java | 31 - .../util/inject/internal/Nullable.java | 37 - .../util/inject/internal/Preconditions.java | 465 ---- .../inject/internal/PrivateElementsImpl.java | 137 -- .../internal/ProviderInstanceBindingImpl.java | 92 - .../util/inject/internal/ProviderMethod.java | 111 - .../internal/ProviderMethodsModule.java | 129 - .../util/inject/internal/Scoping.java | 209 -- .../util/inject/internal/SourceProvider.java | 76 - .../inject/internal/StackTraceElements.java | 50 - .../util/inject/internal/Stopwatch.java | 49 - .../util/inject/internal/Strings.java | 57 - .../util/inject/internal/ToStringBuilder.java | 52 - .../inject/internal/UniqueAnnotations.java | 70 - .../inject/internal/UnmodifiableIterator.java | 36 - .../internal/UntargettedBindingImpl.java | 62 - .../util/inject/internal/package-info.java | 21 - .../util/inject/matcher/AbstractMatcher.java | 93 - .../util/inject/matcher/Matcher.java | 42 - .../util/inject/matcher/Matchers.java | 399 --- .../util/inject/matcher/package-info.java | 21 - .../util/inject/multibindings/Element.java | 36 - .../util/inject/multibindings/MapBinder.java | 365 --- .../inject/multibindings/Multibinder.java | 316 --- .../inject/multibindings/RealElement.java | 63 - .../inject/multibindings/package-info.java | 21 - .../elasticsearch/util/inject/name/Named.java | 35 - .../util/inject/name/NamedImpl.java | 58 - .../elasticsearch/util/inject/name/Names.java | 69 - .../util/inject/name/package-info.java | 20 - .../util/inject/package-info.java | 47 - .../inject/spi/BindingScopingVisitor.java | 56 - .../util/inject/spi/BindingTargetVisitor.java | 83 - .../util/inject/spi/ConstructorBinding.java | 45 - .../inject/spi/ConvertedConstantBinding.java | 47 - .../spi/DefaultBindingScopingVisitor.java | 56 - .../spi/DefaultBindingTargetVisitor.java | 77 - .../inject/spi/DefaultElementVisitor.java | 79 - .../util/inject/spi/Dependency.java | 127 - .../util/inject/spi/Element.java | 64 - .../util/inject/spi/ElementVisitor.java | 82 - .../util/inject/spi/Elements.java | 311 --- .../util/inject/spi/ExposedBinding.java | 39 - .../util/inject/spi/HasDependencies.java | 38 - .../util/inject/spi/InjectionListener.java | 35 - .../util/inject/spi/InjectionPoint.java | 395 --- .../util/inject/spi/InjectionRequest.java | 82 - .../util/inject/spi/InstanceBinding.java | 43 - .../util/inject/spi/LinkedKeyBinding.java | 36 - .../inject/spi/MembersInjectorLookup.java | 102 - .../util/inject/spi/Message.java | 133 - .../util/inject/spi/PrivateElements.java | 60 - .../util/inject/spi/ProviderBinding.java | 38 - .../inject/spi/ProviderInstanceBinding.java | 45 - .../util/inject/spi/ProviderKeyBinding.java | 39 - .../util/inject/spi/ProviderLookup.java | 97 - .../inject/spi/ProviderWithDependencies.java | 27 - .../util/inject/spi/ScopeBinding.java | 65 - .../inject/spi/StaticInjectionRequest.java | 74 - .../util/inject/spi/TypeConverter.java | 33 - .../util/inject/spi/TypeConverterBinding.java | 65 - .../util/inject/spi/TypeEncounter.java | 100 - .../util/inject/spi/TypeListener.java | 48 - .../util/inject/spi/TypeListenerBinding.java | 67 - .../util/inject/spi/UntargettedBinding.java | 28 - .../util/inject/spi/package-info.java | 21 - .../util/inject/util/Modules.java | 259 -- .../util/inject/util/Providers.java | 52 - .../elasticsearch/util/inject/util/Types.java | 133 - .../util/inject/util/package-info.java | 20 - .../util/io/stream/HandlesStreamInput.java | 2 +- .../util/io/stream/HandlesStreamOutput.java | 4 +- .../metadata/ToAndFromJsonMetaDataTests.java | 6 +- .../strategy/FailedShardsRoutingTests.java | 6 +- ...gleShardNoBackupsRoutingStrategyTests.java | 10 +- ...gleShardOneBackupRoutingStrategyTests.java | 6 +- .../TenShardsOneBackupRoutingTests.java | 6 +- .../ClusterSerializationTests.java | 4 +- .../lucene/IndexWritersTests.java | 6 +- .../lucene/all/SimpleAllTests.java | 4 +- .../lucene/search/MoreLikeThisQueryTests.java | 8 +- .../store/InputStreamIndexInputTests.java | 2 +- .../versioned/AbstractVersionedMapTests.java | 2 +- .../versioned/NativeVersionedMapTests.java | 2 +- .../NonBlockingVersionedMapTests.java | 2 +- .../versioned/VersionedIndexReaderTests.java | 6 +- .../{util => common}/path/PathTrieTests.java | 4 +- .../loader/JsonSettingsLoaderTests.java | 6 +- .../loader/YamlSettingsLoaderTests.java | 6 +- .../settings/loader/test-settings.json | 0 .../settings/loader/test-settings.yml | 0 .../builder/XContentBuilderTests.java | 10 +- .../xcontent/xson/JsonVsXsonTests.java | 10 +- .../deps/jackson/JacksonLocationTests.java | 2 +- .../deps/joda/SimpleJodaTests.java | 12 +- .../deps/lucene/IndexWriterNoBufferTests.java | 6 +- .../deps/lucene/LuceneFieldCacheTests.java | 2 +- .../deps/lucene/SimpleLuceneTests.java | 6 +- .../deps/lucene/VectorHighlighterTests.java | 4 +- .../zen/ping/unicast/UnicastZenPingTests.java | 6 +- .../index/analysis/AnalysisModuleTests.java | 8 +- .../index/cache/filter/FilterCacheTests.java | 8 +- .../SnapshotDeletionPolicyTests.java | 8 +- .../engine/AbstractSimpleEngineTests.java | 6 +- .../EngineSearcherTotalHitsMatcher.java | 2 +- .../engine/robin/SimpleRobinEngineTests.java | 2 +- .../data/doubles/DoubleFieldDataTests.java | 4 +- .../data/floats/FloatFieldDataTests.java | 4 +- .../field/data/ints/IntFieldDataTests.java | 4 +- .../field/data/longs/LongFieldDataTests.java | 4 +- .../data/shorts/ShortFieldDataTests.java | 4 +- .../data/strings/StringFieldDataTests.java | 4 +- .../xcontent/all/SimpleAllMapperTests.java | 6 +- .../xcontent/SimpleIndexQueryParserTests.java | 8 +- .../guice/IndexQueryParserModuleTests.java | 10 +- .../xcontent/guice/MyJsonFilterParser.java | 10 +- .../xcontent/guice/MyJsonQueryParser.java | 6 +- .../plugin/IndexQueryParserPluginTests.java | 10 +- .../plugin/PluginJsonFilterParser.java | 6 +- .../plugin/PluginJsonQueryParser.java | 6 +- .../index/shard/SimpleIndexShardTests.java | 4 +- .../memory/MemorySimpleTranslogTests.java | 2 +- .../monitor/jvm/DeadlockSimulator.java | 2 +- .../rest/util/RestUtilsTests.java | 2 +- .../netty/SimpleNettyTransportTests.java | 2 +- .../netty/benchmark/BenchmarkNettyClient.java | 6 +- .../netty/benchmark/BenchmarkNettyServer.java | 4 +- .../elasticsearch/util/TimeValueTests.java | 2 +- .../util/guice/InjectorsTests.java | 7 +- modules/jarjar/build.gradle | 81 + .../test/integration/AbstractNodesTests.java | 12 +- .../broadcast/BroadcastActionsTests.java | 6 +- .../ClientTransportTwoServersSearchTests.java | 2 +- .../DiscoveryTransportClientTests.java | 2 +- .../TransportClientDocumentActionsTests.java | 4 +- ...ransportClientMoreLikeThisActionTests.java | 4 +- .../datanode/SimpleDataNodesTests.java | 2 +- .../AliasedIndexDocumentActionsTests.java | 2 +- .../document/MoreLikeThisActionTests.java | 2 +- .../IndexLifecycleActionTests.java | 8 +- .../integration/ping/PingActionTests.java | 4 +- .../rest/http/RestHttpDocumentActions.java | 8 +- .../SingleInstanceEmbeddedSearchTests.java | 4 +- .../search/TransportSearchFailuresTests.java | 4 +- .../TransportTwoServersSearchTests.java | 6 +- .../TwoInstanceEmbeddedSearchTests.java | 10 +- ...ceUnbalancedShardsEmbeddedSearchTests.java | 14 +- .../customscore/CustomScoreSearchTests.java | 2 +- .../search/facets/SimpleFacetsTests.java | 2 +- .../highlight/HighlightSearchTests.java | 6 +- .../SimpleIndicesBoostSearchTests.java | 2 +- .../scriptfield/ScriptFieldSearchTests.java | 2 +- .../ClientTransportTermsActionTests.java | 2 +- .../integration/terms/TermsActionTests.java | 2 +- .../index/analysis/ICUNormalizer2Filter.java | 2 +- .../IcuCollationTokenFilterFactory.java | 6 +- .../IcuFoldingTokenFilterFactory.java | 6 +- .../IcuNormalizerTokenFilterFactory.java | 8 +- .../analysis/icu/AnalysisICUPlugin.java | 2 +- .../analysis/SimpleIcuAnalysisTests.java | 6 +- .../groovy/client/GClient.groovy | 2 +- .../groovy/node/GNodeBuilder.groovy | 8 +- .../util/xcontent/GXContentBuilder.groovy | 8 +- .../org/elasticsearch/cloud/CloudModule.java | 2 +- .../blobstore/CloudBlobStoreService.java | 10 +- .../cloud/compute/CloudComputeService.java | 10 +- .../cloud/jclouds/JCloudsUtils.java | 4 +- .../jclouds/logging/JCloudsLoggingModule.java | 6 +- .../discovery/cloud/CloudDiscovery.java | 6 +- .../discovery/cloud/CloudDiscoveryModule.java | 2 +- .../cloud/CloudUnicastHostsProvider.java | 10 +- .../gateway/cloud/CloudGateway.java | 18 +- .../gateway/cloud/CloudGatewayModule.java | 2 +- .../gateway/cloud/CloudIndexGateway.java | 4 +- .../cloud/CloudIndexGatewayModule.java | 2 +- .../gateway/cloud/CloudIndexShardGateway.java | 14 +- .../plugin/cloud/CloudPlugin.java | 8 +- .../jgroups/JgroupsCustomLogFactory.java | 4 +- .../discovery/jgroups/JgroupsDiscovery.java | 14 +- .../jgroups/JgroupsDiscoveryModule.java | 4 +- .../gateway/hdfs/HdfsGateway.java | 18 +- .../gateway/hdfs/HdfsGatewayModule.java | 2 +- .../gateway/hdfs/HdfsIndexGatewayModule.java | 2 +- .../index/gateway/hdfs/HdfsIndexGateway.java | 4 +- .../gateway/hdfs/HdfsIndexShardGateway.java | 10 +- .../hadoop/gateway/HdfsGatewayTests.java | 8 +- .../xcontent/XContentAttachmentMapper.java | 4 +- .../XContentAttachmentMapperService.java | 4 +- .../MapperAttachmentsIndexModule.java | 2 +- .../attachments/MapperAttachmentsPlugin.java | 4 +- .../xcontent/SimpleAttachmentMapperTests.java | 2 +- .../SimpleAttachmentIntegrationTests.java | 8 +- plugins/transport/memcached/build.gradle | 30 - .../memcached/MemcachedRestRequest.java | 4 +- .../memcached/MemcachedServer.java | 6 +- .../memcached/MemcachedServerModule.java | 8 +- .../memcached/MemcachedServerTransport.java | 4 +- .../memcached/netty/MemcachedDecoder.java | 10 +- .../memcached/netty/MemcachedDispatcher.java | 6 +- .../memcached/netty/MemcachedRestChannel.java | 6 +- .../netty/NettyMemcachedServerTransport.java | 30 +- .../NettyMemcachedServerTransportModule.java | 2 +- .../memcached/netty/OpenChannelsHandler.java | 2 +- .../memcached/MemcachedTransportPlugin.java | 8 +- .../test/AbstractMemcachedActionsTests.java | 2 +- settings.gradle | 2 + 1529 files changed, 2539 insertions(+), 136071 deletions(-) delete mode 100644 .idea/libraries/jackson.xml delete mode 100644 .idea/libraries/joda_time.xml delete mode 100644 .idea/libraries/netty.xml rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/component/AbstractComponent.java (93%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/component/AbstractLifecycleComponent.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/component/CloseableComponent.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/component/CloseableIndexComponent.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/component/Lifecycle.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/component/LifecycleComponent.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/component/LifecycleListener.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util/http => common/http/client}/HttpClientModule.java (90%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util/http => common/http/client}/HttpClientService.java (87%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util/http => common/http/client}/HttpDownloadHelper.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util/guice => common/inject}/Injectors.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util/guice => common/inject}/ModulesFactory.java (94%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/joda/FormatDateTimeFormatter.java (90%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/joda/Joda.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/ESLogger.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/ESLoggerFactory.java (89%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/Loggers.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/jdk/JdkESLogger.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/jdk/JdkESLoggerFactory.java (88%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/log4j/ConsoleAppender.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/log4j/JLinePatternLayout.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/log4j/Log4jESLogger.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/log4j/Log4jESLoggerFactory.java (87%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/log4j/LogConfigurator.java (90%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/slf4j/Slf4jESLogger.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/slf4j/Slf4jESLoggerFactory.java (87%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/support/AbstractESLogger.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/logging/support/LoggerMessageFormat.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/Directories.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/DocumentBuilder.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/FieldBuilder.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/IndexCommitDelegate.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/IndexWriters.java (93%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/LoggerInfoStream.java (94%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/Lucene.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/MultiCollector.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/ReaderSearcherHolder.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/all/AllEntries.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/all/AllField.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/all/AllTermQuery.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/all/AllTokenStream.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/analysis/CharSequenceTermAttribute.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/docset/AndDocSet.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/docset/DocIdSetCollector.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/docset/DocSet.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/docset/DocSets.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/docset/NotDocSet.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/docset/OpenBitDocSet.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/docset/OrDocSet.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/AndFilter.java (90%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/MoreLikeThisQuery.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/NoopCollector.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/NotFilter.java (91%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/OrFilter.java (90%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/Queries.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/TermFilter.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/function/BoostScoreFunction.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/function/FunctionScoreQuery.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/search/function/ScoreFunction.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/store/InputStreamIndexInput.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/store/SwitchDirectory.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/store/ThreadSafeInputStreamIndexInput.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/versioned/ConcurrentVersionedMap.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/versioned/ConcurrentVersionedMapLong.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/versioned/NativeVersionedMap.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/versioned/VersionedIndexReader.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/lucene/versioned/VersionedMap.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/netty/OpenChannelsHandler.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/network/NetworkModule.java (91%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/network/NetworkService.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/network/NetworkUtils.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/path/PathTrie.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/ImmutableSettings.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/NoClassSettingsException.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/Settings.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/SettingsException.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/SettingsFilter.java (85%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/SettingsModule.java (92%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/loader/JsonSettingsLoader.java (93%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/loader/PropertiesSettingsLoader.java (94%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/loader/SettingsLoader.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/loader/SettingsLoaderFactory.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/loader/YamlSettingsLoader.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/loader/package-info.java (94%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/settings/package-info.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/timer/HashedWheelTimer.java (99%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/timer/Timeout.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/timer/Timer.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/timer/TimerTask.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/transport/BoundTransportAddress.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/transport/DummyTransportAddress.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/transport/InetSocketTransportAddress.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/transport/LocalTransportAddress.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/transport/NetworkExceptionHelper.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/transport/PortsRange.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/transport/TransportAddress.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/transport/TransportAddressSerializers.java (90%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/trove/ExtTIntArrayList.java (92%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/trove/ExtTIntIntHashMap.java (92%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/trove/ExtTObjectFloatHashMap.java (92%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/trove/ExtTObjectIntHasMap.java (92%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/ToXContent.java (94%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/XContent.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/XContentFactory.java (89%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/XContentGenerator.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/XContentParser.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/XContentType.java (93%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/builder/BinaryXContentBuilder.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/builder/TextXContentBuilder.java (97%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/builder/XContentBuilder.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/json/JsonXContent.java (89%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/json/JsonXContentGenerator.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/json/JsonXContentParser.java (94%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/support/AbstractXContentGenerator.java (95%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/support/AbstractXContentParser.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/support/XContentMapConverter.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/support/XContentMapValues.java (98%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/xson/XsonType.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/xson/XsonXContent.java (91%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/xson/XsonXContentGenerator.java (96%) rename modules/elasticsearch/src/main/java/org/elasticsearch/{util => common}/xcontent/xson/XsonXContentParser.java (98%) delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/GwtCompatible.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/GwtIncompatible.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/VisibleForTesting.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizablePhantomReference.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableReference.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableReferenceQueue.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableSoftReference.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableWeakReference.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Function.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Functions.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Joiner.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Objects.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Platform.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Preconditions.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Predicate.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Predicates.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Supplier.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Suppliers.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/internal/Finalizer.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/base/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractBiMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractListMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMapBasedMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMapEntry.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractSetMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractSortedSetMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ArrayListMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AsynchronousComputationException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/BiMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ByFunctionOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ClassToInstanceMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Collections2.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ComparatorOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/CompoundOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ComputationException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ConcurrentHashMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ConstrainedMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/CustomConcurrentHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableListMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSetMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSortedSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumBiMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumHashBiMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ExpirationTimer.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ExplicitOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingCollection.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingConcurrentMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingListIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMapEntry.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingObject.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingQueue.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSortedMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSortedSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashBiMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Hashing.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableBiMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableClassToInstanceMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableCollection.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableEntry.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableEnumSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableListMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSetMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedMapFauxverideShim.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedSetFauxverideShim.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Iterables.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Iterators.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedHashMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedHashMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedListMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ListMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Lists.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapConstraint.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapDifference.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapMaker.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Maps.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multimaps.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multisets.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MutableClassToInstanceMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NaturalOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullOutputException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullsFirstOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullsLastOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ObjectArrays.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Ordering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/PeekingIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Platform.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableBiMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableSortedSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ReverseNaturalOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ReverseOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Serialization.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SetMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Sets.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SortedSetMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Synchronized.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/TreeMultimap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/TreeMultiset.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/UnmodifiableIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/UsingToStringOrdering.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/Decorators.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/HashFunctions.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/PrimeFinder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/SerializationProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteArrayList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFunction.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHash.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHashSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHashingStrategy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteStack.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleArrayList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFunction.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHash.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHashSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHashingStrategy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleStack.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatArrayList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFunction.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHash.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHashSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHashingStrategy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatStack.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THash.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntArrayList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFunction.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHash.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHashSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHashingStrategy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntStack.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkable.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkableAdapter.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkedList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongArrayList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFunction.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHash.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHashSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHashingStrategy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongStack.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFunction.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHash.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHashIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHashingStrategy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIdentityHashingStrategy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectObjectProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TPrimitiveHash.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TPrimitiveIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortArrayList.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFunction.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHash.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHashSet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHashingStrategy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortHashMap.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortStack.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/ToObjectArrayProcedure.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteByteHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteDoubleHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteFloatHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteHashSetDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteIntHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteLongHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteObjectHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteShortHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleByteHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleDoubleHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleFloatHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleHashSetDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleIntHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleLongHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleObjectHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleShortHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatByteHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatDoubleHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatFloatHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatHashSetDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatIntHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatLongHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatObjectHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatShortHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntByteHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntDoubleHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntFloatHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntHashSetDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntIntHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntLongHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntObjectHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntShortHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongByteHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongDoubleHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongFloatHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongHashSetDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongIntHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongLongHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongObjectHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongShortHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectByteHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectDoubleHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectFloatHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectIntHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectLongHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectShortHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortByteHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortDoubleHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortFloatHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortHashSetDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortIntHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortLongHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortObjectHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortShortHashMapDecorator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/package.html delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/package.html delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncCompletionHandler.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncCompletionHandlerBase.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHandler.java delete mode 100755 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpClient.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpClientConfig.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpProvider.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/ByteArrayPart.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Cookie.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/FilePart.java delete mode 100755 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/FutureImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Headers.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpContent.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseBodyPart.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseHeaders.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseStatus.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/MaxRedirectException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Part.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/ProxyServer.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Request.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestBuilderBase.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestType.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Response.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/StringPart.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyAsyncHttpProvider.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyAsyncResponse.java delete mode 100755 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyResponseFuture.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseBodyPart.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseHeaders.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseStatus.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/collection/Pair.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/ByteArrayPartSource.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/FilePart.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/FilePartSource.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/MultipartEncodingUtil.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/MultipartRequestEntity.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/Part.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/PartBase.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/PartSource.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/RequestEntity.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/StringPart.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/url/Url.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/http/util/SslUtils.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/AbstractModule.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/AbstractProcessor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Binder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Binding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BindingAnnotation.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BindingProcessor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BoundProviderFactory.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConfigurationException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstantFactory.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructionProxy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructionProxyFactory.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorBindingImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorInjector.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorInjectorStore.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ContextualCallable.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/CreationException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/DefaultConstructionProxyFactory.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/DeferredLookups.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/EncounterImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Exposed.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ExposedKeyFactory.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/FactoryProxy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Guice.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ImplementedBy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InheritingState.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializable.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializables.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializer.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Inject.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectionRequestProcessor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Injector.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorShell.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InternalFactoryToProviderAdapter.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Key.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/LookupProcessor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Lookups.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjector.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjectorImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjectorStore.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MessageProcessor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Module.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/OutOfScopeException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateBinder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateElementProcessor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateModule.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProvidedBy.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Provider.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProviderToInternalFactoryAdapter.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Provides.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProvisionException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Reflection.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Scope.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ScopeAnnotation.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ScopeBindingProcessor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Scopes.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleFieldInjector.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleMemberInjector.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleMethodInjector.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleParameterInjector.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Singleton.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Stage.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/State.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeConverterBindingProcessor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeListenerBindingProcessor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeLiteral.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/WeakKeySet.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/Assisted.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/AssistedConstructor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/AssistedInject.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/FactoryProvider.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/FactoryProvider2.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/Parameter.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/ParameterListKey.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedBindingBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedConstantBindingBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedElementBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/ConstantBindingBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/LinkedBindingBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/ScopedBindingBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/AbstractBindingBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Annotations.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/AsynchronousComputationException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BindingBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BindingImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BytecodeGen.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Collections2.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ComputationException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ConstantBindingBuilderImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ConstructionContext.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ErrorHandler.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Errors.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ErrorsException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExpirationTimer.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExposedBindingImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExposureBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/FailableCache.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InstanceBindingImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InternalContext.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InternalFactory.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Join.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/LinkedBindingImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/LinkedProviderBindingImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/MatcherAndConverter.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/MoreTypes.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/NullOutputException.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Nullability.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Nullable.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Preconditions.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/PrivateElementsImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderInstanceBindingImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderMethod.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderMethodsModule.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Scoping.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/SourceProvider.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/StackTraceElements.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Stopwatch.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Strings.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ToStringBuilder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UniqueAnnotations.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UnmodifiableIterator.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UntargettedBindingImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/AbstractMatcher.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/Matcher.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/Matchers.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/Element.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/MapBinder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/Multibinder.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/RealElement.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/Named.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/NamedImpl.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/Names.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/BindingScopingVisitor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/BindingTargetVisitor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ConstructorBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ConvertedConstantBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultBindingScopingVisitor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultBindingTargetVisitor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultElementVisitor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Dependency.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Element.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ElementVisitor.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Elements.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ExposedBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/HasDependencies.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionListener.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionPoint.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionRequest.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InstanceBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/LinkedKeyBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/MembersInjectorLookup.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Message.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/PrivateElements.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderInstanceBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderKeyBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderLookup.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderWithDependencies.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ScopeBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/StaticInjectionRequest.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeConverter.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeConverterBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeEncounter.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeListener.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeListenerBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/UntargettedBinding.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/package-info.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Modules.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Providers.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Types.java delete mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/package-info.java rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/lucene/IndexWritersTests.java (92%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/lucene/all/SimpleAllTests.java (99%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/lucene/search/MoreLikeThisQueryTests.java (91%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/lucene/store/InputStreamIndexInputTests.java (99%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/lucene/versioned/AbstractVersionedMapTests.java (97%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/lucene/versioned/NativeVersionedMapTests.java (95%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/lucene/versioned/NonBlockingVersionedMapTests.java (95%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/lucene/versioned/VersionedIndexReaderTests.java (96%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/path/PathTrieTests.java (96%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/settings/loader/JsonSettingsLoaderTests.java (91%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/settings/loader/YamlSettingsLoaderTests.java (91%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/settings/loader/test-settings.json (100%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/settings/loader/test-settings.yml (100%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/xcontent/builder/XContentBuilderTests.java (92%) rename modules/elasticsearch/src/test/java/org/elasticsearch/{util => common}/xcontent/xson/JsonVsXsonTests.java (92%) create mode 100644 modules/jarjar/build.gradle diff --git a/.idea/libraries/jackson.xml b/.idea/libraries/jackson.xml deleted file mode 100644 index 684ca44fb96..00000000000 --- a/.idea/libraries/jackson.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/joda_time.xml b/.idea/libraries/joda_time.xml deleted file mode 100644 index 99b7ace9096..00000000000 --- a/.idea/libraries/joda_time.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/netty.xml b/.idea/libraries/netty.xml deleted file mode 100644 index 872e7eceec0..00000000000 --- a/.idea/libraries/netty.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/elasticsearch.iml b/.idea/modules/elasticsearch.iml index 28e6c3eecd5..e8fa1fb441d 100644 --- a/.idea/modules/elasticsearch.iml +++ b/.idea/modules/elasticsearch.iml @@ -13,21 +13,19 @@ - - - - - + - + + + + - @@ -40,17 +38,6 @@ - - - - - - - - - - - diff --git a/build.gradle b/build.gradle index b05fed69071..5f8a22b0532 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,8 @@ mavenSnapshotRepoUrl = "http://oss.sonatype.org/content/repositories/snapshots" mavenRepoUser = "kimchy" mavenRepoPass = System.getenv("REPO_PASS") +jarjarArchivePath = project(":jarjar").file("build/libs/jarjar-$versionNumber" + ".jar").absolutePath + allprojects { group = 'org.elasticsearch' version = versionNumber @@ -39,6 +41,7 @@ allprojects { mavenRepo urls: 'https://repository.jboss.org/nexus/content/groups/public' mavenRepo urls: 'http://repository.codehaus.org/' mavenRepo urls: 'http://elasticsearch.googlecode.com/svn/maven' + mavenRepo urls: 'http://oss.sonatype.org/content/repositories/snapshots' } } @@ -79,12 +82,8 @@ task explodedDist(dependsOn: [configurations.distLib], description: 'Builds a mi ant.delete { fileset(dir: explodedDistLibDir, includes: "$archivesBaseName-*-javadoc.jar") } ant.delete { fileset(dir: explodedDistLibDir, includes: "$archivesBaseName-*-sources.jar") } ant.delete { fileset(dir: explodedDistLibDir, includes: "slf4j-*.jar") } // no need for slf4j - ant.delete { fileset(dir: explodedDistLibDir, includes: "jackson-*.jar") } // no need jackson, we jarjar it - ant.delete { fileset(dir: explodedDistLibDir, includes: "joda-*.jar") } // no need joda, we jarjar it - ant.delete { fileset(dir: explodedDistLibDir, includes: "snakeyaml-*.jar") } // no need snakeyaml, we jarjar it + ant.delete { fileset(dir: explodedDistLibDir, includes: "jarjar-*.jar") } // no need jackson, we jarjar it ant.delete { fileset(dir: explodedDistLibDir, includes: "sigar-*.jar") } // no need sigar directly under lib... - ant.delete { fileset(dir: explodedDistLibDir, includes: "netty-*.jar") } // no need netty directly under lib... - ant.delete { fileset(dir: explodedDistLibDir, includes: "mvel2-*.jar") } // no need mvel2 directly under lib... ant.chmod(dir: "$explodedDistDir/bin", perm: "ugo+rx", includes: "**/*") } diff --git a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/index/engine/SimpleEngineBenchmark.java b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/index/engine/SimpleEngineBenchmark.java index 18523305aa6..3834bc6aead 100644 --- a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/index/engine/SimpleEngineBenchmark.java +++ b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/index/engine/SimpleEngineBenchmark.java @@ -25,6 +25,8 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; +import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.deletionpolicy.KeepOnlyLastDeletionPolicy; @@ -42,14 +44,12 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.scaling.ScalingThreadPool; import org.elasticsearch.util.StopWatch; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.lucene.Lucene; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; /** * @author kimchy (Shay Banon) diff --git a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/index/store/SimpleStoreBenchmark.java b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/index/store/SimpleStoreBenchmark.java index ed9bd622200..94bb8b9059f 100644 --- a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/index/store/SimpleStoreBenchmark.java +++ b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/index/store/SimpleStoreBenchmark.java @@ -21,6 +21,7 @@ package org.elasticsearch.benchmark.index.store; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexOutput; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; @@ -34,7 +35,6 @@ import org.elasticsearch.index.store.ram.RamStore; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.StopWatch; -import org.elasticsearch.util.settings.Settings; import java.lang.management.ManagementFactory; import java.util.concurrent.CountDownLatch; @@ -42,8 +42,8 @@ import java.util.concurrent.CyclicBarrier; import java.util.concurrent.atomic.AtomicLong; import static java.util.concurrent.TimeUnit.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * @author kimchy diff --git a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/monitor/memory/SimpleMemoryMonitorBenchmark.java b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/monitor/memory/SimpleMemoryMonitorBenchmark.java index 606d245eef1..134be142b68 100644 --- a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/monitor/memory/SimpleMemoryMonitorBenchmark.java +++ b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/monitor/memory/SimpleMemoryMonitorBenchmark.java @@ -21,10 +21,10 @@ package org.elasticsearch.benchmark.monitor.memory; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.client.Client; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.node.Node; import org.elasticsearch.util.StopWatch; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Random; @@ -32,9 +32,9 @@ import java.util.concurrent.TimeUnit; import static org.elasticsearch.client.Requests.*; import static org.elasticsearch.cluster.metadata.IndexMetaData.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.node.NodeBuilder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; /** * @author kimchy (Shay Banon) diff --git a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/stress/NodesStressTest.java b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/stress/NodesStressTest.java index df6b31fcb01..4a963452b4b 100644 --- a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/stress/NodesStressTest.java +++ b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/stress/NodesStressTest.java @@ -22,12 +22,12 @@ package org.elasticsearch.benchmark.stress; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.xcontent.XContentQueryBuilder; import org.elasticsearch.node.Node; import org.elasticsearch.util.StopWatch; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.XContentFactory; import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; @@ -35,12 +35,12 @@ import java.util.concurrent.atomic.AtomicLong; import static org.elasticsearch.client.Requests.*; import static org.elasticsearch.cluster.metadata.IndexMetaData.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.elasticsearch.index.query.xcontent.FilterBuilders.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.node.NodeBuilder.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; /** * @author kimchy (shay.banon) diff --git a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/util/lucene/versioned/VersionedMapBenchmark.java b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/util/lucene/versioned/VersionedMapBenchmark.java index 4c34a6185f0..df91ccb584d 100644 --- a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/util/lucene/versioned/VersionedMapBenchmark.java +++ b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/util/lucene/versioned/VersionedMapBenchmark.java @@ -19,12 +19,12 @@ package org.elasticsearch.benchmark.util.lucene.versioned; +import org.elasticsearch.common.lucene.versioned.ConcurrentVersionedMap; +import org.elasticsearch.common.lucene.versioned.ConcurrentVersionedMapLong; +import org.elasticsearch.common.lucene.versioned.NativeVersionedMap; +import org.elasticsearch.common.lucene.versioned.VersionedMap; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.StopWatch; -import org.elasticsearch.util.lucene.versioned.ConcurrentVersionedMap; -import org.elasticsearch.util.lucene.versioned.ConcurrentVersionedMapLong; -import org.elasticsearch.util.lucene.versioned.NativeVersionedMap; -import org.elasticsearch.util.lucene.versioned.VersionedMap; import java.lang.management.ManagementFactory; import java.util.concurrent.CountDownLatch; diff --git a/modules/elasticsearch/build.gradle b/modules/elasticsearch/build.gradle index 2a45480af47..a41acee097b 100644 --- a/modules/elasticsearch/build.gradle +++ b/modules/elasticsearch/build.gradle @@ -5,6 +5,9 @@ apply plugin: 'maven' archivesBaseName = "$project.archivesBaseName" +// make sure we jarjar things before we compile Java +compileJava.dependsOn << ":jarjar:jar" + processResources.doLast { Properties versionProps = new Properties(); versionProps.setProperty("number", rootProject.version) @@ -22,27 +25,21 @@ sourceSets.main.resources.srcDirs 'src/main/java', rootProject.file('config') sourceSets.test.resources.srcDirs 'src/test/java' dependencies { + compile files(rootProject.jarjarArchivePath) + compile('jline:jline:0.9.94') { transitive = false } compile files(rootProject.file("lib/sigar/sigar-1.6.3.jar").absolutePath) + compile 'org.slf4j:slf4j-api:1.5.11' compile('org.slf4j:slf4j-log4j12:1.5.11') { transitive = false } compile('log4j:log4j:1.2.15') { transitive = false } - compile 'joda-time:joda-time:1.6' - - compile 'org.mvel:mvel2:2.0.17' - - compile 'org.codehaus.jackson:jackson-core-asl:1.5.2' - compile 'org.yaml:snakeyaml:1.6' - compile 'org.apache.lucene:lucene-core:3.0.1' compile 'org.apache.lucene:lucene-analyzers:3.0.1' compile 'org.apache.lucene:lucene-queries:3.0.1' compile 'org.apache.lucene:lucene-fast-vector-highlighter:3.0.1' - compile('org.jboss.netty:netty:3.2.0.CR1') { transitive = false } - testCompile project(':test-testng') testCompile('org.testng:testng:5.10:jdk15') { transitive = false } testCompile('org.hamcrest:hamcrest-all:1.1') { transitive = false } @@ -55,7 +52,6 @@ configurations { dependencies { deployerJars "org.apache.maven.wagon:wagon-http:1.0-beta-2" - tools "com.google.code:jarjar:1.0" } jar { @@ -66,39 +62,14 @@ jar { } jar << { - jarjarArchivePath = new File(jar.archivePath.absolutePath + ".jarjar.jar") + mergedArchivePath = new File(jar.archivePath.absolutePath + ".merged.jar") project.ant { - taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask", classpath: configurations.tools.asPath - jarjar(jarfile: jarjarArchivePath) { - zipfileset(src: jar.archivePath) - configurations.compile.files.findAll {file -> - ['mvel', 'jackson', 'joda', 'snakeyaml', 'netty'].any { file.name.contains(it) } - }.each { jarjarFile -> - zipfileset(src: jarjarFile) { - exclude(name: "META-INF/**") - } - } - rule pattern: "org.mvel2.**", result: "org.elasticsearch.util.mvel2.@1" - rule pattern: "org.codehaus.jackson.**", result: "org.elasticsearch.util.jackson.@1" - rule pattern: "org.joda.**", result: "org.elasticsearch.util.joda.@1" - rule pattern: "org.yaml.**", result: "org.elasticsearch.util.yaml.@1" - rule pattern: "org.jboss.netty.**", result: "org.elasticsearch.util.netty.@1" + jar(destfile: mergedArchivePath) { + zipFileSet(src: jar.archivePath) + zipFileSet(src: rootProject.jarjarArchivePath) } delete(file: jar.archivePath) - copy(file: jarjarArchivePath, tofile: jar.archivePath) - delete(file: jarjarArchivePath) - - // seems like empty dirst still exists, unjar and clean them - unjar(src: jar.archivePath, dest: "build/tmp/extracted") - delete(dir: "build/tmp/extracted/org/codehaus") - delete(dir: "build/tmp/extracted/org/mvel2") - delete(dir: "build/tmp/extracted/org/joda") - delete(dir: "build/tmp/extracted/org/yaml") - delete(dir: "build/tmp/extracted/org/jboss") - - delete(file: jar.archivePath) - jar(destfile: jar.archivePath, basedir: "build/tmp/extracted") - delete(dir: "build/tmp/extracted") + move(file: mergedArchivePath, tofile: jar.archivePath) } } @@ -159,14 +130,10 @@ uploadArchives { pom.whenConfigured {pom -> pom.dependencies = pom.dependencies.findAll {dep -> dep.scope != 'test' } // removes the test scoped ones + pom.dependencies = pom.dependencies.findAll {dep -> !dep.artifactId.contains('jarjar') } pom.dependencies = pom.dependencies.findAll {dep -> !dep.artifactId.contains('log4j') } pom.dependencies = pom.dependencies.findAll {dep -> !dep.artifactId.contains('slf4j') } pom.dependencies = pom.dependencies.findAll {dep -> !dep.artifactId.contains('jline') } - pom.dependencies = pom.dependencies.findAll {dep -> !dep.artifactId.contains('jackson') } - pom.dependencies = pom.dependencies.findAll {dep -> !dep.artifactId.contains('joda') } - pom.dependencies = pom.dependencies.findAll {dep -> !dep.artifactId.contains('snakeyaml') } - pom.dependencies = pom.dependencies.findAll {dep -> !dep.artifactId.contains('netty') } - pom.dependencies = pom.dependencies.findAll {dep -> !dep.artifactId.contains('mvel') } } } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java b/modules/elasticsearch/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java index 62cef1bdb34..d0c5b49a74a 100644 --- a/modules/elasticsearch/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java +++ b/modules/elasticsearch/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java @@ -23,8 +23,8 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.search.*; import org.apache.lucene.search.spans.SpanTermQuery; -import org.elasticsearch.util.lucene.search.TermFilter; -import org.elasticsearch.util.lucene.search.function.FunctionScoreQuery; +import org.elasticsearch.common.lucene.search.TermFilter; +import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import java.io.IOException; import java.lang.reflect.Field; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/ExceptionsHelper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/ExceptionsHelper.java index b682eb8736a..1bc8ebdcee5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/ExceptionsHelper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/ExceptionsHelper.java @@ -19,8 +19,8 @@ package org.elasticsearch; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java index 7977fe953b1..f60f217836b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java @@ -54,7 +54,7 @@ import org.elasticsearch.action.search.TransportSearchAction; import org.elasticsearch.action.search.TransportSearchScrollAction; import org.elasticsearch.action.search.type.*; import org.elasticsearch.action.terms.TransportTermsAction; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java index cf22443083e..9dff6d5b6e6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java @@ -20,8 +20,8 @@ package org.elasticsearch.action.admin.cluster.health; import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.Maps; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.collect.Maps; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; import static org.elasticsearch.action.admin.cluster.health.ClusterIndexHealth.*; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterIndexHealth.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterIndexHealth.java index fda47454a98..eda2944b57c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterIndexHealth.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterIndexHealth.java @@ -19,8 +19,8 @@ package org.elasticsearch.action.admin.cluster.health; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.Maps; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.collect.Maps; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java index 7d0f37c1c10..166cae26ade 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -30,11 +30,11 @@ import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RoutingTableValidation; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.timer.TimerService; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java index c35e94ee7cd..575697f71e8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java @@ -21,17 +21,17 @@ package org.elasticsearch.action.admin.cluster.node.info; import org.elasticsearch.action.support.nodes.NodeOperationResponse; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.monitor.network.NetworkInfo; import org.elasticsearch.monitor.os.OsInfo; import org.elasticsearch.monitor.process.ProcessInfo; import org.elasticsearch.threadpool.ThreadPoolInfo; import org.elasticsearch.transport.TransportInfo; -import org.elasticsearch.util.collect.ImmutableMap; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java index 18e8f5bc5f2..dd35e95fca7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java @@ -25,13 +25,13 @@ import org.elasticsearch.action.support.nodes.NodeOperationRequest; import org.elasticsearch.action.support.nodes.TransportNodesOperationAction; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.MonitorService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.MapBuilder; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.ArrayList; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/TransportNodesRestartAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/TransportNodesRestartAction.java index 44915fe605e..7776a7f6767 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/TransportNodesRestartAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/restart/TransportNodesRestartAction.java @@ -26,14 +26,14 @@ import org.elasticsearch.action.support.nodes.NodeOperationRequest; import org.elasticsearch.action.support.nodes.TransportNodesOperationAction; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.List; @@ -41,8 +41,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReferenceArray; +import static org.elasticsearch.common.collect.Lists.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java index 16ad20f02b9..9e619ffe1bc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java @@ -26,21 +26,21 @@ import org.elasticsearch.action.support.nodes.NodeOperationRequest; import org.elasticsearch.action.support.nodes.TransportNodesOperationAction; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; +import static org.elasticsearch.common.collect.Lists.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java index 50874b0b920..dbac1447c7c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/TransportNodesStatsAction.java @@ -25,12 +25,12 @@ import org.elasticsearch.action.support.nodes.NodeOperationRequest; import org.elasticsearch.action.support.nodes.TransportNodesOperationAction; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.MonitorService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/broadcast/TransportBroadcastPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/broadcast/TransportBroadcastPingAction.java index 1dff6118ff3..2088a851e98 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/broadcast/TransportBroadcastPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/broadcast/TransportBroadcastPingAction.java @@ -29,16 +29,16 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportIndexReplicationPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportIndexReplicationPingAction.java index 3e0f5749f97..750c47cff8c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportIndexReplicationPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportIndexReplicationPingAction.java @@ -23,12 +23,12 @@ import org.elasticsearch.action.support.replication.TransportIndexReplicationOpe import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.IndexRoutingTable; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportReplicationPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportReplicationPingAction.java index 8cabaaf9d21..b639a6d4c51 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportReplicationPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportReplicationPingAction.java @@ -22,10 +22,10 @@ package org.elasticsearch.action.admin.cluster.ping.replication; import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.replication.TransportIndicesReplicationOperationAction; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportShardReplicationPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportShardReplicationPingAction.java index cb5940951a7..8f7612be087 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportShardReplicationPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/replication/TransportShardReplicationPingAction.java @@ -24,11 +24,11 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.action.shard.ShardStateAction; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/single/TransportSinglePingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/single/TransportSinglePingAction.java index 81a620a4615..ebab4d15ae6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/single/TransportSinglePingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/ping/single/TransportSinglePingAction.java @@ -23,11 +23,11 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.single.TransportSingleOperationAction; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java index 5a60551e0c7..a0ba98c4022 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java @@ -24,10 +24,10 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java index 0eacbaa4434..0790f3e15f2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java @@ -22,7 +22,7 @@ package org.elasticsearch.action.admin.indices.alias; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeOperationRequest; import org.elasticsearch.cluster.metadata.AliasAction; -import org.elasticsearch.util.collect.Lists; +import org.elasticsearch.common.collect.Lists; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java index 259fd5655aa..488f1bf285b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java @@ -24,10 +24,10 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaDataService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java index ba5a9f1bce1..13a4dd87cd6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java @@ -29,17 +29,17 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * Indices clear cache action. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java index b972a7efb6e..4997870cee8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java @@ -23,30 +23,30 @@ import org.elasticsearch.ElasticSearchGenerationException; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeOperationRequest; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.TextXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.TextXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; import java.util.concurrent.TimeUnit; import static org.elasticsearch.action.Actions.*; +import static org.elasticsearch.common.collect.Maps.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.collect.Maps.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; /** * A request to create an index. Best created with {@link org.elasticsearch.client.Requests#createIndexRequest(String)}. * - *

The index created can optionally be created with {@link #settings(org.elasticsearch.util.settings.Settings)}. + *

The index created can optionally be created with {@link #settings(org.elasticsearch.common.settings.Settings)}. * * @author kimchy (shay.banon) * @see org.elasticsearch.client.IndicesAdminClient#create(CreateIndexRequest) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java index b155739daad..be9e34a3484 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java @@ -24,10 +24,10 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaDataService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * Create index action. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java index e7ff281034c..78b3b318981 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java @@ -24,10 +24,10 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaDataService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * Delete index action. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportFlushAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportFlushAction.java index 2624efe39df..76e7d485292 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportFlushAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportFlushAction.java @@ -29,18 +29,18 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * Flush Action. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportGatewaySnapshotAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportGatewaySnapshotAction.java index 8977f6105c9..fc5780f9d36 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportGatewaySnapshotAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportGatewaySnapshotAction.java @@ -22,10 +22,10 @@ package org.elasticsearch.action.admin.indices.gateway.snapshot; import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.replication.TransportIndicesReplicationOperationAction; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportIndexGatewaySnapshotAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportIndexGatewaySnapshotAction.java index d1304b555e3..51021f89348 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportIndexGatewaySnapshotAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportIndexGatewaySnapshotAction.java @@ -23,12 +23,12 @@ import org.elasticsearch.action.support.replication.TransportIndexReplicationOpe import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.IndexRoutingTable; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportShardGatewaySnapshotAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportShardGatewaySnapshotAction.java index 990dd1247d7..c54b489d6dd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportShardGatewaySnapshotAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/gateway/snapshot/TransportShardGatewaySnapshotAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.action.shard.ShardStateAction; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.gateway.IndexShardGatewayService; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java index ba4883fd2c8..54ec443b13c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -23,14 +23,14 @@ import org.elasticsearch.ElasticSearchGenerationException; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeOperationRequest; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.TextXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.Required; import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.TextXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java index ec41b4a1017..6c9dda4139c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java @@ -25,10 +25,10 @@ import org.elasticsearch.action.support.master.TransportMasterNodeOperationActio import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.MetaDataService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * Put mapping action. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/optimize/TransportOptimizeAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/optimize/TransportOptimizeAction.java index d0716c000e8..a0b23656baf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/optimize/TransportOptimizeAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/optimize/TransportOptimizeAction.java @@ -29,18 +29,18 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * Optimize index/indices action. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java index 61d80cedf6e..e1cea0edde3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportRefreshAction.java @@ -29,18 +29,18 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * Refresh action. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexShardStatus.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexShardStatus.java index d071f7fdd35..1fef3d7bfe0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexShardStatus.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexShardStatus.java @@ -19,9 +19,9 @@ package org.elasticsearch.action.admin.indices.status; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.collect.Iterators; import java.util.Iterator; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexStatus.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexStatus.java index 5674d2d57cb..3eced7b0bee 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexStatus.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndexStatus.java @@ -19,15 +19,15 @@ package org.elasticsearch.action.admin.indices.status; +import org.elasticsearch.common.collect.Maps; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.settings.Settings; import java.util.Iterator; import java.util.List; import java.util.Map; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusResponse.java index 440a2aaca9a..4358267f08e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/IndicesStatusResponse.java @@ -22,19 +22,19 @@ package org.elasticsearch.action.admin.indices.status; import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.util.collect.ImmutableMap; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.List; import java.util.Map; import static org.elasticsearch.action.admin.indices.status.ShardStatus.*; -import static org.elasticsearch.util.collect.Lists.*; -import static org.elasticsearch.util.collect.Maps.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Maps.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java index 9df9794efd8..a6cd091cbca 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java @@ -30,19 +30,19 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.service.InternalIndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java index 5486e18a173..25bd1eeff8e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/CountRequest.java @@ -26,6 +26,10 @@ import org.elasticsearch.action.Actions; import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Requests; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.util.Required; import org.elasticsearch.util.Strings; @@ -33,10 +37,6 @@ import org.elasticsearch.util.Unicode; import org.elasticsearch.util.io.FastByteArrayOutputStream; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Arrays; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/TransportCountAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/TransportCountAction.java index 71e77148534..90d7fdd1591 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/TransportCountAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/count/TransportCountAction.java @@ -29,17 +29,17 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.List; import java.util.concurrent.atomic.AtomicReferenceArray; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/delete/TransportDeleteAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/delete/TransportDeleteAction.java index d2d7992e797..366e8a8ef16 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/delete/TransportDeleteAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/delete/TransportDeleteAction.java @@ -30,12 +30,12 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.action.shard.ShardStateAction; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * Performs the delete operation. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java index 9ac1afa4b2d..a4a3b3e6929 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java @@ -25,6 +25,10 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.replication.IndicesReplicationOperationRequest; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.Requests; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.util.Required; import org.elasticsearch.util.Strings; @@ -33,10 +37,6 @@ import org.elasticsearch.util.Unicode; import org.elasticsearch.util.io.FastByteArrayOutputStream; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Arrays; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryResponse.java index 348eccff2a1..9d2ba6ba4d8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryResponse.java @@ -28,7 +28,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.Map; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Maps.*; /** * The response of delete by query action. Holds the {@link IndexDeleteByQueryResponse}s from all the diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java index 44a5ba6329e..a92421277e6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java @@ -22,10 +22,10 @@ package org.elasticsearch.action.deletebyquery; import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.replication.TransportIndicesReplicationOperationAction; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportIndexDeleteByQueryAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportIndexDeleteByQueryAction.java index d69e60c85cb..3fcde407dee 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportIndexDeleteByQueryAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportIndexDeleteByQueryAction.java @@ -22,11 +22,11 @@ package org.elasticsearch.action.deletebyquery; import org.elasticsearch.action.support.replication.TransportIndexReplicationOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.routing.GroupShardsIterator; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportShardDeleteByQueryAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportShardDeleteByQueryAction.java index 85529d44f10..5a0993f229c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportShardDeleteByQueryAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/deletebyquery/TransportShardDeleteByQueryAction.java @@ -26,11 +26,11 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.action.shard.ShardStateAction; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/GetResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/GetResponse.java index daaaa87c76e..c3e401d75ee 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/GetResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/GetResponse.java @@ -21,21 +21,21 @@ package org.elasticsearch.action.get; import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.collect.ImmutableMap; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; import java.io.IOException; import java.util.Iterator; import java.util.Map; import static org.elasticsearch.action.get.GetField.*; -import static org.elasticsearch.util.collect.Iterators.*; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Iterators.*; +import static org.elasticsearch.common.collect.Maps.*; /** * The response of a get action. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/TransportGetAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/TransportGetAction.java index 608d253b3cf..b325148c4e0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/TransportGetAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/get/TransportGetAction.java @@ -26,6 +26,9 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.support.single.TransportSingleOperationAction; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.service.IndexService; @@ -33,15 +36,12 @@ import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.lucene.Lucene; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.ArrayList; import java.util.Map; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Maps.*; /** * Performs the get operation. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexRequest.java index 832623d7f4a..7e0b60a4635 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -25,15 +25,15 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.action.support.replication.ShardReplicationOperationRequest; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.Required; import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.Unicode; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Arrays; @@ -49,8 +49,8 @@ import static org.elasticsearch.action.Actions.*; * {@link #source(byte[])} to be set. * *

The source (content to index) can be set in its bytes form using ({@link #source(byte[])}), - * its string form ({@link #source(String)}) or using a {@link org.elasticsearch.util.xcontent.builder.XContentBuilder} - * ({@link #source(org.elasticsearch.util.xcontent.builder.XContentBuilder)}). + * its string form ({@link #source(String)}) or using a {@link org.elasticsearch.common.xcontent.builder.XContentBuilder} + * ({@link #source(org.elasticsearch.common.xcontent.builder.XContentBuilder)}). * *

If the {@link #id(String)} is not set, it will be automatically generated. * @@ -249,7 +249,7 @@ public class IndexRequest extends ShardReplicationOperationRequest { /** * Sets the document source to index. * - *

Note, its preferable to either set it using {@link #source(org.elasticsearch.util.xcontent.builder.XContentBuilder)} + *

Note, its preferable to either set it using {@link #source(org.elasticsearch.common.xcontent.builder.XContentBuilder)} * or using the {@link #source(byte[])}. */ @Required public IndexRequest source(String source) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/TransportIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/TransportIndexAction.java index fb73c5104ae..95177935b06 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/TransportIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/TransportIndexAction.java @@ -31,6 +31,8 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.action.index.MappingUpdatedAction; import org.elasticsearch.cluster.action.shard.ShardStateAction; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.indices.IndexAlreadyExistsException; @@ -38,8 +40,6 @@ import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.UUID; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * Performs the index operation. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequest.java index f79da0cf995..abc44f7ec11 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisRequest.java @@ -27,6 +27,10 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.Actions; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.client.Requests; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.util.Bytes; @@ -36,10 +40,6 @@ import org.elasticsearch.util.Unicode; import org.elasticsearch.util.io.FastByteArrayOutputStream; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Arrays; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java index 67576499ebe..43a45bf784f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/mlt/TransportMoreLikeThisAction.java @@ -34,6 +34,8 @@ import org.elasticsearch.action.search.TransportSearchAction; import org.elasticsearch.action.support.BaseAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.query.xcontent.BoolQueryBuilder; import org.elasticsearch.index.query.xcontent.MoreLikeThisFieldQueryBuilder; @@ -41,17 +43,15 @@ import org.elasticsearch.indices.IndicesService; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.Collections; import java.util.Iterator; import java.util.Set; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.collect.Sets.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; -import static org.elasticsearch.util.collect.Sets.*; /** * The more like this action. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchRequest.java index 5adbfd47325..e884d97a3e1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -25,6 +25,10 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.client.Requests; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.util.Bytes; @@ -34,10 +38,6 @@ import org.elasticsearch.util.Unicode; import org.elasticsearch.util.io.FastByteArrayOutputStream; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Arrays; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchResponse.java index cc54b34c95f..7aeec7d23ec 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchResponse.java @@ -20,13 +20,13 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.facets.Facets; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index 3ada696d196..14c58f3cc89 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -26,11 +26,11 @@ import org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchActi import org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction; import org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction; import org.elasticsearch.action.support.BaseAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import static org.elasticsearch.action.search.SearchType.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/TransportSearchScrollAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/TransportSearchScrollAction.java index 9b4ab61be53..7bd8b30ebe4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/TransportSearchScrollAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/TransportSearchScrollAction.java @@ -26,11 +26,11 @@ import org.elasticsearch.action.search.type.ParsedScrollId; import org.elasticsearch.action.search.type.TransportSearchScrollQueryAndFetchAction; import org.elasticsearch.action.search.type.TransportSearchScrollQueryThenFetchAction; import org.elasticsearch.action.support.BaseAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import static org.elasticsearch.action.search.type.ParsedScrollId.*; import static org.elasticsearch.action.search.type.TransportSearchHelper.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java index e3ab0f402eb..a6d4e13212a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java @@ -24,6 +24,8 @@ import org.elasticsearch.action.search.*; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.action.SearchServiceListener; @@ -36,8 +38,6 @@ import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.search.query.QuerySearchRequest; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.Collection; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java index bf997b8a1cb..839c6929d63 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java @@ -24,6 +24,9 @@ import org.elasticsearch.action.search.*; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.trove.ExtTIntArrayList; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.action.SearchServiceListener; @@ -39,9 +42,6 @@ import org.elasticsearch.search.query.QuerySearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.trove.ExtTIntArrayList; import java.util.Collection; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java index c3ab0539944..4ac8f9074ab 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryAndFetchAction.java @@ -25,6 +25,8 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.action.SearchServiceListener; @@ -34,8 +36,6 @@ import org.elasticsearch.search.fetch.QueryFetchSearchResult; import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java index 0e96f2fdddd..8916a920a58 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java @@ -24,6 +24,9 @@ import org.elasticsearch.action.search.*; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.trove.ExtTIntArrayList; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.action.SearchServiceListener; @@ -36,9 +39,6 @@ import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.trove.ExtTIntArrayList; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryAndFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryAndFetchAction.java index 3f255956790..8f057dcb375 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryAndFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryAndFetchAction.java @@ -24,6 +24,9 @@ import org.elasticsearch.action.search.*; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.action.SearchServiceListener; import org.elasticsearch.search.action.SearchServiceTransportAction; @@ -33,9 +36,6 @@ import org.elasticsearch.search.fetch.QueryFetchSearchResult; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.Collection; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryThenFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryThenFetchAction.java index 2f15fa9eedb..39848fa304b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryThenFetchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchScrollQueryThenFetchAction.java @@ -24,6 +24,10 @@ import org.elasticsearch.action.search.*; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.trove.ExtTIntArrayList; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.action.SearchServiceListener; import org.elasticsearch.search.action.SearchServiceTransportAction; @@ -36,10 +40,6 @@ import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.trove.ExtTIntArrayList; import java.util.Collection; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java index c45ae9cae2f..350a656a505 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java @@ -29,6 +29,8 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.trove.ExtTIntArrayList; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.action.SearchServiceListener; @@ -38,8 +40,6 @@ import org.elasticsearch.search.controller.ShardDoc; import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.trove.ExtTIntArrayList; import java.util.Arrays; import java.util.Collection; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/AbstractListenableActionFuture.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/AbstractListenableActionFuture.java index d6e9b6203fa..9492c69b9f1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/AbstractListenableActionFuture.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/AbstractListenableActionFuture.java @@ -22,8 +22,8 @@ package org.elasticsearch.action.support; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ListenableActionFuture; +import org.elasticsearch.common.collect.Lists; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.collect.Lists; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/BaseAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/BaseAction.java index 72614187cbc..7b64833b8bc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/BaseAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/BaseAction.java @@ -21,8 +21,8 @@ package org.elasticsearch.action.support; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.*; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; import static org.elasticsearch.action.support.PlainActionFuture.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationResponse.java index 338d9becab2..f260bbe407d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationResponse.java @@ -21,7 +21,7 @@ package org.elasticsearch.action.support.broadcast; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ShardOperationFailedException; -import org.elasticsearch.util.collect.ImmutableList; +import org.elasticsearch.common.collect.ImmutableList; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastOperationAction.java index 2e28bdf22a6..b62cd5c80b8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastOperationAction.java @@ -29,24 +29,24 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; -import org.elasticsearch.util.collect.ImmutableList; import org.elasticsearch.util.io.ThrowableObjectInputStream; import org.elasticsearch.util.io.ThrowableObjectOutputStream; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceArray; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java index 8928a5b6ac6..b57a4401d2c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeOperationAction.java @@ -25,9 +25,9 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.BaseAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; -import org.elasticsearch.util.settings.Settings; /** * A base class for operations that needs to be performed on the master node. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationResponse.java index 09bf4b1d5cd..00a39b7f618 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationResponse.java @@ -21,7 +21,7 @@ package org.elasticsearch.action.support.nodes; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.util.collect.Maps; +import org.elasticsearch.common.collect.Maps; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesOperationAction.java index 804a5412de5..89b48eaa363 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesOperationAction.java @@ -28,10 +28,10 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportIndexReplicationOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportIndexReplicationOperationAction.java index 584956d1279..272b4c705fc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportIndexReplicationOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportIndexReplicationOperationAction.java @@ -25,12 +25,12 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.BaseAction; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportIndicesReplicationOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportIndicesReplicationOperationAction.java index 5095d6c4e24..16bf6f55446 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportIndicesReplicationOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportIndicesReplicationOperationAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.BaseAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceArray; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java index eac23738a49..249c8d3047c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java @@ -33,6 +33,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexShardMissingException; import org.elasticsearch.index.shard.IllegalIndexShardStateException; import org.elasticsearch.index.shard.IndexShardNotStartedException; @@ -46,7 +47,6 @@ import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.VoidStreamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/single/TransportSingleOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/single/TransportSingleOperationAction.java index 2f658c1057a..24c5ee0e267 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/single/TransportSingleOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/single/TransportSingleOperationAction.java @@ -30,13 +30,13 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/FieldTermsFreq.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/FieldTermsFreq.java index af2aa882434..d165b1f0916 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/FieldTermsFreq.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/FieldTermsFreq.java @@ -19,11 +19,11 @@ package org.elasticsearch.action.terms; -import org.elasticsearch.util.collect.Iterators; +import org.elasticsearch.common.collect.Iterators; +import org.elasticsearch.common.trove.ExtTObjectIntHasMap; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.trove.ExtTObjectIntHasMap; import java.io.IOException; import java.util.Iterator; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/ShardTermsResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/ShardTermsResponse.java index f890085c6fb..cf80203a398 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/ShardTermsResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/ShardTermsResponse.java @@ -20,11 +20,11 @@ package org.elasticsearch.action.terms; import org.elasticsearch.action.support.broadcast.BroadcastShardOperationResponse; -import org.elasticsearch.util.gnu.trove.TObjectIntHashMap; -import org.elasticsearch.util.gnu.trove.TObjectIntIterator; +import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.trove.TObjectIntHashMap; +import org.elasticsearch.common.trove.TObjectIntIterator; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.lucene.Lucene; import java.io.IOException; import java.util.HashMap; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TermFreq.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TermFreq.java index 04d17fb936a..54bde39d2c9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TermFreq.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TermFreq.java @@ -19,10 +19,10 @@ package org.elasticsearch.action.terms; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.lucene.Lucene; import java.io.IOException; import java.util.Comparator; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TermsResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TermsResponse.java index c3b5ba3ef4b..58a1e9932c1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TermsResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TermsResponse.java @@ -21,7 +21,7 @@ package org.elasticsearch.action.terms; import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse; -import org.elasticsearch.util.collect.Iterators; +import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TransportTermsAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TransportTermsAction.java index f8887aa8892..645c664967c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TransportTermsAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/terms/TransportTermsAction.java @@ -34,6 +34,11 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.collect.Maps; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.trove.TObjectIntHashMap; +import org.elasticsearch.common.trove.TObjectIntIterator; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.service.IndexService; @@ -42,11 +47,6 @@ import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.BoundedTreeSet; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.gnu.trove.TObjectIntHashMap; -import org.elasticsearch.util.gnu.trove.TObjectIntIterator; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import javax.annotation.Nullable; import java.io.IOException; @@ -54,7 +54,7 @@ import java.util.*; import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.regex.Pattern; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index a27b9753f91..71eb8579a25 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -21,6 +21,12 @@ package org.elasticsearch.bootstrap; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; +import org.elasticsearch.common.inject.CreationException; +import org.elasticsearch.common.inject.spi.Message; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.logging.log4j.LogConfigurator; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.jmx.JmxService; import org.elasticsearch.node.Node; @@ -28,22 +34,16 @@ import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.node.internal.InternalSettingsPerparer; import org.elasticsearch.util.Classes; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.inject.CreationException; -import org.elasticsearch.util.inject.spi.Message; import org.elasticsearch.util.jline.ANSI; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.logging.log4j.LogConfigurator; -import org.elasticsearch.util.settings.Settings; import java.io.File; import java.util.Set; import java.util.concurrent.CountDownLatch; import static jline.ANSIBuffer.ANSICodes.*; -import static org.elasticsearch.util.collect.Sets.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.collect.Sets.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * A main entry point when starting from the command line. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cache/NodeCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cache/NodeCache.java index c391487632f..160547de138 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cache/NodeCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cache/NodeCache.java @@ -19,9 +19,9 @@ package org.elasticsearch.cache; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cache/NodeCacheModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cache/NodeCacheModule.java index 1c14ec9e3c4..3bcda776e23 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cache/NodeCacheModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cache/NodeCacheModule.java @@ -19,7 +19,7 @@ package org.elasticsearch.cache; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java index 4d7dfa53fbc..728c5491905 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java @@ -47,7 +47,7 @@ import org.elasticsearch.action.mlt.MoreLikeThisRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchScrollRequest; import org.elasticsearch.action.terms.TermsRequest; -import org.elasticsearch.util.xcontent.XContentType; +import org.elasticsearch.common.xcontent.XContentType; /** * A handy one stop shop for creating requests (make sure to import static this class). diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/create/CreateIndexRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/create/CreateIndexRequestBuilder.java index 737daa37276..3998422cce6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/create/CreateIndexRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/create/CreateIndexRequestBuilder.java @@ -25,9 +25,9 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.support.PlainListenableActionFuture; import org.elasticsearch.client.internal.InternalIndicesAdminClient; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/mapping/put/PutMappingRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/mapping/put/PutMappingRequestBuilder.java index 183129fe941..a06772b91d0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/mapping/put/PutMappingRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/mapping/put/PutMappingRequestBuilder.java @@ -25,8 +25,8 @@ import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.support.PlainListenableActionFuture; import org.elasticsearch.client.internal.InternalIndicesAdminClient; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/deletebyquery/DeleteByQueryRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/deletebyquery/DeleteByQueryRequestBuilder.java index 76fbab5e78a..e0d374ec5de 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/deletebyquery/DeleteByQueryRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/deletebyquery/DeleteByQueryRequestBuilder.java @@ -26,9 +26,9 @@ import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; import org.elasticsearch.action.support.PlainListenableActionFuture; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.internal.InternalClient; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/index/IndexRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/index/IndexRequestBuilder.java index f862563210b..88d10c1a31d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/index/IndexRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/index/IndexRequestBuilder.java @@ -26,9 +26,9 @@ import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.support.PlainListenableActionFuture; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.internal.InternalClient; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import javax.annotation.Nullable; import java.util.Map; @@ -97,7 +97,7 @@ public class IndexRequestBuilder { /** * Sets the document source to index. * - *

Note, its preferable to either set it using {@link #setSource(org.elasticsearch.util.xcontent.builder.XContentBuilder)} + *

Note, its preferable to either set it using {@link #setSource(org.elasticsearch.common.xcontent.builder.XContentBuilder)} * or using the {@link #setSource(byte[])}. */ public IndexRequestBuilder setSource(String source) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java index 49aeca56720..a14316c3ca5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java @@ -22,9 +22,9 @@ package org.elasticsearch.client.node; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClient.java index abb8626935d..0cb91caf866 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClient.java @@ -45,9 +45,9 @@ import org.elasticsearch.action.terms.TransportTermsAction; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.internal.InternalClient; import org.elasticsearch.client.support.AbstractClient; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClientModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClientModule.java index d0be5e31a65..d794bbb0680 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClientModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClientModule.java @@ -23,7 +23,7 @@ import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java index fb52ded7c70..abec093206b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java @@ -50,9 +50,9 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.admin.cluster.state.TransportClusterStateAction; import org.elasticsearch.client.internal.InternalClusterAdminClient; import org.elasticsearch.client.support.AbstractClusterAdminClient; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java index 295403fe624..585e1edb438 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java @@ -53,9 +53,9 @@ import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse; import org.elasticsearch.action.admin.indices.status.TransportIndicesStatusAction; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.support.AbstractIndicesAdminClient; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java index 4b096e453ae..1cbd994322a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java @@ -23,7 +23,7 @@ import org.elasticsearch.client.transport.support.InternalTransportAdminClient; import org.elasticsearch.client.transport.support.InternalTransportClient; import org.elasticsearch.client.transport.support.InternalTransportClusterAdminClient; import org.elasticsearch.client.transport.support.InternalTransportIndicesAdminClient; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 5881cc523b6..0074556d11f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -44,6 +44,15 @@ import org.elasticsearch.client.transport.action.ClientTransportActionModule; import org.elasticsearch.client.transport.support.InternalTransportClient; import org.elasticsearch.cluster.ClusterNameModule; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.inject.Guice; +import org.elasticsearch.common.inject.Injector; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.network.NetworkModule; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsModule; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.env.Environment; import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.monitor.MonitorService; @@ -56,23 +65,14 @@ import org.elasticsearch.transport.TransportModule; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.ThreadLocals; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.inject.Guice; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.network.NetworkModule; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsModule; -import org.elasticsearch.util.transport.TransportAddress; import java.util.ArrayList; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * The transport client allows to create a client that is not part of the cluster, but simply connects to one - * or more nodes directly by adding their respective addresses using {@link #addTransportAddress(org.elasticsearch.util.transport.TransportAddress)}. + * or more nodes directly by adding their respective addresses using {@link #addTransportAddress(org.elasticsearch.common.transport.TransportAddress)}. * *

The transport client important modules used is the {@link org.elasticsearch.transport.TransportModule} which is * started in client mode (only connects, no bind). @@ -157,7 +157,7 @@ public class TransportClient extends AbstractClient { /** * Returns the current registered transport addresses to use (added using - * {@link #addTransportAddress(org.elasticsearch.util.transport.TransportAddress)}. + * {@link #addTransportAddress(org.elasticsearch.common.transport.TransportAddress)}. */ public ImmutableList transportAddresses() { return nodesService.transportAddresses(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientClusterModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientClusterModule.java index c978cd6b0b3..399668f5a8b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientClusterModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientClusterModule.java @@ -21,11 +21,11 @@ package org.elasticsearch.client.transport; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.service.InternalClusterService; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.NoClassSettingsException; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryModule; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.settings.NoClassSettingsException; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientClusterService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientClusterService.java index 383330aab00..ea2b503c000 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientClusterService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientClusterService.java @@ -20,10 +20,10 @@ package org.elasticsearch.client.transport; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryService; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java index 32294f6ec09..35a968c0978 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java @@ -28,17 +28,17 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BaseTransportResponseHandler; import org.elasticsearch.transport.ConnectTransportException; import org.elasticsearch.transport.RemoteTransportException; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.transport.TransportAddress; import java.util.HashSet; import java.util.concurrent.CopyOnWriteArrayList; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java index 1addf16d34f..12a25334055 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java @@ -46,7 +46,7 @@ import org.elasticsearch.client.transport.action.index.ClientTransportIndexActio import org.elasticsearch.client.transport.action.search.ClientTransportSearchAction; import org.elasticsearch.client.transport.action.search.ClientTransportSearchScrollAction; import org.elasticsearch.client.transport.action.terms.ClientTransportTermsAction; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/health/ClientTransportClusterHealthAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/health/ClientTransportClusterHealthAction.java index 6466ba27a8c..24ba1fd32c1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/health/ClientTransportClusterHealthAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/health/ClientTransportClusterHealthAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/info/ClientTransportNodesInfoAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/info/ClientTransportNodesInfoAction.java index ae62cf8ea3a..550e96da187 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/info/ClientTransportNodesInfoAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/info/ClientTransportNodesInfoAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/restart/ClientTransportNodesRestartAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/restart/ClientTransportNodesRestartAction.java index 4c38c60a6aa..fd156d2e519 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/restart/ClientTransportNodesRestartAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/restart/ClientTransportNodesRestartAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartRequest; import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/shutdown/ClientTransportNodesShutdownAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/shutdown/ClientTransportNodesShutdownAction.java index 8df2294fa25..f238f7c0790 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/shutdown/ClientTransportNodesShutdownAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/shutdown/ClientTransportNodesShutdownAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRequest; import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/stats/ClientTransportNodesStatsAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/stats/ClientTransportNodesStatsAction.java index 46a138b49de..fafdef3f8b5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/stats/ClientTransportNodesStatsAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/node/stats/ClientTransportNodesStatsAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/broadcast/ClientTransportBroadcastPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/broadcast/ClientTransportBroadcastPingAction.java index d4e5e0987f8..f823b537fc0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/broadcast/ClientTransportBroadcastPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/broadcast/ClientTransportBroadcastPingAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingRequest; import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/replication/ClientTransportReplicationPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/replication/ClientTransportReplicationPingAction.java index 49e5f8b5f51..92f7e7e1b29 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/replication/ClientTransportReplicationPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/replication/ClientTransportReplicationPingAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingRequest; import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/single/ClientTransportSinglePingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/single/ClientTransportSinglePingAction.java index 05420734133..ad515332e7e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/single/ClientTransportSinglePingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/ping/single/ClientTransportSinglePingAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java index 9af320d4f26..1249cb5efd6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/alias/ClientTransportIndicesAliasesAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/alias/ClientTransportIndicesAliasesAction.java index 5815ba5e40e..a7c20de919f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/alias/ClientTransportIndicesAliasesAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/alias/ClientTransportIndicesAliasesAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/cache/clear/ClientTransportClearIndicesCacheAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/cache/clear/ClientTransportClearIndicesCacheAction.java index 9f826390ed1..bab0a026078 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/cache/clear/ClientTransportClearIndicesCacheAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/cache/clear/ClientTransportClearIndicesCacheAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/create/ClientTransportCreateIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/create/ClientTransportCreateIndexAction.java index aa27c12045d..61c106826c9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/create/ClientTransportCreateIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/create/ClientTransportCreateIndexAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/delete/ClientTransportDeleteIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/delete/ClientTransportDeleteIndexAction.java index 47192f97abe..d044f88ca06 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/delete/ClientTransportDeleteIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/delete/ClientTransportDeleteIndexAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/flush/ClientTransportFlushAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/flush/ClientTransportFlushAction.java index e5b3a027e91..ce911455d0c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/flush/ClientTransportFlushAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/flush/ClientTransportFlushAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/gateway/snapshot/ClientTransportGatewaySnapshotAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/gateway/snapshot/ClientTransportGatewaySnapshotAction.java index dcbb4ce4fd4..e265036d291 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/gateway/snapshot/ClientTransportGatewaySnapshotAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/gateway/snapshot/ClientTransportGatewaySnapshotAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest; import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/mapping/create/ClientTransportPutMappingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/mapping/create/ClientTransportPutMappingAction.java index c7fe9162482..a6f020e022a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/mapping/create/ClientTransportPutMappingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/mapping/create/ClientTransportPutMappingAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/optimize/ClientTransportOptimizeAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/optimize/ClientTransportOptimizeAction.java index bc767b8ff62..38e003f022a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/optimize/ClientTransportOptimizeAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/optimize/ClientTransportOptimizeAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/refresh/ClientTransportRefreshAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/refresh/ClientTransportRefreshAction.java index abd95326047..d2cd0dd7cd7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/refresh/ClientTransportRefreshAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/refresh/ClientTransportRefreshAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/status/ClientTransportIndicesStatusAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/status/ClientTransportIndicesStatusAction.java index 203fed67eaa..0342ea1563a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/status/ClientTransportIndicesStatusAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/status/ClientTransportIndicesStatusAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.admin.indices.status.IndicesStatusRequest; import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/count/ClientTransportCountAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/count/ClientTransportCountAction.java index 0524a5dc142..5c1f8b8dba1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/count/ClientTransportCountAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/count/ClientTransportCountAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.count.CountRequest; import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/delete/ClientTransportDeleteAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/delete/ClientTransportDeleteAction.java index 4a19ceb1a17..71f9f69f5c9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/delete/ClientTransportDeleteAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/delete/ClientTransportDeleteAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/deletebyquery/ClientTransportDeleteByQueryAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/deletebyquery/ClientTransportDeleteByQueryAction.java index a1df72e7473..1ccbafacf5e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/deletebyquery/ClientTransportDeleteByQueryAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/deletebyquery/ClientTransportDeleteByQueryAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.deletebyquery.DeleteByQueryRequest; import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/get/ClientTransportGetAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/get/ClientTransportGetAction.java index 84e56181169..557bfd012d6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/get/ClientTransportGetAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/get/ClientTransportGetAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/index/ClientTransportIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/index/ClientTransportIndexAction.java index d854b4947c2..2d7280e3ac5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/index/ClientTransportIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/index/ClientTransportIndexAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/mlt/ClientTransportMoreLikeThisAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/mlt/ClientTransportMoreLikeThisAction.java index f2ddb238e8d..86e6c080100 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/mlt/ClientTransportMoreLikeThisAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/mlt/ClientTransportMoreLikeThisAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.mlt.MoreLikeThisRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/search/ClientTransportSearchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/search/ClientTransportSearchAction.java index 007d73c4aeb..b688b0523cf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/search/ClientTransportSearchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/search/ClientTransportSearchAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/search/ClientTransportSearchScrollAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/search/ClientTransportSearchScrollAction.java index b8f802b4a9b..a314c2c40f5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/search/ClientTransportSearchScrollAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/search/ClientTransportSearchScrollAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchScrollRequest; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/support/BaseClientTransportAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/support/BaseClientTransportAction.java index 36c4a853e0c..bb90b788114 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/support/BaseClientTransportAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/support/BaseClientTransportAction.java @@ -29,11 +29,11 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.client.transport.action.ClientTransportAction; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.BaseTransportResponseHandler; import org.elasticsearch.transport.RemoteTransportException; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.settings.Settings; import java.lang.reflect.Constructor; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/terms/ClientTransportTermsAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/terms/ClientTransportTermsAction.java index 46474b68795..e1e1034f06d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/terms/ClientTransportTermsAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/terms/ClientTransportTermsAction.java @@ -23,9 +23,9 @@ import org.elasticsearch.action.TransportActions; import org.elasticsearch.action.terms.TermsRequest; import org.elasticsearch.action.terms.TermsResponse; import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java index 5cdca80f8ed..7dccd9ca868 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java @@ -23,9 +23,9 @@ import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.transport.TransportClientNodesService; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java index e617b6507f7..653e6b6cdf4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java @@ -52,9 +52,9 @@ import org.elasticsearch.client.transport.action.search.ClientTransportSearchAct import org.elasticsearch.client.transport.action.search.ClientTransportSearchScrollAction; import org.elasticsearch.client.transport.action.terms.ClientTransportTermsAction; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java index 52ceb2cf494..6bcbd66ba0e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java @@ -53,9 +53,9 @@ import org.elasticsearch.client.transport.action.admin.cluster.ping.replication. import org.elasticsearch.client.transport.action.admin.cluster.ping.single.ClientTransportSinglePingAction; import org.elasticsearch.client.transport.action.admin.cluster.state.ClientTransportClusterStateAction; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java index 79f4e102d0d..2eb28e1ca81 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java @@ -56,9 +56,9 @@ import org.elasticsearch.client.transport.action.admin.indices.optimize.ClientTr import org.elasticsearch.client.transport.action.admin.indices.refresh.ClientTransportRefreshAction; import org.elasticsearch.client.transport.action.admin.indices.status.ClientTransportIndicesStatusAction; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterModule.java index e18d129a45d..ff7e47b8161 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -29,8 +29,8 @@ import org.elasticsearch.cluster.routing.RoutingService; import org.elasticsearch.cluster.routing.strategy.DefaultShardsRoutingStrategy; import org.elasticsearch.cluster.routing.strategy.ShardsRoutingStrategy; import org.elasticsearch.cluster.service.InternalClusterService; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterName.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterName.java index 45edcb2b42c..7b1c27d3721 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterName.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterName.java @@ -19,10 +19,10 @@ package org.elasticsearch.cluster; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterNameModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterNameModule.java index 8b707ea6c54..e8cc6956263 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterNameModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterNameModule.java @@ -19,8 +19,8 @@ package org.elasticsearch.cluster; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterService.java index 9a064c49674..7c9e88eb474 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterService.java @@ -19,8 +19,8 @@ package org.elasticsearch.cluster; +import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.LifecycleComponent; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterState.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterState.java index 85929ee9bc7..a5c803edd26 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -24,11 +24,11 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingNodes; import org.elasticsearch.cluster.routing.RoutingTable; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.io.stream.BytesStreamInput; import org.elasticsearch.util.io.stream.BytesStreamOutput; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.Settings; import javax.annotation.Nullable; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java index 456475b2b36..afa9cdb5ecb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java @@ -26,12 +26,12 @@ import org.elasticsearch.action.support.master.MasterNodeOperationRequest; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaDataService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexCreatedAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexCreatedAction.java index c25632fb9fb..d70b1b9616a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexCreatedAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexCreatedAction.java @@ -22,18 +22,18 @@ package org.elasticsearch.cluster.action.index; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.VoidTransportResponseHandler; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.VoidStreamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexDeletedAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexDeletedAction.java index 10849c2b167..905915829dd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexDeletedAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexDeletedAction.java @@ -22,18 +22,18 @@ package org.elasticsearch.cluster.action.index; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.VoidTransportResponseHandler; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.VoidStreamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeMappingCreatedAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeMappingCreatedAction.java index 8544da5be25..34a1ce720bc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeMappingCreatedAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/index/NodeMappingCreatedAction.java @@ -22,18 +22,18 @@ package org.elasticsearch.cluster.action.index; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.VoidTransportResponseHandler; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.VoidStreamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java index 865b06bc456..87ad5667c17 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java @@ -29,24 +29,24 @@ import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.strategy.ShardsRoutingStrategy; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.VoidTransportResponseHandler; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.VoidStreamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import static org.elasticsearch.cluster.ClusterState.*; import static org.elasticsearch.cluster.routing.ImmutableShardRouting.*; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java index 562fbd507b2..38214c4d400 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java @@ -19,25 +19,25 @@ package org.elasticsearch.cluster.metadata; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.ImmutableSet; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.MapBuilder; import org.elasticsearch.util.Preconditions; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.ImmutableSet; import org.elasticsearch.util.concurrent.Immutable; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import javax.annotation.Nullable; import java.io.IOException; import java.util.Map; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * @author kimchy (shay.banon) @@ -67,7 +67,7 @@ public class IndexMetaData { this.mappings = mappings; this.totalNumberOfShards = numberOfShards() * (numberOfReplicas() + 1); - this.aliases = ImmutableSet.of(settings.getAsArray("index.aliases")); + this.aliases = ImmutableSet.copyOf(settings.getAsArray("index.aliases")); } public String index() { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 762393623f9..bcb9b52651a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -20,30 +20,30 @@ package org.elasticsearch.cluster.metadata; import org.elasticsearch.ElasticSearchIllegalArgumentException; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.ImmutableSet; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.collect.UnmodifiableIterator; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.TextXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.util.MapBuilder; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.UnmodifiableIterator; import org.elasticsearch.util.concurrent.Immutable; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.TextXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import javax.annotation.Nullable; import java.io.IOException; import java.util.*; +import static org.elasticsearch.common.collect.Sets.*; import static org.elasticsearch.util.MapBuilder.*; -import static org.elasticsearch.util.collect.Sets.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataService.java index bfc956c18f1..9edde6deac9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataService.java @@ -29,6 +29,11 @@ import org.elasticsearch.cluster.action.index.NodeMappingCreatedAction; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.strategy.ShardsRoutingStrategy; +import org.elasticsearch.common.collect.Maps; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.mapper.DocumentMapper; @@ -43,12 +48,7 @@ import org.elasticsearch.indices.InvalidIndexNameException; import org.elasticsearch.util.Strings; import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.Streams; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; import java.io.File; import java.io.FileReader; @@ -62,10 +62,10 @@ import java.util.concurrent.TimeUnit; import static org.elasticsearch.cluster.ClusterState.*; import static org.elasticsearch.cluster.metadata.IndexMetaData.*; import static org.elasticsearch.cluster.metadata.MetaData.*; +import static org.elasticsearch.common.collect.Maps.*; +import static org.elasticsearch.common.collect.Sets.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.elasticsearch.index.mapper.DocumentMapper.MergeFlags.*; -import static org.elasticsearch.util.collect.Maps.*; -import static org.elasticsearch.util.collect.Sets.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 49ad1bfb644..a7cfe177d20 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -19,21 +19,21 @@ package org.elasticsearch.cluster.node; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Maps; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.Maps; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.common.transport.TransportAddressSerializers; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.transport.TransportAddress; -import org.elasticsearch.util.transport.TransportAddressSerializers; import java.io.IOException; import java.io.Serializable; import java.util.Map; -import static org.elasticsearch.util.transport.TransportAddressSerializers.*; +import static org.elasticsearch.common.transport.TransportAddressSerializers.*; /** * A discovery node represents a node that is part of the cluster. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index d0cb2b0a522..95c7adb31b1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -19,12 +19,12 @@ package org.elasticsearch.cluster.node; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.UnmodifiableIterator; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.UnmodifiableIterator; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.transport.TransportAddress; import javax.annotation.Nullable; import java.io.IOException; @@ -32,8 +32,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static org.elasticsearch.util.collect.Lists.*; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Maps.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/ImmutableShardRouting.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/ImmutableShardRouting.java index 8f993974750..6478bf94904 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/ImmutableShardRouting.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/ImmutableShardRouting.java @@ -19,8 +19,8 @@ package org.elasticsearch.cluster.routing; +import org.elasticsearch.common.collect.ImmutableList; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.util.collect.ImmutableList; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java index 0af975528b6..f865c8629f2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java @@ -21,10 +21,10 @@ package org.elasticsearch.cluster.routing; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.Sets; +import org.elasticsearch.common.collect.UnmodifiableIterator; import org.elasticsearch.util.IdentityHashSet; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Sets; -import org.elasticsearch.util.collect.UnmodifiableIterator; import org.elasticsearch.util.concurrent.Immutable; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java index 2b801c3a911..747621955ab 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java @@ -19,10 +19,10 @@ package org.elasticsearch.cluster.routing; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.collect.UnmodifiableIterator; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.UnmodifiableIterator; import org.elasticsearch.util.concurrent.jsr166y.ThreadLocalRandom; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; @@ -33,7 +33,7 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.atomic.AtomicInteger; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java index 0902595eb2c..3e6252a3f6c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java index 219ca95213f..bbe30889c47 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java @@ -24,8 +24,8 @@ import org.elasticsearch.util.concurrent.NotThreadSafe; import java.util.*; -import static org.elasticsearch.util.collect.Lists.*; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Maps.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java index 38926c62bab..8eda3171282 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java @@ -22,11 +22,11 @@ package org.elasticsearch.cluster.routing; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.routing.strategy.ShardsRoutingStrategy; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.Future; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index bf6cae4e934..6cd4e17d079 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -21,11 +21,11 @@ package org.elasticsearch.cluster.routing; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.collect.UnmodifiableIterator; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndexMissingException; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.UnmodifiableIterator; import org.elasticsearch.util.concurrent.Immutable; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; @@ -34,7 +34,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Maps.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingTableValidation.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingTableValidation.java index 671bd97f288..dd31d091e8f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingTableValidation.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingTableValidation.java @@ -19,9 +19,9 @@ package org.elasticsearch.cluster.routing; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Lists; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.Lists; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; @@ -31,8 +31,8 @@ import java.io.Serializable; import java.util.List; import java.util.Map; -import static org.elasticsearch.util.collect.Lists.*; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Maps.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/strategy/DefaultShardsRoutingStrategy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/strategy/DefaultShardsRoutingStrategy.java index e8b22e1e41c..44cf61b6147 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/strategy/DefaultShardsRoutingStrategy.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/strategy/DefaultShardsRoutingStrategy.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Set; import static org.elasticsearch.cluster.routing.ShardRoutingState.*; -import static org.elasticsearch.util.collect.Sets.*; +import static org.elasticsearch.common.collect.Sets.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java index b2d8cbbe253..a3d113bd62d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java @@ -23,13 +23,13 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/AbstractComponent.java similarity index 93% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractComponent.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/component/AbstractComponent.java index 0adbc69e5ae..4fd21e72014 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractComponent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/AbstractComponent.java @@ -17,11 +17,11 @@ * under the License. */ -package org.elasticsearch.util.component; +package org.elasticsearch.common.component; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractLifecycleComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/AbstractLifecycleComponent.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractLifecycleComponent.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/component/AbstractLifecycleComponent.java index 4914f02e89e..2e679b0b1a3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractLifecycleComponent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/AbstractLifecycleComponent.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.component; +package org.elasticsearch.common.component; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.settings.Settings; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/CloseableComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/CloseableComponent.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/component/CloseableComponent.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/component/CloseableComponent.java index 59a816225f5..8aa18303e4a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/CloseableComponent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/CloseableComponent.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.component; +package org.elasticsearch.common.component; import org.elasticsearch.ElasticSearchException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/CloseableIndexComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/CloseableIndexComponent.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/component/CloseableIndexComponent.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/component/CloseableIndexComponent.java index ca22cf50f66..ca17cab9270 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/CloseableIndexComponent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/CloseableIndexComponent.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.component; +package org.elasticsearch.common.component; import org.elasticsearch.ElasticSearchException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/Lifecycle.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/Lifecycle.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/component/Lifecycle.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/component/Lifecycle.java index fa43e9dce12..3ccb8ab99ae 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/Lifecycle.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/Lifecycle.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.component; +package org.elasticsearch.common.component; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.util.concurrent.ThreadSafe; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/LifecycleComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/LifecycleComponent.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/component/LifecycleComponent.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/component/LifecycleComponent.java index 438bf14d333..e3a75dddc5d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/LifecycleComponent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/LifecycleComponent.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.component; +package org.elasticsearch.common.component; import org.elasticsearch.ElasticSearchException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/LifecycleListener.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/LifecycleListener.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/component/LifecycleListener.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/component/LifecycleListener.java index 68771835170..64acc453bb9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/LifecycleListener.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/component/LifecycleListener.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.component; +package org.elasticsearch.common.component; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/HttpClientModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/http/client/HttpClientModule.java similarity index 90% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/http/HttpClientModule.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/http/client/HttpClientModule.java index 30e577b8b4f..6236a827446 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/HttpClientModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/http/client/HttpClientModule.java @@ -17,9 +17,9 @@ * under the License. */ -package org.elasticsearch.util.http; +package org.elasticsearch.common.http.client; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/HttpClientService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/http/client/HttpClientService.java similarity index 87% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/http/HttpClientService.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/http/client/HttpClientService.java index e5b6bffb895..9d29e822cfc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/HttpClientService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/http/client/HttpClientService.java @@ -17,13 +17,12 @@ * under the License. */ -package org.elasticsearch.util.http; +package org.elasticsearch.common.http.client; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.http.client.AsyncHttpClient; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/HttpDownloadHelper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/http/client/HttpDownloadHelper.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/http/HttpDownloadHelper.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/http/client/HttpDownloadHelper.java index 69033bf3455..0e5b2a067af 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/HttpDownloadHelper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/http/client/HttpDownloadHelper.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.http; +package org.elasticsearch.common.http.client; import javax.annotation.Nullable; import java.io.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/guice/Injectors.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/inject/Injectors.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/guice/Injectors.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/inject/Injectors.java index e87b018a6ed..d3b241ceb39 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/guice/Injectors.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/inject/Injectors.java @@ -17,12 +17,11 @@ * under the License. */ -package org.elasticsearch.util.guice; +package org.elasticsearch.common.inject; -import org.elasticsearch.util.collect.Sets; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.matcher.Matcher; -import org.elasticsearch.util.inject.name.Names; +import org.elasticsearch.common.collect.Sets; +import org.elasticsearch.common.inject.matcher.Matcher; +import org.elasticsearch.common.inject.name.Names; import java.lang.reflect.Type; import java.util.Map; @@ -35,7 +34,7 @@ import java.util.Set; public class Injectors { /** - * Returns an instance of the given type with the {@link org.elasticsearch.util.inject.name.Named} + * Returns an instance of the given type with the {@link org.elasticsearch.common.inject.name.Named} * annotation value. *

* This method allows you to switch this code diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/guice/ModulesFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/inject/ModulesFactory.java similarity index 94% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/guice/ModulesFactory.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/inject/ModulesFactory.java index e479ffb90df..019b179956e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/guice/ModulesFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/inject/ModulesFactory.java @@ -17,11 +17,10 @@ * under the License. */ -package org.elasticsearch.util.guice; +package org.elasticsearch.common.inject; -import org.elasticsearch.util.inject.Module; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.settings.Settings; import javax.annotation.Nullable; import java.lang.reflect.Constructor; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/joda/FormatDateTimeFormatter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/joda/FormatDateTimeFormatter.java similarity index 90% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/joda/FormatDateTimeFormatter.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/joda/FormatDateTimeFormatter.java index cb364f2a0c2..f97a05cd095 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/joda/FormatDateTimeFormatter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/joda/FormatDateTimeFormatter.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.util.joda; +package org.elasticsearch.common.joda; +import org.elasticsearch.common.joda.time.format.DateTimeFormatter; import org.elasticsearch.util.concurrent.Immutable; -import org.joda.time.format.DateTimeFormatter; /** - * A simple wrapper around {@link org.joda.time.format.DateTimeFormatter} that retains the + * A simple wrapper around {@link DateTimeFormatter} that retains the * format that was used to create it. * * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/joda/Joda.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/joda/Joda.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/joda/Joda.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/joda/Joda.java index 482eebf6a7e..ab0dc459f52 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/joda/Joda.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/joda/Joda.java @@ -17,11 +17,11 @@ * under the License. */ -package org.elasticsearch.util.joda; +package org.elasticsearch.common.joda; +import org.elasticsearch.common.joda.time.DateTimeZone; +import org.elasticsearch.common.joda.time.format.*; import org.elasticsearch.util.Strings; -import org.joda.time.DateTimeZone; -import org.joda.time.format.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/ESLogger.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/ESLogger.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/ESLogger.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/ESLogger.java index 929b59936eb..5ad6cffefc4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/ESLogger.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/ESLogger.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.logging; +package org.elasticsearch.common.logging; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/ESLoggerFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/ESLoggerFactory.java similarity index 89% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/ESLoggerFactory.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/ESLoggerFactory.java index 884216fed30..447aa8db227 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/ESLoggerFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/ESLoggerFactory.java @@ -17,11 +17,11 @@ * under the License. */ -package org.elasticsearch.util.logging; +package org.elasticsearch.common.logging; -import org.elasticsearch.util.logging.jdk.JdkESLoggerFactory; -import org.elasticsearch.util.logging.log4j.Log4jESLoggerFactory; -import org.elasticsearch.util.logging.slf4j.Slf4jESLoggerFactory; +import org.elasticsearch.common.logging.jdk.JdkESLoggerFactory; +import org.elasticsearch.common.logging.log4j.Log4jESLoggerFactory; +import org.elasticsearch.common.logging.slf4j.Slf4jESLoggerFactory; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/Loggers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/Loggers.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/Loggers.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/Loggers.java index 396eff01ffd..57738fdc1f5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/Loggers.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/Loggers.java @@ -17,20 +17,20 @@ * under the License. */ -package org.elasticsearch.util.logging; +package org.elasticsearch.common.logging; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.util.Classes; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.settings.Settings; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.List; -import static java.util.Arrays.*; -import static org.elasticsearch.util.collect.Lists.*; +import static java.util.Arrays.asList; +import static org.elasticsearch.common.collect.Lists.*; /** * A set of utilities around Logging. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/jdk/JdkESLogger.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/jdk/JdkESLogger.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/jdk/JdkESLogger.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/jdk/JdkESLogger.java index c7636a08d77..40aa4d32b21 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/jdk/JdkESLogger.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/jdk/JdkESLogger.java @@ -17,9 +17,9 @@ * under the License. */ -package org.elasticsearch.util.logging.jdk; +package org.elasticsearch.common.logging.jdk; -import org.elasticsearch.util.logging.support.AbstractESLogger; +import org.elasticsearch.common.logging.support.AbstractESLogger; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/jdk/JdkESLoggerFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/jdk/JdkESLoggerFactory.java similarity index 88% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/jdk/JdkESLoggerFactory.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/jdk/JdkESLoggerFactory.java index 4724b4a929c..cbb8cb7ece1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/jdk/JdkESLoggerFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/jdk/JdkESLoggerFactory.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.logging.jdk; +package org.elasticsearch.common.logging.jdk; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.ESLoggerFactory; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.ESLoggerFactory; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/ConsoleAppender.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/ConsoleAppender.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/ConsoleAppender.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/ConsoleAppender.java index 771a1f43146..02c82af43cb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/ConsoleAppender.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/ConsoleAppender.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.util.logging.log4j; +package org.elasticsearch.common.logging.log4j; import org.apache.log4j.Layout; import org.apache.log4j.WriterAppender; import org.apache.log4j.helpers.LogLog; -import org.elasticsearch.util.logging.Loggers; +import org.elasticsearch.common.logging.Loggers; import java.io.IOException; import java.io.OutputStream; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/JLinePatternLayout.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/JLinePatternLayout.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/JLinePatternLayout.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/JLinePatternLayout.java index c4acd69b6d0..6dde3d063b9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/JLinePatternLayout.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/JLinePatternLayout.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.logging.log4j; +package org.elasticsearch.common.logging.log4j; import org.apache.log4j.Level; import org.apache.log4j.PatternLayout; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/Log4jESLogger.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/Log4jESLogger.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/Log4jESLogger.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/Log4jESLogger.java index 065886dfb6b..74bed114d7d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/Log4jESLogger.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/Log4jESLogger.java @@ -17,11 +17,11 @@ * under the License. */ -package org.elasticsearch.util.logging.log4j; +package org.elasticsearch.common.logging.log4j; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.elasticsearch.util.logging.support.AbstractESLogger; +import org.elasticsearch.common.logging.support.AbstractESLogger; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/Log4jESLoggerFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerFactory.java similarity index 87% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/Log4jESLoggerFactory.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerFactory.java index 9bd08a34a0a..e5e37fcbe6c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/Log4jESLoggerFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerFactory.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.logging.log4j; +package org.elasticsearch.common.logging.log4j; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.ESLoggerFactory; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.ESLoggerFactory; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/LogConfigurator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/LogConfigurator.java similarity index 90% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/LogConfigurator.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/LogConfigurator.java index 25b9e9d68a1..b07552e6d0a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/log4j/LogConfigurator.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/log4j/LogConfigurator.java @@ -17,20 +17,20 @@ * under the License. */ -package org.elasticsearch.util.logging.log4j; +package org.elasticsearch.common.logging.log4j; import org.apache.log4j.PropertyConfigurator; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.env.FailedToResolveConfigException; import org.elasticsearch.util.MapBuilder; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; import java.util.Map; import java.util.Properties; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * @author kimchy (Shay Banon) @@ -40,7 +40,7 @@ public class LogConfigurator { private static boolean loaded; private static ImmutableMap replacements = new MapBuilder() - .put("console", "org.elasticsearch.util.logging.log4j.ConsoleAppender") + .put("console", "org.elasticsearch.common.logging.log4j.ConsoleAppender") .put("async", "org.apache.log4j.AsyncAppender") .put("dailyRollingFile", "org.apache.log4j.DailyRollingFileAppender") .put("externallyRolledFile", "org.apache.log4j.ExternallyRolledFileAppender") @@ -60,7 +60,7 @@ public class LogConfigurator { .put("simple", "org.apache.log4j.SimpleLayout") .put("html", "org.apache.log4j.HTMLLayout") .put("pattern", "org.apache.log4j.PatternLayout") - .put("consolePattern", "org.elasticsearch.util.logging.log4j.JLinePatternLayout") + .put("consolePattern", "org.elasticsearch.common.logging.log4j.JLinePatternLayout") .put("ttcc", "org.apache.log4j.TTCCLayout") .put("xml", "org.apache.log4j.XMLLayout") .immutableMap(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/slf4j/Slf4jESLogger.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/slf4j/Slf4jESLogger.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/slf4j/Slf4jESLogger.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/slf4j/Slf4jESLogger.java index cb9a961366e..c3778a27cbf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/slf4j/Slf4jESLogger.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/slf4j/Slf4jESLogger.java @@ -17,9 +17,9 @@ * under the License. */ -package org.elasticsearch.util.logging.slf4j; +package org.elasticsearch.common.logging.slf4j; -import org.elasticsearch.util.logging.support.AbstractESLogger; +import org.elasticsearch.common.logging.support.AbstractESLogger; import org.slf4j.Logger; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/slf4j/Slf4jESLoggerFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/slf4j/Slf4jESLoggerFactory.java similarity index 87% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/slf4j/Slf4jESLoggerFactory.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/slf4j/Slf4jESLoggerFactory.java index 38c82381500..121166e31ad 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/slf4j/Slf4jESLoggerFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/slf4j/Slf4jESLoggerFactory.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.logging.slf4j; +package org.elasticsearch.common.logging.slf4j; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.ESLoggerFactory; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.ESLoggerFactory; import org.slf4j.LoggerFactory; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/support/AbstractESLogger.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/support/AbstractESLogger.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/support/AbstractESLogger.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/support/AbstractESLogger.java index 85fb0d9a5ac..a4f5965d2bc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/support/AbstractESLogger.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/support/AbstractESLogger.java @@ -17,9 +17,9 @@ * under the License. */ -package org.elasticsearch.util.logging.support; +package org.elasticsearch.common.logging.support; -import org.elasticsearch.util.logging.ESLogger; +import org.elasticsearch.common.logging.ESLogger; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/support/LoggerMessageFormat.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/support/LoggerMessageFormat.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/support/LoggerMessageFormat.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/support/LoggerMessageFormat.java index 890b0e98f73..d4e383dd6b8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/logging/support/LoggerMessageFormat.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/logging/support/LoggerMessageFormat.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.logging.support; +package org.elasticsearch.common.logging.support; import java.util.HashMap; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Directories.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Directories.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Directories.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Directories.java index 7c37ae27f8f..36c763ea00c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Directories.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Directories.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; import org.apache.lucene.index.IndexCommit; import org.apache.lucene.index.IndexReader; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/DocumentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/DocumentBuilder.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/DocumentBuilder.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/DocumentBuilder.java index d3c39f7ad2a..5c3163c81c3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/DocumentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/DocumentBuilder.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/FieldBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/FieldBuilder.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/FieldBuilder.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/FieldBuilder.java index fdaa347dd1e..ceb70402c9c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/FieldBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/FieldBuilder.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; import org.apache.lucene.document.Field; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/IndexCommitDelegate.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/IndexCommitDelegate.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/IndexCommitDelegate.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/IndexCommitDelegate.java index 5d406572f85..0242876b47f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/IndexCommitDelegate.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/IndexCommitDelegate.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; import org.apache.lucene.index.IndexCommit; import org.apache.lucene.store.Directory; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/IndexWriters.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/IndexWriters.java similarity index 93% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/IndexWriters.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/IndexWriters.java index c1208af909c..fa2fef59710 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/IndexWriters.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/IndexWriters.java @@ -17,11 +17,11 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; import org.apache.lucene.index.IndexWriter; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import java.lang.reflect.Field; import java.lang.reflect.Method; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/LoggerInfoStream.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/LoggerInfoStream.java similarity index 94% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/LoggerInfoStream.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/LoggerInfoStream.java index fa55eb115d2..b131755e127 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/LoggerInfoStream.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/LoggerInfoStream.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import java.io.OutputStream; import java.io.PrintStream; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Lucene.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Lucene.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Lucene.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Lucene.java index 6cef8a94fdc..cf24db87163 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Lucene.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/Lucene.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; import org.apache.lucene.analysis.KeywordAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; @@ -27,8 +27,8 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.TermDocs; import org.apache.lucene.search.*; import org.apache.lucene.util.Version; +import org.elasticsearch.common.trove.TIntArrayList; import org.elasticsearch.index.analysis.NamedAnalyzer; -import org.elasticsearch.util.gnu.trove.TIntArrayList; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/MultiCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/MultiCollector.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/MultiCollector.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/MultiCollector.java index 59469fd03b5..69b108ad013 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/MultiCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/MultiCollector.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Collector; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/ReaderSearcherHolder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/ReaderSearcherHolder.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/ReaderSearcherHolder.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/ReaderSearcherHolder.java index def949b82a8..64ebe7af9b5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/ReaderSearcherHolder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/ReaderSearcherHolder.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.IndexSearcher; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllEntries.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllEntries.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllEntries.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllEntries.java index 4d165eaaf35..69288ca6219 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllEntries.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllEntries.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.lucene.all; +package org.elasticsearch.common.lucene.all; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.util.collect.Lists; +import org.elasticsearch.common.collect.Lists; import org.elasticsearch.util.io.CharSequenceReader; import org.elasticsearch.util.io.FastCharArrayWriter; import org.elasticsearch.util.io.FastStringReader; @@ -31,7 +31,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import static org.elasticsearch.util.collect.Sets.*; +import static org.elasticsearch.common.collect.Sets.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllField.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllField.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllField.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllField.java index 18481ad8004..a8b3379d2c1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllField.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllField.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.all; +package org.elasticsearch.common.lucene.all; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllTermQuery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllTermQuery.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllTermQuery.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllTermQuery.java index 4bb6ad38bb7..192b2799ee1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllTermQuery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllTermQuery.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.all; +package org.elasticsearch.common.lucene.all; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllTokenStream.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllTokenStream.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllTokenStream.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllTokenStream.java index e66d4ba2eb5..4fabce196b7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/all/AllTokenStream.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/all/AllTokenStream.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.all; +package org.elasticsearch.common.lucene.all; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenFilter; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/analysis/CharSequenceTermAttribute.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/analysis/CharSequenceTermAttribute.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/analysis/CharSequenceTermAttribute.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/analysis/CharSequenceTermAttribute.java index 1e8505c94e8..6a8126f8e97 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/analysis/CharSequenceTermAttribute.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/analysis/CharSequenceTermAttribute.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.analysis; +package org.elasticsearch.common.lucene.analysis; import org.apache.lucene.analysis.tokenattributes.TermAttribute; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/AndDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AndDocSet.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/AndDocSet.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AndDocSet.java index 46a576fed02..4dbc333dec3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/AndDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AndDocSet.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.docset; +package org.elasticsearch.common.lucene.docset; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/DocIdSetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSetCollector.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/DocIdSetCollector.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSetCollector.java index ee73b9ea778..89d4df0ebe2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/DocIdSetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSetCollector.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.docset; +package org.elasticsearch.common.lucene.docset; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Collector; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/DocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSet.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/DocSet.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSet.java index 02794a7bc67..36a97b51b35 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/DocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSet.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.docset; +package org.elasticsearch.common.lucene.docset; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/DocSets.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSets.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/DocSets.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSets.java index 4049b6ae825..def3c9fd2f4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/DocSets.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSets.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.docset; +package org.elasticsearch.common.lucene.docset; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.DocIdSet; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/NotDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocSet.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/NotDocSet.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocSet.java index 535bd0c4675..514b6e3abd0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/NotDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocSet.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.docset; +package org.elasticsearch.common.lucene.docset; import org.apache.lucene.search.DocIdSetIterator; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/OpenBitDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OpenBitDocSet.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/OpenBitDocSet.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OpenBitDocSet.java index be43116cfcb..06a6eb0e23b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/OpenBitDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OpenBitDocSet.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.docset; +package org.elasticsearch.common.lucene.docset; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.util.OpenBitSet; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/OrDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OrDocSet.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/OrDocSet.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OrDocSet.java index 7a179b48f31..baef3a81591 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/docset/OrDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OrDocSet.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.docset; +package org.elasticsearch.common.lucene.docset; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/AndFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/AndFilter.java similarity index 90% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/AndFilter.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/AndFilter.java index 2dddf72b2a9..ad544c192d9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/AndFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/AndFilter.java @@ -17,15 +17,15 @@ * under the License. */ -package org.elasticsearch.util.lucene.search; +package org.elasticsearch.common.lucene.search; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.Filter; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.lucene.docset.AndDocSet; -import org.elasticsearch.util.lucene.docset.DocSet; -import org.elasticsearch.util.lucene.docset.DocSets; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.lucene.docset.AndDocSet; +import org.elasticsearch.common.lucene.docset.DocSet; +import org.elasticsearch.common.lucene.docset.DocSets; import java.io.IOException; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/MoreLikeThisQuery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/MoreLikeThisQuery.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/MoreLikeThisQuery.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/MoreLikeThisQuery.java index 01e08369fdc..329fb54bd5e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/MoreLikeThisQuery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/MoreLikeThisQuery.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.search; +package org.elasticsearch.common.lucene.search; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.IndexReader; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/NoopCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/NoopCollector.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/NoopCollector.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/NoopCollector.java index d5b33ebdc7c..f6924812d8c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/NoopCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/NoopCollector.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.search; +package org.elasticsearch.common.lucene.search; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Collector; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/NotFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/NotFilter.java similarity index 91% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/NotFilter.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/NotFilter.java index 097ba7367ee..37d84b63c92 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/NotFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/NotFilter.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.util.lucene.search; +package org.elasticsearch.common.lucene.search; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.Filter; -import org.elasticsearch.util.lucene.docset.DocSets; -import org.elasticsearch.util.lucene.docset.NotDocSet; +import org.elasticsearch.common.lucene.docset.DocSets; +import org.elasticsearch.common.lucene.docset.NotDocSet; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/OrFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/OrFilter.java similarity index 90% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/OrFilter.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/OrFilter.java index 36a29ff3602..4f367066818 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/OrFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/OrFilter.java @@ -17,15 +17,15 @@ * under the License. */ -package org.elasticsearch.util.lucene.search; +package org.elasticsearch.common.lucene.search; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.Filter; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.lucene.docset.DocSet; -import org.elasticsearch.util.lucene.docset.DocSets; -import org.elasticsearch.util.lucene.docset.OrDocSet; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.lucene.docset.DocSet; +import org.elasticsearch.common.lucene.docset.DocSets; +import org.elasticsearch.common.lucene.docset.OrDocSet; import java.io.IOException; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/Queries.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/Queries.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/Queries.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/Queries.java index 72891491349..35705f8fffd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/Queries.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/Queries.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.search; +package org.elasticsearch.common.lucene.search; import org.apache.lucene.search.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/TermFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/TermFilter.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/TermFilter.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/TermFilter.java index 44b96e0e0be..816989e433d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/TermFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/TermFilter.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.search; +package org.elasticsearch.common.lucene.search; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/function/BoostScoreFunction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/function/BoostScoreFunction.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/function/BoostScoreFunction.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/function/BoostScoreFunction.java index bfa57f74fee..9590e65d439 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/function/BoostScoreFunction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/function/BoostScoreFunction.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.search.function; +package org.elasticsearch.common.lucene.search.function; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Explanation; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/function/FunctionScoreQuery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/function/FunctionScoreQuery.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/function/FunctionScoreQuery.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/function/FunctionScoreQuery.java index 4d22717772f..22f39c7901a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/function/FunctionScoreQuery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/function/FunctionScoreQuery.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.search.function; +package org.elasticsearch.common.lucene.search.function; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/function/ScoreFunction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/function/ScoreFunction.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/function/ScoreFunction.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/function/ScoreFunction.java index dda0ca3d8b8..8b40febe01a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/search/function/ScoreFunction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/function/ScoreFunction.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.search.function; +package org.elasticsearch.common.lucene.search.function; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Explanation; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/store/InputStreamIndexInput.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/store/InputStreamIndexInput.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/store/InputStreamIndexInput.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/store/InputStreamIndexInput.java index 25efc84bc79..4b3798cad30 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/store/InputStreamIndexInput.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/store/InputStreamIndexInput.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.store; +package org.elasticsearch.common.lucene.store; import org.apache.lucene.store.IndexInput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/store/SwitchDirectory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/store/SwitchDirectory.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/store/SwitchDirectory.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/store/SwitchDirectory.java index e03b5593139..d0ec2bcb753 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/store/SwitchDirectory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/store/SwitchDirectory.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.util.lucene.store; +package org.elasticsearch.common.lucene.store; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexOutput; +import org.elasticsearch.common.collect.ImmutableSet; import org.elasticsearch.index.store.support.ForceSyncDirectory; -import org.elasticsearch.util.collect.ImmutableSet; import java.io.IOException; import java.util.Set; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/store/ThreadSafeInputStreamIndexInput.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/store/ThreadSafeInputStreamIndexInput.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/store/ThreadSafeInputStreamIndexInput.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/store/ThreadSafeInputStreamIndexInput.java index c7d25b2462f..88f6fb95ca5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/store/ThreadSafeInputStreamIndexInput.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/store/ThreadSafeInputStreamIndexInput.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.store; +package org.elasticsearch.common.lucene.store; import org.apache.lucene.store.IndexInput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/ConcurrentVersionedMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMap.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/ConcurrentVersionedMap.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMap.java index 326477df0d4..ca75d20eaa3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/ConcurrentVersionedMap.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMap.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.versioned; +package org.elasticsearch.common.lucene.versioned; import org.elasticsearch.util.concurrent.ThreadSafe; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/ConcurrentVersionedMapLong.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMapLong.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/ConcurrentVersionedMapLong.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMapLong.java index ea68152418f..3a8e86f7331 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/ConcurrentVersionedMapLong.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMapLong.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.versioned; +package org.elasticsearch.common.lucene.versioned; import org.elasticsearch.util.concurrent.ConcurrentCollections; import org.elasticsearch.util.concurrent.ConcurrentMapLong; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/NativeVersionedMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/NativeVersionedMap.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/NativeVersionedMap.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/NativeVersionedMap.java index 9e3687aa3bf..aec2cf0094c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/NativeVersionedMap.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/NativeVersionedMap.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.lucene.versioned; +package org.elasticsearch.common.lucene.versioned; +import org.elasticsearch.common.trove.ExtTIntIntHashMap; import org.elasticsearch.util.concurrent.ThreadSafe; -import org.elasticsearch.util.trove.ExtTIntIntHashMap; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/VersionedIndexReader.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReader.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/VersionedIndexReader.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReader.java index 66768f4bb50..701104d4b39 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/VersionedIndexReader.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReader.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.versioned; +package org.elasticsearch.common.lucene.versioned; import org.apache.lucene.index.*; import org.elasticsearch.util.concurrent.ThreadSafe; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/VersionedMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedMap.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/VersionedMap.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedMap.java index 11bc0cae57c..5e1e6d563ec 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/versioned/VersionedMap.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedMap.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.versioned; +package org.elasticsearch.common.lucene.versioned; import org.elasticsearch.util.concurrent.ThreadSafe; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/netty/OpenChannelsHandler.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/netty/OpenChannelsHandler.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/netty/OpenChannelsHandler.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/netty/OpenChannelsHandler.java index 99668229b21..386a1e80451 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/netty/OpenChannelsHandler.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/netty/OpenChannelsHandler.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.netty; +package org.elasticsearch.common.netty; +import org.elasticsearch.common.netty.channel.*; import org.elasticsearch.util.concurrent.ConcurrentCollections; -import org.jboss.netty.channel.*; import java.util.Set; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/network/NetworkModule.java similarity index 91% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkModule.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/network/NetworkModule.java index 8cef93bc81e..2f5787c0f5f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/network/NetworkModule.java @@ -17,9 +17,9 @@ * under the License. */ -package org.elasticsearch.util.network; +package org.elasticsearch.common.network; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/network/NetworkService.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkService.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/network/NetworkService.java index 1db3488e2ff..4e92d186982 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/network/NetworkService.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.util.network; +package org.elasticsearch.common.network; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.MapBuilder; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.net.InetAddress; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkUtils.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/network/NetworkUtils.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkUtils.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/network/NetworkUtils.java index 08f8418d749..aa29f205219 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkUtils.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/network/NetworkUtils.java @@ -17,11 +17,11 @@ * under the License. */ -package org.elasticsearch.util.network; +package org.elasticsearch.common.network; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.util.OsUtils; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; import java.net.*; import java.util.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/path/PathTrie.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/path/PathTrie.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/path/PathTrie.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/path/PathTrie.java index bf4798f3b24..81c7f167a17 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/path/PathTrie.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/path/PathTrie.java @@ -17,9 +17,9 @@ * under the License. */ -package org.elasticsearch.util.path; +package org.elasticsearch.common.path; -import org.elasticsearch.util.collect.ImmutableMap; +import org.elasticsearch.common.collect.ImmutableMap; import java.util.Map; import java.util.regex.Pattern; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/ImmutableSettings.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/ImmutableSettings.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java index 124650ae552..93a3b1c0f7e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/ImmutableSettings.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java @@ -17,16 +17,16 @@ * under the License. */ -package org.elasticsearch.util.settings; +package org.elasticsearch.common.settings; +import org.elasticsearch.common.settings.loader.SettingsLoader; +import org.elasticsearch.common.settings.loader.SettingsLoaderFactory; import org.elasticsearch.util.*; import org.elasticsearch.util.concurrent.Immutable; import org.elasticsearch.util.concurrent.ThreadSafe; import org.elasticsearch.util.io.Streams; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.settings.loader.SettingsLoader; -import org.elasticsearch.util.settings.loader.SettingsLoaderFactory; import java.io.IOException; import java.io.InputStream; @@ -35,10 +35,10 @@ import java.net.URL; import java.util.*; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.common.collect.Lists.*; import static org.elasticsearch.util.SizeValue.*; import static org.elasticsearch.util.Strings.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.collect.Lists.*; /** * An immutable implementation of {@link Settings}. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/NoClassSettingsException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/NoClassSettingsException.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/NoClassSettingsException.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/NoClassSettingsException.java index d6b8f346273..6d543fddb38 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/NoClassSettingsException.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/NoClassSettingsException.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.settings; +package org.elasticsearch.common.settings; /** * A specific type of {@link SettingsException} indicating failure to load a class diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/Settings.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/Settings.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/Settings.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/Settings.java index 8f39c2066a1..b133ebb5a59 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/Settings.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.settings; +package org.elasticsearch.common.settings; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/SettingsException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/SettingsException.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/SettingsException.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/SettingsException.java index 81cdd43ed40..100c0f15176 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/SettingsException.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/SettingsException.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.settings; +package org.elasticsearch.common.settings; import org.elasticsearch.ElasticSearchException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/SettingsFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/SettingsFilter.java similarity index 85% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/SettingsFilter.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/SettingsFilter.java index 477242b1885..8b442c66a87 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/SettingsFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/SettingsFilter.java @@ -1,7 +1,7 @@ -package org.elasticsearch.util.settings; +package org.elasticsearch.common.settings; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; import java.util.concurrent.CopyOnWriteArrayList; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/SettingsModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/SettingsModule.java similarity index 92% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/SettingsModule.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/SettingsModule.java index 13635e3e34b..95d7e6a97ae 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/SettingsModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/SettingsModule.java @@ -17,9 +17,9 @@ * under the License. */ -package org.elasticsearch.util.settings; +package org.elasticsearch.common.settings; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * A module that binds the provided settings to the {@link Settings} interface. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/JsonSettingsLoader.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/JsonSettingsLoader.java similarity index 93% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/JsonSettingsLoader.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/JsonSettingsLoader.java index d108def7e72..69d8b4652ab 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/JsonSettingsLoader.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/JsonSettingsLoader.java @@ -17,18 +17,18 @@ * under the License. */ -package org.elasticsearch.util.settings.loader; +package org.elasticsearch.common.settings.loader; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.XContentType; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; import java.util.List; import java.util.Map; -import static org.elasticsearch.util.collect.Lists.*; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Maps.*; /** * Settings loader that loads (parses) the settings in a json format by flattening them diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/PropertiesSettingsLoader.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java similarity index 94% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/PropertiesSettingsLoader.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java index 4c1f7b9b302..56cd35fcefc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/PropertiesSettingsLoader.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.settings.loader; +package org.elasticsearch.common.settings.loader; import org.elasticsearch.util.io.FastByteArrayInputStream; import org.elasticsearch.util.io.FastStringReader; @@ -26,7 +26,7 @@ import java.io.IOException; import java.util.Map; import java.util.Properties; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Maps.*; /** * Settings loader that loads (parses) the settings in a properties format. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/SettingsLoader.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoader.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/SettingsLoader.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoader.java index baa4c7b3b7e..97aaf240d37 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/SettingsLoader.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoader.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.settings.loader; +package org.elasticsearch.common.settings.loader; import java.io.IOException; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/SettingsLoaderFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/SettingsLoaderFactory.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java index d15e56247b3..061dc5abaf6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/SettingsLoaderFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.settings.loader; +package org.elasticsearch.common.settings.loader; /** * A settings loader factory automatically trying to identify what type of diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/YamlSettingsLoader.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/YamlSettingsLoader.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/YamlSettingsLoader.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/YamlSettingsLoader.java index a55c45f8915..20a44035855 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/YamlSettingsLoader.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/YamlSettingsLoader.java @@ -17,17 +17,17 @@ * under the License. */ -package org.elasticsearch.util.settings.loader; +package org.elasticsearch.common.settings.loader; +import org.elasticsearch.common.yaml.snakeyaml.Yaml; import org.elasticsearch.util.io.FastByteArrayInputStream; -import org.yaml.snakeyaml.Yaml; import java.io.IOException; import java.util.List; import java.util.Map; -import static org.elasticsearch.util.collect.Lists.*; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Maps.*; /** * Settings loader that loads (parses) the settings in a yaml format by flattening them diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/package-info.java similarity index 94% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/package-info.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/package-info.java index 4443b1948cf..8c5636a279e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/package-info.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/loader/package-info.java @@ -21,4 +21,4 @@ * Settings loader (parser) allowing to parse different "source" formats into * a {@link Settings}. */ -package org.elasticsearch.util.settings.loader; \ No newline at end of file +package org.elasticsearch.common.settings.loader; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/package-info.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/package-info.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/package-info.java index d0c099151fb..f4a6201d9b6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/package-info.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/package-info.java @@ -20,4 +20,4 @@ /** * Settings based utility. */ -package org.elasticsearch.util.settings; \ No newline at end of file +package org.elasticsearch.common.settings; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/HashedWheelTimer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/HashedWheelTimer.java similarity index 99% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/HashedWheelTimer.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/HashedWheelTimer.java index 5d56ea740f4..e0183df01c1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/HashedWheelTimer.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/HashedWheelTimer.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.util.timer; +package org.elasticsearch.common.timer; +import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.util.MapBackedSet; import org.elasticsearch.util.ReusableIterator; import org.elasticsearch.util.ThreadRenamingRunnable; import org.elasticsearch.util.concurrent.ConcurrentIdentityHashMap; -import org.elasticsearch.util.logging.ESLogger; import java.util.*; import java.util.concurrent.ThreadFactory; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/Timeout.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/Timeout.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/Timeout.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/Timeout.java index ebcbc076123..7157cbd207d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/Timeout.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/Timeout.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.timer; +package org.elasticsearch.common.timer; /** * A handle associated with a {@link TimerTask} that is returned by a diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/Timer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/Timer.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/Timer.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/Timer.java index 4e2c0f37fe1..300c084d9c2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/Timer.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/Timer.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.timer; +package org.elasticsearch.common.timer; import java.util.Set; import java.util.concurrent.TimeUnit; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/TimerTask.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/TimerTask.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/TimerTask.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/TimerTask.java index 0fa41d86cd9..6baaf5944fe 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/timer/TimerTask.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/timer/TimerTask.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.timer; +package org.elasticsearch.common.timer; /** * A task which is executed after the delay specified with diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/BoundTransportAddress.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/BoundTransportAddress.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/BoundTransportAddress.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/BoundTransportAddress.java index 2b21f1ba745..19a0259debb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/BoundTransportAddress.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/BoundTransportAddress.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.transport; +package org.elasticsearch.common.transport; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/DummyTransportAddress.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/DummyTransportAddress.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/DummyTransportAddress.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/DummyTransportAddress.java index b80f02d98f0..3506129c93f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/DummyTransportAddress.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/DummyTransportAddress.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.transport; +package org.elasticsearch.common.transport; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/InetSocketTransportAddress.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/InetSocketTransportAddress.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java index 34aaf71910e..505ee9f7c8e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/InetSocketTransportAddress.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.transport; +package org.elasticsearch.common.transport; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/LocalTransportAddress.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/LocalTransportAddress.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/LocalTransportAddress.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/LocalTransportAddress.java index d228e54f1db..a35efbc440b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/LocalTransportAddress.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/LocalTransportAddress.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.transport; +package org.elasticsearch.common.transport; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/NetworkExceptionHelper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/NetworkExceptionHelper.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/NetworkExceptionHelper.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/NetworkExceptionHelper.java index 6225d2d039a..7ffe2e2c144 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/NetworkExceptionHelper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/NetworkExceptionHelper.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.transport; +package org.elasticsearch.common.transport; import java.net.ConnectException; import java.nio.channels.ClosedChannelException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/PortsRange.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/PortsRange.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/PortsRange.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/PortsRange.java index a9810bc30c7..fb9d9a8549b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/PortsRange.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/PortsRange.java @@ -17,9 +17,9 @@ * under the License. */ -package org.elasticsearch.util.transport; +package org.elasticsearch.common.transport; -import org.elasticsearch.util.gnu.trove.TIntArrayList; +import org.elasticsearch.common.trove.TIntArrayList; import java.util.StringTokenizer; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/TransportAddress.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/TransportAddress.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/TransportAddress.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/TransportAddress.java index c91a9742189..0c69ed111d6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/TransportAddress.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/TransportAddress.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.transport; +package org.elasticsearch.common.transport; import org.elasticsearch.util.io.stream.Streamable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/TransportAddressSerializers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/TransportAddressSerializers.java similarity index 90% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/TransportAddressSerializers.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/TransportAddressSerializers.java index 1c17a9dffb6..b9098f47f57 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/transport/TransportAddressSerializers.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/transport/TransportAddressSerializers.java @@ -17,14 +17,14 @@ * under the License. */ -package org.elasticsearch.util.transport; +package org.elasticsearch.common.transport; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.util.collect.ImmutableMap; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; import java.io.IOException; import java.lang.reflect.Constructor; @@ -32,10 +32,10 @@ import java.lang.reflect.Constructor; import static org.elasticsearch.util.MapBuilder.*; /** - * A global registry of all different types of {@link org.elasticsearch.util.transport.TransportAddress} allowing + * A global registry of all different types of {@link org.elasticsearch.common.transport.TransportAddress} allowing * to perform serialization of them. * - *

By default, adds {@link org.elasticsearch.util.transport.InetSocketTransportAddress}. + *

By default, adds {@link org.elasticsearch.common.transport.InetSocketTransportAddress}. * * @author kimchy (Shay Banon) */ diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTIntArrayList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTIntArrayList.java similarity index 92% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTIntArrayList.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTIntArrayList.java index 87f382acef7..74dae1f36a9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTIntArrayList.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTIntArrayList.java @@ -17,9 +17,7 @@ * under the License. */ -package org.elasticsearch.util.trove; - -import org.elasticsearch.util.gnu.trove.TIntArrayList; +package org.elasticsearch.common.trove; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTIntIntHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTIntIntHashMap.java similarity index 92% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTIntIntHashMap.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTIntIntHashMap.java index 19dc67516ce..093e986364a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTIntIntHashMap.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTIntIntHashMap.java @@ -17,10 +17,7 @@ * under the License. */ -package org.elasticsearch.util.trove; - -import org.elasticsearch.util.gnu.trove.TIntHashingStrategy; -import org.elasticsearch.util.gnu.trove.TIntIntHashMap; +package org.elasticsearch.common.trove; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTObjectFloatHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTObjectFloatHashMap.java similarity index 92% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTObjectFloatHashMap.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTObjectFloatHashMap.java index 8fd0b2cf445..c2138ddd284 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTObjectFloatHashMap.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTObjectFloatHashMap.java @@ -17,10 +17,7 @@ * under the License. */ -package org.elasticsearch.util.trove; - -import org.elasticsearch.util.gnu.trove.TObjectFloatHashMap; -import org.elasticsearch.util.gnu.trove.TObjectHashingStrategy; +package org.elasticsearch.common.trove; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTObjectIntHasMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTObjectIntHasMap.java similarity index 92% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTObjectIntHasMap.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTObjectIntHasMap.java index b22a078a182..d4a8379477e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/trove/ExtTObjectIntHasMap.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/trove/ExtTObjectIntHasMap.java @@ -17,10 +17,7 @@ * under the License. */ -package org.elasticsearch.util.trove; - -import org.elasticsearch.util.gnu.trove.TObjectHashingStrategy; -import org.elasticsearch.util.gnu.trove.TObjectIntHashMap; +package org.elasticsearch.common.trove; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/ToXContent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/ToXContent.java similarity index 94% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/ToXContent.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/ToXContent.java index f893d79ada0..034cf79e40a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/ToXContent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/ToXContent.java @@ -17,16 +17,16 @@ * under the License. */ -package org.elasticsearch.util.xcontent; +package org.elasticsearch.common.xcontent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.Booleans; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; /** - * An interface allowing to transfer an object to "XContent" using an {@link org.elasticsearch.util.xcontent.builder.XContentBuilder}. + * An interface allowing to transfer an object to "XContent" using an {@link org.elasticsearch.common.xcontent.builder.XContentBuilder}. * * @author kimchy (shay.banon) */ diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContent.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContent.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContent.java index c8ffc1e614c..e36666b2148 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContent.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.xcontent; +package org.elasticsearch.common.xcontent; import java.io.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentFactory.java similarity index 89% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentFactory.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentFactory.java index 15cb8b29127..9d6f98b301c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentFactory.java @@ -17,20 +17,20 @@ * under the License. */ -package org.elasticsearch.util.xcontent; +package org.elasticsearch.common.xcontent; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchParseException; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; -import org.elasticsearch.util.xcontent.builder.TextXContentBuilder; -import org.elasticsearch.util.xcontent.json.JsonXContent; -import org.elasticsearch.util.xcontent.xson.XsonXContent; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; +import org.elasticsearch.common.xcontent.builder.TextXContentBuilder; +import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.common.xcontent.xson.XsonXContent; import java.io.IOException; import java.util.Arrays; /** - * A one stop to use {@link org.elasticsearch.util.xcontent.XContent} and {@link org.elasticsearch.util.xcontent.builder.XContentBuilder}. + * A one stop to use {@link org.elasticsearch.common.xcontent.XContent} and {@link org.elasticsearch.common.xcontent.builder.XContentBuilder}. * * @author kimchy (shay.banon) */ @@ -47,14 +47,14 @@ public class XContentFactory { } /** - * Returns a binary content builder using JSON format ({@link org.elasticsearch.util.xcontent.XContentType#JSON}. + * Returns a binary content builder using JSON format ({@link org.elasticsearch.common.xcontent.XContentType#JSON}. */ public static BinaryXContentBuilder jsonBuilder() throws IOException { return contentBinaryBuilder(XContentType.JSON); } /** - * Returns a binary content builder using XSON format ({@link org.elasticsearch.util.xcontent.XContentType#XSON}. + * Returns a binary content builder using XSON format ({@link org.elasticsearch.common.xcontent.XContentType#XSON}. */ public static BinaryXContentBuilder xsonBuilder() throws IOException { return contentBinaryBuilder(XContentType.XSON); @@ -95,7 +95,7 @@ public class XContentFactory { } /** - * Returns the {@link org.elasticsearch.util.xcontent.XContent} for the provided content type. + * Returns the {@link org.elasticsearch.common.xcontent.XContent} for the provided content type. */ public static XContent xContent(XContentType type) { return contents[type.index()]; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentGenerator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentGenerator.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentGenerator.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentGenerator.java index a0a847b550a..213c33ea58c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentGenerator.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentGenerator.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.xcontent; +package org.elasticsearch.common.xcontent; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentParser.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java index 1d71be351d9..34e40002096 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.xcontent; +package org.elasticsearch.common.xcontent; import java.io.IOException; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentType.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentType.java similarity index 93% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentType.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentType.java index c52fd913eb3..f5cd62b99f0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/XContentType.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentType.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.xcontent; +package org.elasticsearch.common.xcontent; /** - * The content type of {@link org.elasticsearch.util.xcontent.XContent}. + * The content type of {@link org.elasticsearch.common.xcontent.XContent}. * * @author kimchy (shay.banon) */ diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/BinaryXContentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/builder/BinaryXContentBuilder.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/BinaryXContentBuilder.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/builder/BinaryXContentBuilder.java index 293481fd0be..16e4a4fb422 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/BinaryXContentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/builder/BinaryXContentBuilder.java @@ -17,11 +17,11 @@ * under the License. */ -package org.elasticsearch.util.xcontent.builder; +package org.elasticsearch.common.xcontent.builder; +import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.util.Unicode; import org.elasticsearch.util.io.FastByteArrayOutputStream; -import org.elasticsearch.util.xcontent.XContent; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/TextXContentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/builder/TextXContentBuilder.java similarity index 97% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/TextXContentBuilder.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/builder/TextXContentBuilder.java index 579834eb52d..190a70edd3d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/TextXContentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/builder/TextXContentBuilder.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.util.xcontent.builder; +package org.elasticsearch.common.xcontent.builder; import org.apache.lucene.util.UnicodeUtil; +import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.util.Unicode; import org.elasticsearch.util.io.FastCharArrayWriter; -import org.elasticsearch.util.xcontent.XContent; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/XContentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/builder/XContentBuilder.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/XContentBuilder.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/builder/XContentBuilder.java index 39071c115e4..22f71f5a16a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/builder/XContentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/builder/XContentBuilder.java @@ -17,16 +17,16 @@ * under the License. */ -package org.elasticsearch.util.xcontent.builder; +package org.elasticsearch.common.xcontent.builder; +import org.elasticsearch.common.joda.time.DateTimeZone; +import org.elasticsearch.common.joda.time.ReadableInstant; +import org.elasticsearch.common.joda.time.format.DateTimeFormatter; +import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; +import org.elasticsearch.common.xcontent.XContentGenerator; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.support.XContentMapConverter; import org.elasticsearch.util.Strings; -import org.elasticsearch.util.xcontent.XContentGenerator; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.support.XContentMapConverter; -import org.joda.time.DateTimeZone; -import org.joda.time.ReadableInstant; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; import java.io.IOException; import java.util.Date; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java similarity index 89% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContent.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java index 84facf62b4c..da2b89c48e3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java @@ -17,21 +17,21 @@ * under the License. */ -package org.elasticsearch.util.xcontent.json; +package org.elasticsearch.common.xcontent.json; -import org.codehaus.jackson.JsonEncoding; -import org.codehaus.jackson.JsonFactory; -import org.codehaus.jackson.JsonGenerator; -import org.codehaus.jackson.JsonParser; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.jackson.JsonEncoding; +import org.elasticsearch.common.jackson.JsonFactory; +import org.elasticsearch.common.jackson.JsonGenerator; +import org.elasticsearch.common.jackson.JsonParser; +import org.elasticsearch.common.xcontent.XContent; +import org.elasticsearch.common.xcontent.XContentGenerator; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; +import org.elasticsearch.common.xcontent.builder.TextXContentBuilder; import org.elasticsearch.util.ThreadLocals; import org.elasticsearch.util.io.FastStringReader; -import org.elasticsearch.util.xcontent.XContent; -import org.elasticsearch.util.xcontent.XContentGenerator; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; -import org.elasticsearch.util.xcontent.builder.TextXContentBuilder; import java.io.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentGenerator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentGenerator.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentGenerator.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentGenerator.java index 7187466a9f1..f397a98527c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentGenerator.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentGenerator.java @@ -17,11 +17,11 @@ * under the License. */ -package org.elasticsearch.util.xcontent.json; +package org.elasticsearch.common.xcontent.json; -import org.codehaus.jackson.JsonGenerator; -import org.elasticsearch.util.xcontent.XContentGenerator; -import org.elasticsearch.util.xcontent.XContentType; +import org.elasticsearch.common.jackson.JsonGenerator; +import org.elasticsearch.common.xcontent.XContentGenerator; +import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java similarity index 94% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentParser.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java index 4c545fa1327..e8b22d8eb15 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/json/JsonXContentParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.util.xcontent.json; +package org.elasticsearch.common.xcontent.json; -import org.codehaus.jackson.JsonParser; -import org.codehaus.jackson.JsonToken; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.support.AbstractXContentParser; +import org.elasticsearch.common.jackson.JsonParser; +import org.elasticsearch.common.jackson.JsonToken; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.support.AbstractXContentParser; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/AbstractXContentGenerator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentGenerator.java similarity index 95% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/AbstractXContentGenerator.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentGenerator.java index 31c01c239eb..3e83c21e5f7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/AbstractXContentGenerator.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentGenerator.java @@ -17,9 +17,9 @@ * under the License. */ -package org.elasticsearch.util.xcontent.support; +package org.elasticsearch.common.xcontent.support; -import org.elasticsearch.util.xcontent.XContentGenerator; +import org.elasticsearch.common.xcontent.XContentGenerator; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/AbstractXContentParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/AbstractXContentParser.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java index 7c856bcc6e3..cc4cd7d9d49 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/AbstractXContentParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.util.xcontent.support; +package org.elasticsearch.common.xcontent.support; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.util.Booleans; -import org.elasticsearch.util.xcontent.XContentParser; import java.io.IOException; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/XContentMapConverter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapConverter.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/XContentMapConverter.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapConverter.java index ac6864cad73..4b4d97857c2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/XContentMapConverter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapConverter.java @@ -17,11 +17,11 @@ * under the License. */ -package org.elasticsearch.util.xcontent.support; +package org.elasticsearch.common.xcontent.support; -import org.elasticsearch.util.xcontent.XContentGenerator; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentGenerator; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/XContentMapValues.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/XContentMapValues.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java index b6826745509..3e1feef980c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/support/XContentMapValues.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/support/XContentMapValues.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.xcontent.support; +package org.elasticsearch.common.xcontent.support; import java.util.List; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonType.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonType.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonType.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonType.java index a8207ac2f46..d8b609d0a74 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonType.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonType.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.xcontent.xson; +package org.elasticsearch.common.xcontent.xson; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonXContent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonXContent.java similarity index 91% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonXContent.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonXContent.java index 8826d918be4..6ef9c417048 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonXContent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonXContent.java @@ -17,17 +17,17 @@ * under the License. */ -package org.elasticsearch.util.xcontent.xson; +package org.elasticsearch.common.xcontent.xson; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalStateException; +import org.elasticsearch.common.xcontent.XContent; +import org.elasticsearch.common.xcontent.XContentGenerator; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; import org.elasticsearch.util.ThreadLocals; import org.elasticsearch.util.io.FastByteArrayInputStream; -import org.elasticsearch.util.xcontent.XContent; -import org.elasticsearch.util.xcontent.XContentGenerator; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; import java.io.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonXContentGenerator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonXContentGenerator.java similarity index 96% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonXContentGenerator.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonXContentGenerator.java index b9da606bb49..af04904560d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonXContentGenerator.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonXContentGenerator.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.util.xcontent.xson; +package org.elasticsearch.common.xcontent.xson; import org.apache.lucene.util.UnicodeUtil; +import org.elasticsearch.common.xcontent.XContentGenerator; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.support.AbstractXContentGenerator; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.xcontent.XContentGenerator; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.support.AbstractXContentGenerator; import java.io.IOException; import java.io.OutputStream; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonXContentParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonXContentParser.java similarity index 98% rename from modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonXContentParser.java rename to modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonXContentParser.java index 702d301d964..279b37bb326 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/xcontent/xson/XsonXContentParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/xson/XsonXContentParser.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.util.xcontent.xson; +package org.elasticsearch.common.xcontent.xson; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.support.AbstractXContentParser; import org.elasticsearch.util.Bytes; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.support.AbstractXContentParser; import java.io.EOFException; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java index 2b25d827ca1..e0399f5125b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java @@ -20,7 +20,7 @@ package org.elasticsearch.discovery; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.util.component.LifecycleComponent; +import org.elasticsearch.common.component.LifecycleComponent; /** * A pluggable module allowing to implement discovery of other nodes, publishing of the cluster diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/DiscoveryModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/DiscoveryModule.java index cd5a1b37495..5a0f1c5f024 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/DiscoveryModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/DiscoveryModule.java @@ -19,13 +19,13 @@ package org.elasticsearch.discovery; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.local.LocalDiscoveryModule; import org.elasticsearch.discovery.zen.ZenDiscoveryModule; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.settings.Settings; -import static org.elasticsearch.util.guice.ModulesFactory.*; +import static org.elasticsearch.common.inject.ModulesFactory.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/DiscoveryService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/DiscoveryService.java index da3825dffb6..874c86d482c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/DiscoveryService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/DiscoveryService.java @@ -21,10 +21,10 @@ package org.elasticsearch.discovery; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java index fb1ffd9b023..6122ee63108 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java @@ -24,13 +24,13 @@ import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.InitialStateDiscoveryListener; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.component.AbstractLifecycleComponent; import org.elasticsearch.util.concurrent.jsr166y.LinkedTransferQueue; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.Queue; import java.util.Set; @@ -42,7 +42,7 @@ import java.util.concurrent.atomic.AtomicLong; import static org.elasticsearch.cluster.ClusterState.*; import static org.elasticsearch.cluster.node.DiscoveryNode.*; -import static org.elasticsearch.util.collect.Sets.*; +import static org.elasticsearch.common.collect.Sets.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscoveryModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscoveryModule.java index d62278b2d16..d78bccfd548 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscoveryModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscoveryModule.java @@ -19,7 +19,7 @@ package org.elasticsearch.discovery.local; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.discovery.Discovery; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index ed7286f103b..226e68ff4e8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -24,6 +24,9 @@ import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.InitialStateDiscoveryListener; import org.elasticsearch.discovery.zen.elect.ElectMasterService; @@ -37,9 +40,6 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.UUID; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.List; import java.util.Map; @@ -49,8 +49,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.elasticsearch.cluster.ClusterState.*; import static org.elasticsearch.cluster.node.DiscoveryNode.*; import static org.elasticsearch.cluster.node.DiscoveryNodes.*; +import static org.elasticsearch.common.collect.Lists.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscoveryModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscoveryModule.java index d2e202da9ce..521d9a2569d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscoveryModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscoveryModule.java @@ -19,7 +19,7 @@ package org.elasticsearch.discovery.zen; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.zen.ping.ZenPingService; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java index 1347a033cc8..cc98ae8d9d5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java @@ -20,9 +20,9 @@ package org.elasticsearch.discovery.zen.elect; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; import java.util.Collections; import java.util.Comparator; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java index fa065517995..952f113c808 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java @@ -22,15 +22,15 @@ package org.elasticsearch.discovery.zen.fd; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractComponent; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.concurrent.CopyOnWriteArrayList; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java index 2eb5852418d..406bcf93fd1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java @@ -22,14 +22,14 @@ package org.elasticsearch.discovery.zen.fd; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractComponent; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.concurrent.ConcurrentMap; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java index 1eb0686d017..d57295c68ee 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/membership/MembershipAction.java @@ -21,17 +21,17 @@ package org.elasticsearch.discovery.zen.membership; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.VoidTransportResponseHandler; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractComponent; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.VoidStreamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.concurrent.TimeUnit; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java index 3b068dc3683..1b7aef974b4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPing.java @@ -22,9 +22,9 @@ package org.elasticsearch.discovery.zen.ping; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.LifecycleComponent; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPingService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPingService.java index 1190f26d39d..8d5b75d26bc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPingService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/ZenPingService.java @@ -23,17 +23,17 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.network.NetworkService; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.discovery.zen.ping.multicast.MulticastZenPing; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.network.NetworkService; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/multicast/MulticastZenPing.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/multicast/MulticastZenPing.java index 566694d75a8..44c9acae77d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/multicast/MulticastZenPing.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/multicast/MulticastZenPing.java @@ -24,6 +24,9 @@ import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.network.NetworkService; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryException; import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.discovery.zen.ping.ZenPing; @@ -31,10 +34,7 @@ import org.elasticsearch.discovery.zen.ping.ZenPingException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractLifecycleComponent; import org.elasticsearch.util.io.stream.*; -import org.elasticsearch.util.network.NetworkService; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.net.DatagramPacket; @@ -50,9 +50,9 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import static org.elasticsearch.cluster.node.DiscoveryNode.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.elasticsearch.util.concurrent.ConcurrentCollections.*; import static org.elasticsearch.util.concurrent.DynamicExecutors.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java index d2eb6e19734..5a3e4cec8ab 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java @@ -24,20 +24,20 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; import org.elasticsearch.util.Strings; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.component.AbstractLifecycleComponent; import org.elasticsearch.util.concurrent.jsr166y.LinkedTransferQueue; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.transport.TransportAddress; import java.io.IOException; import java.util.List; @@ -47,11 +47,11 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.elasticsearch.discovery.zen.ping.ZenPing.PingResponse.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.collect.Lists.*; import static org.elasticsearch.util.concurrent.ConcurrentCollections.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java index 1a5f783511b..bdbb6ab4f82 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java @@ -21,14 +21,14 @@ package org.elasticsearch.discovery.zen.publish; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.transport.*; -import org.elasticsearch.util.component.AbstractComponent; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.VoidStreamable; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/env/Environment.java b/modules/elasticsearch/src/main/java/org/elasticsearch/env/Environment.java index 655f5ce63a4..19ebc2424e3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/env/Environment.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/env/Environment.java @@ -20,19 +20,18 @@ package org.elasticsearch.env; import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.Classes; import org.elasticsearch.util.io.Streams; -import org.elasticsearch.util.settings.Settings; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.elasticsearch.util.Strings.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; /** * The environment of where things exists. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/env/EnvironmentModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/env/EnvironmentModule.java index 6b53ded287d..18b0bbd7376 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/env/EnvironmentModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/env/EnvironmentModule.java @@ -19,7 +19,7 @@ package org.elasticsearch.env; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/Gateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/Gateway.java index 11b49bf6365..cc1e0f06097 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/Gateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/Gateway.java @@ -20,8 +20,8 @@ package org.elasticsearch.gateway; import org.elasticsearch.cluster.metadata.MetaData; -import org.elasticsearch.util.component.LifecycleComponent; -import org.elasticsearch.util.inject.Module; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.inject.Module; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayModule.java index 17cb44d40ba..4d6c40bd665 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayModule.java @@ -19,10 +19,10 @@ package org.elasticsearch.gateway; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.ModulesFactory; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.none.NoneGatewayModule; -import org.elasticsearch.util.guice.ModulesFactory; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayService.java index 7b5c334492f..9494e5f0bf7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/GatewayService.java @@ -24,12 +24,12 @@ import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaDataService; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.DiscoveryService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import javax.annotation.Nullable; import java.util.concurrent.CountDownLatch; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/fs/FsGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/fs/FsGateway.java index 87134f8d693..0dce7c7de06 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/fs/FsGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/fs/FsGateway.java @@ -22,20 +22,20 @@ package org.elasticsearch.gateway.fs; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; import org.elasticsearch.env.Environment; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.gateway.GatewayException; import org.elasticsearch.index.gateway.fs.FsIndexGatewayModule; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.Module; import org.elasticsearch.util.io.FileSystemUtils; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; import java.io.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/fs/FsGatewayModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/fs/FsGatewayModule.java index ac5d0de6e2a..d9df36b5347 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/fs/FsGatewayModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/fs/FsGatewayModule.java @@ -19,7 +19,7 @@ package org.elasticsearch.gateway.fs; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.gateway.Gateway; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/none/NoneGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/none/NoneGateway.java index 11f0f7726ec..c879e669efe 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/none/NoneGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/none/NoneGateway.java @@ -19,15 +19,15 @@ package org.elasticsearch.gateway.none; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.Module; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.gateway.GatewayException; import org.elasticsearch.index.gateway.none.NoneIndexGatewayModule; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/none/NoneGatewayModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/none/NoneGatewayModule.java index ebc61b72b39..e4fd9502a21 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/none/NoneGatewayModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/none/NoneGatewayModule.java @@ -19,7 +19,7 @@ package org.elasticsearch.gateway.none; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.gateway.Gateway; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServer.java index 83299881326..9b399c34b9b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServer.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServer.java @@ -21,14 +21,14 @@ package org.elasticsearch.http; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfoAction; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.path.PathTrie; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.XContentThrowableRestResponse; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.path.PathTrie; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServerModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServerModule.java index b77ecf5d2b4..78237f1386e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServerModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServerModule.java @@ -19,12 +19,12 @@ package org.elasticsearch.http; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.Module; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.Classes; -import org.elasticsearch.util.settings.Settings; -import static org.elasticsearch.util.guice.ModulesFactory.*; +import static org.elasticsearch.common.inject.ModulesFactory.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServerTransport.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServerTransport.java index f8305d90d30..3a81fc6b2d2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServerTransport.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/HttpServerTransport.java @@ -19,8 +19,8 @@ package org.elasticsearch.http; -import org.elasticsearch.util.component.LifecycleComponent; -import org.elasticsearch.util.transport.BoundTransportAddress; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.transport.BoundTransportAddress; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/HttpRequestHandler.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/HttpRequestHandler.java index f318b0abdfe..c96fbbd4f05 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/HttpRequestHandler.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/HttpRequestHandler.java @@ -19,12 +19,12 @@ package org.elasticsearch.http.netty; -import org.jboss.netty.channel.*; -import org.jboss.netty.handler.codec.http.HttpRequest; +import org.elasticsearch.common.netty.channel.*; +import org.elasticsearch.common.netty.handler.codec.http.HttpRequest; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ @ChannelHandler.Sharable public class HttpRequestHandler extends SimpleChannelUpstreamHandler { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java index f0ab41197e2..922f6b6d46e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java @@ -19,16 +19,16 @@ package org.elasticsearch.http.netty; +import org.elasticsearch.common.netty.buffer.ChannelBuffer; +import org.elasticsearch.common.netty.buffer.ChannelBuffers; +import org.elasticsearch.common.netty.channel.Channel; +import org.elasticsearch.common.netty.channel.ChannelFuture; +import org.elasticsearch.common.netty.channel.ChannelFutureListener; +import org.elasticsearch.common.netty.handler.codec.http.*; import org.elasticsearch.http.HttpChannel; import org.elasticsearch.http.HttpException; import org.elasticsearch.http.HttpResponse; import org.elasticsearch.rest.RestResponse; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelFuture; -import org.jboss.netty.channel.ChannelFutureListener; -import org.jboss.netty.handler.codec.http.*; import java.io.IOException; import java.util.Set; @@ -38,9 +38,9 @@ import java.util.Set; */ public class NettyHttpChannel implements HttpChannel { private final Channel channel; - private final org.jboss.netty.handler.codec.http.HttpRequest request; + private final org.elasticsearch.common.netty.handler.codec.http.HttpRequest request; - public NettyHttpChannel(Channel channel, org.jboss.netty.handler.codec.http.HttpRequest request) { + public NettyHttpChannel(Channel channel, org.elasticsearch.common.netty.handler.codec.http.HttpRequest request) { this.channel = channel; this.request = request; } @@ -55,7 +55,7 @@ public class NettyHttpChannel implements HttpChannel { // Build the response object. HttpResponseStatus status = getStatus(response.status()); - org.jboss.netty.handler.codec.http.HttpResponse resp; + org.elasticsearch.common.netty.handler.codec.http.HttpResponse resp; if (http10) { resp = new DefaultHttpResponse(HttpVersion.HTTP_1_0, status); if (!close) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java index c29bfba4748..9bb5cb270b1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java @@ -19,11 +19,11 @@ package org.elasticsearch.http.netty; +import org.elasticsearch.common.netty.handler.codec.http.HttpHeaders; +import org.elasticsearch.common.netty.handler.codec.http.HttpMethod; import org.elasticsearch.http.HttpRequest; import org.elasticsearch.rest.support.AbstractRestRequest; import org.elasticsearch.rest.support.RestUtils; -import org.jboss.netty.handler.codec.http.HttpHeaders; -import org.jboss.netty.handler.codec.http.HttpMethod; import java.nio.charset.Charset; import java.util.HashMap; @@ -36,7 +36,7 @@ import java.util.Set; */ public class NettyHttpRequest extends AbstractRestRequest implements HttpRequest { - private final org.jboss.netty.handler.codec.http.HttpRequest request; + private final org.elasticsearch.common.netty.handler.codec.http.HttpRequest request; private final Map params; @@ -44,7 +44,7 @@ public class NettyHttpRequest extends AbstractRestRequest implements HttpRequest private byte[] cachedData; - public NettyHttpRequest(org.jboss.netty.handler.codec.http.HttpRequest request) { + public NettyHttpRequest(org.elasticsearch.common.netty.handler.codec.http.HttpRequest request) { this.request = request; this.params = new HashMap(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java index 3b318ddba50..7a4c0042485 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java @@ -20,30 +20,30 @@ package org.elasticsearch.http.netty; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.netty.OpenChannelsHandler; +import org.elasticsearch.common.netty.bootstrap.ServerBootstrap; +import org.elasticsearch.common.netty.channel.*; +import org.elasticsearch.common.netty.channel.socket.nio.NioServerSocketChannelFactory; +import org.elasticsearch.common.netty.handler.codec.http.HttpChunkAggregator; +import org.elasticsearch.common.netty.handler.codec.http.HttpRequestDecoder; +import org.elasticsearch.common.netty.handler.codec.http.HttpResponseEncoder; +import org.elasticsearch.common.netty.handler.timeout.ReadTimeoutException; +import org.elasticsearch.common.netty.logging.InternalLogger; +import org.elasticsearch.common.netty.logging.InternalLoggerFactory; +import org.elasticsearch.common.network.NetworkService; +import org.elasticsearch.common.network.NetworkUtils; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.BoundTransportAddress; +import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.common.transport.NetworkExceptionHelper; +import org.elasticsearch.common.transport.PortsRange; import org.elasticsearch.http.*; import org.elasticsearch.transport.BindTransportException; import org.elasticsearch.transport.netty.NettyInternalESLoggerFactory; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.netty.OpenChannelsHandler; -import org.elasticsearch.util.network.NetworkService; -import org.elasticsearch.util.network.NetworkUtils; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.transport.BoundTransportAddress; -import org.elasticsearch.util.transport.InetSocketTransportAddress; -import org.elasticsearch.util.transport.NetworkExceptionHelper; -import org.elasticsearch.util.transport.PortsRange; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.*; -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; -import org.jboss.netty.handler.codec.http.HttpChunkAggregator; -import org.jboss.netty.handler.codec.http.HttpRequestDecoder; -import org.jboss.netty.handler.codec.http.HttpResponseEncoder; -import org.jboss.netty.handler.timeout.ReadTimeoutException; -import org.jboss.netty.logging.InternalLogger; -import org.jboss.netty.logging.InternalLoggerFactory; import java.io.IOException; import java.net.InetAddress; @@ -51,8 +51,8 @@ import java.net.InetSocketAddress; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.common.network.NetworkService.TcpSettings.*; import static org.elasticsearch.util.concurrent.DynamicExecutors.*; -import static org.elasticsearch.util.network.NetworkService.TcpSettings.*; /** * @author kimchy (shay.banon) @@ -62,7 +62,7 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent extends AbstractStore } // see http://lucene.apache.org/java/3_0_1/fileformats.html String[] primaryExtensions = componentSettings.getAsArray("memory.extensions", new String[]{"", "del", "gen"}); - return new SwitchDirectory(ImmutableSet.of(primaryExtensions), memDir, fsDirectory, true); + return new SwitchDirectory(ImmutableSet.copyOf(primaryExtensions), memDir, fsDirectory, true); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/MmapFsStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/MmapFsStore.java index 1c9ebbf7d6b..00f0a5287ca 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/MmapFsStore.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/MmapFsStore.java @@ -20,14 +20,14 @@ package org.elasticsearch.index.store.fs; import org.apache.lucene.store.*; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lucene.store.SwitchDirectory; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.index.LocalNodeId; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.support.ForceSyncDirectory; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.lucene.store.SwitchDirectory; -import org.elasticsearch.util.settings.Settings; import java.io.File; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/MmapFsStoreModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/MmapFsStoreModule.java index 2bac85153fd..42970e3c135 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/MmapFsStoreModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/MmapFsStoreModule.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.store.fs; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.index.store.Store; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/NioFsStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/NioFsStore.java index 4037f7396d7..f30195c5ac2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/NioFsStore.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/NioFsStore.java @@ -20,14 +20,14 @@ package org.elasticsearch.index.store.fs; import org.apache.lucene.store.*; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lucene.store.SwitchDirectory; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.index.LocalNodeId; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.support.ForceSyncDirectory; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.lucene.store.SwitchDirectory; -import org.elasticsearch.util.settings.Settings; import java.io.File; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/NioFsStoreModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/NioFsStoreModule.java index a9ca1329ccd..9229ad7b4cc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/NioFsStoreModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/NioFsStoreModule.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.store.fs; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.index.store.Store; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/SimpleFsStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/SimpleFsStore.java index cf9735b88c1..2cf7f7ae0e5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/SimpleFsStore.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/SimpleFsStore.java @@ -20,14 +20,14 @@ package org.elasticsearch.index.store.fs; import org.apache.lucene.store.*; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lucene.store.SwitchDirectory; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.index.LocalNodeId; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.support.ForceSyncDirectory; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.lucene.store.SwitchDirectory; -import org.elasticsearch.util.settings.Settings; import java.io.File; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/SimpleFsStoreModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/SimpleFsStoreModule.java index 9a658c2a2bc..5146bcb8043 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/SimpleFsStoreModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/SimpleFsStoreModule.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.store.fs; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.index.store.Store; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/ByteBufferStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/ByteBufferStore.java index 16eec97c165..8e0f20c022b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/ByteBufferStore.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/ByteBufferStore.java @@ -19,13 +19,13 @@ package org.elasticsearch.index.store.memory; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.support.AbstractStore; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/HeapStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/HeapStore.java index b5149850045..b7511704047 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/HeapStore.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/HeapStore.java @@ -19,13 +19,13 @@ package org.elasticsearch.index.store.memory; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.support.AbstractStore; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/MemoryStoreModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/MemoryStoreModule.java index f0cd3a53d22..6598188269d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/MemoryStoreModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/memory/MemoryStoreModule.java @@ -20,9 +20,9 @@ package org.elasticsearch.index.store.memory; import org.elasticsearch.ElasticSearchIllegalArgumentException; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.store.Store; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/ram/RamStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/ram/RamStore.java index 9483b8371d1..3f172b6eff2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/ram/RamStore.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/ram/RamStore.java @@ -20,13 +20,13 @@ package org.elasticsearch.index.store.ram; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.support.AbstractStore; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/ram/RamStoreModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/ram/RamStoreModule.java index de46cf5763f..48fb82676db 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/ram/RamStoreModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/ram/RamStoreModule.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.store.ram; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.index.store.Store; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/support/AbstractStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/support/AbstractStore.java index 1439b66c5d4..be726635726 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/support/AbstractStore.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/support/AbstractStore.java @@ -20,13 +20,13 @@ package org.elasticsearch.index.store.support; import org.apache.lucene.store.Directory; +import org.elasticsearch.common.lucene.Directories; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.Store; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.lucene.Directories; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/TranslogModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/TranslogModule.java index 52167d21f96..8aa698b430c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/TranslogModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/TranslogModule.java @@ -19,10 +19,10 @@ package org.elasticsearch.index.translog; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Scopes; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.translog.memory.MemoryTranslog; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.Scopes; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/memory/MemorySnapshot.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/memory/MemorySnapshot.java index d55630c60c0..b10a5c0fb29 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/memory/MemorySnapshot.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/memory/MemorySnapshot.java @@ -21,8 +21,8 @@ package org.elasticsearch.index.translog.memory; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalArgumentException; +import org.elasticsearch.common.collect.Iterables; import org.elasticsearch.index.translog.Translog; -import org.elasticsearch.util.collect.Iterables; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/memory/MemoryTranslog.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/memory/MemoryTranslog.java index c44e341cef4..46b6fc0ea99 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/memory/MemoryTranslog.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/translog/memory/MemoryTranslog.java @@ -19,6 +19,8 @@ package org.elasticsearch.index.translog.memory; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.ShardId; @@ -28,8 +30,6 @@ import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.concurrent.ThreadSafe; import org.elasticsearch.util.concurrent.jsr166y.LinkedTransferQueue; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.ArrayList; import java.util.Queue; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesMemoryCleaner.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesMemoryCleaner.java index 9df6daca435..b4661a49195 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesMemoryCleaner.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesMemoryCleaner.java @@ -19,6 +19,9 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.FlushNotAllowedEngineException; import org.elasticsearch.index.service.IndexService; @@ -31,16 +34,13 @@ import org.elasticsearch.index.translog.Translog; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Set; -import static org.elasticsearch.util.collect.Sets.*; +import static org.elasticsearch.common.collect.Sets.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesModule.java index 9f190a373da..e01bc2a1399 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesModule.java @@ -19,11 +19,11 @@ package org.elasticsearch.indices; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.indices.cluster.IndicesClusterStateService; import org.elasticsearch.indices.recovery.throttler.RecoveryThrottler; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesService.java index 323d8520b18..e5d778ab3e3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -22,10 +22,10 @@ package org.elasticsearch.indices; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.service.IndexService; -import org.elasticsearch.util.component.LifecycleComponent; import org.elasticsearch.util.concurrent.ThreadSafe; -import org.elasticsearch.util.settings.Settings; import java.util.Set; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java index 5e88723cc4f..154f32fc53c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java @@ -19,13 +19,13 @@ package org.elasticsearch.indices; -import org.elasticsearch.util.inject.Inject; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.service.IndexService; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.service.IndexShard; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.CopyOnWriteArrayList; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java index 141e09efab2..ac35174c783 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java @@ -22,6 +22,15 @@ package org.elasticsearch.indices; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.UnmodifiableIterator; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.component.CloseableIndexComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Injector; +import org.elasticsearch.common.inject.Injectors; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.index.*; import org.elasticsearch.index.analysis.AnalysisModule; @@ -42,16 +51,7 @@ import org.elasticsearch.indices.analysis.IndicesAnalysisService; import org.elasticsearch.indices.cluster.IndicesClusterStateService; import org.elasticsearch.plugins.IndicesPluginsModule; import org.elasticsearch.plugins.PluginsService; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.UnmodifiableIterator; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.component.CloseableIndexComponent; import org.elasticsearch.util.concurrent.ThreadSafe; -import org.elasticsearch.util.guice.Injectors; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.settings.Settings; import java.util.ArrayList; import java.util.HashMap; @@ -59,10 +59,10 @@ import java.util.Map; import java.util.Set; import static org.elasticsearch.cluster.metadata.IndexMetaData.*; +import static org.elasticsearch.common.collect.Maps.*; +import static org.elasticsearch.common.collect.Sets.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.elasticsearch.util.MapBuilder.*; -import static org.elasticsearch.util.collect.Maps.*; -import static org.elasticsearch.util.collect.Sets.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/analysis/IndicesAnalysisService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/analysis/IndicesAnalysisService.java index b3488137c4f..4203e7036cb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/analysis/IndicesAnalysisService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/analysis/IndicesAnalysisService.java @@ -32,17 +32,17 @@ import org.apache.lucene.analysis.nl.DutchAnalyzer; import org.apache.lucene.analysis.ru.RussianAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.analysis.th.ThaiAnalyzer; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.analysis.AnalyzerScope; import org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory; -import org.elasticsearch.util.component.AbstractComponent; import org.elasticsearch.util.concurrent.ConcurrentCollections; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.lucene.Lucene; -import org.elasticsearch.util.settings.Settings; import java.util.Map; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; /** * A node level registry of analyzers, to be reused by different indices which use default analyzers. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index e07be942f76..36e64e7c67c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -34,6 +34,10 @@ import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexShardAlreadyExistsException; import org.elasticsearch.index.IndexShardMissingException; import org.elasticsearch.index.gateway.IgnoreGatewayRecoveryException; @@ -48,16 +52,12 @@ import org.elasticsearch.index.shard.service.IndexShard; import org.elasticsearch.index.shard.service.InternalIndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.Map; import java.util.Set; import static org.elasticsearch.ExceptionsHelper.*; -import static org.elasticsearch.util.collect.Sets.*; +import static org.elasticsearch.common.collect.Sets.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/recovery/throttler/RecoveryThrottler.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/recovery/throttler/RecoveryThrottler.java index e9bb70546e9..d34001eef4d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/recovery/throttler/RecoveryThrottler.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/recovery/throttler/RecoveryThrottler.java @@ -19,11 +19,11 @@ package org.elasticsearch.indices.recovery.throttler; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxClusterService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxClusterService.java index 37ee3725a53..1076cd241a1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxClusterService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxClusterService.java @@ -23,9 +23,9 @@ import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.jmx.action.GetJmxServiceUrlAction; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.settings.Settings; import javax.management.MBeanServerConnection; import javax.management.remote.JMXConnector; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxModule.java index 0e10f1b4a71..d0554923c51 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxModule.java @@ -19,15 +19,15 @@ package org.elasticsearch.jmx; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.TypeLiteral; -import org.elasticsearch.util.inject.matcher.Matchers; -import org.elasticsearch.util.inject.spi.InjectionListener; -import org.elasticsearch.util.inject.spi.TypeEncounter; -import org.elasticsearch.util.inject.spi.TypeListener; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.TypeLiteral; +import org.elasticsearch.common.inject.matcher.Matchers; +import org.elasticsearch.common.inject.spi.InjectionListener; +import org.elasticsearch.common.inject.spi.TypeEncounter; +import org.elasticsearch.common.inject.spi.TypeListener; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.jmx.action.GetJmxServiceUrlAction; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxService.java index 0a8ae3ab137..8409f78e10c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/JmxService.java @@ -19,10 +19,10 @@ package org.elasticsearch.jmx; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.network.NetworkService; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.transport.PortsRange; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.network.NetworkService; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.PortsRange; import javax.management.InstanceAlreadyExistsException; import javax.management.MBeanServer; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/ResourceDMBean.java b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/ResourceDMBean.java index 955469c5fe8..4b40f02a487 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/ResourceDMBean.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/ResourceDMBean.java @@ -19,13 +19,13 @@ package org.elasticsearch.jmx; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.util.Classes; import org.elasticsearch.util.MapBuilder; import org.elasticsearch.util.Preconditions; import org.elasticsearch.util.Strings; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.logging.ESLogger; import javax.management.*; import java.lang.reflect.Field; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/action/GetJmxServiceUrlAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/action/GetJmxServiceUrlAction.java index 0c1d84d5a7c..d65c12abcf4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/action/GetJmxServiceUrlAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/jmx/action/GetJmxServiceUrlAction.java @@ -19,19 +19,19 @@ package org.elasticsearch.jmx.action; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.jmx.JmxService; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.FutureTransportResponseHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.component.AbstractComponent; import org.elasticsearch.util.io.stream.StringStreamable; import org.elasticsearch.util.io.stream.VoidStreamable; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorModule.java index d62a7fe8bc4..cda6fb281ed 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorModule.java @@ -19,6 +19,11 @@ package org.elasticsearch.monitor; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Scopes; +import org.elasticsearch.common.inject.assistedinject.FactoryProvider; +import org.elasticsearch.common.inject.multibindings.MapBinder; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.dump.DumpContributorFactory; import org.elasticsearch.monitor.dump.DumpMonitorService; import org.elasticsearch.monitor.dump.cluster.ClusterDumpContributor; @@ -43,11 +48,6 @@ import org.elasticsearch.monitor.process.ProcessProbe; import org.elasticsearch.monitor.process.ProcessService; import org.elasticsearch.monitor.process.SigarProcessProbe; import org.elasticsearch.monitor.sigar.SigarService; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.Scopes; -import org.elasticsearch.util.inject.assistedinject.FactoryProvider; -import org.elasticsearch.util.inject.multibindings.MapBinder; -import org.elasticsearch.util.settings.Settings; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorService.java index 552da6cc197..3b8e8c3abff 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorService.java @@ -20,15 +20,15 @@ package org.elasticsearch.monitor; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.jvm.JvmMonitorService; import org.elasticsearch.monitor.jvm.JvmService; import org.elasticsearch.monitor.memory.MemoryMonitorService; import org.elasticsearch.monitor.network.NetworkService; import org.elasticsearch.monitor.os.OsService; import org.elasticsearch.monitor.process.ProcessService; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/AbstractDump.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/AbstractDump.java index 084d38318bb..50b6207858b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/AbstractDump.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/AbstractDump.java @@ -19,7 +19,7 @@ package org.elasticsearch.monitor.dump; -import org.elasticsearch.util.collect.ImmutableMap; +import org.elasticsearch.common.collect.ImmutableMap; import javax.annotation.Nullable; import java.io.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpContributorFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpContributorFactory.java index 61724430b11..dd31e145665 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpContributorFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpContributorFactory.java @@ -19,7 +19,7 @@ package org.elasticsearch.monitor.dump; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpMonitorService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpMonitorService.java index 022be528d17..b865336a078 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpMonitorService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpMonitorService.java @@ -20,23 +20,23 @@ package org.elasticsearch.monitor.dump; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.monitor.dump.heap.HeapDumpContributor; import org.elasticsearch.monitor.dump.summary.SummaryDumpContributor; import org.elasticsearch.monitor.dump.thread.ThreadDumpContributor; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import javax.annotation.Nullable; import java.io.File; import java.util.Map; +import static org.elasticsearch.common.collect.Maps.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.elasticsearch.monitor.dump.heap.HeapDumpContributor.*; import static org.elasticsearch.monitor.dump.summary.SummaryDumpContributor.*; import static org.elasticsearch.monitor.dump.thread.ThreadDumpContributor.*; -import static org.elasticsearch.util.collect.Maps.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/SimpleDumpGenerator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/SimpleDumpGenerator.java index 790e4cfaca4..c17a2643bdd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/SimpleDumpGenerator.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/SimpleDumpGenerator.java @@ -20,7 +20,7 @@ package org.elasticsearch.monitor.dump; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.util.collect.ImmutableMap; +import org.elasticsearch.common.collect.ImmutableMap; import javax.annotation.Nullable; import java.io.File; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/cluster/ClusterDumpContributor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/cluster/ClusterDumpContributor.java index 6ef478ddd6c..862b331ccdd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/cluster/ClusterDumpContributor.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/cluster/ClusterDumpContributor.java @@ -19,16 +19,16 @@ package org.elasticsearch.monitor.dump.cluster; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.dump.Dump; import org.elasticsearch.monitor.dump.DumpContributionFailedException; import org.elasticsearch.monitor.dump.DumpContributor; -import org.elasticsearch.util.settings.Settings; import java.io.PrintWriter; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/heap/HeapDumpContributor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/heap/HeapDumpContributor.java index b6b4bfb51da..0cd39997400 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/heap/HeapDumpContributor.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/heap/HeapDumpContributor.java @@ -19,12 +19,12 @@ package org.elasticsearch.monitor.dump.heap; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.dump.Dump; import org.elasticsearch.monitor.dump.DumpContributionFailedException; import org.elasticsearch.monitor.dump.DumpContributor; -import org.elasticsearch.util.settings.Settings; import java.lang.reflect.Method; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/summary/SummaryDumpContributor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/summary/SummaryDumpContributor.java index b46dce7cf84..f953c5ad0ed 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/summary/SummaryDumpContributor.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/summary/SummaryDumpContributor.java @@ -19,12 +19,12 @@ package org.elasticsearch.monitor.dump.summary; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.dump.Dump; import org.elasticsearch.monitor.dump.DumpContributionFailedException; import org.elasticsearch.monitor.dump.DumpContributor; -import org.elasticsearch.util.settings.Settings; import java.io.PrintWriter; import java.text.DateFormat; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/thread/ThreadDumpContributor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/thread/ThreadDumpContributor.java index 28c23df5d26..a9131326f98 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/thread/ThreadDumpContributor.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/thread/ThreadDumpContributor.java @@ -19,12 +19,12 @@ package org.elasticsearch.monitor.dump.thread; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.dump.Dump; import org.elasticsearch.monitor.dump.DumpContributionFailedException; import org.elasticsearch.monitor.dump.DumpContributor; -import org.elasticsearch.util.settings.Settings; import java.io.PrintWriter; import java.lang.management.ManagementFactory; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/DeadlockAnalyzer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/DeadlockAnalyzer.java index cacca4f9afa..edc33925018 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/DeadlockAnalyzer.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/DeadlockAnalyzer.java @@ -19,8 +19,8 @@ package org.elasticsearch.monitor.jvm; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.ImmutableSet; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.ImmutableSet; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java index b382c3a5e0c..8de2c0fdb88 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java @@ -19,11 +19,11 @@ package org.elasticsearch.monitor.jvm; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.io.Serializable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmMonitorService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmMonitorService.java index 385243a8759..394e1ac9cab 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmMonitorService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmMonitorService.java @@ -20,14 +20,14 @@ package org.elasticsearch.monitor.jvm; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.collect.ImmutableSet; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.dump.DumpGenerator; import org.elasticsearch.monitor.dump.DumpMonitorService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.HashSet; import java.util.Set; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmService.java index 192e040a8e3..81a7e5f448b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmService.java @@ -19,9 +19,9 @@ package org.elasticsearch.monitor.jvm; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java index 0cc5227b669..8f0eda021d0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java @@ -19,14 +19,14 @@ package org.elasticsearch.monitor.jvm; +import org.elasticsearch.common.collect.Iterators; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.collect.Iterators; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.io.Serializable; @@ -175,7 +175,7 @@ public class JvmStats implements Streamable, Serializable, ToXContent { builder.endObject(); } builder.endObject(); - + builder.endObject(); } builder.endObject(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/MemoryMonitor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/MemoryMonitor.java index 451a1729c80..de520071275 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/MemoryMonitor.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/MemoryMonitor.java @@ -19,7 +19,7 @@ package org.elasticsearch.monitor.memory; -import org.elasticsearch.util.component.LifecycleComponent; +import org.elasticsearch.common.component.LifecycleComponent; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/MemoryMonitorService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/MemoryMonitorService.java index 9dfe5899d16..f833775aa20 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/MemoryMonitorService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/MemoryMonitorService.java @@ -19,10 +19,10 @@ package org.elasticsearch.monitor.memory; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/alpha/AlphaMemoryMonitor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/alpha/AlphaMemoryMonitor.java index ecd97b003b0..17d00a05078 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/alpha/AlphaMemoryMonitor.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/alpha/AlphaMemoryMonitor.java @@ -20,15 +20,15 @@ package org.elasticsearch.monitor.memory.alpha; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.IndicesMemoryCleaner; import org.elasticsearch.monitor.memory.MemoryMonitor; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.atomic.AtomicLong; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/JmxNetworkProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/JmxNetworkProbe.java index 86d800b5a36..de02f3071ca 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/JmxNetworkProbe.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/JmxNetworkProbe.java @@ -19,9 +19,9 @@ package org.elasticsearch.monitor.network; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java index 9fe0b7f4857..7bffc0ef1d1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java @@ -19,11 +19,11 @@ package org.elasticsearch.monitor.network; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.io.Serializable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java index 99b7c9a891f..ebf89502865 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java @@ -19,9 +19,9 @@ package org.elasticsearch.monitor.network; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import java.net.InetAddress; import java.net.NetworkInterface; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java index 1c514451442..f9fd238ed18 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java @@ -19,11 +19,11 @@ package org.elasticsearch.monitor.network; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.io.Serializable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java index 5d77d191370..13da16451e9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java @@ -19,10 +19,10 @@ package org.elasticsearch.monitor.network; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.sigar.SigarService; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import org.hyperic.sigar.*; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/JmxOsProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/JmxOsProbe.java index 5dda17c193a..154674ad15f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/JmxOsProbe.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/JmxOsProbe.java @@ -19,9 +19,9 @@ package org.elasticsearch.monitor.os; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java index 674a56f89d3..2edc5066f1e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java @@ -19,12 +19,12 @@ package org.elasticsearch.monitor.os; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.io.Serializable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java index c1e9268408c..2b93c04e41d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java @@ -19,9 +19,9 @@ package org.elasticsearch.monitor.os; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java index 02b947b50ac..c1fd3d1a79d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java @@ -19,13 +19,13 @@ package org.elasticsearch.monitor.os; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.io.Serializable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java index 6b086f61a32..fe4be53607c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java @@ -19,10 +19,10 @@ package org.elasticsearch.monitor.os; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.sigar.SigarService; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import org.hyperic.sigar.*; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/JmxProcessProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/JmxProcessProbe.java index bf39f636050..18056edc14c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/JmxProcessProbe.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/JmxProcessProbe.java @@ -19,9 +19,9 @@ package org.elasticsearch.monitor.process; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import static org.elasticsearch.monitor.jvm.JvmInfo.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java index aec28673814..4c51b3fddd0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java @@ -19,11 +19,11 @@ package org.elasticsearch.monitor.process; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.io.Serializable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java index 92dfd88dc26..8301a152158 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java @@ -19,9 +19,9 @@ package org.elasticsearch.monitor.process; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java index 0b8d75c5609..590b84e7307 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java @@ -19,13 +19,13 @@ package org.elasticsearch.monitor.process; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.io.Serializable; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java index 11eeba531aa..ae4b1eb8fff 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java @@ -19,10 +19,10 @@ package org.elasticsearch.monitor.process; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.monitor.sigar.SigarService; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import org.hyperic.sigar.*; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/sigar/SigarService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/sigar/SigarService.java index 348b39cbf42..3bbed4774e2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/sigar/SigarService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/sigar/SigarService.java @@ -19,9 +19,9 @@ package org.elasticsearch.monitor.sigar; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.hyperic.sigar.Sigar; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/node/Node.java b/modules/elasticsearch/src/main/java/org/elasticsearch/node/Node.java index bc26e622c0e..3efe6ce11c5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/node/Node.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/node/Node.java @@ -20,7 +20,7 @@ package org.elasticsearch.node; import org.elasticsearch.client.Client; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.settings.Settings; /** * A node represent a node within a cluster (cluster.name). The {@link #client()} can be used diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/node/NodeBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/node/NodeBuilder.java index 09b281bafb7..6942edadd9e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/node/NodeBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/node/NodeBuilder.java @@ -19,9 +19,9 @@ package org.elasticsearch.node; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.internal.InternalNode; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; /** * A node builder is used to construct a {@link Node} instance. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalNode.java b/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalNode.java index eea1d87b613..17119608727 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalNode.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalNode.java @@ -29,6 +29,20 @@ import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.ClusterNameModule; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.routing.RoutingService; +import org.elasticsearch.common.component.Lifecycle; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.http.client.HttpClientModule; +import org.elasticsearch.common.http.client.HttpClientService; +import org.elasticsearch.common.inject.Guice; +import org.elasticsearch.common.inject.Injector; +import org.elasticsearch.common.inject.Injectors; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.network.NetworkModule; +import org.elasticsearch.common.network.NetworkService; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.DiscoveryService; import org.elasticsearch.env.Environment; @@ -61,27 +75,13 @@ import org.elasticsearch.transport.TransportModule; import org.elasticsearch.transport.TransportService; import org.elasticsearch.util.ThreadLocals; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.component.Lifecycle; -import org.elasticsearch.util.component.LifecycleComponent; -import org.elasticsearch.util.guice.Injectors; -import org.elasticsearch.util.http.HttpClientModule; -import org.elasticsearch.util.http.HttpClientService; -import org.elasticsearch.util.inject.Guice; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Module; import org.elasticsearch.util.io.FileSystemUtils; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.network.NetworkModule; -import org.elasticsearch.util.network.NetworkService; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsModule; import java.io.File; import java.util.ArrayList; import java.util.concurrent.TimeUnit; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalSettingsPerparer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalSettingsPerparer.java index 127bddb18b1..958e109e569 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalSettingsPerparer.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/InternalSettingsPerparer.java @@ -20,15 +20,15 @@ package org.elasticsearch.node.internal; import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.env.FailedToResolveConfigException; import org.elasticsearch.util.Names; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.elasticsearch.util.Strings.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/NodeModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/NodeModule.java index 354342aba6a..a8ad23feea5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/NodeModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/node/internal/NodeModule.java @@ -19,7 +19,7 @@ package org.elasticsearch.node.internal; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.node.Node; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java index 789def5becf..7aa8c7c29d5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/AbstractPlugin.java @@ -19,10 +19,10 @@ package org.elasticsearch.plugins; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.component.CloseableIndexComponent; -import org.elasticsearch.util.component.LifecycleComponent; -import org.elasticsearch.util.inject.Module; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.component.CloseableIndexComponent; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.inject.Module; import java.util.Collection; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/IndicesPluginsModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/IndicesPluginsModule.java index 3f6d11ec8d3..bb580ec1515 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/IndicesPluginsModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/IndicesPluginsModule.java @@ -19,13 +19,13 @@ package org.elasticsearch.plugins; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import java.util.Collection; -import static org.elasticsearch.util.guice.ModulesFactory.*; +import static org.elasticsearch.common.inject.ModulesFactory.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/Plugin.java b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/Plugin.java index 7150003e61c..659aee468be 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/Plugin.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/Plugin.java @@ -19,9 +19,9 @@ package org.elasticsearch.plugins; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.component.CloseableIndexComponent; -import org.elasticsearch.util.component.LifecycleComponent; +import org.elasticsearch.common.component.CloseableIndexComponent; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.inject.Module; import java.util.Collection; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginManager.java b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginManager.java index bebc2abc5c2..ae96c6f20bd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginManager.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginManager.java @@ -1,19 +1,19 @@ package org.elasticsearch.plugins; import org.elasticsearch.Version; +import org.elasticsearch.common.http.client.HttpDownloadHelper; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.node.internal.InternalSettingsPerparer; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.http.HttpDownloadHelper; import org.elasticsearch.util.io.FileSystemUtils; -import org.elasticsearch.util.settings.Settings; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginsModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginsModule.java index 7a33b3ee3e6..7ad1886abc8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginsModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginsModule.java @@ -19,13 +19,13 @@ package org.elasticsearch.plugins; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import java.util.Collection; -import static org.elasticsearch.util.guice.ModulesFactory.*; +import static org.elasticsearch.common.inject.ModulesFactory.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginsService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginsService.java index 72099f95321..4d6692f9897 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -20,17 +20,17 @@ package org.elasticsearch.plugins; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.collect.Maps; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.component.CloseableIndexComponent; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.component.CloseableIndexComponent; -import org.elasticsearch.util.component.LifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.Module; import org.elasticsearch.util.io.Streams; -import org.elasticsearch.util.settings.Settings; import java.io.*; import java.lang.reflect.Method; @@ -39,7 +39,7 @@ import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Maps.*; import static org.elasticsearch.util.io.FileSystemUtils.*; /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java index a7b2fa70fae..9314d92edbe 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/plugins/ShardsPluginsModule.java @@ -19,13 +19,13 @@ package org.elasticsearch.plugins; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import java.util.Collection; -import static org.elasticsearch.util.guice.ModulesFactory.*; +import static org.elasticsearch.common.inject.ModulesFactory.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/BaseRestHandler.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/BaseRestHandler.java index 38f8ed33040..a689208dbb4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/BaseRestHandler.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/BaseRestHandler.java @@ -20,8 +20,8 @@ package org.elasticsearch.rest; import org.elasticsearch.client.Client; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestController.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestController.java index d9a267a9594..d066f7fef7c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestController.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestController.java @@ -21,10 +21,10 @@ package org.elasticsearch.rest; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalArgumentException; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.path.PathTrie; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.path.PathTrie; +import org.elasticsearch.common.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestModule.java index 8863d605113..b5e70defd77 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestModule.java @@ -19,9 +19,9 @@ package org.elasticsearch.rest; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.action.RestActionModule; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java index 36db4e958b2..4b32d8ff8fe 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/RestRequest.java @@ -19,9 +19,9 @@ package org.elasticsearch.rest; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.xcontent.ToXContent; import java.util.List; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/XContentRestResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/XContentRestResponse.java index d5eea173e8c..36cf0180102 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/XContentRestResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/XContentRestResponse.java @@ -20,8 +20,8 @@ package org.elasticsearch.rest; import org.apache.lucene.util.UnicodeUtil; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.util.ThreadLocals; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/XContentThrowableRestResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/XContentThrowableRestResponse.java index 78b341034d2..de089d83152 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/XContentThrowableRestResponse.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/XContentThrowableRestResponse.java @@ -19,7 +19,7 @@ package org.elasticsearch.rest; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java index 169848a3d93..659f5f17632 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.rest.action.admin.cluster.health.RestClusterHealthAction; import org.elasticsearch.rest.action.admin.cluster.node.info.RestNodesInfoAction; import org.elasticsearch.rest.action.admin.cluster.node.restart.RestNodesRestartAction; @@ -48,7 +49,6 @@ import org.elasticsearch.rest.action.mlt.RestMoreLikeThisAction; import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.rest.action.search.RestSearchScrollAction; import org.elasticsearch.rest.action.terms.RestTermsAction; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java index 140e41b105d..037ff0c32e2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/health/RestClusterHealthAction.java @@ -22,12 +22,12 @@ package org.elasticsearch.rest.action.admin.cluster.health; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.health.*; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java index e031d06f791..7c415c92345 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java @@ -24,13 +24,13 @@ import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsFilter; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/restart/RestNodesRestartAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/restart/RestNodesRestartAction.java index a0976d46c1c..acaffd29020 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/restart/RestNodesRestartAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/restart/RestNodesRestartAction.java @@ -23,11 +23,11 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartRequest; import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java index 71ed761f203..8b9784bcde0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java @@ -23,11 +23,11 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRequest; import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java index afd38c3648f..6dc8ef80845 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/broadcast/RestBroadcastPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/broadcast/RestBroadcastPingAction.java index 6694a342790..3007306e65c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/broadcast/RestBroadcastPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/broadcast/RestBroadcastPingAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingReques import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingResponse; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/replication/RestReplicationPingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/replication/RestReplicationPingAction.java index 4012ba42891..9d056d79f0f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/replication/RestReplicationPingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/replication/RestReplicationPingAction.java @@ -26,12 +26,12 @@ import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingRe import org.elasticsearch.action.admin.cluster.ping.replication.ShardReplicationPingRequest; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/single/RestSinglePingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/single/RestSinglePingAction.java index 6cb2c92ccef..c7ded93fd32 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/single/RestSinglePingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/ping/single/RestSinglePingAction.java @@ -23,11 +23,11 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java index 1844a378600..781e460a739 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java @@ -30,12 +30,12 @@ import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsFilter; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java index fee8e839a58..9b8ada01072 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestIndicesAliasesAction.java @@ -25,12 +25,12 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.AliasAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java index 8d85e59ca68..985df3f3d85 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheReque import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java index 1414f9d6967..4f6a7d0d2af 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/create/RestCreateIndexAction.java @@ -23,16 +23,16 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsException; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.indices.InvalidIndexNameException; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.Strings; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsException; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java index 9ab1acb6213..dc4d3917ad9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/delete/RestDeleteIndexAction.java @@ -23,12 +23,12 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java index b93b9aa754b..adc209ba8e1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/flush/RestFlushAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java index 4304000fc3d..e3ab542d801 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/gateway/snapshot/RestGatewaySnapshotAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRe import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotResponse; import org.elasticsearch.action.admin.indices.gateway.snapshot.IndexGatewaySnapshotResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java index 4a144f8881f..185b8353a7b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/put/RestPutMappingAction.java @@ -23,14 +23,14 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.mapper.InvalidTypeNameException; import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java index a711af7500a..ca42609bbca 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/optimize/RestOptimizeAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java index 85745808d37..5cd1100f02c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/refresh/RestRefreshAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java index 2616706de80..7b6c5e4bfb6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java @@ -23,12 +23,12 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.status.*; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsFilter; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java index 2febcc98cfa..190750d558a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/count/RestCountAction.java @@ -24,12 +24,12 @@ import org.elasticsearch.action.count.CountRequest; import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java index 30be159558f..65f2c267214 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/delete/RestDeleteAction.java @@ -24,11 +24,11 @@ import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java index 7a197d4ae26..cfb06143a14 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java @@ -26,12 +26,12 @@ import org.elasticsearch.action.deletebyquery.IndexDeleteByQueryResponse; import org.elasticsearch.action.deletebyquery.ShardDeleteByQueryRequest; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java index 9845980fca1..e3a831298c3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/get/RestGetAction.java @@ -24,11 +24,11 @@ import org.elasticsearch.action.get.GetField; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.regex.Pattern; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java index 0ddb0b290fe..c24c2192b69 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/index/RestIndexAction.java @@ -24,11 +24,11 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.support.replication.ReplicationType; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java index 5838af85acc..6eb5a1f294b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java @@ -21,16 +21,16 @@ package org.elasticsearch.rest.action.main; import org.elasticsearch.Version; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; import org.elasticsearch.util.Classes; import org.elasticsearch.util.concurrent.jsr166y.ThreadLocalRandom; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java index a260b15f063..bc645da13e7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/mlt/RestMoreLikeThisAction.java @@ -24,11 +24,11 @@ import org.elasticsearch.action.mlt.MoreLikeThisRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.search.Scroll; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 50eaab2792a..02296804024 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -25,15 +25,15 @@ import org.elasticsearch.action.search.SearchOperationThreading; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.query.xcontent.QueryBuilders; import org.elasticsearch.index.query.xcontent.QueryStringQueryBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.regex.Pattern; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java index 0998d3439bb..2a15b69e55b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java @@ -24,11 +24,11 @@ import org.elasticsearch.action.search.SearchOperationThreading; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchScrollRequest; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.search.Scroll; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java index c22b27ad286..8849e9e4f68 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java @@ -22,11 +22,11 @@ package org.elasticsearch.rest.action.support; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.query.xcontent.QueryBuilders; import org.elasticsearch.index.query.xcontent.QueryStringQueryBuilder; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.util.Strings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.regex.Pattern; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java index 5305b2d5253..ab757274569 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestXContentBuilder.java @@ -19,11 +19,11 @@ package org.elasticsearch.rest.action.support; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/terms/RestTermsAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/terms/RestTermsAction.java index f77a47f516f..b69061ec1e8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/terms/RestTermsAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/terms/RestTermsAction.java @@ -26,11 +26,11 @@ import org.elasticsearch.action.terms.TermFreq; import org.elasticsearch.action.terms.TermsRequest; import org.elasticsearch.action.terms.TermsResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.rest.*; import org.elasticsearch.rest.action.support.RestXContentBuilder; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.regex.Pattern; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/script/ScriptModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/script/ScriptModule.java index 42326d1f0e9..51ab4789641 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/script/ScriptModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/script/ScriptModule.java @@ -19,7 +19,7 @@ package org.elasticsearch.script; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/script/ScriptService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/script/ScriptService.java index 51a80a3349a..f88032cd528 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/script/ScriptService.java @@ -19,13 +19,13 @@ package org.elasticsearch.script; -import org.elasticsearch.util.component.AbstractComponent; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.mvel2.MVEL; +import org.elasticsearch.common.mvel2.ParserContext; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.concurrent.ConcurrentCollections; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.math.UnboxedMathUtils; -import org.elasticsearch.util.settings.Settings; -import org.mvel2.MVEL; -import org.mvel2.ParserContext; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -47,7 +47,7 @@ public class ScriptService extends AbstractComponent { parserContext = new ParserContext(); parserContext.addPackageImport("java.util"); parserContext.addPackageImport("org.elasticsearch.util.gnu.trove"); - parserContext.addPackageImport("org.elasticsearch.util.joda"); + parserContext.addPackageImport("org.elasticsearch.common.joda"); parserContext.addImport("time", MVEL.getStaticMethod(System.class, "currentTimeMillis", new Class[0])); // unboxed version of Math, better performance since conversion from boxed to unboxed my mvel is not needed for (Method m : UnboxedMathUtils.class.getMethods()) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHit.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHit.java index 0b653ea0fbf..d25cc8657ce 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHit.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHit.java @@ -21,9 +21,9 @@ package org.elasticsearch.search; import org.apache.lucene.search.Explanation; import org.elasticsearch.ElasticSearchParseException; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.search.highlight.HighlightField; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHits.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHits.java index 8a8e895596c..e7dcffb76ce 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHits.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchHits.java @@ -19,8 +19,8 @@ package org.elasticsearch.search; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; /** * The hits of a search request. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchModule.java index 45652e1b8ce..3817cd12663 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchModule.java @@ -19,6 +19,7 @@ package org.elasticsearch.search; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.dfs.DfsPhase; @@ -26,7 +27,6 @@ import org.elasticsearch.search.facets.FacetsPhase; import org.elasticsearch.search.fetch.FetchPhase; import org.elasticsearch.search.highlight.HighlightPhase; import org.elasticsearch.search.query.QueryPhase; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchParseElement.java index 6a620bd73b9..e740487de1d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchParseElement.java @@ -19,8 +19,8 @@ package org.elasticsearch.search; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.xcontent.XContentParser; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java index b5a5da130d0..fa6b0c447f7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java @@ -22,6 +22,14 @@ package org.elasticsearch.search; import org.apache.lucene.search.TopDocs; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.timer.Timeout; +import org.elasticsearch.common.timer.TimerTask; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.Index; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.service.IndexService; @@ -47,16 +55,8 @@ import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.timer.TimerService; import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.component.AbstractLifecycleComponent; import org.elasticsearch.util.concurrent.ConcurrentCollections; import org.elasticsearch.util.concurrent.ConcurrentMapLong; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.timer.Timeout; -import org.elasticsearch.util.timer.TimerTask; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; import java.io.IOException; import java.util.HashMap; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/action/SearchServiceTransportAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/action/SearchServiceTransportAction.java index 467a063ba1a..752100c4771 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/action/SearchServiceTransportAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/action/SearchServiceTransportAction.java @@ -21,6 +21,10 @@ package org.elasticsearch.search.action; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.search.SearchService; import org.elasticsearch.search.dfs.DfsSearchResult; import org.elasticsearch.search.fetch.FetchSearchRequest; @@ -31,12 +35,8 @@ import org.elasticsearch.search.internal.InternalSearchRequest; import org.elasticsearch.search.query.QuerySearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.transport.*; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.LongStreamable; import org.elasticsearch.util.io.stream.VoidStreamable; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.settings.Settings; /** * An encapsulation of {@link org.elasticsearch.search.SearchService} operations exposed through diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 42d2ba5300b..6e678a7d415 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -19,23 +19,23 @@ package org.elasticsearch.search.builder; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.trove.TObjectFloatHashMap; +import org.elasticsearch.common.trove.TObjectFloatIterator; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.query.xcontent.XContentQueryBuilder; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.gnu.trove.TObjectFloatHashMap; -import org.elasticsearch.util.gnu.trove.TObjectFloatIterator; import org.elasticsearch.util.io.FastByteArrayOutputStream; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * A search source builder allowing to easily build search source. Simple construction diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceFacetsBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceFacetsBuilder.java index b89718b4327..798738a4305 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceFacetsBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceFacetsBuilder.java @@ -19,6 +19,8 @@ package org.elasticsearch.search.builder; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.query.xcontent.XContentFilterBuilder; import org.elasticsearch.index.query.xcontent.XContentQueryBuilder; import org.elasticsearch.search.facets.histogram.HistogramFacet; @@ -26,14 +28,12 @@ import org.elasticsearch.search.facets.histogram.HistogramFacetCollectorParser; import org.elasticsearch.search.facets.query.QueryFacetCollectorParser; import org.elasticsearch.search.facets.statistical.StatisticalFacetCollectorParser; import org.elasticsearch.search.facets.terms.TermsFacetCollectorParser; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import javax.annotation.Nullable; import java.io.IOException; import java.util.List; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * A search source facets builder. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceHighlightBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceHighlightBuilder.java index abba6c27ce0..cb76c5fdd14 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceHighlightBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/builder/SearchSourceHighlightBuilder.java @@ -19,13 +19,13 @@ package org.elasticsearch.search.builder; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.List; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * A builder for search highlighting. diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java index b51a3c9b768..2b11ae23f48 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java @@ -25,6 +25,11 @@ import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.ShardFieldDocSortedHitQueue; import org.apache.lucene.search.TopFieldDocs; import org.apache.lucene.util.PriorityQueue; +import org.elasticsearch.common.collect.Iterables; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.collect.Maps; +import org.elasticsearch.common.trove.ExtTIntArrayList; +import org.elasticsearch.common.trove.ExtTObjectIntHasMap; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.dfs.AggregatedDfs; import org.elasticsearch.search.dfs.DfsSearchResult; @@ -38,11 +43,6 @@ import org.elasticsearch.search.internal.InternalSearchHits; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; -import org.elasticsearch.util.collect.Iterables; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.trove.ExtTIntArrayList; -import org.elasticsearch.util.trove.ExtTObjectIntHasMap; import java.util.ArrayList; import java.util.Collection; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/dfs/AggregatedDfs.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/dfs/AggregatedDfs.java index 22fd6bf810e..fb199a20af0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/dfs/AggregatedDfs.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/dfs/AggregatedDfs.java @@ -20,11 +20,11 @@ package org.elasticsearch.search.dfs; import org.apache.lucene.index.Term; -import org.elasticsearch.util.gnu.trove.TObjectIntProcedure; +import org.elasticsearch.common.trove.ExtTObjectIntHasMap; +import org.elasticsearch.common.trove.TObjectIntProcedure; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.trove.ExtTObjectIntHasMap; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java index 25857182fd0..78959cb4962 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java @@ -20,12 +20,12 @@ package org.elasticsearch.search.dfs; import org.apache.lucene.index.Term; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.trove.THashSet; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchPhase; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.util.ThreadLocals; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.gnu.trove.THashSet; import java.util.Map; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsParseElement.java index 1f4b45c63e7..6bdf3f4fc43 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsParseElement.java @@ -20,6 +20,9 @@ package org.elasticsearch.search.facets; import org.apache.lucene.search.Filter; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.xcontent.XContentIndexQueryParser; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchParseException; @@ -31,9 +34,6 @@ import org.elasticsearch.search.facets.statistical.StatisticalFacetCollectorPars import org.elasticsearch.search.facets.terms.TermsFacetCollectorParser; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.util.MapBuilder; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.xcontent.XContentParser; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsPhase.java index 73a34b0de37..4e383a3610d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/FacetsPhase.java @@ -21,6 +21,11 @@ package org.elasticsearch.search.facets; import org.apache.lucene.search.*; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.lucene.search.NoopCollector; +import org.elasticsearch.common.lucene.search.Queries; +import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchPhase; @@ -28,11 +33,6 @@ import org.elasticsearch.search.facets.collector.FacetCollector; import org.elasticsearch.search.facets.internal.InternalFacets; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.query.QueryPhaseExecutionException; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.lucene.search.NoopCollector; -import org.elasticsearch.util.lucene.search.Queries; -import org.elasticsearch.util.lucene.search.TermFilter; import java.io.IOException; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/FacetCollectorParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/FacetCollectorParser.java index 546b2b2071f..b7c971cd9cb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/FacetCollectorParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/collector/FacetCollectorParser.java @@ -19,8 +19,8 @@ package org.elasticsearch.search.facets.collector; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.xcontent.XContentParser; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/HistogramFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/HistogramFacetCollector.java index 754bffb1b63..f9b4eb6d278 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/HistogramFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/HistogramFacetCollector.java @@ -20,6 +20,8 @@ package org.elasticsearch.search.facets.histogram; import org.apache.lucene.index.IndexReader; +import org.elasticsearch.common.trove.TLongDoubleHashMap; +import org.elasticsearch.common.trove.TLongLongHashMap; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.field.data.NumericFieldData; @@ -28,8 +30,6 @@ import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.search.facets.Facet; import org.elasticsearch.search.facets.FacetPhaseExecutionException; import org.elasticsearch.search.facets.support.AbstractFacetCollector; -import org.elasticsearch.util.gnu.trove.TLongDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TLongLongHashMap; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/HistogramFacetCollectorParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/HistogramFacetCollectorParser.java index 990c689bc26..f51e4b79809 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/HistogramFacetCollectorParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/HistogramFacetCollectorParser.java @@ -19,12 +19,12 @@ package org.elasticsearch.search.facets.histogram; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.facets.FacetPhaseExecutionException; import org.elasticsearch.search.facets.collector.FacetCollector; import org.elasticsearch.search.facets.collector.FacetCollectorParser; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.xcontent.XContentParser; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/InternalHistogramFacet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/InternalHistogramFacet.java index 154bda7bd3a..c10a1dbd585 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/InternalHistogramFacet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/InternalHistogramFacet.java @@ -19,16 +19,16 @@ package org.elasticsearch.search.facets.histogram; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.trove.TLongDoubleHashMap; +import org.elasticsearch.common.trove.TLongDoubleIterator; +import org.elasticsearch.common.trove.TLongLongHashMap; +import org.elasticsearch.common.trove.TLongLongIterator; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.facets.Facet; import org.elasticsearch.search.facets.internal.InternalFacet; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.gnu.trove.TLongDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TLongDoubleIterator; -import org.elasticsearch.util.gnu.trove.TLongLongHashMap; -import org.elasticsearch.util.gnu.trove.TLongLongIterator; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Collection; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/KeyValueHistogramFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/KeyValueHistogramFacetCollector.java index d390a713d1b..7f0c680f8fa 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/KeyValueHistogramFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/histogram/KeyValueHistogramFacetCollector.java @@ -20,6 +20,8 @@ package org.elasticsearch.search.facets.histogram; import org.apache.lucene.index.IndexReader; +import org.elasticsearch.common.trove.TLongDoubleHashMap; +import org.elasticsearch.common.trove.TLongLongHashMap; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.field.data.NumericFieldData; @@ -28,8 +30,6 @@ import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.search.facets.Facet; import org.elasticsearch.search.facets.FacetPhaseExecutionException; import org.elasticsearch.search.facets.support.AbstractFacetCollector; -import org.elasticsearch.util.gnu.trove.TLongDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TLongLongHashMap; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/internal/InternalFacet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/internal/InternalFacet.java index 4a37db8e5ef..4b514339a3b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/internal/InternalFacet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/internal/InternalFacet.java @@ -19,9 +19,9 @@ package org.elasticsearch.search.facets.internal; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.search.facets.Facet; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/internal/InternalFacets.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/internal/InternalFacets.java index 0ada723ce16..d4c8014ad15 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/internal/InternalFacets.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/internal/InternalFacets.java @@ -19,27 +19,27 @@ package org.elasticsearch.search.facets.internal; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.facets.Facet; import org.elasticsearch.search.facets.Facets; import org.elasticsearch.search.facets.histogram.InternalHistogramFacet; import org.elasticsearch.search.facets.query.InternalQueryFacet; import org.elasticsearch.search.facets.statistical.InternalStatisticalFacet; import org.elasticsearch.search.facets.terms.InternalTermsFacet; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Lists; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Maps.*; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/InternalQueryFacet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/InternalQueryFacet.java index 6baa2b28209..5e91ddcc34f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/InternalQueryFacet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/InternalQueryFacet.java @@ -19,11 +19,11 @@ package org.elasticsearch.search.facets.query; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.facets.Facet; import org.elasticsearch.search.facets.internal.InternalFacet; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/QueryFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/QueryFacetCollector.java index 20cb3d521bf..2cb01805884 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/QueryFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/QueryFacetCollector.java @@ -23,11 +23,11 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.apache.lucene.search.QueryWrapperFilter; +import org.elasticsearch.common.lucene.docset.DocSet; +import org.elasticsearch.common.lucene.docset.DocSets; import org.elasticsearch.index.cache.filter.FilterCache; import org.elasticsearch.search.facets.Facet; import org.elasticsearch.search.facets.support.AbstractFacetCollector; -import org.elasticsearch.util.lucene.docset.DocSet; -import org.elasticsearch.util.lucene.docset.DocSets; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/QueryFacetCollectorParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/QueryFacetCollectorParser.java index 284447f38a1..e7f25671acf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/QueryFacetCollectorParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/query/QueryFacetCollectorParser.java @@ -20,11 +20,11 @@ package org.elasticsearch.search.facets.query; import org.apache.lucene.search.Query; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.xcontent.XContentIndexQueryParser; import org.elasticsearch.search.facets.collector.FacetCollector; import org.elasticsearch.search.facets.collector.FacetCollectorParser; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.xcontent.XContentParser; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/statistical/InternalStatisticalFacet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/statistical/InternalStatisticalFacet.java index 65acc98bc43..e22af6a7066 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/statistical/InternalStatisticalFacet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/statistical/InternalStatisticalFacet.java @@ -19,11 +19,11 @@ package org.elasticsearch.search.facets.statistical; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.facets.Facet; import org.elasticsearch.search.facets.internal.InternalFacet; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/statistical/StatisticalFacetCollectorParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/statistical/StatisticalFacetCollectorParser.java index dbeece158d8..4a95e523aa9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/statistical/StatisticalFacetCollectorParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/statistical/StatisticalFacetCollectorParser.java @@ -19,10 +19,10 @@ package org.elasticsearch.search.facets.statistical; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.facets.collector.FacetCollector; import org.elasticsearch.search.facets.collector.FacetCollectorParser; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.xcontent.XContentParser; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/support/AbstractFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/support/AbstractFacetCollector.java index 4f40ae61c3c..fc854bfa817 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/support/AbstractFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/support/AbstractFacetCollector.java @@ -22,9 +22,9 @@ package org.elasticsearch.search.facets.support; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Filter; import org.apache.lucene.search.Scorer; +import org.elasticsearch.common.lucene.docset.DocSet; +import org.elasticsearch.common.lucene.docset.DocSets; import org.elasticsearch.search.facets.collector.FacetCollector; -import org.elasticsearch.util.lucene.docset.DocSet; -import org.elasticsearch.util.lucene.docset.DocSets; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/InternalTermsFacet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/InternalTermsFacet.java index 5e297ba4974..a34259ff7c4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/InternalTermsFacet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/InternalTermsFacet.java @@ -19,16 +19,16 @@ package org.elasticsearch.search.facets.terms; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.trove.TObjectIntHashMap; +import org.elasticsearch.common.trove.TObjectIntIterator; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.facets.Facet; import org.elasticsearch.search.facets.internal.InternalFacet; import org.elasticsearch.util.BoundedTreeSet; import org.elasticsearch.util.ThreadLocals; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.gnu.trove.TObjectIntHashMap; -import org.elasticsearch.util.gnu.trove.TObjectIntIterator; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.ArrayList; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/TermsFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/TermsFacetCollector.java index ef720523d9a..57c31d72ff7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/TermsFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/TermsFacetCollector.java @@ -20,6 +20,9 @@ package org.elasticsearch.search.facets.terms; import org.apache.lucene.index.IndexReader; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.trove.TObjectIntHashMap; +import org.elasticsearch.common.trove.TObjectIntIterator; import org.elasticsearch.index.cache.field.data.FieldDataCache; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.index.mapper.FieldMapper; @@ -28,9 +31,6 @@ import org.elasticsearch.search.facets.Facet; import org.elasticsearch.search.facets.support.AbstractFacetCollector; import org.elasticsearch.util.BoundedTreeSet; import org.elasticsearch.util.ThreadLocals; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.gnu.trove.TObjectIntHashMap; -import org.elasticsearch.util.gnu.trove.TObjectIntIterator; import java.io.IOException; import java.util.ArrayDeque; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/TermsFacetCollectorParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/TermsFacetCollectorParser.java index 259faa57963..845aacc1cca 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/TermsFacetCollectorParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facets/terms/TermsFacetCollectorParser.java @@ -19,10 +19,10 @@ package org.elasticsearch.search.facets.terms; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.facets.collector.FacetCollector; import org.elasticsearch.search.facets.collector.FacetCollectorParser; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.xcontent.XContentParser; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/ExplainParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/ExplainParseElement.java index cc2121172f0..956ba758306 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/ExplainParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/ExplainParseElement.java @@ -19,9 +19,9 @@ package org.elasticsearch.search.fetch; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.xcontent.XContentParser; /** * @author kimchy (shay.banon) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java index 609dd1450e0..97adfdbf328 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java @@ -23,6 +23,8 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldSelector; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.IndexReader; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.inject.Inject; import org.elasticsearch.index.mapper.*; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchParseElement; @@ -34,8 +36,6 @@ import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.InternalSearchHitField; import org.elasticsearch.search.internal.InternalSearchHits; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.inject.Inject; import java.io.IOException; import java.util.ArrayList; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java index 8b93d57accd..b1f683b697e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FetchSearchRequest.java @@ -19,10 +19,10 @@ package org.elasticsearch.search.fetch; +import org.elasticsearch.common.trove.ExtTIntArrayList; import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.Streamable; -import org.elasticsearch.util.trove.ExtTIntArrayList; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FieldsParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FieldsParseElement.java index b9c11369549..282c678f016 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FieldsParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/FieldsParseElement.java @@ -19,10 +19,10 @@ package org.elasticsearch.search.fetch; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.xcontent.XContentParser; import java.util.ArrayList; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsParseElement.java index 36d7f569a3c..2c4838e9f60 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/fetch/script/ScriptFieldsParseElement.java @@ -19,11 +19,11 @@ package org.elasticsearch.search.fetch.script; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.field.function.script.ScriptFieldsFunction; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.xcontent.XContentParser; import java.util.HashMap; import java.util.List; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java index 926d9b70b4c..4a1a1e73d1e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.highlight; import org.apache.lucene.search.vectorhighlight.*; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.search.SearchHit; @@ -29,7 +30,6 @@ import org.elasticsearch.search.SearchPhase; import org.elasticsearch.search.fetch.FetchPhaseExecutionException; import org.elasticsearch.search.internal.InternalSearchHit; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.collect.ImmutableMap; import java.io.IOException; import java.util.HashMap; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java index 575bd5fcf45..47255a17dd2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlighterParseElement.java @@ -19,15 +19,15 @@ package org.elasticsearch.search.highlight; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.SearchParseElement; import org.elasticsearch.search.SearchParseException; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.xcontent.XContentParser; import java.util.List; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** *

diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java
index b9aefde791f..1be00f814eb 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java
@@ -21,9 +21,9 @@ package org.elasticsearch.search.internal;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.*;
+import org.elasticsearch.common.collect.Lists;
+import org.elasticsearch.common.lucene.MultiCollector;
 import org.elasticsearch.search.dfs.CachedDfSource;
-import org.elasticsearch.util.collect.Lists;
-import org.elasticsearch.util.lucene.MultiCollector;
 
 import java.io.IOException;
 import java.util.List;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java
index d2b4ced5297..76fbc5d519d 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java
@@ -21,28 +21,28 @@ package org.elasticsearch.search.internal;
 
 import org.apache.lucene.search.Explanation;
 import org.elasticsearch.ElasticSearchParseException;
+import org.elasticsearch.common.collect.ImmutableMap;
+import org.elasticsearch.common.trove.TIntObjectHashMap;
+import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.common.xcontent.builder.XContentBuilder;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.SearchHitField;
 import org.elasticsearch.search.SearchShardTarget;
 import org.elasticsearch.search.highlight.HighlightField;
 import org.elasticsearch.util.Unicode;
-import org.elasticsearch.util.collect.ImmutableMap;
-import org.elasticsearch.util.gnu.trove.TIntObjectHashMap;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.StreamOutput;
-import org.elasticsearch.util.xcontent.XContentFactory;
-import org.elasticsearch.util.xcontent.XContentParser;
-import org.elasticsearch.util.xcontent.builder.XContentBuilder;
 
 import javax.annotation.Nullable;
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
 
+import static org.elasticsearch.common.lucene.Lucene.*;
 import static org.elasticsearch.search.SearchShardTarget.*;
 import static org.elasticsearch.search.highlight.HighlightField.*;
 import static org.elasticsearch.search.internal.InternalSearchHitField.*;
-import static org.elasticsearch.util.lucene.Lucene.*;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHitField.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHitField.java
index 486c5e778fb..e3e0cc3bec1 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHitField.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHitField.java
@@ -19,10 +19,10 @@
 
 package org.elasticsearch.search.internal;
 
+import org.elasticsearch.common.lucene.Lucene;
 import org.elasticsearch.search.SearchHitField;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.StreamOutput;
-import org.elasticsearch.util.lucene.Lucene;
 
 import java.io.IOException;
 import java.util.ArrayList;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java
index fb251166566..f91e4f0b6ef 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java
@@ -19,14 +19,14 @@
 
 package org.elasticsearch.search.internal;
 
+import org.elasticsearch.common.collect.Iterators;
+import org.elasticsearch.common.trove.TIntObjectHashMap;
+import org.elasticsearch.common.xcontent.builder.XContentBuilder;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.SearchHits;
 import org.elasticsearch.search.SearchShardTarget;
-import org.elasticsearch.util.collect.Iterators;
-import org.elasticsearch.util.gnu.trove.TIntObjectHashMap;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.StreamOutput;
-import org.elasticsearch.util.xcontent.builder.XContentBuilder;
 
 import java.io.IOException;
 import java.util.IdentityHashMap;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java
index cfe49e66204..3f32f85f4b8 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java
@@ -19,14 +19,14 @@
 
 package org.elasticsearch.search.internal;
 
+import org.elasticsearch.common.xcontent.ToXContent;
+import org.elasticsearch.common.xcontent.builder.XContentBuilder;
 import org.elasticsearch.search.SearchHits;
 import org.elasticsearch.search.facets.Facets;
 import org.elasticsearch.search.facets.internal.InternalFacets;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.StreamOutput;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.elasticsearch.util.xcontent.ToXContent;
-import org.elasticsearch.util.xcontent.builder.XContentBuilder;
 
 import java.io.IOException;
 
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java
index 04f6d8bd294..f36e40bade6 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java
@@ -23,6 +23,7 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.store.AlreadyClosedException;
 import org.elasticsearch.ElasticSearchException;
+import org.elasticsearch.common.timer.Timeout;
 import org.elasticsearch.index.cache.field.data.FieldDataCache;
 import org.elasticsearch.index.cache.filter.FilterCache;
 import org.elasticsearch.index.engine.Engine;
@@ -43,7 +44,6 @@ import org.elasticsearch.search.highlight.SearchContextHighlight;
 import org.elasticsearch.search.query.QuerySearchResult;
 import org.elasticsearch.util.TimeValue;
 import org.elasticsearch.util.lease.Releasable;
-import org.elasticsearch.util.timer.Timeout;
 
 import java.io.IOException;
 import java.util.List;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java
index d47aa19b581..5559f890558 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java
@@ -19,9 +19,9 @@
 
 package org.elasticsearch.search.query;
 
+import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.search.SearchParseElement;
 import org.elasticsearch.search.internal.SearchContext;
-import org.elasticsearch.util.xcontent.XContentParser;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/IndicesBoostParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/IndicesBoostParseElement.java
index 401ae32f64f..f55d343c260 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/IndicesBoostParseElement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/IndicesBoostParseElement.java
@@ -19,9 +19,9 @@
 
 package org.elasticsearch.search.query;
 
+import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.search.SearchParseElement;
 import org.elasticsearch.search.internal.SearchContext;
-import org.elasticsearch.util.xcontent.XContentParser;
 
 /**
  * 
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryParseElement.java
index 75af6efbacf..42beebfa35d 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryParseElement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryParseElement.java
@@ -20,10 +20,10 @@
 package org.elasticsearch.search.query;
 
 import org.apache.lucene.search.Query;
+import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.index.query.xcontent.XContentIndexQueryParser;
 import org.elasticsearch.search.SearchParseElement;
 import org.elasticsearch.search.internal.SearchContext;
-import org.elasticsearch.util.xcontent.XContentParser;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryParserNameParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryParserNameParseElement.java
index f30e9aa9e7a..4075fc7d526 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryParserNameParseElement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryParserNameParseElement.java
@@ -19,9 +19,9 @@
 
 package org.elasticsearch.search.query;
 
+import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.search.SearchParseElement;
 import org.elasticsearch.search.internal.SearchContext;
-import org.elasticsearch.util.xcontent.XContentParser;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java
index 1c992a500b6..f6078fa6bef 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QueryPhase.java
@@ -20,17 +20,17 @@
 package org.elasticsearch.search.query;
 
 import org.apache.lucene.search.*;
+import org.elasticsearch.common.collect.ImmutableMap;
+import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.common.lucene.search.TermFilter;
+import org.elasticsearch.common.lucene.search.function.BoostScoreFunction;
+import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
 import org.elasticsearch.index.mapper.DocumentMapper;
 import org.elasticsearch.search.SearchParseElement;
 import org.elasticsearch.search.SearchParseException;
 import org.elasticsearch.search.SearchPhase;
 import org.elasticsearch.search.facets.FacetsPhase;
 import org.elasticsearch.search.internal.SearchContext;
-import org.elasticsearch.util.collect.ImmutableMap;
-import org.elasticsearch.util.inject.Inject;
-import org.elasticsearch.util.lucene.search.TermFilter;
-import org.elasticsearch.util.lucene.search.function.BoostScoreFunction;
-import org.elasticsearch.util.lucene.search.function.FunctionScoreQuery;
 
 import java.util.Map;
 
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QuerySearchResult.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QuerySearchResult.java
index 3052e77dd88..7f397e1ebda 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QuerySearchResult.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/QuerySearchResult.java
@@ -29,8 +29,8 @@ import org.elasticsearch.util.io.stream.Streamable;
 
 import java.io.IOException;
 
+import static org.elasticsearch.common.lucene.Lucene.*;
 import static org.elasticsearch.search.SearchShardTarget.*;
-import static org.elasticsearch.util.lucene.Lucene.*;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java
index 398796c5e63..2ec0ac26538 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java
@@ -19,9 +19,9 @@
 
 package org.elasticsearch.search.query;
 
+import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.search.SearchParseElement;
 import org.elasticsearch.search.internal.SearchContext;
-import org.elasticsearch.util.xcontent.XContentParser;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SortParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SortParseElement.java
index 9c4a8714e9c..269d13786c8 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SortParseElement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SortParseElement.java
@@ -21,15 +21,15 @@ package org.elasticsearch.search.query;
 
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
+import org.elasticsearch.common.collect.Lists;
+import org.elasticsearch.common.trove.ExtTObjectIntHasMap;
+import org.elasticsearch.common.trove.TObjectIntHashMap;
+import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.index.mapper.FieldMappers;
 import org.elasticsearch.search.SearchParseElement;
 import org.elasticsearch.search.SearchParseException;
 import org.elasticsearch.search.internal.SearchContext;
 import org.elasticsearch.util.Booleans;
-import org.elasticsearch.util.collect.Lists;
-import org.elasticsearch.util.gnu.trove.TObjectIntHashMap;
-import org.elasticsearch.util.trove.ExtTObjectIntHasMap;
-import org.elasticsearch.util.xcontent.XContentParser;
 
 import java.io.IOException;
 import java.util.List;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java
index be3d672a6e7..486e46317e1 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolInfo.java
@@ -19,11 +19,11 @@
 
 package org.elasticsearch.threadpool;
 
+import org.elasticsearch.common.xcontent.ToXContent;
+import org.elasticsearch.common.xcontent.builder.XContentBuilder;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.StreamOutput;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.elasticsearch.util.xcontent.ToXContent;
-import org.elasticsearch.util.xcontent.builder.XContentBuilder;
 
 import java.io.IOException;
 import java.io.Serializable;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolModule.java
index 7368bb5a74d..e830c4d1d24 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolModule.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolModule.java
@@ -19,12 +19,12 @@
 
 package org.elasticsearch.threadpool;
 
+import org.elasticsearch.common.inject.AbstractModule;
+import org.elasticsearch.common.inject.Module;
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.threadpool.cached.CachedThreadPoolModule;
-import org.elasticsearch.util.inject.AbstractModule;
-import org.elasticsearch.util.inject.Module;
-import org.elasticsearch.util.settings.Settings;
 
-import static org.elasticsearch.util.guice.ModulesFactory.*;
+import static org.elasticsearch.common.inject.ModulesFactory.*;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolStats.java
index 7dc3a7ff4b1..4ed17c22915 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolStats.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPoolStats.java
@@ -19,11 +19,11 @@
 
 package org.elasticsearch.threadpool;
 
+import org.elasticsearch.common.xcontent.ToXContent;
+import org.elasticsearch.common.xcontent.builder.XContentBuilder;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.StreamOutput;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.elasticsearch.util.xcontent.ToXContent;
-import org.elasticsearch.util.xcontent.builder.XContentBuilder;
 
 import java.io.IOException;
 import java.io.Serializable;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPool.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPool.java
index 8cf9c94a9d4..bed863c63ef 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPool.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPool.java
@@ -19,19 +19,19 @@
 
 package org.elasticsearch.threadpool.blocking;
 
+import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.threadpool.support.AbstractThreadPool;
 import org.elasticsearch.util.SizeUnit;
 import org.elasticsearch.util.SizeValue;
 import org.elasticsearch.util.TimeValue;
 import org.elasticsearch.util.concurrent.DynamicExecutors;
-import org.elasticsearch.util.inject.Inject;
-import org.elasticsearch.util.settings.Settings;
 
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadPoolExecutor;
 
+import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*;
 import static org.elasticsearch.util.TimeValue.*;
-import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*;
 
 /**
  * A thread pool that will will block the execute if all threads are busy.
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPoolManagement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPoolManagement.java
index 49e4f84847c..5eb3e108bce 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPoolManagement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPoolManagement.java
@@ -19,10 +19,10 @@
 
 package org.elasticsearch.threadpool.blocking;
 
+import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.jmx.MBean;
 import org.elasticsearch.jmx.ManagedAttribute;
 import org.elasticsearch.threadpool.ThreadPool;
-import org.elasticsearch.util.inject.Inject;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPoolModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPoolModule.java
index 5c83cec0cde..2902144ec0c 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPoolModule.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/blocking/BlockingThreadPoolModule.java
@@ -19,8 +19,8 @@
 
 package org.elasticsearch.threadpool.blocking;
 
+import org.elasticsearch.common.inject.AbstractModule;
 import org.elasticsearch.threadpool.ThreadPool;
-import org.elasticsearch.util.inject.AbstractModule;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPool.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPool.java
index 1cb4862f0aa..008d41d708f 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPool.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPool.java
@@ -19,19 +19,19 @@
 
 package org.elasticsearch.threadpool.cached;
 
+import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.threadpool.support.AbstractThreadPool;
 import org.elasticsearch.util.TimeValue;
 import org.elasticsearch.util.concurrent.DynamicExecutors;
-import org.elasticsearch.util.inject.Inject;
-import org.elasticsearch.util.settings.Settings;
 
 import java.util.concurrent.Executors;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
+import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*;
 import static org.elasticsearch.util.TimeValue.*;
-import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*;
 
 /**
  * A thread pool that will create an unbounded number of threads.
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPoolManagement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPoolManagement.java
index 9ceae8b4b4b..eaafb1a969b 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPoolManagement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPoolManagement.java
@@ -19,10 +19,10 @@
 
 package org.elasticsearch.threadpool.cached;
 
+import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.jmx.MBean;
 import org.elasticsearch.jmx.ManagedAttribute;
 import org.elasticsearch.threadpool.ThreadPool;
-import org.elasticsearch.util.inject.Inject;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPoolModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPoolModule.java
index 6f7c094a0f0..bc9860ed285 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPoolModule.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/cached/CachedThreadPoolModule.java
@@ -19,8 +19,8 @@
 
 package org.elasticsearch.threadpool.cached;
 
+import org.elasticsearch.common.inject.AbstractModule;
 import org.elasticsearch.threadpool.ThreadPool;
-import org.elasticsearch.util.inject.AbstractModule;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPool.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPool.java
index 7f0bd56a7f3..dee92be3a29 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPool.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPool.java
@@ -19,18 +19,18 @@
 
 package org.elasticsearch.threadpool.scaling;
 
+import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.threadpool.support.AbstractThreadPool;
 import org.elasticsearch.util.TimeValue;
 import org.elasticsearch.util.concurrent.DynamicExecutors;
 import org.elasticsearch.util.concurrent.ScalingThreadPoolExecutor;
-import org.elasticsearch.util.inject.Inject;
-import org.elasticsearch.util.settings.Settings;
 
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadPoolExecutor;
 
+import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*;
 import static org.elasticsearch.util.TimeValue.*;
-import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPoolManagement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPoolManagement.java
index 4b88245a0e0..40d81e342f3 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPoolManagement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPoolManagement.java
@@ -19,10 +19,10 @@
 
 package org.elasticsearch.threadpool.scaling;
 
+import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.jmx.MBean;
 import org.elasticsearch.jmx.ManagedAttribute;
 import org.elasticsearch.threadpool.ThreadPool;
-import org.elasticsearch.util.inject.Inject;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPoolModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPoolModule.java
index 3610ebb6799..0035999552b 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPoolModule.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/scaling/ScalingThreadPoolModule.java
@@ -19,8 +19,8 @@
 
 package org.elasticsearch.threadpool.scaling;
 
+import org.elasticsearch.common.inject.AbstractModule;
 import org.elasticsearch.threadpool.ThreadPool;
-import org.elasticsearch.util.inject.AbstractModule;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/support/AbstractThreadPool.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/support/AbstractThreadPool.java
index 9d713ca367c..169041349db 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/support/AbstractThreadPool.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/support/AbstractThreadPool.java
@@ -19,13 +19,13 @@
 
 package org.elasticsearch.threadpool.support;
 
+import org.elasticsearch.common.component.AbstractComponent;
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.threadpool.FutureListener;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.threadpool.ThreadPoolInfo;
 import org.elasticsearch.threadpool.ThreadPoolStats;
 import org.elasticsearch.util.TimeValue;
-import org.elasticsearch.util.component.AbstractComponent;
-import org.elasticsearch.util.settings.Settings;
 
 import java.util.concurrent.*;
 
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerModule.java
index 84c44ed6397..774c8430de1 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerModule.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerModule.java
@@ -19,7 +19,7 @@
 
 package org.elasticsearch.timer;
 
-import org.elasticsearch.util.inject.AbstractModule;
+import org.elasticsearch.common.inject.AbstractModule;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerService.java
index b98de11a60b..a7b7844cabd 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerService.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/timer/TimerService.java
@@ -19,16 +19,16 @@
 
 package org.elasticsearch.timer;
 
-import org.elasticsearch.util.inject.Inject;
+import org.elasticsearch.common.component.AbstractComponent;
+import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.timer.HashedWheelTimer;
+import org.elasticsearch.common.timer.Timeout;
+import org.elasticsearch.common.timer.Timer;
+import org.elasticsearch.common.timer.TimerTask;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.util.TimeValue;
-import org.elasticsearch.util.component.AbstractComponent;
-import org.elasticsearch.util.settings.ImmutableSettings;
-import org.elasticsearch.util.settings.Settings;
-import org.elasticsearch.util.timer.HashedWheelTimer;
-import org.elasticsearch.util.timer.Timeout;
-import org.elasticsearch.util.timer.Timer;
-import org.elasticsearch.util.timer.TimerTask;
 
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/RemoteTransportException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/RemoteTransportException.java
index 4abae142a50..dca381e69ef 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/RemoteTransportException.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/RemoteTransportException.java
@@ -20,7 +20,7 @@
 package org.elasticsearch.transport;
 
 import org.elasticsearch.ElasticSearchWrapperException;
-import org.elasticsearch.util.transport.TransportAddress;
+import org.elasticsearch.common.transport.TransportAddress;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/Transport.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/Transport.java
index 63111f88001..a582ed90346 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/Transport.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/Transport.java
@@ -20,10 +20,10 @@
 package org.elasticsearch.transport;
 
 import org.elasticsearch.cluster.node.DiscoveryNode;
-import org.elasticsearch.util.component.LifecycleComponent;
+import org.elasticsearch.common.component.LifecycleComponent;
+import org.elasticsearch.common.transport.BoundTransportAddress;
+import org.elasticsearch.common.transport.TransportAddress;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.elasticsearch.util.transport.BoundTransportAddress;
-import org.elasticsearch.util.transport.TransportAddress;
 
 import java.io.IOException;
 
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportInfo.java
index 295ce54988e..d9e4eca113e 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportInfo.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportInfo.java
@@ -19,12 +19,12 @@
 
 package org.elasticsearch.transport;
 
+import org.elasticsearch.common.transport.BoundTransportAddress;
+import org.elasticsearch.common.xcontent.ToXContent;
+import org.elasticsearch.common.xcontent.builder.XContentBuilder;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.StreamOutput;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.elasticsearch.util.transport.BoundTransportAddress;
-import org.elasticsearch.util.xcontent.ToXContent;
-import org.elasticsearch.util.xcontent.builder.XContentBuilder;
 
 import java.io.IOException;
 import java.io.Serializable;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportModule.java
index 84cbd0df7d8..65a333a04c5 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportModule.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportModule.java
@@ -19,13 +19,13 @@
 
 package org.elasticsearch.transport;
 
-import org.elasticsearch.util.inject.AbstractModule;
-import org.elasticsearch.util.inject.Module;
+import org.elasticsearch.common.inject.AbstractModule;
+import org.elasticsearch.common.inject.Module;
+import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.transport.local.LocalTransportModule;
 import org.elasticsearch.util.Classes;
-import org.elasticsearch.util.settings.Settings;
 
-import static org.elasticsearch.util.guice.ModulesFactory.*;
+import static org.elasticsearch.common.inject.ModulesFactory.*;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportService.java
index f7422f9d808..f18b9f1ede8 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportService.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportService.java
@@ -21,19 +21,19 @@ package org.elasticsearch.transport;
 
 import org.elasticsearch.ElasticSearchException;
 import org.elasticsearch.cluster.node.DiscoveryNode;
+import org.elasticsearch.common.component.AbstractLifecycleComponent;
+import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.timer.Timeout;
+import org.elasticsearch.common.timer.TimerTask;
+import org.elasticsearch.common.transport.BoundTransportAddress;
+import org.elasticsearch.common.transport.TransportAddress;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.timer.TimerService;
 import org.elasticsearch.util.TimeValue;
-import org.elasticsearch.util.component.AbstractLifecycleComponent;
 import org.elasticsearch.util.concurrent.ConcurrentCollections;
 import org.elasticsearch.util.concurrent.ConcurrentMapLong;
-import org.elasticsearch.util.inject.Inject;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.elasticsearch.util.settings.Settings;
-import org.elasticsearch.util.timer.Timeout;
-import org.elasticsearch.util.timer.TimerTask;
-import org.elasticsearch.util.transport.BoundTransportAddress;
-import org.elasticsearch.util.transport.TransportAddress;
 
 import java.util.Collections;
 import java.util.LinkedHashMap;
@@ -42,8 +42,8 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.atomic.AtomicLong;
 
+import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*;
 import static org.elasticsearch.util.concurrent.ConcurrentCollections.*;
-import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportServiceManagement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportServiceManagement.java
index bdfe2ad9ad7..9a78687dc80 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportServiceManagement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportServiceManagement.java
@@ -19,7 +19,7 @@
 
 package org.elasticsearch.transport;
 
-import org.elasticsearch.util.inject.Inject;
+import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.jmx.MBean;
 import org.elasticsearch.jmx.ManagedAttribute;
 
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportStats.java
index 797acadc4d4..222aa351820 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportStats.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/TransportStats.java
@@ -19,12 +19,12 @@
 
 package org.elasticsearch.transport;
 
+import org.elasticsearch.common.xcontent.ToXContent;
+import org.elasticsearch.common.xcontent.builder.XContentBuilder;
 import org.elasticsearch.util.SizeValue;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.StreamOutput;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.elasticsearch.util.xcontent.ToXContent;
-import org.elasticsearch.util.xcontent.builder.XContentBuilder;
 
 import java.io.IOException;
 import java.io.Serializable;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransport.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransport.java
index afde7d05d92..af6c90fcee0 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransport.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransport.java
@@ -21,17 +21,17 @@ package org.elasticsearch.transport.local;
 
 import org.elasticsearch.ElasticSearchException;
 import org.elasticsearch.cluster.node.DiscoveryNode;
+import org.elasticsearch.common.component.AbstractLifecycleComponent;
+import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.transport.BoundTransportAddress;
+import org.elasticsearch.common.transport.LocalTransportAddress;
+import org.elasticsearch.common.transport.TransportAddress;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.transport.*;
-import org.elasticsearch.util.component.AbstractLifecycleComponent;
-import org.elasticsearch.util.inject.Inject;
 import org.elasticsearch.util.io.ThrowableObjectInputStream;
 import org.elasticsearch.util.io.stream.*;
-import org.elasticsearch.util.settings.ImmutableSettings;
-import org.elasticsearch.util.settings.Settings;
-import org.elasticsearch.util.transport.BoundTransportAddress;
-import org.elasticsearch.util.transport.LocalTransportAddress;
-import org.elasticsearch.util.transport.TransportAddress;
 
 import javax.annotation.Nullable;
 import java.io.IOException;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransportManagement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransportManagement.java
index 789ff8dd9f8..9b35f284567 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransportManagement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransportManagement.java
@@ -19,9 +19,9 @@
 
 package org.elasticsearch.transport.local;
 
+import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.jmx.MBean;
 import org.elasticsearch.transport.Transport;
-import org.elasticsearch.util.inject.Inject;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransportModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransportModule.java
index b3a172ef2a5..2249d1de7ef 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransportModule.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/local/LocalTransportModule.java
@@ -19,7 +19,7 @@
 
 package org.elasticsearch.transport.local;
 
-import org.elasticsearch.util.inject.AbstractModule;
+import org.elasticsearch.common.inject.AbstractModule;
 import org.elasticsearch.transport.Transport;
 
 /**
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/ChannelBufferStreamInput.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/ChannelBufferStreamInput.java
index 36e1f84dbeb..2f90f7ccfed 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/ChannelBufferStreamInput.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/ChannelBufferStreamInput.java
@@ -19,13 +19,13 @@
 
 package org.elasticsearch.transport.netty;
 
+import org.elasticsearch.common.netty.buffer.ChannelBuffer;
 import org.elasticsearch.util.io.stream.StreamInput;
-import org.jboss.netty.buffer.ChannelBuffer;
 
 import java.io.IOException;
 
 /**
- * A Netty {@link org.jboss.netty.buffer.ChannelBuffer} based {@link org.elasticsearch.util.io.stream.StreamInput}.
+ * A Netty {@link org.elasticsearch.common.netty.buffer.ChannelBuffer} based {@link org.elasticsearch.util.io.stream.StreamInput}.
  *
  * @author kimchy (shay.banon)
  */
@@ -38,6 +38,7 @@ public class ChannelBufferStreamInput extends StreamInput {
     }
 
     // Not really maps to InputStream, but good enough for us
+
     @Override public int read() throws IOException {
         return buffer.readByte() & 0xFF;
     }
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java
index 3cc3f080f8e..f40a4ae16ce 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java
@@ -19,15 +19,15 @@
 
 package org.elasticsearch.transport.netty;
 
+import org.elasticsearch.common.logging.ESLogger;
+import org.elasticsearch.common.netty.buffer.ChannelBuffer;
+import org.elasticsearch.common.netty.channel.*;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.transport.*;
 import org.elasticsearch.util.io.ThrowableObjectInputStream;
 import org.elasticsearch.util.io.stream.HandlesStreamInput;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.elasticsearch.util.logging.ESLogger;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.*;
 
 import java.io.IOException;
 
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyInternalESLogger.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyInternalESLogger.java
index 8637f40d839..f6c849f9a8d 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyInternalESLogger.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyInternalESLogger.java
@@ -19,8 +19,8 @@
 
 package org.elasticsearch.transport.netty;
 
-import org.elasticsearch.util.logging.ESLogger;
-import org.jboss.netty.logging.AbstractInternalLogger;
+import org.elasticsearch.common.logging.ESLogger;
+import org.elasticsearch.common.netty.logging.AbstractInternalLogger;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyInternalESLoggerFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyInternalESLoggerFactory.java
index 17eb49f1f10..a7f69ac332a 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyInternalESLoggerFactory.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyInternalESLoggerFactory.java
@@ -19,9 +19,9 @@
 
 package org.elasticsearch.transport.netty;
 
-import org.elasticsearch.util.logging.Loggers;
-import org.jboss.netty.logging.InternalLogger;
-import org.jboss.netty.logging.InternalLoggerFactory;
+import org.elasticsearch.common.logging.Loggers;
+import org.elasticsearch.common.netty.logging.InternalLogger;
+import org.elasticsearch.common.netty.logging.InternalLoggerFactory;
 
 /**
  * @author kimchy (shay.banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java
index bd5692bfa00..72a560d4251 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java
@@ -22,34 +22,34 @@ package org.elasticsearch.transport.netty;
 import org.elasticsearch.ElasticSearchException;
 import org.elasticsearch.ElasticSearchIllegalStateException;
 import org.elasticsearch.cluster.node.DiscoveryNode;
+import org.elasticsearch.common.collect.Lists;
+import org.elasticsearch.common.component.AbstractLifecycleComponent;
+import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.common.netty.OpenChannelsHandler;
+import org.elasticsearch.common.netty.bootstrap.ClientBootstrap;
+import org.elasticsearch.common.netty.bootstrap.ServerBootstrap;
+import org.elasticsearch.common.netty.buffer.ChannelBuffer;
+import org.elasticsearch.common.netty.buffer.ChannelBuffers;
+import org.elasticsearch.common.netty.channel.*;
+import org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketChannelFactory;
+import org.elasticsearch.common.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.elasticsearch.common.netty.logging.InternalLogger;
+import org.elasticsearch.common.netty.logging.InternalLoggerFactory;
+import org.elasticsearch.common.network.NetworkService;
+import org.elasticsearch.common.network.NetworkUtils;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.transport.BoundTransportAddress;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
+import org.elasticsearch.common.transport.PortsRange;
+import org.elasticsearch.common.transport.TransportAddress;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.transport.*;
 import org.elasticsearch.util.SizeValue;
 import org.elasticsearch.util.Strings;
 import org.elasticsearch.util.TimeValue;
-import org.elasticsearch.util.collect.Lists;
-import org.elasticsearch.util.component.AbstractLifecycleComponent;
-import org.elasticsearch.util.inject.Inject;
 import org.elasticsearch.util.io.stream.BytesStreamOutput;
 import org.elasticsearch.util.io.stream.HandlesStreamOutput;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.elasticsearch.util.netty.OpenChannelsHandler;
-import org.elasticsearch.util.network.NetworkService;
-import org.elasticsearch.util.network.NetworkUtils;
-import org.elasticsearch.util.settings.Settings;
-import org.elasticsearch.util.transport.BoundTransportAddress;
-import org.elasticsearch.util.transport.InetSocketTransportAddress;
-import org.elasticsearch.util.transport.PortsRange;
-import org.elasticsearch.util.transport.TransportAddress;
-import org.jboss.netty.bootstrap.ClientBootstrap;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.*;
-import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
-import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
-import org.jboss.netty.logging.InternalLogger;
-import org.jboss.netty.logging.InternalLoggerFactory;
 
 import java.io.IOException;
 import java.net.InetAddress;
@@ -65,14 +65,14 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
+import static org.elasticsearch.common.collect.Lists.*;
+import static org.elasticsearch.common.network.NetworkService.TcpSettings.*;
+import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*;
+import static org.elasticsearch.common.transport.NetworkExceptionHelper.*;
 import static org.elasticsearch.transport.Transport.Helper.*;
 import static org.elasticsearch.util.TimeValue.*;
-import static org.elasticsearch.util.collect.Lists.*;
 import static org.elasticsearch.util.concurrent.ConcurrentCollections.*;
 import static org.elasticsearch.util.concurrent.DynamicExecutors.*;
-import static org.elasticsearch.util.network.NetworkService.TcpSettings.*;
-import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*;
-import static org.elasticsearch.util.transport.NetworkExceptionHelper.*;
 
 /**
  * @author kimchy (shay.banon)
@@ -82,7 +82,7 @@ public class NettyTransport extends AbstractLifecycleComponent implem
     static {
         InternalLoggerFactory.setDefaultFactory(new NettyInternalESLoggerFactory() {
             @Override public InternalLogger newInstance(String name) {
-                return super.newInstance(name.replace("org.jboss.netty.", "netty."));
+                return super.newInstance(name.replace("org.elasticsearch.common.netty.", "netty.").replace("org.jboss.netty.", "netty."));
             }
         });
     }
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java
index ed7247eaeb7..b74f15f9c45 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java
@@ -19,6 +19,9 @@
 
 package org.elasticsearch.transport.netty;
 
+import org.elasticsearch.common.netty.buffer.ChannelBuffer;
+import org.elasticsearch.common.netty.buffer.ChannelBuffers;
+import org.elasticsearch.common.netty.channel.Channel;
 import org.elasticsearch.transport.NotSerializableTransportException;
 import org.elasticsearch.transport.RemoteTransportException;
 import org.elasticsearch.transport.TransportChannel;
@@ -26,9 +29,6 @@ import org.elasticsearch.util.io.ThrowableObjectOutputStream;
 import org.elasticsearch.util.io.stream.BytesStreamOutput;
 import org.elasticsearch.util.io.stream.HandlesStreamOutput;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
 
 import java.io.IOException;
 import java.io.NotSerializableException;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportManagement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportManagement.java
index 7aeae3de98a..33e974e9fc3 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportManagement.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportManagement.java
@@ -19,10 +19,10 @@
 
 package org.elasticsearch.transport.netty;
 
+import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.jmx.MBean;
 import org.elasticsearch.jmx.ManagedAttribute;
 import org.elasticsearch.transport.Transport;
-import org.elasticsearch.util.inject.Inject;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportModule.java
index 26e3f11e878..83550e90786 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportModule.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransportModule.java
@@ -19,7 +19,7 @@
 
 package org.elasticsearch.transport.netty;
 
-import org.elasticsearch.util.inject.AbstractModule;
+import org.elasticsearch.common.inject.AbstractModule;
 import org.elasticsearch.transport.Transport;
 
 /**
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/SizeHeaderFrameDecoder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/SizeHeaderFrameDecoder.java
index 82a47a6a65b..9073cb00394 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/SizeHeaderFrameDecoder.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/SizeHeaderFrameDecoder.java
@@ -19,10 +19,10 @@
 
 package org.elasticsearch.transport.netty;
 
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
+import org.elasticsearch.common.netty.buffer.ChannelBuffer;
+import org.elasticsearch.common.netty.channel.Channel;
+import org.elasticsearch.common.netty.channel.ChannelHandlerContext;
+import org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder;
 
 import java.io.StreamCorruptedException;
 
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/MapBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/MapBuilder.java
index 75723dc0c01..3a101062559 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/MapBuilder.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/MapBuilder.java
@@ -19,11 +19,11 @@
 
 package org.elasticsearch.util;
 
-import org.elasticsearch.util.collect.ImmutableMap;
+import org.elasticsearch.common.collect.ImmutableMap;
 
 import java.util.Map;
 
-import static org.elasticsearch.util.collect.Maps.*;
+import static org.elasticsearch.common.collect.Maps.*;
 
 /**
  * @author kimchy (Shay Banon)
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/Strings.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/Strings.java
index d05d35e8adb..84d8da78bd6 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/Strings.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/Strings.java
@@ -19,8 +19,8 @@
 
 package org.elasticsearch.util;
 
-import org.elasticsearch.util.collect.ImmutableSet;
-import org.elasticsearch.util.collect.Iterables;
+import org.elasticsearch.common.collect.ImmutableSet;
+import org.elasticsearch.common.collect.Iterables;
 
 import java.util.*;
 
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/ThreadLocals.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/ThreadLocals.java
index a0b5e5896ed..32ec5ed4388 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/ThreadLocals.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/ThreadLocals.java
@@ -19,8 +19,8 @@
 
 package org.elasticsearch.util;
 
-import org.elasticsearch.util.logging.ESLogger;
-import org.elasticsearch.util.logging.Loggers;
+import org.elasticsearch.common.logging.ESLogger;
+import org.elasticsearch.common.logging.Loggers;
 
 import java.lang.ref.Reference;
 import java.lang.reflect.Field;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/ThreadRenamingRunnable.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/ThreadRenamingRunnable.java
index fbd85a8a7ee..846774d3573 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/ThreadRenamingRunnable.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/ThreadRenamingRunnable.java
@@ -19,8 +19,8 @@
 
 package org.elasticsearch.util;
 
-import org.elasticsearch.util.logging.ESLogger;
-import org.elasticsearch.util.logging.Loggers;
+import org.elasticsearch.common.logging.ESLogger;
+import org.elasticsearch.common.logging.Loggers;
 
 /**
  * A {@link Runnable} that changes the current thread name and reverts it back
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/TimeValue.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/TimeValue.java
index 7c6f2487894..50861d226ab 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/TimeValue.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/TimeValue.java
@@ -20,13 +20,13 @@
 package org.elasticsearch.util;
 
 import org.elasticsearch.ElasticSearchParseException;
+import org.elasticsearch.common.joda.time.Period;
+import org.elasticsearch.common.joda.time.PeriodType;
+import org.elasticsearch.common.joda.time.format.PeriodFormat;
+import org.elasticsearch.common.joda.time.format.PeriodFormatter;
 import org.elasticsearch.util.io.stream.StreamInput;
 import org.elasticsearch.util.io.stream.StreamOutput;
 import org.elasticsearch.util.io.stream.Streamable;
-import org.joda.time.Period;
-import org.joda.time.PeriodType;
-import org.joda.time.format.PeriodFormat;
-import org.joda.time.format.PeriodFormatter;
 
 import java.io.IOException;
 import java.io.Serializable;
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/GwtCompatible.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/GwtCompatible.java
deleted file mode 100644
index efd7b309f4d..00000000000
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/GwtCompatible.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.elasticsearch.util.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * The presence of this annotation on a type indicates that the type may be
- * used with the
- * Google Web Toolkit (GWT).
- * When applied to a method, the return type of the method is GWT compatible.
- * It's useful to indicate that an instance created by factory methods has a GWT
- * serializable type.  In the following example,
- *
- * 
- * {@literal @}GwtCompatible
- * class Lists {
- *   ...
- *   {@literal @}GwtCompatible(serializable = true)
- *   static <E> List<E> newArrayList(E... elements) {
- *     ...
- *   }
- * }
- * 
- * The return value of {@code Lists.newArrayList(E[])} has GWT - * serializable type. It is also useful in specifying contracts of interface - * methods. In the following example, - * - *
- * {@literal @}GwtCompatible
- * interface ListFactory {
- *   ...
- *   {@literal @}GwtCompatible(serializable = true)
- *   <E> List<E> newArrayList(E... elements);
- * }
- * 
- * The {@code newArrayList(E[])} method of all implementations of {@code - * ListFactory} is expected to return a value with a GWT serializable type. - * - *

Note that a {@code GwtCompatible} type may have some {@link - * GwtIncompatible} methods. - * - * @author Charles Fry - * @author Hayward Chan - */ -@Retention(RetentionPolicy.CLASS) -@Target({ ElementType.TYPE, ElementType.METHOD }) -// @Documented - uncomment when GWT support is official -@GwtCompatible -public @interface GwtCompatible { - - /** - * When {@code true}, the annotated type or the type of the method return - * value is GWT serializable. - * - * @see - * Documentation about GWT serialization - */ - boolean serializable() default false; - - /** - * When {@code true}, the annotated type is emulated in GWT. The emulated - * source (also known as super-source) is different from the implementation - * used by the JVM. - * - * @see - * Documentation about GWT emulated source - */ - boolean emulated() default false; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/GwtIncompatible.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/GwtIncompatible.java deleted file mode 100644 index d71d077f460..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/GwtIncompatible.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * The presence of this annotation on a method indicates that the method may - * not be used with the - * Google Web Toolkit (GWT), - * even though its type is annotated as {@link GwtCompatible} and accessible in - * GWT. They can cause GWT compilation errors or simply unexpected exceptions - * when used in GWT. - * - *

Note that this annotation should only be applied to methods of types which - * are annotated as {@link GwtCompatible}. - * - * @author Charles Fry - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.METHOD) -// @Documented - uncomment when GWT support is official -@GwtCompatible -public @interface GwtIncompatible { - - /** - * Describes why the annotated element is incompatible with GWT. Since this is - * generally due to a dependence on a type/method which GWT doesn't support, - * it is sufficient to simply reference the unsupported type/method. E.g. - * "Class.isInstance". - */ - String value(); - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/VisibleForTesting.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/VisibleForTesting.java deleted file mode 100644 index 47a58adc229..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/annotations/VisibleForTesting.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.annotations; - -/** - * An annotation that indicates that the visibility of a type or member has - * been relaxed to make the code testable. - * - * @author Johannes Henkel - */ -@GwtCompatible -public @interface VisibleForTesting {} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizablePhantomReference.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizablePhantomReference.java deleted file mode 100644 index fde1c9994cc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizablePhantomReference.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import java.lang.ref.PhantomReference; - -/** - * Phantom reference with a {@code finalizeReferent()} method which a - * background thread invokes after the garbage collector reclaims the - * referent. This is a simpler alternative to using a {@link - * java.lang.ref.ReferenceQueue}. - * - *

Unlike a normal phantom reference, this reference will be cleared - * automatically. - * - * @author Bob Lee - */ -public abstract class FinalizablePhantomReference - extends PhantomReference implements FinalizableReference { - - /** - * Constructs a new finalizable phantom reference. - * - * @param referent to phantom reference - * @param queue that should finalize the referent - */ - protected FinalizablePhantomReference(T referent, - FinalizableReferenceQueue queue) { - super(referent, queue.queue); - queue.cleanUp(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableReference.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableReference.java deleted file mode 100644 index 31f5d2b70a0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableReference.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -/** - * Implemented by references that have code to run after garbage collection of - * their referents. - * - * @see FinalizableReferenceQueue - * @author Bob Lee - */ -public interface FinalizableReference { - - /** - * Invoked on a background thread after the referent has been garbage - * collected unless security restrictions prevented starting a background - * thread, in which case this method is invoked when new references - * are created. - */ - void finalizeReferent(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableReferenceQueue.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableReferenceQueue.java deleted file mode 100644 index d1750702317..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableReferenceQueue.java +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.lang.ref.Reference; -import java.lang.ref.ReferenceQueue; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A reference queue with an associated background thread that dequeues - * references and invokes {@link FinalizableReference#finalizeReferent()} on - * them. - * - *

Keep a strong reference to this object until all of the associated - * referents have been finalized. If this object is garbage collected earlier, - * the backing thread will not invoke {@code finalizeReferent()} on the - * remaining references. - * - * @author Bob Lee - */ -public class FinalizableReferenceQueue { - - /* - * The Finalizer thread keeps a phantom reference to this object. When the - * client (ReferenceMap, for example) no longer has a strong reference to - * this object, the garbage collector will reclaim it and enqueue the - * phantom reference. The enqueued reference will trigger the Finalizer to - * stop. - * - * If this library is loaded in the system class loader, - * FinalizableReferenceQueue can load Finalizer directly with no problems. - * - * If this library is loaded in an application class loader, it's important - * that Finalizer not have a strong reference back to the class loader. - * Otherwise, you could have a graph like this: - * - * Finalizer Thread - * runs instance of -> Finalizer.class - * loaded by -> Application class loader - * which loaded -> ReferenceMap.class - * which has a static -> FinalizableReferenceQueue instance - * - * Even if no other references to classes from the application class loader - * remain, the Finalizer thread keeps an indirect strong reference to the - * queue in ReferenceMap, which keeps the Finalizer running, and as a result, - * the application class loader can never be reclaimed. - * - * This means that dynamically loaded web applications and OSGi bundles can't - * be unloaded. - * - * If the library is loaded in an application class loader, we try to break - * the cycle by loading Finalizer in its own independent class loader: - * - * System class loader - * -> Application class loader - * -> ReferenceMap - * -> FinalizableReferenceQueue - * -> etc. - * -> Decoupled class loader - * -> Finalizer - * - * Now, Finalizer no longer keeps an indirect strong reference to the - * static FinalizableReferenceQueue field in ReferenceMap. The application - * class loader can be reclaimed at which point the Finalizer thread will - * stop and its decoupled class loader can also be reclaimed. - * - * If any of this fails along the way, we fall back to loading Finalizer - * directly in the application class loader. - */ - - private static final Logger logger - = Logger.getLogger(FinalizableReferenceQueue.class.getName()); - - private static final String FINALIZER_CLASS_NAME - = "org.elasticsearch.util.base.internal.Finalizer"; - - /** Reference to Finalizer.startFinalizer(). */ - private static final Method startFinalizer; - static { - Class finalizer = loadFinalizer( - new SystemLoader(), new DecoupledLoader(), new DirectLoader()); - startFinalizer = getStartFinalizer(finalizer); - } - - /** - * The actual reference queue that our background thread will poll. - */ - final ReferenceQueue queue; - - /** - * Whether or not the background thread started successfully. - */ - final boolean threadStarted; - - /** - * Constructs a new queue. - */ - @SuppressWarnings("unchecked") - public FinalizableReferenceQueue() { - // We could start the finalizer lazily, but I'd rather it blow up early. - ReferenceQueue queue; - boolean threadStarted = false; - try { - queue = (ReferenceQueue) startFinalizer.invoke(null, - FinalizableReference.class, this); - threadStarted = true; - } catch (IllegalAccessException e) { - // Finalizer.startFinalizer() is public. - throw new AssertionError(e); - } catch (Throwable t) { - logger.log(Level.INFO, "Failed to start reference finalizer thread." - + " Reference cleanup will only occur when new references are" - + " created.", t); - queue = new ReferenceQueue(); - } - - this.queue = queue; - this.threadStarted = threadStarted; - } - - /** - * Repeatedly dequeues references from the queue and invokes - * {@link FinalizableReference#finalizeReferent()} on them until the queue - * is empty. This method is a no-op if the background thread was created - * successfully. - */ - void cleanUp() { - if (threadStarted) { - return; - } - - Reference reference; - while ((reference = queue.poll()) != null) { - /* - * This is for the benefit of phantom references. Weak and soft - * references will have already been cleared by this point. - */ - reference.clear(); - try { - ((FinalizableReference) reference).finalizeReferent(); - } catch (Throwable t) { - logger.log(Level.SEVERE, "Error cleaning up after reference.", t); - } - } - } - - /** - * Iterates through the given loaders until it finds one that can load - * Finalizer. - * - * @return Finalizer.class - */ - private static Class loadFinalizer(FinalizerLoader... loaders) { - for (FinalizerLoader loader : loaders) { - Class finalizer = loader.loadFinalizer(); - if (finalizer != null) { - return finalizer; - } - } - - throw new AssertionError(); - } - - /** - * Loads Finalizer.class. - */ - interface FinalizerLoader { - - /** - * Returns Finalizer.class or null if this loader shouldn't or can't load - * it. - * - * @throws SecurityException if we don't have the appropriate privileges - */ - Class loadFinalizer(); - } - - /** - * Tries to load Finalizer from the system class loader. If Finalizer is - * in the system class path, we needn't create a separate loader. - */ - static class SystemLoader implements FinalizerLoader { - public Class loadFinalizer() { - ClassLoader systemLoader; - try { - systemLoader = ClassLoader.getSystemClassLoader(); - } catch (SecurityException e) { - logger.info("Not allowed to access system class loader."); - return null; - } - if (systemLoader != null) { - try { - return systemLoader.loadClass(FINALIZER_CLASS_NAME); - } catch (ClassNotFoundException e) { - // Ignore. Finalizer is simply in a child class loader. - return null; - } - } else { - return null; - } - } - } - - /** - * Try to load Finalizer in its own class loader. If Finalizer's thread - * had a direct reference to our class loader (which could be that of - * a dynamically loaded web application or OSGi bundle), it would prevent - * our class loader from getting garbage collected. - */ - static class DecoupledLoader implements FinalizerLoader { - - private static final String LOADING_ERROR = "Could not load Finalizer in" - + " its own class loader. Loading Finalizer in the current class loader" - + " instead. As a result, you will not be able to garbage collect this" - + " class loader. To support reclaiming this class loader, either" - + " resolve the underlying issue, or move Google Collections to your" - + " system class path."; - - public Class loadFinalizer() { - try { - /* - * We use URLClassLoader because it's the only concrete class loader - * implementation in the JDK. If we used our own ClassLoader subclass, - * Finalizer would indirectly reference this class loader: - * - * Finalizer.class -> - * CustomClassLoader -> - * CustomClassLoader.class -> - * This class loader - * - * System class loader will (and must) be the parent. - */ - ClassLoader finalizerLoader = newLoader(getBaseUrl()); - return finalizerLoader.loadClass(FINALIZER_CLASS_NAME); - } catch (Exception e) { - logger.log(Level.WARNING, LOADING_ERROR, e); - return null; - } - } - - /** - * Gets URL for base of path containing Finalizer.class. - */ - URL getBaseUrl() throws IOException { - // Find URL pointing to Finalizer.class file. - String finalizerPath = FINALIZER_CLASS_NAME.replace('.', '/') + ".class"; - URL finalizerUrl = getClass().getClassLoader().getResource(finalizerPath); - if (finalizerUrl == null) { - throw new FileNotFoundException(finalizerPath); - } - - // Find URL pointing to base of class path. - String urlString = finalizerUrl.toString(); - if (!urlString.endsWith(finalizerPath)) { - throw new IOException("Unsupported path style: " + urlString); - } - urlString = urlString.substring(0, - urlString.length() - finalizerPath.length()); - return new URL(finalizerUrl, urlString); - } - - /** Creates a class loader with the given base URL as its classpath. */ - URLClassLoader newLoader(URL base) { - return new URLClassLoader(new URL[] { base }); - } - } - - /** - * Loads Finalizer directly using the current class loader. We won't be - * able to garbage collect this class loader, but at least the world - * doesn't end. - */ - static class DirectLoader implements FinalizerLoader { - public Class loadFinalizer() { - try { - return Class.forName(FINALIZER_CLASS_NAME); - } catch (ClassNotFoundException e) { - throw new AssertionError(e); - } - } - } - - /** - * Looks up Finalizer.startFinalizer(). - */ - static Method getStartFinalizer(Class finalizer) { - try { - return finalizer.getMethod("startFinalizer", Class.class, Object.class); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableSoftReference.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableSoftReference.java deleted file mode 100644 index 38b91c2a4c3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableSoftReference.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import java.lang.ref.SoftReference; - -/** - * Soft reference with a {@code finalizeReferent()} method which a background - * thread invokes after the garbage collector reclaims the referent. This is a - * simpler alternative to using a {@link java.lang.ref.ReferenceQueue}. - * - * @author Bob Lee - */ -public abstract class FinalizableSoftReference extends SoftReference - implements FinalizableReference { - - /** - * Constructs a new finalizable soft reference. - * - * @param referent to softly reference - * @param queue that should finalize the referent - */ - protected FinalizableSoftReference(T referent, - FinalizableReferenceQueue queue) { - super(referent, queue.queue); - queue.cleanUp(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableWeakReference.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableWeakReference.java deleted file mode 100644 index 172e94d0d80..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/FinalizableWeakReference.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import java.lang.ref.WeakReference; - -/** - * Weak reference with a {@code finalizeReferent()} method which a background - * thread invokes after the garbage collector reclaims the referent. This is a - * simpler alternative to using a {@link java.lang.ref.ReferenceQueue}. - * - * @author Bob Lee - */ -public abstract class FinalizableWeakReference extends WeakReference - implements FinalizableReference { - - /** - * Constructs a new finalizable weak reference. - * - * @param referent to weakly reference - * @param queue that should finalize the referent - */ - protected FinalizableWeakReference(T referent, - FinalizableReferenceQueue queue) { - super(referent, queue.queue); - queue.cleanUp(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Function.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Function.java deleted file mode 100644 index 0714a13e37f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Function.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; - -/** - * A transformation from one object to another. For example, a - * {@code StringToIntegerFunction} may implement - * Function<String,Integer> and transform integers in - * {@code String} format to {@code Integer} format. - * - *

The transformation on the source object does not necessarily result in - * an object of a different type. For example, a - * {@code FarenheitToCelsiusFunction} may implement - * Function<Float,Float>. - * - *

Implementations which may cause side effects upon evaluation are strongly - * encouraged to state this fact clearly in their API documentation. - * - * @param the type of the function input - * @param the type of the function output - * @author Kevin Bourrillion - * @author Scott Bonneau - */ -@GwtCompatible -public interface Function { - - /** - * Applies the function to an object of type {@code F}, resulting in an object - * of type {@code T}. Note that types {@code F} and {@code T} may or may not - * be the same. - * - * @param from the source object - * @return the resulting object - */ - T apply(@Nullable F from); - - /** - * Indicates whether some other object is equal to this {@code Function}. - * This method can return {@code true} only if the specified object is - * also a {@code Function} and, for every input object {@code o}, it returns - * exactly the same value. Thus, {@code function1.equals(function2)} implies - * that either {@code function1.apply(o)} and {@code function2.apply(o)} are - * both null, or {@code function1.apply(o).equals(function2.apply(o))}. - * - *

Note that it is always safe not to override - * {@link Object#equals}. - */ - boolean equals(@Nullable Object obj); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Functions.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Functions.java deleted file mode 100644 index 8174cb0c7a3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Functions.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.Map; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Useful functions. - * - *

All methods returns serializable functions as long as they're given - * serializable parameters. - * - * @author Mike Bostock - * @author Vlad Patryshev - * @author Jared Levy - */ -@GwtCompatible -public final class Functions { - private Functions() {} - - /** - * Returns a function that calls {@code toString()} on its argument. The - * function does not accept nulls; it will throw a - * {@link NullPointerException} when applied to {@code null}. - */ - public static Function toStringFunction() { - return ToStringFunction.INSTANCE; - } - - // enum singleton pattern - private enum ToStringFunction implements Function { - INSTANCE; - - public String apply(Object o) { - return o.toString(); - } - - @Override public String toString() { - return "toString"; - } - } - - /** - * Returns the identity function. - */ - @SuppressWarnings("unchecked") - public static Function identity() { - return (Function) IdentityFunction.INSTANCE; - } - - // enum singleton pattern - private enum IdentityFunction implements Function { - INSTANCE; - - public Object apply(Object o) { - return o; - } - - @Override public String toString() { - return "identity"; - } - } - - /** - * Returns a function which performs a map lookup. The returned function - * throws an {@link IllegalArgumentException} if given a key that does not - * exist in the map. - */ - public static Function forMap(Map map) { - return new FunctionForMapNoDefault(map); - } - - private static class FunctionForMapNoDefault - implements Function, Serializable { - final Map map; - - FunctionForMapNoDefault(Map map) { - this.map = checkNotNull(map); - } - public V apply(K key) { - V result = map.get(key); - checkArgument(result != null || map.containsKey(key), - "Key '%s' not present in map", key); - return result; - } - @Override public boolean equals(Object o) { - if (o instanceof FunctionForMapNoDefault) { - FunctionForMapNoDefault that = (FunctionForMapNoDefault) o; - return map.equals(that.map); - } - return false; - } - @Override public int hashCode() { - return map.hashCode(); - } - @Override public String toString() { - return "forMap(" + map + ")"; - } - private static final long serialVersionUID = 0; - } - - /** - * Returns a function which performs a map lookup with a default value. The - * function created by this method returns {@code defaultValue} for all - * inputs that do not belong to the map's key set. - * - * @param map source map that determines the function behavior - * @param defaultValue the value to return for inputs that aren't map keys - * @return function that returns {@code map.get(a)} when {@code a} is a key, - * or {@code defaultValue} otherwise - */ - public static Function forMap( - Map map, @Nullable V defaultValue) { - return new ForMapWithDefault(map, defaultValue); - } - - private static class ForMapWithDefault - implements Function, Serializable { - final Map map; - final V defaultValue; - - ForMapWithDefault(Map map, V defaultValue) { - this.map = checkNotNull(map); - this.defaultValue = defaultValue; - } - public V apply(K key) { - return map.containsKey(key) ? map.get(key) : defaultValue; - } - @Override public boolean equals(Object o) { - if (o instanceof ForMapWithDefault) { - ForMapWithDefault that = (ForMapWithDefault) o; - return map.equals(that.map) - && Objects.equal(defaultValue, that.defaultValue); - } - return false; - } - @Override public int hashCode() { - return Objects.hashCode(map, defaultValue); - } - @Override public String toString() { - return "forMap(" + map + ", defaultValue=" + defaultValue + ")"; - } - private static final long serialVersionUID = 0; - } - - /** - * Returns the composition of two functions. For {@code f: A->B} and - * {@code g: B->C}, composition is defined as the function h such that - * {@code h(a) == g(f(a))} for each {@code a}. - * - * @see - * function composition - * - * @param g the second function to apply - * @param f the first function to apply - * @return the composition of {@code f} and {@code g} - */ - public static Function compose( - Function g, Function f) { - return new FunctionComposition(g, f); - } - - private static class FunctionComposition - implements Function, Serializable { - private final Function g; - private final Function f; - - public FunctionComposition(Function g, - Function f) { - this.g = checkNotNull(g); - this.f = checkNotNull(f); - } - public C apply(A a) { - return g.apply(f.apply(a)); - } - @Override public boolean equals(Object obj) { - if (obj instanceof FunctionComposition) { - FunctionComposition that = (FunctionComposition) obj; - return f.equals(that.f) && g.equals(that.g); - } - return false; - } - - @Override public int hashCode() { - return f.hashCode() ^ g.hashCode(); - } - @Override public String toString() { - return g.toString() + "(" + f.toString() + ")"; - } - private static final long serialVersionUID = 0; - } - - /** - * Creates a function that returns the same boolean output as the given - * predicate for all inputs. - */ - public static Function forPredicate(Predicate predicate) { - return new PredicateFunction(predicate); - } - - /** @see Functions#forPredicate */ - private static class PredicateFunction - implements Function, Serializable { - private final Predicate predicate; - - private PredicateFunction(Predicate predicate) { - this.predicate = checkNotNull(predicate); - } - - public Boolean apply(T t) { - return predicate.apply(t); - } - @Override public boolean equals(Object obj) { - if (obj instanceof PredicateFunction) { - PredicateFunction that = (PredicateFunction) obj; - return predicate.equals(that.predicate); - } - return false; - } - @Override public int hashCode() { - return predicate.hashCode(); - } - @Override public String toString() { - return "forPredicate(" + predicate + ")"; - } - private static final long serialVersionUID = 0; - } - - /** - * Creates a function that returns {@code value} for any input. - * - * @param value the constant value for the function to return - * @return a function that always returns {@code value} - */ - public static Function constant(@Nullable E value) { - return new ConstantFunction(value); - } - - private static class ConstantFunction - implements Function, Serializable { - private final E value; - - public ConstantFunction(@Nullable E value) { - this.value = value; - } - public E apply(Object from) { - return value; - } - @Override public boolean equals(Object obj) { - if (obj instanceof ConstantFunction) { - ConstantFunction that = (ConstantFunction) obj; - return Objects.equal(value, that.value); - } - return false; - } - @Override public int hashCode() { - return (value == null) ? 0 : value.hashCode(); - } - @Override public String toString() { - return "constant(" + value + ")"; - } - private static final long serialVersionUID = 0; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Joiner.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Joiner.java deleted file mode 100644 index 3118a5eb1de..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Joiner.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.util.AbstractList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * An object which joins pieces of text (specified as an array, {@link - * Iterable}, varargs or even a {@link Map}) with a separator. It either - * appends the results to an {@link Appendable} or returns them as a {@link - * String}. Example:

   {@code
- *
- *   Joiner joiner = Joiner.on("; ").skipNulls();
- *    . . .
- *   return joiner.join("Harry", null, "Ron", "Hermione");}
- * - * This returns the string {@code "Harry; Ron; Hermione"}. Note that all input - * elements are converted to strings using {@link Object#toString()} before - * being appended. - * - *

If neither {@link #skipNulls()} nor {@link #useForNull(String)} is - * specified, the joining methods will throw {@link NullPointerException} if any - * given element is null. - * - * @author Kevin Bourrillion - */ -@GwtCompatible public class Joiner { - /** - * Returns a joiner which automatically places {@code separator} between - * consecutive elements. - */ - public static Joiner on(String separator) { - return new Joiner(separator); - } - - /** - * Returns a joiner which automatically places {@code separator} between - * consecutive elements. - */ - public static Joiner on(char separator) { - return new Joiner(String.valueOf(separator)); - } - - private final String separator; - - private Joiner(String separator) { - this.separator = checkNotNull(separator); - } - - private Joiner(Joiner prototype) { - this.separator = prototype.separator; - } - - /** - * Appends the string representation of each of {@code parts}, using the - * previously configured separator between each, to {@code appendable}. - */ - public A appendTo(A appendable, Iterable parts) - throws IOException { - checkNotNull(appendable); - Iterator iterator = parts.iterator(); - if (iterator.hasNext()) { - appendable.append(toString(iterator.next())); - while (iterator.hasNext()) { - appendable.append(separator); - appendable.append(toString(iterator.next())); - } - } - return appendable; - } - - /** - * Appends the string representation of each of {@code parts}, using the - * previously configured separator between each, to {@code appendable}. - */ - public final A appendTo( - A appendable, Object[] parts) throws IOException { - return appendTo(appendable, Arrays.asList(parts)); - } - - /** - * Appends to {@code appendable} the string representation of each of the - * remaining arguments. - */ - public final A appendTo(A appendable, - @Nullable Object first, @Nullable Object second, Object... rest) - throws IOException { - return appendTo(appendable, iterable(first, second, rest)); - } - - /** - * Appends the string representation of each of {@code parts}, using the - * previously configured separator between each, to {@code builder}. Identical - * to {@link #appendTo(Appendable, Iterable)}, except that it does not throw - * {@link IOException}. - */ - public final StringBuilder appendTo(StringBuilder builder, Iterable parts) - { - try { - appendTo((Appendable) builder, parts); - } catch (IOException impossible) { - throw new AssertionError(impossible); - } - return builder; - } - - /** - * Appends the string representation of each of {@code parts}, using the - * previously configured separator between each, to {@code builder}. Identical - * to {@link #appendTo(Appendable, Iterable)}, except that it does not throw - * {@link IOException}. - */ - public final StringBuilder appendTo(StringBuilder builder, Object[] parts) { - return appendTo(builder, Arrays.asList(parts)); - } - - /** - * Appends to {@code builder} the string representation of each of the - * remaining arguments. Identical to {@link #appendTo(Appendable, Object, - * Object, Object[])}, except that it does not throw {@link IOException}. - */ - public final StringBuilder appendTo(StringBuilder builder, - @Nullable Object first, @Nullable Object second, Object... rest) { - return appendTo(builder, iterable(first, second, rest)); - } - - /** - * Returns a string containing the string representation of each of {@code - * parts}, using the previously configured separator between each. - */ - public final String join(Iterable parts) { - return appendTo(new StringBuilder(), parts).toString(); - } - - /** - * Returns a string containing the string representation of each of {@code - * parts}, using the previously configured separator between each. - */ - public final String join(Object[] parts) { - return join(Arrays.asList(parts)); - } - - /** - * Returns a string containing the string representation of each argument, - * using the previously configured separator between each. - */ - public final String join( - @Nullable Object first, @Nullable Object second, Object... rest) { - return join(iterable(first, second, rest)); - } - - /** - * Returns a joiner with the same behavior as this one, except automatically - * substituting {@code nullText} for any provided null elements. - */ - public Joiner useForNull(final String nullText) { - checkNotNull(nullText); - return new Joiner(this) { - @Override CharSequence toString(Object part) { - return (part == null) ? nullText : Joiner.this.toString(part); - } - @Override public Joiner useForNull(String nullText) { - checkNotNull(nullText); // weird, just to satisfy NullPointerTester! - // TODO: fix that? - throw new UnsupportedOperationException("already specified useForNull"); - } - @Override public Joiner skipNulls() { - throw new UnsupportedOperationException("already specified useForNull"); - } - }; - } - - /** - * Returns a joiner with the same behavior as this joiner, except - * automatically skipping over any provided null elements. - */ - public Joiner skipNulls() { - return new Joiner(this) { - @Override public A appendTo( - A appendable, Iterable parts) throws IOException { - checkNotNull(appendable, "appendable"); - checkNotNull(parts, "parts"); - Iterator iterator = parts.iterator(); - while (iterator.hasNext()) { - Object part = iterator.next(); - if (part != null) { - appendable.append(Joiner.this.toString(part)); - break; - } - } - while (iterator.hasNext()) { - Object part = iterator.next(); - if (part != null) { - appendable.append(separator); - appendable.append(Joiner.this.toString(part)); - } - } - return appendable; - } - @Override public Joiner useForNull(String nullText) { - checkNotNull(nullText); // weird, just to satisfy NullPointerTester! - throw new UnsupportedOperationException("already specified skipNulls"); - } - @Override public MapJoiner withKeyValueSeparator(String kvs) { - checkNotNull(kvs); // weird, just to satisfy NullPointerTester! - throw new UnsupportedOperationException( - "can't use .skipNulls() with maps"); - } - }; - } - - /** - * Returns a {@code MapJoiner} using the given key-value separator, and the - * same configuration as this {@code Joiner} otherwise. - */ - public MapJoiner withKeyValueSeparator(String keyValueSeparator) { - return new MapJoiner(this, checkNotNull(keyValueSeparator)); - } - - /** - * An object that joins map entries in the same manner as {@code Joiner} joins - * iterables and arrays. - */ - public static class MapJoiner { - private Joiner joiner; - private String keyValueSeparator; - - private MapJoiner(Joiner joiner, String keyValueSeparator) { - this.joiner = joiner; - this.keyValueSeparator = keyValueSeparator; - } - - /** - * Appends the string representation of each entry of {@code map}, using the - * previously configured separator and key-value separator, to {@code - * appendable}. - */ - public A appendTo(A appendable, Map map) - throws IOException { - checkNotNull(appendable); - Iterator> iterator = map.entrySet().iterator(); - if (iterator.hasNext()) { - Entry entry = iterator.next(); - appendable.append(joiner.toString(entry.getKey())); - appendable.append(keyValueSeparator); - appendable.append(joiner.toString(entry.getValue())); - while (iterator.hasNext()) { - appendable.append(joiner.separator); - Entry e = iterator.next(); - appendable.append(joiner.toString(e.getKey())); - appendable.append(keyValueSeparator); - appendable.append(joiner.toString(e.getValue())); - } - } - return appendable; - } - - /** - * Appends the string representation of each entry of {@code map}, using the - * previously configured separator and key-value separator, to {@code - * builder}. Identical to {@link #appendTo(Appendable, Map)}, except that it - * does not throw {@link IOException}. - */ - public StringBuilder appendTo(StringBuilder builder, Map map) { - try { - appendTo((Appendable) builder, map); - } catch (IOException impossible) { - throw new AssertionError(impossible); - } - return builder; - } - - /** - * Returns a string containing the string representation of each entry of - * {@code map}, using the previously configured separator and key-value - * separator. - */ - public String join(Map map) { - return appendTo(new StringBuilder(), map).toString(); - } - - /** - * Returns a map joiner with the same behavior as this one, except - * automatically substituting {@code nullText} for any provided null keys or - * values. - */ - public MapJoiner useForNull(String nullText) { - return new MapJoiner(joiner.useForNull(nullText), keyValueSeparator); - } - } - - CharSequence toString(Object part) { - return (part instanceof CharSequence) - ? (CharSequence) part - : part.toString(); - } - - private static Iterable iterable( - final Object first, final Object second, final Object[] rest) { - checkNotNull(rest); - return new AbstractList() { - @Override public int size() { - return rest.length + 2; - } - @Override public Object get(int index) { - switch (index) { - case 0: - return first; - case 1: - return second; - default: - return rest[index - 2]; - } - } - }; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Objects.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Objects.java deleted file mode 100644 index 90472e49560..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Objects.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Arrays; - -/** - * Helper functions that can operate on any {@code Object}. - * - * @author Laurence Gonsalves - */ -@GwtCompatible -public final class Objects { - private Objects() {} - - /** - * Determines whether two possibly-null objects are equal. Returns: - * - *
    - *
  • {@code true} if {@code a} and {@code b} are both null. - *
  • {@code true} if {@code a} and {@code b} are both non-null and they are - * equal according to {@link Object#equals(Object)}. - *
  • {@code false} in all other situations. - *
- * - *

This assumes that any non-null objects passed to this function conform - * to the {@code equals()} contract. - */ - public static boolean equal(@Nullable Object a, @Nullable Object b) { - return a == b || (a != null && a.equals(b)); - } - - /** - * Generates a hash code for multiple values. The hash code is generated by - * calling {@link Arrays#hashCode(Object[])}. - * - *

This is useful for implementing {@link Object#hashCode()}. For example, - * in an object that has three properties, {@code x}, {@code y}, and - * {@code z}, one could write: - *

-   * public int hashCode() {
-   *   return Objects.hashCode(getX(), getY(), getZ());
-   * }
- * - * Warning: When a single object is supplied, the returned hash code - * does not equal the hash code of that object. - */ - public static int hashCode(Object... objects) { - return Arrays.hashCode(objects); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Platform.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Platform.java deleted file mode 100644 index ae3744e1ed9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Platform.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.GwtCompatible; - -/** - * Methods factored out so that they can be emulated differently in GWT. - * - * @author Jesse Wilson - */ -@GwtCompatible(emulated = true) -final class Platform { - private Platform() {} - - /** - * Calls {@link Class#isInstance(Object)}. - * - *

This method is not supported in GWT yet. - */ - static boolean isInstance(Class clazz, Object obj) { - return clazz.isInstance(obj); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Preconditions.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Preconditions.java deleted file mode 100644 index ec550bb7fe3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Preconditions.java +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.VisibleForTesting; - -import java.util.NoSuchElementException; - -/** - * Simple static methods to be called at the start of your own methods to verify - * correct arguments and state. This allows constructs such as - *

- *     if (count <= 0) {
- *       throw new IllegalArgumentException("must be positive: " + count);
- *     }
- * - * to be replaced with the more compact - *
- *     checkArgument(count > 0, "must be positive: %s", count);
- * - * Note that the sense of the expression is inverted; with {@code Preconditions} - * you declare what you expect to be true, just as you do with an - * - * {@code assert} or a JUnit {@code assertTrue} call. - * - *

Warning: only the {@code "%s"} specifier is recognized as a - * placeholder in these messages, not the full range of {@link - * String#format(String, Object[])} specifiers. - * - *

Take care not to confuse precondition checking with other similar types - * of checks! Precondition exceptions -- including those provided here, but also - * {@link IndexOutOfBoundsException}, {@link NoSuchElementException}, {@link - * UnsupportedOperationException} and others -- are used to signal that the - * calling method has made an error. This tells the caller that it should - * not have invoked the method when it did, with the arguments it did, or - * perhaps ever. Postcondition or other invariant failures should not throw - * these types of exceptions. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -public final class Preconditions { - private Preconditions() {} - - /** - * Ensures the truth of an expression involving one or more parameters to the - * calling method. - * - * @param expression a boolean expression - * @throws IllegalArgumentException if {@code expression} is false - */ - public static void checkArgument(boolean expression) { - if (!expression) { - throw new IllegalArgumentException(); - } - } - - /** - * Ensures the truth of an expression involving one or more parameters to the - * calling method. - * - * @param expression a boolean expression - * @param errorMessage the exception message to use if the check fails; will - * be converted to a string using {@link String#valueOf(Object)} - * @throws IllegalArgumentException if {@code expression} is false - */ - public static void checkArgument(boolean expression, Object errorMessage) { - if (!expression) { - throw new IllegalArgumentException(String.valueOf(errorMessage)); - } - } - - /** - * Ensures the truth of an expression involving one or more parameters to the - * calling method. - * - * @param expression a boolean expression - * @param errorMessageTemplate a template for the exception message should the - * check fail. The message is formed by replacing each {@code %s} - * placeholder in the template with an argument. These are matched by - * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. - * Unmatched arguments will be appended to the formatted message in square - * braces. Unmatched placeholders will be left as-is. - * @param errorMessageArgs the arguments to be substituted into the message - * template. Arguments are converted to strings using - * {@link String#valueOf(Object)}. - * @throws IllegalArgumentException if {@code expression} is false - * @throws NullPointerException if the check fails and either {@code - * errorMessageTemplate} or {@code errorMessageArgs} is null (don't let - * this happen) - */ - public static void checkArgument(boolean expression, - String errorMessageTemplate, Object... errorMessageArgs) { - if (!expression) { - throw new IllegalArgumentException( - format(errorMessageTemplate, errorMessageArgs)); - } - } - - /** - * Ensures the truth of an expression involving the state of the calling - * instance, but not involving any parameters to the calling method. - * - * @param expression a boolean expression - * @throws IllegalStateException if {@code expression} is false - */ - public static void checkState(boolean expression) { - if (!expression) { - throw new IllegalStateException(); - } - } - - /** - * Ensures the truth of an expression involving the state of the calling - * instance, but not involving any parameters to the calling method. - * - * @param expression a boolean expression - * @param errorMessage the exception message to use if the check fails; will - * be converted to a string using {@link String#valueOf(Object)} - * @throws IllegalStateException if {@code expression} is false - */ - public static void checkState(boolean expression, Object errorMessage) { - if (!expression) { - throw new IllegalStateException(String.valueOf(errorMessage)); - } - } - - /** - * Ensures the truth of an expression involving the state of the calling - * instance, but not involving any parameters to the calling method. - * - * @param expression a boolean expression - * @param errorMessageTemplate a template for the exception message should the - * check fail. The message is formed by replacing each {@code %s} - * placeholder in the template with an argument. These are matched by - * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. - * Unmatched arguments will be appended to the formatted message in square - * braces. Unmatched placeholders will be left as-is. - * @param errorMessageArgs the arguments to be substituted into the message - * template. Arguments are converted to strings using - * {@link String#valueOf(Object)}. - * @throws IllegalStateException if {@code expression} is false - * @throws NullPointerException if the check fails and either {@code - * errorMessageTemplate} or {@code errorMessageArgs} is null (don't let - * this happen) - */ - public static void checkState(boolean expression, - String errorMessageTemplate, Object... errorMessageArgs) { - if (!expression) { - throw new IllegalStateException( - format(errorMessageTemplate, errorMessageArgs)); - } - } - - /** - * Ensures that an object reference passed as a parameter to the calling - * method is not null. - * - * @param reference an object reference - * @return the non-null reference that was validated - * @throws NullPointerException if {@code reference} is null - */ - public static T checkNotNull(T reference) { - if (reference == null) { - throw new NullPointerException(); - } - return reference; - } - - /** - * Ensures that an object reference passed as a parameter to the calling - * method is not null. - * - * @param reference an object reference - * @param errorMessage the exception message to use if the check fails; will - * be converted to a string using {@link String#valueOf(Object)} - * @return the non-null reference that was validated - * @throws NullPointerException if {@code reference} is null - */ - public static T checkNotNull(T reference, Object errorMessage) { - if (reference == null) { - throw new NullPointerException(String.valueOf(errorMessage)); - } - return reference; - } - - /** - * Ensures that an object reference passed as a parameter to the calling - * method is not null. - * - * @param reference an object reference - * @param errorMessageTemplate a template for the exception message should the - * check fail. The message is formed by replacing each {@code %s} - * placeholder in the template with an argument. These are matched by - * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. - * Unmatched arguments will be appended to the formatted message in square - * braces. Unmatched placeholders will be left as-is. - * @param errorMessageArgs the arguments to be substituted into the message - * template. Arguments are converted to strings using - * {@link String#valueOf(Object)}. - * @return the non-null reference that was validated - * @throws NullPointerException if {@code reference} is null - */ - public static T checkNotNull(T reference, String errorMessageTemplate, - Object... errorMessageArgs) { - if (reference == null) { - // If either of these parameters is null, the right thing happens anyway - throw new NullPointerException( - format(errorMessageTemplate, errorMessageArgs)); - } - return reference; - } - - /** - * Ensures that {@code index} specifies a valid element in an array, - * list or string of size {@code size}. An element index may range from zero, - * inclusive, to {@code size}, exclusive. - * - * @param index a user-supplied index identifying an element of an array, list - * or string - * @param size the size of that array, list or string - * @return the value of {@code index} - * @throws IndexOutOfBoundsException if {@code index} is negative or is not - * less than {@code size} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static int checkElementIndex(int index, int size) { - return checkElementIndex(index, size, "index"); - } - - /** - * Ensures that {@code index} specifies a valid element in an array, - * list or string of size {@code size}. An element index may range from zero, - * inclusive, to {@code size}, exclusive. - * - * @param index a user-supplied index identifying an element of an array, list - * or string - * @param size the size of that array, list or string - * @param desc the text to use to describe this index in an error message - * @return the value of {@code index} - * @throws IndexOutOfBoundsException if {@code index} is negative or is not - * less than {@code size} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static int checkElementIndex(int index, int size, String desc) { - // Carefully optimized for execution by hotspot (explanatory comment above) - if (index < 0 || index >= size) { - throw new IndexOutOfBoundsException(badElementIndex(index, size, desc)); - } - return index; - } - - private static String badElementIndex(int index, int size, String desc) { - if (index < 0) { - return format("%s (%s) must not be negative", desc, index); - } else if (size < 0) { - throw new IllegalArgumentException("negative size: " + size); - } else { // index >= size - return format("%s (%s) must be less than size (%s)", desc, index, size); - } - } - - /** - * Ensures that {@code index} specifies a valid position in an array, - * list or string of size {@code size}. A position index may range from zero - * to {@code size}, inclusive. - * - * @param index a user-supplied index identifying a position in an array, list - * or string - * @param size the size of that array, list or string - * @return the value of {@code index} - * @throws IndexOutOfBoundsException if {@code index} is negative or is - * greater than {@code size} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static int checkPositionIndex(int index, int size) { - return checkPositionIndex(index, size, "index"); - } - - /** - * Ensures that {@code index} specifies a valid position in an array, - * list or string of size {@code size}. A position index may range from zero - * to {@code size}, inclusive. - * - * @param index a user-supplied index identifying a position in an array, list - * or string - * @param size the size of that array, list or string - * @param desc the text to use to describe this index in an error message - * @return the value of {@code index} - * @throws IndexOutOfBoundsException if {@code index} is negative or is - * greater than {@code size} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static int checkPositionIndex(int index, int size, String desc) { - // Carefully optimized for execution by hotspot (explanatory comment above) - if (index < 0 || index > size) { - throw new IndexOutOfBoundsException(badPositionIndex(index, size, desc)); - } - return index; - } - - private static String badPositionIndex(int index, int size, String desc) { - if (index < 0) { - return format("%s (%s) must not be negative", desc, index); - } else if (size < 0) { - throw new IllegalArgumentException("negative size: " + size); - } else { // index > size - return format("%s (%s) must not be greater than size (%s)", - desc, index, size); - } - } - - /** - * Ensures that {@code start} and {@code end} specify a valid positions - * in an array, list or string of size {@code size}, and are in order. A - * position index may range from zero to {@code size}, inclusive. - * - * @param start a user-supplied index identifying a starting position in an - * array, list or string - * @param end a user-supplied index identifying a ending position in an array, - * list or string - * @param size the size of that array, list or string - * @throws IndexOutOfBoundsException if either index is negative or is - * greater than {@code size}, or if {@code end} is less than {@code start} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static void checkPositionIndexes(int start, int end, int size) { - // Carefully optimized for execution by hotspot (explanatory comment above) - if (start < 0 || end < start || end > size) { - throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size)); - } - } - - private static String badPositionIndexes(int start, int end, int size) { - if (start < 0 || start > size) { - return badPositionIndex(start, size, "start index"); - } - if (end < 0 || end > size) { - return badPositionIndex(end, size, "end index"); - } - // end < start - return format("end index (%s) must not be less than start index (%s)", - end, start); - } - - /** - * Substitutes each {@code %s} in {@code template} with an argument. These - * are matched by position - the first {@code %s} gets {@code args[0]}, etc. - * If there are more arguments than placeholders, the unmatched arguments will - * be appended to the end of the formatted message in square braces. - * - * @param template a non-null string containing 0 or more {@code %s} - * placeholders. - * @param args the arguments to be substituted into the message - * template. Arguments are converted to strings using - * {@link String#valueOf(Object)}. Arguments can be null. - */ - @VisibleForTesting static String format(String template, Object... args) { - // start substituting the arguments into the '%s' placeholders - StringBuilder builder = new StringBuilder( - template.length() + 16 * args.length); - int templateStart = 0; - int i = 0; - while (i < args.length) { - int placeholderStart = template.indexOf("%s", templateStart); - if (placeholderStart == -1) { - break; - } - builder.append(template.substring(templateStart, placeholderStart)); - builder.append(args[i++]); - templateStart = placeholderStart + 2; - } - builder.append(template.substring(templateStart)); - - // if we run out of placeholders, append the extra args in square braces - if (i < args.length) { - builder.append(" ["); - builder.append(args[i++]); - while (i < args.length) { - builder.append(", "); - builder.append(args[i++]); - } - builder.append("]"); - } - - return builder.toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Predicate.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Predicate.java deleted file mode 100644 index d81b3b43eb4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Predicate.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; - -/** - * Determines a true or false value for a given input. For example, a - * {@code RegexPredicate} might implement {@code Predicate}, and return - * {@code true} for any string that matches its given regular expression. - * - *

Implementations which may cause side effects upon evaluation are strongly - * encouraged to state this fact clearly in their API documentation. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -public interface Predicate { - - /* - * This interface does not extend Function because doing so would - * let predicates return null. - */ - - /** - * Applies this predicate to the given object. - * - * @param input the input that the predicate should act on - * @return the value of this predicate when applied to the input {@code t} - */ - boolean apply(@Nullable T input); - - /** - * Indicates whether some other object is equal to this {@code Predicate}. - * This method can return {@code true} only if the specified object is - * also a {@code Predicate} and, for every input object {@code input}, it - * returns exactly the same value. Thus, {@code predicate1.equals(predicate2)} - * implies that either {@code predicate1.apply(input)} and - * {@code predicate2.apply(input)} are both {@code true} or both - * {@code false}. - * - *

Note that it is always safe not to override - * {@link Object#equals}. - */ - boolean equals(@Nullable Object obj); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Predicates.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Predicates.java deleted file mode 100644 index 0ebb4da2eb5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Predicates.java +++ /dev/null @@ -1,550 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Contains static factory methods for creating {@code Predicate} instances. - * - *

All methods returns serializable predicates as long as they're given - * serializable parameters. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -public final class Predicates { - private Predicates() {} - - // TODO: considering having these implement a VisitablePredicate interface - // which specifies an accept(PredicateVisitor) method. - - /** - * Returns a predicate that always evaluates to {@code true}. - */ - @GwtCompatible(serializable = true) - @SuppressWarnings("unchecked") - public static Predicate alwaysTrue() { - return (Predicate) AlwaysTruePredicate.INSTANCE; - } - - /** - * Returns a predicate that always evaluates to {@code false}. - */ - @GwtCompatible(serializable = true) - @SuppressWarnings("unchecked") - public static Predicate alwaysFalse() { - return (Predicate) AlwaysFalsePredicate.INSTANCE; - } - - /** - * Returns a predicate that evaluates to {@code true} if the object reference - * being tested is null. - */ - @SuppressWarnings("unchecked") - public static Predicate isNull() { - return (Predicate) IsNullPredicate.INSTANCE; - } - - /** - * Returns a predicate that evaluates to {@code true} if the object reference - * being tested is not null. - */ - @SuppressWarnings("unchecked") - public static Predicate notNull() { - return (Predicate) NotNullPredicate.INSTANCE; - } - - /** - * Returns a predicate that evaluates to {@code true} if the given predicate - * evaluates to {@code false}. - */ - public static Predicate not(Predicate predicate) { - return new NotPredicate(predicate); - } - - /** - * Returns a predicate that evaluates to {@code true} if each of its - * components evaluates to {@code true}. The components are evaluated in - * order, and evaluation will be "short-circuited" as soon as a false - * predicate is found. It defensively copies the iterable passed in, so future - * changes to it won't alter the behavior of this predicate. If {@code - * components} is empty, the returned predicate will always evaluate to {@code - * true}. - */ - public static Predicate and( - Iterable> components) { - return new AndPredicate(defensiveCopy(components)); - } - - /** - * Returns a predicate that evaluates to {@code true} if each of its - * components evaluates to {@code true}. The components are evaluated in - * order, and evaluation will be "short-circuited" as soon as a false - * predicate is found. It defensively copies the array passed in, so future - * changes to it won't alter the behavior of this predicate. If {@code - * components} is empty, the returned predicate will always evaluate to {@code - * true}. - */ - public static Predicate and(Predicate... components) { - return new AndPredicate(defensiveCopy(components)); - } - - /** - * Returns a predicate that evaluates to {@code true} if both of its - * components evaluate to {@code true}. The components are evaluated in - * order, and evaluation will be "short-circuited" as soon as a false - * predicate is found. - */ - public static Predicate and(Predicate first, - Predicate second) { - return new AndPredicate(Predicates.asList( - checkNotNull(first), checkNotNull(second))); - } - - /** - * Returns a predicate that evaluates to {@code true} if any one of its - * components evaluates to {@code true}. The components are evaluated in - * order, and evaluation will be "short-circuited" as soon as as soon as a - * true predicate is found. It defensively copies the iterable passed in, so - * future changes to it won't alter the behavior of this predicate. If {@code - * components} is empty, the returned predicate will always evaluate to {@code - * false}. - */ - public static Predicate or( - Iterable> components) { - return new OrPredicate(defensiveCopy(components)); - } - - /** - * Returns a predicate that evaluates to {@code true} if any one of its - * components evaluates to {@code true}. The components are evaluated in - * order, and evaluation will be "short-circuited" as soon as as soon as a - * true predicate is found. It defensively copies the array passed in, so - * future changes to it won't alter the behavior of this predicate. If {@code - * components} is empty, the returned predicate will always evaluate to {@code - * false}. - */ - public static Predicate or(Predicate... components) { - return new OrPredicate(defensiveCopy(components)); - } - - /** - * Returns a predicate that evaluates to {@code true} if either of its - * components evaluates to {@code true}. The components are evaluated in - * order, and evaluation will be "short-circuited" as soon as as soon as a - * true predicate is found. - */ - public static Predicate or(Predicate first, - Predicate second) { - return new OrPredicate(Predicates.asList( - checkNotNull(first), checkNotNull(second))); - } - - /** - * Returns a predicate that evaluates to {@code true} if the object being - * tested {@code equals()} the given target or both are null. - */ - public static Predicate equalTo(@Nullable T target) { - // TODO: Change signature to return Predicate. - return (target == null) - ? Predicates.isNull() - : new IsEqualToPredicate(target); - } - - /** - * Returns a predicate that evaluates to {@code true} if the object being - * tested is an instance of the given class. If the object being tested - * is {@code null} this predicate evaluates to {@code false}. - * - *

If you want to filter an {@code Iterable} to narrow its type, consider - * using {@link org.elasticsearch.util.collect.Iterables#filter(Iterable, Class)} - * in preference. - */ - @GwtIncompatible("Class.isInstance") - public static Predicate instanceOf(Class clazz) { - return new InstanceOfPredicate(clazz); - } - - /** - * Returns a predicate that evaluates to {@code true} if the object reference - * being tested is a member of the given collection. It does not defensively - * copy the collection passed in, so future changes to it will alter the - * behavior of the predicate. - * - * This method can technically accept any Collection, but using a typed - * collection helps prevent bugs. This approach doesn't block any potential - * users since it is always possible to use {@code Predicates.in()}. - * - * @param target the collection that may contain the function input - */ - public static Predicate in(Collection target) { - return new InPredicate(target); - } - - /** - * Returns the composition of a function and a predicate. For every {@code x}, - * the generated predicate returns {@code predicate(function(x))}. - * - * @return the composition of the provided function and predicate - */ - public static Predicate compose( - Predicate predicate, Function function) { - return new CompositionPredicate(predicate, function); - } - - /** @see Predicates#alwaysTrue() */ - // Package private for GWT serialization. - enum AlwaysTruePredicate implements Predicate { - INSTANCE; - - public boolean apply(Object o) { - return true; - } - @Override public String toString() { - return "AlwaysTrue"; - } - } - - /** @see Predicates#alwaysFalse() */ - // Package private for GWT serialization. - enum AlwaysFalsePredicate implements Predicate { - INSTANCE; - - public boolean apply(Object o) { - return false; - } - @Override public String toString() { - return "AlwaysFalse"; - } - } - - /** @see Predicates#not(Predicate) */ - private static class NotPredicate - implements Predicate, Serializable { - private final Predicate predicate; - - private NotPredicate(Predicate predicate) { - this.predicate = checkNotNull(predicate); - } - public boolean apply(T t) { - return !predicate.apply(t); - } - @Override public int hashCode() { - return ~predicate.hashCode(); /* Invert all bits. */ - } - @Override public boolean equals(Object obj) { - if (obj instanceof NotPredicate) { - NotPredicate that = (NotPredicate) obj; - return predicate.equals(that.predicate); - } - return false; - } - @Override public String toString() { - return "Not(" + predicate.toString() + ")"; - } - private static final long serialVersionUID = 0; - } - - private static final Joiner commaJoiner = Joiner.on(","); - - /** @see Predicates#and(Iterable) */ - private static class AndPredicate - implements Predicate, Serializable { - private final Iterable> components; - - private AndPredicate(Iterable> components) { - this.components = components; - } - public boolean apply(T t) { - for (Predicate predicate : components) { - if (!predicate.apply(t)) { - return false; - } - } - return true; - } - @Override public int hashCode() { - int result = -1; /* Start with all bits on. */ - for (Predicate predicate : components) { - result &= predicate.hashCode(); - } - return result; - } - @Override public boolean equals(Object obj) { - if (obj instanceof AndPredicate) { - AndPredicate that = (AndPredicate) obj; - return iterableElementsEqual(components, that.components); - } - return false; - } - @Override public String toString() { - return "And(" + commaJoiner.join(components) + ")"; - } - private static final long serialVersionUID = 0; - } - - /** @see Predicates#or(Iterable) */ - private static class OrPredicate - implements Predicate, Serializable { - private final Iterable> components; - - private OrPredicate(Iterable> components) { - this.components = components; - } - public boolean apply(T t) { - for (Predicate predicate : components) { - if (predicate.apply(t)) { - return true; - } - } - return false; - } - @Override public int hashCode() { - int result = 0; /* Start with all bits off. */ - for (Predicate predicate : components) { - result |= predicate.hashCode(); - } - return result; - } - @Override public boolean equals(Object obj) { - if (obj instanceof OrPredicate) { - OrPredicate that = (OrPredicate) obj; - return iterableElementsEqual(components, that.components); - } - return false; - } - @Override public String toString() { - return "Or(" + commaJoiner.join(components) + ")"; - } - private static final long serialVersionUID = 0; - } - - /** @see Predicates#equalTo(Object) */ - private static class IsEqualToPredicate - implements Predicate, Serializable { - private final T target; - - private IsEqualToPredicate(T target) { - this.target = target; - } - public boolean apply(T t) { - return target.equals(t); - } - @Override public int hashCode() { - return target.hashCode(); - } - @Override public boolean equals(Object obj) { - if (obj instanceof IsEqualToPredicate) { - IsEqualToPredicate that = (IsEqualToPredicate) obj; - return target.equals(that.target); - } - return false; - } - @Override public String toString() { - return "IsEqualTo(" + target + ")"; - } - private static final long serialVersionUID = 0; - } - - /** @see Predicates#instanceOf(Class) */ - private static class InstanceOfPredicate - implements Predicate, Serializable { - private final Class clazz; - - private InstanceOfPredicate(Class clazz) { - this.clazz = checkNotNull(clazz); - } - public boolean apply(Object o) { - return Platform.isInstance(clazz, o); - } - @Override public int hashCode() { - return clazz.hashCode(); - } - @Override public boolean equals(Object obj) { - if (obj instanceof InstanceOfPredicate) { - InstanceOfPredicate that = (InstanceOfPredicate) obj; - return clazz == that.clazz; - } - return false; - } - @Override public String toString() { - return "IsInstanceOf(" + clazz.getName() + ")"; - } - private static final long serialVersionUID = 0; - } - - /** @see Predicates#isNull() */ - // enum singleton pattern - private enum IsNullPredicate implements Predicate { - INSTANCE; - - public boolean apply(Object o) { - return o == null; - } - @Override public String toString() { - return "IsNull"; - } - } - - /** @see Predicates#notNull() */ - // enum singleton pattern - private enum NotNullPredicate implements Predicate { - INSTANCE; - - public boolean apply(Object o) { - return o != null; - } - @Override public String toString() { - return "NotNull"; - } - } - - /** @see Predicates#in(Collection) */ - private static class InPredicate - implements Predicate, Serializable { - private final Collection target; - - private InPredicate(Collection target) { - this.target = checkNotNull(target); - } - - public boolean apply(T t) { - try { - return target.contains(t); - } catch (NullPointerException e) { - return false; - } catch (ClassCastException e) { - return false; - } - } - - @Override public boolean equals(Object obj) { - if (obj instanceof InPredicate) { - InPredicate that = (InPredicate) obj; - return target.equals(that.target); - } - return false; - } - - @Override public int hashCode() { - return target.hashCode(); - } - - @Override public String toString() { - return "In(" + target + ")"; - } - private static final long serialVersionUID = 0; - } - - /** @see Predicates#compose(Predicate, Function) */ - private static class CompositionPredicate - implements Predicate, Serializable { - final Predicate p; - final Function f; - - private CompositionPredicate(Predicate p, Function f) { - this.p = checkNotNull(p); - this.f = checkNotNull(f); - } - - public boolean apply(A a) { - return p.apply(f.apply(a)); - } - - @Override public boolean equals(Object obj) { - if (obj instanceof CompositionPredicate) { - CompositionPredicate that = (CompositionPredicate) obj; - return f.equals(that.f) && p.equals(that.p); - } - return false; - } - - @Override public int hashCode() { - /* - * TODO: To leave the door open for future enhancement, this - * calculation should be coordinated with the hashCode() method of the - * corresponding composition method in Functions. To construct the - * composition: - * predicate(function2(function1(x))) - * - * There are two different ways of composing it: - * compose(predicate, compose(function2, function1)) - * compose(compose(predicate, function2), function1) - * - * It would be nice if these could be equal. - */ - return f.hashCode() ^ p.hashCode(); - } - - @Override public String toString() { - return p.toString() + "(" + f.toString() + ")"; - } - - private static final long serialVersionUID = 0; - } - - /** - * Determines whether the two Iterables contain equal elements. More - * specifically, this method returns {@code true} if {@code iterable1} and - * {@code iterable2} contain the same number of elements and every element of - * {@code iterable1} is equal to the corresponding element of {@code - * iterable2}. - * - *

This is not a general-purpose method; it assumes that the iterations - * contain no {@code null} elements. - */ - private static boolean iterableElementsEqual( - Iterable iterable1, Iterable iterable2) { - Iterator iterator1 = iterable1.iterator(); - Iterator iterator2 = iterable2.iterator(); - while (iterator1.hasNext()) { - if (!iterator2.hasNext()) { - return false; - } - if (!iterator1.next().equals(iterator2.next())) { - return false; - } - } - return !iterator2.hasNext(); - } - - @SuppressWarnings("unchecked") - private static List> asList( - Predicate first, Predicate second) { - return Arrays.>asList(first, second); - } - - private static List defensiveCopy(T... array) { - return defensiveCopy(Arrays.asList(array)); - } - - static List defensiveCopy(Iterable iterable) { - ArrayList list = new ArrayList(); - for (T element : iterable) { - list.add(checkNotNull(element)); - } - return list; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Supplier.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Supplier.java deleted file mode 100644 index 2b1d5bb5949..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Supplier.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.GwtCompatible; - -/** - * A class that can supply objects of a single type. Semantically, this could - * be a factory, generator, builder, closure, or something else entirely. No - * guarantees are implied by this interface. - * - * @author Harry Heymann - */ -@GwtCompatible -public interface Supplier { - /** - * Retrieves an instance of the appropriate type. The returned object may or - * may not be a new instance, depending on the implementation. - * - * @return an instance of the appropriate type - */ - public T get(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Suppliers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Suppliers.java deleted file mode 100644 index 707e97116a4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/Suppliers.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base; - -import org.elasticsearch.util.annotations.VisibleForTesting; - -import javax.annotation.Nullable; -import java.io.Serializable; - -/** - * Useful suppliers. - * - *

All methods return serializable suppliers as long as they're given - * serializable parameters. - * - * @author Laurence Gonsalves - * @author Harry Heymann - */ -public final class Suppliers { - private Suppliers() {} - - /** - * Returns a new supplier which is the composition of the provided function - * and supplier. In other words, the new supplier's value will be computed by - * retrieving the value from {@code first}, and then applying - * {@code function} to that value. Note that the resulting supplier will not - * call {@code first} or invoke {@code function} until it is called. - */ - public static Supplier compose( - Function function, Supplier first) { - Preconditions.checkNotNull(function); - Preconditions.checkNotNull(first); - return new SupplierComposition(function, first); - } - - private static class SupplierComposition - implements Supplier, Serializable { - final Function function; - final Supplier first; - - SupplierComposition(Function function, - Supplier first) { - this.function = function; - this.first = first; - } - public T get() { - return function.apply(first.get()); - } - private static final long serialVersionUID = 0; - } - - /** - * Returns a supplier which caches the instance retrieved during the first - * call to {@code get()} and returns that value on subsequent calls to - * {@code get()}. See: - * memoization - * - *

The returned supplier is thread-safe. The supplier's serialized form - * does not contain the cached value, which will be recalculated when {@code - * get()} is called on the reserialized instance. - */ - public static Supplier memoize(Supplier delegate) { - return new MemoizingSupplier(Preconditions.checkNotNull(delegate)); - } - - @VisibleForTesting static class MemoizingSupplier - implements Supplier, Serializable { - final Supplier delegate; - transient boolean initialized; - transient T value; - - MemoizingSupplier(Supplier delegate) { - this.delegate = delegate; - } - - public synchronized T get() { - if (!initialized) { - value = delegate.get(); - initialized = true; - } - return value; - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a supplier that always supplies {@code instance}. - */ - public static Supplier ofInstance(@Nullable T instance) { - return new SupplierOfInstance(instance); - } - - private static class SupplierOfInstance - implements Supplier, Serializable { - final T instance; - - SupplierOfInstance(T instance) { - this.instance = instance; - } - public T get() { - return instance; - } - private static final long serialVersionUID = 0; - } - - /** - * Returns a supplier whose {@code get()} method synchronizes on - * {@code delegate} before calling it, making it thread-safe. - */ - public static Supplier synchronizedSupplier(Supplier delegate) { - return new ThreadSafeSupplier(Preconditions.checkNotNull(delegate)); - } - - private static class ThreadSafeSupplier - implements Supplier, Serializable { - final Supplier delegate; - - ThreadSafeSupplier(Supplier delegate) { - this.delegate = delegate; - } - public T get() { - synchronized (delegate) { - return delegate.get(); - } - } - private static final long serialVersionUID = 0; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/internal/Finalizer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/internal/Finalizer.java deleted file mode 100644 index e0136add7ce..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/internal/Finalizer.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.base.internal; - -import java.lang.ref.PhantomReference; -import java.lang.ref.Reference; -import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Thread that finalizes referents. All references should implement - * {@code com.google.common.base.FinalizableReference}. - * - *

While this class is public, we consider it to be *internal* and not part - * of our published API. It is public so we can access it reflectively across - * class loaders in secure environments. - * - *

This class can't depend on other Google Collections code. If we were - * to load this class in the same class loader as the rest of - * Google Collections, this thread would keep an indirect strong reference - * to the class loader and prevent it from being garbage collected. This - * poses a problem for environments where you want to throw away the class - * loader. For example, dynamically reloading a web application or unloading - * an OSGi bundle. - * - *

{@code com.google.common.base.FinalizableReferenceQueue} loads this class - * in its own class loader. That way, this class doesn't prevent the main - * class loader from getting garbage collected, and this class can detect when - * the main class loader has been garbage collected and stop itself. - */ -public class Finalizer extends Thread { - - private static final Logger logger - = Logger.getLogger(Finalizer.class.getName()); - - /** Name of FinalizableReference.class. */ - private static final String FINALIZABLE_REFERENCE - = "org.elasticsearch.util.base.FinalizableReference"; - - /** - * Starts the Finalizer thread. FinalizableReferenceQueue calls this method - * reflectively. - * - * @param finalizableReferenceClass FinalizableReference.class - * @param frq reference to instance of FinalizableReferenceQueue that started - * this thread - * @return ReferenceQueue which Finalizer will poll - */ - public static ReferenceQueue startFinalizer( - Class finalizableReferenceClass, Object frq) { - /* - * We use FinalizableReference.class for two things: - * - * 1) To invoke FinalizableReference.finalizeReferent() - * - * 2) To detect when FinalizableReference's class loader has to be garbage - * collected, at which point, Finalizer can stop running - */ - if (!finalizableReferenceClass.getName().equals(FINALIZABLE_REFERENCE)) { - throw new IllegalArgumentException( - "Expected " + FINALIZABLE_REFERENCE + "."); - } - - Finalizer finalizer = new Finalizer(finalizableReferenceClass, frq); - finalizer.start(); - return finalizer.queue; - } - - private final WeakReference> finalizableReferenceClassReference; - private final PhantomReference frqReference; - private final ReferenceQueue queue = new ReferenceQueue(); - - private static final Field inheritableThreadLocals - = getInheritableThreadLocalsField(); - - /** Constructs a new finalizer thread. */ - private Finalizer(Class finalizableReferenceClass, Object frq) { - super(Finalizer.class.getName()); - - this.finalizableReferenceClassReference - = new WeakReference>(finalizableReferenceClass); - - // Keep track of the FRQ that started us so we know when to stop. - this.frqReference = new PhantomReference(frq, queue); - - setDaemon(true); - - try { - if (inheritableThreadLocals != null) { - inheritableThreadLocals.set(this, null); - } - } catch (Throwable t) { - logger.log(Level.INFO, "Failed to clear thread local values inherited" - + " by reference finalizer thread.", t); - } - - // TODO: Priority? - } - - /** - * Loops continuously, pulling references off the queue and cleaning them up. - */ - @SuppressWarnings("InfiniteLoopStatement") - @Override - public void run() { - try { - while (true) { - try { - cleanUp(queue.remove()); - } catch (InterruptedException e) { /* ignore */ } - } - } catch (ShutDown shutDown) { /* ignore */ } - } - - /** - * Cleans up a single reference. Catches and logs all throwables. - */ - private void cleanUp(Reference reference) throws ShutDown { - Method finalizeReferentMethod = getFinalizeReferentMethod(); - do { - /* - * This is for the benefit of phantom references. Weak and soft - * references will have already been cleared by this point. - */ - reference.clear(); - - if (reference == frqReference) { - /* - * The client no longer has a reference to the - * FinalizableReferenceQueue. We can stop. - */ - throw new ShutDown(); - } - - try { - finalizeReferentMethod.invoke(reference); - } catch (Throwable t) { - logger.log(Level.SEVERE, "Error cleaning up after reference.", t); - } - - /* - * Loop as long as we have references available so as not to waste - * CPU looking up the Method over and over again. - */ - } while ((reference = queue.poll()) != null); - } - - /** - * Looks up FinalizableReference.finalizeReferent() method. - */ - private Method getFinalizeReferentMethod() throws ShutDown { - Class finalizableReferenceClass - = finalizableReferenceClassReference.get(); - if (finalizableReferenceClass == null) { - /* - * FinalizableReference's class loader was reclaimed. While there's a - * chance that other finalizable references could be enqueued - * subsequently (at which point the class loader would be resurrected - * by virtue of us having a strong reference to it), we should pretty - * much just shut down and make sure we don't keep it alive any longer - * than necessary. - */ - throw new ShutDown(); - } - try { - return finalizableReferenceClass.getMethod("finalizeReferent"); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } - } - - public static Field getInheritableThreadLocalsField() { - try { - Field inheritableThreadLocals - = Thread.class.getDeclaredField("inheritableThreadLocals"); - inheritableThreadLocals.setAccessible(true); - return inheritableThreadLocals; - } catch (Throwable t) { - logger.log(Level.INFO, "Couldn't access Thread.inheritableThreadLocals." - + " Reference finalizer threads will inherit thread local" - + " values."); - return null; - } - } - - /** Indicates that it's time to shut down the Finalizer. */ - @SuppressWarnings("serial") // Never serialized or thrown out of this class. - private static class ShutDown extends Exception { } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/package-info.java deleted file mode 100644 index 9ae2256ec7b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/base/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Miscellaneous common util classes and annotations. - */ -package org.elasticsearch.util.base; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractBiMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractBiMap.java deleted file mode 100644 index ee3f4e6e5d6..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractBiMap.java +++ /dev/null @@ -1,393 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Objects; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * A general-purpose bimap implementation using any two backing {@code Map} - * instances. - * - *

Note that this class contains {@code equals()} calls that keep it from - * supporting {@code IdentityHashMap} backing maps. - * - * @author Kevin Bourrillion - * @author Mike Bostock - */ -@GwtCompatible -abstract class AbstractBiMap extends ForwardingMap - implements BiMap, Serializable { - - private transient Map delegate; - private transient AbstractBiMap inverse; - - /** Package-private constructor for creating a map-backed bimap. */ - AbstractBiMap(Map forward, Map backward) { - setDelegates(forward, backward); - } - - /** Private constructor for inverse bimap. */ - private AbstractBiMap(Map backward, AbstractBiMap forward) { - delegate = backward; - inverse = forward; - } - - @Override protected Map delegate() { - return delegate; - } - - /** - * Specifies the delegate maps going in each direction. Called by the - * constructor and by subclasses during deserialization. - */ - void setDelegates(Map forward, Map backward) { - checkState(delegate == null); - checkState(inverse == null); - checkArgument(forward.isEmpty()); - checkArgument(backward.isEmpty()); - checkArgument(forward != backward); - delegate = forward; - inverse = new Inverse(backward, this); - } - - void setInverse(AbstractBiMap inverse) { - this.inverse = inverse; - } - - // Query Operations (optimizations) - - @Override public boolean containsValue(Object value) { - return inverse.containsKey(value); - } - - // Modification Operations - - @Override public V put(K key, V value) { - return putInBothMaps(key, value, false); - } - - public V forcePut(K key, V value) { - return putInBothMaps(key, value, true); - } - - private V putInBothMaps(@Nullable K key, @Nullable V value, boolean force) { - boolean containedKey = containsKey(key); - if (containedKey && Objects.equal(value, get(key))) { - return value; - } - if (force) { - inverse().remove(value); - } else { - checkArgument(!containsValue(value), "value already present: %s", value); - } - V oldValue = delegate.put(key, value); - updateInverseMap(key, containedKey, oldValue, value); - return oldValue; - } - - private void updateInverseMap( - K key, boolean containedKey, V oldValue, V newValue) { - if (containedKey) { - removeFromInverseMap(oldValue); - } - inverse.delegate.put(newValue, key); - } - - @Override public V remove(Object key) { - return containsKey(key) ? removeFromBothMaps(key) : null; - } - - private V removeFromBothMaps(Object key) { - V oldValue = delegate.remove(key); - removeFromInverseMap(oldValue); - return oldValue; - } - - private void removeFromInverseMap(V oldValue) { - inverse.delegate.remove(oldValue); - } - - // Bulk Operations - - @Override public void putAll(Map map) { - for (Entry entry : map.entrySet()) { - put(entry.getKey(), entry.getValue()); - } - } - - @Override public void clear() { - delegate.clear(); - inverse.delegate.clear(); - } - - // Views - - public BiMap inverse() { - return inverse; - } - - private transient Set keySet; - - @Override public Set keySet() { - Set result = keySet; - return (result == null) ? keySet = new KeySet() : result; - } - - private class KeySet extends ForwardingSet { - @Override protected Set delegate() { - return delegate.keySet(); - } - - @Override public void clear() { - AbstractBiMap.this.clear(); - } - - @Override public boolean remove(Object key) { - if (!contains(key)) { - return false; - } - removeFromBothMaps(key); - return true; - } - - @Override public boolean removeAll(Collection keysToRemove) { - return Iterators.removeAll(iterator(), keysToRemove); - } - - @Override public boolean retainAll(Collection keysToRetain) { - return Iterators.retainAll(iterator(), keysToRetain); - } - - @Override public Iterator iterator() { - final Iterator> iterator = delegate.entrySet().iterator(); - return new Iterator() { - Entry entry; - - public boolean hasNext() { - return iterator.hasNext(); - } - public K next() { - entry = iterator.next(); - return entry.getKey(); - } - public void remove() { - checkState(entry != null); - V value = entry.getValue(); - iterator.remove(); - removeFromInverseMap(value); - } - }; - } - } - - private transient Set valueSet; - - @Override public Set values() { - /* - * We can almost reuse the inverse's keySet, except we have to fix the - * iteration order so that it is consistent with the forward map. - */ - Set result = valueSet; - return (result == null) ? valueSet = new ValueSet() : result; - } - - private class ValueSet extends ForwardingSet { - final Set valuesDelegate = inverse.keySet(); - - @Override protected Set delegate() { - return valuesDelegate; - } - - @Override public Iterator iterator() { - final Iterator iterator = delegate.values().iterator(); - return new Iterator() { - V valueToRemove; - - /*@Override*/ public boolean hasNext() { - return iterator.hasNext(); - } - - /*@Override*/ public V next() { - return valueToRemove = iterator.next(); - } - - /*@Override*/ public void remove() { - iterator.remove(); - removeFromInverseMap(valueToRemove); - } - }; - } - - @Override public Object[] toArray() { - return ObjectArrays.toArrayImpl(this); - } - - @Override public T[] toArray(T[] array) { - return ObjectArrays.toArrayImpl(this, array); - } - - @Override public String toString() { - return Iterators.toString(iterator()); - } - } - - private transient Set> entrySet; - - @Override public Set> entrySet() { - Set> result = entrySet; - return (result == null) ? entrySet = new EntrySet() : result; - } - - private class EntrySet extends ForwardingSet> { - final Set> esDelegate = delegate.entrySet(); - - @Override protected Set> delegate() { - return esDelegate; - } - - @Override public void clear() { - AbstractBiMap.this.clear(); - } - - @Override public boolean remove(Object object) { - if (!esDelegate.remove(object)) { - return false; - } - Entry entry = (Entry) object; - inverse.delegate.remove(entry.getValue()); - return true; - } - - @Override public Iterator> iterator() { - final Iterator> iterator = esDelegate.iterator(); - return new Iterator>() { - Entry entry; - - /*@Override*/ public boolean hasNext() { - return iterator.hasNext(); - } - - /*@Override*/ public Entry next() { - entry = iterator.next(); - final Entry finalEntry = entry; - - return new ForwardingMapEntry() { - @Override protected Entry delegate() { - return finalEntry; - } - - @Override public V setValue(V value) { - // Preconditions keep the map and inverse consistent. - checkState(contains(this), "entry no longer in map"); - // similar to putInBothMaps, but set via entry - if (Objects.equal(value, getValue())) { - return value; - } - checkArgument(!containsValue(value), - "value already present: %s", value); - V oldValue = finalEntry.setValue(value); - checkState(Objects.equal(value, get(getKey())), - "entry no longer in map"); - updateInverseMap(getKey(), true, oldValue, value); - return oldValue; - } - }; - } - - /*@Override*/ public void remove() { - checkState(entry != null); - V value = entry.getValue(); - iterator.remove(); - removeFromInverseMap(value); - } - }; - } - - // See java.util.Collections.CheckedEntrySet for details on attacks. - - @Override public Object[] toArray() { - return ObjectArrays.toArrayImpl(this); - } - @Override public T[] toArray(T[] array) { - return ObjectArrays.toArrayImpl(this, array); - } - @Override public boolean contains(Object o) { - return Maps.containsEntryImpl(delegate(), o); - } - @Override public boolean containsAll(Collection c) { - return Collections2.containsAll(this, c); - } - @Override public boolean removeAll(Collection c) { - return Iterators.removeAll(iterator(), c); - } - @Override public boolean retainAll(Collection c) { - return Iterators.retainAll(iterator(), c); - } - } - - /** The inverse of any other {@code AbstractBiMap} subclass. */ - private static class Inverse extends AbstractBiMap { - private Inverse(Map backward, AbstractBiMap forward) { - super(backward, forward); - } - - /* - * Serialization stores the forward bimap, the inverse of this inverse. - * Deserialization calls inverse() on the forward bimap and returns that - * inverse. - * - * If a bimap and its inverse are serialized together, the deserialized - * instances have inverse() methods that return the other. - */ - - /** - * @serialData the forward bimap - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(inverse()); - } - - @SuppressWarnings("unchecked") // reading data stored by writeObject - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - setInverse((AbstractBiMap) stream.readObject()); - } - - Object readResolve() { - return inverse().inverse(); - } - - private static final long serialVersionUID = 0; - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractIterator.java deleted file mode 100644 index f113be63a01..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractIterator.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.NoSuchElementException; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * This class provides a skeletal implementation of the {@code Iterator} - * interface, to make this interface easier to implement for certain types of - * data sources. - * - *

{@code Iterator} requires its implementations to support querying the - * end-of-data status without changing the iterator's state, using the {@link - * #hasNext} method. But many data sources, such as {@link - * java.io.Reader#read()}), do not expose this information; the only way to - * discover whether there is any data left is by trying to retrieve it. These - * types of data sources are ordinarily difficult to write iterators for. But - * using this class, one must implement only the {@link #computeNext} method, - * and invoke the {@link #endOfData} method when appropriate. - * - *

Another example is an iterator that skips over null elements in a backing - * iterator. This could be implemented as:

   {@code
- *
- *   public static Iterator skipNulls(final Iterator in) {
- *     return new AbstractIterator() {
- *       protected String computeNext() {
- *         while (in.hasNext()) {
- *           String s = in.next();
- *           if (s != null) {
- *             return s;
- *           }
- *         }
- *         return endOfData();
- *       }
- *     };
- *   }}
- * - * This class supports iterators that include null elements. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -public abstract class AbstractIterator extends UnmodifiableIterator { - private State state = State.NOT_READY; - - private enum State { - /** We have computed the next element and haven't returned it yet. */ - READY, - - /** We haven't yet computed or have already returned the element. */ - NOT_READY, - - /** We have reached the end of the data and are finished. */ - DONE, - - /** We've suffered an exception and are kaput. */ - FAILED, - } - - private T next; - - /** - * Returns the next element. Note: the implementation must call {@link - * #endOfData()} when there are no elements left in the iteration. Failure to - * do so could result in an infinite loop. - * - *

The initial invocation of {@link #hasNext()} or {@link #next()} calls - * this method, as does the first invocation of {@code hasNext} or {@code - * next} following each successful call to {@code next}. Once the - * implementation either invokes {@code endOfData} or throws an exception, - * {@code computeNext} is guaranteed to never be called again. - * - *

If this method throws an exception, it will propagate outward to the - * {@code hasNext} or {@code next} invocation that invoked this method. Any - * further attempts to use the iterator will result in an {@link - * IllegalStateException}. - * - *

The implementation of this method may not invoke the {@code hasNext}, - * {@code next}, or {@link #peek()} methods on this instance; if it does, an - * {@code IllegalStateException} will result. - * - * @return the next element if there was one. If {@code endOfData} was called - * during execution, the return value will be ignored. - * @throws RuntimeException if any unrecoverable error happens. This exception - * will propagate outward to the {@code hasNext()}, {@code next()}, or - * {@code peek()} invocation that invoked this method. Any further - * attempts to use the iterator will result in an - * {@link IllegalStateException}. - */ - protected abstract T computeNext(); - - /** - * Implementations of {@code computeNext} must invoke this method when - * there are no elements left in the iteration. - * - * @return {@code null}; a convenience so your {@link #computeNext} - * implementation can use the simple statement {@code return endOfData();} - */ - protected final T endOfData() { - state = State.DONE; - return null; - } - - public final boolean hasNext() { - checkState(state != State.FAILED); - switch (state) { - case DONE: - return false; - case READY: - return true; - default: - } - return tryToComputeNext(); - } - - private boolean tryToComputeNext() { - state = State.FAILED; // temporary pessimism - next = computeNext(); - if (state != State.DONE) { - state = State.READY; - return true; - } - return false; - } - - public final T next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - state = State.NOT_READY; - return next; - } - - /** - * Returns the next element in the iteration without advancing the iteration, - * according to the contract of {@link PeekingIterator#peek()}. - * - *

Implementations of {@code AbstractIterator} that wish to expose this - * functionality should implement {@code PeekingIterator}. - */ - public final T peek() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - return next; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractListMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractListMultimap.java deleted file mode 100644 index f75f75fb988..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractListMultimap.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -/** - * Basic implementation of the {@link ListMultimap} interface. It's a wrapper - * around {@link AbstractMultimap} that converts the returned collections into - * {@code Lists}. The {@link #createCollection} method must return a {@code - * List}. - * - * @author Jared Levy - */ -@GwtCompatible -abstract class AbstractListMultimap - extends AbstractMultimap implements ListMultimap { - /** - * Creates a new multimap that uses the provided map. - * - * @param map place to store the mapping from each key to its corresponding - * values - */ - protected AbstractListMultimap(Map> map) { - super(map); - } - - @Override abstract List createCollection(); - - @Override public List get(@Nullable K key) { - return (List) super.get(key); - } - - @Override public List removeAll(@Nullable Object key) { - return (List) super.removeAll(key); - } - - @Override public List replaceValues( - @Nullable K key, Iterable values) { - return (List) super.replaceValues(key, values); - } - - /** - * Stores a key-value pair in the multimap. - * - * @param key key to store in the multimap - * @param value value to store in the multimap - * @return {@code true} always - */ - @Override public boolean put(@Nullable K key, @Nullable V value) { - return super.put(key, value); - } - - /** - * Compares the specified object to this multimap for equality. - * - *

Two {@code ListMultimap} instances are equal if, for each key, they - * contain the same values in the same order. If the value orderings disagree, - * the multimaps will not be considered equal. - */ - @Override public boolean equals(@Nullable Object object) { - return super.equals(object); - } - - private static final long serialVersionUID = 6588350623831699109L; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMapBasedMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMapBasedMultiset.java deleted file mode 100644 index 202702795a4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMapBasedMultiset.java +++ /dev/null @@ -1,407 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.InvalidObjectException; -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.elasticsearch.util.base.Preconditions.*; -import static org.elasticsearch.util.collect.Multisets.*; - -/** - * Basic implementation of {@code Multiset} backed by an instance of {@code - * Map}. - * - *

For serialization to work, the subclass must specify explicit {@code - * readObject} and {@code writeObject} methods. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -abstract class AbstractMapBasedMultiset extends AbstractMultiset - implements Serializable { - - // TODO: Replace AtomicInteger with a to-be-written IntegerHolder class for - // better performance. - private transient Map backingMap; - - /* - * Cache the size for efficiency. Using a long lets us avoid the need for - * overflow checking and ensures that size() will function correctly even if - * the multiset had once been larger than Integer.MAX_VALUE. - */ - private transient long size; - - /** Standard constructor. */ - protected AbstractMapBasedMultiset(Map backingMap) { - this.backingMap = checkNotNull(backingMap); - this.size = super.size(); - } - - Map backingMap() { - return backingMap; - } - - /** Used during deserialization only. The backing map must be empty. */ - void setBackingMap(Map backingMap) { - this.backingMap = backingMap; - } - - // Required Implementations - - private transient EntrySet entrySet; - - /** - * {@inheritDoc} - * - *

Invoking {@link Multiset.Entry#getCount} on an entry in the returned - * set always returns the current count of that element in the multiset, as - * opposed to the count at the time the entry was retrieved. - */ - @Override public Set> entrySet() { - EntrySet result = entrySet; - if (result == null) { - entrySet = result = new EntrySet(); - } - return result; - } - - private class EntrySet extends AbstractSet> { - @Override public Iterator> iterator() { - final Iterator> backingEntries - = backingMap.entrySet().iterator(); - return new Iterator>() { - Map.Entry toRemove; - - public boolean hasNext() { - return backingEntries.hasNext(); - } - - public Multiset.Entry next() { - final Map.Entry mapEntry = backingEntries.next(); - toRemove = mapEntry; - return new Multisets.AbstractEntry() { - public E getElement() { - return mapEntry.getKey(); - } - public int getCount() { - int count = mapEntry.getValue().get(); - if (count == 0) { - AtomicInteger frequency = backingMap.get(getElement()); - if (frequency != null) { - count = frequency.get(); - } - } - return count; - } - }; - } - - public void remove() { - checkState(toRemove != null, - "no calls to next() since the last call to remove()"); - size -= toRemove.getValue().getAndSet(0); - backingEntries.remove(); - toRemove = null; - } - }; - } - - @Override public int size() { - return backingMap.size(); - } - - // The following overrides are for better performance. - - @Override public void clear() { - for (AtomicInteger frequency : backingMap.values()) { - frequency.set(0); - } - backingMap.clear(); - size = 0L; - } - - @Override public boolean contains(Object o) { - if (o instanceof Entry) { - Entry entry = (Entry) o; - int count = count(entry.getElement()); - return (count == entry.getCount()) && (count > 0); - } - return false; - } - - @Override public boolean remove(Object o) { - if (contains(o)) { - Entry entry = (Entry) o; - AtomicInteger frequency = backingMap.remove(entry.getElement()); - int numberRemoved = frequency.getAndSet(0); - size -= numberRemoved; - return true; - } - return false; - } - } - - // Optimizations - Query Operations - - @Override public int size() { - return (int) Math.min(this.size, Integer.MAX_VALUE); - } - - @Override public Iterator iterator() { - return new MapBasedMultisetIterator(); - } - - /* - * Not subclassing AbstractMultiset$MultisetIterator because next() needs to - * retrieve the Map.Entry entry, which can then be used for - * a more efficient remove() call. - */ - private class MapBasedMultisetIterator implements Iterator { - final Iterator> entryIterator; - Map.Entry currentEntry; - int occurrencesLeft; - boolean canRemove; - - MapBasedMultisetIterator() { - this.entryIterator = backingMap.entrySet().iterator(); - } - - public boolean hasNext() { - return occurrencesLeft > 0 || entryIterator.hasNext(); - } - - public E next() { - if (occurrencesLeft == 0) { - currentEntry = entryIterator.next(); - occurrencesLeft = currentEntry.getValue().get(); - } - occurrencesLeft--; - canRemove = true; - return currentEntry.getKey(); - } - - public void remove() { - checkState(canRemove, - "no calls to next() since the last call to remove()"); - int frequency = currentEntry.getValue().get(); - if (frequency <= 0) { - throw new ConcurrentModificationException(); - } - if (currentEntry.getValue().addAndGet(-1) == 0) { - entryIterator.remove(); - } - size--; - canRemove = false; - } - } - - @Override public int count(@Nullable Object element) { - AtomicInteger frequency = backingMap.get(element); - return (frequency == null) ? 0 : frequency.get(); - } - - // Optional Operations - Modification Operations - - /** - * {@inheritDoc} - * - * @throws IllegalArgumentException if the call would result in more than - * {@link Integer#MAX_VALUE} occurrences of {@code element} in this - * multiset. - */ - @Override public int add(@Nullable E element, int occurrences) { - if (occurrences == 0) { - return count(element); - } - checkArgument( - occurrences > 0, "occurrences cannot be negative: %s", occurrences); - AtomicInteger frequency = backingMap.get(element); - int oldCount; - if (frequency == null) { - oldCount = 0; - backingMap.put(element, new AtomicInteger(occurrences)); - } else { - oldCount = frequency.get(); - long newCount = (long) oldCount + (long) occurrences; - checkArgument(newCount <= Integer.MAX_VALUE, - "too many occurrences: %s", newCount); - frequency.getAndAdd(occurrences); - } - size += occurrences; - return oldCount; - } - - @Override public int remove(@Nullable Object element, int occurrences) { - if (occurrences == 0) { - return count(element); - } - checkArgument( - occurrences > 0, "occurrences cannot be negative: %s", occurrences); - AtomicInteger frequency = backingMap.get(element); - if (frequency == null) { - return 0; - } - - int oldCount = frequency.get(); - - int numberRemoved; - if (oldCount > occurrences) { - numberRemoved = occurrences; - } else { - numberRemoved = oldCount; - backingMap.remove(element); - } - - frequency.addAndGet(-numberRemoved); - size -= numberRemoved; - return oldCount; - } - - // Roughly a 33% performance improvement over AbstractMultiset.setCount(). - @Override public int setCount(E element, int count) { - checkNonnegative(count, "count"); - - AtomicInteger existingCounter; - int oldCount; - if (count == 0) { - existingCounter = backingMap.remove(element); - oldCount = getAndSet(existingCounter, count); - } else { - existingCounter = backingMap.get(element); - oldCount = getAndSet(existingCounter, count); - - if (existingCounter == null) { - backingMap.put(element, new AtomicInteger(count)); - } - } - - size += (count - oldCount); - return oldCount; - } - - private static int getAndSet(AtomicInteger i, int count) { - if (i == null) { - return 0; - } - - return i.getAndSet(count); - } - - private int removeAllOccurrences(@Nullable Object element, - Map map) { - AtomicInteger frequency = map.remove(element); - if (frequency == null) { - return 0; - } - int numberRemoved = frequency.getAndSet(0); - size -= numberRemoved; - return numberRemoved; - } - - // Views - - @Override Set createElementSet() { - return new MapBasedElementSet(backingMap); - } - - class MapBasedElementSet extends ForwardingSet { - - // This mapping is the usually the same as {@code backingMap}, but can be a - // submap in some implementations. - private final Map map; - private final Set delegate; - - MapBasedElementSet(Map map) { - this.map = map; - delegate = map.keySet(); - } - - @Override protected Set delegate() { - return delegate; - } - - // TODO: a way to not have to write this much code? - - @Override public Iterator iterator() { - final Iterator> entries - = map.entrySet().iterator(); - return new Iterator() { - Map.Entry toRemove; - - public boolean hasNext() { - return entries.hasNext(); - } - - public E next() { - toRemove = entries.next(); - return toRemove.getKey(); - } - - public void remove() { - checkState(toRemove != null, - "no calls to next() since the last call to remove()"); - size -= toRemove.getValue().getAndSet(0); - entries.remove(); - toRemove = null; - } - }; - } - - @Override public boolean remove(Object element) { - return removeAllOccurrences(element, map) != 0; - } - - @Override public boolean removeAll(Collection elementsToRemove) { - return Iterators.removeAll(iterator(), elementsToRemove); - } - - @Override public boolean retainAll(Collection elementsToRetain) { - return Iterators.retainAll(iterator(), elementsToRetain); - } - - @Override public void clear() { - if (map == backingMap) { - AbstractMapBasedMultiset.this.clear(); - } else { - Iterator i = iterator(); - while (i.hasNext()) { - i.next(); - i.remove(); - } - } - } - - public Map getMap() { - return map; - } - } - - // Don't allow default serialization. - @SuppressWarnings("unused") // actually used during deserialization - private void readObjectNoData() throws ObjectStreamException { - throw new InvalidObjectException("Stream data required"); - } - - private static final long serialVersionUID = -2250766705698539974L; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMapEntry.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMapEntry.java deleted file mode 100644 index 6b7bd0abf2e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMapEntry.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Objects; - -import javax.annotation.Nullable; -import java.util.Map.Entry; - -/** - * Implementation of the {@code equals}, {@code hashCode}, and {@code toString} - * methods of {@code Entry}. - * - * @author Jared Levy - */ -@GwtCompatible -abstract class AbstractMapEntry implements Entry { - - public abstract K getKey(); - - public abstract V getValue(); - - public V setValue(V value) { - throw new UnsupportedOperationException(); - } - - @Override public boolean equals(@Nullable Object object) { - if (object instanceof Entry) { - Entry that = (Entry) object; - return Objects.equal(this.getKey(), that.getKey()) - && Objects.equal(this.getValue(), that.getValue()); - } - return false; - } - - @Override public int hashCode() { - K k = getKey(); - V v = getValue(); - return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode()); - } - - /** - * Returns a string representation of the form {key}={value}. - */ - @Override public String toString() { - return getKey() + "=" + getValue(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMultimap.java deleted file mode 100644 index c10e9f33417..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMultimap.java +++ /dev/null @@ -1,1476 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Basic implementation of the {@link Multimap} interface. This class represents - * a multimap as a map that associates each key with a collection of values. All - * methods of {@link Multimap} are supported, including those specified as - * optional in the interface. - * - *

To implement a multimap, a subclass must define the method {@link - * #createCollection()}, which creates an empty collection of values for a key. - * - *

The multimap constructor takes a map that has a single entry for each - * distinct key. When you insert a key-value pair with a key that isn't already - * in the multimap, {@code AbstractMultimap} calls {@link #createCollection()} - * to create the collection of values for that key. The subclass should not call - * {@link #createCollection()} directly, and a new instance should be created - * every time the method is called. - * - *

For example, the subclass could pass a {@link java.util.TreeMap} during - * construction, and {@link #createCollection()} could return a {@link - * java.util.TreeSet}, in which case the multimap's iterators would propagate - * through the keys and values in sorted order. - * - *

Keys and values may be null, as long as the underlying collection classes - * support null elements. - * - *

The collections created by {@link #createCollection()} may or may not - * allow duplicates. If the collection, such as a {@link Set}, does not support - * duplicates, an added key-value pair will replace an existing pair with the - * same key and value, if such a pair is present. With collections like {@link - * List} that allow duplicates, the collection will keep the existing key-value - * pairs while adding a new pair. - * - *

This class is not threadsafe when any concurrent operations update the - * multimap, even if the underlying map and {@link #createCollection()} method - * return threadsafe classes. Concurrent read operations will work correctly. To - * allow concurrent update operations, wrap your multimap with a call to {@link - * Multimaps#synchronizedMultimap}. - * - *

For serialization to work, the subclass must specify explicit - * {@code readObject} and {@code writeObject} methods. - * - * @author Jared Levy - */ -@GwtCompatible -abstract class AbstractMultimap implements Multimap, Serializable { - /* - * Here's an outline of the overall design. - * - * The map variable contains the collection of values associated with each - * key. When a key-value pair is added to a multimap that didn't previously - * contain any values for that key, a new collection generated by - * createCollection is added to the map. That same collection instance - * remains in the map as long as the multimap has any values for the key. If - * all values for the key are removed, the key and collection are removed - * from the map. - * - * The get method returns a WrappedCollection, which decorates the collection - * in the map (if the key is present) or an empty collection (if the key is - * not present). When the collection delegate in the WrappedCollection is - * empty, the multimap may contain subsequently added values for that key. To - * handle that situation, the WrappedCollection checks whether map contains - * an entry for the provided key, and if so replaces the delegate. - */ - - private transient Map> map; - private transient int totalSize; - - /** - * Creates a new multimap that uses the provided map. - * - * @param map place to store the mapping from each key to its corresponding - * values - * @throws IllegalArgumentException if {@code map} is not empty - */ - protected AbstractMultimap(Map> map) { - checkArgument(map.isEmpty()); - this.map = map; - } - - /** Used during deserialization only. */ - final void setMap(Map> map) { - this.map = map; - totalSize = 0; - for (Collection values : map.values()) { - checkArgument(!values.isEmpty()); - totalSize += values.size(); - } - } - - /** - * Creates the collection of values for a single key. - * - *

Collections with weak, soft, or phantom references are not supported. - * Each call to {@code createCollection} should create a new instance. - * - *

The returned collection class determines whether duplicate key-value - * pairs are allowed. - * - * @return an empty collection of values - */ - abstract Collection createCollection(); - - /** - * Creates the collection of values for an explicitly provided key. By - * default, it simply calls {@link #createCollection()}, which is the correct - * behavior for most implementations. The {@link LinkedHashMultimap} class - * overrides it. - * - * @param key key to associate with values in the collection - * @return an empty collection of values - */ - Collection createCollection(@Nullable K key) { - return createCollection(); - } - - Map> backingMap() { - return map; - } - - // Query Operations - - public int size() { - return totalSize; - } - - public boolean isEmpty() { - return totalSize == 0; - } - - public boolean containsKey(@Nullable Object key) { - return map.containsKey(key); - } - - public boolean containsValue(@Nullable Object value) { - for (Collection collection : map.values()) { - if (collection.contains(value)) { - return true; - } - } - - return false; - } - - public boolean containsEntry(@Nullable Object key, @Nullable Object value) { - Collection collection = map.get(key); - return collection != null && collection.contains(value); - } - - // Modification Operations - - public boolean put(@Nullable K key, @Nullable V value) { - Collection collection = getOrCreateCollection(key); - - if (collection.add(value)) { - totalSize++; - return true; - } else { - return false; - } - } - - private Collection getOrCreateCollection(@Nullable K key) { - Collection collection = map.get(key); - if (collection == null) { - collection = createCollection(key); - map.put(key, collection); - } - return collection; - } - - public boolean remove(@Nullable Object key, @Nullable Object value) { - Collection collection = map.get(key); - if (collection == null) { - return false; - } - - boolean changed = collection.remove(value); - if (changed) { - totalSize--; - if (collection.isEmpty()) { - map.remove(key); - } - } - return changed; - } - - // Bulk Operations - - public boolean putAll(@Nullable K key, Iterable values) { - if (!values.iterator().hasNext()) { - return false; - } - Collection collection = getOrCreateCollection(key); - int oldSize = collection.size(); - - boolean changed = false; - if (values instanceof Collection) { - @SuppressWarnings("unchecked") - Collection c = (Collection) values; - changed = collection.addAll(c); - } else { - for (V value : values) { - changed |= collection.add(value); - } - } - - totalSize += (collection.size() - oldSize); - return changed; - } - - public boolean putAll(Multimap multimap) { - boolean changed = false; - for (Map.Entry entry : multimap.entries()) { - changed |= put(entry.getKey(), entry.getValue()); - } - return changed; - } - - /** - * {@inheritDoc} - * - *

The returned collection is immutable. - */ - public Collection replaceValues( - @Nullable K key, Iterable values) { - Iterator iterator = values.iterator(); - if (!iterator.hasNext()) { - return removeAll(key); - } - - Collection collection = getOrCreateCollection(key); - Collection oldValues = createCollection(); - oldValues.addAll(collection); - - totalSize -= collection.size(); - collection.clear(); - - while (iterator.hasNext()) { - if (collection.add(iterator.next())) { - totalSize++; - } - } - - return unmodifiableCollectionSubclass(oldValues); - } - - /** - * {@inheritDoc} - * - *

The returned collection is immutable. - */ - public Collection removeAll(@Nullable Object key) { - Collection collection = map.remove(key); - Collection output = createCollection(); - - if (collection != null) { - output.addAll(collection); - totalSize -= collection.size(); - collection.clear(); - } - - return unmodifiableCollectionSubclass(output); - } - - private Collection unmodifiableCollectionSubclass( - Collection collection) { - if (collection instanceof SortedSet) { - return Collections.unmodifiableSortedSet((SortedSet) collection); - } else if (collection instanceof Set) { - return Collections.unmodifiableSet((Set) collection); - } else if (collection instanceof List) { - return Collections.unmodifiableList((List) collection); - } else { - return Collections.unmodifiableCollection(collection); - } - } - - public void clear() { - // Clear each collection, to make previously returned collections empty. - for (Collection collection : map.values()) { - collection.clear(); - } - map.clear(); - totalSize = 0; - } - - // Views - - /** - * {@inheritDoc} - * - *

The returned collection is not serializable. - */ - public Collection get(@Nullable K key) { - Collection collection = map.get(key); - if (collection == null) { - collection = createCollection(key); - } - return wrapCollection(key, collection); - } - - /** - * Generates a decorated collection that remains consistent with the values in - * the multimap for the provided key. Changes to the multimap may alter the - * returned collection, and vice versa. - */ - private Collection wrapCollection( - @Nullable K key, Collection collection) { - if (collection instanceof SortedSet) { - return new WrappedSortedSet(key, (SortedSet) collection, null); - } else if (collection instanceof Set) { - return new WrappedSet(key, (Set) collection); - } else if (collection instanceof List) { - return wrapList(key, (List) collection, null); - } else { - return new WrappedCollection(key, collection, null); - } - } - - private List wrapList( - K key, List list, @Nullable WrappedCollection ancestor) { - return (list instanceof RandomAccess) - ? new RandomAccessWrappedList(key, list, ancestor) - : new WrappedList(key, list, ancestor); - } - - /** - * Collection decorator that stays in sync with the multimap values for a key. - * There are two kinds of wrapped collections: full and subcollections. Both - * have a delegate pointing to the underlying collection class. - * - *

Full collections, identified by a null ancestor field, contain all - * multimap values for a given key. Its delegate is a value in {@link - * AbstractMultimap#map} whenever the delegate is non-empty. The {@code - * refreshIfEmpty}, {@code removeIfEmpty}, and {@code addToMap} methods ensure - * that the {@code WrappedCollection} and map remain consistent. - * - *

A subcollection, such as a sublist, contains some of the values for a - * given key. Its ancestor field points to the full wrapped collection with - * all values for the key. The subcollection {@code refreshIfEmpty}, {@code - * removeIfEmpty}, and {@code addToMap} methods call the corresponding methods - * of the full wrapped collection. - */ - private class WrappedCollection extends AbstractCollection { - final K key; - Collection delegate; - final WrappedCollection ancestor; - final Collection ancestorDelegate; - - WrappedCollection(@Nullable K key, Collection delegate, - @Nullable WrappedCollection ancestor) { - this.key = key; - this.delegate = delegate; - this.ancestor = ancestor; - this.ancestorDelegate - = (ancestor == null) ? null : ancestor.getDelegate(); - } - - /** - * If the delegate collection is empty, but the multimap has values for the - * key, replace the delegate with the new collection for the key. - * - *

For a subcollection, refresh its ancestor and validate that the - * ancestor delegate hasn't changed. - */ - void refreshIfEmpty() { - if (ancestor != null) { - ancestor.refreshIfEmpty(); - if (ancestor.getDelegate() != ancestorDelegate) { - throw new ConcurrentModificationException(); - } - } else if (delegate.isEmpty()) { - Collection newDelegate = map.get(key); - if (newDelegate != null) { - delegate = newDelegate; - } - } - } - - /** - * If collection is empty, remove it from {@code map}. For subcollections, - * check whether the ancestor collection is empty. - */ - void removeIfEmpty() { - if (ancestor != null) { - ancestor.removeIfEmpty(); - } else if (delegate.isEmpty()) { - map.remove(key); - } - } - - K getKey() { - return key; - } - - /** - * Add the delegate to the map. Other {@code WrappedCollection} methods - * should call this method after adding elements to a previously empty - * collection. - * - *

Subcollection add the ancestor's delegate instead. - */ - void addToMap() { - if (ancestor != null) { - ancestor.addToMap(); - } else { - map.put(key, delegate); - } - } - - @Override public int size() { - refreshIfEmpty(); - return delegate.size(); - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - refreshIfEmpty(); - return delegate.equals(object); - } - - @Override public int hashCode() { - refreshIfEmpty(); - return delegate.hashCode(); - } - - @Override public String toString() { - refreshIfEmpty(); - return delegate.toString(); - } - - Collection getDelegate() { - return delegate; - } - - @Override public Iterator iterator() { - refreshIfEmpty(); - return new WrappedIterator(); - } - - /** Collection iterator for {@code WrappedCollection}. */ - class WrappedIterator implements Iterator { - final Iterator delegateIterator; - final Collection originalDelegate = delegate; - - WrappedIterator() { - delegateIterator = iteratorOrListIterator(delegate); - } - - WrappedIterator(Iterator delegateIterator) { - this.delegateIterator = delegateIterator; - } - - /** - * If the delegate changed since the iterator was created, the iterator is - * no longer valid. - */ - void validateIterator() { - refreshIfEmpty(); - if (delegate != originalDelegate) { - throw new ConcurrentModificationException(); - } - } - - public boolean hasNext() { - validateIterator(); - return delegateIterator.hasNext(); - } - - public V next() { - validateIterator(); - return delegateIterator.next(); - } - - public void remove() { - delegateIterator.remove(); - totalSize--; - removeIfEmpty(); - } - - Iterator getDelegateIterator() { - validateIterator(); - return delegateIterator; - } - } - - @Override public boolean add(V value) { - refreshIfEmpty(); - boolean wasEmpty = delegate.isEmpty(); - boolean changed = delegate.add(value); - if (changed) { - totalSize++; - if (wasEmpty) { - addToMap(); - } - } - return changed; - } - - WrappedCollection getAncestor() { - return ancestor; - } - - // The following methods are provided for better performance. - - @Override public boolean addAll(Collection collection) { - if (collection.isEmpty()) { - return false; - } - int oldSize = size(); // calls refreshIfEmpty - boolean changed = delegate.addAll(collection); - if (changed) { - int newSize = delegate.size(); - totalSize += (newSize - oldSize); - if (oldSize == 0) { - addToMap(); - } - } - return changed; - } - - @Override public boolean contains(Object o) { - refreshIfEmpty(); - return delegate.contains(o); - } - - @Override public boolean containsAll(Collection c) { - refreshIfEmpty(); - return delegate.containsAll(c); - } - - @Override public void clear() { - int oldSize = size(); // calls refreshIfEmpty - if (oldSize == 0) { - return; - } - delegate.clear(); - totalSize -= oldSize; - removeIfEmpty(); // maybe shouldn't be removed if this is a sublist - } - - @Override public boolean remove(Object o) { - refreshIfEmpty(); - boolean changed = delegate.remove(o); - if (changed) { - totalSize--; - removeIfEmpty(); - } - return changed; - } - - @Override public boolean removeAll(Collection c) { - if (c.isEmpty()) { - return false; - } - int oldSize = size(); // calls refreshIfEmpty - boolean changed = delegate.removeAll(c); - if (changed) { - int newSize = delegate.size(); - totalSize += (newSize - oldSize); - removeIfEmpty(); - } - return changed; - } - - @Override public boolean retainAll(Collection c) { - checkNotNull(c); - int oldSize = size(); // calls refreshIfEmpty - boolean changed = delegate.retainAll(c); - if (changed) { - int newSize = delegate.size(); - totalSize += (newSize - oldSize); - removeIfEmpty(); - } - return changed; - } - } - - private Iterator iteratorOrListIterator(Collection collection) { - return (collection instanceof List) - ? ((List) collection).listIterator() - : collection.iterator(); - } - - /** Set decorator that stays in sync with the multimap values for a key. */ - private class WrappedSet extends WrappedCollection implements Set { - WrappedSet(K key, Set delegate) { - super(key, delegate, null); - } - } - - /** - * SortedSet decorator that stays in sync with the multimap values for a key. - */ - private class WrappedSortedSet extends WrappedCollection - implements SortedSet { - WrappedSortedSet(@Nullable K key, SortedSet delegate, - @Nullable WrappedCollection ancestor) { - super(key, delegate, ancestor); - } - - SortedSet getSortedSetDelegate() { - return (SortedSet) getDelegate(); - } - - public Comparator comparator() { - return getSortedSetDelegate().comparator(); - } - - public V first() { - refreshIfEmpty(); - return getSortedSetDelegate().first(); - } - - public V last() { - refreshIfEmpty(); - return getSortedSetDelegate().last(); - } - - public SortedSet headSet(V toElement) { - refreshIfEmpty(); - return new WrappedSortedSet( - getKey(), getSortedSetDelegate().headSet(toElement), - (getAncestor() == null) ? this : getAncestor()); - } - - public SortedSet subSet(V fromElement, V toElement) { - refreshIfEmpty(); - return new WrappedSortedSet( - getKey(), getSortedSetDelegate().subSet(fromElement, toElement), - (getAncestor() == null) ? this : getAncestor()); - } - - public SortedSet tailSet(V fromElement) { - refreshIfEmpty(); - return new WrappedSortedSet( - getKey(), getSortedSetDelegate().tailSet(fromElement), - (getAncestor() == null) ? this : getAncestor()); - } - } - - /** List decorator that stays in sync with the multimap values for a key. */ - private class WrappedList extends WrappedCollection implements List { - WrappedList(K key, List delegate, @Nullable WrappedCollection ancestor) { - super(key, delegate, ancestor); - } - - List getListDelegate() { - return (List) getDelegate(); - } - - public boolean addAll(int index, Collection c) { - if (c.isEmpty()) { - return false; - } - int oldSize = size(); // calls refreshIfEmpty - boolean changed = getListDelegate().addAll(index, c); - if (changed) { - int newSize = getDelegate().size(); - totalSize += (newSize - oldSize); - if (oldSize == 0) { - addToMap(); - } - } - return changed; - } - - public V get(int index) { - refreshIfEmpty(); - return getListDelegate().get(index); - } - - public V set(int index, V element) { - refreshIfEmpty(); - return getListDelegate().set(index, element); - } - - public void add(int index, V element) { - refreshIfEmpty(); - boolean wasEmpty = getDelegate().isEmpty(); - getListDelegate().add(index, element); - totalSize++; - if (wasEmpty) { - addToMap(); - } - } - - public V remove(int index) { - refreshIfEmpty(); - V value = getListDelegate().remove(index); - totalSize--; - removeIfEmpty(); - return value; - } - - public int indexOf(Object o) { - refreshIfEmpty(); - return getListDelegate().indexOf(o); - } - - public int lastIndexOf(Object o) { - refreshIfEmpty(); - return getListDelegate().lastIndexOf(o); - } - - public ListIterator listIterator() { - refreshIfEmpty(); - return new WrappedListIterator(); - } - - public ListIterator listIterator(int index) { - refreshIfEmpty(); - return new WrappedListIterator(index); - } - - @GwtIncompatible("List.subList") - public List subList(int fromIndex, int toIndex) { - refreshIfEmpty(); - return wrapList(getKey(), - Platform.subList(getListDelegate(), fromIndex, toIndex), - (getAncestor() == null) ? this : getAncestor()); - } - - /** ListIterator decorator. */ - private class WrappedListIterator extends WrappedIterator - implements ListIterator { - WrappedListIterator() {} - - public WrappedListIterator(int index) { - super(getListDelegate().listIterator(index)); - } - - private ListIterator getDelegateListIterator() { - return (ListIterator) getDelegateIterator(); - } - - public boolean hasPrevious() { - return getDelegateListIterator().hasPrevious(); - } - - public V previous() { - return getDelegateListIterator().previous(); - } - - public int nextIndex() { - return getDelegateListIterator().nextIndex(); - } - - public int previousIndex() { - return getDelegateListIterator().previousIndex(); - } - - public void set(V value) { - getDelegateListIterator().set(value); - } - - public void add(V value) { - boolean wasEmpty = isEmpty(); - getDelegateListIterator().add(value); - totalSize++; - if (wasEmpty) { - addToMap(); - } - } - } - } - - /** - * List decorator that stays in sync with the multimap values for a key and - * supports rapid random access. - */ - private class RandomAccessWrappedList extends WrappedList - implements RandomAccess { - RandomAccessWrappedList(K key, List delegate, - @Nullable WrappedCollection ancestor) { - super(key, delegate, ancestor); - } - } - - private transient Set keySet; - - public Set keySet() { - Set result = keySet; - return (result == null) ? keySet = createKeySet() : result; - } - - private Set createKeySet() { - return (map instanceof SortedMap) - ? new SortedKeySet((SortedMap>) map) : new KeySet(map); - } - - private class KeySet extends AbstractSet { - - /** - * This is usually the same as map, except when someone requests a - * subcollection of a {@link SortedKeySet}. - */ - final Map> subMap; - - KeySet(final Map> subMap) { - this.subMap = subMap; - } - - @Override public int size() { - return subMap.size(); - } - - @Override public Iterator iterator() { - return new Iterator() { - final Iterator>> entryIterator - = subMap.entrySet().iterator(); - Map.Entry> entry; - - public boolean hasNext() { - return entryIterator.hasNext(); - } - public K next() { - entry = entryIterator.next(); - return entry.getKey(); - } - public void remove() { - checkState(entry != null); - Collection collection = entry.getValue(); - entryIterator.remove(); - totalSize -= collection.size(); - collection.clear(); - } - }; - } - - // The following methods are included for better performance. - - @Override public boolean contains(Object key) { - return subMap.containsKey(key); - } - - @Override public boolean remove(Object key) { - int count = 0; - Collection collection = subMap.remove(key); - if (collection != null) { - count = collection.size(); - collection.clear(); - totalSize -= count; - } - return count > 0; - } - - @Override public boolean containsAll(Collection c) { - return subMap.keySet().containsAll(c); - } - - @Override public boolean equals(@Nullable Object object) { - return this == object || this.subMap.keySet().equals(object); - } - - @Override public int hashCode() { - return subMap.keySet().hashCode(); - } - } - - private class SortedKeySet extends KeySet implements SortedSet { - - SortedKeySet(SortedMap> subMap) { - super(subMap); - } - - SortedMap> sortedMap() { - return (SortedMap>) subMap; - } - - public Comparator comparator() { - return sortedMap().comparator(); - } - - public K first() { - return sortedMap().firstKey(); - } - - public SortedSet headSet(K toElement) { - return new SortedKeySet(sortedMap().headMap(toElement)); - } - - public K last() { - return sortedMap().lastKey(); - } - - public SortedSet subSet(K fromElement, K toElement) { - return new SortedKeySet(sortedMap().subMap(fromElement, toElement)); - } - - public SortedSet tailSet(K fromElement) { - return new SortedKeySet(sortedMap().tailMap(fromElement)); - } - } - - private transient Multiset multiset; - - public Multiset keys() { - Multiset result = multiset; - return (result == null) ? multiset = new MultisetView() : result; - } - - /** Multiset view that stays in sync with the multimap keys. */ - private class MultisetView extends AbstractMultiset { - - @Override public int remove(Object key, int occurrences) { - if (occurrences == 0) { - return count(key); - } - checkArgument(occurrences > 0); - - Collection collection; - try { - collection = map.get(key); - } catch (NullPointerException e) { - return 0; - } catch (ClassCastException e) { - return 0; - } - - if (collection == null) { - return 0; - } - int count = collection.size(); - - if (occurrences >= count) { - return removeValuesForKey(key); - } - - Iterator iterator = collection.iterator(); - for (int i = 0; i < occurrences; i++) { - iterator.next(); - iterator.remove(); - } - totalSize -= occurrences; - return count; - } - - @Override public Set elementSet() { - return AbstractMultimap.this.keySet(); - } - - transient Set> entrySet; - - @Override public Set> entrySet() { - Set> result = entrySet; - return (result == null) ? entrySet = new EntrySet() : result; - } - - private class EntrySet extends AbstractSet> { - @Override public Iterator> iterator() { - return new MultisetEntryIterator(); - } - @Override public int size() { - return map.size(); - } - - // The following methods are included for better performance. - - @Override public boolean contains(Object o) { - if (!(o instanceof Multiset.Entry)) { - return false; - } - Multiset.Entry entry = (Multiset.Entry) o; - Collection collection = map.get(entry.getElement()); - return (collection != null) && - (collection.size() == entry.getCount()); - } - @Override public void clear() { - AbstractMultimap.this.clear(); - } - @Override public boolean remove(Object o) { - return contains(o) && - (removeValuesForKey(((Multiset.Entry) o).getElement()) > 0); - } - } - - @Override public Iterator iterator() { - return new MultisetKeyIterator(); - } - - // The following methods are included for better performance. - - @Override public int count(Object key) { - try { - Collection collection = map.get(key); - return (collection == null) ? 0 : collection.size(); - } catch (NullPointerException e) { - return 0; - } catch (ClassCastException e) { - return 0; - } - } - - @Override public int size() { - return totalSize; - } - - @Override public void clear() { - AbstractMultimap.this.clear(); - } - } - - /** - * Removes all values for the provided key. Unlike {@link #removeAll}, it - * returns the number of removed mappings. - */ - private int removeValuesForKey(Object key) { - Collection collection; - try { - collection = map.remove(key); - } catch (NullPointerException e) { - return 0; - } catch (ClassCastException e) { - return 0; - } - - int count = 0; - if (collection != null) { - count = collection.size(); - collection.clear(); - totalSize -= count; - } - return count; - } - - /** Iterator across each key, repeating once per value. */ - private class MultisetEntryIterator implements Iterator> { - final Iterator>> asMapIterator - = asMap().entrySet().iterator(); - - public boolean hasNext() { - return asMapIterator.hasNext(); - } - public Multiset.Entry next() { - return new MultisetEntry(asMapIterator.next()); - } - public void remove() { - asMapIterator.remove(); - } - } - - private class MultisetEntry extends Multisets.AbstractEntry { - final Map.Entry> entry; - - public MultisetEntry(Map.Entry> entry) { - this.entry = entry; - } - public K getElement() { - return entry.getKey(); - } - public int getCount() { - return entry.getValue().size(); - } - } - - /** Iterator across each key, repeating once per value. */ - private class MultisetKeyIterator implements Iterator { - final Iterator> entryIterator = entries().iterator(); - - public boolean hasNext() { - return entryIterator.hasNext(); - } - public K next() { - return entryIterator.next().getKey(); - } - public void remove() { - entryIterator.remove(); - } - } - - private transient Collection valuesCollection; - - /** - * {@inheritDoc} - * - *

The iterator generated by the returned collection traverses the values - * for one key, followed by the values of a second key, and so on. - */ - public Collection values() { - Collection result = valuesCollection; - return (result == null) ? valuesCollection = new Values() : result; - } - - private class Values extends AbstractCollection { - @Override public Iterator iterator() { - return new ValueIterator(); - } - @Override public int size() { - return totalSize; - } - - // The following methods are included to improve performance. - - @Override public void clear() { - AbstractMultimap.this.clear(); - } - - @Override public boolean contains(Object value) { - return containsValue(value); - } - } - - /** Iterator across all values. */ - private class ValueIterator implements Iterator { - final Iterator> entryIterator = createEntryIterator(); - - public boolean hasNext() { - return entryIterator.hasNext(); - } - public V next() { - return entryIterator.next().getValue(); - } - public void remove() { - entryIterator.remove(); - } - } - - private transient Collection> entries; - - // TODO: should we copy this javadoc to each concrete class, so that classes - // like LinkedHashMultimap that need to say something different are still - // able to {@inheritDoc} all the way from Multimap? - - /** - * {@inheritDoc} - * - *

The iterator generated by the returned collection traverses the values - * for one key, followed by the values of a second key, and so on. - * - *

Each entry is an immutable snapshot of a key-value mapping in the - * multimap, taken at the time the entry is returned by a method call to the - * collection or its iterator. - */ - public Collection> entries() { - Collection> result = entries; - return (entries == null) ? entries = createEntries() : result; - } - - private Collection> createEntries() { - // TODO: can we refactor so we're not doing "this instanceof"? - return (this instanceof SetMultimap) ? new EntrySet() : new Entries(); - } - - /** Entries for multimap. */ - private class Entries extends AbstractCollection> { - @Override public Iterator> iterator() { - return createEntryIterator(); - } - @Override public int size() { - return totalSize; - } - - // The following methods are included to improve performance. - - @Override public boolean contains(Object o) { - if (!(o instanceof Map.Entry)) { - return false; - } - Map.Entry entry = (Map.Entry) o; - return containsEntry(entry.getKey(), entry.getValue()); - } - - @Override public void clear() { - AbstractMultimap.this.clear(); - } - - @Override public boolean remove(Object o) { - if (!(o instanceof Map.Entry)) { - return false; - } - Map.Entry entry = (Map.Entry) o; - return AbstractMultimap.this.remove(entry.getKey(), entry.getValue()); - } - } - - /** - * Returns an iterator across all key-value map entries, used by {@code - * entries().iterator()} and {@code values().iterator()}. The default - * behavior, which traverses the values for one key, the values for a second - * key, and so on, suffices for most {@code AbstractMultimap} implementations. - * - * @return an iterator across map entries - */ - Iterator> createEntryIterator() { - return new EntryIterator(); - } - - /** Iterator across all key-value pairs. */ - private class EntryIterator implements Iterator> { - final Iterator>> keyIterator; - K key; - Collection collection; - Iterator valueIterator; - - EntryIterator() { - keyIterator = map.entrySet().iterator(); - if (keyIterator.hasNext()) { - findValueIteratorAndKey(); - } else { - valueIterator = Iterators.emptyModifiableIterator(); - } - } - - void findValueIteratorAndKey() { - Map.Entry> entry = keyIterator.next(); - key = entry.getKey(); - collection = entry.getValue(); - valueIterator = collection.iterator(); - } - - public boolean hasNext() { - return keyIterator.hasNext() || valueIterator.hasNext(); - } - - public Map.Entry next() { - if (!valueIterator.hasNext()) { - findValueIteratorAndKey(); - } - return Maps.immutableEntry(key, valueIterator.next()); - } - - public void remove() { - valueIterator.remove(); - if (collection.isEmpty()) { - keyIterator.remove(); - } - totalSize--; - } - } - - /** Entry set for a {@link SetMultimap}. */ - private class EntrySet extends Entries implements Set> { - @Override public boolean equals(@Nullable Object object) { - return Collections2.setEquals(this, object); - } - @Override public int hashCode() { - return Sets.hashCodeImpl(this); - } - } - - private transient Map> asMap; - - public Map> asMap() { - Map> result = asMap; - return (result == null) ? asMap = createAsMap() : result; - } - - private Map> createAsMap() { - return (map instanceof SortedMap) - ? new SortedAsMap((SortedMap>) map) : new AsMap(map); - } - - private class AsMap extends AbstractMap> { - /** - * Usually the same as map, but smaller for the headMap(), tailMap(), or - * subMap() of a SortedAsMap. - */ - final transient Map> submap; - - AsMap(Map> submap) { - this.submap = submap; - } - - transient Set>> entrySet; - - @Override public Set>> entrySet() { - Set>> result = entrySet; - return (entrySet == null) ? entrySet = new AsMapEntries() : result; - } - - // The following methods are included for performance. - - @Override public boolean containsKey(Object key) { - return submap.containsKey(key); - } - - @Override public Collection get(Object key) { - Collection collection = submap.get(key); - if (collection == null) { - return null; - } - @SuppressWarnings("unchecked") - K k = (K) key; - return wrapCollection(k, collection); - } - - @Override public Set keySet() { - return AbstractMultimap.this.keySet(); - } - - @Override public Collection remove(Object key) { - Collection collection = submap.remove(key); - if (collection == null) { - return null; - } - - Collection output = createCollection(); - output.addAll(collection); - totalSize -= collection.size(); - collection.clear(); - return output; - } - - @Override public boolean equals(@Nullable Object object) { - return this == object || submap.equals(object); - } - - @Override public int hashCode() { - return submap.hashCode(); - } - - @Override public String toString() { - return submap.toString(); - } - - class AsMapEntries extends AbstractSet>> { - @Override public Iterator>> iterator() { - return new AsMapIterator(); - } - - @Override public int size() { - return submap.size(); - } - - // The following methods are included for performance. - - @Override public boolean contains(Object o) { - return submap.entrySet().contains(o); - } - - @Override public boolean remove(Object o) { - if (!contains(o)) { - return false; - } - Map.Entry entry = (Map.Entry) o; - removeValuesForKey(entry.getKey()); - return true; - } - } - - /** Iterator across all keys and value collections. */ - class AsMapIterator implements Iterator>> { - final Iterator>> delegateIterator - = submap.entrySet().iterator(); - Collection collection; - - public boolean hasNext() { - return delegateIterator.hasNext(); - } - - public Map.Entry> next() { - Map.Entry> entry = delegateIterator.next(); - K key = entry.getKey(); - collection = entry.getValue(); - return Maps.immutableEntry(key, wrapCollection(key, collection)); - } - - public void remove() { - delegateIterator.remove(); - totalSize -= collection.size(); - collection.clear(); - } - } - } - - private class SortedAsMap extends AsMap - implements SortedMap> { - SortedAsMap(SortedMap> submap) { - super(submap); - } - - SortedMap> sortedMap() { - return (SortedMap>) submap; - } - - public Comparator comparator() { - return sortedMap().comparator(); - } - - public K firstKey() { - return sortedMap().firstKey(); - } - - public K lastKey() { - return sortedMap().lastKey(); - } - - public SortedMap> headMap(K toKey) { - return new SortedAsMap(sortedMap().headMap(toKey)); - } - - public SortedMap> subMap(K fromKey, K toKey) { - return new SortedAsMap(sortedMap().subMap(fromKey, toKey)); - } - - public SortedMap> tailMap(K fromKey) { - return new SortedAsMap(sortedMap().tailMap(fromKey)); - } - - SortedSet sortedKeySet; - - // returns a SortedSet, even though returning a Set would be sufficient to - // satisfy the SortedMap.keySet() interface - @Override public SortedSet keySet() { - SortedSet result = sortedKeySet; - return (result == null) - ? sortedKeySet = new SortedKeySet(sortedMap()) : result; - } - } - - // Comparison and hashing - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof Multimap) { - Multimap that = (Multimap) object; - return this.map.equals(that.asMap()); - } - return false; - } - - /** - * Returns the hash code for this multimap. - * - *

The hash code of a multimap is defined as the hash code of the map view, - * as returned by {@link Multimap#asMap}. - * - * @see Map#hashCode - */ - @Override public int hashCode() { - return map.hashCode(); - } - - /** - * Returns a string representation of the multimap, generated by calling - * {@code toString} on the map returned by {@link Multimap#asMap}. - * - * @return a string representation of the multimap - */ - @Override public String toString() { - return map.toString(); - } - - private static final long serialVersionUID = 2447537837011683357L; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMultiset.java deleted file mode 100644 index edce3021e66..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractMultiset.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Objects; - -import javax.annotation.Nullable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; -import static org.elasticsearch.util.collect.Multisets.*; - -/** - * This class provides a skeletal implementation of the {@link Multiset} - * interface. A new multiset implementation can be created easily by extending - * this class and implementing the {@link Multiset#entrySet()} method, plus - * optionally overriding {@link #add(Object, int)} and - * {@link #remove(Object, int)} to enable modifications to the multiset. - * - *

The {@link #contains}, {@link #containsAll}, {@link #count}, and - * {@link #size} implementations all iterate across the set returned by - * {@link Multiset#entrySet()}, as do many methods acting on the set returned by - * {@link #elementSet()}. Override those methods for better performance. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -abstract class AbstractMultiset extends AbstractCollection - implements Multiset { - public abstract Set> entrySet(); - - // Query Operations - - @Override public int size() { - long sum = 0L; - for (Entry entry : entrySet()) { - sum += entry.getCount(); - } - return (int) Math.min(sum, Integer.MAX_VALUE); - } - - @Override public boolean isEmpty() { - return entrySet().isEmpty(); - } - - @Override public boolean contains(@Nullable Object element) { - return elementSet().contains(element); - } - - @Override public Iterator iterator() { - return new MultisetIterator(); - } - - private class MultisetIterator implements Iterator { - private final Iterator> entryIterator; - private Entry currentEntry; - /** Count of subsequent elements equal to current element */ - private int laterCount; - /** Count of all elements equal to current element */ - private int totalCount; - private boolean canRemove; - - MultisetIterator() { - this.entryIterator = entrySet().iterator(); - } - - public boolean hasNext() { - return laterCount > 0 || entryIterator.hasNext(); - } - - public E next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - if (laterCount == 0) { - currentEntry = entryIterator.next(); - totalCount = laterCount = currentEntry.getCount(); - } - laterCount--; - canRemove = true; - return currentEntry.getElement(); - } - - public void remove() { - checkState(canRemove, - "no calls to next() since the last call to remove()"); - if (totalCount == 1) { - entryIterator.remove(); - } else { - AbstractMultiset.this.remove(currentEntry.getElement()); - } - totalCount--; - canRemove = false; - } - } - - public int count(Object element) { - for (Entry entry : entrySet()) { - if (Objects.equal(entry.getElement(), element)) { - return entry.getCount(); - } - } - return 0; - } - - // Modification Operations - - @Override public boolean add(@Nullable E element) { - add(element, 1); - return true; - } - - public int add(E element, int occurrences) { - throw new UnsupportedOperationException(); - } - - @Override public boolean remove(Object element) { - return remove(element, 1) > 0; - } - - public int remove(Object element, int occurrences) { - throw new UnsupportedOperationException(); - } - - public int setCount(E element, int count) { - return setCountImpl(this, element, count); - } - - public boolean setCount(E element, int oldCount, int newCount) { - return setCountImpl(this, element, oldCount, newCount); - } - - // Bulk Operations - - @Override public boolean containsAll(Collection elements) { - return elementSet().containsAll(elements); - } - - @Override public boolean addAll(Collection elementsToAdd) { - if (elementsToAdd.isEmpty()) { - return false; - } - if (elementsToAdd instanceof Multiset) { - @SuppressWarnings("unchecked") - Multiset that = (Multiset) elementsToAdd; - for (Entry entry : that.entrySet()) { - add(entry.getElement(), entry.getCount()); - } - } else { - super.addAll(elementsToAdd); - } - return true; - } - - @Override public boolean removeAll(Collection elementsToRemove) { - Collection collection = (elementsToRemove instanceof Multiset) - ? ((Multiset) elementsToRemove).elementSet() : elementsToRemove; - - return elementSet().removeAll(collection); - // TODO: implement retainAll similarly? - } - - @Override public boolean retainAll(Collection elementsToRetain) { - checkNotNull(elementsToRetain); - Iterator> entries = entrySet().iterator(); - boolean modified = false; - while (entries.hasNext()) { - Entry entry = entries.next(); - if (!elementsToRetain.contains(entry.getElement())) { - entries.remove(); - modified = true; - } - } - return modified; - } - - @Override public void clear() { - entrySet().clear(); - } - - // Views - - private transient Set elementSet; - - public Set elementSet() { - Set result = elementSet; - if (result == null) { - elementSet = result = createElementSet(); - } - return result; - } - - /** - * Creates a new instance of this multiset's element set, which will be - * returned by {@link #elementSet()}. - */ - Set createElementSet() { - return new ElementSet(); - } - - private class ElementSet extends AbstractSet { - @Override public Iterator iterator() { - final Iterator> entryIterator = entrySet().iterator(); - return new Iterator() { - public boolean hasNext() { - return entryIterator.hasNext(); - } - public E next() { - return entryIterator.next().getElement(); - } - public void remove() { - entryIterator.remove(); - } - }; - } - @Override public int size() { - return entrySet().size(); - } - } - - // Object methods - - /** - * {@inheritDoc} - * - *

This implementation returns {@code true} if {@code other} is a multiset - * of the same size and if, for each element, the two multisets have the same - * count. - */ - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof Multiset) { - Multiset that = (Multiset) object; - /* - * We can't simply check whether the entry sets are equal, since that - * approach fails when a TreeMultiset has a comparator that returns 0 - * when passed unequal elements. - */ - - if (this.size() != that.size()) { - return false; - } - for (Entry entry : that.entrySet()) { - if (count(entry.getElement()) != entry.getCount()) { - return false; - } - } - return true; - } - return false; - } - - /** - * {@inheritDoc} - * - *

This implementation returns the hash code of {@link - * Multiset#entrySet()}. - */ - @Override public int hashCode() { - return entrySet().hashCode(); - } - - /** - * {@inheritDoc} - * - *

This implementation returns the result of invoking {@code toString} on - * {@link Multiset#entrySet()}. - */ - @Override public String toString() { - return entrySet().toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractSetMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractSetMultimap.java deleted file mode 100644 index 4d624d57cdb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractSetMultimap.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -/** - * Basic implementation of the {@link SetMultimap} interface. It's a wrapper - * around {@link AbstractMultimap} that converts the returned collections into - * {@code Sets}. The {@link #createCollection} method must return a {@code Set}. - * - * @author Jared Levy - */ -@GwtCompatible -abstract class AbstractSetMultimap - extends AbstractMultimap implements SetMultimap { - /** - * Creates a new multimap that uses the provided map. - * - * @param map place to store the mapping from each key to its corresponding - * values - */ - protected AbstractSetMultimap(Map> map) { - super(map); - } - - @Override abstract Set createCollection(); - - @Override public Set get(@Nullable K key) { - return (Set) super.get(key); - } - - @Override public Set> entries() { - return (Set>) super.entries(); - } - - @Override public Set removeAll(@Nullable Object key) { - return (Set) super.removeAll(key); - } - - /** - * {@inheritDoc} - * - *

Any duplicates in {@code values} will be stored in the multimap once. - */ - @Override public Set replaceValues( - @Nullable K key, Iterable values) { - return (Set) super.replaceValues(key, values); - } - - /** - * Stores a key-value pair in the multimap. - * - * @param key key to store in the multimap - * @param value value to store in the multimap - * @return {@code true} if the method increased the size of the multimap, or - * {@code false} if the multimap already contained the key-value pair - */ - @Override public boolean put(K key, V value) { - return super.put(key, value); - } - - /** - * Compares the specified object to this multimap for equality. - * - *

Two {@code SetMultimap} instances are equal if, for each key, they - * contain the same values. Equality does not depend on the ordering of keys - * or values. - */ - @Override public boolean equals(@Nullable Object object) { - return super.equals(object); - } - - private static final long serialVersionUID = 7431625294878419160L; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractSortedSetMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractSortedSetMultimap.java deleted file mode 100644 index 6655997e851..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AbstractSortedSetMultimap.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Map; -import java.util.SortedSet; - -/** - * Basic implementation of the {@link SortedSetMultimap} interface. It's a - * wrapper around {@link AbstractMultimap} that converts the returned - * collections into sorted sets. The {@link #createCollection} method - * must return a {@code SortedSet}. - * - * @author Jared Levy - */ -@GwtCompatible -abstract class AbstractSortedSetMultimap - extends AbstractSetMultimap implements SortedSetMultimap { - /** - * Creates a new multimap that uses the provided map. - * - * @param map place to store the mapping from each key to its corresponding - * values - */ - protected AbstractSortedSetMultimap(Map> map) { - super(map); - } - - @Override abstract SortedSet createCollection(); - - @Override public SortedSet get(@Nullable K key) { - return (SortedSet) super.get(key); - } - - @Override public SortedSet removeAll(@Nullable Object key) { - return (SortedSet) super.removeAll(key); - } - - @Override public SortedSet replaceValues( - K key, Iterable values) { - return (SortedSet) super.replaceValues(key, values); - } - - /** - * {@inheritDoc} - * - * Consequently, the values do not follow their natural ordering or the - * ordering of the value comparator. - */ - @Override public Collection values() { - return super.values(); - } - - private static final long serialVersionUID = 430848587173315748L; -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ArrayListMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ArrayListMultimap.java deleted file mode 100644 index 0bc30bea34d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ArrayListMultimap.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.VisibleForTesting; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Implementation of {@code Multimap} that uses an {@code ArrayList} to store - * the values for a given key. A {@link HashMap} associates each key with an - * {@link ArrayList} of values. - * - *

When iterating through the collections supplied by this class, the - * ordering of values for a given key agrees with the order in which the values - * were added. - * - *

This multimap allows duplicate key-value pairs. After adding a new - * key-value pair equal to an existing key-value pair, the {@code - * ArrayListMultimap} will contain entries for both the new value and the old - * value. - * - *

Keys and values may be null. All optional multimap methods are supported, - * and all returned views are modifiable. - * - *

The lists returned by {@link #get}, {@link #removeAll}, and {@link - * #replaceValues} all implement {@link java.util.RandomAccess}. - * - *

This class is not threadsafe when any concurrent operations update the - * multimap. Concurrent read operations will work correctly. To allow concurrent - * update operations, wrap your multimap with a call to {@link - * Multimaps#synchronizedListMultimap}. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -public final class ArrayListMultimap extends AbstractListMultimap { - // Default from ArrayList - private static final int DEFAULT_VALUES_PER_KEY = 10; - - @VisibleForTesting transient int expectedValuesPerKey; - - /** - * Creates a new, empty {@code ArrayListMultimap} with the default initial - * capacities. - */ - public static ArrayListMultimap create() { - return new ArrayListMultimap(); - } - - /** - * Constructs an empty {@code ArrayListMultimap} with enough capacity to hold - * the specified numbers of keys and values without resizing. - * - * @param expectedKeys the expected number of distinct keys - * @param expectedValuesPerKey the expected average number of values per key - * @throws IllegalArgumentException if {@code expectedKeys} or {@code - * expectedValuesPerKey} is negative - */ - public static ArrayListMultimap create( - int expectedKeys, int expectedValuesPerKey) { - return new ArrayListMultimap(expectedKeys, expectedValuesPerKey); - } - - /** - * Constructs an {@code ArrayListMultimap} with the same mappings as the - * specified multimap. - * - * @param multimap the multimap whose contents are copied to this multimap - */ - public static ArrayListMultimap create( - Multimap multimap) { - return new ArrayListMultimap(multimap); - } - - private ArrayListMultimap() { - super(new HashMap>()); - expectedValuesPerKey = DEFAULT_VALUES_PER_KEY; - } - - private ArrayListMultimap(int expectedKeys, int expectedValuesPerKey) { - super(Maps.>newHashMapWithExpectedSize(expectedKeys)); - checkArgument(expectedValuesPerKey >= 0); - this.expectedValuesPerKey = expectedValuesPerKey; - } - - private ArrayListMultimap(Multimap multimap) { - this(multimap.keySet().size(), - (multimap instanceof ArrayListMultimap) ? - ((ArrayListMultimap) multimap).expectedValuesPerKey : - DEFAULT_VALUES_PER_KEY); - putAll(multimap); - } - - /** - * Creates a new, empty {@code ArrayList} to hold the collection of values for - * an arbitrary key. - */ - @Override List createCollection() { - return new ArrayList(expectedValuesPerKey); - } - - /** - * Reduces the memory used by this {@code ArrayListMultimap}, if feasible. - */ - public void trimToSize() { - for (Collection collection : backingMap().values()) { - ArrayList arrayList = (ArrayList) collection; - arrayList.trimToSize(); - } - } - - /** - * @serialData expectedValuesPerKey, number of distinct keys, and then for - * each distinct key: the key, number of values for that key, and the - * key's values - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeInt(expectedValuesPerKey); - Serialization.writeMultimap(this, stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - expectedValuesPerKey = stream.readInt(); - int distinctKeys = Serialization.readCount(stream); - Map> map = Maps.newHashMapWithExpectedSize(distinctKeys); - setMap(map); - Serialization.populateMultimap(this, stream, distinctKeys); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AsynchronousComputationException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AsynchronousComputationException.java deleted file mode 100644 index ac6bfce2c87..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/AsynchronousComputationException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -/** - * Wraps an exception that occured during a computation in a different thread. - * - * @author Bob Lee - */ -public class AsynchronousComputationException extends ComputationException { - /** - * Creates a new instance with the given cause. - */ - public AsynchronousComputationException(Throwable cause) { - super(cause); - } - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/BiMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/BiMap.java deleted file mode 100644 index 5238d7a5739..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/BiMap.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Map; -import java.util.Set; - -/** - * A bimap (or "bidirectional map") is a map that preserves the uniqueness of - * its values as well as that of its keys. This constraint enables bimaps to - * support an "inverse view", which is another bimap containing the same entries - * as this bimap but with reversed keys and values. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -public interface BiMap extends Map { - // Modification Operations - - /** - * {@inheritDoc} - * - * @throws IllegalArgumentException if the given value is already bound to a - * different key in this bimap. The bimap will remain unmodified in this - * event. To avoid this exception, call {@link #forcePut} instead. - */ - V put(@Nullable K key, @Nullable V value); - - /** - * An alternate form of {@code put} that silently removes any existing entry - * with the value {@code value} before proceeding with the {@link #put} - * operation. If the bimap previously contained the provided key-value - * mapping, this method has no effect. - * - *

Note that a successful call to this method could cause the size of the - * bimap to increase by one, stay the same, or even decrease by one. - * - *

Warning: If an existing entry with this value is removed, the key - * for that entry is discarded and not returned. - * - * @param key the key with which the specified value is to be associated - * @param value the value to be associated with the specified key - * @return the value which was previously associated with the key, which may - * be {@code null}, or {@code null} if there was no previous entry - */ - V forcePut(@Nullable K key, @Nullable V value); - - // Bulk Operations - - /** - * {@inheritDoc} - * - *

Warning: the results of calling this method may vary depending on - * the iteration order of {@code map}. - * - * @throws IllegalArgumentException if an attempt to {@code put} any - * entry fails. Note that some map entries may have been added to the - * bimap before the exception was thrown. - */ - void putAll(Map map); - - // Views - - /** - * {@inheritDoc} - * - *

Because a bimap has unique values, this method returns a {@link Set}, - * instead of the {@link java.util.Collection} specified in the {@link Map} - * interface. - */ - Set values(); - - /** - * Returns the inverse view of this bimap, which maps each of this bimap's - * values to its associated key. The two bimaps are backed by the same data; - * any changes to one will appear in the other. - * - *

Note:There is no guaranteed correspondence between the iteration - * order of a bimap and that of its inverse. - * - * @return the inverse view of this bimap - */ - BiMap inverse(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ByFunctionOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ByFunctionOrdering.java deleted file mode 100644 index 1bf9a1ca918..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ByFunctionOrdering.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Function; -import org.elasticsearch.util.base.Objects; - -import javax.annotation.Nullable; -import java.io.Serializable; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * An ordering that orders elements by applying an order to the result of a - * function on those elements. - */ -@GwtCompatible(serializable = true) -final class ByFunctionOrdering - extends Ordering implements Serializable { - final Function function; - final Ordering ordering; - - ByFunctionOrdering( - Function function, Ordering ordering) { - this.function = checkNotNull(function); - this.ordering = checkNotNull(ordering); - } - - public int compare(F left, F right) { - return ordering.compare(function.apply(left), function.apply(right)); - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof ByFunctionOrdering) { - ByFunctionOrdering that = (ByFunctionOrdering) object; - return this.function.equals(that.function) - && this.ordering.equals(that.ordering); - } - return false; - } - - @Override public int hashCode() { - return Objects.hashCode(function, ordering); - } - - @Override public String toString() { - return ordering + ".onResultOf(" + function + ")"; - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ClassToInstanceMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ClassToInstanceMap.java deleted file mode 100644 index a4a346388dc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ClassToInstanceMap.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Map; - -/** - * A map, each entry of which maps a Java - * raw type to an instance of that type. - * In addition to implementing {@code Map}, the additional type-safe operations - * {@link #putInstance} and {@link #getInstance} are available. - * - *

Like any other {@code Map}, this map may contain entries - * for primitive types, and a primitive type and its corresponding wrapper type - * may map to different values. - * - * @param the common supertype that all entries must share; often this is - * simply {@link Object} - * - * @author Kevin Bourrillion - */ -@GwtCompatible -public interface ClassToInstanceMap extends Map, B> { - /** - * Returns the value the specified class is mapped to, or {@code null} if no - * entry for this class is present. This will only return a value that was - * bound to this specific class, not a value that may have been bound to a - * subtype. - */ - T getInstance(Class type); - - /** - * Maps the specified class to the specified value. Does not associate - * this value with any of the class's supertypes. - * - * @return the value previously associated with this class (possibly {@code - * null}), or {@code null} if there was no previous entry. - */ - T putInstance(Class type, @Nullable T value); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Collections2.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Collections2.java deleted file mode 100644 index 2a50c0de032..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Collections2.java +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Function; -import org.elasticsearch.util.base.Joiner; -import org.elasticsearch.util.base.Predicate; -import org.elasticsearch.util.base.Predicates; - -import javax.annotation.Nullable; -import java.util.AbstractCollection; -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Provides static methods for working with {@code Collection} instances. - * - * @author Chris Povirk - * @author Mike Bostock - * @author Jared Levy - */ -@GwtCompatible -public final class Collections2 { - private Collections2() {} - - /** - * Returns {@code true} if the collection {@code self} contains all of the - * elements in the collection {@code c}. - * - *

This method iterates over the specified collection {@code c}, checking - * each element returned by the iterator in turn to see if it is contained in - * the specified collection {@code self}. If all elements are so contained, - * {@code true} is returned, otherwise {@code false}. - * - * @param self a collection which might contain all elements in {@code c} - * @param c a collection whose elements might be contained by {@code self} - */ - // TODO: Make public? - static boolean containsAll(Collection self, Collection c) { - checkNotNull(self); - for (Object o : c) { - if (!self.contains(o)) { - return false; - } - } - return true; - } - - /** - * Converts an iterable into a collection. If the iterable is already a - * collection, it is returned. Otherwise, an {@link java.util.ArrayList} is - * created with the contents of the iterable in the same iteration order. - */ - static Collection toCollection(Iterable iterable) { - return (iterable instanceof Collection) - ? (Collection) iterable : Lists.newArrayList(iterable); - } - - /** - * Returns the elements of {@code unfiltered} that satisfy a predicate. The - * returned collection is a live view of {@code unfiltered}; changes to one - * affect the other. - * - *

The resulting collection's iterator does not support {@code remove()}, - * but all other collection methods are supported. The collection's - * {@code add()} and {@code addAll()} methods throw an - * {@link IllegalArgumentException} if an element that doesn't satisfy the - * predicate is provided. When methods such as {@code removeAll()} and - * {@code clear()} are called on the filtered collection, only elements that - * satisfy the filter will be removed from the underlying collection. - * - *

The returned collection isn't threadsafe or serializable, even if - * {@code unfiltered} is. - * - *

Many of the filtered collection's methods, such as {@code size()}, - * iterate across every element in the underlying collection and determine - * which elements satisfy the filter. When a live view is not needed, - * it may be faster to copy {@code Iterables.filter(unfiltered, predicate)} - * and use the copy. - */ - public static Collection filter( - Collection unfiltered, Predicate predicate) { - if (unfiltered instanceof FilteredCollection) { - // Support clear(), removeAll(), and retainAll() when filtering a filtered - // collection. - return ((FilteredCollection) unfiltered).createCombined(predicate); - } - - return new FilteredCollection( - checkNotNull(unfiltered), checkNotNull(predicate)); - } - - static class FilteredCollection implements Collection { - final Collection unfiltered; - final Predicate predicate; - - FilteredCollection(Collection unfiltered, - Predicate predicate) { - this.unfiltered = unfiltered; - this.predicate = predicate; - } - - FilteredCollection createCombined(Predicate newPredicate) { - return new FilteredCollection(unfiltered, - Predicates.and(predicate, newPredicate)); - // . above needed to compile in JDK 5 - } - - public boolean add(E element) { - checkArgument(predicate.apply(element)); - return unfiltered.add(element); - } - - public boolean addAll(Collection collection) { - for (E element : collection) { - checkArgument(predicate.apply(element)); - } - return unfiltered.addAll(collection); - } - - public void clear() { - Iterables.removeIf(unfiltered, predicate); - } - - public boolean contains(Object element) { - try { - // unsafe cast can result in a CCE from predicate.apply(), which we - // will catch - @SuppressWarnings("unchecked") - E e = (E) element; - return predicate.apply(e) && unfiltered.contains(element); - } catch (NullPointerException e) { - return false; - } catch (ClassCastException e) { - return false; - } - } - - public boolean containsAll(Collection collection) { - for (Object element : collection) { - if (!contains(element)) { - return false; - } - } - return true; - } - - public boolean isEmpty() { - return !Iterators.any(unfiltered.iterator(), predicate); - } - - public Iterator iterator() { - return Iterators.filter(unfiltered.iterator(), predicate); - } - - public boolean remove(Object element) { - try { - // unsafe cast can result in a CCE from predicate.apply(), which we - // will catch - @SuppressWarnings("unchecked") - E e = (E) element; - return predicate.apply(e) && unfiltered.remove(element); - } catch (NullPointerException e) { - return false; - } catch (ClassCastException e) { - return false; - } - } - - public boolean removeAll(final Collection collection) { - checkNotNull(collection); - Predicate combinedPredicate = new Predicate() { - public boolean apply(E input) { - return predicate.apply(input) && collection.contains(input); - } - }; - return Iterables.removeIf(unfiltered, combinedPredicate); - } - - public boolean retainAll(final Collection collection) { - checkNotNull(collection); - Predicate combinedPredicate = new Predicate() { - public boolean apply(E input) { - return predicate.apply(input) && !collection.contains(input); - } - }; - return Iterables.removeIf(unfiltered, combinedPredicate); - } - - public int size() { - return Iterators.size(iterator()); - } - - public Object[] toArray() { - // creating an ArrayList so filtering happens once - return Lists.newArrayList(iterator()).toArray(); - } - - public T[] toArray(T[] array) { - return Lists.newArrayList(iterator()).toArray(array); - } - - @Override public String toString() { - return Iterators.toString(iterator()); - } - } - - /** - * Returns a collection that applies {@code function} to each element of - * {@code fromCollection}. The returned collection is a live view of {@code - * fromCollection}; changes to one affect the other. - * - *

The returned collection's {@code add()} and {@code addAll()} methods - * throw an {@link UnsupportedOperationException}. All other collection - * methods are supported, as long as {@code fromCollection} supports them. - * - *

The returned collection isn't threadsafe or serializable, even if - * {@code fromCollection} is. - * - *

When a live view is not needed, it may be faster to copy the - * transformed collection and use the copy. - */ - public static Collection transform(Collection fromCollection, - Function function) { - return new TransformedCollection(fromCollection, function); - } - - static class TransformedCollection extends AbstractCollection { - final Collection fromCollection; - final Function function; - - TransformedCollection(Collection fromCollection, - Function function) { - this.fromCollection = checkNotNull(fromCollection); - this.function = checkNotNull(function); - } - - @Override public void clear() { - fromCollection.clear(); - } - - @Override public boolean isEmpty() { - return fromCollection.isEmpty(); - } - - @Override public Iterator iterator() { - return Iterators.transform(fromCollection.iterator(), function); - } - - @Override public int size() { - return fromCollection.size(); - } - } - - static boolean setEquals(Set thisSet, @Nullable Object object) { - if (object == thisSet) { - return true; - } - if (object instanceof Set) { - Set thatSet = (Set) object; - return thisSet.size() == thatSet.size() - && thisSet.containsAll(thatSet); - } - return false; - } - - static final Joiner standardJoiner = Joiner.on(", "); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ComparatorOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ComparatorOrdering.java deleted file mode 100644 index 176f5165e1d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ComparatorOrdering.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** An ordering for a pre-existing {@code comparator}. */ -@GwtCompatible(serializable = true) -final class ComparatorOrdering extends Ordering implements Serializable { - final Comparator comparator; - - ComparatorOrdering(Comparator comparator) { - this.comparator = checkNotNull(comparator); - } - - public int compare(T a, T b) { - return comparator.compare(a, b); - } - - // Override just to remove a level of indirection from inner loops - @Override public int binarySearch(List sortedList, T key) { - return Collections.binarySearch(sortedList, key, comparator); - } - - // Override just to remove a level of indirection from inner loops - @Override public List sortedCopy(Iterable iterable) { - List list = Lists.newArrayList(iterable); - Collections.sort(list, comparator); - return list; - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof ComparatorOrdering) { - ComparatorOrdering that = (ComparatorOrdering) object; - return this.comparator.equals(that.comparator); - } - return false; - } - - @Override public int hashCode() { - return comparator.hashCode(); - } - - @Override public String toString() { - return comparator.toString(); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/CompoundOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/CompoundOrdering.java deleted file mode 100644 index e2ade917986..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/CompoundOrdering.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.Serializable; -import java.util.Comparator; -import java.util.List; - -/** An ordering that tries several comparators in order. */ -@GwtCompatible(serializable = true) -final class CompoundOrdering extends Ordering implements Serializable { - final ImmutableList> comparators; - - CompoundOrdering(Comparator primary, - Comparator secondary) { - this.comparators - = ImmutableList.>of(primary, secondary); - } - - CompoundOrdering(Iterable> comparators) { - this.comparators = ImmutableList.copyOf(comparators); - } - - CompoundOrdering(List> comparators, - Comparator lastComparator) { - this.comparators = new ImmutableList.Builder>() - .addAll(comparators).add(lastComparator).build(); - } - - public int compare(T left, T right) { - for (Comparator comparator : comparators) { - int result = comparator.compare(left, right); - if (result != 0) { - return result; - } - } - return 0; - } - - @Override public boolean equals(Object object) { - if (object == this) { - return true; - } - if (object instanceof CompoundOrdering) { - CompoundOrdering that = (CompoundOrdering) object; - return this.comparators.equals(that.comparators); - } - return false; - } - - @Override public int hashCode() { - return comparators.hashCode(); - } - - @Override public String toString() { - return "Ordering.compound(" + comparators + ")"; - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ComputationException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ComputationException.java deleted file mode 100644 index d8f91be5aca..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ComputationException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -/** - * Wraps an exception that occured during a computation. - */ -@GwtCompatible -public class ComputationException extends RuntimeException { - /** - * Creates a new instance with the given cause. - */ - public ComputationException(Throwable cause) { - super(cause); - } - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ConcurrentHashMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ConcurrentHashMultiset.java deleted file mode 100644 index 96cbfa54e32..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ConcurrentHashMultiset.java +++ /dev/null @@ -1,481 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.VisibleForTesting; -import org.elasticsearch.util.collect.Serialization.FieldSetter; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import static org.elasticsearch.util.base.Preconditions.*; -import static org.elasticsearch.util.collect.Multisets.*; - -/** - * A multiset that supports concurrent modifications and that provides atomic - * versions of most {@code Multiset} operations (exceptions where noted). Null - * elements are not supported. - * - * @author Cliff L. Biffle - */ -public final class ConcurrentHashMultiset extends AbstractMultiset - implements Serializable { - /* - * The ConcurrentHashMultiset's atomic operations are implemented in terms of - * ConcurrentMap's atomic operations. Many of them, such as add(E, int), are - * read-modify-write sequences, and so are implemented as loops that wrap - * ConcurrentMap's compare-and-set operations (like putIfAbsent). - */ - - /** The number of occurrences of each element. */ - private final transient ConcurrentMap countMap; - - // This constant allows the deserialization code to set a final field. This - // holder class makes sure it is not initialized unless an instance is - // deserialized. - private static class FieldSettersHolder { - @SuppressWarnings("unchecked") - // eclipse doesn't like the raw type here, but it's harmless - static final FieldSetter COUNT_MAP_FIELD_SETTER - = Serialization.getFieldSetter( - ConcurrentHashMultiset.class, "countMap"); - } - - /** - * Creates a new, empty {@code ConcurrentHashMultiset} using the default - * initial capacity, load factor, and concurrency settings. - */ - public static ConcurrentHashMultiset create() { - return new ConcurrentHashMultiset(new ConcurrentHashMap()); - } - - /** - * Creates a new {@code ConcurrentHashMultiset} containing the specified - * elements, using the default initial capacity, load factor, and concurrency - * settings. - * - * @param elements the elements that the multiset should contain - */ - public static ConcurrentHashMultiset create( - Iterable elements) { - ConcurrentHashMultiset multiset = ConcurrentHashMultiset.create(); - Iterables.addAll(multiset, elements); - return multiset; - } - - /** - * Creates an instance using {@code countMap} to store elements and their - * counts. - * - *

This instance will assume ownership of {@code countMap}, and other code - * should not maintain references to the map or modify it in any way. - * - * @param countMap backing map for storing the elements in the multiset and - * their counts. It must be empty. - * @throws IllegalArgumentException if {@code countMap} is not empty - */ - @VisibleForTesting ConcurrentHashMultiset( - ConcurrentMap countMap) { - checkArgument(countMap.isEmpty()); - this.countMap = countMap; - } - - // Query Operations - - /** - * Returns the number of occurrences of {@code element} in this multiset. - * - * @param element the element to look for - * @return the nonnegative number of occurrences of the element - */ - @Override public int count(@Nullable Object element) { - try { - return unbox(countMap.get(element)); - } catch (NullPointerException e) { - return 0; - } catch (ClassCastException e) { - return 0; - } - } - - /** - * {@inheritDoc} - * - *

If the data in the multiset is modified by any other threads during this - * method, it is undefined which (if any) of these modifications will be - * reflected in the result. - */ - @Override public int size() { - long sum = 0L; - for (Integer value : countMap.values()) { - sum += value; - } - return (int) Math.min(sum, Integer.MAX_VALUE); - } - - /* - * Note: the superclass toArray() methods assume that size() gives a correct - * answer, which ours does not. - */ - - @Override public Object[] toArray() { - return snapshot().toArray(); - } - - @Override public T[] toArray(T[] array) { - return snapshot().toArray(array); - } - - /* - * We'd love to use 'new ArrayList(this)' or 'list.addAll(this)', but - * either of these would recurse back to us again! - */ - private List snapshot() { - List list = Lists.newArrayListWithExpectedSize(size()); - for (Multiset.Entry entry : entrySet()) { - E element = entry.getElement(); - for (int i = entry.getCount(); i > 0; i--) { - list.add(element); - } - } - return list; - } - - // Modification Operations - - /** - * Adds a number of occurrences of the specified element to this multiset. - * - * @param element the element to add - * @param occurrences the number of occurrences to add - * @return the previous count of the element before the operation; possibly - * zero - * @throws IllegalArgumentException if {@code occurrences} is negative, or if - * the resulting amount would exceed {@link Integer#MAX_VALUE} - */ - @Override public int add(E element, int occurrences) { - if (occurrences == 0) { - return count(element); - } - checkArgument(occurrences > 0, "Invalid occurrences: %s", occurrences); - - while (true) { - int current = count(element); - if (current == 0) { - if (countMap.putIfAbsent(element, occurrences) == null) { - return 0; - } - } else { - checkArgument(occurrences <= Integer.MAX_VALUE - current, - "Overflow adding %s occurrences to a count of %s", - occurrences, current); - int next = current + occurrences; - if (countMap.replace(element, current, next)) { - return current; - } - } - // If we're still here, there was a race, so just try again. - } - } - - /** - * Removes a number of occurrences of the specified element from this - * multiset. If the multiset contains fewer than this number of occurrences to - * begin with, all occurrences will be removed. - * - * @param element the element whose occurrences should be removed - * @param occurrences the number of occurrences of the element to remove - * @return the count of the element before the operation; possibly zero - * @throws IllegalArgumentException if {@code occurrences} is negative - */ - @Override public int remove(@Nullable Object element, int occurrences) { - if (occurrences == 0) { - return count(element); - } - checkArgument(occurrences > 0, "Invalid occurrences: %s", occurrences); - - while (true) { - int current = count(element); - if (current == 0) { - return 0; - } - if (occurrences >= current) { - if (countMap.remove(element, current)) { - return current; - } - } else { - // We know it's an "E" because it already exists in the map. - @SuppressWarnings("unchecked") - E casted = (E) element; - - if (countMap.replace(casted, current, current - occurrences)) { - return current; - } - } - // If we're still here, there was a race, so just try again. - } - } - - /** - * Removes all occurrences of the specified element from this multiset. - * This method complements {@link Multiset#remove(Object)}, which removes only - * one occurrence at a time. - * - * @param element the element whose occurrences should all be removed - * @return the number of occurrences successfully removed, possibly zero - */ - private int removeAllOccurrences(@Nullable Object element) { - try { - return unbox(countMap.remove(element)); - } catch (NullPointerException e) { - return 0; - } catch (ClassCastException e) { - return 0; - } - } - - /** - * Removes exactly the specified number of occurrences of {@code element}, or - * makes no change if this is not possible. - * - *

This method, in contrast to {@link #remove(Object, int)}, has no effect - * when the element count is smaller than {@code occurrences}. - * - * @param element the element to remove - * @param occurrences the number of occurrences of {@code element} to remove - * @return {@code true} if the removal was possible (including if {@code - * occurrences} is zero) - */ - public boolean removeExactly(@Nullable Object element, int occurrences) { - if (occurrences == 0) { - return true; - } - checkArgument(occurrences > 0, "Invalid occurrences: %s", occurrences); - - while (true) { - int current = count(element); - if (occurrences > current) { - return false; - } - if (occurrences == current) { - if (countMap.remove(element, occurrences)) { - return true; - } - } else { - @SuppressWarnings("unchecked") // it's in the map, must be an "E" - E casted = (E) element; - if (countMap.replace(casted, current, current - occurrences)) { - return true; - } - } - // If we're still here, there was a race, so just try again. - } - } - - /** - * Adds or removes occurrences of {@code element} such that the {@link #count} - * of the element becomes {@code count}. - * - * @return the count of {@code element} in the multiset before this call - * @throws IllegalArgumentException if {@code count} is negative - */ - @Override public int setCount(E element, int count) { - checkNonnegative(count, "count"); - return (count == 0) - ? removeAllOccurrences(element) - : unbox(countMap.put(element, count)); - } - - /** - * Sets the number of occurrences of {@code element} to {@code newCount}, but - * only if the count is currently {@code oldCount}. If {@code element} does - * not appear in the multiset exactly {@code oldCount} times, no changes will - * be made. - * - * @return {@code true} if the change was successful. This usually indicates - * that the multiset has been modified, but not always: in the case that - * {@code oldCount == newCount}, the method will return {@code true} if - * the condition was met. - * @throws IllegalArgumentException if {@code oldCount} or {@code newCount} is - * negative - */ - @Override public boolean setCount(E element, int oldCount, int newCount) { - checkNonnegative(oldCount, "oldCount"); - checkNonnegative(newCount, "newCount"); - if (newCount == 0) { - if (oldCount == 0) { - // No change to make, but must return true if the element is not present - return !countMap.containsKey(element); - } else { - return countMap.remove(element, oldCount); - } - } - if (oldCount == 0) { - return countMap.putIfAbsent(element, newCount) == null; - } - return countMap.replace(element, oldCount, newCount); - } - - // Views - - @Override Set createElementSet() { - final Set delegate = countMap.keySet(); - return new ForwardingSet() { - @Override protected Set delegate() { - return delegate; - } - @Override public boolean remove(Object object) { - try { - return delegate.remove(object); - } catch (NullPointerException e) { - return false; - } catch (ClassCastException e) { - return false; - } - } - }; - } - - private transient EntrySet entrySet; - - @Override public Set> entrySet() { - EntrySet result = entrySet; - if (result == null) { - entrySet = result = new EntrySet(); - } - return result; - } - - private class EntrySet extends AbstractSet> { - @Override public int size() { - return countMap.size(); - } - - @Override public boolean isEmpty() { - return countMap.isEmpty(); - } - - @Override public boolean contains(Object object) { - if (object instanceof Multiset.Entry) { - Multiset.Entry entry = (Multiset.Entry) object; - Object element = entry.getElement(); - int entryCount = entry.getCount(); - return entryCount > 0 && count(element) == entryCount; - } - return false; - } - - @Override public Iterator> iterator() { - final Iterator> backingIterator - = countMap.entrySet().iterator(); - return new Iterator>() { - public boolean hasNext() { - return backingIterator.hasNext(); - } - - public Multiset.Entry next() { - Map.Entry backingEntry = backingIterator.next(); - return Multisets.immutableEntry( - backingEntry.getKey(), backingEntry.getValue()); - } - - public void remove() { - backingIterator.remove(); - } - }; - } - - /* - * Note: the superclass toArray() methods assume that size() gives a correct - * answer, which ours does not. - */ - - @Override public Object[] toArray() { - return snapshot().toArray(); - } - - @Override public T[] toArray(T[] array) { - return snapshot().toArray(array); - } - - /* - * We'd love to use 'new ArrayList(this)' or 'list.addAll(this)', but - * either of these would recurse back to us again! - */ - private List> snapshot() { - List> list = Lists.newArrayListWithExpectedSize(size()); - for (Multiset.Entry entry : this) { - list.add(entry); - } - return list; - } - - @Override public boolean remove(Object object) { - if (object instanceof Multiset.Entry) { - Multiset.Entry entry = (Multiset.Entry) object; - Object element = entry.getElement(); - int entryCount = entry.getCount(); - return countMap.remove(element, entryCount); - } - return false; - } - - @Override public void clear() { - countMap.clear(); - } - - /** - * The hash code is the same as countMap's, though the objects aren't equal. - */ - @Override public int hashCode() { - return countMap.hashCode(); - } - } - - /** - * We use a special form of unboxing that treats null as zero. - */ - private static int unbox(Integer i) { - return (i == null) ? 0 : i; - } - - /** - * @serialData the number of distinct elements, the first element, its count, - * the second element, its count, and so on - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - // creating HashMultiset to handle concurrent changes - Serialization.writeMultiset(HashMultiset.create(this), stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - FieldSettersHolder.COUNT_MAP_FIELD_SETTER.set( - this, new ConcurrentHashMap()); - Serialization.populateMultiset(this, stream); - } - - private static final long serialVersionUID = 0L; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ConstrainedMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ConstrainedMap.java deleted file mode 100644 index d4e7fb35e84..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ConstrainedMap.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Factory and utilities pertaining to the {@code MapConstraint} interface. - * - * @author Mike Bostock - */ -@GwtCompatible -class ConstrainedMap extends ForwardingMap { - final Map delegate; - final MapConstraint constraint; - private volatile Set> entrySet; - - ConstrainedMap( - Map delegate, MapConstraint constraint) { - this.delegate = checkNotNull(delegate); - this.constraint = checkNotNull(constraint); - } - - @Override protected Map delegate() { - return delegate; - } - @Override public Set> entrySet() { - if (entrySet == null) { - entrySet = constrainedEntrySet(delegate.entrySet(), constraint); - } - return entrySet; - } - @Override public V put(K key, V value) { - constraint.checkKeyValue(key, value); - return delegate.put(key, value); - } - @Override public void putAll(Map map) { - for (Entry entry : map.entrySet()) { - put(entry.getKey(), entry.getValue()); - } - } - - private static Entry constrainedEntry( - final Entry entry, - final MapConstraint constraint) { - checkNotNull(entry); - checkNotNull(constraint); - return new ForwardingMapEntry() { - @Override protected Entry delegate() { - return entry; - } - @Override public V setValue(V value) { - constraint.checkKeyValue(getKey(), value); - return entry.setValue(value); - } - }; - } - - private static Set> constrainedEntrySet( - Set> entries, - MapConstraint constraint) { - return new ConstrainedEntrySet(entries, constraint); - } - - private static class ConstrainedEntries - extends ForwardingCollection> { - final MapConstraint constraint; - final Collection> entries; - - ConstrainedEntries(Collection> entries, - MapConstraint constraint) { - this.entries = entries; - this.constraint = constraint; - } - @Override protected Collection> delegate() { - return entries; - } - - @Override public Iterator> iterator() { - final Iterator> iterator = entries.iterator(); - return new ForwardingIterator>() { - @Override public Entry next() { - return constrainedEntry(iterator.next(), constraint); - } - @Override protected Iterator> delegate() { - return iterator; - } - }; - } - - // See Collections.CheckedMap.CheckedEntrySet for details on attacks. - - @Override public Object[] toArray() { - return ObjectArrays.toArrayImpl(this); - } - @Override public T[] toArray(T[] array) { - return ObjectArrays.toArrayImpl(this, array); - } - @Override public boolean contains(Object o) { - return Maps.containsEntryImpl(delegate(), o); - } - @Override public boolean containsAll(Collection c) { - return Collections2.containsAll(this, c); - } - @Override public boolean remove(Object o) { - return Maps.removeEntryImpl(delegate(), o); - } - @Override public boolean removeAll(Collection c) { - return Iterators.removeAll(iterator(), c); - } - @Override public boolean retainAll(Collection c) { - return Iterators.retainAll(iterator(), c); - } - } - - static class ConstrainedEntrySet - extends ConstrainedEntries implements Set> { - ConstrainedEntrySet(Set> entries, - MapConstraint constraint) { - super(entries, constraint); - } - - // See Collections.CheckedMap.CheckedEntrySet for details on attacks. - - @Override public boolean equals(@Nullable Object object) { - return Collections2.setEquals(this, object); - } - - @Override public int hashCode() { - return Sets.hashCodeImpl(this); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/CustomConcurrentHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/CustomConcurrentHashMap.java deleted file mode 100644 index 827885af9e4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/CustomConcurrentHashMap.java +++ /dev/null @@ -1,2153 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.base.Function; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicReferenceArray; -import java.util.concurrent.locks.ReentrantLock; - -/** - * A framework for concurrent hash map implementations. The - * CustomConcurrentHashMap class itself is not extensible and does not contain - * any methods. Use {@link Builder} to create a custom concurrent hash map - * instance. Client libraries implement {@link Strategy}, and this class - * provides the surrounding concurrent data structure which implements {@link - * ConcurrentMap}. Additionally supports implementing maps where {@link - * Map#get} atomically computes values on demand (see {@link - * Builder#buildComputingMap(CustomConcurrentHashMap.ComputingStrategy, - * Function)}). - * - *

The resulting hash table supports full concurrency of retrievals and - * adjustable expected concurrency for updates. Even though all operations are - * thread-safe, retrieval operations do not entail locking, - * and there is not any support for locking the entire table - * in a way that prevents all access. - * - *

Retrieval operations (including {@link Map#get}) generally do not - * block, so may overlap with update operations (including - * {@link Map#put} and {@link Map#remove}). Retrievals reflect the results - * of the most recently completed update operations holding - * upon their onset. For aggregate operations such as {@link Map#putAll} - * and {@link Map#clear}, concurrent retrievals may reflect insertion or - * removal of only some entries. Similarly, iterators return elements - * reflecting the state of the hash table at some point at or since the - * creation of the iterator. They do not throw - * {@link java.util.ConcurrentModificationException}. However, iterators can - * only be used by one thread at a time. - * - *

The resulting {@link ConcurrentMap} and its views and iterators implement - * all of the optional methods of the {@link java.util.Map} and {@link - * java.util.Iterator} interfaces. Partially reclaimed entries are never - * exposed through the views or iterators. - * - *

For example, the following strategy emulates the behavior of - * {@link java.util.concurrent.ConcurrentHashMap}: - * - *

 {@code
- * class ConcurrentHashMapStrategy
- *     implements CustomConcurrentHashMap.Strategy>, Serializable {
- *   public InternalEntry newEntry(K key, int hash,
- *       InternalEntry next) {
- *     return new InternalEntry(key, hash, null, next);
- *   }
- *   public InternalEntry copyEntry(K key,
- *       InternalEntry original, InternalEntry next) {
- *     return new InternalEntry(key, original.hash, original.value, next);
- *   }
- *   public void setValue(InternalEntry entry, V value) {
- *     entry.value = value;
- *   }
- *   public V getValue(InternalEntry entry) { return entry.value; }
- *   public boolean equalKeys(K a, Object b) { return a.equals(b); }
- *   public boolean equalValues(V a, Object b) { return a.equals(b); }
- *   public int hashKey(Object key) { return key.hashCode(); }
- *   public K getKey(InternalEntry entry) { return entry.key; }
- *   public InternalEntry getNext(InternalEntry entry) {
- *     return entry.next;
- *   }
- *   public int getHash(InternalEntry entry) { return entry.hash; }
- *   public void setInternals(CustomConcurrentHashMap.Internals> internals) {} // ignored
- * }
- *
- * class InternalEntry {
- *   final K key;
- *   final int hash;
- *   volatile V value;
- *   final InternalEntry next;
- *   InternalEntry(K key, int hash, V value, InternalEntry next) {
- *     this.key = key;
- *     this.hash = hash;
- *     this.value = value;
- *     this.next = next;
- *   }
- * }
- * }
- * - * To create a {@link java.util.concurrent.ConcurrentMap} using the strategy - * above: - * - *
{@code
- *   ConcurrentMap map = new CustomConcurrentHashMap.Builder()
- *       .build(new ConcurrentHashMapStrategy());
- * }
- * - * @author Bob Lee - * @author Doug Lea - */ -final class CustomConcurrentHashMap { - - /** Prevents instantiation. */ - private CustomConcurrentHashMap() {} - - /** - * Builds a custom concurrent hash map. - */ - static final class Builder { - private static final int DEFAULT_INITIAL_CAPACITY = 16; - private static final int DEFAULT_CONCURRENCY_LEVEL = 16; - - private static final int UNSET_INITIAL_CAPACITY = -1; - private static final int UNSET_CONCURRENCY_LEVEL = -1; - - int initialCapacity = UNSET_INITIAL_CAPACITY; - int concurrencyLevel = UNSET_CONCURRENCY_LEVEL; - - /** - * Sets a custom initial capacity (defaults to 16). Resizing this or any - * other kind of hash table is a relatively slow operation, so, when - * possible, it is a good idea to provide estimates of expected table - * sizes. - * - * @throws IllegalArgumentException if initialCapacity < 0 - */ - public Builder initialCapacity(int initialCapacity) { - if (this.initialCapacity != UNSET_INITIAL_CAPACITY) { - throw new IllegalStateException( - "initial capacity was already set to " + this.initialCapacity); - } - if (initialCapacity < 0) { - throw new IllegalArgumentException(); - } - this.initialCapacity = initialCapacity; - return this; - } - - /** - * Guides the allowed concurrency among update operations. Used as a - * hint for internal sizing. The table is internally partitioned to try to - * permit the indicated number of concurrent updates without contention. - * Because placement in hash tables is essentially random, the actual - * concurrency will vary. Ideally, you should choose a value to accommodate - * as many threads as will ever concurrently modify the table. Using a - * significantly higher value than you need can waste space and time, - * and a significantly lower value can lead to thread contention. But - * overestimates and underestimates within an order of magnitude do - * not usually have much noticeable impact. A value of one is - * appropriate when it is known that only one thread will modify and - * all others will only read. Defaults to {@literal 16}. - * - * @throws IllegalArgumentException if concurrencyLevel < 0 - */ - public Builder concurrencyLevel(int concurrencyLevel) { - if (this.concurrencyLevel != UNSET_CONCURRENCY_LEVEL) { - throw new IllegalStateException( - "concurrency level was already set to " + this.concurrencyLevel); - } - if (concurrencyLevel <= 0) { - throw new IllegalArgumentException(); - } - this.concurrencyLevel = concurrencyLevel; - return this; - } - - /** - * Creates a new concurrent hash map backed by the given strategy. - * - * @param strategy used to implement and manipulate the entries - * - * @param the type of keys to be stored in the returned map - * @param the type of values to be stored in the returned map - * @param the type of internal entry to be stored in the returned map - * - * @throws NullPointerException if strategy is null - */ - public ConcurrentMap buildMap(Strategy strategy) { - if (strategy == null) { - throw new NullPointerException("strategy"); - } - return new Impl(strategy, this); - } - - /** - * Creates a {@link ConcurrentMap}, backed by the given strategy, that - * supports atomic, on-demand computation of values. {@link Map#get} - * returns the value corresponding to the given key, atomically computes - * it using the computer function passed to this builder, or waits for - * another thread to compute the value if necessary. Only one value will - * be computed for each key at a given time. - * - *

If an entry's value has not finished computing yet, query methods - * besides {@link java.util.Map#get} return immediately as if an entry - * doesn't exist. In other words, an entry isn't externally visible until - * the value's computation completes. - * - *

{@link Map#get} in the returned map implementation throws: - *

    - *
  • {@link NullPointerException} if the key is null or the - * computer returns null
  • - *
  • or {@link ComputationException} wrapping an exception thrown by the - * computation
  • - *
- * - *

Note: Callers of {@code get()} must ensure that the key - * argument is of type {@code K}. {@code Map.get()} takes {@code Object}, - * so the key type is not checked at compile time. Passing an object of - * a type other than {@code K} can result in that object being unsafely - * passed to the computer function as type {@code K} not to mention the - * unsafe key being stored in the map. - * - * @param strategy used to implement and manipulate the entries - * @param computer used to compute values for keys - * - * @param the type of keys to be stored in the returned map - * @param the type of values to be stored in the returned map - * @param the type of internal entry to be stored in the returned map - * - * @throws NullPointerException if strategy or computer is null - */ - public ConcurrentMap buildComputingMap( - ComputingStrategy strategy, - Function computer) { - if (strategy == null) { - throw new NullPointerException("strategy"); - } - if (computer == null) { - throw new NullPointerException("computer"); - } - - return new ComputingImpl(strategy, this, computer); - } - - int getInitialCapacity() { - return (initialCapacity == UNSET_INITIAL_CAPACITY) - ? DEFAULT_INITIAL_CAPACITY : initialCapacity; - } - - int getConcurrencyLevel() { - return (concurrencyLevel == UNSET_CONCURRENCY_LEVEL) - ? DEFAULT_CONCURRENCY_LEVEL : concurrencyLevel; - } - } - - /** - * Implements behavior specific to the client's concurrent hash map - * implementation. Used by the framework to create new entries and perform - * operations on them. - * - *

Method parameters are never null unless otherwise specified. - * - *

Partially Reclaimed Entries

- * - *

This class does not allow {@code null} to be used as a key. - * Setting values to null is not permitted, but entries may have null keys - * or values for various reasons. For example, the key or value may have - * been garbage collected or reclaimed through other means. - * CustomConcurrentHashMap treats entries with null keys and values as - * "partially reclaimed" and ignores them for the most part. Entries may - * enter a partially reclaimed state but they must not leave it. Partially - * reclaimed entries will not be copied over during table expansions, for - * example. Strategy implementations should proactively remove partially - * reclaimed entries so that {@link Map#isEmpty} and {@link Map#size()} - * return up-to-date results. - * - * @param the type of keys to be stored in the returned map - * @param the type of values to be stored in the returned map - * @param internal entry type, not directly exposed to clients in map - * views - */ - public interface Strategy { - - /** - * Constructs a new entry for the given key with a pointer to the given - * next entry. - * - *

This method may return different entry implementations - * depending upon whether next is null or not. For example, if next is - * null (as will often be the case), this factory might use an entry - * class that doesn't waste memory on an unnecessary field. - * - * @param key for this entry - * @param hash of key returned by {@link #hashKey} - * @param next entry (used when implementing a hash bucket as a linked - * list, for example), possibly null - * @return a new entry - */ - abstract E newEntry(K key, int hash, E next); - - /** - * Creates a copy of the given entry pointing to the given next entry. - * Copies the value and any other implementation-specific state from - * {@code original} to the returned entry. For example, - * CustomConcurrentHashMap might use this method when removing other - * entries or expanding the internal table. - * - * @param key for {@code original} as well as the returned entry. - * Explicitly provided here to prevent reclamation of the key at an - * inopportune time in implementations that don't otherwise keep - * a strong reference to the key. - * @param original entry from which the value and other - * implementation-specific state should be copied - * @param newNext the next entry the new entry should point to, possibly - * null - */ - E copyEntry(K key, E original, E newNext); - - /** - * Sets the value of an entry using volatile semantics. Values are set - * synchronously on a per-entry basis. - * - * @param entry to set the value on - * @param value to set - */ - void setValue(E entry, V value); - - /** - * Gets the value of an entry using volatile semantics. - * - * @param entry to get the value from - */ - V getValue(E entry); - - /** - * Returns true if the two given keys are equal, false otherwise. Neither - * key will be null. - * - * @param a key from inside the map - * @param b key passed from caller, not necesarily of type K - * - * @see Object#equals the same contractual obligations apply here - */ - boolean equalKeys(K a, Object b); - - /** - * Returns true if the two given values are equal, false otherwise. Neither - * value will be null. - * - * @param a value from inside the map - * @param b value passed from caller, not necesarily of type V - * - * @see Object#equals the same contractual obligations apply here - */ - boolean equalValues(V a, Object b); - - /** - * Returns a hash code for the given key. - * - * @see Object#hashCode the same contractual obligations apply here - */ - int hashKey(Object key); - - /** - * Gets the key for the given entry. This may return null (for example, - * if the key was reclaimed by the garbage collector). - * - * @param entry to get key from - * @return key from the given entry - */ - K getKey(E entry); - - /** - * Gets the next entry relative to the given entry, the exact same entry - * that was provided to {@link Strategy#newEntry} when the given entry was - * created. - * - * @return the next entry or null if null was passed to - * {@link Strategy#newEntry} - */ - E getNext(E entry); - - /** - * Returns the hash code that was passed to {@link Strategy#newEntry}) - * when the given entry was created. - */ - int getHash(E entry); - -// TODO: -// /** -// * Notifies the strategy that an entry has been removed from the map. -// * -// * @param entry that was recently removed -// */ -// void remove(E entry); - - /** - * Provides an API for interacting directly with the map's internal - * entries to this strategy. Invoked once when the map is created. - * Strategies that don't need access to the map's internal entries - * can simply ignore the argument. - * - * @param internals of the map, enables direct interaction with the - * internal entries - */ - void setInternals(Internals internals); - } - - /** - * Provides access to a map's internal entries. - */ - public interface Internals { - -// TODO: -// /** -// * Returns a set view of the internal entries. -// */ -// Set entrySet(); - - /** - * Returns the internal entry corresponding to the given key from the map. - * - * @param key to retrieve entry for - * - * @throws NullPointerException if key is null - */ - E getEntry(K key); - - /** - * Removes the given entry from the map if the value of the entry in the - * map matches the given value. - * - * @param entry to remove - * @param value entry must have for the removal to succeed - * - * @throws NullPointerException if entry is null - */ - boolean removeEntry(E entry, @Nullable V value); - - /** - * Removes the given entry from the map. - * - * @param entry to remove - * - * @throws NullPointerException if entry is null - */ - boolean removeEntry(E entry); - } - - /** - * Extends {@link Strategy} to add support for computing values on-demand. - * Implementations should typically intialize the entry's value to a - * placeholder value in {@link #newEntry(Object, int, Object)} so that - * {@link #waitForValue(Object)} can tell the difference between a - * pre-intialized value and an in-progress computation. {@link - * #copyEntry(Object, Object, Object)} must detect and handle the case where - * an entry is copied in the middle of a computation. Implementations can - * throw {@link UnsupportedOperationException} in {@link #setValue(Object, - * Object)} if they wish to prevent users from setting values directly. - * - * @see Builder#buildComputingMap(CustomConcurrentHashMap.ComputingStrategy, - * Function) - */ - public interface ComputingStrategy extends Strategy { - - /** - * Computes a value for the given key and stores it in the given entry. - * Called as a result of {@link Map#get}. If this method throws an - * exception, CustomConcurrentHashMap will remove the entry and retry - * the computation on subsequent requests. - * - * @param entry that was created - * @param computer passed to {@link Builder#buildMap} - * - * @throws ComputationException if the computation threw an exception - * @throws NullPointerException if the computer returned null - * - * @return the computed value - */ - V compute(K key, E entry, Function computer); - - /** - * Gets a value from an entry waiting for the value to be set by {@link - * #compute} if necessary. Returns null if a value isn't available at - * which point CustomConcurrentHashMap tries to compute a new value. - * - * @param entry to return value from - * @return stored value or null if the value isn't available - * - * @throws InterruptedException if the thread was interrupted while - * waiting - */ - V waitForValue(E entry) throws InterruptedException; - } - - /** - * Applies a supplemental hash function to a given hash code, which defends - * against poor quality hash functions. This is critical when the - * concurrent hash map uses power-of-two length hash tables, that otherwise - * encounter collisions for hash codes that do not differ in lower or upper - * bits. - * - * @param h hash code - */ - private static int rehash(int h) { - // Spread bits to regularize both segment and index locations, - // using variant of single-word Wang/Jenkins hash. - h += (h << 15) ^ 0xffffcd7d; - h ^= (h >>> 10); - h += (h << 3); - h ^= (h >>> 6); - h += (h << 2) + (h << 14); - return h ^ (h >>> 16); - } - - /** The concurrent hash map implementation. */ - static class Impl extends AbstractMap - implements ConcurrentMap, Serializable { - - /* - * The basic strategy is to subdivide the table among Segments, - * each of which itself is a concurrently readable hash table. - */ - - /* ---------------- Constants -------------- */ - - /** - * The maximum capacity, used if a higher value is implicitly specified by - * either of the constructors with arguments. MUST be a power of two <= - * 1<<30 to ensure that entries are indexable using ints. - */ - static final int MAXIMUM_CAPACITY = 1 << 30; - - /** - * The maximum number of segments to allow; used to bound constructor - * arguments. - */ - static final int MAX_SEGMENTS = 1 << 16; // slightly conservative - - /** - * Number of unsynchronized retries in size and containsValue methods before - * resorting to locking. This is used to avoid unbounded retries if tables - * undergo continuous modification which would make it impossible to obtain - * an accurate result. - */ - static final int RETRIES_BEFORE_LOCK = 2; - - /* ---------------- Fields -------------- */ - - /** - * The strategy used to implement this map. - */ - final Strategy strategy; - - /** - * Mask value for indexing into segments. The upper bits of a key's hash - * code are used to choose the segment. - */ - final int segmentMask; - - /** - * Shift value for indexing within segments. Helps prevent entries that - * end up in the same segment from also ending up in the same bucket. - */ - final int segmentShift; - - /** - * The segments, each of which is a specialized hash table - */ - final Segment[] segments; - - /** - * Creates a new, empty map with the specified strategy, initial capacity, - * load factor and concurrency level. - */ - Impl(Strategy strategy, Builder builder) { - int concurrencyLevel = builder.getConcurrencyLevel(); - int initialCapacity = builder.getInitialCapacity(); - - if (concurrencyLevel > MAX_SEGMENTS) { - concurrencyLevel = MAX_SEGMENTS; - } - - // Find power-of-two sizes best matching arguments - int segmentShift = 0; - int segmentCount = 1; - while (segmentCount < concurrencyLevel) { - ++segmentShift; - segmentCount <<= 1; - } - this.segmentShift = 32 - segmentShift; - segmentMask = segmentCount - 1; - this.segments = newSegmentArray(segmentCount); - - if (initialCapacity > MAXIMUM_CAPACITY) { - initialCapacity = MAXIMUM_CAPACITY; - } - - int segmentCapacity = initialCapacity / segmentCount; - if (segmentCapacity * segmentCount < initialCapacity) { - ++segmentCapacity; - } - - int segmentSize = 1; - while (segmentSize < segmentCapacity) { - segmentSize <<= 1; - } - for (int i = 0; i < this.segments.length; ++i) { - this.segments[i] = new Segment(segmentSize); - } - - this.strategy = strategy; - - strategy.setInternals(new InternalsImpl()); - } - - int hash(Object key) { - int h = strategy.hashKey(key); - return rehash(h); - } - - class InternalsImpl implements Internals, Serializable { - - static final long serialVersionUID = 0; - - public E getEntry(K key) { - if (key == null) { - throw new NullPointerException("key"); - } - int hash = hash(key); - return segmentFor(hash).getEntry(key, hash); - } - - public boolean removeEntry(E entry, V value) { - if (entry == null) { - throw new NullPointerException("entry"); - } - int hash = strategy.getHash(entry); - return segmentFor(hash).removeEntry(entry, hash, value); - } - - public boolean removeEntry(E entry) { - if (entry == null) { - throw new NullPointerException("entry"); - } - int hash = strategy.getHash(entry); - return segmentFor(hash).removeEntry(entry, hash); - } - } - - @SuppressWarnings("unchecked") - Segment[] newSegmentArray(int ssize) { - // Note: This is the only way I could figure out how to create - // a segment array (the compile has a tough time with arrays of - // inner classes of generic types apparently). Safe because we're - // restricting what can go in the array and no one has an - // unrestricted reference. - return (Segment[]) Array.newInstance(Segment.class, ssize); - } - - /* ---------------- Small Utilities -------------- */ - - /** - * Returns the segment that should be used for key with given hash - * - * @param hash the hash code for the key - * @return the segment - */ - Segment segmentFor(int hash) { - return segments[(hash >>> segmentShift) & segmentMask]; - } - - /* ---------------- Inner Classes -------------- */ - - /** - * Segments are specialized versions of hash tables. This subclasses from - * ReentrantLock opportunistically, just to simplify some locking and avoid - * separate construction. - */ - @SuppressWarnings("serial") // This class is never serialized. - final class Segment extends ReentrantLock { - - /* - * Segments maintain a table of entry lists that are ALWAYS - * kept in a consistent state, so can be read without locking. - * Next fields of nodes are immutable (final). All list - * additions are performed at the front of each bin. This - * makes it easy to check changes, and also fast to traverse. - * When nodes would otherwise be changed, new nodes are - * created to replace them. This works well for hash tables - * since the bin lists tend to be short. (The average length - * is less than two for the default load factor threshold.) - * - * Read operations can thus proceed without locking, but rely - * on selected uses of volatiles to ensure that completed - * write operations performed by other threads are - * noticed. For most purposes, the "count" field, tracking the - * number of elements, serves as that volatile variable - * ensuring visibility. This is convenient because this field - * needs to be read in many read operations anyway: - * - * - All (unsynchronized) read operations must first read the - * "count" field, and should not look at table entries if - * it is 0. - * - * - All (synchronized) write operations should write to - * the "count" field after structurally changing any bin. - * The operations must not take any action that could even - * momentarily cause a concurrent read operation to see - * inconsistent data. This is made easier by the nature of - * the read operations in Map. For example, no operation - * can reveal that the table has grown but the threshold - * has not yet been updated, so there are no atomicity - * requirements for this with respect to reads. - * - * As a guide, all critical volatile reads and writes to the - * count field are marked in code comments. - */ - - /** - * The number of elements in this segment's region. - */ - volatile int count; - - /** - * Number of updates that alter the size of the table. This is used - * during bulk-read methods to make sure they see a consistent snapshot: - * If modCounts change during a traversal of segments computing size or - * checking containsValue, then we might have an inconsistent view of - * state so (usually) must retry. - */ - int modCount; - - /** - * The table is expanded when its size exceeds this threshold. (The - * value of this field is always {@code (int)(capacity * loadFactor)}.) - */ - int threshold; - - /** - * The per-segment table. - */ - volatile AtomicReferenceArray table; - - Segment(int initialCapacity) { - setTable(newEntryArray(initialCapacity)); - } - - AtomicReferenceArray newEntryArray(int size) { - return new AtomicReferenceArray(size); - } - - /** - * Sets table to new HashEntry array. Call only while holding lock or in - * constructor. - */ - void setTable(AtomicReferenceArray newTable) { - this.threshold = newTable.length() * 3 / 4; - this.table = newTable; - } - - /** - * Returns properly casted first entry of bin for given hash. - */ - E getFirst(int hash) { - AtomicReferenceArray table = this.table; - return table.get(hash & (table.length() - 1)); - } - - /* Specialized implementations of map methods */ - - public E getEntry(Object key, int hash) { - Strategy s = Impl.this.strategy; - if (count != 0) { // read-volatile - for (E e = getFirst(hash); e != null; e = s.getNext(e)) { - if (s.getHash(e) != hash) { - continue; - } - - K entryKey = s.getKey(e); - if (entryKey == null) { - continue; - } - - if (s.equalKeys(entryKey, key)) { - return e; - } - } - } - - return null; - } - - V get(Object key, int hash) { - E entry = getEntry(key, hash); - if (entry == null) { - return null; - } - - return strategy.getValue(entry); - } - - boolean containsKey(Object key, int hash) { - Strategy s = Impl.this.strategy; - if (count != 0) { // read-volatile - for (E e = getFirst(hash); e != null; e = s.getNext(e)) { - if (s.getHash(e) != hash) { - continue; - } - - K entryKey = s.getKey(e); - if (entryKey == null) { - continue; - } - - if (s.equalKeys(entryKey, key)) { - // Return true only if this entry has a value. - return s.getValue(e) != null; - } - } - } - - return false; - } - - boolean containsValue(Object value) { - Strategy s = Impl.this.strategy; - if (count != 0) { // read-volatile - AtomicReferenceArray table = this.table; - int length = table.length(); - for (int i = 0; i < length; i++) { - for (E e = table.get(i); e != null; e = s.getNext(e)) { - V entryValue = s.getValue(e); - - // If the value disappeared, this entry is partially collected, - // and we should skip it. - if (entryValue == null) { - continue; - } - - if (s.equalValues(entryValue, value)) { - return true; - } - } - } - } - - return false; - } - - boolean replace(K key, int hash, V oldValue, V newValue) { - Strategy s = Impl.this.strategy; - lock(); - try { - for (E e = getFirst(hash); e != null; e = s.getNext(e)) { - K entryKey = s.getKey(e); - if (s.getHash(e) == hash && entryKey != null - && s.equalKeys(key, entryKey)) { - // If the value disappeared, this entry is partially collected, - // and we should pretend like it doesn't exist. - V entryValue = s.getValue(e); - if (entryValue == null) { - return false; - } - - if (s.equalValues(entryValue, oldValue)) { - s.setValue(e, newValue); - return true; - } - } - } - - return false; - } finally { - unlock(); - } - } - - V replace(K key, int hash, V newValue) { - Strategy s = Impl.this.strategy; - lock(); - try { - for (E e = getFirst(hash); e != null; e = s.getNext(e)) { - K entryKey = s.getKey(e); - if (s.getHash(e) == hash && entryKey != null - && s.equalKeys(key, entryKey)) { - // If the value disappeared, this entry is partially collected, - // and we should pretend like it doesn't exist. - V entryValue = s.getValue(e); - if (entryValue == null) { - return null; - } - - s.setValue(e, newValue); - return entryValue; - } - } - - return null; - } finally { - unlock(); - } - } - - V put(K key, int hash, V value, boolean onlyIfAbsent) { - Strategy s = Impl.this.strategy; - lock(); - try { - int count = this.count; - if (count++ > this.threshold) { // ensure capacity - expand(); - } - - AtomicReferenceArray table = this.table; - int index = hash & (table.length() - 1); - - E first = table.get(index); - - // Look for an existing entry. - for (E e = first; e != null; e = s.getNext(e)) { - K entryKey = s.getKey(e); - if (s.getHash(e) == hash && entryKey != null - && s.equalKeys(key, entryKey)) { - // We found an existing entry. - - // If the value disappeared, this entry is partially collected, - // and we should pretend like it doesn't exist. - V entryValue = s.getValue(e); - if (onlyIfAbsent && entryValue != null) { - return entryValue; - } - - s.setValue(e, value); - return entryValue; - } - } - - // Create a new entry. - ++modCount; - E newEntry = s.newEntry(key, hash, first); - s.setValue(newEntry, value); - table.set(index, newEntry); - this.count = count; // write-volatile - return null; - } finally { - unlock(); - } - } - - /** - * Expands the table if possible. - */ - void expand() { - AtomicReferenceArray oldTable = table; - int oldCapacity = oldTable.length(); - if (oldCapacity >= MAXIMUM_CAPACITY) { - return; - } - - /* - * Reclassify nodes in each list to new Map. Because we are - * using power-of-two expansion, the elements from each bin - * must either stay at same index, or move with a power of two - * offset. We eliminate unnecessary node creation by catching - * cases where old nodes can be reused because their next - * fields won't change. Statistically, at the default - * threshold, only about one-sixth of them need cloning when - * a table doubles. The nodes they replace will be garbage - * collectable as soon as they are no longer referenced by any - * reader thread that may be in the midst of traversing table - * right now. - */ - - Strategy s = Impl.this.strategy; - AtomicReferenceArray newTable = newEntryArray(oldCapacity << 1); - threshold = newTable.length() * 3 / 4; - int newMask = newTable.length() - 1; - for (int oldIndex = 0; oldIndex < oldCapacity; oldIndex++) { - // We need to guarantee that any existing reads of old Map can - // proceed. So we cannot yet null out each bin. - E head = oldTable.get(oldIndex); - - if (head != null) { - E next = s.getNext(head); - int headIndex = s.getHash(head) & newMask; - - // Single node on list - if (next == null) { - newTable.set(headIndex, head); - } else { - // Reuse the consecutive sequence of nodes with the same target - // index from the end of the list. tail points to the first - // entry in the reusable list. - E tail = head; - int tailIndex = headIndex; - for (E last = next; last != null; last = s.getNext(last)) { - int newIndex = s.getHash(last) & newMask; - if (newIndex != tailIndex) { - // The index changed. We'll need to copy the previous entry. - tailIndex = newIndex; - tail = last; - } - } - newTable.set(tailIndex, tail); - - // Clone nodes leading up to the tail. - for (E e = head; e != tail; e = s.getNext(e)) { - K key = s.getKey(e); - if (key != null) { - int newIndex = s.getHash(e) & newMask; - E newNext = newTable.get(newIndex); - newTable.set(newIndex, s.copyEntry(key, e, newNext)); - } else { - // Key was reclaimed. Skip entry. - } - } - } - } - } - table = newTable; - } - - V remove(Object key, int hash) { - Strategy s = Impl.this.strategy; - lock(); - try { - int count = this.count - 1; - AtomicReferenceArray table = this.table; - int index = hash & (table.length() - 1); - E first = table.get(index); - - for (E e = first; e != null; e = s.getNext(e)) { - K entryKey = s.getKey(e); - if (s.getHash(e) == hash && entryKey != null - && s.equalKeys(entryKey, key)) { - V entryValue = strategy.getValue(e); - // All entries following removed node can stay - // in list, but all preceding ones need to be - // cloned. - ++modCount; - E newFirst = s.getNext(e); - for (E p = first; p != e; p = s.getNext(p)) { - K pKey = s.getKey(p); - if (pKey != null) { - newFirst = s.copyEntry(pKey, p, newFirst); - } else { - // Key was reclaimed. Skip entry. - } - } - table.set(index, newFirst); - this.count = count; // write-volatile - return entryValue; - } - } - - return null; - } finally { - unlock(); - } - } - - boolean remove(Object key, int hash, Object value) { - Strategy s = Impl.this.strategy; - lock(); - try { - int count = this.count - 1; - AtomicReferenceArray table = this.table; - int index = hash & (table.length() - 1); - E first = table.get(index); - - for (E e = first; e != null; e = s.getNext(e)) { - K entryKey = s.getKey(e); - if (s.getHash(e) == hash && entryKey != null - && s.equalKeys(entryKey, key)) { - V entryValue = strategy.getValue(e); - if (value == entryValue || (value != null && entryValue != null - && s.equalValues(entryValue, value))) { - // All entries following removed node can stay - // in list, but all preceding ones need to be - // cloned. - ++modCount; - E newFirst = s.getNext(e); - for (E p = first; p != e; p = s.getNext(p)) { - K pKey = s.getKey(p); - if (pKey != null) { - newFirst = s.copyEntry(pKey, p, newFirst); - } else { - // Key was reclaimed. Skip entry. - } - } - table.set(index, newFirst); - this.count = count; // write-volatile - return true; - } else { - return false; - } - } - } - - return false; - } finally { - unlock(); - } - } - - public boolean removeEntry(E entry, int hash, V value) { - Strategy s = Impl.this.strategy; - lock(); - try { - int count = this.count - 1; - AtomicReferenceArray table = this.table; - int index = hash & (table.length() - 1); - E first = table.get(index); - - for (E e = first; e != null; e = s.getNext(e)) { - if (s.getHash(e) == hash && entry.equals(e)) { - V entryValue = s.getValue(e); - if (entryValue == value || (value != null - && s.equalValues(entryValue, value))) { - // All entries following removed node can stay - // in list, but all preceding ones need to be - // cloned. - ++modCount; - E newFirst = s.getNext(e); - for (E p = first; p != e; p = s.getNext(p)) { - K pKey = s.getKey(p); - if (pKey != null) { - newFirst = s.copyEntry(pKey, p, newFirst); - } else { - // Key was reclaimed. Skip entry. - } - } - table.set(index, newFirst); - this.count = count; // write-volatile - return true; - } else { - return false; - } - } - } - - return false; - } finally { - unlock(); - } - } - - public boolean removeEntry(E entry, int hash) { - Strategy s = Impl.this.strategy; - lock(); - try { - int count = this.count - 1; - AtomicReferenceArray table = this.table; - int index = hash & (table.length() - 1); - E first = table.get(index); - - for (E e = first; e != null; e = s.getNext(e)) { - if (s.getHash(e) == hash && entry.equals(e)) { - // All entries following removed node can stay - // in list, but all preceding ones need to be - // cloned. - ++modCount; - E newFirst = s.getNext(e); - for (E p = first; p != e; p = s.getNext(p)) { - K pKey = s.getKey(p); - if (pKey != null) { - newFirst = s.copyEntry(pKey, p, newFirst); - } else { - // Key was reclaimed. Skip entry. - } - } - table.set(index, newFirst); - this.count = count; // write-volatile - return true; - } - } - - return false; - } finally { - unlock(); - } - } - - void clear() { - if (count != 0) { - lock(); - try { - AtomicReferenceArray table = this.table; - for (int i = 0; i < table.length(); i++) { - table.set(i, null); - } - ++modCount; - count = 0; // write-volatile - } finally { - unlock(); - } - } - } - } - - /* ---------------- Public operations -------------- */ - - /** - * Returns {@code true} if this map contains no key-value mappings. - * - * @return {@code true} if this map contains no key-value mappings - */ - @Override public boolean isEmpty() { - final Segment[] segments = this.segments; - /* - * We keep track of per-segment modCounts to avoid ABA - * problems in which an element in one segment was added and - * in another removed during traversal, in which case the - * table was never actually empty at any point. Note the - * similar use of modCounts in the size() and containsValue() - * methods, which are the only other methods also susceptible - * to ABA problems. - */ - int[] mc = new int[segments.length]; - int mcsum = 0; - for (int i = 0; i < segments.length; ++i) { - if (segments[i].count != 0) { - return false; - } else { - mcsum += mc[i] = segments[i].modCount; - } - } - // If mcsum happens to be zero, then we know we got a snapshot - // before any modifications at all were made. This is - // probably common enough to bother tracking. - if (mcsum != 0) { - for (int i = 0; i < segments.length; ++i) { - if (segments[i].count != 0 || - mc[i] != segments[i].modCount) { - return false; - } - } - } - return true; - } - - /** - * Returns the number of key-value mappings in this map. If the map - * contains more than {@code Integer.MAX_VALUE} elements, returns - * {@code Integer.MAX_VALUE}. - * - * @return the number of key-value mappings in this map - */ - @Override public int size() { - final Segment[] segments = this.segments; - long sum = 0; - long check = 0; - int[] mc = new int[segments.length]; - // Try a few times to get accurate count. On failure due to - // continuous async changes in table, resort to locking. - for (int k = 0; k < RETRIES_BEFORE_LOCK; ++k) { - check = 0; - sum = 0; - int mcsum = 0; - for (int i = 0; i < segments.length; ++i) { - sum += segments[i].count; - mcsum += mc[i] = segments[i].modCount; - } - if (mcsum != 0) { - for (int i = 0; i < segments.length; ++i) { - check += segments[i].count; - if (mc[i] != segments[i].modCount) { - check = -1; // force retry - break; - } - } - } - if (check == sum) { - break; - } - } - if (check != sum) { // Resort to locking all segments - sum = 0; - for (Segment segment : segments) { - segment.lock(); - } - for (Segment segment : segments) { - sum += segment.count; - } - for (Segment segment : segments) { - segment.unlock(); - } - } - if (sum > Integer.MAX_VALUE) { - return Integer.MAX_VALUE; - } else { - return (int) sum; - } - } - - /** - * 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.equals(k)}, then this method - * returns {@code v}; otherwise it returns {@code null}. (There can be at - * most one such mapping.) - * - * @throws NullPointerException if the specified key is null - */ - @Override public V get(Object key) { - if (key == null) { - throw new NullPointerException("key"); - } - int hash = hash(key); - return segmentFor(hash).get(key, hash); - } - - /** - * Tests if the specified object is a key in this table. - * - * @param key possible key - * @return {@code true} if and only if the specified object is a key in - * this table, as determined by the {@code equals} method; - * {@code false} otherwise. - * @throws NullPointerException if the specified key is null - */ - @Override public boolean containsKey(Object key) { - if (key == null) { - throw new NullPointerException("key"); - } - int hash = hash(key); - return segmentFor(hash).containsKey(key, hash); - } - - /** - * Returns {@code true} if this map maps one or more keys to the specified - * value. Note: This method requires a full internal traversal of the hash - * table, and so is much slower than method {@code containsKey}. - * - * @param value value whose presence in this map is to be tested - * @return {@code true} if this map maps one or more keys to the specified - * value - * @throws NullPointerException if the specified value is null - */ - @Override public boolean containsValue(Object value) { - if (value == null) { - throw new NullPointerException("value"); - } - - // See explanation of modCount use above - - final Segment[] segments = this.segments; - int[] mc = new int[segments.length]; - - // Try a few times without locking - for (int k = 0; k < RETRIES_BEFORE_LOCK; ++k) { - int mcsum = 0; - for (int i = 0; i < segments.length; ++i) { - @SuppressWarnings("UnusedDeclaration") - int c = segments[i].count; - mcsum += mc[i] = segments[i].modCount; - if (segments[i].containsValue(value)) { - return true; - } - } - boolean cleanSweep = true; - if (mcsum != 0) { - for (int i = 0; i < segments.length; ++i) { - @SuppressWarnings("UnusedDeclaration") - int c = segments[i].count; - if (mc[i] != segments[i].modCount) { - cleanSweep = false; - break; - } - } - } - if (cleanSweep) { - return false; - } - } - // Resort to locking all segments - for (Segment segment : segments) { - segment.lock(); - } - boolean found = false; - try { - for (Segment segment : segments) { - if (segment.containsValue(value)) { - found = true; - break; - } - } - } finally { - for (Segment segment : segments) { - segment.unlock(); - } - } - return found; - } - - /** - * Maps the specified key to the specified value in this table. Neither the - * key nor the value can be null. - * - *

The value can be retrieved by calling the {@code get} method with a - * key that is equal to the original key. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return the previous value associated with {@code key}, or {@code null} - * if there was no mapping for {@code key} - * @throws NullPointerException if the specified key or value is null - */ - @Override public V put(K key, V value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } - int hash = hash(key); - return segmentFor(hash).put(key, hash, value, false); - } - - /** - * {@inheritDoc} - * - * @return the previous value associated with the specified key, or - * {@code null} if there was no mapping for the key - * @throws NullPointerException if the specified key or value is null - */ - public V putIfAbsent(K key, V value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } - int hash = hash(key); - return segmentFor(hash).put(key, hash, value, true); - } - - /** - * Copies all of the mappings from the specified map to this one. These - * mappings replace any mappings that this map had for any of the keys - * currently in the specified map. - * - * @param m mappings to be stored in this map - */ - @Override public void putAll(Map m) { - for (Entry e : m.entrySet()) { - put(e.getKey(), e.getValue()); - } - } - - /** - * Removes the key (and its corresponding value) from this map. This method - * does nothing if the key is not in the map. - * - * @param key the key that needs to be removed - * @return the previous value associated with {@code key}, or {@code null} - * if there was no mapping for {@code key} - * @throws NullPointerException if the specified key is null - */ - @Override public V remove(Object key) { - if (key == null) { - throw new NullPointerException("key"); - } - int hash = hash(key); - return segmentFor(hash).remove(key, hash); - } - - /** - * {@inheritDoc} - * - * @throws NullPointerException if the specified key is null - */ - public boolean remove(Object key, Object value) { - if (key == null) { - throw new NullPointerException("key"); - } - int hash = hash(key); - return segmentFor(hash).remove(key, hash, value); - } - - /** - * {@inheritDoc} - * - * @throws NullPointerException if any of the arguments are null - */ - public boolean replace(K key, V oldValue, V newValue) { - if (key == null) { - throw new NullPointerException("key"); - } - if (oldValue == null) { - throw new NullPointerException("oldValue"); - } - if (newValue == null) { - throw new NullPointerException("newValue"); - } - int hash = hash(key); - return segmentFor(hash).replace(key, hash, oldValue, newValue); - } - - /** - * {@inheritDoc} - * - * @return the previous value associated with the specified key, or - * {@code null} if there was no mapping for the key - * @throws NullPointerException if the specified key or value is null - */ - public V replace(K key, V value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } - int hash = hash(key); - return segmentFor(hash).replace(key, hash, value); - } - - /** - * Removes all of the mappings from this map. - */ - @Override public void clear() { - for (Segment segment : segments) { - segment.clear(); - } - } - - Set keySet; - - /** - * Returns a {@link java.util.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. The set supports element removal, which removes the - * corresponding mapping from this map, via the {@code Iterator.remove}, - * {@code Set.remove}, {@code removeAll}, {@code retainAll}, and - * {@code clear} operations. It does not support the {@code add} or - * {@code addAll} operations. - * - *

The view's {@code iterator} is a "weakly consistent" iterator that - * will never throw {@link java.util.ConcurrentModificationException}, and - * guarantees to traverse elements as they existed upon construction of the - * iterator, and may (but is not guaranteed to) reflect any modifications - * subsequent to construction. - */ - @Override public Set keySet() { - Set ks = keySet; - return (ks != null) ? ks : (keySet = new KeySet()); - } - - Collection values; - - /** - * Returns a {@link java.util.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. The collection supports - * element removal, which removes the corresponding mapping from this map, - * via the {@code Iterator.remove}, {@code Collection.remove}, - * {@code removeAll}, {@code retainAll}, and {@code clear} operations. It - * does not support the {@code add} or {@code addAll} operations. - * - *

The view's {@code iterator} is a "weakly consistent" iterator that - * will never throw {@link java.util.ConcurrentModificationException}, and - * guarantees to traverse elements as they existed upon construction of the - * iterator, and may (but is not guaranteed to) reflect any modifications - * subsequent to construction. - */ - @Override public Collection values() { - Collection vs = values; - return (vs != null) ? vs : (values = new Values()); - } - - Set> entrySet; - - /** - * Returns a {@link java.util.Set} view of the mappings contained in this - * map. The set is backed by the map, so changes to the map are reflected in - * the set, and vice-versa. The set supports element removal, which removes - * the corresponding mapping from the map, via the {@code Iterator.remove}, - * {@code Set.remove}, {@code removeAll}, {@code retainAll}, and - * {@code clear} operations. It does not support the {@code add} or - * {@code addAll} operations. - * - *

The view's {@code iterator} is a "weakly consistent" iterator that - * will never throw {@link java.util.ConcurrentModificationException}, and - * guarantees to traverse elements as they existed upon construction of the - * iterator, and may (but is not guaranteed to) reflect any modifications - * subsequent to construction. - */ - @Override public Set> entrySet() { - Set> es = entrySet; - return (es != null) ? es : (entrySet = new EntrySet()); - } - - /* ---------------- Iterator Support -------------- */ - - abstract class HashIterator { - - int nextSegmentIndex; - int nextTableIndex; - AtomicReferenceArray currentTable; - E nextEntry; - WriteThroughEntry nextExternal; - WriteThroughEntry lastReturned; - - HashIterator() { - nextSegmentIndex = segments.length - 1; - nextTableIndex = -1; - advance(); - } - - public boolean hasMoreElements() { - return hasNext(); - } - - final void advance() { - nextExternal = null; - - if (nextInChain()) { - return; - } - - if (nextInTable()) { - return; - } - - while (nextSegmentIndex >= 0) { - Segment seg = segments[nextSegmentIndex--]; - if (seg.count != 0) { - currentTable = seg.table; - nextTableIndex = currentTable.length() - 1; - if (nextInTable()) { - return; - } - } - } - } - - /** - * Finds the next entry in the current chain. Returns true if an entry - * was found. - */ - boolean nextInChain() { - Strategy s = Impl.this.strategy; - if (nextEntry != null) { - for (nextEntry = s.getNext(nextEntry); nextEntry != null; - nextEntry = s.getNext(nextEntry)) { - if (advanceTo(nextEntry)) { - return true; - } - } - } - return false; - } - - /** - * Finds the next entry in the current table. Returns true if an entry - * was found. - */ - boolean nextInTable() { - while (nextTableIndex >= 0) { - if ((nextEntry = currentTable.get(nextTableIndex--)) != null) { - if (advanceTo(nextEntry) || nextInChain()) { - return true; - } - } - } - return false; - } - - /** - * Advances to the given entry. Returns true if the entry was valid, - * false if it should be skipped. - */ - boolean advanceTo(E entry) { - Strategy s = Impl.this.strategy; - K key = s.getKey(entry); - V value = s.getValue(entry); - if (key != null && value != null) { - nextExternal = new WriteThroughEntry(key, value); - return true; - } else { - // Skip partially reclaimed entry. - return false; - } - } - - public boolean hasNext() { - return nextExternal != null; - } - - WriteThroughEntry nextEntry() { - if (nextExternal == null) { - throw new NoSuchElementException(); - } - lastReturned = nextExternal; - advance(); - return lastReturned; - } - - public void remove() { - if (lastReturned == null) { - throw new IllegalStateException(); - } - Impl.this.remove(lastReturned.getKey()); - lastReturned = null; - } - } - - final class KeyIterator extends HashIterator implements Iterator { - - public K next() { - return super.nextEntry().getKey(); - } - } - - final class ValueIterator extends HashIterator implements Iterator { - - public V next() { - return super.nextEntry().getValue(); - } - } - - /** - * Custom Entry class used by EntryIterator.next(), that relays setValue - * changes to the underlying map. - */ - final class WriteThroughEntry extends AbstractMapEntry { - final K key; - V value; - - WriteThroughEntry(K key, V value) { - this.key = key; - this.value = value; - } - - @Override public K getKey() { - return key; - } - - @Override public V getValue() { - return value; - } - - /** - * Set our entry's value and write through to the map. The value to - * return is somewhat arbitrary here. Since a WriteThroughEntry does not - * necessarily track asynchronous changes, the most recent "previous" - * value could be different from what we return (or could even have been - * removed in which case the put will re-establish). We do not and - * cannot guarantee more. - */ - @Override public V setValue(V value) { - if (value == null) { - throw new NullPointerException(); - } - V oldValue = Impl.this.put(getKey(), value); - this.value = value; - return oldValue; - } - } - - final class EntryIterator extends HashIterator - implements Iterator> { - - public Entry next() { - return nextEntry(); - } - } - - final class KeySet extends AbstractSet { - - @Override public Iterator iterator() { - return new KeyIterator(); - } - - @Override public int size() { - return Impl.this.size(); - } - - @Override public boolean isEmpty() { - return Impl.this.isEmpty(); - } - - @Override public boolean contains(Object o) { - return Impl.this.containsKey(o); - } - - @Override public boolean remove(Object o) { - return Impl.this.remove(o) != null; - } - - @Override public void clear() { - Impl.this.clear(); - } - } - - final class Values extends AbstractCollection { - - @Override public Iterator iterator() { - return new ValueIterator(); - } - - @Override public int size() { - return Impl.this.size(); - } - - @Override public boolean isEmpty() { - return Impl.this.isEmpty(); - } - - @Override public boolean contains(Object o) { - return Impl.this.containsValue(o); - } - - @Override public void clear() { - Impl.this.clear(); - } - } - - final class EntrySet extends AbstractSet> { - - @Override public Iterator> iterator() { - return new EntryIterator(); - } - - @Override public boolean contains(Object o) { - if (!(o instanceof Entry)) { - return false; - } - Entry e = (Entry) o; - Object key = e.getKey(); - if (key == null) { - return false; - } - V v = Impl.this.get(key); - - return v != null && strategy.equalValues(v, e.getValue()); - } - - @Override public boolean remove(Object o) { - if (!(o instanceof Entry)) { - return false; - } - Entry e = (Entry) o; - Object key = e.getKey(); - return key != null && Impl.this.remove(key, e.getValue()); - } - - @Override public int size() { - return Impl.this.size(); - } - - @Override public boolean isEmpty() { - return Impl.this.isEmpty(); - } - - @Override public void clear() { - Impl.this.clear(); - } - } - - /* ---------------- Serialization Support -------------- */ - - private static final long serialVersionUID = 1; - - private void writeObject(java.io.ObjectOutputStream out) - throws IOException { - out.writeInt(size()); - out.writeInt(segments.length); // concurrencyLevel - out.writeObject(strategy); - for (Entry entry : entrySet()) { - out.writeObject(entry.getKey()); - out.writeObject(entry.getValue()); - } - out.writeObject(null); // terminate entries - } - - /** - * Fields used during deserialization. We use a nested class so we don't - * load them until we need them. We need to use reflection to set final - * fields outside of the constructor. - */ - static class Fields { - - static final Field segmentShift = findField("segmentShift"); - static final Field segmentMask = findField("segmentMask"); - static final Field segments = findField("segments"); - static final Field strategy = findField("strategy"); - - static Field findField(String name) { - try { - Field f = Impl.class.getDeclaredField(name); - f.setAccessible(true); - return f; - } catch (NoSuchFieldException e) { - throw new AssertionError(e); - } - } - } - - @SuppressWarnings("unchecked") - private void readObject(java.io.ObjectInputStream in) - throws IOException, ClassNotFoundException { - try { - int initialCapacity = in.readInt(); - int concurrencyLevel = in.readInt(); - Strategy strategy = (Strategy) in.readObject(); - - if (concurrencyLevel > MAX_SEGMENTS) { - concurrencyLevel = MAX_SEGMENTS; - } - - // Find power-of-two sizes best matching arguments - int segmentShift = 0; - int segmentCount = 1; - while (segmentCount < concurrencyLevel) { - ++segmentShift; - segmentCount <<= 1; - } - Fields.segmentShift.set(this, 32 - segmentShift); - Fields.segmentMask.set(this, segmentCount - 1); - Fields.segments.set(this, newSegmentArray(segmentCount)); - - if (initialCapacity > MAXIMUM_CAPACITY) { - initialCapacity = MAXIMUM_CAPACITY; - } - - int segmentCapacity = initialCapacity / segmentCount; - if (segmentCapacity * segmentCount < initialCapacity) { - ++segmentCapacity; - } - - int segmentSize = 1; - while (segmentSize < segmentCapacity) { - segmentSize <<= 1; - } - for (int i = 0; i < this.segments.length; ++i) { - this.segments[i] = new Segment(segmentSize); - } - - Fields.strategy.set(this, strategy); - - while (true) { - K key = (K) in.readObject(); - if (key == null) { - break; // terminator - } - V value = (V) in.readObject(); - put(key, value); - } - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } - } - } - - static class ComputingImpl extends Impl { - - static final long serialVersionUID = 0; - - final ComputingStrategy computingStrategy; - final Function computer; - - /** - * Creates a new, empty map with the specified strategy, initial capacity, - * load factor and concurrency level. - */ - ComputingImpl(ComputingStrategy strategy, Builder builder, - Function computer) { - super(strategy, builder); - this.computingStrategy = strategy; - this.computer = computer; - } - - @Override public V get(Object k) { - /* - * This cast isn't safe, but we can rely on the fact that K is almost - * always passed to Map.get(), and tools like IDEs and Findbugs can - * catch situations where this isn't the case. - * - * The alternative is to add an overloaded method, but the chances of - * a user calling get() instead of the new API and the risks inherent - * in adding a new API outweigh this little hole. - */ - @SuppressWarnings("unchecked") - K key = (K) k; - - if (key == null) { - throw new NullPointerException("key"); - } - - int hash = hash(key); - Segment segment = segmentFor(hash); - outer: while (true) { - E entry = segment.getEntry(key, hash); - if (entry == null) { - boolean created = false; - segment.lock(); - try { - // Try again--an entry could have materialized in the interim. - entry = segment.getEntry(key, hash); - if (entry == null) { - // Create a new entry. - created = true; - int count = segment.count; - if (count++ > segment.threshold) { // ensure capacity - segment.expand(); - } - AtomicReferenceArray table = segment.table; - int index = hash & (table.length() - 1); - E first = table.get(index); - ++segment.modCount; - entry = computingStrategy.newEntry(key, hash, first); - table.set(index, entry); - segment.count = count; // write-volatile - } - } finally { - segment.unlock(); - } - - if (created) { - // This thread solely created the entry. - boolean success = false; - try { - V value = computingStrategy.compute(key, entry, computer); - if (value == null) { - throw new NullPointerException( - "compute() returned null unexpectedly"); - } - success = true; - return value; - } finally { - if (!success) { - segment.removeEntry(entry, hash); - } - } - } - } - - // The entry already exists. Wait for the computation. - boolean interrupted = false; - try { - while (true) { - try { - V value = computingStrategy.waitForValue(entry); - if (value == null) { - // Purge entry and try again. - segment.removeEntry(entry, hash); - continue outer; - } - return value; - } catch (InterruptedException e) { - interrupted = true; - } - } - } finally { - if (interrupted) { - Thread.currentThread().interrupt(); - } - } - } - } - } - - /** - * A basic, no-frills implementation of {@code Strategy} using {@link - * SimpleInternalEntry}. Intended to be subclassed to provide customized - * behavior. For example, the following creates a map that uses byte arrays as - * keys:

   {@code
-   *
-   *   return new CustomConcurrentHashMap.Builder().buildMap(
-   *       new SimpleStrategy() {
-   *         public int hashKey(Object key) {
-   *           return Arrays.hashCode((byte[]) key);
-   *         }
-   *         public boolean equalKeys(byte[] a, Object b) {
-   *           return Arrays.equals(a, (byte[]) b);
-   *         }
-   *       });}
- * - * With nothing overridden, it yields map behavior equivalent to that of - * {@link ConcurrentHashMap}. - */ - static class SimpleStrategy - implements Strategy> { - public SimpleInternalEntry newEntry( - K key, int hash, SimpleInternalEntry next) { - return new SimpleInternalEntry(key, hash, null, next); - } - public SimpleInternalEntry copyEntry(K key, - SimpleInternalEntry original, SimpleInternalEntry next) { - return new SimpleInternalEntry( - key, original.hash, original.value, next); - } - public void setValue(SimpleInternalEntry entry, V value) { - entry.value = value; - } - public V getValue(SimpleInternalEntry entry) { - return entry.value; - } - public boolean equalKeys(K a, Object b) { - return a.equals(b); - } - public boolean equalValues(V a, Object b) { - return a.equals(b); - } - public int hashKey(Object key) { - return key.hashCode(); - } - public K getKey(SimpleInternalEntry entry) { - return entry.key; - } - public SimpleInternalEntry getNext(SimpleInternalEntry entry) { - return entry.next; - } - public int getHash(SimpleInternalEntry entry) { - return entry.hash; - } - public void setInternals( - Internals> internals) { - // ignore? - } - } - - /** - * A basic, no-frills entry class used by {@link SimpleInternalEntry}. - */ - static class SimpleInternalEntry { - final K key; - final int hash; - final SimpleInternalEntry next; - volatile V value; - SimpleInternalEntry( - K key, int hash, @Nullable V value, SimpleInternalEntry next) { - this.key = key; - this.hash = hash; - this.value = value; - this.next = next; - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableList.java deleted file mode 100644 index 536ad7aa7a5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableList.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * An empty immutable list. - * - * @author Kevin Bourrillion - */ -@GwtCompatible(serializable = true) -final class EmptyImmutableList extends ImmutableList { - static final EmptyImmutableList INSTANCE = new EmptyImmutableList(); - - private EmptyImmutableList() {} - - public int size() { - return 0; - } - - @Override public boolean isEmpty() { - return true; - } - - @Override public boolean contains(Object target) { - return false; - } - - @Override public UnmodifiableIterator iterator() { - return Iterators.emptyIterator(); - } - - private static final Object[] EMPTY_ARRAY = new Object[0]; - - @Override public Object[] toArray() { - return EMPTY_ARRAY; - } - - @Override public T[] toArray(T[] a) { - if (a.length > 0) { - a[0] = null; - } - return a; - } - - public Object get(int index) { - // guaranteed to fail, but at least we get a consistent message - checkElementIndex(index, 0); - throw new AssertionError("unreachable"); - } - - @Override public int indexOf(Object target) { - return -1; - } - - @Override public int lastIndexOf(Object target) { - return -1; - } - - @Override public ImmutableList subList(int fromIndex, int toIndex) { - checkPositionIndexes(fromIndex, toIndex, 0); - return this; - } - - public ListIterator listIterator() { - return Collections.emptyList().listIterator(); - } - - public ListIterator listIterator(int start) { - checkPositionIndex(start, 0); - return Collections.emptyList().listIterator(); - } - - @Override public boolean containsAll(Collection targets) { - return targets.isEmpty(); - } - - @Override public boolean equals(@Nullable Object object) { - if (object instanceof List) { - List that = (List) object; - return that.isEmpty(); - } - return false; - } - - @Override public int hashCode() { - return 1; - } - - @Override public String toString() { - return "[]"; - } - - Object readResolve() { - return INSTANCE; // preserve singleton property - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableListMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableListMultimap.java deleted file mode 100644 index 15fee296e82..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableListMultimap.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -/** - * Implementation of {@link ImmutableListMultimap} with no entries. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -class EmptyImmutableListMultimap extends ImmutableListMultimap { - static final EmptyImmutableListMultimap INSTANCE - = new EmptyImmutableListMultimap(); - - private EmptyImmutableListMultimap() { - super(ImmutableMap.>of(), 0); - } - - private Object readResolve() { - return INSTANCE; // preserve singleton property - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableMap.java deleted file mode 100644 index e26ab34acc4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableMap.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Map; - -/** - * An empty immutable map. - * - * @author Jesse Wilson - * @author Kevin Bourrillion - */ -@GwtCompatible(serializable = true) -final class EmptyImmutableMap extends ImmutableMap { - static final EmptyImmutableMap INSTANCE = new EmptyImmutableMap(); - - private EmptyImmutableMap() {} - - @Override public Object get(Object key) { - return null; - } - - public int size() { - return 0; - } - - @Override public boolean isEmpty() { - return true; - } - - @Override public boolean containsKey(Object key) { - return false; - } - - @Override public boolean containsValue(Object value) { - return false; - } - - @Override public ImmutableSet> entrySet() { - return ImmutableSet.of(); - } - - @Override public ImmutableSet keySet() { - return ImmutableSet.of(); - } - - @Override public ImmutableCollection values() { - return ImmutableCollection.EMPTY_IMMUTABLE_COLLECTION; - } - - @Override public boolean equals(@Nullable Object object) { - if (object instanceof Map) { - Map that = (Map) object; - return that.isEmpty(); - } - return false; - } - - @Override public int hashCode() { - return 0; - } - - @Override public String toString() { - return "{}"; - } - - Object readResolve() { - return INSTANCE; // preserve singleton property - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableMultiset.java deleted file mode 100644 index a97f5241a8c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableMultiset.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -/** - * An empty immutable multiset. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -final class EmptyImmutableMultiset extends ImmutableMultiset { - static final EmptyImmutableMultiset INSTANCE = new EmptyImmutableMultiset(); - - private EmptyImmutableMultiset() { - super(ImmutableMap.of(), 0); - } - - Object readResolve() { - return INSTANCE; // preserve singleton property - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSet.java deleted file mode 100644 index 02b3519b108..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSet.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Set; - -/** - * An empty immutable set. - * - * @author Kevin Bourrillion - */ -@GwtCompatible(serializable = true) -final class EmptyImmutableSet extends ImmutableSet { - static final EmptyImmutableSet INSTANCE = new EmptyImmutableSet(); - - private EmptyImmutableSet() {} - - public int size() { - return 0; - } - - @Override public boolean isEmpty() { - return true; - } - - @Override public boolean contains(Object target) { - return false; - } - - @Override public UnmodifiableIterator iterator() { - return Iterators.emptyIterator(); - } - - private static final Object[] EMPTY_ARRAY = new Object[0]; - - @Override public Object[] toArray() { - return EMPTY_ARRAY; - } - - @Override public T[] toArray(T[] a) { - if (a.length > 0) { - a[0] = null; - } - return a; - } - - @Override public boolean containsAll(Collection targets) { - return targets.isEmpty(); - } - - @Override public boolean equals(@Nullable Object object) { - if (object instanceof Set) { - Set that = (Set) object; - return that.isEmpty(); - } - return false; - } - - @Override public final int hashCode() { - return 0; - } - - @Override boolean isHashCodeFast() { - return true; - } - - @Override public String toString() { - return "[]"; - } - - Object readResolve() { - return INSTANCE; // preserve singleton property - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSetMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSetMultimap.java deleted file mode 100644 index 1b70aab704b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSetMultimap.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -/** - * Implementation of {@link ImmutableListMultimap} with no entries. - * - * @author Mike Ward - */ -@GwtCompatible(serializable = true) -class EmptyImmutableSetMultimap extends ImmutableSetMultimap { - static final EmptyImmutableSetMultimap INSTANCE - = new EmptyImmutableSetMultimap(); - - private EmptyImmutableSetMultimap() { - super(ImmutableMap.>of(), 0); - } - - private Object readResolve() { - return INSTANCE; // preserve singleton property - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSortedSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSortedSet.java deleted file mode 100644 index a1b3217f96d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EmptyImmutableSortedSet.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Comparator; -import java.util.NoSuchElementException; -import java.util.Set; - -/** - * An empty immutable sorted set. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // uses writeReplace(), not default serialization -class EmptyImmutableSortedSet extends ImmutableSortedSet { - EmptyImmutableSortedSet(Comparator comparator) { - super(comparator); - } - - public int size() { - return 0; - } - - @Override public boolean isEmpty() { - return true; - } - - @Override public boolean contains(Object target) { - return false; - } - - @Override public UnmodifiableIterator iterator() { - return Iterators.emptyIterator(); - } - - private static final Object[] EMPTY_ARRAY = new Object[0]; - - @Override public Object[] toArray() { - return EMPTY_ARRAY; - } - - @Override public T[] toArray(T[] a) { - if (a.length > 0) { - a[0] = null; - } - return a; - } - - @Override public boolean containsAll(Collection targets) { - return targets.isEmpty(); - } - - @Override public boolean equals(@Nullable Object object) { - if (object instanceof Set) { - Set that = (Set) object; - return that.isEmpty(); - } - return false; - } - - @Override public int hashCode() { - return 0; - } - - @Override public String toString() { - return "[]"; - } - - public E first() { - throw new NoSuchElementException(); - } - - public E last() { - throw new NoSuchElementException(); - } - - @Override ImmutableSortedSet headSetImpl(E toElement) { - return this; - } - - @Override ImmutableSortedSet subSetImpl(E fromElement, E toElement) { - return this; - } - - @Override ImmutableSortedSet tailSetImpl(E fromElement) { - return this; - } - - @Override boolean hasPartialArray() { - return false; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumBiMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumBiMap.java deleted file mode 100644 index 6476b17bdec..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumBiMap.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.EnumMap; -import java.util.Map; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * A {@code BiMap} backed by two {@code EnumMap} instances. Null keys and values - * are not permitted. An {@code EnumBiMap} and its inverse are both - * serializable. - * - * @author Mike Bostock - */ -public final class EnumBiMap, V extends Enum> - extends AbstractBiMap { - private transient Class keyType; - private transient Class valueType; - - /** - * Returns a new, empty {@code EnumBiMap} using the specified key and value - * types. - * - * @param keyType the key type - * @param valueType the value type - */ - public static , V extends Enum> EnumBiMap - create(Class keyType, Class valueType) { - return new EnumBiMap(keyType, valueType); - } - - /** - * Returns a new bimap with the same mappings as the specified map. If the - * specified map is an {@code EnumBiMap}, the new bimap has the same types as - * the provided map. Otherwise, the specified map must contain at least one - * mapping, in order to determine the key and value types. - * - * @param map the map whose mappings are to be placed in this map - * @throws IllegalArgumentException if map is not an {@code EnumBiMap} - * instance and contains no mappings - */ - public static , V extends Enum> EnumBiMap - create(Map map) { - EnumBiMap bimap = create(inferKeyType(map), inferValueType(map)); - bimap.putAll(map); - return bimap; - } - - private EnumBiMap(Class keyType, Class valueType) { - super(new EnumMap(keyType), new EnumMap(valueType)); - this.keyType = keyType; - this.valueType = valueType; - } - - static > Class inferKeyType(Map map) { - if (map instanceof EnumBiMap) { - return ((EnumBiMap) map).keyType(); - } - if (map instanceof EnumHashBiMap) { - return ((EnumHashBiMap) map).keyType(); - } - checkArgument(!map.isEmpty()); - return map.keySet().iterator().next().getDeclaringClass(); - } - - private static > Class inferValueType(Map map) { - if (map instanceof EnumBiMap) { - return ((EnumBiMap) map).valueType; - } - checkArgument(!map.isEmpty()); - return map.values().iterator().next().getDeclaringClass(); - } - - /** Returns the associated key type. */ - public Class keyType() { - return keyType; - } - - /** Returns the associated value type. */ - public Class valueType() { - return valueType; - } - - /** - * @serialData the key class, value class, number of entries, first key, first - * value, second key, second value, and so on. - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(keyType); - stream.writeObject(valueType); - Serialization.writeMap(this, stream); - } - - @SuppressWarnings("unchecked") // reading fields populated by writeObject - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - keyType = (Class) stream.readObject(); - valueType = (Class) stream.readObject(); - setDelegates(new EnumMap(keyType), new EnumMap(valueType)); - Serialization.populateMap(this, stream); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumHashBiMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumHashBiMap.java deleted file mode 100644 index dcb7175d43e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumHashBiMap.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.Map; - -/** - * A {@code BiMap} backed by an {@code EnumMap} instance for keys-to-values, and - * a {@code HashMap} instance for values-to-keys. Null keys are not permitted, - * but null values are. An {@code EnumHashBiMap} and its inverse are both - * serializable. - * - * @author Mike Bostock - */ -public final class EnumHashBiMap, V> - extends AbstractBiMap { - private transient Class keyType; - - /** - * Returns a new, empty {@code EnumHashBiMap} using the specified key type. - * - * @param keyType the key type - */ - public static , V> EnumHashBiMap - create(Class keyType) { - return new EnumHashBiMap(keyType); - } - - /** - * Constructs a new bimap with the same mappings as the specified map. If the - * specified map is an {@code EnumHashBiMap} or an {@link EnumBiMap}, the new - * bimap has the same key type as the input bimap. Otherwise, the specified - * map must contain at least one mapping, in order to determine the key type. - * - * @param map the map whose mappings are to be placed in this map - * @throws IllegalArgumentException if map is not an {@code EnumBiMap} or an - * {@code EnumHashBiMap} instance and contains no mappings - */ - public static , V> EnumHashBiMap - create(Map map) { - EnumHashBiMap bimap = create(EnumBiMap.inferKeyType(map)); - bimap.putAll(map); - return bimap; - } - - private EnumHashBiMap(Class keyType) { - super(new EnumMap(keyType), Maps.newHashMapWithExpectedSize( - keyType.getEnumConstants().length)); - this.keyType = keyType; - } - - // Overriding these two methods to show that values may be null (but not keys) - - @Override public V put(K key, @Nullable V value) { - return super.put(key, value); - } - - @Override public V forcePut(K key, @Nullable V value) { - return super.forcePut(key, value); - } - - /** Returns the associated key type. */ - public Class keyType() { - return keyType; - } - - /** - * @serialData the key class, number of entries, first key, first value, - * second key, second value, and so on. - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(keyType); - Serialization.writeMap(this, stream); - } - - @SuppressWarnings("unchecked") // reading field populated by writeObject - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - keyType = (Class) stream.readObject(); - setDelegates(new EnumMap(keyType), - new HashMap(keyType.getEnumConstants().length * 3 / 2)); - Serialization.populateMap(this, stream); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumMultiset.java deleted file mode 100644 index 3227c38041f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/EnumMultiset.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.EnumMap; -import java.util.Iterator; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Multiset implementation backed by an {@link EnumMap}. - * - * @author Jared Levy - */ -@GwtCompatible -public final class EnumMultiset> - extends AbstractMapBasedMultiset { - /** Creates an empty {@code EnumMultiset}. */ - public static > EnumMultiset create(Class type) { - return new EnumMultiset(type); - } - - /** - * Creates a new {@code EnumMultiset} containing the specified elements. - * - * @param elements the elements that the multiset should contain - * @throws IllegalArgumentException if {@code elements} is empty - */ - public static > EnumMultiset create( - Iterable elements) { - Iterator iterator = elements.iterator(); - checkArgument(iterator.hasNext(), - "EnumMultiset constructor passed empty Iterable"); - EnumMultiset multiset - = new EnumMultiset(iterator.next().getDeclaringClass()); - Iterables.addAll(multiset, elements); - return multiset; - } - - private transient Class type; - - /** Creates an empty {@code EnumMultiset}. */ - private EnumMultiset(Class type) { - super(new EnumMap(type)); - this.type = type; - } - - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(type); - Serialization.writeMultiset(this, stream); - } - - /** - * @serialData the {@code Class} for the enum type, the number of distinct - * elements, the first element, its count, the second element, its count, - * and so on - */ - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - @SuppressWarnings("unchecked") // reading data stored by writeObject - Class localType = (Class) stream.readObject(); - type = localType; - setBackingMap(new EnumMap(type)); - Serialization.populateMultiset(this, stream); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ExpirationTimer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ExpirationTimer.java deleted file mode 100644 index a4dc7d2d6dc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ExpirationTimer.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import java.util.Timer; - -/** - * Timer used for entry expiration in MapMaker. - */ -class ExpirationTimer { - static Timer instance = new Timer(true); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ExplicitOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ExplicitOrdering.java deleted file mode 100644 index 56b3aeeff35..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ExplicitOrdering.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.List; - -/** An ordering that compares objects according to a given order. */ -@GwtCompatible(serializable = true) -final class ExplicitOrdering extends Ordering implements Serializable { - final ImmutableMap rankMap; - - ExplicitOrdering(List valuesInOrder) { - this(buildRankMap(valuesInOrder)); - } - - ExplicitOrdering(ImmutableMap rankMap) { - this.rankMap = rankMap; - } - - public int compare(T left, T right) { - return rank(left) - rank(right); // safe because both are nonnegative - } - - private int rank(T value) { - Integer rank = rankMap.get(value); - if (rank == null) { - throw new IncomparableValueException(value); - } - return rank; - } - - private static ImmutableMap buildRankMap( - List valuesInOrder) { - ImmutableMap.Builder builder = ImmutableMap.builder(); - int rank = 0; - for (T value : valuesInOrder) { - builder.put(value, rank++); - } - return builder.build(); - } - - @Override public boolean equals(@Nullable Object object) { - if (object instanceof ExplicitOrdering) { - ExplicitOrdering that = (ExplicitOrdering) object; - return this.rankMap.equals(that.rankMap); - } - return false; - } - - @Override public int hashCode() { - return rankMap.hashCode(); - } - - @Override public String toString() { - return "Ordering.explicit(" + rankMap.keySet() + ")"; - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingCollection.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingCollection.java deleted file mode 100644 index 4219cb4a1e5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingCollection.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.Collection; -import java.util.Iterator; - -/** - * A collection which forwards all its method calls to another collection. - * Subclasses should override one or more methods to modify the behavior of - * the backing collection as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Kevin Bourrillion - */ -@GwtCompatible -public abstract class ForwardingCollection extends ForwardingObject - implements Collection { - - @Override protected abstract Collection delegate(); - - public Iterator iterator() { - return delegate().iterator(); - } - - public int size() { - return delegate().size(); - } - - public boolean removeAll(Collection collection) { - return delegate().removeAll(collection); - } - - public boolean isEmpty() { - return delegate().isEmpty(); - } - - public boolean contains(Object object) { - return delegate().contains(object); - } - - public Object[] toArray() { - return delegate().toArray(); - } - - public T[] toArray(T[] array) { - return delegate().toArray(array); - } - - public boolean add(E element) { - return delegate().add(element); - } - - public boolean remove(Object object) { - return delegate().remove(object); - } - - public boolean containsAll(Collection collection) { - return delegate().containsAll(collection); - } - - public boolean addAll(Collection collection) { - return delegate().addAll(collection); - } - - public boolean retainAll(Collection collection) { - return delegate().retainAll(collection); - } - - public void clear() { - delegate().clear(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingConcurrentMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingConcurrentMap.java deleted file mode 100644 index d78c43d970d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingConcurrentMap.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.concurrent.ConcurrentMap; - -/** - * A concurrent map which forwards all its method calls to another concurrent - * map. Subclasses should override one or more methods to modify the behavior of - * the backing map as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Charles Fry - */ -@GwtCompatible -public abstract class ForwardingConcurrentMap extends ForwardingMap - implements ConcurrentMap { - - @Override protected abstract ConcurrentMap delegate(); - - public V putIfAbsent(K key, V value) { - return delegate().putIfAbsent(key, value); - } - - public boolean remove(Object key, Object value) { - return delegate().remove(key, value); - } - - public V replace(K key, V value) { - return delegate().replace(key, value); - } - - public boolean replace(K key, V oldValue, V newValue) { - return delegate().replace(key, oldValue, newValue); - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingIterator.java deleted file mode 100644 index 63da0bd71fc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingIterator.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.Iterator; - -/** - * An iterator which forwards all its method calls to another iterator. - * Subclasses should override one or more methods to modify the behavior of the - * backing iterator as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Kevin Bourrillion - */ -@GwtCompatible -public abstract class ForwardingIterator - extends ForwardingObject implements Iterator { - - @Override protected abstract Iterator delegate(); - - public boolean hasNext() { - return delegate().hasNext(); - } - - public T next() { - return delegate().next(); - } - - public void remove() { - delegate().remove(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingList.java deleted file mode 100644 index 1f59895ce21..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingList.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.List; -import java.util.ListIterator; - -/** - * A list which forwards all its method calls to another list. Subclasses should - * override one or more methods to modify the behavior of the backing list as - * desired per the decorator pattern. - * - *

This class does not implement {@link java.util.RandomAccess}. If the - * delegate supports random access, the {@code ForwadingList} subclass should - * implement the {@code RandomAccess} interface. - * - * @author Mike Bostock - */ -@GwtCompatible -public abstract class ForwardingList extends ForwardingCollection - implements List { - - @Override protected abstract List delegate(); - - public void add(int index, E element) { - delegate().add(index, element); - } - - public boolean addAll(int index, Collection elements) { - return delegate().addAll(index, elements); - } - - public E get(int index) { - return delegate().get(index); - } - - public int indexOf(Object element) { - return delegate().indexOf(element); - } - - public int lastIndexOf(Object element) { - return delegate().lastIndexOf(element); - } - - public ListIterator listIterator() { - return delegate().listIterator(); - } - - public ListIterator listIterator(int index) { - return delegate().listIterator(index); - } - - public E remove(int index) { - return delegate().remove(index); - } - - public E set(int index, E element) { - return delegate().set(index, element); - } - - @GwtIncompatible("List.subList") - public List subList(int fromIndex, int toIndex) { - return Platform.subList(delegate(), fromIndex, toIndex); - } - - @Override public boolean equals(@Nullable Object object) { - return object == this || delegate().equals(object); - } - - @Override public int hashCode() { - return delegate().hashCode(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingListIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingListIterator.java deleted file mode 100644 index 0731a6e70e9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingListIterator.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.ListIterator; - -/** - * A list iterator which forwards all its method calls to another list - * iterator. Subclasses should override one or more methods to modify the - * behavior of the backing iterator as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Mike Bostock - */ -@GwtCompatible -public abstract class ForwardingListIterator extends ForwardingIterator - implements ListIterator { - - @Override protected abstract ListIterator delegate(); - - public void add(E element) { - delegate().add(element); - } - - public boolean hasPrevious() { - return delegate().hasPrevious(); - } - - public int nextIndex() { - return delegate().nextIndex(); - } - - public E previous() { - return delegate().previous(); - } - - public int previousIndex() { - return delegate().previousIndex(); - } - - public void set(E element) { - delegate().set(element); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMap.java deleted file mode 100644 index fdf7b563134..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMap.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -/** - * A map which forwards all its method calls to another map. Subclasses should - * override one or more methods to modify the behavior of the backing map as - * desired per the decorator pattern. - * - * @see ForwardingObject - * @author Kevin Bourrillion - * @author Jared Levy - */ -@GwtCompatible -public abstract class ForwardingMap extends ForwardingObject - implements Map { - - @Override protected abstract Map delegate(); - - public int size() { - return delegate().size(); - } - - public boolean isEmpty() { - return delegate().isEmpty(); - } - - public V remove(Object object) { - return delegate().remove(object); - } - - public void clear() { - delegate().clear(); - } - - public boolean containsKey(Object key) { - return delegate().containsKey(key); - } - - public boolean containsValue(Object value) { - return delegate().containsValue(value); - } - - public V get(Object key) { - return delegate().get(key); - } - - public V put(K key, V value) { - return delegate().put(key, value); - } - - public void putAll(Map map) { - delegate().putAll(map); - } - - public Set keySet() { - return delegate().keySet(); - } - - public Collection values() { - return delegate().values(); - } - - public Set> entrySet() { - return delegate().entrySet(); - } - - @Override public boolean equals(@Nullable Object object) { - return object == this || delegate().equals(object); - } - - @Override public int hashCode() { - return delegate().hashCode(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMapEntry.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMapEntry.java deleted file mode 100644 index 7f225775078..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMapEntry.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Map; - -/** - * A map entry which forwards all its method calls to another map entry. - * Subclasses should override one or more methods to modify the behavior of the - * backing map entry as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Mike Bostock - */ -@GwtCompatible -public abstract class ForwardingMapEntry - extends ForwardingObject implements Map.Entry { - - @Override protected abstract Map.Entry delegate(); - - public K getKey() { - return delegate().getKey(); - } - - public V getValue() { - return delegate().getValue(); - } - - public V setValue(V value) { - return delegate().setValue(value); - } - - @Override public boolean equals(@Nullable Object object) { - return delegate().equals(object); - } - - @Override public int hashCode() { - return delegate().hashCode(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMultimap.java deleted file mode 100644 index 98558cc4d3d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMultimap.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -/** - * A multimap which forwards all its method calls to another multimap. - * Subclasses should override one or more methods to modify the behavior of - * the backing multimap as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Robert Konigsberg - */ -@GwtCompatible -public abstract class ForwardingMultimap extends ForwardingObject - implements Multimap { - - @Override protected abstract Multimap delegate(); - - public Map> asMap() { - return delegate().asMap(); - } - - public void clear() { - delegate().clear(); - } - - public boolean containsEntry(@Nullable Object key, @Nullable Object value) { - return delegate().containsEntry(key, value); - } - - public boolean containsKey(@Nullable Object key) { - return delegate().containsKey(key); - } - - public boolean containsValue(@Nullable Object value) { - return delegate().containsValue(value); - } - - public Collection> entries() { - return delegate().entries(); - } - - public Collection get(@Nullable K key) { - return delegate().get(key); - } - - public boolean isEmpty() { - return delegate().isEmpty(); - } - - public Multiset keys() { - return delegate().keys(); - } - - public Set keySet() { - return delegate().keySet(); - } - - public boolean put(K key, V value) { - return delegate().put(key, value); - } - - public boolean putAll(K key, Iterable values) { - return delegate().putAll(key, values); - } - - public boolean putAll(Multimap multimap) { - return delegate().putAll(multimap); - } - - public boolean remove(@Nullable Object key, @Nullable Object value) { - return delegate().remove(key, value); - } - - public Collection removeAll(@Nullable Object key) { - return delegate().removeAll(key); - } - - public Collection replaceValues(K key, Iterable values) { - return delegate().replaceValues(key, values); - } - - public int size() { - return delegate().size(); - } - - public Collection values() { - return delegate().values(); - } - - @Override public boolean equals(@Nullable Object object) { - return object == this || delegate().equals(object); - } - - @Override public int hashCode() { - return delegate().hashCode(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMultiset.java deleted file mode 100644 index 154b6e1c82f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingMultiset.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Set; - -/** - * A multiset which forwards all its method calls to another multiset. - * Subclasses should override one or more methods to modify the behavior of the - * backing multiset as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Kevin Bourrillion - */ -@GwtCompatible -public abstract class ForwardingMultiset extends ForwardingCollection - implements Multiset { - - @Override protected abstract Multiset delegate(); - - public int count(Object element) { - return delegate().count(element); - } - - public int add(E element, int occurrences) { - return delegate().add(element, occurrences); - } - - public int remove(Object element, int occurrences) { - return delegate().remove(element, occurrences); - } - - public Set elementSet() { - return delegate().elementSet(); - } - - public Set> entrySet() { - return delegate().entrySet(); - } - - @Override public boolean equals(@Nullable Object object) { - return object == this || delegate().equals(object); - } - - @Override public int hashCode() { - return delegate().hashCode(); - } - - public int setCount(E element, int count) { - return delegate().setCount(element, count); - } - - public boolean setCount(E element, int oldCount, int newCount) { - return delegate().setCount(element, oldCount, newCount); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingObject.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingObject.java deleted file mode 100644 index a1f0a4d486a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingObject.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.Serializable; - -/** - * An abstract base class for implementing the decorator pattern. - * The {@link #delegate()} method must be overridden to return the instance - * being decorated. - * - * This class does not forward the {@code hashCode} and {@code equals} - * methods through to the backing object, but relies on {@code Object}'s - * implementation. This is necessary to preserve the symmetry of {@code equals}. - * Custom definitions of equality are usually based on an interface, such as - * {@code Set} or {@code List}, so that the implementation of {@code equals} can - * cast the object being tested for equality to the custom interface. {@code - * ForwardingObject} implements no such custom interfaces directly; they - * are implemented only in subclasses. Therefore, forwarding {@code equals} - * would break symmetry, as the forwarding object might consider itself equal to - * the object being tested, but the reverse could not be true. This behavior is - * consistent with the JDK's collection wrappers, such as - * {@link java.util.Collections#unmodifiableCollection}. Use an - * interface-specific subclass of {@code ForwardingObject}, such as {@link - * ForwardingList}, to preserve equality behavior, or override {@code equals} - * directly. - * - *

The {@code toString} method is forwarded to the delegate. Although this - * class does not implement {@link Serializable}, a serializable subclass may be - * created since this class has a parameter-less constructor. - * - * @author Mike Bostock - */ -@GwtCompatible -public abstract class ForwardingObject { - - /** Sole constructor. */ - protected ForwardingObject() {} - - /** - * Returns the backing delegate instance that methods are forwarded to. - * Abstract subclasses generally override this method with an abstract method - * that has a more specific return type, such as {@link - * ForwardingSet#delegate}. Concrete subclasses override this method to supply - * the instance being decorated. - */ - protected abstract Object delegate(); - - /** - * Returns the string representation generated by the delegate's - * {@code toString} method. - */ - @Override public String toString() { - return delegate().toString(); - } - - /* No equals or hashCode. See class comments for details. */ -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingQueue.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingQueue.java deleted file mode 100644 index 1048947d741..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingQueue.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.Queue; - -/** - * A queue which forwards all its method calls to another queue. Subclasses - * should override one or more methods to modify the behavior of the backing - * queue as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Mike Bostock - */ -@GwtCompatible -public abstract class ForwardingQueue extends ForwardingCollection - implements Queue { - - @Override protected abstract Queue delegate(); - - public boolean offer(E o) { - return delegate().offer(o); - } - - public E poll() { - return delegate().poll(); - } - - public E remove() { - return delegate().remove(); - } - - public E peek() { - return delegate().peek(); - } - - public E element() { - return delegate().element(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSet.java deleted file mode 100644 index 325db029cfa..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSet.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Set; - -/** - * A set which forwards all its method calls to another set. Subclasses should - * override one or more methods to modify the behavior of the backing set as - * desired per the decorator pattern. - * - * @see ForwardingObject - * @author Kevin Bourrillion - */ -@GwtCompatible -public abstract class ForwardingSet extends ForwardingCollection - implements Set { - - @Override protected abstract Set delegate(); - - @Override public boolean equals(@Nullable Object object) { - return object == this || delegate().equals(object); - } - - @Override public int hashCode() { - return delegate().hashCode(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSortedMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSortedMap.java deleted file mode 100644 index c8ddcb24042..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSortedMap.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.Comparator; -import java.util.SortedMap; - -/** - * A sorted map which forwards all its method calls to another sorted map. - * Subclasses should override one or more methods to modify the behavior of - * the backing sorted map as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Mike Bostock - */ -@GwtCompatible -public abstract class ForwardingSortedMap extends ForwardingMap - implements SortedMap { - - @Override protected abstract SortedMap delegate(); - - public Comparator comparator() { - return delegate().comparator(); - } - - public K firstKey() { - return delegate().firstKey(); - } - - public SortedMap headMap(K toKey) { - return delegate().headMap(toKey); - } - - public K lastKey() { - return delegate().lastKey(); - } - - public SortedMap subMap(K fromKey, K toKey) { - return delegate().subMap(fromKey, toKey); - } - - public SortedMap tailMap(K fromKey) { - return delegate().tailMap(fromKey); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSortedSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSortedSet.java deleted file mode 100644 index 3b492bac231..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ForwardingSortedSet.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.Comparator; -import java.util.SortedSet; - -/** - * A sorted set which forwards all its method calls to another sorted set. - * Subclasses should override one or more methods to modify the behavior of the - * backing sorted set as desired per the decorator pattern. - * - * @see ForwardingObject - * @author Mike Bostock - */ -@GwtCompatible -public abstract class ForwardingSortedSet extends ForwardingSet - implements SortedSet { - - @Override protected abstract SortedSet delegate(); - - public Comparator comparator() { - return delegate().comparator(); - } - - public E first() { - return delegate().first(); - } - - public SortedSet headSet(E toElement) { - return delegate().headSet(toElement); - } - - public E last() { - return delegate().last(); - } - - public SortedSet subSet(E fromElement, E toElement) { - return delegate().subSet(fromElement, toElement); - } - - public SortedSet tailSet(E fromElement) { - return delegate().tailSet(fromElement); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashBiMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashBiMap.java deleted file mode 100644 index e206a6fa860..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashBiMap.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.HashMap; -import java.util.Map; - -/** - * A {@link BiMap} backed by two {@link HashMap} instances. This implementation - * allows null keys and values. A {@code HashBiMap} and its inverse are both - * serializable. - * - * @author Mike Bostock - */ -@GwtCompatible -public final class HashBiMap extends AbstractBiMap { - - /** - * Returns a new, empty {@code HashBiMap} with the default initial capacity - * (16). - */ - public static HashBiMap create() { - return new HashBiMap(); - } - - /** - * Constructs a new, empty bimap with the specified expected size. - * - * @param expectedSize the expected number of entries - * @throws IllegalArgumentException if the specified expected size is - * negative - */ - public static HashBiMap create(int expectedSize) { - return new HashBiMap(expectedSize); - } - - /** - * Constructs a new bimap containing initial values from {@code map}. The - * bimap is created with an initial capacity sufficient to hold the mappings - * in the specified map. - */ - public static HashBiMap create( - Map map) { - HashBiMap bimap = create(map.size()); - bimap.putAll(map); - return bimap; - } - - private HashBiMap() { - super(new HashMap(), new HashMap()); - } - - private HashBiMap(int expectedSize) { - super(new HashMap(Maps.capacity(expectedSize)), - new HashMap(Maps.capacity(expectedSize))); - } - - // Override these two methods to show that keys and values may be null - - @Override public V put(@Nullable K key, @Nullable V value) { - return super.put(key, value); - } - - @Override public V forcePut(@Nullable K key, @Nullable V value) { - return super.forcePut(key, value); - } - - /** - * @serialData the number of entries, first key, first value, second key, - * second value, and so on. - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - Serialization.writeMap(this, stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - int size = Serialization.readCount(stream); - setDelegates(Maps.newHashMapWithExpectedSize(size), - Maps.newHashMapWithExpectedSize(size)); - Serialization.populateMap(this, stream, size); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashMultimap.java deleted file mode 100644 index 4c07401c11b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashMultimap.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.VisibleForTesting; -import org.elasticsearch.util.base.Preconditions; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** - * Implementation of {@link Multimap} using hash tables. - * - *

The multimap does not store duplicate key-value pairs. Adding a new - * key-value pair equal to an existing key-value pair has no effect. - * - *

Keys and values may be null. All optional multimap methods are supported, - * and all returned views are modifiable. - * - *

This class is not threadsafe when any concurrent operations update the - * multimap. Concurrent read operations will work correctly. To allow concurrent - * update operations, wrap your multimap with a call to {@link - * Multimaps#synchronizedSetMultimap}. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -public final class HashMultimap extends AbstractSetMultimap { - private static final int DEFAULT_VALUES_PER_KEY = 8; - - @VisibleForTesting - transient int expectedValuesPerKey = DEFAULT_VALUES_PER_KEY; - - /** - * Creates a new, empty {@code HashMultimap} with the default initial - * capacities. - */ - public static HashMultimap create() { - return new HashMultimap(); - } - - /** - * Constructs an empty {@code HashMultimap} with enough capacity to hold the - * specified numbers of keys and values without rehashing. - * - * @param expectedKeys the expected number of distinct keys - * @param expectedValuesPerKey the expected average number of values per key - * @throws IllegalArgumentException if {@code expectedKeys} or {@code - * expectedValuesPerKey} is negative - */ - public static HashMultimap create( - int expectedKeys, int expectedValuesPerKey) { - return new HashMultimap(expectedKeys, expectedValuesPerKey); - } - - /** - * Constructs a {@code HashMultimap} with the same mappings as the specified - * multimap. If a key-value mapping appears multiple times in the input - * multimap, it only appears once in the constructed multimap. - * - * @param multimap the multimap whose contents are copied to this multimap - */ - public static HashMultimap create( - Multimap multimap) { - return new HashMultimap(multimap); - } - - private HashMultimap() { - super(new HashMap>()); - } - - private HashMultimap(int expectedKeys, int expectedValuesPerKey) { - super(Maps.>newHashMapWithExpectedSize(expectedKeys)); - Preconditions.checkArgument(expectedValuesPerKey >= 0); - this.expectedValuesPerKey = expectedValuesPerKey; - } - - private HashMultimap(Multimap multimap) { - super(Maps.>newHashMapWithExpectedSize( - multimap.keySet().size())); - putAll(multimap); - } - - /** - * {@inheritDoc} - * - *

Creates an empty {@code HashSet} for a collection of values for one key. - * - * @return a new {@code HashSet} containing a collection of values for one key - */ - @Override Set createCollection() { - return Sets.newHashSetWithExpectedSize(expectedValuesPerKey); - } - - /** - * @serialData expectedValuesPerKey, number of distinct keys, and then for - * each distinct key: the key, number of values for that key, and the - * key's values - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeInt(expectedValuesPerKey); - Serialization.writeMultimap(this, stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - expectedValuesPerKey = stream.readInt(); - int distinctKeys = Serialization.readCount(stream); - Map> map = Maps.newHashMapWithExpectedSize(distinctKeys); - setMap(map); - Serialization.populateMultimap(this, stream, distinctKeys); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashMultiset.java deleted file mode 100644 index e77df0b4810..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/HashMultiset.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.HashMap; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Multiset implementation backed by a {@link HashMap}. - * - * @author Kevin Bourrillion - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -public final class HashMultiset extends AbstractMapBasedMultiset { - - /** - * Creates a new, empty {@code HashMultiset} using the default initial - * capacity. - */ - public static HashMultiset create() { - return new HashMultiset(); - } - - /** - * Creates a new, empty {@code HashMultiset} with the specified expected - * number of distinct elements. - * - * @param distinctElements the expected number of distinct elements - * @throws IllegalArgumentException if {@code distinctElements} is negative - */ - public static HashMultiset create(int distinctElements) { - return new HashMultiset(distinctElements); - } - - /** - * Creates a new {@code HashMultiset} containing the specified elements. - * - * @param elements the elements that the multiset should contain - */ - public static HashMultiset create(Iterable elements) { - HashMultiset multiset = - create(Multisets.inferDistinctElements(elements)); - Iterables.addAll(multiset, elements); - return multiset; - } - - private HashMultiset() { - super(new HashMap()); - } - - private HashMultiset(int distinctElements) { - super(new HashMap(Maps.capacity(distinctElements))); - } - - /** - * @serialData the number of distinct elements, the first element, its count, - * the second element, its count, and so on - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - Serialization.writeMultiset(this, stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - int distinctElements = Serialization.readCount(stream); - setBackingMap( - Maps.newHashMapWithExpectedSize(distinctElements)); - Serialization.populateMultiset(this, stream, distinctElements); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Hashing.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Hashing.java deleted file mode 100644 index 1c1e3ecdd58..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Hashing.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Static methods for implementing hash-based collections. - * - * @author Kevin Bourrillion - * @author Jesse Wilson - */ -@GwtCompatible -final class Hashing { - private Hashing() {} - - /* - * This method was written by Doug Lea with assistance from members of JCP - * JSR-166 Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain - */ - static int smear(int hashCode) { - hashCode ^= (hashCode >>> 20) ^ (hashCode >>> 12); - return hashCode ^ (hashCode >>> 7) ^ (hashCode >>> 4); - } - - // We use power-of-2 tables, and this is the highest int that's a power of 2 - private static final int MAX_TABLE_SIZE = 1 << 30; - - // If the set has this many elements, it will "max out" the table size - private static final int CUTOFF = 1 << 29; - - // Size the table to be at most 50% full, if possible - static int chooseTableSize(int setSize) { - if (setSize < CUTOFF) { - return Integer.highestOneBit(setSize) << 2; - } - - // The table can't be completely full or we'll get infinite reprobes - checkArgument(setSize < MAX_TABLE_SIZE, "collection too large"); - return MAX_TABLE_SIZE; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableBiMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableBiMap.java deleted file mode 100644 index bff5f0bff4e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableBiMap.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Map; - -/** - * An immutable {@link BiMap} with reliable user-specified iteration order. Does - * not permit null keys or values. An {@code ImmutableBiMap} and its inverse - * have the same iteration ordering. - * - *

An instance of {@code ImmutableBiMap} contains its own data and will - * never change. {@code ImmutableBiMap} is convenient for - * {@code public static final} maps ("constant maps") and also lets you easily - * make a "defensive copy" of a bimap provided to your class by a caller. - * - *

Note: Although this class is not final, it cannot be subclassed as - * it has no public or protected constructors. Thus, instances of this class are - * guaranteed to be immutable. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -public abstract class ImmutableBiMap extends ImmutableMap - implements BiMap { - - private static final ImmutableBiMap EMPTY_IMMUTABLE_BIMAP - = new EmptyBiMap(); - - /** - * Returns the empty bimap. - */ - // Casting to any type is safe because the set will never hold any elements. - @SuppressWarnings("unchecked") - public static ImmutableBiMap of() { - return (ImmutableBiMap) EMPTY_IMMUTABLE_BIMAP; - } - - /** - * Returns an immutable bimap containing a single entry. - */ - public static ImmutableBiMap of(K k1, V v1) { - return new RegularImmutableBiMap(ImmutableMap.of(k1, v1)); - } - - /** - * Returns an immutable map containing the given entries, in order. - * - * @throws IllegalArgumentException if duplicate keys or values are added - */ - public static ImmutableBiMap of(K k1, V v1, K k2, V v2) { - return new RegularImmutableBiMap(ImmutableMap.of(k1, v1, k2, v2)); - } - - /** - * Returns an immutable map containing the given entries, in order. - * - * @throws IllegalArgumentException if duplicate keys or values are added - */ - public static ImmutableBiMap of( - K k1, V v1, K k2, V v2, K k3, V v3) { - return new RegularImmutableBiMap(ImmutableMap.of( - k1, v1, k2, v2, k3, v3)); - } - - /** - * Returns an immutable map containing the given entries, in order. - * - * @throws IllegalArgumentException if duplicate keys or values are added - */ - public static ImmutableBiMap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - return new RegularImmutableBiMap(ImmutableMap.of( - k1, v1, k2, v2, k3, v3, k4, v4)); - } - - /** - * Returns an immutable map containing the given entries, in order. - * - * @throws IllegalArgumentException if duplicate keys or values are added - */ - public static ImmutableBiMap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - return new RegularImmutableBiMap(ImmutableMap.of( - k1, v1, k2, v2, k3, v3, k4, v4, k5, v5)); - } - - // looking for of() with > 5 entries? Use the builder instead. - - /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. - */ - public static Builder builder() { - return new Builder(); - } - - /** - * A builder for creating immutable bimap instances, especially {@code public - * static final} bimaps ("constant bimaps"). Example:

   {@code
-   *
-   *   static final ImmutableBiMap WORD_TO_INT =
-   *       new ImmutableBiMap.Builder()
-   *           .put("one", 1)
-   *           .put("two", 2)
-   *           .put("three", 3)
-   *           .build();}
- * - * For small immutable bimaps, the {@code ImmutableBiMap.of()} methods - * are even more convenient. - * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple bimaps in series. Each bimap is a superset - * of the bimaps created before it. - */ - public static final class Builder extends ImmutableMap.Builder { - - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableBiMap#builder}. - */ - public Builder() {} - - /** - * Associates {@code key} with {@code value} in the built bimap. Duplicate - * keys or values are not allowed, and will cause {@link #build} to fail. - */ - @Override public Builder put(K key, V value) { - super.put(key, value); - return this; - } - - /** - * Associates all of the given map's keys and values in the built bimap. - * Duplicate keys or values are not allowed, and will cause {@link #build} - * to fail. - * - * @throws NullPointerException if any key or value in {@code map} is null - */ - @Override public Builder putAll(Map map) { - super.putAll(map); - return this; - } - - /** - * Returns a newly-created immutable bimap. - * - * @throws IllegalArgumentException if duplicate keys or values were added - */ - @Override public ImmutableBiMap build() { - ImmutableMap map = super.build(); - if (map.isEmpty()) { - return of(); - } - return new RegularImmutableBiMap(super.build()); - } - } - - /** - * Returns an immutable bimap containing the same entries as {@code map}. If - * {@code map} somehow contains entries with duplicate keys (for example, if - * it is a {@code SortedMap} whose comparator is not consistent with - * equals), the results of this method are undefined. - * - *

Note: If {@code map} is an {@code ImmutableBiMap}, the given map - * itself will be returned. - * - * @throws IllegalArgumentException if two keys have the same value - * @throws NullPointerException if any key or value in {@code map} is null - */ - public static ImmutableBiMap copyOf( - Map map) { - if (map instanceof ImmutableBiMap) { - @SuppressWarnings("unchecked") // safe since map is not writable - ImmutableBiMap bimap = (ImmutableBiMap) map; - return bimap; - } - - if (map.isEmpty()) { - return of(); - } - - ImmutableMap immutableMap = ImmutableMap.copyOf(map); - return new RegularImmutableBiMap(immutableMap); - } - - ImmutableBiMap() {} - - abstract ImmutableMap delegate(); - - /** - * {@inheritDoc} - * - *

The inverse of an {@code ImmutableBiMap} is another - * {@code ImmutableBiMap}. - */ - public abstract ImmutableBiMap inverse(); - - @Override public boolean containsKey(@Nullable Object key) { - return delegate().containsKey(key); - } - - @Override public boolean containsValue(@Nullable Object value) { - return inverse().containsKey(value); - } - - @Override public ImmutableSet> entrySet() { - return delegate().entrySet(); - } - - @Override public V get(@Nullable Object key) { - return delegate().get(key); - } - - @Override public ImmutableSet keySet() { - return delegate().keySet(); - } - - /** - * Returns an immutable set of the values in this map. The values are in the - * same order as the parameters used to build this map. - */ - @Override public ImmutableSet values() { - return inverse().keySet(); - } - - /** - * Guaranteed to throw an exception and leave the bimap unmodified. - * - * @throws UnsupportedOperationException always - */ - public V forcePut(K key, V value) { - throw new UnsupportedOperationException(); - } - - @Override public boolean isEmpty() { - return delegate().isEmpty(); - } - - public int size() { - return delegate().size(); - } - - @Override public boolean equals(@Nullable Object object) { - return object == this || delegate().equals(object); - } - - @Override public int hashCode() { - return delegate().hashCode(); - } - - @Override public String toString() { - return delegate().toString(); - } - - /** Bimap with no mappings. */ - @SuppressWarnings("serial") // uses writeReplace(), not default serialization - static class EmptyBiMap extends ImmutableBiMap { - @Override ImmutableMap delegate() { - return ImmutableMap.of(); - } - @Override public ImmutableBiMap inverse() { - return this; - } - Object readResolve() { - return EMPTY_IMMUTABLE_BIMAP; // preserve singleton property - } - } - - /** - * Serialized type for all ImmutableBiMap instances. It captures the logical - * contents and they are reconstructed using public factory methods. This - * ensures that the implementation types remain as implementation details. - * - * Since the bimap is immutable, ImmutableBiMap doesn't require special logic - * for keeping the bimap and its inverse in sync during serialization, the way - * AbstractBiMap does. - */ - private static class SerializedForm extends ImmutableMap.SerializedForm { - SerializedForm(ImmutableBiMap bimap) { - super(bimap); - } - @Override Object readResolve() { - Builder builder = new Builder(); - return createMap(builder); - } - private static final long serialVersionUID = 0; - } - - @Override Object writeReplace() { - return new SerializedForm(this); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableClassToInstanceMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableClassToInstanceMap.java deleted file mode 100644 index 2356fbc15d8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableClassToInstanceMap.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import java.util.Map; - -import static org.elasticsearch.util.collect.MutableClassToInstanceMap.*; - -/** - * A class-to-instance map backed by an {@link ImmutableMap}. See also {@link - * MutableClassToInstanceMap}. - * - * @author Kevin Bourrillion - */ -public final class ImmutableClassToInstanceMap extends - ForwardingMap, B> implements ClassToInstanceMap { - /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. - */ - public static Builder builder() { - return new Builder(); - } - - /** - * A builder for creating immutable class-to-instance maps. Example: - *

   {@code
-   *
-   *   static final ImmutableClassToInstanceMap HANDLERS =
-   *       new ImmutableClassToInstanceMap.Builder()
-   *           .put(FooHandler.class, new FooHandler())
-   *           .put(BarHandler.class, new SubBarHandler())
-   *           .put(Handler.class, new QuuxHandler())
-   *           .build();}
- * - *

After invoking {@link #build()} it is still possible to add more - * entries and build again. Thus each map generated by this builder will be - * a superset of any map generated before it. - */ - public static final class Builder { - private final ImmutableMap.Builder, B> mapBuilder - = ImmutableMap.builder(); - - /** - * Associates {@code key} with {@code value} in the built map. Duplicate - * keys are not allowed, and will cause {@link #build} to fail. - */ - public Builder put(Class type, T value) { - mapBuilder.put(type, value); - return this; - } - - /** - * Associates all of {@code map's} keys and values in the built map. - * Duplicate keys are not allowed, and will cause {@link #build} to fail. - * - * @throws NullPointerException if any key or value in {@code map} is null - * @throws ClassCastException if any value is not an instance of the type - * specified by its key - */ - public Builder putAll( - Map, ? extends T> map) { - for (Entry, ? extends T> entry - : map.entrySet()) { - Class type = entry.getKey(); - T value = entry.getValue(); - mapBuilder.put(type, cast(type, value)); - } - return this; - } - - /** - * Returns a new immutable class-to-instance map containing the entries - * provided to this builder. - * - * @throws IllegalArgumentException if duplicate keys were added - */ - public ImmutableClassToInstanceMap build() { - return new ImmutableClassToInstanceMap(mapBuilder.build()); - } - } - - /** - * Returns an immutable map containing the same entries as {@code map}. If - * {@code map} somehow contains entries with duplicate keys (for example, if - * it is a {@code SortedMap} whose comparator is not consistent with - * equals), the results of this method are undefined. - * - *

Note: Despite what the method name suggests, if {@code map} is - * an {@code ImmutableClassToInstanceMap}, no copy will actually be performed. - * - * @throws NullPointerException if any key or value in {@code map} is null - * @throws ClassCastException if any value is not an instance of the type - * specified by its key - */ - @SuppressWarnings("unchecked") // covariant casts safe (unmodifiable) - public static ImmutableClassToInstanceMap copyOf( - Map, ? extends S> map) { - if (map instanceof ImmutableClassToInstanceMap) { - return (ImmutableClassToInstanceMap) (Map) map; - } - return new Builder().putAll(map).build(); - } - - private final ImmutableMap, B> delegate; - - private ImmutableClassToInstanceMap( - ImmutableMap, B> delegate) { - this.delegate = delegate; - } - - @Override protected Map, B> delegate() { - return delegate; - } - - @SuppressWarnings("unchecked") // value could not get in if not a T - public T getInstance(Class type) { - return (T) delegate.get(type); - } - - /** - * Guaranteed to throw an exception and leave the map unmodified. - * - * @throws UnsupportedOperationException always - */ - public T putInstance(Class type, T value) { - throw new UnsupportedOperationException(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableCollection.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableCollection.java deleted file mode 100644 index 3246484458e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableCollection.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.Collection; -import java.util.Iterator; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * An immutable collection. Does not permit null elements. - * - *

Note: Although this class is not final, it cannot be subclassed - * outside of this package as it has no public or protected constructors. Thus, - * instances of this type are guaranteed to be immutable. - * - * @author Jesse Wilson - */ -@GwtCompatible -@SuppressWarnings("serial") // we're overriding default serialization -public abstract class ImmutableCollection - implements Collection, Serializable { - static final ImmutableCollection EMPTY_IMMUTABLE_COLLECTION - = new EmptyImmutableCollection(); - - ImmutableCollection() {} - - /** - * Returns an unmodifiable iterator across the elements in this collection. - */ - public abstract UnmodifiableIterator iterator(); - - public Object[] toArray() { - Object[] newArray = new Object[size()]; - return toArray(newArray); - } - - public T[] toArray(T[] other) { - int size = size(); - if (other.length < size) { - other = ObjectArrays.newArray(other, size); - } else if (other.length > size) { - other[size] = null; - } - - // Writes will produce ArrayStoreException when the toArray() doc requires. - Object[] otherAsObjectArray = other; - int index = 0; - for (E element : this) { - otherAsObjectArray[index++] = element; - } - return other; - } - - public boolean contains(@Nullable Object object) { - if (object == null) { - return false; - } - for (E element : this) { - if (element.equals(object)) { - return true; - } - } - return false; - } - - public boolean containsAll(Collection targets) { - for (Object target : targets) { - if (!contains(target)) { - return false; - } - } - return true; - } - - public boolean isEmpty() { - return size() == 0; - } - - @Override public String toString() { - StringBuilder sb = new StringBuilder(size() * 16).append('['); - Collections2.standardJoiner.appendTo(sb, this); - return sb.append(']').toString(); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public final boolean add(E e) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public final boolean remove(Object object) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public final boolean addAll(Collection newElements) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public final boolean removeAll(Collection oldElements) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public final boolean retainAll(Collection elementsToKeep) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public final void clear() { - throw new UnsupportedOperationException(); - } - - private static class EmptyImmutableCollection - extends ImmutableCollection { - public int size() { - return 0; - } - - @Override public boolean isEmpty() { - return true; - } - - @Override public boolean contains(@Nullable Object object) { - return false; - } - - @Override public UnmodifiableIterator iterator() { - return Iterators.EMPTY_ITERATOR; - } - - private static final Object[] EMPTY_ARRAY = new Object[0]; - - @Override public Object[] toArray() { - return EMPTY_ARRAY; - } - - @Override public T[] toArray(T[] array) { - if (array.length > 0) { - array[0] = null; - } - return array; - } - } - - private static class ArrayImmutableCollection - extends ImmutableCollection { - private final E[] elements; - - ArrayImmutableCollection(E[] elements) { - this.elements = elements; - } - - public int size() { - return elements.length; - } - - @Override public boolean isEmpty() { - return false; - } - - @Override public UnmodifiableIterator iterator() { - return Iterators.forArray(elements); - } - } - - /* - * Serializes ImmutableCollections as their logical contents. This ensures - * that implementation types do not leak into the serialized representation. - */ - private static class SerializedForm implements Serializable { - final Object[] elements; - SerializedForm(Object[] elements) { - this.elements = elements; - } - Object readResolve() { - return elements.length == 0 - ? EMPTY_IMMUTABLE_COLLECTION - : new ArrayImmutableCollection(Platform.clone(elements)); - } - private static final long serialVersionUID = 0; - } - - Object writeReplace() { - return new SerializedForm(toArray()); - } - - /** - * Abstract base class for builders of {@link ImmutableCollection} types. - */ - abstract static class Builder { - /** - * Adds {@code element} to the {@code ImmutableCollection} being built. - * - *

Note that each builder class covariantly returns its own type from - * this method. - * - * @param element the element to add - * @return this {@code Builder} instance - * @throws NullPointerException if {@code element} is null - */ - public abstract Builder add(E element); - - /** - * Adds each element of {@code elements} to the {@code ImmutableCollection} - * being built. - * - *

Note that each builder class overrides this method in order to - * covariantly return its own type. - * - * @param elements the elements to add - * @return this {@code Builder} instance - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - public Builder add(E... elements) { - checkNotNull(elements); // for GWT - for (E element : elements) { - add(element); - } - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableCollection} - * being built. - * - *

Note that each builder class overrides this method in order to - * covariantly return its own type. - * - * @param elements the elements to add - * @return this {@code Builder} instance - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - public Builder addAll(Iterable elements) { - checkNotNull(elements); // for GWT - for (E element : elements) { - add(element); - } - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableCollection} - * being built. - * - *

Note that each builder class overrides this method in order to - * covariantly return its own type. - * - * @param elements the elements to add - * @return this {@code Builder} instance - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - public Builder addAll(Iterator elements) { - checkNotNull(elements); // for GWT - while (elements.hasNext()) { - add(elements.next()); - } - return this; - } - - /** - * Returns a newly-created {@code ImmutableCollection} of the appropriate - * type, containing the elements provided to this builder. - * - *

Note that each builder class covariantly returns the appropriate type - * of {@code ImmutableCollection} from this method. - */ - public abstract ImmutableCollection build(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableEntry.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableEntry.java deleted file mode 100644 index af12a93b64c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableEntry.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; - -/** - * @see org.elasticsearch.util.collect.Maps#immutableEntry(Object, Object) - */ -@GwtCompatible -class ImmutableEntry extends AbstractMapEntry - implements Serializable { - private final K key; - private final V value; - - ImmutableEntry(@Nullable K key, @Nullable V value) { - this.key = key; - this.value = value; - } - - @Override public K getKey() { - return key; - } - - @Override public V getValue() { - return value; - } - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableEnumSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableEnumSet.java deleted file mode 100644 index 54ac735a26f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableEnumSet.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.Serializable; -import java.util.Collection; -import java.util.EnumSet; -import java.util.Set; - -/** - * Implementation of {@link ImmutableSet} backed by a non-empty {@link - * java.util.EnumSet}. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // we're overriding default serialization -final class ImmutableEnumSet*/> extends ImmutableSet { - /* - * Notes on EnumSet and >: - * - * This class isn't an arbitrary ForwardingImmutableSet because we need to - * know that calling {@code clone()} during deserialization will return an - * object that no one else has a reference to, allowing us to guarantee - * immutability. Hence, we support only {@link EnumSet}. - * - * GWT complicates matters. If we declare the class's type parameter as - * > (as is necessary to declare a field of type - * EnumSet), GWT generates serializers for every available enum. This - * increases the size of some applications' JavaScript by over 10%. To avoid - * this, we declare the type parameter as just and the field as just - * Set. writeReplace() must then use an unchecked cast to return to - * EnumSet, guaranteeing immutability as described above. - */ - private final transient Set delegate; - - ImmutableEnumSet(Set delegate) { - this.delegate = delegate; - } - - @Override public UnmodifiableIterator iterator() { - return Iterators.unmodifiableIterator(delegate.iterator()); - } - - public int size() { - return delegate.size(); - } - - @Override public boolean contains(Object object) { - return delegate.contains(object); - } - - @Override public boolean containsAll(Collection collection) { - return delegate.containsAll(collection); - } - - @Override public boolean isEmpty() { - return delegate.isEmpty(); - } - - @Override public Object[] toArray() { - return delegate.toArray(); - } - - @Override public T[] toArray(T[] array) { - return delegate.toArray(array); - } - - @Override public boolean equals(Object object) { - return object == this || delegate.equals(object); - } - - private transient int hashCode; - - @Override public int hashCode() { - int result = hashCode; - return (result == 0) ? hashCode = delegate.hashCode() : result; - } - - @Override public String toString() { - return delegate.toString(); - } - - // All callers of the constructor are restricted to >. - @SuppressWarnings("unchecked") - @Override Object writeReplace() { - return new EnumSerializedForm((EnumSet) delegate); - } - - /* - * This class is used to serialize ImmutableEnumSet instances. - */ - private static class EnumSerializedForm> - implements Serializable { - final EnumSet delegate; - EnumSerializedForm(EnumSet delegate) { - this.delegate = delegate; - } - Object readResolve() { - // EJ2 #76: Write readObject() methods defensively. - return new ImmutableEnumSet(delegate.clone()); - } - private static final long serialVersionUID = 0; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableList.java deleted file mode 100644 index b5d1b6bc8d0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableList.java +++ /dev/null @@ -1,505 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * A high-performance, immutable, random-access {@code List} implementation. - * Does not permit null elements. - * - *

Unlike {@link Collections#unmodifiableList}, which is a view of a - * separate collection that can still change, an instance of {@code - * ImmutableList} contains its own private data and will never change. - * {@code ImmutableList} is convenient for {@code public static final} lists - * ("constant lists") and also lets you easily make a "defensive copy" of a list - * provided to your class by a caller. - * - *

Note: Although this class is not final, it cannot be subclassed as - * it has no public or protected constructors. Thus, instances of this type are - * guaranteed to be immutable. - * - * @see ImmutableMap - * @see ImmutableSet - * @author Kevin Bourrillion - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // we're overriding default serialization -public abstract class ImmutableList extends ImmutableCollection - implements List, RandomAccess { - /** - * Returns the empty immutable list. This set behaves and performs comparably - * to {@link Collections#emptyList}, and is preferable mainly for consistency - * and maintainability of your code. - */ - // Casting to any type is safe because the list will never hold any elements. - @SuppressWarnings("unchecked") - public static ImmutableList of() { - return (ImmutableList) EmptyImmutableList.INSTANCE; - } - - /** - * Returns an immutable list containing a single element. This list behaves - * and performs comparably to {@link Collections#singleton}, but will not - * accept a null element. It is preferable mainly for consistency and - * maintainability of your code. - * - * @throws NullPointerException if {@code element} is null - */ - public static ImmutableList of(E element) { - return new SingletonImmutableList(element); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of(E e1, E e2) { - return new RegularImmutableList(copyIntoArray(e1, e2)); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of(E e1, E e2, E e3) { - return new RegularImmutableList(copyIntoArray(e1, e2, e3)); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of(E e1, E e2, E e3, E e4) { - return new RegularImmutableList(copyIntoArray(e1, e2, e3, e4)); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of(E e1, E e2, E e3, E e4, E e5) { - return new RegularImmutableList(copyIntoArray(e1, e2, e3, e4, e5)); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of(E e1, E e2, E e3, E e4, E e5, E e6) { - return new RegularImmutableList(copyIntoArray(e1, e2, e3, e4, e5, e6)); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of( - E e1, E e2, E e3, E e4, E e5, E e6, E e7) { - return new RegularImmutableList( - copyIntoArray(e1, e2, e3, e4, e5, e6, e7)); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of( - E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { - return new RegularImmutableList( - copyIntoArray(e1, e2, e3, e4, e5, e6, e7, e8)); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of( - E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { - return new RegularImmutableList( - copyIntoArray(e1, e2, e3, e4, e5, e6, e7, e8, e9)); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of( - E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { - return new RegularImmutableList( - copyIntoArray(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10)); - } - - /** - * Identical to {@link #of(Object[])}. - * - * @throws NullPointerException if any element is null - */ - public static ImmutableList of( - E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11) { - return new RegularImmutableList( - copyIntoArray(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11)); - } - - // These go up to eleven. After that, you just get the varargs form, and - // whatever warnings might come along with it. :( - - /** - * Returns an immutable list containing the given elements, in order. - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableList of(E... elements) { - checkNotNull(elements); // for GWT - switch (elements.length) { - case 0: - return ImmutableList.of(); - case 1: - return new SingletonImmutableList(elements[0]); - default: - return new RegularImmutableList(copyIntoArray(elements)); - } - } - - /** - * Returns an immutable list containing the given elements, in order. This - * method iterates over {@code elements} at most once. Note that if {@code - * list} is a {@code List}, then {@code ImmutableList.copyOf(list)} - * returns an {@code ImmutableList} containing each of the strings - * in {@code list}, while ImmutableList.of(list)} returns an {@code - * ImmutableList>} containing one element (the given list - * itself). - * - *

Note: Despite what the method name suggests, if {@code elements} - * is an {@code ImmutableList}, no copy will actually be performed, and the - * given list itself will be returned. - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableList copyOf(Iterable elements) { - if (elements instanceof ImmutableList) { - /* - * TODO: If the given ImmutableList is a sublist, copy the referenced - * portion of the array into a new array to save space? - */ - @SuppressWarnings("unchecked") // all supported methods are covariant - ImmutableList list = (ImmutableList) elements; - return list; - } else if (elements instanceof Collection) { - @SuppressWarnings("unchecked") - Collection coll = (Collection) elements; - return copyOfInternal(coll); - } else { - return copyOfInternal(Lists.newArrayList(elements)); - } - } - - /** - * Returns an immutable list containing the given elements, in order. - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableList copyOf(Iterator elements) { - return copyOfInternal(Lists.newArrayList(elements)); - } - - private static ImmutableList copyOfInternal( - ArrayList list) { - switch (list.size()) { - case 0: - return of(); - case 1: - return new SingletonImmutableList(list.iterator().next()); - default: - return new RegularImmutableList(nullChecked(list.toArray())); - } - } - - /** - * Checks that all the array elements are non-null. - * - * @return the argument array - * @throws NullPointerException if any element is null - */ - private static Object[] nullChecked(Object[] array) { - for (int i = 0, len = array.length; i < len; i++) { - if (array[i] == null) { - throw new NullPointerException("at index " + i); - } - } - return array; - } - - private static ImmutableList copyOfInternal( - Collection collection) { - int size = collection.size(); - return (size == 0) - ? ImmutableList.of() - : ImmutableList.createFromIterable(collection, size); - } - - ImmutableList() {} - - // This declaration is needed to make List.iterator() and - // ImmutableCollection.iterator() consistent. - @Override public abstract UnmodifiableIterator iterator(); - - // Mark these two methods with @Nullable - - public abstract int indexOf(@Nullable Object object); - - public abstract int lastIndexOf(@Nullable Object object); - - // constrain the return type to ImmutableList - - /** - * Returns an immutable list of the elements between the specified {@code - * fromIndex}, inclusive, and {@code toIndex}, exclusive. (If {@code - * fromIndex} and {@code toIndex} are equal, the empty immutable list is - * returned.) - */ - public abstract ImmutableList subList(int fromIndex, int toIndex); - - /** - * Guaranteed to throw an exception and leave the list unmodified. - * - * @throws UnsupportedOperationException always - */ - public final boolean addAll(int index, Collection newElements) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the list unmodified. - * - * @throws UnsupportedOperationException always - */ - public final E set(int index, E element) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the list unmodified. - * - * @throws UnsupportedOperationException always - */ - public final void add(int index, E element) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the list unmodified. - * - * @throws UnsupportedOperationException always - */ - public final E remove(int index) { - throw new UnsupportedOperationException(); - } - - private static Object[] copyIntoArray(Object... source) { - Object[] array = new Object[source.length]; - int index = 0; - for (Object element : source) { - if (element == null) { - throw new NullPointerException("at index " + index); - } - array[index++] = element; - } - return array; - } - - private static ImmutableList createFromIterable( - Iterable source, int estimatedSize) { - Object[] array = new Object[estimatedSize]; - int index = 0; - - for (Object element : source) { - if (index == estimatedSize) { - // At least one element was added after our call to size(). - estimatedSize = ((estimatedSize / 2) + 1) * 3; - array = copyOf(array, estimatedSize); - } - if (element == null) { - throw new NullPointerException("at index " + index); - } - array[index++] = element; - } - - if (index == 0) { - return of(); - } else if (index == 1) { - // The elements of "array" come from a Iterable. - @SuppressWarnings("unchecked") - E element = (E) array[0]; - return of(element); - } - - if (index != estimatedSize) { - array = copyOf(array, index); - } - - return new RegularImmutableList(array, 0, index); - } - - // Avoid using Arrays.copyOf(), which is not present until JDK6. - private static Object[] copyOf(Object[] oldArray, int newSize) { - Object[] newArray = new Object[newSize]; - System.arraycopy(oldArray, 0, newArray, 0, - Math.min(oldArray.length, newSize)); - return newArray; - } - - /* - * Serializes ImmutableLists as their logical contents. This ensures that - * implementation types do not leak into the serialized representation. - */ - private static class SerializedForm implements Serializable { - final Object[] elements; - SerializedForm(Object[] elements) { - this.elements = elements; - } - Object readResolve() { - return of(elements); - } - private static final long serialVersionUID = 0; - } - - private void readObject(ObjectInputStream stream) - throws InvalidObjectException { - throw new InvalidObjectException("Use SerializedForm"); - } - - @Override Object writeReplace() { - return new SerializedForm(toArray()); - } - - /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. - */ - public static Builder builder() { - return new Builder(); - } - - /** - * A builder for creating immutable list instances, especially - * {@code public static final} lists ("constant lists"). - * - *

Example: - *

   {@code
-   *   public static final ImmutableList GOOGLE_COLORS
-   *       = new ImmutableList.Builder()
-   *           .addAll(WEBSAFE_COLORS)
-   *           .add(new Color(0, 191, 255))
-   *           .build();}
- * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple lists in series. Each new list - * contains the one created before it. - */ - public static final class Builder extends ImmutableCollection.Builder { - private final ArrayList contents = Lists.newArrayList(); - - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableList#builder}. - */ - public Builder() {} - - /** - * Adds {@code element} to the {@code ImmutableList}. - * - * @param element the element to add - * @return this {@code Builder} object - * @throws NullPointerException if {@code element} is null - */ - @Override public Builder add(E element) { - contents.add(checkNotNull(element)); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableList}. - * - * @param elements the {@code Iterable} to add to the {@code ImmutableList} - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - @Override public Builder addAll(Iterable elements) { - if (elements instanceof Collection) { - Collection collection = (Collection) elements; - contents.ensureCapacity(contents.size() + collection.size()); - } - super.addAll(elements); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableList}. - * - * @param elements the {@code Iterable} to add to the {@code ImmutableList} - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - @Override public Builder add(E... elements) { - checkNotNull(elements); // for GWT - contents.ensureCapacity(contents.size() + elements.length); - super.add(elements); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableList}. - * - * @param elements the {@code Iterable} to add to the {@code ImmutableList} - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - @Override public Builder addAll(Iterator elements) { - super.addAll(elements); - return this; - } - - /** - * Returns a newly-created {@code ImmutableList} based on the contents of - * the {@code Builder}. - */ - @Override public ImmutableList build() { - return copyOf(contents); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableListMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableListMultimap.java deleted file mode 100644 index e0fce1e174f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableListMultimap.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Collection; -import java.util.Map; - -/** - * An immutable {@link ListMultimap} with reliable user-specified key and value - * iteration order. Does not permit null keys or values. - * - *

Unlike {@link Multimaps#unmodifiableListMultimap(ListMultimap)}, which is - * a view of a separate multimap which can still change, an instance of - * {@code ImmutableListMultimap} contains its own data and will never - * change. {@code ImmutableListMultimap} is convenient for - * {@code public static final} multimaps ("constant multimaps") and also lets - * you easily make a "defensive copy" of a multimap provided to your class by - * a caller. - * - *

Note: Although this class is not final, it cannot be subclassed as - * it has no public or protected constructors. Thus, instances of this class - * are guaranteed to be immutable. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -public class ImmutableListMultimap - extends ImmutableMultimap - implements ListMultimap { - - /** Returns the empty multimap. */ - // Casting is safe because the multimap will never hold any elements. - @SuppressWarnings("unchecked") - public static ImmutableListMultimap of() { - return (ImmutableListMultimap) EmptyImmutableListMultimap.INSTANCE; - } - - /** - * Returns an immutable multimap containing a single entry. - */ - public static ImmutableListMultimap of(K k1, V v1) { - ImmutableListMultimap.Builder builder - = ImmutableListMultimap.builder(); - builder.put(k1, v1); - return builder.build(); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - */ - public static ImmutableListMultimap of(K k1, V v1, K k2, V v2) { - ImmutableListMultimap.Builder builder - = ImmutableListMultimap.builder(); - builder.put(k1, v1); - builder.put(k2, v2); - return builder.build(); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - */ - public static ImmutableListMultimap of( - K k1, V v1, K k2, V v2, K k3, V v3) { - ImmutableListMultimap.Builder builder - = ImmutableListMultimap.builder(); - builder.put(k1, v1); - builder.put(k2, v2); - builder.put(k3, v3); - return builder.build(); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - */ - public static ImmutableListMultimap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - ImmutableListMultimap.Builder builder - = ImmutableListMultimap.builder(); - builder.put(k1, v1); - builder.put(k2, v2); - builder.put(k3, v3); - builder.put(k4, v4); - return builder.build(); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - */ - public static ImmutableListMultimap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - ImmutableListMultimap.Builder builder - = ImmutableListMultimap.builder(); - builder.put(k1, v1); - builder.put(k2, v2); - builder.put(k3, v3); - builder.put(k4, v4); - builder.put(k5, v5); - return builder.build(); - } - - // looking for of() with > 5 entries? Use the builder instead. - - /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. - */ - public static Builder builder() { - return new Builder(); - } - - /** - * A builder for creating immutable {@code ListMultimap} instances, especially - * {@code public static final} multimaps ("constant multimaps"). Example: - *

   {@code
-   *
-   *   static final Multimap STRING_TO_INTEGER_MULTIMAP =
-   *       new ImmutableListMultimap.Builder()
-   *           .put("one", 1)
-   *           .putAll("several", 1, 2, 3)
-   *           .putAll("many", 1, 2, 3, 4, 5)
-   *           .build();}
- * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple multimaps in series. Each multimap - * contains the key-value mappings in the previously created multimaps. - */ - public static final class Builder - extends ImmutableMultimap.Builder { - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableListMultimap#builder}. - */ - public Builder() {} - - /** - * Adds a key-value mapping to the built multimap. - */ - @Override public Builder put(K key, V value) { - super.put(key, value); - return this; - } - - /** - * Stores a collection of values with the same key in the built multimap. - * - * @throws NullPointerException if {@code key}, {@code values}, or any - * element in {@code values} is null. The builder is left in an invalid - * state. - */ - @Override public Builder putAll(K key, Iterable values) { - super.putAll(key, values); - return this; - } - - /** - * Stores an array of values with the same key in the built multimap. - * - * @throws NullPointerException if the key or any value is null. The builder - * is left in an invalid state. - */ - @Override public Builder putAll(K key, V... values) { - super.putAll(key, values); - return this; - } - - /** - * Stores another multimap's entries in the built multimap. The generated - * multimap's key and value orderings correspond to the iteration ordering - * of the {@code multimap.asMap()} view, with new keys and values following - * any existing keys and values. - * - * @throws NullPointerException if any key or value in {@code multimap} is - * null. The builder is left in an invalid state. - */ - @Override public Builder putAll( - Multimap multimap) { - super.putAll(multimap); - return this; - } - - /** - * Returns a newly-created immutable multimap. - */ - @Override public ImmutableListMultimap build() { - return (ImmutableListMultimap) super.build(); - } - } - - /** - * Returns an immutable multimap containing the same mappings as - * {@code multimap}. The generated multimap's key and value orderings - * correspond to the iteration ordering of the {@code multimap.asMap()} view. - * - *

Note: Despite what the method name suggests, if - * {@code multimap} is an {@code ImmutableListMultimap}, no copy will actually - * be performed, and the given multimap itself will be returned. - * - * @throws NullPointerException if any key or value in {@code multimap} is - * null - */ - public static ImmutableListMultimap copyOf( - Multimap multimap) { - if (multimap.isEmpty()) { - return of(); - } - - if (multimap instanceof ImmutableListMultimap) { - @SuppressWarnings("unchecked") // safe since multimap is not writable - ImmutableListMultimap kvMultimap - = (ImmutableListMultimap) multimap; - return kvMultimap; - } - - ImmutableMap.Builder> builder = ImmutableMap.builder(); - int size = 0; - - for (Map.Entry> entry - : multimap.asMap().entrySet()) { - ImmutableList list = ImmutableList.copyOf(entry.getValue()); - if (!list.isEmpty()) { - builder.put(entry.getKey(), list); - size += list.size(); - } - } - - return new ImmutableListMultimap(builder.build(), size); - } - - ImmutableListMultimap(ImmutableMap> map, int size) { - super(map, size); - } - - // views - - /** - * Returns an immutable list of the values for the given key. If no mappings - * in the multimap have the provided key, an empty immutable list is - * returned. The values are in the same order as the parameters used to build - * this multimap. - */ - @Override public ImmutableList get(@Nullable K key) { - // This cast is safe as its type is known in constructor. - ImmutableList list = (ImmutableList) map.get(key); - return (list == null) ? ImmutableList.of() : list; - } - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - @Override public ImmutableList removeAll(Object key) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - @Override public ImmutableList replaceValues( - K key, Iterable values) { - throw new UnsupportedOperationException(); - } - - /** - * @serialData number of distinct keys, and then for each distinct key: the - * key, the number of values for that key, and the key's values - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - Serialization.writeMultimap(this, stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - int keyCount = stream.readInt(); - if (keyCount < 0) { - throw new InvalidObjectException("Invalid key count " + keyCount); - } - ImmutableMap.Builder> builder - = ImmutableMap.builder(); - int tmpSize = 0; - - for (int i = 0; i < keyCount; i++) { - Object key = stream.readObject(); - int valueCount = stream.readInt(); - if (valueCount <= 0) { - throw new InvalidObjectException("Invalid value count " + valueCount); - } - - Object[] array = new Object[valueCount]; - for (int j = 0; j < valueCount; j++) { - array[j] = stream.readObject(); - } - builder.put(key, ImmutableList.of(array)); - tmpSize += valueCount; - } - - ImmutableMap> tmpMap; - try { - tmpMap = builder.build(); - } catch (IllegalArgumentException e) { - throw (InvalidObjectException) - new InvalidObjectException(e.getMessage()).initCause(e); - } - - FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap); - FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMap.java deleted file mode 100644 index 4c04b210b8c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMap.java +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static org.elasticsearch.util.base.Preconditions.*; -import static org.elasticsearch.util.collect.Iterables.*; - -/** - * An immutable, hash-based {@link Map} with reliable user-specified iteration - * order. Does not permit null keys or values. - * - *

Unlike {@link Collections#unmodifiableMap}, which is a view of a - * separate map which can still change, an instance of {@code ImmutableMap} - * contains its own data and will never change. {@code ImmutableMap} is - * convenient for {@code public static final} maps ("constant maps") and also - * lets you easily make a "defensive copy" of a map provided to your class by a - * caller. - * - *

Note: Although this class is not final, it cannot be subclassed as - * it has no public or protected constructors. Thus, instances of this class are - * guaranteed to be immutable. - * - * @see ImmutableList - * @see ImmutableSet - * @author Jesse Wilson - * @author Kevin Bourrillion - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // we're overriding default serialization -public abstract class ImmutableMap implements Map, Serializable { - /** - * Returns the empty map. This map behaves and performs comparably to - * {@link Collections#emptyMap}, and is preferable mainly for consistency - * and maintainability of your code. - */ - // Casting to any type is safe because the set will never hold any elements. - @SuppressWarnings("unchecked") - public static ImmutableMap of() { - return (ImmutableMap) EmptyImmutableMap.INSTANCE; - } - - /** - * Returns an immutable map containing a single entry. This map behaves and - * performs comparably to {@link Collections#singletonMap} but will not accept - * a null key or value. It is preferable mainly for consistency and - * maintainability of your code. - */ - public static ImmutableMap of(K k1, V v1) { - return new SingletonImmutableMap( - checkNotNull(k1), checkNotNull(v1)); - } - - /** - * Returns an immutable map containing the given entries, in order. - * - * @throws IllegalArgumentException if duplicate keys are provided - */ - public static ImmutableMap of(K k1, V v1, K k2, V v2) { - return new RegularImmutableMap(entryOf(k1, v1), entryOf(k2, v2)); - } - - /** - * Returns an immutable map containing the given entries, in order. - * - * @throws IllegalArgumentException if duplicate keys are provided - */ - public static ImmutableMap of( - K k1, V v1, K k2, V v2, K k3, V v3) { - return new RegularImmutableMap( - entryOf(k1, v1), entryOf(k2, v2), entryOf(k3, v3)); - } - - /** - * Returns an immutable map containing the given entries, in order. - * - * @throws IllegalArgumentException if duplicate keys are provided - */ - public static ImmutableMap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - return new RegularImmutableMap( - entryOf(k1, v1), entryOf(k2, v2), entryOf(k3, v3), entryOf(k4, v4)); - } - - /** - * Returns an immutable map containing the given entries, in order. - * - * @throws IllegalArgumentException if duplicate keys are provided - */ - public static ImmutableMap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - return new RegularImmutableMap(entryOf(k1, v1), - entryOf(k2, v2), entryOf(k3, v3), entryOf(k4, v4), entryOf(k5, v5)); - } - - // looking for of() with > 5 entries? Use the builder instead. - - /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. - */ - public static Builder builder() { - return new Builder(); - } - - /** - * Verifies that {@code key} and {@code value} are non-null, and returns a new - * immutable entry with those values. - * - *

A call to {@link Map.Entry#setValue} on the returned entry will always - * throw {@link UnsupportedOperationException}. - */ - static Entry entryOf(K key, V value) { - return Maps.immutableEntry(checkNotNull(key), checkNotNull(value)); - } - - /** - * A builder for creating immutable map instances, especially {@code public - * static final} maps ("constant maps"). Example:

   {@code
-   *
-   *   static final ImmutableMap WORD_TO_INT =
-   *       new ImmutableMap.Builder()
-   *           .put("one", 1)
-   *           .put("two", 2)
-   *           .put("three", 3)
-   *           .build();}
- * - * For small immutable maps, the {@code ImmutableMap.of()} methods are - * even more convenient. - * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple maps in series. Each map is a superset of - * the maps created before it. - */ - public static class Builder { - final List> entries = Lists.newArrayList(); - - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableMap#builder}. - */ - public Builder() {} - - /** - * Associates {@code key} with {@code value} in the built map. Duplicate - * keys are not allowed, and will cause {@link #build} to fail. - */ - public Builder put(K key, V value) { - entries.add(entryOf(key, value)); - return this; - } - - /** - * Associates all of the given map's keys and values in the built map. - * Duplicate keys are not allowed, and will cause {@link #build} to fail. - * - * @throws NullPointerException if any key or value in {@code map} is null - */ - public Builder putAll(Map map) { - for (Entry entry : map.entrySet()) { - put(entry.getKey(), entry.getValue()); - } - return this; - } - - // TODO: Should build() and the ImmutableBiMap & ImmutableSortedMap versions - // throw an IllegalStateException instead? - - /** - * Returns a newly-created immutable map. - * - * @throws IllegalArgumentException if duplicate keys were added - */ - public ImmutableMap build() { - return fromEntryList(entries); - } - - private static ImmutableMap fromEntryList( - List> entries) { - int size = entries.size(); - switch (size) { - case 0: - return of(); - case 1: - return new SingletonImmutableMap(getOnlyElement(entries)); - default: - Entry[] entryArray - = entries.toArray(new Entry[entries.size()]); - return new RegularImmutableMap(entryArray); - } - } - } - - /** - * Returns an immutable map containing the same entries as {@code map}. If - * {@code map} somehow contains entries with duplicate keys (for example, if - * it is a {@code SortedMap} whose comparator is not consistent with - * equals), the results of this method are undefined. - * - *

Note: Despite what the method name suggests, if {@code map} is an - * {@code ImmutableMap}, no copy will actually be performed, and the given map - * itself will be returned. - * - * @throws NullPointerException if any key or value in {@code map} is null - */ - public static ImmutableMap copyOf( - Map map) { - if ((map instanceof ImmutableMap) && !(map instanceof ImmutableSortedMap)) { - @SuppressWarnings("unchecked") // safe since map is not writable - ImmutableMap kvMap = (ImmutableMap) map; - return kvMap; - } - - @SuppressWarnings("unchecked") // we won't write to this array - Entry[] entries = map.entrySet().toArray(new Entry[0]); - switch (entries.length) { - case 0: - return of(); - case 1: - return new SingletonImmutableMap(entryOf( - entries[0].getKey(), entries[0].getValue())); - default: - for (int i = 0; i < entries.length; i++) { - K k = entries[i].getKey(); - V v = entries[i].getValue(); - entries[i] = entryOf(k, v); - } - return new RegularImmutableMap(entries); - } - } - - ImmutableMap() {} - - /** - * Guaranteed to throw an exception and leave the map unmodified. - * - * @throws UnsupportedOperationException always - */ - public final V put(K k, V v) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the map unmodified. - * - * @throws UnsupportedOperationException always - */ - public final V remove(Object o) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the map unmodified. - * - * @throws UnsupportedOperationException always - */ - public final void putAll(Map map) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the map unmodified. - * - * @throws UnsupportedOperationException always - */ - public final void clear() { - throw new UnsupportedOperationException(); - } - - public boolean isEmpty() { - return size() == 0; - } - - public boolean containsKey(@Nullable Object key) { - return get(key) != null; - } - - // Overriding to mark it Nullable - public abstract boolean containsValue(@Nullable Object value); - - // Overriding to mark it Nullable - public abstract V get(@Nullable Object key); - - /** - * Returns an immutable set of the mappings in this map. The entries are in - * the same order as the parameters used to build this map. - */ - public abstract ImmutableSet> entrySet(); - - /** - * Returns an immutable set of the keys in this map. These keys are in - * the same order as the parameters used to build this map. - */ - public abstract ImmutableSet keySet(); - - /** - * Returns an immutable collection of the values in this map. The values are - * in the same order as the parameters used to build this map. - */ - public abstract ImmutableCollection values(); - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof Map) { - Map that = (Map) object; - return this.entrySet().equals(that.entrySet()); - } - return false; - } - - @Override public int hashCode() { - // not caching hash code since it could change if map values are mutable - // in a way that modifies their hash codes - return entrySet().hashCode(); - } - - @Override public String toString() { - StringBuilder result = new StringBuilder(size() * 16).append('{'); - Maps.standardJoiner.appendTo(result, this); - return result.append('}').toString(); - } - - /** - * Serialized type for all ImmutableMap instances. It captures the logical - * contents and they are reconstructed using public factory methods. This - * ensures that the implementation types remain as implementation details. - */ - static class SerializedForm implements Serializable { - private final Object[] keys; - private final Object[] values; - SerializedForm(ImmutableMap map) { - keys = new Object[map.size()]; - values = new Object[map.size()]; - int i = 0; - for (Entry entry : map.entrySet()) { - keys[i] = entry.getKey(); - values[i] = entry.getValue(); - i++; - } - } - Object readResolve() { - Builder builder = new Builder(); - return createMap(builder); - } - Object createMap(Builder builder) { - for (int i = 0; i < keys.length; i++) { - builder.put(keys[i], values[i]); - } - return builder.build(); - } - private static final long serialVersionUID = 0; - } - - Object writeReplace() { - return new SerializedForm(this); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMultimap.java deleted file mode 100644 index 6a71a7fd096..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMultimap.java +++ /dev/null @@ -1,509 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * An immutable {@link Multimap}. Does not permit null keys or values. - * - *

Unlike {@link Multimaps#unmodifiableMultimap(Multimap)}, which is - * a view of a separate multimap which can still change, an instance of - * {@code ImmutableMultimap} contains its own data and will never - * change. {@code ImmutableMultimap} is convenient for - * {@code public static final} multimaps ("constant multimaps") and also lets - * you easily make a "defensive copy" of a multimap provided to your class by - * a caller. - * - *

Note: Although this class is not final, it cannot be subclassed as - * it has no public or protected constructors. Thus, instances of this class - * are guaranteed to be immutable. - * - * @author Jared Levy - */ -@GwtCompatible -public abstract class ImmutableMultimap - implements Multimap, Serializable { - - /** Returns an empty multimap. */ - public static ImmutableMultimap of() { - return ImmutableListMultimap.of(); - } - - /** - * Returns an immutable multimap containing a single entry. - */ - public static ImmutableMultimap of(K k1, V v1) { - return ImmutableListMultimap.of(k1, v1); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - */ - public static ImmutableMultimap of(K k1, V v1, K k2, V v2) { - return ImmutableListMultimap.of(k1, v1, k2, v2); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - */ - public static ImmutableMultimap of( - K k1, V v1, K k2, V v2, K k3, V v3) { - return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - */ - public static ImmutableMultimap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3, k4, v4); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - */ - public static ImmutableMultimap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5); - } - - // looking for of() with > 5 entries? Use the builder instead. - - /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. - */ - public static Builder builder() { - return new Builder(); - } - - /** - * Multimap for {@link ImmutableMultimap.Builder} that maintains key and - * value orderings, allows duplicate values, and performs better than - * {@link LinkedListMultimap}. - */ - private static class BuilderMultimap extends AbstractMultimap { - BuilderMultimap() { - super(new LinkedHashMap>()); - } - @Override Collection createCollection() { - return Lists.newArrayList(); - } - private static final long serialVersionUID = 0; - } - - /** - * A builder for creating immutable multimap instances, especially - * {@code public static final} multimaps ("constant multimaps"). Example: - *

   {@code
-   *
-   *   static final Multimap STRING_TO_INTEGER_MULTIMAP =
-   *       new ImmutableMultimap.Builder()
-   *           .put("one", 1)
-   *           .putAll("several", 1, 2, 3)
-   *           .putAll("many", 1, 2, 3, 4, 5)
-   *           .build();}
- * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple multimaps in series. Each multimap - * contains the key-value mappings in the previously created multimaps. - */ - public static class Builder { - private final Multimap builderMultimap = new BuilderMultimap(); - - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableMultimap#builder}. - */ - public Builder() {} - - /** - * Adds a key-value mapping to the built multimap. - */ - public Builder put(K key, V value) { - builderMultimap.put(checkNotNull(key), checkNotNull(value)); - return this; - } - - /** - * Stores a collection of values with the same key in the built multimap. - * - * @throws NullPointerException if {@code key}, {@code values}, or any - * element in {@code values} is null. The builder is left in an invalid - * state. - */ - public Builder putAll(K key, Iterable values) { - Collection valueList = builderMultimap.get(checkNotNull(key)); - for (V value : values) { - valueList.add(checkNotNull(value)); - } - return this; - } - - /** - * Stores an array of values with the same key in the built multimap. - * - * @throws NullPointerException if the key or any value is null. The builder - * is left in an invalid state. - */ - public Builder putAll(K key, V... values) { - return putAll(key, Arrays.asList(values)); - } - - /** - * Stores another multimap's entries in the built multimap. The generated - * multimap's key and value orderings correspond to the iteration ordering - * of the {@code multimap.asMap()} view, with new keys and values following - * any existing keys and values. - * - * @throws NullPointerException if any key or value in {@code multimap} is - * null. The builder is left in an invalid state. - */ - public Builder putAll(Multimap multimap) { - for (Map.Entry> entry - : multimap.asMap().entrySet()) { - putAll(entry.getKey(), entry.getValue()); - } - return this; - } - - /** - * Returns a newly-created immutable multimap. - */ - public ImmutableMultimap build() { - return copyOf(builderMultimap); - } - } - - /** - * Returns an immutable multimap containing the same mappings as - * {@code multimap}. The generated multimap's key and value orderings - * correspond to the iteration ordering of the {@code multimap.asMap()} view. - * - *

Note: Despite what the method name suggests, if - * {@code multimap} is an {@code ImmutableMultimap}, no copy will actually be - * performed, and the given multimap itself will be returned. - * - * @throws NullPointerException if any key or value in {@code multimap} is - * null - */ - public static ImmutableMultimap copyOf( - Multimap multimap) { - if (multimap instanceof ImmutableMultimap) { - @SuppressWarnings("unchecked") // safe since multimap is not writable - ImmutableMultimap kvMultimap - = (ImmutableMultimap) multimap; - return kvMultimap; - } else { - return ImmutableListMultimap.copyOf(multimap); - } - } - - final transient ImmutableMap> map; - final transient int size; - - // These constants allow the deserialization code to set final fields. This - // holder class makes sure they are not initialized unless an instance is - // deserialized. - static class FieldSettersHolder { - // Eclipse doesn't like the raw ImmutableMultimap - @SuppressWarnings("unchecked") - static final Serialization.FieldSetter - MAP_FIELD_SETTER = Serialization.getFieldSetter( - ImmutableMultimap.class, "map"); - // Eclipse doesn't like the raw ImmutableMultimap - @SuppressWarnings("unchecked") - static final Serialization.FieldSetter - SIZE_FIELD_SETTER = Serialization.getFieldSetter( - ImmutableMultimap.class, "size"); - } - - ImmutableMultimap(ImmutableMap> map, - int size) { - this.map = map; - this.size = size; - } - - // mutators (not supported) - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - public ImmutableCollection removeAll(Object key) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - public ImmutableCollection replaceValues(K key, - Iterable values) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - public void clear() { - throw new UnsupportedOperationException(); - } - - /** - * Returns an immutable collection of the values for the given key. If no - * mappings in the multimap have the provided key, an empty immutable - * collection is returned. The values are in the same order as the parameters - * used to build this multimap. - */ - public abstract ImmutableCollection get(K key); - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - public boolean put(K key, V value) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - public boolean putAll(K key, Iterable values) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - public boolean putAll(Multimap multimap) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - public boolean remove(Object key, Object value) { - throw new UnsupportedOperationException(); - } - - // accessors - - public boolean containsEntry(@Nullable Object key, @Nullable Object value) { - Collection values = map.get(key); - return values != null && values.contains(value); - } - - public boolean containsKey(@Nullable Object key) { - return map.containsKey(key); - } - - public boolean containsValue(@Nullable Object value) { - for (Collection valueCollection : map.values()) { - if (valueCollection.contains(value)) { - return true; - } - } - return false; - } - - public boolean isEmpty() { - return size == 0; - } - - public int size() { - return size; - } - - @Override public boolean equals(@Nullable Object object) { - if (object instanceof Multimap) { - Multimap that = (Multimap) object; - return this.map.equals(that.asMap()); - } - return false; - } - - @Override public int hashCode() { - return map.hashCode(); - } - - @Override public String toString() { - return map.toString(); - } - - // views - - /** - * Returns an immutable set of the distinct keys in this multimap. These keys - * are ordered according to when they first appeared during the construction - * of this multimap. - */ - public ImmutableSet keySet() { - return map.keySet(); - } - - /** - * Returns an immutable map that associates each key with its corresponding - * values in the multimap. - */ - @SuppressWarnings("unchecked") // a widening cast - public ImmutableMap> asMap() { - return (ImmutableMap) map; - } - - private transient ImmutableCollection> entries; - - /** - * Returns an immutable collection of all key-value pairs in the multimap. Its - * iterator traverses the values for the first key, the values for the second - * key, and so on. - */ - public ImmutableCollection> entries() { - ImmutableCollection> result = entries; - return (result == null) - ? (entries = new EntryCollection(this)) : result; - } - - private static class EntryCollection - extends ImmutableCollection> { - final ImmutableMultimap multimap; - - EntryCollection(ImmutableMultimap multimap) { - this.multimap = multimap; - } - - @Override public UnmodifiableIterator> iterator() { - final Iterator>> - mapIterator = this.multimap.map.entrySet().iterator(); - - return new UnmodifiableIterator>() { - K key; - Iterator valueIterator; - - public boolean hasNext() { - return (key != null && valueIterator.hasNext()) - || mapIterator.hasNext(); - } - - public Map.Entry next() { - if (key == null || !valueIterator.hasNext()) { - Map.Entry> entry - = mapIterator.next(); - key = entry.getKey(); - valueIterator = entry.getValue().iterator(); - } - return Maps.immutableEntry(key, valueIterator.next()); - } - }; - } - - public int size() { - return multimap.size(); - } - - @Override public boolean contains(Object object) { - if (object instanceof Map.Entry) { - Map.Entry entry = (Map.Entry) object; - return multimap.containsEntry(entry.getKey(), entry.getValue()); - } - return false; - } - - private static final long serialVersionUID = 0; - } - - private transient ImmutableMultiset keys; - - /** - * Returns a collection, which may contain duplicates, of all keys. The number - * of times a key appears in the returned multiset equals the number of - * mappings the key has in the multimap. Duplicate keys appear consecutively - * in the multiset's iteration order. - */ - public ImmutableMultiset keys() { - ImmutableMultiset result = keys; - return (result == null) ? (keys = createKeys()) : result; - } - - private ImmutableMultiset createKeys() { - ImmutableMultiset.Builder builder = ImmutableMultiset.builder(); - for (Map.Entry> entry - : map.entrySet()) { - builder.addCopies(entry.getKey(), entry.getValue().size()); - } - return builder.build(); - } - - private transient ImmutableCollection values; - - /** - * Returns an immutable collection of the values in this multimap. Its - * iterator traverses the values for the first key, the values for the second - * key, and so on. - */ - public ImmutableCollection values() { - ImmutableCollection result = values; - return (result == null) ? (values = new Values(this)) : result; - } - - private static class Values extends ImmutableCollection { - final Multimap multimap; - - Values(Multimap multimap) { - this.multimap = multimap; - } - - @Override public UnmodifiableIterator iterator() { - final Iterator> entryIterator - = multimap.entries().iterator(); - return new UnmodifiableIterator() { - public boolean hasNext() { - return entryIterator.hasNext(); - } - public V next() { - return entryIterator.next().getValue(); - } - }; - } - - public int size() { - return multimap.size(); - } - - private static final long serialVersionUID = 0; - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMultiset.java deleted file mode 100644 index bbca79b3cdb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableMultiset.java +++ /dev/null @@ -1,502 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.collect.Serialization.FieldSetter; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * An immutable hash-based multiset. Does not permit null elements. - * - *

Its iterator orders elements according to the first appearance of the - * element among the items passed to the factory method or builder. When the - * multiset contains multiple instances of an element, those instances are - * consecutive in the iteration order. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -public class ImmutableMultiset extends ImmutableCollection - implements Multiset { - - /** - * Returns the empty immutable multiset. - */ - @SuppressWarnings("unchecked") // all supported methods are covariant - public static ImmutableMultiset of() { - return (ImmutableMultiset) EmptyImmutableMultiset.INSTANCE; - } - - /** - * Returns an immutable multiset containing the given elements. - * - *

The multiset is ordered by the first occurrence of each element. For - * example, {@code ImmutableMultiset.of(2, 3, 1, 3)} yields a multiset with - * elements in the order {@code 2, 3, 3, 1}. - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableMultiset of(E... elements) { - return copyOf(Arrays.asList(elements)); - } - - /** - * Returns an immutable multiset containing the given elements. - * - *

The multiset is ordered by the first occurrence of each element. For - * example, {@code ImmutableMultiset.copyOf(Arrays.asList(2, 3, 1, 3))} yields - * a multiset with elements in the order {@code 2, 3, 3, 1}. - * - *

Note that if {@code c} is a {@code Collection}, then {@code - * ImmutableMultiset.copyOf(c)} returns an {@code ImmutableMultiset} - * containing each of the strings in {@code c}, while - * {@code ImmutableMultiset.of(c)} returns an - * {@code ImmutableMultiset>} containing one element (the - * given collection itself). - * - *

Note: Despite what the method name suggests, if {@code elements} - * is an {@code ImmutableMultiset}, no copy will actually be performed, and - * the given multiset itself will be returned. - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableMultiset copyOf( - Iterable elements) { - if (elements instanceof ImmutableMultiset) { - @SuppressWarnings("unchecked") // all supported methods are covariant - ImmutableMultiset result = (ImmutableMultiset) elements; - return result; - } - - @SuppressWarnings("unchecked") // the cast causes a warning - Multiset multiset = (elements instanceof Multiset) - ? (Multiset) elements - : LinkedHashMultiset.create(elements); - - return copyOfInternal(multiset); - } - - private static ImmutableMultiset copyOfInternal( - Multiset multiset) { - long size = 0; - ImmutableMap.Builder builder = ImmutableMap.builder(); - - for (Entry entry : multiset.entrySet()) { - int count = entry.getCount(); - if (count > 0) { - // Since ImmutableMap.Builder throws an NPE if an element is null, no - // other null checks are needed. - builder.put(entry.getElement(), count); - size += count; - } - } - - if (size == 0) { - return of(); - } - return new ImmutableMultiset( - builder.build(), (int) Math.min(size, Integer.MAX_VALUE)); - } - - /** - * Returns an immutable multiset containing the given elements. - * - *

The multiset is ordered by the first occurrence of each element. For - * example, - * {@code ImmutableMultiset.copyOf(Arrays.asList(2, 3, 1, 3).iterator())} - * yields a multiset with elements in the order {@code 2, 3, 3, 1}. - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableMultiset copyOf( - Iterator elements) { - Multiset multiset = LinkedHashMultiset.create(); - Iterators.addAll(multiset, elements); - return copyOfInternal(multiset); - } - - private final transient ImmutableMap map; - private final transient int size; - - // These constants allow the deserialization code to set final fields. This - // holder class makes sure they are not initialized unless an instance is - // deserialized. - @SuppressWarnings("unchecked") - // eclipse doesn't like the raw types here, but they're harmless - private static class FieldSettersHolder { - static final FieldSetter MAP_FIELD_SETTER - = Serialization.getFieldSetter(ImmutableMultiset.class, "map"); - static final FieldSetter SIZE_FIELD_SETTER - = Serialization.getFieldSetter(ImmutableMultiset.class, "size"); - } - - ImmutableMultiset(ImmutableMap map, int size) { - this.map = map; - this.size = size; - } - - public int count(@Nullable Object element) { - Integer value = map.get(element); - return (value == null) ? 0 : value; - } - - @Override public UnmodifiableIterator iterator() { - final Iterator> mapIterator - = map.entrySet().iterator(); - - return new UnmodifiableIterator() { - int remaining; - E element; - - public boolean hasNext() { - return (remaining > 0) || mapIterator.hasNext(); - } - - public E next() { - if (remaining <= 0) { - Map.Entry entry = mapIterator.next(); - element = entry.getKey(); - remaining = entry.getValue(); - } - remaining--; - return element; - } - }; - } - - public int size() { - return size; - } - - @Override public boolean contains(@Nullable Object element) { - return map.containsKey(element); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public int add(E element, int occurrences) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public int remove(Object element, int occurrences) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public int setCount(E element, int count) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the collection unmodified. - * - * @throws UnsupportedOperationException always - */ - public boolean setCount(E element, int oldCount, int newCount) { - throw new UnsupportedOperationException(); - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof Multiset) { - Multiset that = (Multiset) object; - if (this.size() != that.size()) { - return false; - } - for (Entry entry : that.entrySet()) { - if (count(entry.getElement()) != entry.getCount()) { - return false; - } - } - return true; - } - return false; - } - - @Override public int hashCode() { - // could cache this, but not considered worthwhile to do so - return map.hashCode(); - } - - @Override public String toString() { - return entrySet().toString(); - } - - // TODO: Serialization of the element set should serialize the multiset, and - // deserialization should call multiset.elementSet(). Then - // reserialized(multiset).elementSet() == reserialized(multiset.elementSet()) - // Currently, those object references differ. - public Set elementSet() { - return map.keySet(); - } - - private transient ImmutableSet> entrySet; - - public Set> entrySet() { - ImmutableSet> es = entrySet; - return (es == null) ? (entrySet = new EntrySet(this)) : es; - } - - private static class EntrySet extends ImmutableSet> { - final ImmutableMultiset multiset; - - public EntrySet(ImmutableMultiset multiset) { - this.multiset = multiset; - } - - @Override public UnmodifiableIterator> iterator() { - final Iterator> mapIterator - = multiset.map.entrySet().iterator(); - return new UnmodifiableIterator>() { - public boolean hasNext() { - return mapIterator.hasNext(); - } - public Entry next() { - Map.Entry mapEntry = mapIterator.next(); - return - Multisets.immutableEntry(mapEntry.getKey(), mapEntry.getValue()); - } - }; - } - - public int size() { - return multiset.map.size(); - } - - @Override public boolean contains(Object o) { - if (o instanceof Entry) { - Entry entry = (Entry) o; - if (entry.getCount() <= 0) { - return false; - } - int count = multiset.count(entry.getElement()); - return count == entry.getCount(); - } - return false; - } - - @Override public int hashCode() { - return multiset.map.hashCode(); - } - - @Override Object writeReplace() { - return this; - } - - private static final long serialVersionUID = 0; - } - - /** - * @serialData the number of distinct elements, the first element, its count, - * the second element, its count, and so on - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - Serialization.writeMultiset(this, stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - int entryCount = stream.readInt(); - ImmutableMap.Builder builder = ImmutableMap.builder(); - long tmpSize = 0; - for (int i = 0; i < entryCount; i++) { - @SuppressWarnings("unchecked") // reading data stored by writeMultiset - E element = (E) stream.readObject(); - int count = stream.readInt(); - if (count <= 0) { - throw new InvalidObjectException("Invalid count " + count); - } - builder.put(element, count); - tmpSize += count; - } - - FieldSettersHolder.MAP_FIELD_SETTER.set(this, builder.build()); - FieldSettersHolder.SIZE_FIELD_SETTER.set( - this, (int) Math.min(tmpSize, Integer.MAX_VALUE)); - } - - @Override Object writeReplace() { - return this; - } - - private static final long serialVersionUID = 0; - - /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. - */ - public static Builder builder() { - return new Builder(); - } - - /** - * A builder for creating immutable multiset instances, especially - * {@code public static final} multisets ("constant multisets"). - * - *

Example: - *

   {@code
-   *   public static final ImmutableMultiset BEANS
-   *       = new ImmutableMultiset.Builder()
-   *           .addCopies(Bean.COCOA, 4)
-   *           .addCopies(Bean.GARDEN, 6)
-   *           .addCopies(Bean.RED, 8)
-   *           .addCopies(Bean.BLACK_EYED, 10)
-   *           .build();}
- * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple multisets in series. Each multiset - * is a superset of the multiset created before it. - */ - public static final class Builder extends ImmutableCollection.Builder { - private final Multiset contents = LinkedHashMultiset.create(); - - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableMultiset#builder}. - */ - public Builder() {} - - /** - * Adds {@code element} to the {@code ImmutableMultiset}. - * - * @param element the element to add - * @return this {@code Builder} object - * @throws NullPointerException if {@code element} is null - */ - @Override public Builder add(E element) { - contents.add(checkNotNull(element)); - return this; - } - - /** - * Adds a number of occurrences of an element to this {@code - * ImmutableMultiset}. - * - * @param element the element to add - * @param occurrences the number of occurrences of the element to add. May - * be zero, in which case no change will be made. - * @return this {@code Builder} object - * @throws NullPointerException if {@code element} is null - * @throws IllegalArgumentException if {@code occurrences} is negative, or - * if this operation would result in more than {@link Integer#MAX_VALUE} - * occurrences of the element - */ - public Builder addCopies(E element, int occurrences) { - contents.add(checkNotNull(element), occurrences); - return this; - } - - /** - * Adds or removes the necessary occurrences of an element such that the - * element attains the desired count. - * - * @param element the element to add or remove occurrences of - * @param count the desired count of the element in this multiset - * @return this {@code Builder} object - * @throws NullPointerException if {@code element} is null - * @throws IllegalArgumentException if {@code count} is negative - */ - public Builder setCount(E element, int count) { - contents.setCount(checkNotNull(element), count); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableMultiset}. - * - * @param elements the elements to add - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - @Override public Builder add(E... elements) { - super.add(elements); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableMultiset}. - * - * @param elements the {@code Iterable} to add to the {@code - * ImmutableMultiset} - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - @Override public Builder addAll(Iterable elements) { - if (elements instanceof Multiset) { - @SuppressWarnings("unchecked") - Multiset multiset = (Multiset) elements; - for (Entry entry : multiset.entrySet()) { - addCopies(entry.getElement(), entry.getCount()); - } - } else { - super.addAll(elements); - } - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableMultiset}. - * - * @param elements the elements to add to the {@code ImmutableMultiset} - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - @Override public Builder addAll(Iterator elements) { - super.addAll(elements); - return this; - } - - /** - * Returns a newly-created {@code ImmutableMultiset} based on the contents - * of the {@code Builder}. - */ - @Override public ImmutableMultiset build() { - return copyOf(contents); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSet.java deleted file mode 100644 index 8e3913cf06f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSet.java +++ /dev/null @@ -1,529 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * A high-performance, immutable {@code Set} with reliable, user-specified - * iteration order. Does not permit null elements. - * - *

Unlike {@link Collections#unmodifiableSet}, which is a view of a - * separate collection that can still change, an instance of this class contains - * its own private data and will never change. This class is convenient - * for {@code public static final} sets ("constant sets") and also lets you - * easily make a "defensive copy" of a set provided to your class by a caller. - * - *

Warning: Like most sets, an {@code ImmutableSet} will not function - * correctly if an element is modified after being placed in the set. For this - * reason, and to avoid general confusion, it is strongly recommended to place - * only immutable objects into this collection. - * - *

This class has been observed to perform significantly better than {@link - * HashSet} for objects with very fast {@link Object#hashCode} implementations - * (as a well-behaved immutable object should). While this class's factory - * methods create hash-based instances, the {@link ImmutableSortedSet} subclass - * performs binary searches instead. - * - *

Note: Although this class is not final, it cannot be subclassed - * outside its package as it has no public or protected constructors. Thus, - * instances of this type are guaranteed to be immutable. - * - * @see ImmutableList - * @see ImmutableMap - * @author Kevin Bourrillion - * @author Nick Kralevich - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // we're overriding default serialization -public abstract class ImmutableSet extends ImmutableCollection - implements Set { - /** - * Returns the empty immutable set. This set behaves and performs comparably - * to {@link Collections#emptySet}, and is preferable mainly for consistency - * and maintainability of your code. - */ - // Casting to any type is safe because the set will never hold any elements. - @SuppressWarnings({"unchecked"}) - public static ImmutableSet of() { - return (ImmutableSet) EmptyImmutableSet.INSTANCE; - } - - /** - * Returns an immutable set containing a single element. This set behaves and - * performs comparably to {@link Collections#singleton}, but will not accept - * a null element. It is preferable mainly for consistency and - * maintainability of your code. - */ - public static ImmutableSet of(E element) { - return new SingletonImmutableSet(element); - } - - /** - * Returns an immutable set containing the given elements, in order. Repeated - * occurrences of an element (according to {@link Object#equals}) after the - * first are ignored. - * - * @throws NullPointerException if any element is null - */ - @SuppressWarnings("unchecked") - public static ImmutableSet of(E e1, E e2) { - return create(e1, e2); - } - - /** - * Returns an immutable set containing the given elements, in order. Repeated - * occurrences of an element (according to {@link Object#equals}) after the - * first are ignored. - * - * @throws NullPointerException if any element is null - */ - @SuppressWarnings("unchecked") - public static ImmutableSet of(E e1, E e2, E e3) { - return create(e1, e2, e3); - } - - /** - * Returns an immutable set containing the given elements, in order. Repeated - * occurrences of an element (according to {@link Object#equals}) after the - * first are ignored. - * - * @throws NullPointerException if any element is null - */ - @SuppressWarnings("unchecked") - public static ImmutableSet of(E e1, E e2, E e3, E e4) { - return create(e1, e2, e3, e4); - } - - /** - * Returns an immutable set containing the given elements, in order. Repeated - * occurrences of an element (according to {@link Object#equals}) after the - * first are ignored. - * - * @throws NullPointerException if any element is null - */ - @SuppressWarnings("unchecked") - public static ImmutableSet of(E e1, E e2, E e3, E e4, E e5) { - return create(e1, e2, e3, e4, e5); - } - - /** - * Returns an immutable set containing the given elements, in order. Repeated - * occurrences of an element (according to {@link Object#equals}) after the - * first are ignored (but too many of these may result in the set being - * sized inappropriately). - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableSet of(E... elements) { - checkNotNull(elements); // for GWT - switch (elements.length) { - case 0: - return of(); - case 1: - return of(elements[0]); - default: - return create(elements); - } - } - - /** - * Returns an immutable set containing the given elements, in order. Repeated - * occurrences of an element (according to {@link Object#equals}) after the - * first are ignored (but too many of these may result in the set being - * sized inappropriately). This method iterates over {@code elements} at most - * once. - * - *

Note that if {@code s} is a {@code Set}, then {@code - * ImmutableSet.copyOf(s)} returns an {@code ImmutableSet} containing - * each of the strings in {@code s}, while {@code ImmutableSet.of(s)} returns - * a {@code ImmutableSet>} containing one element (the given set - * itself). - * - *

Note: Despite what the method name suggests, if {@code elements} - * is an {@code ImmutableSet} (but not an {@code ImmutableSortedSet}), no copy - * will actually be performed, and the given set itself will be returned. - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableSet copyOf(Iterable elements) { - if (elements instanceof ImmutableSet - && !(elements instanceof ImmutableSortedSet)) { - @SuppressWarnings("unchecked") // all supported methods are covariant - ImmutableSet set = (ImmutableSet) elements; - return set; - } - return copyOfInternal(Collections2.toCollection(elements)); - } - - /** - * Returns an immutable set containing the given elements, in order. Repeated - * occurrences of an element (according to {@link Object#equals}) after the - * first are ignored. - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableSet copyOf(Iterator elements) { - Collection list = Lists.newArrayList(elements); - return copyOfInternal(list); - } - - private static ImmutableSet copyOfInternal( - Collection collection) { - // TODO: Support concurrent collections that change while this method is - // running. - switch (collection.size()) { - case 0: - return of(); - case 1: - // TODO: Remove "ImmutableSet." when eclipse bug is fixed. - return ImmutableSet.of(collection.iterator().next()); - default: - return create(collection, collection.size()); - } - } - - ImmutableSet() {} - - /** Returns {@code true} if the {@code hashCode()} method runs quickly. */ - boolean isHashCodeFast() { - return false; - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof ImmutableSet - && isHashCodeFast() - && ((ImmutableSet) object).isHashCodeFast() - && hashCode() != object.hashCode()) { - return false; - } - return Collections2.setEquals(this, object); - } - - @Override public int hashCode() { - int hashCode = 0; - for (Object o : this) { - hashCode += o.hashCode(); - } - return hashCode; - } - - // This declaration is needed to make Set.iterator() and - // ImmutableCollection.iterator() consistent. - @Override public abstract UnmodifiableIterator iterator(); - - private static ImmutableSet create(E... elements) { - return create(Arrays.asList(elements), elements.length); - } - - private static ImmutableSet create( - Iterable iterable, int count) { - // count is always the (nonzero) number of elements in the iterable - int tableSize = Hashing.chooseTableSize(count); - Object[] table = new Object[tableSize]; - int mask = tableSize - 1; - - List elements = new ArrayList(count); - int hashCode = 0; - - for (E element : iterable) { - checkNotNull(element); // for GWT - int hash = element.hashCode(); - for (int i = Hashing.smear(hash); true; i++) { - int index = i & mask; - Object value = table[index]; - if (value == null) { - // Came to an empty bucket. Put the element here. - table[index] = element; - elements.add(element); - hashCode += hash; - break; - } else if (value.equals(element)) { - break; // Found a duplicate. Nothing to do. - } - } - } - - if (elements.size() == 1) { - // The iterable contained only duplicates of the same element. - return new SingletonImmutableSet(elements.get(0), hashCode); - } else if (tableSize > Hashing.chooseTableSize(elements.size())) { - // Resize the table when the iterable includes too many duplicates. - return create(elements, elements.size()); - } else { - return new RegularImmutableSet( - elements.toArray(), hashCode, table, mask); - } - } - - abstract static class ArrayImmutableSet extends ImmutableSet { - // the elements (two or more) in the desired order. - final transient Object[] elements; - - ArrayImmutableSet(Object[] elements) { - this.elements = elements; - } - - public int size() { - return elements.length; - } - - @Override public boolean isEmpty() { - return false; - } - - /* - * The cast is safe because the only way to create an instance is via the - * create() method above, which only permits elements of type E. - */ - @SuppressWarnings("unchecked") - @Override public UnmodifiableIterator iterator() { - return (UnmodifiableIterator) Iterators.forArray(elements); - } - - @Override public Object[] toArray() { - Object[] array = new Object[size()]; - System.arraycopy(elements, 0, array, 0, size()); - return array; - } - - @Override public T[] toArray(T[] array) { - int size = size(); - if (array.length < size) { - array = ObjectArrays.newArray(array, size); - } else if (array.length > size) { - array[size] = null; - } - System.arraycopy(elements, 0, array, 0, size); - return array; - } - - @Override public boolean containsAll(Collection targets) { - if (targets == this) { - return true; - } - if (!(targets instanceof ArrayImmutableSet)) { - return super.containsAll(targets); - } - if (targets.size() > size()) { - return false; - } - for (Object target : ((ArrayImmutableSet) targets).elements) { - if (!contains(target)) { - return false; - } - } - return true; - } - } - - /** such as ImmutableMap.keySet() */ - abstract static class TransformedImmutableSet extends ImmutableSet { - final D[] source; - final int hashCode; - - TransformedImmutableSet(D[] source, int hashCode) { - this.source = source; - this.hashCode = hashCode; - } - - abstract E transform(D element); - - public int size() { - return source.length; - } - - @Override public boolean isEmpty() { - return false; - } - - @Override public UnmodifiableIterator iterator() { - return new AbstractIterator() { - int index = 0; - @Override protected E computeNext() { - return index < source.length - ? transform(source[index++]) - : endOfData(); - } - }; - } - - @Override public Object[] toArray() { - return toArray(new Object[size()]); - } - - @Override public T[] toArray(T[] array) { - int size = size(); - if (array.length < size) { - array = ObjectArrays.newArray(array, size); - } else if (array.length > size) { - array[size] = null; - } - - // Writes will produce ArrayStoreException when the toArray() doc requires. - Object[] objectArray = array; - for (int i = 0; i < source.length; i++) { - objectArray[i] = transform(source[i]); - } - return array; - } - - @Override public final int hashCode() { - return hashCode; - } - - @Override boolean isHashCodeFast() { - return true; - } - } - - /* - * This class is used to serialize all ImmutableSet instances, except for - * ImmutableEnumSet/ImmutableSortedSet, regardless of implementation type. It - * captures their "logical contents" and they are reconstructed using public - * static factories. This is necessary to ensure that the existence of a - * particular implementation type is an implementation detail. - */ - private static class SerializedForm implements Serializable { - final Object[] elements; - SerializedForm(Object[] elements) { - this.elements = elements; - } - Object readResolve() { - return of(elements); - } - private static final long serialVersionUID = 0; - } - - @Override Object writeReplace() { - return new SerializedForm(toArray()); - } - - /** - * Returns a new builder. The generated builder is equivalent to the builder - * created by the {@link Builder} constructor. - */ - public static Builder builder() { - return new Builder(); - } - - /** - * A builder for creating immutable set instances, especially - * {@code public static final} sets ("constant sets"). - * - *

Example: - *

{@code
-   *   public static final ImmutableSet GOOGLE_COLORS
-   *       = new ImmutableSet.Builder()
-   *           .addAll(WEBSAFE_COLORS)
-   *           .add(new Color(0, 191, 255))
-   *           .build();}
- * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple sets in series. Each set - * is a superset of the set created before it. - */ - public static class Builder extends ImmutableCollection.Builder { - // accessed directly by ImmutableSortedSet - final ArrayList contents = Lists.newArrayList(); - - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableSet#builder}. - */ - public Builder() {} - - /** - * Adds {@code element} to the {@code ImmutableSet}. If the {@code - * ImmutableSet} already contains {@code element}, then {@code add} has no - * effect (only the previously added element is retained). - * - * @param element the element to add - * @return this {@code Builder} object - * @throws NullPointerException if {@code element} is null - */ - @Override public Builder add(E element) { - contents.add(checkNotNull(element)); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableSet}, - * ignoring duplicate elements (only the first duplicate element is added). - * - * @param elements the elements to add - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - @Override public Builder add(E... elements) { - checkNotNull(elements); // for GWT - contents.ensureCapacity(contents.size() + elements.length); - super.add(elements); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableSet}, - * ignoring duplicate elements (only the first duplicate element is added). - * - * @param elements the {@code Iterable} to add to the {@code ImmutableSet} - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - @Override public Builder addAll(Iterable elements) { - if (elements instanceof Collection) { - Collection collection = (Collection) elements; - contents.ensureCapacity(contents.size() + collection.size()); - } - super.addAll(elements); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableSet}, - * ignoring duplicate elements (only the first duplicate element is added). - * - * @param elements the elements to add to the {@code ImmutableSet} - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} is null or contains a - * null element - */ - @Override public Builder addAll(Iterator elements) { - super.addAll(elements); - return this; - } - - /** - * Returns a newly-created {@code ImmutableSet} based on the contents of - * the {@code Builder}. - */ - @Override public ImmutableSet build() { - return copyOf(contents); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSetMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSetMultimap.java deleted file mode 100644 index af9e7628751..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSetMultimap.java +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * An immutable {@link SetMultimap} with reliable user-specified key and value - * iteration order. Does not permit null keys or values. - * - *

Unlike {@link Multimaps#unmodifiableSetMultimap(SetMultimap)}, which is - * a view of a separate multimap which can still change, an instance of - * {@code ImmutableSetMultimap} contains its own data and will never - * change. {@code ImmutableSetMultimap} is convenient for - * {@code public static final} multimaps ("constant multimaps") and also lets - * you easily make a "defensive copy" of a multimap provided to your class by - * a caller. - * - *

Note: Although this class is not final, it cannot be subclassed as - * it has no public or protected constructors. Thus, instances of this class - * are guaranteed to be immutable. - * - * @author Mike Ward - */ -@GwtCompatible(serializable = true) -public class ImmutableSetMultimap - extends ImmutableMultimap - implements SetMultimap { - - /** Returns the empty multimap. */ - // Casting is safe because the multimap will never hold any elements. - @SuppressWarnings("unchecked") - public static ImmutableSetMultimap of() { - return (ImmutableSetMultimap) EmptyImmutableSetMultimap.INSTANCE; - } - - /** - * Returns an immutable multimap containing a single entry. - */ - public static ImmutableSetMultimap of(K k1, V v1) { - ImmutableSetMultimap.Builder builder = ImmutableSetMultimap.builder(); - builder.put(k1, v1); - return builder.build(); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - * Repeated occurrences of an entry (according to {@link Object#equals}) after - * the first are ignored. - */ - public static ImmutableSetMultimap of(K k1, V v1, K k2, V v2) { - ImmutableSetMultimap.Builder builder = ImmutableSetMultimap.builder(); - builder.put(k1, v1); - builder.put(k2, v2); - return builder.build(); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - * Repeated occurrences of an entry (according to {@link Object#equals}) after - * the first are ignored. - */ - public static ImmutableSetMultimap of( - K k1, V v1, K k2, V v2, K k3, V v3) { - ImmutableSetMultimap.Builder builder = ImmutableSetMultimap.builder(); - builder.put(k1, v1); - builder.put(k2, v2); - builder.put(k3, v3); - return builder.build(); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - * Repeated occurrences of an entry (according to {@link Object#equals}) after - * the first are ignored. - */ - public static ImmutableSetMultimap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - ImmutableSetMultimap.Builder builder = ImmutableSetMultimap.builder(); - builder.put(k1, v1); - builder.put(k2, v2); - builder.put(k3, v3); - builder.put(k4, v4); - return builder.build(); - } - - /** - * Returns an immutable multimap containing the given entries, in order. - * Repeated occurrences of an entry (according to {@link Object#equals}) after - * the first are ignored. - */ - public static ImmutableSetMultimap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - ImmutableSetMultimap.Builder builder = ImmutableSetMultimap.builder(); - builder.put(k1, v1); - builder.put(k2, v2); - builder.put(k3, v3); - builder.put(k4, v4); - builder.put(k5, v5); - return builder.build(); - } - - // looking for of() with > 5 entries? Use the builder instead. - - /** - * Returns a new {@link Builder}. - */ - public static Builder builder() { - return new Builder(); - } - - /** - * Multimap for {@link ImmutableSetMultimap.Builder} that maintains key - * and value orderings and performs better than {@link LinkedHashMultimap}. - */ - private static class BuilderMultimap extends AbstractMultimap { - BuilderMultimap() { - super(new LinkedHashMap>()); - } - @Override Collection createCollection() { - return Sets.newLinkedHashSet(); - } - private static final long serialVersionUID = 0; - } - - /** - * A builder for creating immutable {@code SetMultimap} instances, especially - * {@code public static final} multimaps ("constant multimaps"). Example: - *

   {@code
-   *
-   *   static final Multimap STRING_TO_INTEGER_MULTIMAP =
-   *       new ImmutableSetMultimap.Builder()
-   *           .put("one", 1)
-   *           .putAll("several", 1, 2, 3)
-   *           .putAll("many", 1, 2, 3, 4, 5)
-   *           .build();}
- * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple multimaps in series. Each multimap - * contains the key-value mappings in the previously created multimaps. - */ - public static final class Builder - extends ImmutableMultimap.Builder { - private final Multimap builderMultimap = new BuilderMultimap(); - - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableSetMultimap#builder}. - */ - public Builder() {} - - /** - * Adds a key-value mapping to the built multimap if it is not already - * present. - */ - @Override public Builder put(K key, V value) { - builderMultimap.put(checkNotNull(key), checkNotNull(value)); - return this; - } - - /** - * Stores a collection of values with the same key in the built multimap. - * - * @throws NullPointerException if {@code key}, {@code values}, or any - * element in {@code values} is null. The builder is left in an invalid - * state. - */ - @Override public Builder putAll(K key, Iterable values) { - Collection collection = builderMultimap.get(checkNotNull(key)); - for (V value : values) { - collection.add(checkNotNull(value)); - } - return this; - } - - /** - * Stores an array of values with the same key in the built multimap. - * - * @throws NullPointerException if the key or any value is null. The - * builder is left in an invalid state. - */ - @Override public Builder putAll(K key, V... values) { - return putAll(key, Arrays.asList(values)); - } - - /** - * Stores another multimap's entries in the built multimap. The generated - * multimap's key and value orderings correspond to the iteration ordering - * of the {@code multimap.asMap()} view, with new keys and values following - * any existing keys and values. - * - * @throws NullPointerException if any key or value in {@code multimap} is - * null. The builder is left in an invalid state. - */ - @Override public Builder putAll( - Multimap multimap) { - for (Map.Entry> entry - : multimap.asMap().entrySet()) { - putAll(entry.getKey(), entry.getValue()); - } - return this; - } - - /** - * Returns a newly-created immutable set multimap. - */ - @Override public ImmutableSetMultimap build() { - return copyOf(builderMultimap); - } - } - - /** - * Returns an immutable set multimap containing the same mappings as - * {@code multimap}. The generated multimap's key and value orderings - * correspond to the iteration ordering of the {@code multimap.asMap()} view. - * Repeated occurrences of an entry in the multimap after the first are - * ignored. - * - *

Note: Despite what the method name suggests, if - * {@code multimap} is an {@code ImmutableSetMultimap}, no copy will actually - * be performed, and the given multimap itself will be returned. - * - * @throws NullPointerException if any key or value in {@code multimap} is - * null - */ - public static ImmutableSetMultimap copyOf( - Multimap multimap) { - if (multimap.isEmpty()) { - return of(); - } - - if (multimap instanceof ImmutableSetMultimap) { - @SuppressWarnings("unchecked") // safe since multimap is not writable - ImmutableSetMultimap kvMultimap - = (ImmutableSetMultimap) multimap; - return kvMultimap; - } - - ImmutableMap.Builder> builder = ImmutableMap.builder(); - int size = 0; - - for (Map.Entry> entry - : multimap.asMap().entrySet()) { - K key = entry.getKey(); - Collection values = entry.getValue(); - ImmutableSet set = ImmutableSet.copyOf(values); - if (!set.isEmpty()) { - builder.put(key, set); - size += set.size(); - } - } - - return new ImmutableSetMultimap(builder.build(), size); - } - - ImmutableSetMultimap(ImmutableMap> map, int size) { - super(map, size); - } - - // views - - /** - * Returns an immutable set of the values for the given key. If no mappings - * in the multimap have the provided key, an empty immutable set is returned. - * The values are in the same order as the parameters used to build this - * multimap. - */ - @Override public ImmutableSet get(@Nullable K key) { - // This cast is safe as its type is known in constructor. - ImmutableSet set = (ImmutableSet) map.get(key); - return (set == null) ? ImmutableSet.of() : set; - } - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - @Override public ImmutableSet removeAll(Object key) { - throw new UnsupportedOperationException(); - } - - /** - * Guaranteed to throw an exception and leave the multimap unmodified. - * - * @throws UnsupportedOperationException always - */ - @Override public ImmutableSet replaceValues( - K key, Iterable values) { - throw new UnsupportedOperationException(); - } - - private transient ImmutableSet> entries; - - /** - * Returns an immutable collection of all key-value pairs in the multimap. - * Its iterator traverses the values for the first key, the values for the - * second key, and so on. - */ - // TODO: Fix this so that two copies of the entries are not created. - @Override public ImmutableSet> entries() { - ImmutableSet> result = entries; - return (result == null) - ? (entries = ImmutableSet.copyOf(super.entries())) - : result; - } - - /** - * @serialData number of distinct keys, and then for each distinct key: the - * key, the number of values for that key, and the key's values - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - Serialization.writeMultimap(this, stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - int keyCount = stream.readInt(); - if (keyCount < 0) { - throw new InvalidObjectException("Invalid key count " + keyCount); - } - ImmutableMap.Builder> builder - = ImmutableMap.builder(); - int tmpSize = 0; - - for (int i = 0; i < keyCount; i++) { - Object key = stream.readObject(); - int valueCount = stream.readInt(); - if (valueCount <= 0) { - throw new InvalidObjectException("Invalid value count " + valueCount); - } - - Object[] array = new Object[valueCount]; - for (int j = 0; j < valueCount; j++) { - array[j] = stream.readObject(); - } - ImmutableSet valueSet = ImmutableSet.of(array); - if (valueSet.size() != array.length) { - throw new InvalidObjectException( - "Duplicate key-value pairs exist for key " + key); - } - builder.put(key, valueSet); - tmpSize += valueCount; - } - - ImmutableMap> tmpMap; - try { - tmpMap = builder.build(); - } catch (IllegalArgumentException e) { - throw (InvalidObjectException) - new InvalidObjectException(e.getMessage()).initCause(e); - } - - FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap); - FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedMap.java deleted file mode 100644 index c2de8cf7aac..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedMap.java +++ /dev/null @@ -1,686 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * An immutable {@link SortedMap}. Does not permit null keys or values. - * - *

Unlike {@link Collections#unmodifiableSortedMap}, which is a view - * of a separate map which can still change, an instance of {@code - * ImmutableSortedMap} contains its own data and will never change. - * {@code ImmutableSortedMap} is convenient for {@code public static final} maps - * ("constant maps") and also lets you easily make a "defensive copy" of a map - * provided to your class by a caller. - * - *

Note: Although this class is not final, it cannot be subclassed as - * it has no public or protected constructors. Thus, instances of this class are - * guaranteed to be immutable. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -public class ImmutableSortedMap - extends ImmutableSortedMapFauxverideShim implements SortedMap { - - // TODO: Confirm that ImmutableSortedMap is faster to construct and uses less - // memory than TreeMap; then say so in the class Javadoc. - - // TODO: Create separate subclasses for empty, single-entry, and - // multiple-entry instances. - - @SuppressWarnings("unchecked") - private static final Comparator NATURAL_ORDER = Ordering.natural(); - private static final Entry[] EMPTY_ARRAY = new Entry[0]; - - @SuppressWarnings("unchecked") - private static final ImmutableMap NATURAL_EMPTY_MAP - = new ImmutableSortedMap(EMPTY_ARRAY, NATURAL_ORDER); - - /** - * Returns the empty sorted map. - */ - // Casting to any type is safe because the set will never hold any elements. - @SuppressWarnings("unchecked") - public static ImmutableSortedMap of() { - return (ImmutableSortedMap) NATURAL_EMPTY_MAP; - } - - private static ImmutableSortedMap emptyMap( - Comparator comparator) { - if (NATURAL_ORDER.equals(comparator)) { - return ImmutableSortedMap.of(); - } else { - return new ImmutableSortedMap(EMPTY_ARRAY, comparator); - } - } - - /** - * Returns an immutable map containing a single entry. - */ - public static , V> ImmutableSortedMap - of(K k1, V v1) { - Entry[] entries = { entryOf(k1, v1) }; - return new ImmutableSortedMap(entries, Ordering.natural()); - } - - /** - * Returns an immutable sorted map containing the given entries, sorted by the - * natural ordering of their keys. - * - * @throws IllegalArgumentException if the two keys are equal according to - * their natural ordering - */ - public static , V> ImmutableSortedMap - of(K k1, V v1, K k2, V v2) { - return new Builder(Ordering.natural()) - .put(k1, v1).put(k2, v2).build(); - } - - /** - * Returns an immutable sorted map containing the given entries, sorted by the - * natural ordering of their keys. - * - * @throws IllegalArgumentException if any two keys are equal according to - * their natural ordering - */ - public static , V> ImmutableSortedMap - of(K k1, V v1, K k2, V v2, K k3, V v3) { - return new Builder(Ordering.natural()) - .put(k1, v1).put(k2, v2).put(k3, v3).build(); - } - - /** - * Returns an immutable sorted map containing the given entries, sorted by the - * natural ordering of their keys. - * - * @throws IllegalArgumentException if any two keys are equal according to - * their natural ordering - */ - public static , V> ImmutableSortedMap - of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - return new Builder(Ordering.natural()) - .put(k1, v1).put(k2, v2).put(k3, v3).put(k4, v4).build(); - } - - /** - * Returns an immutable sorted map containing the given entries, sorted by the - * natural ordering of their keys. - * - * @throws IllegalArgumentException if any two keys are equal according to - * their natural ordering - */ - public static , V> ImmutableSortedMap - of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - return new Builder(Ordering.natural()) - .put(k1, v1).put(k2, v2).put(k3, v3).put(k4, v4).put(k5, v5).build(); - } - - /** - * Returns an immutable map containing the same entries as {@code map}, sorted - * by the natural ordering of the keys. - * - *

Note: Despite what the method name suggests, if {@code map} is an - * {@code ImmutableSortedMap}, it may be returned instead of a copy. - * - *

This method is not type-safe, as it may be called on a map with keys - * that are not mutually comparable. - * - * @throws ClassCastException if the keys in {@code map} are not mutually - * comparable - * @throws NullPointerException if any key or value in {@code map} is null - * @throws IllegalArgumentException if any two keys are equal according to - * their natural ordering - */ - public static ImmutableSortedMap copyOf( - Map map) { - // Hack around K not being a subtype of Comparable. - // Unsafe, see ImmutableSortedSetFauxverideShim. - @SuppressWarnings("unchecked") - Ordering naturalOrder = (Ordering) Ordering.natural(); - return copyOfInternal(map, naturalOrder); - } - - /** - * Returns an immutable map containing the same entries as {@code map}, with - * keys sorted by the provided comparator. - * - *

Note: Despite what the method name suggests, if {@code map} is an - * {@code ImmutableSortedMap}, it may be returned instead of a copy. - * - * @throws NullPointerException if any key or value in {@code map} is null - * @throws IllegalArgumentException if any two keys are equal according to - * the comparator - */ - public static ImmutableSortedMap copyOf( - Map map, Comparator comparator) { - return copyOfInternal(map, checkNotNull(comparator)); - } - - /** - * Returns an immutable map containing the same entries as the provided sorted - * map, with the same ordering. - * - *

Note: Despite what the method name suggests, if {@code map} is an - * {@code ImmutableSortedMap}, it may be returned instead of a copy. - * - * @throws NullPointerException if any key or value in {@code map} is null - */ - public static ImmutableSortedMap copyOfSorted( - SortedMap map) { - // If map has a null comparator, the keys should have a natural ordering, - // even though K doesn't explicitly implement Comparable. - @SuppressWarnings("unchecked") - Comparator comparator = - (map.comparator() == null) ? NATURAL_ORDER : map.comparator(); - return copyOfInternal(map, comparator); - } - - private static ImmutableSortedMap copyOfInternal( - Map map, Comparator comparator) { - boolean sameComparator = false; - if (map instanceof SortedMap) { - SortedMap sortedMap = (SortedMap) map; - Comparator comparator2 = sortedMap.comparator(); - sameComparator = (comparator2 == null) - ? comparator == NATURAL_ORDER - : comparator.equals(comparator2); - } - - if (sameComparator && (map instanceof ImmutableSortedMap)) { - // TODO: Prove that this cast is safe, even though - // Collections.unmodifiableSortedMap requires the same key type. - @SuppressWarnings("unchecked") - ImmutableSortedMap kvMap = (ImmutableSortedMap) map; - return kvMap; - } - - // Using List to support concurrent map whose size changes - List> list = Lists.newArrayListWithCapacity(map.size()); - for (Entry entry : map.entrySet()) { - list.add(entryOf(entry.getKey(), entry.getValue())); - } - Entry[] entryArray = list.toArray(new Entry[list.size()]); - - if (!sameComparator) { - sortEntries(entryArray, comparator); - validateEntries(entryArray, comparator); - } - - return new ImmutableSortedMap(entryArray, comparator); - } - - private static void sortEntries(Entry[] entryArray, - final Comparator comparator) { - Comparator> entryComparator = new Comparator>() { - public int compare(Entry entry1, Entry entry2) { - return ImmutableSortedSet.unsafeCompare( - comparator, entry1.getKey(), entry2.getKey()); - } - }; - Arrays.sort(entryArray, entryComparator); - } - - private static void validateEntries(Entry[] entryArray, - Comparator comparator) { - for (int i = 1; i < entryArray.length; i++) { - if (ImmutableSortedSet.unsafeCompare(comparator, - entryArray[i - 1].getKey(), entryArray[i].getKey()) == 0) { - throw new IllegalArgumentException( - "Duplicate keys in mappings " - + entryArray[i - 1] + " and " + entryArray[i]); - } - } - } - - /** - * Returns a builder that creates immutable sorted maps whose keys are - * ordered by their natural ordering. The sorted maps use {@link - * Ordering#natural()} as the comparator. - * - *

Note: the type parameter {@code K} extends {@code Comparable} rather - * than {@code Comparable} as a workaround for javac bug - * 6468354. - */ - public static , V> Builder naturalOrder() { - return new Builder(Ordering.natural()); - } - - /** - * Returns a builder that creates immutable sorted maps with an explicit - * comparator. If the comparator has a more general type than the map's keys, - * such as creating a {@code SortedMap} with a {@code - * Comparator}, use the {@link Builder} constructor instead. - * - * @throws NullPointerException if {@code comparator} is null - */ - public static Builder orderedBy(Comparator comparator) { - return new Builder(comparator); - } - - /** - * Returns a builder that creates immutable sorted maps whose keys are - * ordered by the reverse of their natural ordering. - * - *

Note: the type parameter {@code K} extends {@code Comparable} rather - * than {@code Comparable} as a workaround for javac bug - * 6468354. - */ - public static , V> Builder reverseOrder() { - return new Builder(Ordering.natural().reverse()); - } - - /** - * A builder for creating immutable sorted map instances, especially {@code - * public static final} maps ("constant maps"). Example:

   {@code
-   *
-   *   static final ImmutableSortedMap INT_TO_WORD =
-   *       new ImmutableSortedMap.Builder(Ordering.natural())
-   *           .put(1, "one")
-   *           .put(2, "two")
-   *           .put(3, "three")
-   *           .build();}
- * - * For small immutable sorted maps, the {@code ImmutableSortedMap.of()} - * methods are even more convenient. - * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple maps in series. Each map is a superset of - * the maps created before it. - */ - public static final class Builder extends ImmutableMap.Builder { - private final Comparator comparator; - - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableSortedMap#orderedBy}. - */ - public Builder(Comparator comparator) { - this.comparator = checkNotNull(comparator); - } - - /** - * Associates {@code key} with {@code value} in the built map. Duplicate - * keys, according to the comparator (which might be the keys' natural - * order), are not allowed, and will cause {@link #build} to fail. - */ - @Override public Builder put(K key, V value) { - entries.add(entryOf(key, value)); - return this; - } - - /** - * Associates all of the given map's keys and values in the built map. - * Duplicate keys, according to the comparator (which might be the keys' - * natural order), are not allowed, and will cause {@link #build} to fail. - * - * @throws NullPointerException if any key or value in {@code map} is null - */ - @Override public Builder putAll(Map map) { - for (Entry entry : map.entrySet()) { - put(entry.getKey(), entry.getValue()); - } - return this; - } - - /** - * Returns a newly-created immutable sorted map. - * - * @throws IllegalArgumentException if any two keys are equal according to - * the comparator (which might be the keys' natural order) - */ - @Override public ImmutableSortedMap build() { - Entry[] entryArray - = entries.toArray(new Entry[entries.size()]); - sortEntries(entryArray, comparator); - validateEntries(entryArray, comparator); - return new ImmutableSortedMap(entryArray, comparator); - } - } - - private final transient Entry[] entries; - private final transient Comparator comparator; - private final transient int fromIndex; - private final transient int toIndex; - - private ImmutableSortedMap(Entry[] entries, - Comparator comparator, int fromIndex, int toIndex) { - // each of the callers carefully put only Entrys into the array! - @SuppressWarnings("unchecked") - Entry[] tmp = (Entry[]) entries; - this.entries = tmp; - this.comparator = comparator; - this.fromIndex = fromIndex; - this.toIndex = toIndex; - } - - ImmutableSortedMap(Entry[] entries, - Comparator comparator) { - this(entries, comparator, 0, entries.length); - } - - public int size() { - return toIndex - fromIndex; - } - - @Override public V get(@Nullable Object key) { - if (key == null) { - return null; - } - int i; - try { - i = binarySearch(key); - } catch (ClassCastException e) { - return null; - } - return (i >= 0) ? entries[i].getValue() : null; - } - - private int binarySearch(Object key) { - int lower = fromIndex; - int upper = toIndex - 1; - - while (lower <= upper) { - int middle = lower + (upper - lower) / 2; - int c = ImmutableSortedSet.unsafeCompare( - comparator, key, entries[middle].getKey()); - if (c < 0) { - upper = middle - 1; - } else if (c > 0) { - lower = middle + 1; - } else { - return middle; - } - } - - return -lower - 1; - } - - @Override public boolean containsValue(@Nullable Object value) { - if (value == null) { - return false; - } - for (int i = fromIndex; i < toIndex; i++) { - if (entries[i].getValue().equals(value)) { - return true; - } - } - return false; - } - - private transient ImmutableSet> entrySet; - - /** - * Returns an immutable set of the mappings in this map, sorted by the key - * ordering. - */ - @Override public ImmutableSet> entrySet() { - ImmutableSet> es = entrySet; - return (es == null) ? (entrySet = createEntrySet()) : es; - } - - private ImmutableSet> createEntrySet() { - return isEmpty() ? ImmutableSet.>of() - : new EntrySet(this); - } - - @SuppressWarnings("serial") // uses writeReplace(), not default serialization - private static class EntrySet extends ImmutableSet> { - final transient ImmutableSortedMap map; - - EntrySet(ImmutableSortedMap map) { - this.map = map; - } - - public int size() { - return map.size(); - } - - @Override public UnmodifiableIterator> iterator() { - return Iterators.forArray(map.entries, map.fromIndex, size()); - } - - @Override public boolean contains(Object target) { - if (target instanceof Entry) { - Entry entry = (Entry) target; - V mappedValue = map.get(entry.getKey()); - return mappedValue != null && mappedValue.equals(entry.getValue()); - } - return false; - } - - @Override Object writeReplace() { - return new EntrySetSerializedForm(map); - } - } - - private static class EntrySetSerializedForm implements Serializable { - final ImmutableSortedMap map; - EntrySetSerializedForm(ImmutableSortedMap map) { - this.map = map; - } - Object readResolve() { - return map.entrySet(); - } - private static final long serialVersionUID = 0; - } - - private transient ImmutableSortedSet keySet; - - /** - * Returns an immutable sorted set of the keys in this map. - */ - @Override public ImmutableSortedSet keySet() { - ImmutableSortedSet ks = keySet; - return (ks == null) ? (keySet = createKeySet()) : ks; - } - - private ImmutableSortedSet createKeySet() { - if (isEmpty()) { - return ImmutableSortedSet.emptySet(comparator); - } - - // TODO: For better performance, don't create a separate array. - Object[] array = new Object[size()]; - for (int i = fromIndex; i < toIndex; i++) { - array[i - fromIndex] = entries[i].getKey(); - } - return new RegularImmutableSortedSet(array, comparator); - } - - private transient ImmutableCollection values; - - /** - * Returns an immutable collection of the values in this map, sorted by the - * ordering of the corresponding keys. - */ - @Override public ImmutableCollection values() { - ImmutableCollection v = values; - return (v == null) ? (values = new Values(this)) : v; - } - - @SuppressWarnings("serial") // uses writeReplace(), not default serialization - private static class Values extends ImmutableCollection { - private final ImmutableSortedMap map; - - Values(ImmutableSortedMap map) { - this.map = map; - } - - public int size() { - return map.size(); - } - - @Override public UnmodifiableIterator iterator() { - return new AbstractIterator() { - int index = map.fromIndex; - @Override protected V computeNext() { - return (index < map.toIndex) - ? map.entries[index++].getValue() - : endOfData(); - } - }; - } - - @Override public boolean contains(Object target) { - return map.containsValue(target); - } - - @Override Object writeReplace() { - return new ValuesSerializedForm(map); - } - } - - private static class ValuesSerializedForm implements Serializable { - final ImmutableSortedMap map; - ValuesSerializedForm(ImmutableSortedMap map) { - this.map = map; - } - Object readResolve() { - return map.values(); - } - private static final long serialVersionUID = 0; - } - - /** - * Returns the comparator that orders the keys, which is - * {@link Ordering#natural()} when the natural ordering of the keys is used. - * Note that its behavior is not consistent with {@link TreeMap#comparator()}, - * which returns {@code null} to indicate natural ordering. - */ - public Comparator comparator() { - return comparator; - } - - public K firstKey() { - if (isEmpty()) { - throw new NoSuchElementException(); - } - return entries[fromIndex].getKey(); - } - - public K lastKey() { - if (isEmpty()) { - throw new NoSuchElementException(); - } - return entries[toIndex - 1].getKey(); - } - - /** - * This method returns a {@code ImmutableSortedMap}, consisting of the entries - * whose keys are less than {@code toKey}. - * - *

The {@link SortedMap#headMap} documentation states that a submap of a - * submap throws an {@link IllegalArgumentException} if passed a {@code toKey} - * greater than an earlier {@code toKey}. However, this method doesn't throw - * an exception in that situation, but instead keeps the original {@code - * toKey}. - */ - public ImmutableSortedMap headMap(K toKey) { - int newToIndex = findSubmapIndex(checkNotNull(toKey)); - return createSubmap(fromIndex, newToIndex); - } - - /** - * This method returns a {@code ImmutableSortedMap}, consisting of the entries - * whose keys ranges from {@code fromKey}, inclusive, to {@code toKey}, - * exclusive. - * - *

The {@link SortedMap#subMap} documentation states that a submap of a - * submap throws an {@link IllegalArgumentException} if passed a {@code - * fromKey} less than an earlier {@code fromKey}. However, this method doesn't - * throw an exception in that situation, but instead keeps the original {@code - * fromKey}. Similarly, this method keeps the original {@code toKey}, instead - * of throwing an exception, if passed a {@code toKey} greater than an earlier - * {@code toKey}. - */ - public ImmutableSortedMap subMap(K fromKey, K toKey) { - checkNotNull(fromKey); - checkNotNull(toKey); - checkArgument(comparator.compare(fromKey, toKey) <= 0); - int newFromIndex = findSubmapIndex(fromKey); - int newToIndex = findSubmapIndex(toKey); - return createSubmap(newFromIndex, newToIndex); - } - - /** - * This method returns a {@code ImmutableSortedMap}, consisting of the entries - * whose keys are greater than or equals to {@code fromKey}. - * - *

The {@link SortedMap#tailMap} documentation states that a submap of a - * submap throws an {@link IllegalArgumentException} if passed a {@code - * fromKey} less than an earlier {@code fromKey}. However, this method doesn't - * throw an exception in that situation, but instead keeps the original {@code - * fromKey}. - */ - public ImmutableSortedMap tailMap(K fromKey) { - int newFromIndex = findSubmapIndex(checkNotNull(fromKey)); - return createSubmap(newFromIndex, toIndex); - } - - private int findSubmapIndex(K key) { - int index = binarySearch(key); - return (index >= 0) ? index : (-index - 1); - } - - private ImmutableSortedMap createSubmap( - int newFromIndex, int newToIndex) { - if (newFromIndex < newToIndex) { - return new ImmutableSortedMap(entries, comparator, - newFromIndex, newToIndex); - } else { - return emptyMap(comparator); - } - } - - /** - * Serialized type for all ImmutableSortedMap instances. It captures the - * logical contents and they are reconstructed using public factory methods. - * This ensures that the implementation types remain as implementation - * details. - */ - private static class SerializedForm extends ImmutableMap.SerializedForm { - private final Comparator comparator; - @SuppressWarnings("unchecked") - SerializedForm(ImmutableSortedMap sortedMap) { - super(sortedMap); - comparator = (Comparator) sortedMap.comparator(); - } - @Override Object readResolve() { - Builder builder = new Builder(comparator); - return createMap(builder); - } - private static final long serialVersionUID = 0; - } - - @Override Object writeReplace() { - return new SerializedForm(this); - } - - // This class is never actually serialized directly, but we have to make the - // warning go away (and suppressing would suppress for all nested classes too) - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedMapFauxverideShim.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedMapFauxverideShim.java deleted file mode 100644 index e7a01fbfebb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedMapFauxverideShim.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -/** - * "Overrides" the {@link ImmutableMap} static methods that lack - * {@link ImmutableSortedMap} equivalents with deprecated, exception-throwing - * versions. See {@link ImmutableSortedSetFauxverideShim} for details. - * - * @author Chris Povirk - */ -@GwtCompatible -abstract class ImmutableSortedMapFauxverideShim - extends ImmutableMap { - /** - * Not supported. Use {@link ImmutableSortedMap#naturalOrder}, which offers - * better type-safety, instead. This method exists only to hide - * {@link ImmutableMap#builder} from consumers of {@code ImmutableSortedMap}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedMap#naturalOrder}, which offers - * better type-safety. - */ - @Deprecated public static ImmutableSortedMap.Builder builder() { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a map that may contain a - * non-{@code Comparable} key. Proper calls will resolve to the version in - * {@code ImmutableSortedMap}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass a key of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object)}. - */ - @Deprecated public static ImmutableSortedMap of(K k1, V v1) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a map that may contain - * non-{@code Comparable} keys. Proper calls will resolve to the version - * in {@code ImmutableSortedMap}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object)}. - */ - @Deprecated public static ImmutableSortedMap of( - K k1, V v1, K k2, V v2) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a map that may contain - * non-{@code Comparable} keys. Proper calls to will resolve to the - * version in {@code ImmutableSortedMap}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, - * Comparable, Object)}. - */ - @Deprecated public static ImmutableSortedMap of( - K k1, V v1, K k2, V v2, K k3, V v3) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a map that may contain - * non-{@code Comparable} keys. Proper calls will resolve to the version - * in {@code ImmutableSortedMap}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, - * Comparable, Object, Comparable, Object)}. - */ - @Deprecated public static ImmutableSortedMap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a map that may contain - * non-{@code Comparable} keys. Proper calls will resolve to the version - * in {@code ImmutableSortedMap}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass keys of type {@code Comparable} to use {@link - * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, - * Comparable, Object, Comparable, Object, Comparable, Object)}. - */ - @Deprecated public static ImmutableSortedMap of( - K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - throw new UnsupportedOperationException(); - } - - // No copyOf() fauxveride; see ImmutableSortedSetFauxverideShim. -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedSet.java deleted file mode 100644 index cb40aed199e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedSet.java +++ /dev/null @@ -1,671 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * An immutable {@code SortedSet} that stores its elements in a sorted array. - * Some instances are ordered by an explicit comparator, while others follow the - * natural sort ordering of their elements. Either way, null elements are not - * supported. - * - *

Unlike {@link Collections#unmodifiableSortedSet}, which is a view - * of a separate collection that can still change, an instance of {@code - * ImmutableSortedSet} contains its own private data and will never - * change. This class is convenient for {@code public static final} sets - * ("constant sets") and also lets you easily make a "defensive copy" of a set - * provided to your class by a caller. - * - *

The sets returned by {@link #headSet}, {@link #tailSet}, and - * {@link #subSet} methods share the same array as the original set, preventing - * that array from being garbage collected. If this is a concern, the data may - * be copied into a correctly-sized array by calling {@link #copyOfSorted}. - * - *

Note on element equivalence: The {@link #contains(Object)}, - * {@link #containsAll(Collection)}, and {@link #equals(Object)} - * implementations must check whether a provided object is equivalent to an - * element in the collection. Unlike most collections, an - * {@code ImmutableSortedSet} doesn't use {@link Object#equals} to determine if - * two elements are equivalent. Instead, with an explicit comparator, the - * following relation determines whether elements {@code x} and {@code y} are - * equivalent:

   {@code
- *
- *   {(x, y) | comparator.compare(x, y) == 0}}
- * - * With natural ordering of elements, the following relation determines whether - * two elements are equivalent:
   {@code
- *
- *   {(x, y) | x.compareTo(y) == 0}}
- * - * Warning: Like most sets, an {@code ImmutableSortedSet} will not - * function correctly if an element is modified after being placed in the set. - * For this reason, and to avoid general confusion, it is strongly recommended - * to place only immutable objects into this collection. - * - *

Note: Although this class is not final, it cannot be subclassed as - * it has no public or protected constructors. Thus, instances of this type are - * guaranteed to be immutable. - * - * @see ImmutableSet - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // we're overriding default serialization -public abstract class ImmutableSortedSet - extends ImmutableSortedSetFauxverideShim implements SortedSet { - - // TODO: Can we find a way to remove this @SuppressWarnings even for eclipse? - @SuppressWarnings("unchecked") - private static final Comparator NATURAL_ORDER = Ordering.natural(); - - @SuppressWarnings("unchecked") - private static final ImmutableSortedSet NATURAL_EMPTY_SET = - new EmptyImmutableSortedSet(NATURAL_ORDER); - - @SuppressWarnings("unchecked") - private static ImmutableSortedSet emptySet() { - return (ImmutableSortedSet) NATURAL_EMPTY_SET; - } - - static ImmutableSortedSet emptySet( - Comparator comparator) { - if (NATURAL_ORDER.equals(comparator)) { - return emptySet(); - } else { - return new EmptyImmutableSortedSet(comparator); - } - } - - /** - * Returns the empty immutable sorted set. - */ - public static ImmutableSortedSet of() { - return emptySet(); - } - - /** - * Returns an immutable sorted set containing a single element. - */ - public static > ImmutableSortedSet of( - E element) { - Object[] array = { checkNotNull(element) }; - return new RegularImmutableSortedSet(array, Ordering.natural()); - } - - /** - * Returns an immutable sorted set containing the given elements sorted by - * their natural ordering. When multiple elements are equivalent according to - * {@link Comparable#compareTo}, only the first one specified is included. - * - * @throws NullPointerException if any element is null - */ - @SuppressWarnings("unchecked") - public static > ImmutableSortedSet of( - E e1, E e2) { - return ofInternal(Ordering.natural(), e1, e2); - } - - /** - * Returns an immutable sorted set containing the given elements sorted by - * their natural ordering. When multiple elements are equivalent according to - * {@link Comparable#compareTo}, only the first one specified is included. - * - * @throws NullPointerException if any element is null - */ - @SuppressWarnings("unchecked") - public static > ImmutableSortedSet of( - E e1, E e2, E e3) { - return ofInternal(Ordering.natural(), e1, e2, e3); - } - - /** - * Returns an immutable sorted set containing the given elements sorted by - * their natural ordering. When multiple elements are equivalent according to - * {@link Comparable#compareTo}, only the first one specified is included. - * - * @throws NullPointerException if any element is null - */ - @SuppressWarnings("unchecked") - public static > ImmutableSortedSet of( - E e1, E e2, E e3, E e4) { - return ofInternal(Ordering.natural(), e1, e2, e3, e4); - } - - /** - * Returns an immutable sorted set containing the given elements sorted by - * their natural ordering. When multiple elements are equivalent according to - * {@link Comparable#compareTo}, only the first one specified is included. - * - * @throws NullPointerException if any element is null - */ - @SuppressWarnings("unchecked") - public static > ImmutableSortedSet of( - E e1, E e2, E e3, E e4, E e5) { - return ofInternal(Ordering.natural(), e1, e2, e3, e4, e5); - } - - // TODO: Consider adding factory methods that throw an exception when given - // duplicate elements. - - /** - * Returns an immutable sorted set containing the given elements sorted by - * their natural ordering. When multiple elements are equivalent according to - * {@link Comparable#compareTo}, only the first one specified is included. - * - * @throws NullPointerException if any of {@code elements} is null - */ - public static > ImmutableSortedSet of( - E... elements) { - return ofInternal(Ordering.natural(), elements); - } - - private static ImmutableSortedSet ofInternal( - Comparator comparator, E... elements) { - checkNotNull(elements); // for GWT - switch (elements.length) { - case 0: - return emptySet(comparator); - default: - /* - * We can't use Platform.clone() because of GWT bug 3621. See our GWT - * ImmutableSortedSetTest.testOf_gwtArraycopyBug() for details. We can't - * use System.arraycopy() here for the same reason. - */ - Object[] array = new Object[elements.length]; - for (int i = 0; i < elements.length; i++) { - array[i] = checkNotNull(elements[i]); - } - sort(array, comparator); - array = removeDupes(array, comparator); - return new RegularImmutableSortedSet(array, comparator); - } - } - - /** Sort the array, according to the comparator. */ - @SuppressWarnings("unchecked") // E comparator with Object array - private static void sort( - Object[] array, Comparator comparator) { - Arrays.sort(array, (Comparator) comparator); - } - - /** - * Returns an array that removes duplicate consecutive elements, according to - * the provided comparator. Note that the input array is modified. This method - * does not support empty arrays. - */ - private static Object[] removeDupes(Object[] array, - Comparator comparator) { - int size = 1; - for (int i = 1; i < array.length; i++) { - Object element = array[i]; - if (unsafeCompare(comparator, array[size - 1], element) != 0) { - array[size] = element; - size++; - } - } - - // TODO: Move to ObjectArrays? - if (size == array.length) { - return array; - } else { - Object[] copy = new Object[size]; - System.arraycopy(array, 0, copy, 0, size); - return copy; - } - } - - /** - * Returns an immutable sorted set containing the given elements sorted by - * their natural ordering. When multiple elements are equivalent according to - * {@code compareTo()}, only the first one specified is included. To create a - * copy of a {@code SortedSet} that preserves the comparator, call - * {@link #copyOfSorted} instead. This method iterates over {@code elements} - * at most once. - * - *

Note that if {@code s} is a {@code Set}, then - * {@code ImmutableSortedSet.copyOf(s)} returns an - * {@code ImmutableSortedSet} containing each of the strings in - * {@code s}, while {@code ImmutableSortedSet.of(s)} returns an - * {@code ImmutableSortedSet>} containing one element (the given - * set itself). - * - *

Note: Despite what the method name suggests, if {@code elements} - * is an {@code ImmutableSortedSet}, it may be returned instead of a copy. - * - *

This method is not type-safe, as it may be called on elements that are - * not mutually comparable. - * - * @throws ClassCastException if the elements are not mutually comparable - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableSortedSet copyOf( - Iterable elements) { - // Hack around K not being a subtype of Comparable. - // Unsafe, see ImmutableSortedSetFauxverideShim. - @SuppressWarnings("unchecked") - Ordering naturalOrder = (Ordering) Ordering.natural(); - return copyOfInternal(naturalOrder, elements, false); - } - - /** - * Returns an immutable sorted set containing the given elements sorted by - * their natural ordering. When multiple elements are equivalent according to - * {@code compareTo()}, only the first one specified is included. - * - *

This method is not type-safe, as it may be called on elements that are - * not mutually comparable. - * - * @throws ClassCastException if the elements are not mutually comparable - * @throws NullPointerException if any of {@code elements} is null - */ - public static ImmutableSortedSet copyOf( - Iterator elements) { - // Hack around K not being a subtype of Comparable. - // Unsafe, see ImmutableSortedSetFauxverideShim. - @SuppressWarnings("unchecked") - Ordering naturalOrder = (Ordering) Ordering.natural(); - return copyOfInternal(naturalOrder, elements); - } - - /** - * Returns an immutable sorted set containing the given elements sorted by - * the given {@code Comparator}. When multiple elements are equivalent - * according to {@code compare()}, only the first one specified is - * included. This method iterates over {@code elements} at most once. - * - *

Note: Despite what the method name suggests, if {@code elements} - * is an {@code ImmutableSortedSet}, it may be returned instead of a copy. - * - * @throws NullPointerException if {@code comparator} or any of - * {@code elements} is null - */ - public static ImmutableSortedSet copyOf( - Comparator comparator, Iterable elements) { - checkNotNull(comparator); - return copyOfInternal(comparator, elements, false); - } - - /** - * Returns an immutable sorted set containing the given elements sorted by - * the given {@code Comparator}. When multiple elements are equivalent - * according to {@code compareTo()}, only the first one specified is - * included. - * - * @throws NullPointerException if {@code comparator} or any of - * {@code elements} is null - */ - public static ImmutableSortedSet copyOf( - Comparator comparator, Iterator elements) { - checkNotNull(comparator); - return copyOfInternal(comparator, elements); - } - - /** - * Returns an immutable sorted set containing the elements of a sorted set, - * sorted by the same {@code Comparator}. That behavior differs from - * {@link #copyOf(Iterable)}, which always uses the natural ordering of the - * elements. - * - *

Note: Despite what the method name suggests, if {@code sortedSet} - * is an {@code ImmutableSortedSet}, it may be returned instead of a copy. - * - * @throws NullPointerException if any of {@code elements} is null - */ - @SuppressWarnings("unchecked") - public static ImmutableSortedSet copyOfSorted(SortedSet sortedSet) { - Comparator comparator = sortedSet.comparator(); - if (comparator == null) { - comparator = NATURAL_ORDER; - } - return copyOfInternal(comparator, sortedSet, true); - } - - private static ImmutableSortedSet copyOfInternal( - Comparator comparator, Iterable elements, - boolean fromSortedSet) { - boolean hasSameComparator - = fromSortedSet || hasSameComparator(elements, comparator); - - if (hasSameComparator && (elements instanceof ImmutableSortedSet)) { - @SuppressWarnings("unchecked") - ImmutableSortedSet result = (ImmutableSortedSet) elements; - if (!result.hasPartialArray()) { - return result; - } - } - - Object[] array = newObjectArray(elements); - if (array.length == 0) { - return emptySet(comparator); - } - - for (Object e : array) { - checkNotNull(e); - } - if (!hasSameComparator) { - sort(array, comparator); - array = removeDupes(array, comparator); - } - return new RegularImmutableSortedSet(array, comparator); - } - - /** Simplified version of {@link Iterables#toArray} that is GWT safe. */ - private static Object[] newObjectArray(Iterable iterable) { - Collection collection = (iterable instanceof Collection) - ? (Collection) iterable : Lists.newArrayList(iterable); - Object[] array = new Object[collection.size()]; - return collection.toArray(array); - } - - private static ImmutableSortedSet copyOfInternal( - Comparator comparator, Iterator elements) { - if (!elements.hasNext()) { - return emptySet(comparator); - } - List list = Lists.newArrayList(); - while (elements.hasNext()) { - list.add(checkNotNull(elements.next())); - } - Object[] array = list.toArray(); - sort(array, comparator); - array = removeDupes(array, comparator); - return new RegularImmutableSortedSet(array, comparator); - } - - /** - * Returns {@code true} if {@code elements} is a {@code SortedSet} that uses - * {@code comparator} to order its elements. Note that equivalent comparators - * may still return {@code false}, if {@code equals} doesn't consider them - * equal. If one comparator is {@code null} and the other is - * {@link Ordering#natural()}, this method returns {@code true}. - */ - static boolean hasSameComparator( - Iterable elements, Comparator comparator) { - if (elements instanceof SortedSet) { - SortedSet sortedSet = (SortedSet) elements; - Comparator comparator2 = sortedSet.comparator(); - return (comparator2 == null) - ? comparator == Ordering.natural() - : comparator.equals(comparator2); - } - return false; - } - - /** - * Returns a builder that creates immutable sorted sets with an explicit - * comparator. If the comparator has a more general type than the set being - * generated, such as creating a {@code SortedSet} with a - * {@code Comparator}, use the {@link Builder} constructor instead. - * - * @throws NullPointerException if {@code comparator} is null - */ - public static Builder orderedBy(Comparator comparator) { - return new Builder(comparator); - } - - /** - * Returns a builder that creates immutable sorted sets whose elements are - * ordered by the reverse of their natural ordering. - * - *

Note: the type parameter {@code E} extends {@code Comparable} rather - * than {@code Comparable} as a workaround for javac bug - * 6468354. - */ - public static > Builder reverseOrder() { - return new Builder(Ordering.natural().reverse()); - } - - /** - * Returns a builder that creates immutable sorted sets whose elements are - * ordered by their natural ordering. The sorted sets use {@link - * Ordering#natural()} as the comparator. This method provides more - * type-safety than {@link #builder}, as it can be called only for classes - * that implement {@link Comparable}. - * - *

Note: the type parameter {@code E} extends {@code Comparable} rather - * than {@code Comparable} as a workaround for javac bug - * 6468354. - */ - public static > Builder naturalOrder() { - return new Builder(Ordering.natural()); - } - - /** - * A builder for creating immutable sorted set instances, especially - * {@code public static final} sets ("constant sets"), with a given - * comparator. - * - *

Example: - *

{@code
-   *   public static final ImmutableSortedSet LUCKY_NUMBERS
-   *       = new ImmutableSortedSet.Builder(ODDS_FIRST_COMPARATOR)
-   *           .addAll(SINGLE_DIGIT_PRIMES)
-   *           .add(42)
-   *           .build();}
- * - *

Builder instances can be reused - it is safe to call {@link #build} - * multiple times to build multiple sets in series. Each set - * is a superset of the set created before it. - */ - public static final class Builder extends ImmutableSet.Builder { - private final Comparator comparator; - - /** - * Creates a new builder. The returned builder is equivalent to the builder - * generated by {@link ImmutableSortedSet#orderedBy}. - */ - public Builder(Comparator comparator) { - this.comparator = checkNotNull(comparator); - } - - /** - * Adds {@code element} to the {@code ImmutableSortedSet}. If the - * {@code ImmutableSortedSet} already contains {@code element}, then - * {@code add} has no effect. (only the previously added element - * is retained). - * - * @param element the element to add - * @return this {@code Builder} object - * @throws NullPointerException if {@code element} is null - */ - @Override public Builder add(E element) { - super.add(element); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableSortedSet}, - * ignoring duplicate elements (only the first duplicate element is added). - * - * @param elements the elements to add - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} contains a null element - */ - @Override public Builder add(E... elements) { - super.add(elements); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableSortedSet}, - * ignoring duplicate elements (only the first duplicate element is added). - * - * @param elements the elements to add to the {@code ImmutableSortedSet} - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} contains a null element - */ - @Override public Builder addAll(Iterable elements) { - super.addAll(elements); - return this; - } - - /** - * Adds each element of {@code elements} to the {@code ImmutableSortedSet}, - * ignoring duplicate elements (only the first duplicate element is added). - * - * @param elements the elements to add to the {@code ImmutableSortedSet} - * @return this {@code Builder} object - * @throws NullPointerException if {@code elements} contains a null element - */ - @Override public Builder addAll(Iterator elements) { - super.addAll(elements); - return this; - } - - /** - * Returns a newly-created {@code ImmutableSortedSet} based on the contents - * of the {@code Builder} and its comparator. - */ - @Override public ImmutableSortedSet build() { - return copyOfInternal(comparator, contents.iterator()); - } - } - - int unsafeCompare(Object a, Object b) { - return unsafeCompare(comparator, a, b); - } - - static int unsafeCompare( - Comparator comparator, Object a, Object b) { - // Pretend the comparator can compare anything. If it turns out it can't - // compare a and b, we should get a CCE on the subsequent line. Only methods - // that are spec'd to throw CCE should call this. - @SuppressWarnings("unchecked") - Comparator unsafeComparator = (Comparator) comparator; - return unsafeComparator.compare(a, b); - } - - final transient Comparator comparator; - - ImmutableSortedSet(Comparator comparator) { - this.comparator = comparator; - } - - /** - * Returns the comparator that orders the elements, which is - * {@link Ordering#natural()} when the natural ordering of the - * elements is used. Note that its behavior is not consistent with - * {@link SortedSet#comparator()}, which returns {@code null} to indicate - * natural ordering. - */ - public Comparator comparator() { - return comparator; - } - - /** - * {@inheritDoc} - * - *

This method returns a serializable {@code ImmutableSortedSet}. - * - *

The {@link SortedSet#headSet} documentation states that a subset of a - * subset throws an {@link IllegalArgumentException} if passed a - * {@code toElement} greater than an earlier {@code toElement}. However, this - * method doesn't throw an exception in that situation, but instead keeps the - * original {@code toElement}. - */ - public ImmutableSortedSet headSet(E toElement) { - return headSetImpl(checkNotNull(toElement)); - } - - /** - * {@inheritDoc} - * - *

This method returns a serializable {@code ImmutableSortedSet}. - * - *

The {@link SortedSet#subSet} documentation states that a subset of a - * subset throws an {@link IllegalArgumentException} if passed a - * {@code fromElement} smaller than an earlier {@code fromElement}. However, - * this method doesn't throw an exception in that situation, but instead keeps - * the original {@code fromElement}. Similarly, this method keeps the - * original {@code toElement}, instead of throwing an exception, if passed a - * {@code toElement} greater than an earlier {@code toElement}. - */ - public ImmutableSortedSet subSet(E fromElement, E toElement) { - checkNotNull(fromElement); - checkNotNull(toElement); - checkArgument(comparator.compare(fromElement, toElement) <= 0); - return subSetImpl(fromElement, toElement); - } - - /** - * {@inheritDoc} - * - *

This method returns a serializable {@code ImmutableSortedSet}. - * - *

The {@link SortedSet#tailSet} documentation states that a subset of a - * subset throws an {@link IllegalArgumentException} if passed a - * {@code fromElement} smaller than an earlier {@code fromElement}. However, - * this method doesn't throw an exception in that situation, but instead keeps - * the original {@code fromElement}. - */ - public ImmutableSortedSet tailSet(E fromElement) { - return tailSetImpl(checkNotNull(fromElement)); - } - - /* - * These methods perform most headSet, subSet, and tailSet logic, besides - * parameter validation. - */ - abstract ImmutableSortedSet headSetImpl(E toElement); - abstract ImmutableSortedSet subSetImpl(E fromElement, E toElement); - abstract ImmutableSortedSet tailSetImpl(E fromElement); - - /** Returns whether the elements are stored in a subset of a larger array. */ - abstract boolean hasPartialArray(); - - /* - * This class is used to serialize all ImmutableSortedSet instances, - * regardless of implementation type. It captures their "logical contents" - * only. This is necessary to ensure that the existence of a particular - * implementation type is an implementation detail. - */ - private static class SerializedForm implements Serializable { - final Comparator comparator; - final Object[] elements; - - public SerializedForm(Comparator comparator, Object[] elements) { - this.comparator = comparator; - this.elements = elements; - } - - @SuppressWarnings("unchecked") - Object readResolve() { - return new Builder(comparator).add((E[]) elements).build(); - } - - private static final long serialVersionUID = 0; - } - - private void readObject(ObjectInputStream stream) - throws InvalidObjectException { - throw new InvalidObjectException("Use SerializedForm"); - } - - @Override Object writeReplace() { - return new SerializedForm(comparator, toArray()); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedSetFauxverideShim.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedSetFauxverideShim.java deleted file mode 100644 index 463e93b06e0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ImmutableSortedSetFauxverideShim.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -/** - * "Overrides" the {@link ImmutableSet} static methods that lack - * {@link ImmutableSortedSet} equivalents with deprecated, exception-throwing - * versions. This prevents accidents like the following:

   {@code
- *
- *   List objects = ...;
- *   // Sort them:
- *   Set sorted = ImmutableSortedSet.copyOf(objects);
- *   // BAD CODE! The returned set is actually an unsorted ImmutableSet!}
- *
- * 

While we could put the overrides in {@link ImmutableSortedSet} itself, it - * seems clearer to separate these "do not call" methods from those intended for - * normal use. - * - * @author Chris Povirk - */ -@GwtCompatible -abstract class ImmutableSortedSetFauxverideShim extends ImmutableSet { - /** - * Not supported. Use {@link ImmutableSortedSet#naturalOrder}, which offers - * better type-safety, instead. This method exists only to hide - * {@link ImmutableSet#builder} from consumers of {@code ImmutableSortedSet}. - * - * @throws UnsupportedOperationException always - * @deprecated Use {@link ImmutableSortedSet#naturalOrder}, which offers - * better type-safety. - */ - @Deprecated public static ImmutableSortedSet.Builder builder() { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a set that may contain a - * non-{@code Comparable} element. Proper calls will resolve to the - * version in {@code ImmutableSortedSet}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass a parameter of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable)}. - */ - @Deprecated public static ImmutableSortedSet of(E element) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a set that may contain a - * non-{@code Comparable} element. Proper calls will resolve to the - * version in {@code ImmutableSortedSet}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable, Comparable)}. - */ - @Deprecated public static ImmutableSortedSet of(E e1, E e2) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a set that may contain a - * non-{@code Comparable} element. Proper calls will resolve to the - * version in {@code ImmutableSortedSet}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable, Comparable, Comparable)}. - */ - @Deprecated public static ImmutableSortedSet of(E e1, E e2, E e3) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a set that may contain a - * non-{@code Comparable} element. Proper calls will resolve to the - * version in {@code ImmutableSortedSet}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable)}. - * - */ - @Deprecated public static ImmutableSortedSet of( - E e1, E e2, E e3, E e4) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a set that may contain a - * non-{@code Comparable} element. Proper calls will resolve to the - * version in {@code ImmutableSortedSet}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass the parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of( - * Comparable, Comparable, Comparable, Comparable, Comparable)}. - */ - @Deprecated public static ImmutableSortedSet of( - E e1, E e2, E e3, E e4, E e5) { - throw new UnsupportedOperationException(); - } - - /** - * Not supported. You are attempting to create a set that may contain - * non-{@code Comparable} elements. Proper calls will resolve to the - * version in {@code ImmutableSortedSet}, not this dummy version. - * - * @throws UnsupportedOperationException always - * @deprecated Pass parameters of type {@code Comparable} to use {@link - * ImmutableSortedSet#of(Comparable[])}. - */ - @Deprecated public static ImmutableSortedSet of(E... elements) { - throw new UnsupportedOperationException(); - } - - /* - * We would like to include an unsupported " copyOf(Iterable)" here, - * providing only the properly typed - * "> copyOf(Iterable)" in ImmutableSortedSet (and - * likewise for the Iterator equivalent). However, due to a change in Sun's - * interpretation of the JLS (as described at - * http://bugs.sun.com/view_bug.do?bug_id=6182950), the OpenJDK 7 compiler - * available as of this writing rejects our attempts. To maintain - * compatibility with that version and with any other compilers that interpret - * the JLS similarly, there is no definition of copyOf() here, and the - * definition in ImmutableSortedSet matches that in ImmutableSet. - * - * The result is that ImmutableSortedSet.copyOf() may be called on - * non-Comparable elements. We have not discovered a better solution. In - * retrospect, the static factory methods should have gone in a separate class - * so that ImmutableSortedSet wouldn't "inherit" too-permissive factory - * methods from ImmutableSet. - */ -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Iterables.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Iterables.java deleted file mode 100644 index 2fc2e7d861d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Iterables.java +++ /dev/null @@ -1,706 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; -import org.elasticsearch.util.base.Function; -import org.elasticsearch.util.base.Objects; -import org.elasticsearch.util.base.Preconditions; -import org.elasticsearch.util.base.Predicate; - -import javax.annotation.Nullable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * This class contains static utility methods that operate on or return objects - * of type {@code Iterable}. Except as noted, each method has a corresponding - * {@link Iterator}-based method in the {@link Iterators} class. - * - * @author Kevin Bourrillion - * @author Jared Levy - */ -@GwtCompatible -public final class Iterables { - private Iterables() {} - - /** Returns an unmodifiable view of {@code iterable}. */ - public static Iterable unmodifiableIterable(final Iterable iterable) - { - checkNotNull(iterable); - return new Iterable() { - public Iterator iterator() { - return Iterators.unmodifiableIterator(iterable.iterator()); - } - @Override public String toString() { - return iterable.toString(); - } - // no equals and hashCode; it would break the contract! - }; - } - - /** - * Returns the number of elements in {@code iterable}. - */ - public static int size(Iterable iterable) { - return (iterable instanceof Collection) - ? ((Collection) iterable).size() - : Iterators.size(iterable.iterator()); - } - - /** - * Returns {@code true} if {@code iterable} contains {@code element}; that is, - * any object for while {@code equals(element)} is true. - */ - public static boolean contains(Iterable iterable, @Nullable Object element) - { - if (iterable instanceof Collection) { - Collection collection = (Collection) iterable; - try { - return collection.contains(element); - } catch (NullPointerException e) { - return false; - } catch (ClassCastException e) { - return false; - } - } - return Iterators.contains(iterable.iterator(), element); - } - - /** - * Removes, from an iterable, every element that belongs to the provided - * collection. - * - *

This method calls {@link Collection#removeAll} if {@code iterable} is a - * collection, and {@link Iterators#removeAll} otherwise. - * - * @param removeFrom the iterable to (potentially) remove elements from - * @param elementsToRemove the elements to remove - * @return {@code true} if any elements are removed from {@code iterable} - */ - public static boolean removeAll( - Iterable removeFrom, Collection elementsToRemove) { - return (removeFrom instanceof Collection) - ? ((Collection) removeFrom).removeAll(checkNotNull(elementsToRemove)) - : Iterators.removeAll(removeFrom.iterator(), elementsToRemove); - } - - /** - * Removes, from an iterable, every element that does not belong to the - * provided collection. - * - *

This method calls {@link Collection#retainAll} if {@code iterable} is a - * collection, and {@link Iterators#retainAll} otherwise. - * - * @param removeFrom the iterable to (potentially) remove elements from - * @param elementsToRetain the elements to retain - * @return {@code true} if any elements are removed from {@code iterable} - */ - public static boolean retainAll( - Iterable removeFrom, Collection elementsToRetain) { - return (removeFrom instanceof Collection) - ? ((Collection) removeFrom).retainAll(checkNotNull(elementsToRetain)) - : Iterators.retainAll(removeFrom.iterator(), elementsToRetain); - } - - /** - * Removes, from an iterable, every element that satisfies the provided - * predicate. - * - * @param removeFrom the iterable to (potentially) remove elements from - * @param predicate a predicate that determines whether an element should - * be removed - * @return {@code true} if any elements were removed from the iterable - * - * @throws UnsupportedOperationException if the iterable does not support - * {@code remove()}. - */ - static boolean removeIf( - Iterable removeFrom, Predicate predicate) { - if (removeFrom instanceof RandomAccess && removeFrom instanceof List) { - return removeIfFromRandomAccessList( - (List) removeFrom, checkNotNull(predicate)); - } - return Iterators.removeIf(removeFrom.iterator(), predicate); - } - - private static boolean removeIfFromRandomAccessList( - List list, Predicate predicate) { - int from = 0; - int to = 0; - - for (; from < list.size(); from++) { - T element = list.get(from); - if (!predicate.apply(element)) { - if (from > to) { - list.set(to, element); - } - to++; - } - } - - // Clear the tail of any remaining items - // Note: hand-written GWT-compatible version of - // list.subList(to, list.size()).clear(); - ListIterator iter = list.listIterator(list.size()); - for (int idx = from - to; idx > 0; idx--) { - iter.previous(); - iter.remove(); - } - - return from != to; - } - - /** - * Determines whether two iterables contain equal elements in the same order. - * More specifically, this method returns {@code true} if {@code iterable1} - * and {@code iterable2} contain the same number of elements and every element - * of {@code iterable1} is equal to the corresponding element of - * {@code iterable2}. - */ - public static boolean elementsEqual( - Iterable iterable1, Iterable iterable2) { - return Iterators.elementsEqual(iterable1.iterator(), iterable2.iterator()); - } - - /** - * Returns a string representation of {@code iterable}, with the format - * {@code [e1, e2, ..., en]}. - */ - public static String toString(Iterable iterable) { - return Iterators.toString(iterable.iterator()); - } - - /** - * Returns the single element contained in {@code iterable}. - * - * @throws NoSuchElementException if the iterable is empty - * @throws IllegalArgumentException if the iterable contains multiple - * elements - */ - public static T getOnlyElement(Iterable iterable) { - return Iterators.getOnlyElement(iterable.iterator()); - } - - /** - * Returns the single element contained in {@code iterable}, or {@code - * defaultValue} if the iterable is empty. - * - * @throws IllegalArgumentException if the iterator contains multiple - * elements - */ - public static T getOnlyElement( - Iterable iterable, @Nullable T defaultValue) { - return Iterators.getOnlyElement(iterable.iterator(), defaultValue); - } - - /** - * Copies an iterable's elements into an array. - * - * @param iterable the iterable to copy - * @param type the type of the elements - * @return a newly-allocated array into which all the elements of the iterable - * have been copied - */ - @GwtIncompatible("Array.newInstance(Class, int)") - public static T[] toArray(Iterable iterable, Class type) { - @SuppressWarnings("unchecked") // bugs.sun.com/view_bug.do?bug_id=6558557 - Collection collection = (iterable instanceof Collection) - ? (Collection) iterable - : Lists.newArrayList(iterable); - T[] array = ObjectArrays.newArray(type, collection.size()); - return collection.toArray(array); - } - - /** - * Adds all elements in {@code iterable} to {@code collection}. - * - * @return {@code true} if {@code collection} was modified as a result of this - * operation. - */ - public static boolean addAll( - Collection addTo, Iterable elementsToAdd) { - if (elementsToAdd instanceof Collection) { - @SuppressWarnings("unchecked") - Collection c = (Collection) elementsToAdd; - return addTo.addAll(c); - } - return Iterators.addAll(addTo, elementsToAdd.iterator()); - } - - /** - * Returns the number of elements in the specified iterable that equal the - * specified object. - * - * @see Collections#frequency - */ - public static int frequency(Iterable iterable, @Nullable Object element) { - if ((iterable instanceof Multiset)) { - return ((Multiset) iterable).count(element); - } - if ((iterable instanceof Set)) { - return ((Set) iterable).contains(element) ? 1 : 0; - } - return Iterators.frequency(iterable.iterator(), element); - } - - /** - * Returns an iterable whose iterators cycle indefinitely over the elements of - * {@code iterable}. - * - *

That iterator supports {@code remove()} if {@code iterable.iterator()} - * does. After {@code remove()} is called, subsequent cycles omit the removed - * element, which is no longer in {@code iterable}. The iterator's - * {@code hasNext()} method returns {@code true} until {@code iterable} is - * empty. - * - *

Warning: Typical uses of the resulting iterator may produce an - * infinite loop. You should use an explicit {@code break} or be certain that - * you will eventually remove all the elements. - * - *

To cycle over the iterable {@code n} times, use the following: - * {@code Iterables.concat(Collections.nCopies(n, iterable))} - */ - public static Iterable cycle(final Iterable iterable) { - checkNotNull(iterable); - return new Iterable() { - public Iterator iterator() { - return Iterators.cycle(iterable); - } - @Override public String toString() { - return iterable.toString() + " (cycled)"; - } - }; - } - - /** - * Returns an iterable whose iterators cycle indefinitely over the provided - * elements. - * - *

After {@code remove} is invoked on a generated iterator, the removed - * element will no longer appear in either that iterator or any other iterator - * created from the same source iterable. That is, this method behaves exactly - * as {@code Iterables.cycle(Lists.newArrayList(elements))}. The iterator's - * {@code hasNext} method returns {@code true} until all of the original - * elements have been removed. - * - *

Warning: Typical uses of the resulting iterator may produce an - * infinite loop. You should use an explicit {@code break} or be certain that - * you will eventually remove all the elements. - * - *

To cycle over the elements {@code n} times, use the following: - * {@code Iterables.concat(Collections.nCopies(n, Arrays.asList(elements)))} - */ - public static Iterable cycle(T... elements) { - return cycle(Lists.newArrayList(elements)); - } - - /** - * Combines two iterables into a single iterable. The returned iterable has an - * iterator that traverses the elements in {@code a}, followed by the elements - * in {@code b}. The source iterators are not polled until necessary. - * - *

The returned iterable's iterator supports {@code remove()} when the - * corresponding input iterator supports it. - */ - @SuppressWarnings("unchecked") - public static Iterable concat( - Iterable a, Iterable b) { - checkNotNull(a); - checkNotNull(b); - return concat(Arrays.asList(a, b)); - } - - /** - * Combines three iterables into a single iterable. The returned iterable has - * an iterator that traverses the elements in {@code a}, followed by the - * elements in {@code b}, followed by the elements in {@code c}. The source - * iterators are not polled until necessary. - * - *

The returned iterable's iterator supports {@code remove()} when the - * corresponding input iterator supports it. - */ - @SuppressWarnings("unchecked") - public static Iterable concat(Iterable a, - Iterable b, Iterable c) { - checkNotNull(a); - checkNotNull(b); - checkNotNull(c); - return concat(Arrays.asList(a, b, c)); - } - - /** - * Combines four iterables into a single iterable. The returned iterable has - * an iterator that traverses the elements in {@code a}, followed by the - * elements in {@code b}, followed by the elements in {@code c}, followed by - * the elements in {@code d}. The source iterators are not polled until - * necessary. - * - *

The returned iterable's iterator supports {@code remove()} when the - * corresponding input iterator supports it. - */ - @SuppressWarnings("unchecked") - public static Iterable concat(Iterable a, - Iterable b, Iterable c, - Iterable d) { - checkNotNull(a); - checkNotNull(b); - checkNotNull(c); - checkNotNull(d); - return concat(Arrays.asList(a, b, c, d)); - } - - /** - * Combines multiple iterables into a single iterable. The returned iterable - * has an iterator that traverses the elements of each iterable in - * {@code inputs}. The input iterators are not polled until necessary. - * - *

The returned iterable's iterator supports {@code remove()} when the - * corresponding input iterator supports it. - * - * @throws NullPointerException if any of the provided iterables is null - */ - public static Iterable concat(Iterable... inputs) { - return concat(ImmutableList.of(inputs)); - } - - /** - * Combines multiple iterables into a single iterable. The returned iterable - * has an iterator that traverses the elements of each iterable in - * {@code inputs}. The input iterators are not polled until necessary. - * - *

The returned iterable's iterator supports {@code remove()} when the - * corresponding input iterator supports it. The methods of the returned - * iterable may throw {@code NullPointerException} if any of the input - * iterators are null. - */ - public static Iterable concat( - Iterable> inputs) { - /* - * Hint: if you let A represent Iterable and B represent - * Iterator, then this Function would look simply like: - * - * Function function = new Function { - * public B apply(A from) { - * return from.iterator(); - * } - * } - * - * TODO: there may be a better way to do this. - */ - - Function, Iterator> function - = new Function, Iterator>() { - public Iterator apply(Iterable from) { - return from.iterator(); - } - }; - final Iterable> iterators - = transform(inputs, function); - return new IterableWithToString() { - public Iterator iterator() { - return Iterators.concat(iterators.iterator()); - } - }; - } - - /** - * Divides an iterable into unmodifiable sublists of the given size (the final - * iterable may be smaller). For example, partitioning an iterable containing - * {@code [a, b, c, d, e]} with a partition size of 3 yields {@code - * [[a, b, c], [d, e]]} -- an outer iterable containing two inner lists of - * three and two elements, all in the original order. - * - *

Iterators returned by the returned iterable do not support the {@link - * Iterator#remove()} method. The returned lists implement {@link - * RandomAccess}, whether or not the input list does. - * - *

Note: if {@code iterable} is a {@link List}, use {@link - * Lists#partition(List, int)} instead. - * - * @param iterable the iterable to return a partitioned view of - * @param size the desired size of each partition (the last may be smaller) - * @return an iterable of unmodifiable lists containing the elements of {@code - * iterable} divided into partitions - * @throws IllegalArgumentException if {@code size} is nonpositive - */ - public static Iterable> partition( - final Iterable iterable, final int size) { - checkNotNull(iterable); - checkArgument(size > 0); - return new IterableWithToString>() { - public Iterator> iterator() { - return Iterators.partition(iterable.iterator(), size); - } - }; - } - - /** - * Divides an iterable into unmodifiable sublists of the given size, padding - * the final iterable with null values if necessary. For example, partitioning - * an iterable containing {@code [a, b, c, d, e]} with a partition size of 3 - * yields {@code [[a, b, c], [d, e, null]]} -- an outer iterable containing - * two inner lists of three elements each, all in the original order. - * - *

Iterators returned by the returned iterable do not support the {@link - * Iterator#remove()} method. - * - * @param iterable the iterable to return a partitioned view of - * @param size the desired size of each partition - * @return an iterable of unmodifiable lists containing the elements of {@code - * iterable} divided into partitions (the final iterable may have - * trailing null elements) - * @throws IllegalArgumentException if {@code size} is nonpositive - */ - public static Iterable> paddedPartition( - final Iterable iterable, final int size) { - checkNotNull(iterable); - checkArgument(size > 0); - return new IterableWithToString>() { - public Iterator> iterator() { - return Iterators.paddedPartition(iterable.iterator(), size); - } - }; - } - - /** - * Returns the elements of {@code unfiltered} that satisfy a predicate. The - * resulting iterable's iterator does not support {@code remove()}. - */ - public static Iterable filter( - final Iterable unfiltered, final Predicate predicate) { - checkNotNull(unfiltered); - checkNotNull(predicate); - return new IterableWithToString() { - public Iterator iterator() { - return Iterators.filter(unfiltered.iterator(), predicate); - } - }; - } - - /** - * Returns all instances of class {@code type} in {@code unfiltered}. The - * returned iterable has elements whose class is {@code type} or a subclass of - * {@code type}. The returned iterable's iterator does not support - * {@code remove()}. - * - * @param unfiltered an iterable containing objects of any type - * @param type the type of elements desired - * @return an unmodifiable iterable containing all elements of the original - * iterable that were of the requested type - */ - @GwtIncompatible("Class.isInstance") - public static Iterable filter( - final Iterable unfiltered, final Class type) { - checkNotNull(unfiltered); - checkNotNull(type); - return new IterableWithToString() { - public Iterator iterator() { - return Iterators.filter(unfiltered.iterator(), type); - } - }; - } - - /** - * Returns {@code true} if one or more elements in {@code iterable} satisfy - * the predicate. - */ - public static boolean any( - Iterable iterable, Predicate predicate) { - return Iterators.any(iterable.iterator(), predicate); - } - - /** - * Returns {@code true} if every element in {@code iterable} satisfies the - * predicate. If {@code iterable} is empty, {@code true} is returned. - */ - public static boolean all( - Iterable iterable, Predicate predicate) { - return Iterators.all(iterable.iterator(), predicate); - } - - /** - * Returns the first element in {@code iterable} that satisfies the given - * predicate. - * - * @throws NoSuchElementException if no element in {@code iterable} matches - * the given predicate - */ - public static T find(Iterable iterable, - Predicate predicate) { - return Iterators.find(iterable.iterator(), predicate); - } - - /** - * Returns an iterable that applies {@code function} to each element of {@code - * fromIterable}. - * - *

The returned iterable's iterator supports {@code remove()} if the - * provided iterator does. After a successful {@code remove()} call, - * {@code fromIterable} no longer contains the corresponding element. - */ - public static Iterable transform(final Iterable fromIterable, - final Function function) { - checkNotNull(fromIterable); - checkNotNull(function); - return new IterableWithToString() { - public Iterator iterator() { - return Iterators.transform(fromIterable.iterator(), function); - } - }; - } - - /** - * Returns the element at the specified position in an iterable. - * - * @param position position of the element to return - * @return the element at the specified position in {@code iterable} - * @throws IndexOutOfBoundsException if {@code position} is negative or - * greater than or equal to the size of {@code iterable} - */ - public static T get(Iterable iterable, int position) { - checkNotNull(iterable); - if (iterable instanceof List) { - return ((List) iterable).get(position); - } - - if (iterable instanceof Collection) { - // Can check both ends - Collection collection = (Collection) iterable; - Preconditions.checkElementIndex(position, collection.size()); - } else { - // Can only check the lower end - if (position < 0) { - throw new IndexOutOfBoundsException( - "position cannot be negative: " + position); - } - } - return Iterators.get(iterable.iterator(), position); - } - - /** - * Returns the last element of {@code iterable}. - * - * @return the last element of {@code iterable} - * @throws NoSuchElementException if the iterable has no elements - */ - public static T getLast(Iterable iterable) { - if (iterable instanceof List) { - List list = (List) iterable; - // TODO: Support a concurrent list whose size changes while this method - // is running. - if (list.isEmpty()) { - throw new NoSuchElementException(); - } - return list.get(list.size() - 1); - } - - if (iterable instanceof SortedSet) { - SortedSet sortedSet = (SortedSet) iterable; - return sortedSet.last(); - } - - return Iterators.getLast(iterable.iterator()); - } - - // Methods only in Iterables, not in Iterators - - /** - * Adapts a list to an iterable with reversed iteration order. It is - * especially useful in foreach-style loops:

   {@code
-   *
-   *   List mylist = ...
-   *   for (String str : Iterables.reverse(mylist)) {
-   *     ...
-   *   }}
- * - * There is no corresponding method in {@link Iterators}, since {@link - * Iterable#iterator} can simply be invoked on the result of calling this - * method. - * - * @return an iterable with the same elements as the list, in reverse - */ - public static Iterable reverse(final List list) { - checkNotNull(list); - return new IterableWithToString() { - public Iterator iterator() { - final ListIterator listIter = list.listIterator(list.size()); - return new Iterator() { - public boolean hasNext() { - return listIter.hasPrevious(); - } - public T next() { - return listIter.previous(); - } - public void remove() { - listIter.remove(); - } - }; - } - }; - } - - /** - * Determines if the given iterable contains no elements. - * - *

There is no precise {@link Iterator} equivalent to this method, since - * one can only ask an iterator whether it has any elements remaining - * (which one does using {@link Iterator#hasNext}). - * - * @return {@code true} if the iterable contains no elements - */ - public static boolean isEmpty(Iterable iterable) { - return !iterable.iterator().hasNext(); - } - - /** - * Removes the specified element from the specified iterable. - * - *

This method iterates over the iterable, checking each element returned - * by the iterator in turn to see if it equals the object {@code o}. If they - * are equal, it is removed from the iterable with the iterator's - * {@code remove} method. At most one element is removed, even if the iterable - * contains multiple members that equal {@code o}. - * - *

Warning: Do not use this method for a collection, such as a - * {@link HashSet}, that has a fast {@code remove} method. - * - * @param iterable the iterable from which to remove - * @param o an element to remove from the collection - * @return {@code true} if the iterable changed as a result - * @throws UnsupportedOperationException if the iterator does not support the - * {@code remove} method and the iterable contains the object - */ - static boolean remove(Iterable iterable, @Nullable Object o) { - Iterator i = iterable.iterator(); - while (i.hasNext()) { - if (Objects.equal(i.next(), o)) { - i.remove(); - return true; - } - } - return false; - } - - abstract static class IterableWithToString implements Iterable { - @Override public String toString() { - return Iterables.toString(this); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Iterators.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Iterators.java deleted file mode 100644 index 58d814ab891..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Iterators.java +++ /dev/null @@ -1,964 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; -import org.elasticsearch.util.base.*; - -import javax.annotation.Nullable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * This class contains static utility methods that operate on or return objects - * of type {@link Iterator}. Except as noted, each method has a corresponding - * {@link Iterable}-based method in the {@link Iterables} class. - * - * @author Kevin Bourrillion - * @author Jared Levy - */ -@GwtCompatible -public final class Iterators { - private Iterators() {} - - static final UnmodifiableIterator EMPTY_ITERATOR - = new UnmodifiableIterator() { - public boolean hasNext() { - return false; - } - public Object next() { - throw new NoSuchElementException(); - } - }; - - /** - * Returns the empty iterator. - * - *

The {@link Iterable} equivalent of this method is {@link - * Collections#emptySet}. - */ - // Casting to any type is safe since there are no actual elements. - @SuppressWarnings("unchecked") - public static UnmodifiableIterator emptyIterator() { - return (UnmodifiableIterator) EMPTY_ITERATOR; - } - - private static final Iterator EMPTY_MODIFIABLE_ITERATOR = - new Iterator() { - /*@Override*/ public boolean hasNext() { - return false; - } - - /*@Override*/ public Object next() { - throw new NoSuchElementException(); - } - - /*@Override*/ public void remove() { - throw new IllegalStateException(); - } - }; - - /** - * Returns the empty {@code Iterator} that throws - * {@link IllegalStateException} instead of - * {@link UnsupportedOperationException} on a call to - * {@link Iterator#remove()}. - */ - // Casting to any type is safe since there are no actual elements. - @SuppressWarnings("unchecked") - static Iterator emptyModifiableIterator() { - return (Iterator) EMPTY_MODIFIABLE_ITERATOR; - } - - /** Returns an unmodifiable view of {@code iterator}. */ - public static UnmodifiableIterator unmodifiableIterator( - final Iterator iterator) { - checkNotNull(iterator); - return new UnmodifiableIterator() { - public boolean hasNext() { - return iterator.hasNext(); - } - public T next() { - return iterator.next(); - } - }; - } - - /** - * Returns the number of elements remaining in {@code iterator}. The iterator - * will be left exhausted: its {@code hasNext()} method will return - * {@code false}. - */ - public static int size(Iterator iterator) { - int count = 0; - while (iterator.hasNext()) { - iterator.next(); - count++; - } - return count; - } - - /** - * Returns {@code true} if {@code iterator} contains {@code element}. - */ - public static boolean contains(Iterator iterator, @Nullable Object element) - { - if (element == null) { - while (iterator.hasNext()) { - if (iterator.next() == null) { - return true; - } - } - } else { - while (iterator.hasNext()) { - if (element.equals(iterator.next())) { - return true; - } - } - } - return false; - } - - /** - * Traverses an iterator and removes every element that belongs to the - * provided collection. The iterator will be left exhausted: its - * {@code hasNext()} method will return {@code false}. - * - * @param removeFrom the iterator to (potentially) remove elements from - * @param elementsToRemove the elements to remove - * @return {@code true} if any elements are removed from {@code iterator} - */ - public static boolean removeAll( - Iterator removeFrom, Collection elementsToRemove) { - checkNotNull(elementsToRemove); - boolean modified = false; - while (removeFrom.hasNext()) { - if (elementsToRemove.contains(removeFrom.next())) { - removeFrom.remove(); - modified = true; - } - } - return modified; - } - - /** - * Removes every element that satisfies the provided predicate from the - * iterator. The iterator will be left exhausted: its {@code hasNext()} - * method will return {@code false}. - * - * @param removeFrom the iterator to (potentially) remove elements from - * @param predicate a predicate that determines whether an element should - * be removed - * @return {@code true} if any elements were removed from the iterator - */ - // TODO: make public post-1.0 - static boolean removeIf( - Iterator removeFrom, Predicate predicate) { - checkNotNull(predicate); - boolean modified = false; - while (removeFrom.hasNext()) { - if (predicate.apply(removeFrom.next())) { - removeFrom.remove(); - modified = true; - } - } - return modified; - } - - /** - * Traverses an iterator and removes every element that does not belong to the - * provided collection. The iterator will be left exhausted: its - * {@code hasNext()} method will return {@code false}. - * - * @param removeFrom the iterator to (potentially) remove elements from - * @param elementsToRetain the elements to retain - * @return {@code true} if any elements are removed from {@code iterator} - */ - public static boolean retainAll( - Iterator removeFrom, Collection elementsToRetain) { - checkNotNull(elementsToRetain); - boolean modified = false; - while (removeFrom.hasNext()) { - if (!elementsToRetain.contains(removeFrom.next())) { - removeFrom.remove(); - modified = true; - } - } - return modified; - } - - /** - * Determines whether two iterators contain equal elements in the same order. - * More specifically, this method returns {@code true} if {@code iterator1} - * and {@code iterator2} contain the same number of elements and every element - * of {@code iterator1} is equal to the corresponding element of - * {@code iterator2}. - * - *

Note that this will modify the supplied iterators, since they will have - * been advanced some number of elements forward. - */ - public static boolean elementsEqual( - Iterator iterator1, Iterator iterator2) { - while (iterator1.hasNext()) { - if (!iterator2.hasNext()) { - return false; - } - Object o1 = iterator1.next(); - Object o2 = iterator2.next(); - if (!Objects.equal(o1, o2)) { - return false; - } - } - return !iterator2.hasNext(); - } - - /** - * Returns a string representation of {@code iterator}, with the format - * {@code [e1, e2, ..., en]}. The iterator will be left exhausted: its - * {@code hasNext()} method will return {@code false}. - */ - public static String toString(Iterator iterator) { - if (!iterator.hasNext()) { - return "[]"; - } - StringBuilder builder = new StringBuilder(); - builder.append('[').append(iterator.next()); - while (iterator.hasNext()) { - builder.append(", ").append(iterator.next()); - } - return builder.append(']').toString(); - } - - /** - * Returns the single element contained in {@code iterator}. - * - * @throws NoSuchElementException if the iterator is empty - * @throws IllegalArgumentException if the iterator contains multiple - * elements. The state of the iterator is unspecified. - */ - public static T getOnlyElement(Iterator iterator) { - T first = iterator.next(); - if (!iterator.hasNext()) { - return first; - } - - StringBuilder sb = new StringBuilder(); - sb.append("expected one element but was: <" + first); - for (int i = 0; i < 4 && iterator.hasNext(); i++) { - sb.append(", " + iterator.next()); - } - if (iterator.hasNext()) { - sb.append(", ..."); - } - sb.append(">"); - - throw new IllegalArgumentException(sb.toString()); - } - - /** - * Returns the single element contained in {@code iterator}, or {@code - * defaultValue} if the iterator is empty. - * - * @throws IllegalArgumentException if the iterator contains multiple - * elements. The state of the iterator is unspecified. - */ - public static T getOnlyElement( - Iterator iterator, @Nullable T defaultValue) { - return iterator.hasNext() ? getOnlyElement(iterator) : defaultValue; - } - - /** - * Copies an iterator's elements into an array. The iterator will be left - * exhausted: its {@code hasNext()} method will return {@code false}. - * - * @param iterator the iterator to copy - * @param type the type of the elements - * @return a newly-allocated array into which all the elements of the iterator - * have been copied - */ - @GwtIncompatible("Array.newArray") - public static T[] toArray( - Iterator iterator, Class type) { - List list = Lists.newArrayList(iterator); - return Iterables.toArray(list, type); - } - - /** - * Adds all elements in {@code iterator} to {@code collection}. The iterator - * will be left exhausted: its {@code hasNext()} method will return - * {@code false}. - * - * @return {@code true} if {@code collection} was modified as a result of this - * operation - */ - public static boolean addAll( - Collection addTo, Iterator iterator) { - checkNotNull(addTo); - boolean wasModified = false; - while (iterator.hasNext()) { - wasModified |= addTo.add(iterator.next()); - } - return wasModified; - } - - /** - * Returns the number of elements in the specified iterator that equal the - * specified object. The iterator will be left exhausted: its - * {@code hasNext()} method will return {@code false}. - * - * @see Collections#frequency - */ - public static int frequency(Iterator iterator, @Nullable Object element) { - int result = 0; - if (element == null) { - while (iterator.hasNext()) { - if (iterator.next() == null) { - result++; - } - } - } else { - while (iterator.hasNext()) { - if (element.equals(iterator.next())) { - result++; - } - } - } - return result; - } - - /** - * Returns an iterator that cycles indefinitely over the elements of {@code - * iterable}. - * - *

The returned iterator supports {@code remove()} if the provided iterator - * does. After {@code remove()} is called, subsequent cycles omit the removed - * element, which is no longer in {@code iterable}. The iterator's - * {@code hasNext()} method returns {@code true} until {@code iterable} is - * empty. - * - *

Warning: Typical uses of the resulting iterator may produce an - * infinite loop. You should use an explicit {@code break} or be certain that - * you will eventually remove all the elements. - */ - public static Iterator cycle(final Iterable iterable) { - checkNotNull(iterable); - return new Iterator() { - Iterator iterator = emptyIterator(); - Iterator removeFrom; - - public boolean hasNext() { - if (!iterator.hasNext()) { - iterator = iterable.iterator(); - } - return iterator.hasNext(); - } - public T next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - removeFrom = iterator; - return iterator.next(); - } - public void remove() { - checkState(removeFrom != null, - "no calls to next() since last call to remove()"); - removeFrom.remove(); - removeFrom = null; - } - }; - } - - /** - * Returns an iterator that cycles indefinitely over the provided elements. - * - *

The returned iterator supports {@code remove()} if the provided iterator - * does. After {@code remove()} is called, subsequent cycles omit the removed - * element, but {@code elements} does not change. The iterator's - * {@code hasNext()} method returns {@code true} until all of the original - * elements have been removed. - * - *

Warning: Typical uses of the resulting iterator may produce an - * infinite loop. You should use an explicit {@code break} or be certain that - * you will eventually remove all the elements. - */ - public static Iterator cycle(T... elements) { - return cycle(Lists.newArrayList(elements)); - } - - /** - * Combines two iterators into a single iterator. The returned iterator - * iterates across the elements in {@code a}, followed by the elements in - * {@code b}. The source iterators are not polled until necessary. - * - *

The returned iterator supports {@code remove()} when the corresponding - * input iterator supports it. - */ - @SuppressWarnings("unchecked") - public static Iterator concat(Iterator a, - Iterator b) { - checkNotNull(a); - checkNotNull(b); - return concat(Arrays.asList(a, b).iterator()); - } - - /** - * Combines three iterators into a single iterator. The returned iterator - * iterates across the elements in {@code a}, followed by the elements in - * {@code b}, followed by the elements in {@code c}. The source iterators - * are not polled until necessary. - * - *

The returned iterator supports {@code remove()} when the corresponding - * input iterator supports it. - */ - @SuppressWarnings("unchecked") - public static Iterator concat(Iterator a, - Iterator b, Iterator c) { - checkNotNull(a); - checkNotNull(b); - checkNotNull(c); - return concat(Arrays.asList(a, b, c).iterator()); - } - - /** - * Combines four iterators into a single iterator. The returned iterator - * iterates across the elements in {@code a}, followed by the elements in - * {@code b}, followed by the elements in {@code c}, followed by the elements - * in {@code d}. The source iterators are not polled until necessary. - * - *

The returned iterator supports {@code remove()} when the corresponding - * input iterator supports it. - */ - @SuppressWarnings("unchecked") - public static Iterator concat(Iterator a, - Iterator b, Iterator c, - Iterator d) { - checkNotNull(a); - checkNotNull(b); - checkNotNull(c); - checkNotNull(d); - return concat(Arrays.asList(a, b, c, d).iterator()); - } - - /** - * Combines multiple iterators into a single iterator. The returned iterator - * iterates across the elements of each iterator in {@code inputs}. The input - * iterators are not polled until necessary. - * - *

The returned iterator supports {@code remove()} when the corresponding - * input iterator supports it. - * - * @throws NullPointerException if any of the provided iterators is null - */ - public static Iterator concat(Iterator... inputs) { - return concat(ImmutableList.of(inputs).iterator()); - } - - /** - * Combines multiple iterators into a single iterator. The returned iterator - * iterates across the elements of each iterator in {@code inputs}. The input - * iterators are not polled until necessary. - * - *

The returned iterator supports {@code remove()} when the corresponding - * input iterator supports it. The methods of the returned iterator may throw - * {@code NullPointerException} if any of the input iterators are null. - */ - public static Iterator concat( - final Iterator> inputs) { - checkNotNull(inputs); - return new Iterator() { - Iterator current = emptyIterator(); - Iterator removeFrom; - - public boolean hasNext() { - // http://code.google.com/p/google-collections/issues/detail?id=151 - // current.hasNext() might be relatively expensive, worth minimizing. - boolean currentHasNext; - while (!(currentHasNext = current.hasNext()) && inputs.hasNext()) { - current = inputs.next(); - } - return currentHasNext; - } - public T next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - removeFrom = current; - return current.next(); - } - public void remove() { - checkState(removeFrom != null, - "no calls to next() since last call to remove()"); - removeFrom.remove(); - removeFrom = null; - } - }; - } - - /** - * Divides an iterator into unmodifiable sublists of the given size (the final - * list may be smaller). For example, partitioning an iterator containing - * {@code [a, b, c, d, e]} with a partition size of 3 yields {@code - * [[a, b, c], [d, e]]} -- an outer iterator containing two inner lists of - * three and two elements, all in the original order. - * - *

The returned lists implement {@link java.util.RandomAccess}. - * - * @param iterator the iterator to return a partitioned view of - * @param size the desired size of each partition (the last may be smaller) - * @return an iterator of immutable lists containing the elements of {@code - * iterator} divided into partitions - * @throws IllegalArgumentException if {@code size} is nonpositive - */ - public static UnmodifiableIterator> partition( - Iterator iterator, int size) { - return partitionImpl(iterator, size, false); - } - - /** - * Divides an iterator into unmodifiable sublists of the given size, padding - * the final iterator with null values if necessary. For example, partitioning - * an iterator containing {@code [a, b, c, d, e]} with a partition size of 3 - * yields {@code [[a, b, c], [d, e, null]]} -- an outer iterator containing - * two inner lists of three elements each, all in the original order. - * - *

The returned lists implement {@link java.util.RandomAccess}. - * - * @param iterator the iterator to return a partitioned view of - * @param size the desired size of each partition - * @return an iterator of immutable lists containing the elements of {@code - * iterator} divided into partitions (the final iterable may have - * trailing null elements) - * @throws IllegalArgumentException if {@code size} is nonpositive - */ - public static UnmodifiableIterator> paddedPartition( - Iterator iterator, int size) { - return partitionImpl(iterator, size, true); - } - - private static UnmodifiableIterator> partitionImpl( - final Iterator iterator, final int size, final boolean pad) { - checkNotNull(iterator); - checkArgument(size > 0); - return new UnmodifiableIterator>() { - public boolean hasNext() { - return iterator.hasNext(); - } - public List next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - Object[] array = new Object[size]; - int count = 0; - for (; count < size && iterator.hasNext(); count++) { - array[count] = iterator.next(); - } - - @SuppressWarnings("unchecked") // we only put Ts in it - List list = Collections.unmodifiableList( - (List) Arrays.asList(array)); - return (pad || count == size) ? list : Platform.subList(list, 0, count); - } - }; - } - - /** - * Returns the elements of {@code unfiltered} that satisfy a predicate. - */ - public static UnmodifiableIterator filter( - final Iterator unfiltered, final Predicate predicate) { - checkNotNull(unfiltered); - checkNotNull(predicate); - return new AbstractIterator() { - @Override protected T computeNext() { - while (unfiltered.hasNext()) { - T element = unfiltered.next(); - if (predicate.apply(element)) { - return element; - } - } - return endOfData(); - } - }; - } - - /** - * Returns all instances of class {@code type} in {@code unfiltered}. The - * returned iterator has elements whose class is {@code type} or a subclass of - * {@code type}. - * - * @param unfiltered an iterator containing objects of any type - * @param type the type of elements desired - * @return an unmodifiable iterator containing all elements of the original - * iterator that were of the requested type - */ - @SuppressWarnings("unchecked") // can cast to because non-Ts are removed - @GwtIncompatible("Class.isInstance") - public static UnmodifiableIterator filter( - Iterator unfiltered, Class type) { - return (UnmodifiableIterator) - filter(unfiltered, Predicates.instanceOf(type)); - } - - /** - * Returns {@code true} if one or more elements returned by {@code iterator} - * satisfy the given predicate. - */ - public static boolean any( - Iterator iterator, Predicate predicate) { - checkNotNull(predicate); - while (iterator.hasNext()) { - T element = iterator.next(); - if (predicate.apply(element)) { - return true; - } - } - return false; - } - - /** - * Returns {@code true} if every element returned by {@code iterator} - * satisfies the given predicate. If {@code iterator} is empty, {@code true} - * is returned. - */ - public static boolean all( - Iterator iterator, Predicate predicate) { - checkNotNull(predicate); - while (iterator.hasNext()) { - T element = iterator.next(); - if (!predicate.apply(element)) { - return false; - } - } - return true; - } - - /** - * Returns the first element in {@code iterator} that satisfies the given - * predicate. If a matching element is found, the iterator will be left in a - * state such that calling {@code iterator.remove()} will remove the found - * item. If no such element is found, the iterator will be left exhausted: its - * {@code hasNext()} method will return {@code false}. - * - * @return the first matching element in {@code iterator} - * @throws NoSuchElementException if no element in {@code iterator} matches - * the given predicate - */ - public static T find(Iterator iterator, Predicate predicate) - { - return filter(iterator, predicate).next(); - } - - /** - * Returns an iterator that applies {@code function} to each element of {@code - * fromIterator}. - * - *

The returned iterator supports {@code remove()} if the provided iterator - * does. After a successful {@code remove()} call, {@code fromIterator} no - * longer contains the corresponding element. - */ - public static Iterator transform(final Iterator fromIterator, - final Function function) { - checkNotNull(fromIterator); - checkNotNull(function); - return new Iterator() { - public boolean hasNext() { - return fromIterator.hasNext(); - } - public T next() { - F from = fromIterator.next(); - return function.apply(from); - } - public void remove() { - fromIterator.remove(); - } - }; - } - - /** - * Advances {@code iterator} {@code position + 1} times, returning the element - * at the {@code position}th position. - * - * @param position position of the element to return - * @return the element at the specified position in {@code iterator} - * @throws IndexOutOfBoundsException if {@code position} is negative or - * greater than or equal to the number of elements remaining in - * {@code iterator} - */ - public static T get(Iterator iterator, int position) { - if (position < 0) { - throw new IndexOutOfBoundsException("position (" + position - + ") must not be negative"); - } - - int skipped = 0; - while (iterator.hasNext()) { - T t = iterator.next(); - if (skipped++ == position) { - return t; - } - } - - throw new IndexOutOfBoundsException("position (" + position - + ") must be less than the number of elements that remained (" - + skipped + ")"); - } - - /** - * Advances {@code iterator} to the end, returning the last element. - * - * @return the last element of {@code iterator} - * @throws NoSuchElementException if the iterator has no remaining elements - */ - public static T getLast(Iterator iterator) { - while (true) { - T current = iterator.next(); - if (!iterator.hasNext()) { - return current; - } - } - } - - // Methods only in Iterators, not in Iterables - - /** - * Returns an iterator containing the elements of {@code array} in order. The - * returned iterator is a view of the array; subsequent changes to the array - * will be reflected in the iterator. - * - *

Note: It is often preferable to represent your data using a - * collection type, for example using {@link Arrays#asList(Object[])}, making - * this method unnecessary. - * - *

The {@code Iterable} equivalent of this method is either {@link - * Arrays#asList(Object[])} or {@link ImmutableList#of(Object[])}}. - */ - public static UnmodifiableIterator forArray(final T... array) { - // optimized. benchmarks at nearly 2x of the straightforward impl - return new UnmodifiableIterator() { - final int length = array.length; - int i = 0; - public boolean hasNext() { - return i < length; - } - public T next() { - try { - // 'return array[i++];' almost works - T t = array[i]; - i++; - return t; - } catch (ArrayIndexOutOfBoundsException e) { - throw new NoSuchElementException(); - } - } - }; - } - - /** - * Returns an iterator containing the elements in the specified range of - * {@code array} in order. The returned iterator is a view of the array; - * subsequent changes to the array will be reflected in the iterator. - * - *

The {@code Iterable} equivalent of this method is {@code - * Arrays.asList(array).subList(offset, offset + length)}. - * - * @param array array to read elements out of - * @param offset index of first array element to retrieve - * @param length number of elements in iteration - * - * @throws IndexOutOfBoundsException if {@code offset} is negative, - * {@code length} is negative, or {@code offset + length > array.length} - */ - static UnmodifiableIterator forArray( - final T[] array, final int offset, int length) { - checkArgument(length >= 0); - final int end = offset + length; - - // Technically we should give a slightly more descriptive error on overflow - Preconditions.checkPositionIndexes(offset, end, array.length); - - // If length == 0 is a common enough case, we could return emptyIterator(). - - return new UnmodifiableIterator() { - int i = offset; - public boolean hasNext() { - return i < end; - } - public T next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - return array[i++]; - } - }; - } - - /** - * Returns an iterator containing only {@code value}. - * - *

The {@link Iterable} equivalent of this method is {@link - * Collections#singleton}. - */ - public static UnmodifiableIterator singletonIterator( - @Nullable final T value) { - return new UnmodifiableIterator() { - boolean done; - public boolean hasNext() { - return !done; - } - public T next() { - if (done) { - throw new NoSuchElementException(); - } - done = true; - return value; - } - }; - } - - /** - * Adapts an {@code Enumeration} to the {@code Iterator} interface. - * - *

This method has no equivalent in {@link Iterables} because viewing an - * {@code Enumeration} as an {@code Iterable} is impossible. However, the - * contents can be copied into a collection using {@link - * Collections#list}. - */ - public static UnmodifiableIterator forEnumeration( - final Enumeration enumeration) { - checkNotNull(enumeration); - return new UnmodifiableIterator() { - public boolean hasNext() { - return enumeration.hasMoreElements(); - } - public T next() { - return enumeration.nextElement(); - } - }; - } - - /** - * Adapts an {@code Iterator} to the {@code Enumeration} interface. - * - *

The {@code Iterable} equivalent of this method is either {@link - * Collections#enumeration} (if you have a {@link Collection}), or - * {@code Iterators.asEnumeration(collection.iterator())}. - */ - public static Enumeration asEnumeration(final Iterator iterator) { - checkNotNull(iterator); - return new Enumeration() { - public boolean hasMoreElements() { - return iterator.hasNext(); - } - public T nextElement() { - return iterator.next(); - } - }; - } - - /** - * Implementation of PeekingIterator that avoids peeking unless necessary. - */ - private static class PeekingImpl implements PeekingIterator { - - private final Iterator iterator; - private boolean hasPeeked; - private E peekedElement; - - public PeekingImpl(Iterator iterator) { - this.iterator = checkNotNull(iterator); - } - - public boolean hasNext() { - return hasPeeked || iterator.hasNext(); - } - - public E next() { - if (!hasPeeked) { - return iterator.next(); - } - E result = peekedElement; - hasPeeked = false; - peekedElement = null; - return result; - } - - public void remove() { - checkState(!hasPeeked, "Can't remove after you've peeked at next"); - iterator.remove(); - } - - public E peek() { - if (!hasPeeked) { - peekedElement = iterator.next(); - hasPeeked = true; - } - return peekedElement; - } - } - - /** - * Returns a {@code PeekingIterator} backed by the given iterator. - * - *

Calls to the {@code peek} method with no intervening calls to {@code - * next} do not affect the iteration, and hence return the same object each - * time. A subsequent call to {@code next} is guaranteed to return the same - * object again. For example:

   {@code
-   *
-   *   PeekingIterator peekingIterator =
-   *       Iterators.peekingIterator(Iterators.forArray("a", "b"));
-   *   String a1 = peekingIterator.peek(); // returns "a"
-   *   String a2 = peekingIterator.peek(); // also returns "a"
-   *   String a3 = peekingIterator.next(); // also returns "a"}
- * - * Any structural changes to the underlying iteration (aside from those - * performed by the iterator's own {@link PeekingIterator#remove()} method) - * will leave the iterator in an undefined state. - * - *

The returned iterator does not support removal after peeking, as - * explained by {@link PeekingIterator#remove()}. - * - *

Note: If the given iterator is already a {@code PeekingIterator}, - * it might be returned to the caller, although this is neither - * guaranteed to occur nor required to be consistent. For example, this - * method might choose to pass through recognized implementations of - * {@code PeekingIterator} when the behavior of the implementation is - * known to meet the contract guaranteed by this method. - * - *

There is no {@link Iterable} equivalent to this method, so use this - * method to wrap each individual iterator as it is generated. - * - * @param iterator the backing iterator. The {@link PeekingIterator} assumes - * ownership of this iterator, so users should cease making direct calls - * to it after calling this method. - * @return a peeking iterator backed by that iterator. Apart from the - * additional {@link PeekingIterator#peek()} method, this iterator behaves - * exactly the same as {@code iterator}. - */ - public static PeekingIterator peekingIterator( - Iterator iterator) { - if (iterator instanceof PeekingImpl) { - // Safe to cast to because PeekingImpl only uses T - // covariantly (and cannot be subclassed to add non-covariant uses). - @SuppressWarnings("unchecked") - PeekingImpl peeking = (PeekingImpl) iterator; - return peeking; - } - return new PeekingImpl(iterator); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedHashMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedHashMultimap.java deleted file mode 100644 index 8238b556e18..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedHashMultimap.java +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.VisibleForTesting; -import org.elasticsearch.util.base.Preconditions; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.*; - -/** - * Implementation of {@code Multimap} that does not allow duplicate key-value - * entries and that returns collections whose iterators follow the ordering in - * which the data was added to the multimap. - * - *

The collections returned by {@code keySet}, {@code keys}, and {@code - * asMap} iterate through the keys in the order they were first added to the - * multimap. Similarly, {@code get}, {@code removeAll}, and {@code - * replaceValues} return collections that iterate through the values in the - * order they were added. The collections generated by {@code entries} and - * {@code values} iterate across the key-value mappings in the order they were - * added to the multimap. - * - *

The iteration ordering of the collections generated by {@code keySet}, - * {@code keys}, and {@code asMap} has a few subtleties. As long as the set of - * keys remains unchanged, adding or removing mappings does not affect the key - * iteration order. However, if you remove all values associated with a key and - * then add the key back to the multimap, that key will come last in the key - * iteration order. - * - *

The multimap does not store duplicate key-value pairs. Adding a new - * key-value pair equal to an existing key-value pair has no effect. - * - *

Keys and values may be null. All optional multimap methods are supported, - * and all returned views are modifiable. - * - *

This class is not threadsafe when any concurrent operations update the - * multimap. Concurrent read operations will work correctly. To allow concurrent - * update operations, wrap your multimap with a call to {@link - * Multimaps#synchronizedSetMultimap}. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -public final class LinkedHashMultimap extends AbstractSetMultimap { - private static final int DEFAULT_VALUES_PER_KEY = 8; - - @VisibleForTesting - transient int expectedValuesPerKey = DEFAULT_VALUES_PER_KEY; - - /** - * Map entries with an iteration order corresponding to the order in which the - * key-value pairs were added to the multimap. - */ - // package-private for GWT deserialization - transient Collection> linkedEntries; - - /** - * Creates a new, empty {@code LinkedHashMultimap} with the default initial - * capacities. - */ - public static LinkedHashMultimap create() { - return new LinkedHashMultimap(); - } - - /** - * Constructs an empty {@code LinkedHashMultimap} with enough capacity to hold - * the specified numbers of keys and values without rehashing. - * - * @param expectedKeys the expected number of distinct keys - * @param expectedValuesPerKey the expected average number of values per key - * @throws IllegalArgumentException if {@code expectedKeys} or {@code - * expectedValuesPerKey} is negative - */ - public static LinkedHashMultimap create( - int expectedKeys, int expectedValuesPerKey) { - return new LinkedHashMultimap(expectedKeys, expectedValuesPerKey); - } - - /** - * Constructs a {@code LinkedHashMultimap} with the same mappings as the - * specified multimap. If a key-value mapping appears multiple times in the - * input multimap, it only appears once in the constructed multimap. The new - * multimap has the same {@link Multimap#entries()} iteration order as the - * input multimap, except for excluding duplicate mappings. - * - * @param multimap the multimap whose contents are copied to this multimap - */ - public static LinkedHashMultimap create( - Multimap multimap) { - return new LinkedHashMultimap(multimap); - } - - private LinkedHashMultimap() { - super(new LinkedHashMap>()); - linkedEntries = Sets.newLinkedHashSet(); - } - - private LinkedHashMultimap(int expectedKeys, int expectedValuesPerKey) { - super(new LinkedHashMap>(expectedKeys)); - Preconditions.checkArgument(expectedValuesPerKey >= 0); - this.expectedValuesPerKey = expectedValuesPerKey; - linkedEntries = new LinkedHashSet>( - expectedKeys * expectedValuesPerKey); - } - - private LinkedHashMultimap(Multimap multimap) { - super(new LinkedHashMap>( - Maps.capacity(multimap.keySet().size()))); - linkedEntries - = new LinkedHashSet>(Maps.capacity(multimap.size())); - putAll(multimap); - } - - /** - * {@inheritDoc} - * - *

Creates an empty {@code LinkedHashSet} for a collection of values for - * one key. - * - * @return a new {@code LinkedHashSet} containing a collection of values for - * one key - */ - @Override Set createCollection() { - return new LinkedHashSet(Maps.capacity(expectedValuesPerKey)); - } - - /** - * {@inheritDoc} - * - *

Creates a decorated {@code LinkedHashSet} that also keeps track of the - * order in which key-value pairs are added to the multimap. - * - * @param key key to associate with values in the collection - * @return a new decorated {@code LinkedHashSet} containing a collection of - * values for one key - */ - @Override Collection createCollection(@Nullable K key) { - return new SetDecorator(key, createCollection()); - } - - private class SetDecorator extends ForwardingSet { - final Set delegate; - final K key; - - SetDecorator(@Nullable K key, Set delegate) { - this.delegate = delegate; - this.key = key; - } - - @Override protected Set delegate() { - return delegate; - } - - Map.Entry createEntry(@Nullable E value) { - return Maps.immutableEntry(key, value); - } - - Collection> createEntries(Collection values) { - // converts a collection of values into a list of key/value map entries - Collection> entries - = Lists.newArrayListWithExpectedSize(values.size()); - for (E value : values) { - entries.add(createEntry(value)); - } - return entries; - } - - @Override public boolean add(@Nullable V value) { - boolean changed = delegate.add(value); - if (changed) { - linkedEntries.add(createEntry(value)); - } - return changed; - } - - @Override public boolean addAll(Collection values) { - boolean changed = delegate.addAll(values); - if (changed) { - linkedEntries.addAll(createEntries(delegate())); - } - return changed; - } - - @Override public void clear() { - linkedEntries.removeAll(createEntries(delegate())); - delegate.clear(); - } - - @Override public Iterator iterator() { - final Iterator delegateIterator = delegate.iterator(); - return new Iterator() { - V value; - - public boolean hasNext() { - return delegateIterator.hasNext(); - } - public V next() { - value = delegateIterator.next(); - return value; - } - public void remove() { - delegateIterator.remove(); - linkedEntries.remove(createEntry(value)); - } - }; - } - - @Override public boolean remove(@Nullable Object value) { - boolean changed = delegate.remove(value); - if (changed) { - /* - * linkedEntries.remove() will return false when this method is called - * by entries().iterator().remove() - */ - linkedEntries.remove(createEntry(value)); - } - return changed; - } - - @Override public boolean removeAll(Collection values) { - boolean changed = delegate.removeAll(values); - if (changed) { - linkedEntries.removeAll(createEntries(values)); - } - return changed; - } - - @Override public boolean retainAll(Collection values) { - /* - * Calling linkedEntries.retainAll() would incorrectly remove values - * with other keys. - */ - boolean changed = false; - Iterator iterator = delegate.iterator(); - while (iterator.hasNext()) { - V value = iterator.next(); - if (!values.contains(value)) { - iterator.remove(); - linkedEntries.remove(Maps.immutableEntry(key, value)); - changed = true; - } - } - return changed; - } - } - - /** - * {@inheritDoc} - * - *

Generates an iterator across map entries that follows the ordering in - * which the key-value pairs were added to the multimap. - * - * @return a key-value iterator with the correct ordering - */ - @Override Iterator> createEntryIterator() { - final Iterator> delegateIterator = linkedEntries.iterator(); - - return new Iterator>() { - Map.Entry entry; - - public boolean hasNext() { - return delegateIterator.hasNext(); - } - - public Map.Entry next() { - entry = delegateIterator.next(); - return entry; - } - - public void remove() { - // Remove from iterator first to keep iterator valid. - delegateIterator.remove(); - LinkedHashMultimap.this.remove(entry.getKey(), entry.getValue()); - } - }; - } - - /** - * {@inheritDoc} - * - *

If {@code values} is not empty and the multimap already contains a - * mapping for {@code key}, the {@code keySet()} ordering is unchanged. - * However, the provided values always come last in the {@link #entries()} and - * {@link #values()} iteration orderings. - */ - @Override public Set replaceValues( - @Nullable K key, Iterable values) { - return super.replaceValues(key, values); - } - - /** - * Returns a set of all key-value pairs. Changes to the returned set will - * update the underlying multimap, and vice versa. The entries set does not - * support the {@code add} or {@code addAll} operations. - * - *

The iterator generated by the returned set traverses the entries in the - * order they were added to the multimap. - * - *

Each entry is an immutable snapshot of a key-value mapping in the - * multimap, taken at the time the entry is returned by a method call to the - * collection or its iterator. - */ - @Override public Set> entries() { - return super.entries(); - } - - /** - * Returns a collection of all values in the multimap. Changes to the returned - * collection will update the underlying multimap, and vice versa. - * - *

The iterator generated by the returned collection traverses the values - * in the order they were added to the multimap. - */ - @Override public Collection values() { - return super.values(); - } - - // Unfortunately, the entries() ordering does not determine the key ordering; - // see the example in the LinkedListMultimap class Javadoc. - - /** - * @serialData the number of distinct keys, and then for each distinct key: - * the first key, the number of values for that key, and the key's values, - * followed by successive keys and values from the entries() ordering - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeInt(expectedValuesPerKey); - Serialization.writeMultimap(this, stream); - for (Map.Entry entry : linkedEntries) { - stream.writeObject(entry.getKey()); - stream.writeObject(entry.getValue()); - } - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - expectedValuesPerKey = stream.readInt(); - int distinctKeys = Serialization.readCount(stream); - setMap(new LinkedHashMap>(Maps.capacity(distinctKeys))); - linkedEntries = new LinkedHashSet>( - distinctKeys * expectedValuesPerKey); - Serialization.populateMultimap(this, stream, distinctKeys); - linkedEntries.clear(); // will clear and repopulate entries - for (int i = 0; i < size(); i++) { - @SuppressWarnings("unchecked") // reading data stored by writeObject - K key = (K) stream.readObject(); - @SuppressWarnings("unchecked") // reading data stored by writeObject - V value = (V) stream.readObject(); - linkedEntries.add(Maps.immutableEntry(key, value)); - } - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedHashMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedHashMultiset.java deleted file mode 100644 index 4e7e0c83694..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedHashMultiset.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.LinkedHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * A {@code Multiset} implementation with predictable iteration order. Its - * iterator orders elements according to when the first occurrence of the - * element was added. When the multiset contains multiple instances of an - * element, those instances are consecutive in the iteration order. If all - * occurrences of an element are removed, after which that element is added to - * the multiset, the element will appear at the end of the iteration. - * - * @author Kevin Bourrillion - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // we're overriding default serialization -public final class LinkedHashMultiset extends AbstractMapBasedMultiset { - - /** - * Creates a new, empty {@code LinkedHashMultiset} using the default initial - * capacity. - */ - public static LinkedHashMultiset create() { - return new LinkedHashMultiset(); - } - - /** - * Creates a new, empty {@code LinkedHashMultiset} with the specified expected - * number of distinct elements. - * - * @param distinctElements the expected number of distinct elements - * @throws IllegalArgumentException if {@code distinctElements} is negative - */ - public static LinkedHashMultiset create(int distinctElements) { - return new LinkedHashMultiset(distinctElements); - } - - /** - * Creates a new {@code LinkedHashMultiset} containing the specified elements. - * - * @param elements the elements that the multiset should contain - */ - public static LinkedHashMultiset create( - Iterable elements) { - LinkedHashMultiset multiset = - create(Multisets.inferDistinctElements(elements)); - Iterables.addAll(multiset, elements); - return multiset; - } - - private LinkedHashMultiset() { - super(new LinkedHashMap()); - } - - private LinkedHashMultiset(int distinctElements) { - // Could use newLinkedHashMapWithExpectedSize() if it existed - super(new LinkedHashMap(Maps.capacity(distinctElements))); - } - - /** - * @serialData the number of distinct elements, the first element, its count, - * the second element, its count, and so on - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - Serialization.writeMultiset(this, stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - int distinctElements = Serialization.readCount(stream); - setBackingMap(new LinkedHashMap( - Maps.capacity(distinctElements))); - Serialization.populateMultiset(this, stream, distinctElements); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedListMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedListMultimap.java deleted file mode 100644 index 3889612f5a5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/LinkedListMultimap.java +++ /dev/null @@ -1,939 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Objects; -import org.elasticsearch.util.base.Preconditions; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.*; -import java.util.Map.Entry; - -import static java.util.Collections.*; -import static org.elasticsearch.util.base.Preconditions.*; -import static org.elasticsearch.util.collect.Multisets.*; - -/** - * An implementation of {@code ListMultimap} that supports deterministic - * iteration order for both keys and values. The iteration order is preserved - * across non-distinct key values. For example, for the following multimap - * definition:

   {@code
- *
- *   Multimap multimap = LinkedListMultimap.create();
- *   multimap.put(key1, foo);
- *   multimap.put(key2, bar);
- *   multimap.put(key1, baz);}
- * - * ... the iteration order for {@link #keys()} is {@code [key1, key2, key1]}, - * and similarly for {@link #entries()}. Unlike {@link LinkedHashMultimap}, the - * iteration order is kept consistent between keys, entries and values. For - * example, calling:
   {@code
- *
- *   map.remove(key1, foo);}
- * - * changes the entries iteration order to {@code [key2=bar, key1=baz]} and the - * key iteration order to {@code [key2, key1]}. The {@link #entries()} iterator - * returns mutable map entries, and {@link #replaceValues} attempts to preserve - * iteration order as much as possible. - * - *

The collections returned by {@link #keySet} and {@link #asMap} iterate - * through the keys in the order they were first added to the multimap. - * Similarly, {@link #get}, {@link #removeAll}, and {@link #replaceValues} - * return collections that iterate through the values in the order they were - * added. The collections generated by {@link #entries}, {@link #keys}, and - * {@link #values} iterate across the key-value mappings in the order they were - * added to the multimap. - * - *

Keys and values may be null. All optional multimap methods are supported, - * and all returned views are modifiable. - * - *

The methods {@link #get}, {@link #keySet}, {@link #keys}, {@link #values}, - * {@link #entries}, and {@link #asMap} return collections that are views of the - * multimap. If the multimap is modified while an iteration over any of those - * collections is in progress, except through the iterator's own {@code remove} - * operation, the results of the iteration are undefined. - * - *

This class is not threadsafe when any concurrent operations update the - * multimap. Concurrent read operations will work correctly. To allow concurrent - * update operations, wrap your multimap with a call to {@link - * Multimaps#synchronizedListMultimap}. - * - * @author Mike Bostock - */ -@GwtCompatible(serializable = true) -public final class LinkedListMultimap - implements ListMultimap, Serializable { - /* - * Order is maintained using a linked list containing all key-value pairs. In - * addition, a series of disjoint linked lists of "siblings", each containing - * the values for a specific key, is used to implement {@link - * ValueForKeyIterator} in constant time. - */ - - private static final class Node { - final K key; - V value; - Node next; // the next node (with any key) - Node previous; // the previous node (with any key) - Node nextSibling; // the next node with the same key - Node previousSibling; // the previous node with the same key - - Node(@Nullable K key, @Nullable V value) { - this.key = key; - this.value = value; - } - - @Override public String toString() { - return key + "=" + value; - } - } - - private transient Node head; // the head for all keys - private transient Node tail; // the tail for all keys - private transient Multiset keyCount; // the number of values for each key - private transient Map> keyToKeyHead; // the head for a given key - private transient Map> keyToKeyTail; // the tail for a given key - - /** - * Creates a new, empty {@code LinkedListMultimap} with the default initial - * capacity. - */ - public static LinkedListMultimap create() { - return new LinkedListMultimap(); - } - - /** - * Constructs an empty {@code LinkedListMultimap} with enough capacity to hold - * the specified number of keys without rehashing. - * - * @param expectedKeys the expected number of distinct keys - * @throws IllegalArgumentException if {@code expectedKeys} is negative - */ - public static LinkedListMultimap create(int expectedKeys) { - return new LinkedListMultimap(expectedKeys); - } - - /** - * Constructs a {@code LinkedListMultimap} with the same mappings as the - * specified {@code Multimap}. The new multimap has the same - * {@link Multimap#entries()} iteration order as the input multimap. - * - * @param multimap the multimap whose contents are copied to this multimap - */ - public static LinkedListMultimap create( - Multimap multimap) { - return new LinkedListMultimap(multimap); - } - - private LinkedListMultimap() { - keyCount = LinkedHashMultiset.create(); - keyToKeyHead = Maps.newHashMap(); - keyToKeyTail = Maps.newHashMap(); - } - - private LinkedListMultimap(int expectedKeys) { - keyCount = LinkedHashMultiset.create(expectedKeys); - keyToKeyHead = Maps.newHashMapWithExpectedSize(expectedKeys); - keyToKeyTail = Maps.newHashMapWithExpectedSize(expectedKeys); - } - - private LinkedListMultimap(Multimap multimap) { - this(multimap.keySet().size()); - putAll(multimap); - } - - /** - * Adds a new node for the specified key-value pair before the specified - * {@code nextSibling} element, or at the end of the list if {@code - * nextSibling} is null. Note: if {@code nextSibling} is specified, it MUST be - * for an node for the same {@code key}! - */ - private Node addNode( - @Nullable K key, @Nullable V value, @Nullable Node nextSibling) { - Node node = new Node(key, value); - if (head == null) { // empty list - head = tail = node; - keyToKeyHead.put(key, node); - keyToKeyTail.put(key, node); - } else if (nextSibling == null) { // non-empty list, add to tail - tail.next = node; - node.previous = tail; - Node keyTail = keyToKeyTail.get(key); - if (keyTail == null) { // first for this key - keyToKeyHead.put(key, node); - } else { - keyTail.nextSibling = node; - node.previousSibling = keyTail; - } - keyToKeyTail.put(key, node); - tail = node; - } else { // non-empty list, insert before nextSibling - node.previous = nextSibling.previous; - node.previousSibling = nextSibling.previousSibling; - node.next = nextSibling; - node.nextSibling = nextSibling; - if (nextSibling.previousSibling == null) { // nextSibling was key head - keyToKeyHead.put(key, node); - } else { - nextSibling.previousSibling.nextSibling = node; - } - if (nextSibling.previous == null) { // nextSibling was head - head = node; - } else { - nextSibling.previous.next = node; - } - nextSibling.previous = node; - nextSibling.previousSibling = node; - } - keyCount.add(key); - return node; - } - - /** - * Removes the specified node from the linked list. This method is only - * intended to be used from the {@code Iterator} classes. See also {@link - * LinkedListMultimap#removeAllNodes(Object)}. - */ - private void removeNode(Node node) { - if (node.previous != null) { - node.previous.next = node.next; - } else { // node was head - head = node.next; - } - if (node.next != null) { - node.next.previous = node.previous; - } else { // node was tail - tail = node.previous; - } - if (node.previousSibling != null) { - node.previousSibling.nextSibling = node.nextSibling; - } else if (node.nextSibling != null) { // node was key head - keyToKeyHead.put(node.key, node.nextSibling); - } else { - keyToKeyHead.remove(node.key); // don't leak a key-null entry - } - if (node.nextSibling != null) { - node.nextSibling.previousSibling = node.previousSibling; - } else if (node.previousSibling != null) { // node was key tail - keyToKeyTail.put(node.key, node.previousSibling); - } else { - keyToKeyTail.remove(node.key); // don't leak a key-null entry - } - keyCount.remove(node.key); - } - - /** Removes all nodes for the specified key. */ - private void removeAllNodes(@Nullable Object key) { - for (Iterator i = new ValueForKeyIterator(key); i.hasNext();) { - i.next(); - i.remove(); - } - } - - /** Helper method for verifying that an iterator element is present. */ - private static void checkElement(@Nullable Object node) { - if (node == null) { - throw new NoSuchElementException(); - } - } - - /** An {@code Iterator} over all nodes. */ - private class NodeIterator implements Iterator> { - Node next = head; - Node current; - - public boolean hasNext() { - return next != null; - } - public Node next() { - checkElement(next); - current = next; - next = next.next; - return current; - } - public void remove() { - checkState(current != null); - removeNode(current); - current = null; - } - } - - /** An {@code Iterator} over distinct keys in key head order. */ - private class DistinctKeyIterator implements Iterator { - final Set seenKeys = new HashSet(Maps.capacity(keySet().size())); - Node next = head; - Node current; - - public boolean hasNext() { - return next != null; - } - public K next() { - checkElement(next); - current = next; - seenKeys.add(current.key); - do { // skip ahead to next unseen key - next = next.next; - } while ((next != null) && !seenKeys.add(next.key)); - return current.key; - } - public void remove() { - checkState(current != null); - removeAllNodes(current.key); - current = null; - } - } - - /** A {@code ListIterator} over values for a specified key. */ - private class ValueForKeyIterator implements ListIterator { - final Object key; - int nextIndex; - Node next; - Node current; - Node previous; - - /** Constructs a new iterator over all values for the specified key. */ - ValueForKeyIterator(@Nullable Object key) { - this.key = key; - next = keyToKeyHead.get(key); - } - - /** - * Constructs a new iterator over all values for the specified key starting - * at the specified index. This constructor is optimized so that it starts - * at either the head or the tail, depending on which is closer to the - * specified index. This allows adds to the tail to be done in constant - * time. - * - * @throws IndexOutOfBoundsException if index is invalid - */ - public ValueForKeyIterator(@Nullable Object key, int index) { - int size = keyCount.count(key); - Preconditions.checkPositionIndex(index, size); - if (index >= (size / 2)) { - previous = keyToKeyTail.get(key); - nextIndex = size; - while (index++ < size) { - previous(); - } - } else { - next = keyToKeyHead.get(key); - while (index-- > 0) { - next(); - } - } - this.key = key; - current = null; - } - - public boolean hasNext() { - return next != null; - } - - public V next() { - checkElement(next); - previous = current = next; - next = next.nextSibling; - nextIndex++; - return current.value; - } - - public boolean hasPrevious() { - return previous != null; - } - - public V previous() { - checkElement(previous); - next = current = previous; - previous = previous.previousSibling; - nextIndex--; - return current.value; - } - - public int nextIndex() { - return nextIndex; - } - - public int previousIndex() { - return nextIndex - 1; - } - - public void remove() { - checkState(current != null); - if (current != next) { // removing next element - previous = current.previousSibling; - nextIndex--; - } else { - next = current.nextSibling; - } - removeNode(current); - current = null; - } - - public void set(V value) { - checkState(current != null); - current.value = value; - } - - @SuppressWarnings("unchecked") - public void add(V value) { - previous = addNode((K) key, value, next); - nextIndex++; - current = null; - } - } - - // Query Operations - - public int size() { - return keyCount.size(); - } - - public boolean isEmpty() { - return head == null; - } - - public boolean containsKey(@Nullable Object key) { - return keyToKeyHead.containsKey(key); - } - - public boolean containsValue(@Nullable Object value) { - for (Iterator> i = new NodeIterator(); i.hasNext();) { - if (Objects.equal(i.next().value, value)) { - return true; - } - } - return false; - } - - public boolean containsEntry(@Nullable Object key, @Nullable Object value) { - for (Iterator i = new ValueForKeyIterator(key); i.hasNext();) { - if (Objects.equal(i.next(), value)) { - return true; - } - } - return false; - } - - // Modification Operations - - /** - * Stores a key-value pair in the multimap. - * - * @param key key to store in the multimap - * @param value value to store in the multimap - * @return {@code true} always - */ - public boolean put(@Nullable K key, @Nullable V value) { - addNode(key, value, null); - return true; - } - - public boolean remove(@Nullable Object key, @Nullable Object value) { - Iterator values = new ValueForKeyIterator(key); - while (values.hasNext()) { - if (Objects.equal(values.next(), value)) { - values.remove(); - return true; - } - } - return false; - } - - // Bulk Operations - - public boolean putAll(@Nullable K key, Iterable values) { - boolean changed = false; - for (V value : values) { - changed |= put(key, value); - } - return changed; - } - - public boolean putAll(Multimap multimap) { - boolean changed = false; - for (Entry entry : multimap.entries()) { - changed |= put(entry.getKey(), entry.getValue()); - } - return changed; - } - - /** - * {@inheritDoc} - * - *

If any entries for the specified {@code key} already exist in the - * multimap, their values are changed in-place without affecting the iteration - * order. - * - *

The returned list is immutable and implements - * {@link java.util.RandomAccess}. - */ - public List replaceValues(@Nullable K key, Iterable values) { - List oldValues = getCopy(key); - ListIterator keyValues = new ValueForKeyIterator(key); - Iterator newValues = values.iterator(); - - // Replace existing values, if any. - while (keyValues.hasNext() && newValues.hasNext()) { - keyValues.next(); - keyValues.set(newValues.next()); - } - - // Remove remaining old values, if any. - while (keyValues.hasNext()) { - keyValues.next(); - keyValues.remove(); - } - - // Add remaining new values, if any. - while (newValues.hasNext()) { - keyValues.add(newValues.next()); - } - - return oldValues; - } - - private List getCopy(@Nullable Object key) { - return unmodifiableList(Lists.newArrayList(new ValueForKeyIterator(key))); - } - - /** - * {@inheritDoc} - * - *

The returned list is immutable and implements - * {@link java.util.RandomAccess}. - */ - public List removeAll(@Nullable Object key) { - List oldValues = getCopy(key); - removeAllNodes(key); - return oldValues; - } - - public void clear() { - head = null; - tail = null; - keyCount.clear(); - keyToKeyHead.clear(); - keyToKeyTail.clear(); - } - - // Views - - /** - * {@inheritDoc} - * - *

If the multimap is modified while an iteration over the list is in - * progress (except through the iterator's own {@code add}, {@code set} or - * {@code remove} operations) the results of the iteration are undefined. - * - *

The returned list is not serializable and does not have random access. - */ - public List get(final @Nullable K key) { - return new AbstractSequentialList() { - @Override public int size() { - return keyCount.count(key); - } - @Override public ListIterator listIterator(int index) { - return new ValueForKeyIterator(key, index); - } - @Override public boolean removeAll(Collection c) { - return Iterators.removeAll(iterator(), c); - } - @Override public boolean retainAll(Collection c) { - return Iterators.retainAll(iterator(), c); - } - }; - } - - private transient Set keySet; - - public Set keySet() { - Set result = keySet; - if (result == null) { - keySet = result = new AbstractSet() { - @Override public int size() { - return keyCount.elementSet().size(); - } - @Override public Iterator iterator() { - return new DistinctKeyIterator(); - } - @Override public boolean contains(Object key) { // for performance - return keyCount.contains(key); - } - }; - } - return result; - } - - private transient Multiset keys; - - public Multiset keys() { - Multiset result = keys; - if (result == null) { - keys = result = new MultisetView(); - } - return result; - } - - private class MultisetView extends AbstractCollection - implements Multiset { - - @Override public int size() { - return keyCount.size(); - } - - @Override public Iterator iterator() { - final Iterator> nodes = new NodeIterator(); - return new Iterator() { - public boolean hasNext() { - return nodes.hasNext(); - } - public K next() { - return nodes.next().key; - } - public void remove() { - nodes.remove(); - } - }; - } - - public int count(@Nullable Object key) { - return keyCount.count(key); - } - - public int add(@Nullable K key, int occurrences) { - throw new UnsupportedOperationException(); - } - - public int remove(@Nullable Object key, int occurrences) { - checkArgument(occurrences >= 0); - int oldCount = count(key); - Iterator values = new ValueForKeyIterator(key); - while ((occurrences-- > 0) && values.hasNext()) { - values.next(); - values.remove(); - } - return oldCount; - } - - public int setCount(K element, int count) { - return setCountImpl(this, element, count); - } - - public boolean setCount(K element, int oldCount, int newCount) { - return setCountImpl(this, element, oldCount, newCount); - } - - @Override public boolean removeAll(Collection c) { - return Iterators.removeAll(iterator(), c); - } - - @Override public boolean retainAll(Collection c) { - return Iterators.retainAll(iterator(), c); - } - - public Set elementSet() { - return keySet(); - } - - public Set> entrySet() { - // TODO: lazy init? - return new AbstractSet>() { - @Override public int size() { - return keyCount.elementSet().size(); - } - - @Override public Iterator> iterator() { - final Iterator keyIterator = new DistinctKeyIterator(); - return new Iterator>() { - public boolean hasNext() { - return keyIterator.hasNext(); - } - public Entry next() { - final K key = keyIterator.next(); - return new Multisets.AbstractEntry() { - public K getElement() { - return key; - } - public int getCount() { - return keyCount.count(key); - } - }; - } - public void remove() { - keyIterator.remove(); - } - }; - } - }; - } - - @Override public boolean equals(@Nullable Object object) { - return keyCount.equals(object); - } - - @Override public int hashCode() { - return keyCount.hashCode(); - } - - @Override public String toString() { - return keyCount.toString(); // XXX observe order? - } - } - - private transient Collection valuesCollection; - - /** - * {@inheritDoc} - * - *

The iterator generated by the returned collection traverses the values - * in the order they were added to the multimap. - */ - public Collection values() { - Collection result = valuesCollection; - if (result == null) { - valuesCollection = result = new AbstractCollection() { - @Override public int size() { - return keyCount.size(); - } - @Override public Iterator iterator() { - final Iterator> nodes = new NodeIterator(); - return new Iterator() { - public boolean hasNext() { - return nodes.hasNext(); - } - public V next() { - return nodes.next().value; - } - public void remove() { - nodes.remove(); - } - }; - } - }; - } - return result; - } - - private transient Collection> entries; - - /** - * {@inheritDoc} - * - *

The iterator generated by the returned collection traverses the entries - * in the order they were added to the multimap. - * - *

An entry's {@link Entry#getKey} method always returns the same key, - * regardless of what happens subsequently. As long as the corresponding - * key-value mapping is not removed from the multimap, {@link Entry#getValue} - * returns the value from the multimap, which may change over time, and {@link - * Entry#setValue} modifies that value. Removing the mapping from the - * multimap does not alter the value returned by {@code getValue()}, though a - * subsequent {@code setValue()} call won't update the multimap but will lead - * to a revised value being returned by {@code getValue()}. - */ - public Collection> entries() { - Collection> result = entries; - if (result == null) { - entries = result = new AbstractCollection>() { - @Override public int size() { - return keyCount.size(); - } - - @Override public Iterator> iterator() { - final Iterator> nodes = new NodeIterator(); - return new Iterator>() { - public boolean hasNext() { - return nodes.hasNext(); - } - - public Entry next() { - final Node node = nodes.next(); - return new AbstractMapEntry() { - @Override public K getKey() { - return node.key; - } - @Override public V getValue() { - return node.value; - } - @Override public V setValue(V value) { - V oldValue = node.value; - node.value = value; - return oldValue; - } - }; - } - - public void remove() { - nodes.remove(); - } - }; - } - }; - } - return result; - } - - private class AsMapEntries extends AbstractSet>> { - - // TODO: Override contains() and remove() for better performance. - - @Override public int size() { - return keyCount.elementSet().size(); - } - - @Override public Iterator>> iterator() { - final Iterator keyIterator = new DistinctKeyIterator(); - return new Iterator>>() { - public boolean hasNext() { - return keyIterator.hasNext(); - } - - public Entry> next() { - final K key = keyIterator.next(); - return new AbstractMapEntry>() { - @Override public K getKey() { - return key; - } - - @Override public Collection getValue() { - return LinkedListMultimap.this.get(key); - } - }; - } - - public void remove() { - keyIterator.remove(); - } - }; - } - } - - private transient Map> map; - - public Map> asMap() { - Map> result = map; - if (result == null) { - map = result = new AbstractMap>() { - Set>> entrySet; - - @Override public Set>> entrySet() { - Set>> result = entrySet; - if (result == null) { - entrySet = result = new AsMapEntries(); - } - return result; - } - - // The following methods are included for performance. - - @Override public boolean containsKey(@Nullable Object key) { - return LinkedListMultimap.this.containsKey(key); - } - - @SuppressWarnings("unchecked") - @Override public Collection get(@Nullable Object key) { - Collection collection = LinkedListMultimap.this.get((K) key); - return collection.isEmpty() ? null : collection; - } - - @Override public Collection remove(@Nullable Object key) { - Collection collection = removeAll(key); - return collection.isEmpty() ? null : collection; - } - }; - } - - return result; - } - - // Comparison and hashing - - /** - * Compares the specified object to this multimap for equality. - * - *

Two {@code ListMultimap} instances are equal if, for each key, they - * contain the same values in the same order. If the value orderings disagree, - * the multimaps will not be considered equal. - */ - @Override public boolean equals(@Nullable Object other) { - if (other == this) { - return true; - } - if (other instanceof Multimap) { - Multimap that = (Multimap) other; - return this.asMap().equals(that.asMap()); - } - return false; - } - - /** - * Returns the hash code for this multimap. - * - *

The hash code of a multimap is defined as the hash code of the map view, - * as returned by {@link Multimap#asMap}. - */ - @Override public int hashCode() { - return asMap().hashCode(); - } - - /** - * Returns a string representation of the multimap, generated by calling - * {@code toString} on the map returned by {@link Multimap#asMap}. - * - * @return a string representation of the multimap - */ - @Override public String toString() { - return asMap().toString(); - } - - /** - * @serialData the number of distinct keys, and then for each distinct key: - * the first key, the number of values for that key, and the key's values, - * followed by successive keys and values from the entries() ordering - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeInt(size()); - for (Entry entry : entries()) { - stream.writeObject(entry.getKey()); - stream.writeObject(entry.getValue()); - } - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - keyCount = LinkedHashMultiset.create(); - keyToKeyHead = Maps.newHashMap(); - keyToKeyTail = Maps.newHashMap(); - int size = stream.readInt(); - for (int i = 0; i < size; i++) { - @SuppressWarnings("unchecked") // reading data stored by writeObject - K key = (K) stream.readObject(); - @SuppressWarnings("unchecked") // reading data stored by writeObject - V value = (V) stream.readObject(); - put(key, value); - } - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ListMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ListMultimap.java deleted file mode 100644 index dc89640e12a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ListMultimap.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -/** - * A {@code Multimap} that can hold duplicate key-value pairs and that maintains - * the insertion ordering of values for a given key. - * - *

The {@link #get}, {@link #removeAll}, and {@link #replaceValues} methods - * each return a {@link List} of values. Though the method signature doesn't say - * so explicitly, the map returned by {@link #asMap} has {@code List} values. - * - * @author Jared Levy - */ -@GwtCompatible -public interface ListMultimap extends Multimap { - /** - * {@inheritDoc} - * - *

Because the values for a given key may have duplicates and follow the - * insertion ordering, this method returns a {@link List}, instead of the - * {@link java.util.Collection} specified in the {@link Multimap} interface. - */ - List get(@Nullable K key); - - /** - * {@inheritDoc} - * - *

Because the values for a given key may have duplicates and follow the - * insertion ordering, this method returns a {@link List}, instead of the - * {@link java.util.Collection} specified in the {@link Multimap} interface. - */ - List removeAll(@Nullable Object key); - - /** - * {@inheritDoc} - * - *

Because the values for a given key may have duplicates and follow the - * insertion ordering, this method returns a {@link List}, instead of the - * {@link java.util.Collection} specified in the {@link Multimap} interface. - */ - List replaceValues(K key, Iterable values); - - /** - * {@inheritDoc} - * - *

Though the method signature doesn't say so explicitly, the returned map - * has {@link List} values. - */ - Map> asMap(); - - /** - * Compares the specified object to this multimap for equality. - * - *

Two {@code ListMultimap} instances are equal if, for each key, they - * contain the same values in the same order. If the value orderings disagree, - * the multimaps will not be considered equal. - */ - boolean equals(@Nullable Object obj); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Lists.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Lists.java deleted file mode 100644 index 6b548c56ea8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Lists.java +++ /dev/null @@ -1,491 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.VisibleForTesting; -import org.elasticsearch.util.base.Function; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Static utility methods pertaining to {@link List} instances. Also see this - * class's counterparts {@link Sets} and {@link Maps}. - * - * @author Kevin Bourrillion - * @author Mike Bostock - */ -@GwtCompatible -public final class Lists { - private Lists() {} - - // ArrayList - - /** - * Creates a mutable, empty {@code ArrayList} instance. - * - *

Note: if mutability is not required, use {@link - * ImmutableList#of()} instead. - * - * @return a new, empty {@code ArrayList} - */ - @GwtCompatible(serializable = true) - public static ArrayList newArrayList() { - return new ArrayList(); - } - - /** - * Creates a mutable {@code ArrayList} instance containing the given - * elements. - * - *

Note: if mutability is not required and the elements are - * non-null, use {@link ImmutableList#of(Object[])} instead. - * - * @param elements the elements that the list should contain, in order - * @return a new {@code ArrayList} containing those elements - */ - @GwtCompatible(serializable = true) - public static ArrayList newArrayList(E... elements) { - checkNotNull(elements); // for GWT - // Avoid integer overflow when a large array is passed in - int capacity = computeArrayListCapacity(elements.length); - ArrayList list = new ArrayList(capacity); - Collections.addAll(list, elements); - return list; - } - - @VisibleForTesting static int computeArrayListCapacity(int arraySize) { - checkArgument(arraySize >= 0); - - // TODO: Figure out the right behavior, and document it - return (int) Math.min(5L + arraySize + (arraySize / 10), Integer.MAX_VALUE); - } - - /** - * Creates a mutable {@code ArrayList} instance containing the given - * elements. - * - *

Note: if mutability is not required and the elements are - * non-null, use {@link ImmutableList#copyOf(Iterator)} instead. - * - * @param elements the elements that the list should contain, in order - * @return a new {@code ArrayList} containing those elements - */ - @GwtCompatible(serializable = true) - public static ArrayList newArrayList(Iterable elements) { - checkNotNull(elements); // for GWT - // Let ArrayList's sizing logic work, if possible - if (elements instanceof Collection) { - @SuppressWarnings("unchecked") - Collection collection = (Collection) elements; - return new ArrayList(collection); - } else { - return newArrayList(elements.iterator()); - } - } - - /** - * Creates a mutable {@code ArrayList} instance containing the given - * elements. - * - *

Note: if mutability is not required and the elements are - * non-null, use {@link ImmutableList#copyOf(Iterator)} instead. - * - * @param elements the elements that the list should contain, in order - * @return a new {@code ArrayList} containing those elements - */ - @GwtCompatible(serializable = true) - public static ArrayList newArrayList(Iterator elements) { - checkNotNull(elements); // for GWT - ArrayList list = newArrayList(); - while (elements.hasNext()) { - list.add(elements.next()); - } - return list; - } - - /** - * Creates an {@code ArrayList} instance backed by an array of the - * exact size specified; equivalent to - * {@link ArrayList#ArrayList(int)}. - * - *

Note: if you know the exact size your list will be, consider - * using a fixed-size list ({@link Arrays#asList(Object[])}) or an {@link - * ImmutableList} instead of a growable {@link ArrayList}. - * - *

Note: If you have only an estimate of the eventual size of - * the list, consider padding this estimate by a suitable amount, or simply - * use {@link #newArrayListWithExpectedSize(int)} instead. - * - * @param initialArraySize the exact size of the initial backing array for - * the returned array list ({@code ArrayList} documentation calls this - * value the "capacity") - * @return a new, empty {@code ArrayList} which is guaranteed not to resize - * itself unless its size reaches {@code initialArraySize + 1} - * @throws IllegalArgumentException if {@code initialArraySize} is negative - */ - @GwtCompatible(serializable = true) - public static ArrayList newArrayListWithCapacity( - int initialArraySize) { - return new ArrayList(initialArraySize); - } - - /** - * Creates an {@code ArrayList} instance sized appropriately to hold an - * estimated number of elements without resizing. A small amount of - * padding is added in case the estimate is low. - * - *

Note: If you know the exact number of elements the list - * will hold, or prefer to calculate your own amount of padding, refer to - * {@link #newArrayListWithCapacity(int)}. - * - * @param estimatedSize an estimate of the eventual {@link List#size()} of - * the new list - * @return a new, empty {@code ArrayList}, sized appropriately to hold the - * estimated number of elements - * @throws IllegalArgumentException if {@code estimatedSize} is negative - */ - @GwtCompatible(serializable = true) - public static ArrayList newArrayListWithExpectedSize( - int estimatedSize) { - return new ArrayList(computeArrayListCapacity(estimatedSize)); - } - - // LinkedList - - /** - * Creates an empty {@code LinkedList} instance. - * - *

Note: if you need an immutable empty {@link List}, use - * {@link Collections#emptyList} instead. - * - * @return a new, empty {@code LinkedList} - */ - @GwtCompatible(serializable = true) - public static LinkedList newLinkedList() { - return new LinkedList(); - } - - /** - * Creates a {@code LinkedList} instance containing the given elements. - * - * @param elements the elements that the list should contain, in order - * @return a new {@code LinkedList} containing those elements - */ - @GwtCompatible(serializable = true) - public static LinkedList newLinkedList( - Iterable elements) { - LinkedList list = newLinkedList(); - for (E element : elements) { - list.add(element); - } - return list; - } - - /** - * Returns an unmodifiable list containing the specified first element and - * backed by the specified array of additional elements. Changes to the {@code - * rest} array will be reflected in the returned list. Unlike {@link - * Arrays#asList}, the returned list is unmodifiable. - * - *

This is useful when a varargs method needs to use a signature such as - * {@code (Foo firstFoo, Foo... moreFoos)}, in order to avoid overload - * ambiguity or to enforce a minimum argument count. - * - *

The returned list is serializable and implements {@link RandomAccess}. - * - * @param first the first element - * @param rest an array of additional elements, possibly empty - * @return an unmodifiable list containing the specified elements - */ - public static List asList(@Nullable E first, E[] rest) { - return new OnePlusArrayList(first, rest); - } - - /** @see Lists#asList(Object, Object[]) */ - private static class OnePlusArrayList extends AbstractList - implements Serializable, RandomAccess { - final E first; - final E[] rest; - - OnePlusArrayList(@Nullable E first, E[] rest) { - this.first = first; - this.rest = checkNotNull(rest); - } - @Override public int size() { - return rest.length + 1; - } - @Override public E get(int index) { - // check explicitly so the IOOBE will have the right message - checkElementIndex(index, size()); - return (index == 0) ? first : rest[index - 1]; - } - private static final long serialVersionUID = 0; - } - - /** - * Returns an unmodifiable list containing the specified first and second - * element, and backed by the specified array of additional elements. Changes - * to the {@code rest} array will be reflected in the returned list. Unlike - * {@link Arrays#asList}, the returned list is unmodifiable. - * - *

This is useful when a varargs method needs to use a signature such as - * {@code (Foo firstFoo, Foo secondFoo, Foo... moreFoos)}, in order to avoid - * overload ambiguity or to enforce a minimum argument count. - * - *

The returned list is serializable and implements {@link RandomAccess}. - * - * @param first the first element - * @param second the second element - * @param rest an array of additional elements, possibly empty - * @return an unmodifiable list containing the specified elements - */ - public static List asList( - @Nullable E first, @Nullable E second, E[] rest) { - return new TwoPlusArrayList(first, second, rest); - } - - /** @see Lists#asList(Object, Object, Object[]) */ - private static class TwoPlusArrayList extends AbstractList - implements Serializable, RandomAccess { - final E first; - final E second; - final E[] rest; - - TwoPlusArrayList(@Nullable E first, @Nullable E second, E[] rest) { - this.first = first; - this.second = second; - this.rest = checkNotNull(rest); - } - @Override public int size() { - return rest.length + 2; - } - @Override public E get(int index) { - switch (index) { - case 0: - return first; - case 1: - return second; - default: - // check explicitly so the IOOBE will have the right message - checkElementIndex(index, size()); - return rest[index - 2]; - } - } - private static final long serialVersionUID = 0; - } - - /** - * Returns a list that applies {@code function} to each element of {@code - * fromList}. The returned list is a transformed view of {@code fromList}; - * changes to {@code fromList} will be reflected in the returned list and vice - * versa. - * - *

Since functions are not reversible, the transform is one-way and new - * items cannot be stored in the returned list. The {@code add}, - * {@code addAll} and {@code set} methods are unsupported in the returned - * list. - * - *

The function is applied lazily, invoked when needed. This is necessary - * for the returned list to be a view, but it means that the function will be - * applied many times for bulk operations like {@link List#contains} and - * {@link List#hashCode}. For this to perform well, {@code function} should be - * fast. To avoid lazy evaluation when the returned list doesn't need to be a - * view, copy the returned list into a new list of your choosing. - * - *

If {@code fromList} implements {@link RandomAccess}, so will the - * returned list. The returned list always implements {@link Serializable}, - * but serialization will succeed only when {@code fromList} and - * {@code function} are serializable. The returned list is threadsafe if the - * supplied list and function are. - */ - public static List transform( - List fromList, Function function) { - return (fromList instanceof RandomAccess) - ? new TransformingRandomAccessList(fromList, function) - : new TransformingSequentialList(fromList, function); - } - - /** - * Implementation of a sequential transforming list. - * - * @see Lists#transform - */ - private static class TransformingSequentialList - extends AbstractSequentialList implements Serializable { - final List fromList; - final Function function; - - TransformingSequentialList( - List fromList, Function function) { - this.fromList = checkNotNull(fromList); - this.function = checkNotNull(function); - } - /** - * The default implementation inherited is based on iteration and removal of - * each element which can be overkill. That's why we forward this call - * directly to the backing list. - */ - @Override public void clear() { - fromList.clear(); - } - @Override public int size() { - return fromList.size(); - } - @Override public ListIterator listIterator(final int index) { - final ListIterator delegate = fromList.listIterator(index); - return new ListIterator() { - public void add(T e) { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - return delegate.hasNext(); - } - - public boolean hasPrevious() { - return delegate.hasPrevious(); - } - - public T next() { - return function.apply(delegate.next()); - } - - public int nextIndex() { - return delegate.nextIndex(); - } - - public T previous() { - return function.apply(delegate.previous()); - } - - public int previousIndex() { - return delegate.previousIndex(); - } - - public void remove() { - delegate.remove(); - } - - public void set(T e) { - throw new UnsupportedOperationException("not supported"); - } - }; - } - - private static final long serialVersionUID = 0; - } - - /** - * Implementation of a transforming random access list. We try to make as many - * of these methods pass-through to the source list as possible so that the - * performance characteristics of the source list and transformed list are - * similar. - * - * @see Lists#transform - */ - private static class TransformingRandomAccessList - extends AbstractList implements RandomAccess, Serializable { - final List fromList; - final Function function; - - TransformingRandomAccessList( - List fromList, Function function) { - this.fromList = checkNotNull(fromList); - this.function = checkNotNull(function); - } - @Override public void clear() { - fromList.clear(); - } - @Override public T get(int index) { - return function.apply(fromList.get(index)); - } - @Override public boolean isEmpty() { - return fromList.isEmpty(); - } - @Override public T remove(int index) { - return function.apply(fromList.remove(index)); - } - @Override public int size() { - return fromList.size(); - } - private static final long serialVersionUID = 0; - } - - /** - * Returns consecutive {@linkplain List#subList(int, int) sublists} of a list, - * each of the same size (the final list may be smaller). For example, - * partitioning a list containing {@code [a, b, c, d, e]} with a partition - * size of 3 yields {@code [[a, b, c], [d, e]]} -- an outer list containing - * two inner lists of three and two elements, all in the original order. - * - *

The outer list is unmodifiable, but reflects the latest state of the - * source list. The inner lists are sublist views of the original list, - * produced on demand using {@link List#subList(int, int)}, and are subject - * to all the usual caveats about modification as explained in that API. - * - * @param list the list to return consecutive sublists of - * @param size the desired size of each sublist (the last may be - * smaller) - * @return a list of consecutive sublists - * @throws IllegalArgumentException if {@code partitionSize} is nonpositive - */ - public static List> partition(List list, int size) { - checkNotNull(list); - checkArgument(size > 0); - return (list instanceof RandomAccess) - ? new RandomAccessPartition(list, size) - : new Partition(list, size); - } - - private static class Partition extends AbstractList> { - final List list; - final int size; - - Partition(List list, int size) { - this.list = list; - this.size = size; - } - - @Override public List get(int index) { - int listSize = size(); - checkElementIndex(index, listSize); - int start = index * size; - int end = Math.min(start + size, list.size()); - return Platform.subList(list, start, end); - } - - @Override public int size() { - return (list.size() + size - 1) / size; - } - - @Override public boolean isEmpty() { - return list.isEmpty(); - } - } - - private static class RandomAccessPartition extends Partition - implements RandomAccess { - RandomAccessPartition(List list, int size) { - super(list, size); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapConstraint.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapConstraint.java deleted file mode 100644 index 2955699f8eb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapConstraint.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; - -@GwtCompatible -interface MapConstraint { - /** - * Throws a suitable {@code RuntimeException} if the specified key or value is - * illegal. Typically this is either a {@link NullPointerException}, an - * {@link IllegalArgumentException}, or a {@link ClassCastException}, though - * an application-specific exception class may be used if appropriate. - */ - void checkKeyValue(@Nullable K key, @Nullable V value); - - /** - * Returns a brief human readable description of this constraint, such as - * "Not null". - */ - String toString(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapDifference.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapDifference.java deleted file mode 100644 index 4c6b6e49dff..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapDifference.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Map; - -/** - * An object representing the differences between two maps. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -public interface MapDifference { - /** - * Returns {@code true} if there are no differences between the two maps; - * that is, if the maps are equal. - */ - boolean areEqual(); - - /** - * Returns an unmodifiable map containing the entries from the left map whose - * keys are not present in the right map. - */ - Map entriesOnlyOnLeft(); - - /** - * Returns an unmodifiable map containing the entries from the right map whose - * keys are not present in the left map. - */ - Map entriesOnlyOnRight(); - - /** - * Returns an unmodifiable map containing the entries that appear in both - * maps; that is, the intersection of the two maps. - */ - Map entriesInCommon(); - - /** - * Returns an unmodifiable map describing keys that appear in both maps, but - * with different values. - */ - Map> entriesDiffering(); - - /** - * Compares the specified object with this instance for equality. Returns - * {@code true} if the given object is also a {@code MapDifference} and the - * values returned by the {@link #entriesOnlyOnLeft()}, {@link - * #entriesOnlyOnRight()}, {@link #entriesInCommon()} and {@link - * #entriesDiffering()} of the two instances are equal. - */ - boolean equals(@Nullable Object object); - - /** - * Returns the hash code for this instance. This is defined as the hash code - * of

   {@code
-   *
-   *   Arrays.asList(entriesOnlyOnLeft(), entriesOnlyOnRight(),
-   *       entriesInCommon(), entriesDiffering())}
- */ - int hashCode(); - - /** - * A difference between the mappings from two maps with the same key. The - * {@code leftValue()} and {@code rightValue} are not equal, and one but not - * both of them may be null. - */ - interface ValueDifference { - /** - * Returns the value from the left map (possibly null). - */ - V leftValue(); - - /** - * Returns the value from the right map (possibly null). - */ - V rightValue(); - - /** - * Two instances are considered equal if their {@link #leftValue()} - * values are equal and their {@link #rightValue()} values are also equal. - */ - @Override boolean equals(@Nullable Object other); - - /** - * The hash code equals the value - * {@code Arrays.asList(leftValue(), rightValue()).hashCode()}. - */ - @Override int hashCode(); - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapMaker.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapMaker.java deleted file mode 100644 index c6ee02c1514..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MapMaker.java +++ /dev/null @@ -1,1118 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; -import org.elasticsearch.util.base.FinalizableReferenceQueue; -import org.elasticsearch.util.base.FinalizableSoftReference; -import org.elasticsearch.util.base.FinalizableWeakReference; -import org.elasticsearch.util.base.Function; -import org.elasticsearch.util.collect.CustomConcurrentHashMap.ComputingStrategy; -import org.elasticsearch.util.collect.CustomConcurrentHashMap.Internals; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.ref.SoftReference; -import java.lang.ref.WeakReference; -import java.lang.reflect.Field; -import java.util.Map; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.TimeUnit; - -/** - * A {@link ConcurrentMap} builder, providing any combination of these - * features: {@linkplain SoftReference soft} or {@linkplain WeakReference - * weak} keys, soft or weak values, timed expiration, and on-demand - * computation of values. Usage example:
 {@code
- *
- *   ConcurrentMap graphs = new MapMaker()
- *       .concurrencyLevel(32)
- *       .softKeys()
- *       .weakValues()
- *       .expiration(30, TimeUnit.MINUTES)
- *       .makeComputingMap(
- *           new Function() {
- *             public Graph apply(Key key) {
- *               return createExpensiveGraph(key);
- *             }
- *           });}
- * - * These features are all optional; {@code new MapMaker().makeMap()} - * returns a valid concurrent map that behaves exactly like a - * {@link ConcurrentHashMap}. - * - * The returned map is implemented as a hash table with similar performance - * characteristics to {@link ConcurrentHashMap}. It supports all optional - * operations of the {@code ConcurrentMap} interface. It does not permit - * null keys or values. It is serializable; however, serializing a map that - * uses soft or weak references can give unpredictable results. - * - *

Note: by default, the returned map uses equality comparisons - * (the {@link Object#equals(Object) equals} method) to determine equality - * for keys or values. However, if {@link #weakKeys()} or {@link - * #softKeys()} was specified, the map uses identity ({@code ==}) - * comparisons instead for keys. Likewise, if {@link #weakValues()} or - * {@link #softValues()} was specified, the map uses identity comparisons - * for values. - * - *

The returned map has weakly consistent iteration: an iterator - * over one of the map's view collections may reflect some, all or none of - * the changes made to the map after the iterator was created. - * - *

An entry whose key or value is reclaimed by the garbage collector - * immediately disappears from the map. (If the default settings of strong - * keys and strong values are used, this will never happen.) The client can - * never observe a partially-reclaimed entry. Any {@link java.util.Map.Entry} - * instance retrieved from the map's {@linkplain Map#entrySet() entry set} - * is snapshot of that entry's state at the time of retrieval. - * - *

{@code new MapMaker().weakKeys().makeMap()} can almost always be - * used as a drop-in replacement for {@link java.util.WeakHashMap}, adding - * concurrency, asynchronous cleanup, identity-based equality for keys, and - * great flexibility. - * - * @author Bob Lee - * @author Kevin Bourrillion - */ -@GwtCompatible(emulated = true) -public final class MapMaker { - private Strength keyStrength = Strength.STRONG; - private Strength valueStrength = Strength.STRONG; - private long expirationNanos = 0; - private boolean useCustomMap; - private final CustomConcurrentHashMap.Builder builder - = new CustomConcurrentHashMap.Builder(); - - /** - * Constructs a new {@code MapMaker} instance with default settings, - * including strong keys, strong values, and no automatic expiration. - */ - public MapMaker() {} - - /** - * Sets a custom initial capacity (defaults to 16). Resizing this or - * any other kind of hash table is a relatively slow operation, so, - * when possible, it is a good idea to provide estimates of expected - * table sizes. - * - * @throws IllegalArgumentException if {@code initialCapacity} is - * negative - * @throws IllegalStateException if an initial capacity was already set - */ - public MapMaker initialCapacity(int initialCapacity) { - builder.initialCapacity(initialCapacity); - return this; - } - - /** - * Guides the allowed concurrency among update operations. Used as a - * hint for internal sizing. The table is internally partitioned to try - * to permit the indicated number of concurrent updates without - * contention. Because placement in hash tables is essentially random, - * the actual concurrency will vary. Ideally, you should choose a value - * to accommodate as many threads as will ever concurrently modify the - * table. Using a significantly higher value than you need can waste - * space and time, and a significantly lower value can lead to thread - * contention. But overestimates and underestimates within an order of - * magnitude do not usually have much noticeable impact. A value of one - * is appropriate when it is known that only one thread will modify and - * all others will only read. Defaults to 16. - * - * @throws IllegalArgumentException if {@code concurrencyLevel} is - * nonpositive - * @throws IllegalStateException if a concurrency level was already set - */ - @GwtIncompatible("java.util.concurrent.ConcurrentHashMap concurrencyLevel") - public MapMaker concurrencyLevel(int concurrencyLevel) { - builder.concurrencyLevel(concurrencyLevel); - return this; - } - - /** - * Specifies that each key (not value) stored in the map should be - * wrapped in a {@link WeakReference} (by default, strong references - * are used). - * - *

Note: the map will use identity ({@code ==}) comparison - * to determine equality of weak keys, which may not behave as you expect. - * For example, storing a key in the map and then attempting a lookup - * using a different but {@link Object#equals(Object) equals}-equivalent - * key will always fail. - * - * @throws IllegalStateException if the key strength was already set - * @see WeakReference - */ - @GwtIncompatible("java.lang.ref.WeakReference") - public MapMaker weakKeys() { - return setKeyStrength(Strength.WEAK); - } - - /** - * Specifies that each key (not value) stored in the map should be - * wrapped in a {@link SoftReference} (by default, strong references - * are used). - * - *

Note: the map will use identity ({@code ==}) comparison - * to determine equality of soft keys, which may not behave as you expect. - * For example, storing a key in the map and then attempting a lookup - * using a different but {@link Object#equals(Object) equals}-equivalent - * key will always fail. - * - * @throws IllegalStateException if the key strength was already set - * @see SoftReference - */ - @GwtIncompatible("java.lang.ref.SoftReference") - public MapMaker softKeys() { - return setKeyStrength(Strength.SOFT); - } - - private MapMaker setKeyStrength(Strength strength) { - if (keyStrength != Strength.STRONG) { - throw new IllegalStateException("Key strength was already set to " - + keyStrength + "."); - } - keyStrength = strength; - useCustomMap = true; - return this; - } - - /** - * Specifies that each value (not key) stored in the map should be - * wrapped in a {@link WeakReference} (by default, strong references - * are used). - * - *

Weak values will be garbage collected once they are weakly - * reachable. This makes them a poor candidate for caching; consider - * {@link #softValues()} instead. - * - *

Note: the map will use identity ({@code ==}) comparison - * to determine equality of weak values. This will notably impact - * the behavior of {@link Map#containsValue(Object) containsValue}, - * {@link ConcurrentMap#remove(Object, Object) remove(Object, Object)}, - * and {@link ConcurrentMap#replace(Object, Object, Object) replace(K, V, V)}. - * - * @throws IllegalStateException if the key strength was already set - * @see WeakReference - */ - @GwtIncompatible("java.lang.ref.WeakReference") - public MapMaker weakValues() { - return setValueStrength(Strength.WEAK); - } - - /** - * Specifies that each value (not key) stored in the map should be - * wrapped in a {@link SoftReference} (by default, strong references - * are used). - * - *

Soft values will be garbage collected in response to memory - * demand, and in a least-recently-used manner. This makes them a - * good candidate for caching. - * - *

Note: the map will use identity ({@code ==}) comparison - * to determine equality of soft values. This will notably impact - * the behavior of {@link Map#containsValue(Object) containsValue}, - * {@link ConcurrentMap#remove(Object, Object) remove(Object, Object)}, - * and {@link ConcurrentMap#replace(Object, Object, Object) replace(K, V, V)}. - * - * @throws IllegalStateException if the value strength was already set - * @see SoftReference - */ - @GwtIncompatible("java.lang.ref.SoftReference") - public MapMaker softValues() { - return setValueStrength(Strength.SOFT); - } - - private MapMaker setValueStrength(Strength strength) { - if (valueStrength != Strength.STRONG) { - throw new IllegalStateException("Value strength was already set to " - + valueStrength + "."); - } - valueStrength = strength; - useCustomMap = true; - return this; - } - - /** - * Specifies that each entry should be automatically removed from the - * map once a fixed duration has passed since the entry's creation. - * - * @param duration the length of time after an entry is created that it - * should be automatically removed - * @param unit the unit that {@code duration} is expressed in - * @throws IllegalArgumentException if {@code duration} is not positive - * @throws IllegalStateException if the expiration time was already set - */ - public MapMaker expiration(long duration, TimeUnit unit) { - if (expirationNanos != 0) { - throw new IllegalStateException("expiration time of " - + expirationNanos + " ns was already set"); - } - if (duration <= 0) { - throw new IllegalArgumentException("invalid duration: " + duration); - } - this.expirationNanos = unit.toNanos(duration); - useCustomMap = true; - return this; - } - - /** - * Builds the final map, without on-demand computation of values. This method - * does not alter the state of this {@code MapMaker} instance, so it can be - * invoked again to create multiple independent maps. - * - * @param the type of keys to be stored in the returned map - * @param the type of values to be stored in the returned map - * @return a concurrent map having the requested features - */ - public ConcurrentMap makeMap() { - return useCustomMap - ? new StrategyImpl(this).map - : new ConcurrentHashMap(builder.getInitialCapacity(), - 0.75f, builder.getConcurrencyLevel()); - } - - /** - * Builds a map that supports atomic, on-demand computation of values. {@link - * Map#get} either returns an already-computed value for the given key, - * atomically computes it using the supplied function, or, if another thread - * is currently computing the value for this key, simply waits for that thread - * to finish and returns its computed value. Note that the function may be - * executed concurrently by multiple threads, but only for distinct keys. - * - *

If an entry's value has not finished computing yet, query methods - * besides {@code get} return immediately as if an entry doesn't exist. In - * other words, an entry isn't externally visible until the value's - * computation completes. - * - *

{@link Map#get} on the returned map will never return {@code null}. It - * may throw: - * - *

    - *
  • {@link NullPointerException} if the key is null or the computing - * function returns null - *
  • {@link ComputationException} if an exception was thrown by the - * computing function. If that exception is already of type {@link - * ComputationException}, it is propagated directly; otherwise it is - * wrapped. - *
- * - *

Note: Callers of {@code get} must ensure that the key - * argument is of type {@code K}. The {@code get} method accepts {@code - * Object}, so the key type is not checked at compile time. Passing an object - * of a type other than {@code K} can result in that object being unsafely - * passed to the computing function as type {@code K}, and unsafely stored in - * the map. - * - *

If {@link Map#put} is called before a computation completes, other - * threads waiting on the computation will wake up and return the stored - * value. When the computation completes, its new result will overwrite the - * value that was put in the map manually. - * - *

This method does not alter the state of this {@code MapMaker} instance, - * so it can be invoked again to create multiple independent maps. - */ - public ConcurrentMap makeComputingMap( - Function computingFunction) { - return new StrategyImpl(this, computingFunction).map; - } - - // Remainder of this file is private implementation details - - private enum Strength { - WEAK { - @Override boolean equal(Object a, Object b) { - return a == b; - } - @Override int hash(Object o) { - return System.identityHashCode(o); - } - @Override ValueReference referenceValue( - ReferenceEntry entry, V value) { - return new WeakValueReference(value, entry); - } - @Override ReferenceEntry newEntry( - Internals> internals, K key, - int hash, ReferenceEntry next) { - return (next == null) - ? new WeakEntry(internals, key, hash) - : new LinkedWeakEntry(internals, key, hash, next); - } - @Override ReferenceEntry copyEntry( - K key, ReferenceEntry original, - ReferenceEntry newNext) { - WeakEntry from = (WeakEntry) original; - return (newNext == null) - ? new WeakEntry(from.internals, key, from.hash) - : new LinkedWeakEntry( - from.internals, key, from.hash, newNext); - } - }, - - SOFT { - @Override boolean equal(Object a, Object b) { - return a == b; - } - @Override int hash(Object o) { - return System.identityHashCode(o); - } - @Override ValueReference referenceValue( - ReferenceEntry entry, V value) { - return new SoftValueReference(value, entry); - } - @Override ReferenceEntry newEntry( - Internals> internals, K key, - int hash, ReferenceEntry next) { - return (next == null) - ? new SoftEntry(internals, key, hash) - : new LinkedSoftEntry(internals, key, hash, next); - } - @Override ReferenceEntry copyEntry( - K key, ReferenceEntry original, - ReferenceEntry newNext) { - SoftEntry from = (SoftEntry) original; - return (newNext == null) - ? new SoftEntry(from.internals, key, from.hash) - : new LinkedSoftEntry( - from.internals, key, from.hash, newNext); - } - }, - - STRONG { - @Override boolean equal(Object a, Object b) { - return a.equals(b); - } - @Override int hash(Object o) { - return o.hashCode(); - } - @Override ValueReference referenceValue( - ReferenceEntry entry, V value) { - return new StrongValueReference(value); - } - @Override ReferenceEntry newEntry( - Internals> internals, K key, - int hash, ReferenceEntry next) { - return (next == null) - ? new StrongEntry(internals, key, hash) - : new LinkedStrongEntry( - internals, key, hash, next); - } - @Override ReferenceEntry copyEntry( - K key, ReferenceEntry original, - ReferenceEntry newNext) { - StrongEntry from = (StrongEntry) original; - return (newNext == null) - ? new StrongEntry(from.internals, key, from.hash) - : new LinkedStrongEntry( - from.internals, key, from.hash, newNext); - } - }; - - /** - * Determines if two keys or values are equal according to this - * strength strategy. - */ - abstract boolean equal(Object a, Object b); - - /** - * Hashes a key according to this strategy. - */ - abstract int hash(Object o); - - /** - * Creates a reference for the given value according to this value - * strength. - */ - abstract ValueReference referenceValue( - ReferenceEntry entry, V value); - - /** - * Creates a new entry based on the current key strength. - */ - abstract ReferenceEntry newEntry( - Internals> internals, K key, - int hash, ReferenceEntry next); - - /** - * Creates a new entry and copies the value and other state from an - * existing entry. - */ - abstract ReferenceEntry copyEntry(K key, - ReferenceEntry original, ReferenceEntry newNext); - } - - private static class StrategyImpl implements Serializable, - ComputingStrategy> { - final Strength keyStrength; - final Strength valueStrength; - final ConcurrentMap map; - final long expirationNanos; - Internals> internals; - - StrategyImpl(MapMaker maker) { - this.keyStrength = maker.keyStrength; - this.valueStrength = maker.valueStrength; - this.expirationNanos = maker.expirationNanos; - - map = maker.builder.buildMap(this); - } - - StrategyImpl( - MapMaker maker, Function computer) { - this.keyStrength = maker.keyStrength; - this.valueStrength = maker.valueStrength; - this.expirationNanos = maker.expirationNanos; - - map = maker.builder.buildComputingMap(this, computer); - } - - public void setValue(ReferenceEntry entry, V value) { - setValueReference( - entry, valueStrength.referenceValue(entry, value)); - if (expirationNanos > 0) { - scheduleRemoval(entry.getKey(), value); - } - } - - void scheduleRemoval(K key, V value) { - /* - * TODO: Keep weak reference to map, too. Build a priority - * queue out of the entries themselves instead of creating a - * task per entry. Then, we could have one recurring task per - * map (which would clean the entire map and then reschedule - * itself depending upon when the next expiration comes). We - * also want to avoid removing an entry prematurely if the - * entry was set to the same value again. - */ - final WeakReference keyReference = new WeakReference(key); - final WeakReference valueReference = new WeakReference(value); - ExpirationTimer.instance.schedule( - new TimerTask() { - @Override public void run() { - K key = keyReference.get(); - if (key != null) { - // Remove if the value is still the same. - map.remove(key, valueReference.get()); - } - } - }, TimeUnit.NANOSECONDS.toMillis(expirationNanos)); - } - - public boolean equalKeys(K a, Object b) { - return keyStrength.equal(a, b); - } - - public boolean equalValues(V a, Object b) { - return valueStrength.equal(a, b); - } - - public int hashKey(Object key) { - return keyStrength.hash(key); - } - - public K getKey(ReferenceEntry entry) { - return entry.getKey(); - } - - public int getHash(ReferenceEntry entry) { - return entry.getHash(); - } - - public ReferenceEntry newEntry( - K key, int hash, ReferenceEntry next) { - return keyStrength.newEntry(internals, key, hash, next); - } - - public ReferenceEntry copyEntry(K key, - ReferenceEntry original, ReferenceEntry newNext) { - ValueReference valueReference = original.getValueReference(); - if (valueReference == COMPUTING) { - ReferenceEntry newEntry - = newEntry(key, original.getHash(), newNext); - newEntry.setValueReference( - new FutureValueReference(original, newEntry)); - return newEntry; - } else { - ReferenceEntry newEntry - = newEntry(key, original.getHash(), newNext); - newEntry.setValueReference(valueReference.copyFor(newEntry)); - return newEntry; - } - } - - /** - * Waits for a computation to complete. Returns the result of the - * computation or null if none was available. - */ - public V waitForValue(ReferenceEntry entry) - throws InterruptedException { - ValueReference valueReference = entry.getValueReference(); - if (valueReference == COMPUTING) { - synchronized (entry) { - while ((valueReference = entry.getValueReference()) - == COMPUTING) { - entry.wait(); - } - } - } - return valueReference.waitForValue(); - } - - /** - * Used by CustomConcurrentHashMap to retrieve values. Returns null - * instead of blocking or throwing an exception. - */ - public V getValue(ReferenceEntry entry) { - ValueReference valueReference = entry.getValueReference(); - return valueReference.get(); - } - - public V compute(K key, final ReferenceEntry entry, - Function computer) { - V value; - try { - value = computer.apply(key); - } catch (ComputationException e) { - // if computer has thrown a computation exception, propagate rather - // than wrap - setValueReference(entry, - new ComputationExceptionReference(e.getCause())); - throw e; - } catch (Throwable t) { - setValueReference( - entry, new ComputationExceptionReference(t)); - throw new ComputationException(t); - } - - if (value == null) { - String message - = computer + " returned null for key " + key + "."; - setValueReference( - entry, new NullOutputExceptionReference(message)); - throw new NullOutputException(message); - } else { - setValue(entry, value); - } - return value; - } - - /** - * Sets the value reference on an entry and notifies waiting - * threads. - */ - void setValueReference(ReferenceEntry entry, - ValueReference valueReference) { - boolean notifyOthers = (entry.getValueReference() == COMPUTING); - entry.setValueReference(valueReference); - if (notifyOthers) { - synchronized (entry) { - entry.notifyAll(); - } - } - } - - /** - * Points to an old entry where a value is being computed. Used to - * support non-blocking copying of entries during table expansion, - * removals, etc. - */ - private class FutureValueReference implements ValueReference { - final ReferenceEntry original; - final ReferenceEntry newEntry; - - FutureValueReference( - ReferenceEntry original, ReferenceEntry newEntry) { - this.original = original; - this.newEntry = newEntry; - } - - public V get() { - boolean success = false; - try { - V value = original.getValueReference().get(); - success = true; - return value; - } finally { - if (!success) { - removeEntry(); - } - } - } - - public ValueReference copyFor(ReferenceEntry entry) { - return new FutureValueReference(original, entry); - } - - public V waitForValue() throws InterruptedException { - boolean success = false; - try { - // assert that key != null - V value = StrategyImpl.this.waitForValue(original); - success = true; - return value; - } finally { - if (!success) { - removeEntry(); - } - } - } - - /** - * Removes the entry in the event of an exception. Ideally, - * we'd clean up as soon as the computation completes, but we - * can't do that without keeping a reference to this entry from - * the original. - */ - void removeEntry() { - internals.removeEntry(newEntry); - } - } - - public ReferenceEntry getNext( - ReferenceEntry entry) { - return entry.getNext(); - } - - public void setInternals( - Internals> internals) { - this.internals = internals; - } - - private static final long serialVersionUID = 0; - - private void writeObject(ObjectOutputStream out) - throws IOException { - // Custom serialization code ensures that the key and value - // strengths are written before the map. We'll need them to - // deserialize the map entries. - out.writeObject(keyStrength); - out.writeObject(valueStrength); - out.writeLong(expirationNanos); - - // TODO: It is possible for the strategy to try to use the map - // or internals during deserialization, for example, if an - // entry gets reclaimed. We could detect this case and queue up - // removals to be flushed after we deserialize the map. - out.writeObject(internals); - out.writeObject(map); - } - - /** - * Fields used during deserialization. We use a nested class so we - * don't load them until we need them. We need to use reflection to - * set final fields outside of the constructor. - */ - private static class Fields { - static final Field keyStrength = findField("keyStrength"); - static final Field valueStrength = findField("valueStrength"); - static final Field expirationNanos = findField("expirationNanos"); - static final Field internals = findField("internals"); - static final Field map = findField("map"); - - static Field findField(String name) { - try { - Field f = StrategyImpl.class.getDeclaredField(name); - f.setAccessible(true); - return f; - } catch (NoSuchFieldException e) { - throw new AssertionError(e); - } - } - } - - private void readObject(ObjectInputStream in) - throws IOException, ClassNotFoundException { - try { - Fields.keyStrength.set(this, in.readObject()); - Fields.valueStrength.set(this, in.readObject()); - Fields.expirationNanos.set(this, in.readLong()); - Fields.internals.set(this, in.readObject()); - Fields.map.set(this, in.readObject()); - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } - } - } - - /** A reference to a value. */ - private interface ValueReference { - /** - * Gets the value. Does not block or throw exceptions. - */ - V get(); - - /** Creates a copy of this reference for the given entry. */ - ValueReference copyFor(ReferenceEntry entry); - - /** - * Waits for a value that may still be computing. Unlike get(), - * this method can block (in the case of FutureValueReference) or - * throw an exception. - */ - V waitForValue() throws InterruptedException; - } - - private static final ValueReference COMPUTING - = new ValueReference() { - public Object get() { - return null; - } - public ValueReference copyFor( - ReferenceEntry entry) { - throw new AssertionError(); - } - public Object waitForValue() { - throw new AssertionError(); - } - }; - - /** - * Singleton placeholder that indicates a value is being computed. - */ - @SuppressWarnings("unchecked") - // Safe because impl never uses a parameter or returns any non-null value - private static ValueReference computing() { - return (ValueReference) COMPUTING; - } - - /** Used to provide null output exceptions to other threads. */ - private static class NullOutputExceptionReference - implements ValueReference { - final String message; - NullOutputExceptionReference(String message) { - this.message = message; - } - public V get() { - return null; - } - public ValueReference copyFor( - ReferenceEntry entry) { - return this; - } - public V waitForValue() { - throw new NullOutputException(message); - } - } - - /** Used to provide computation exceptions to other threads. */ - private static class ComputationExceptionReference - implements ValueReference { - final Throwable t; - ComputationExceptionReference(Throwable t) { - this.t = t; - } - public V get() { - return null; - } - public ValueReference copyFor( - ReferenceEntry entry) { - return this; - } - public V waitForValue() { - throw new AsynchronousComputationException(t); - } - } - - /** Wrapper class ensures that queue isn't created until it's used. */ - private static class QueueHolder { - static final FinalizableReferenceQueue queue - = new FinalizableReferenceQueue(); - } - - /** - * An entry in a reference map. - */ - private interface ReferenceEntry { - /** - * Gets the value reference from this entry. - */ - ValueReference getValueReference(); - - /** - * Sets the value reference for this entry. - * - * @param valueReference - */ - void setValueReference(ValueReference valueReference); - - /** - * Removes this entry from the map if its value reference hasn't - * changed. Used to clean up after values. The value reference can - * just call this method on the entry so it doesn't have to keep - * its own reference to the map. - */ - void valueReclaimed(); - - /** Gets the next entry in the chain. */ - ReferenceEntry getNext(); - - /** Gets the entry's hash. */ - int getHash(); - - /** Gets the key for this entry. */ - public K getKey(); - } - - /** - * Used for strongly-referenced keys. - */ - private static class StrongEntry implements ReferenceEntry { - final K key; - - StrongEntry(Internals> internals, K key, - int hash) { - this.internals = internals; - this.key = key; - this.hash = hash; - } - - public K getKey() { - return this.key; - } - - // The code below is exactly the same for each entry type. - - final Internals> internals; - final int hash; - volatile ValueReference valueReference = computing(); - - public ValueReference getValueReference() { - return valueReference; - } - public void setValueReference( - ValueReference valueReference) { - this.valueReference = valueReference; - } - public void valueReclaimed() { - internals.removeEntry(this, null); - } - public ReferenceEntry getNext() { - return null; - } - public int getHash() { - return hash; - } - } - - private static class LinkedStrongEntry extends StrongEntry { - - LinkedStrongEntry(Internals> internals, - K key, int hash, ReferenceEntry next) { - super(internals, key, hash); - this.next = next; - } - - final ReferenceEntry next; - - @Override public ReferenceEntry getNext() { - return next; - } - } - - /** - * Used for softly-referenced keys. - */ - private static class SoftEntry extends FinalizableSoftReference - implements ReferenceEntry { - SoftEntry(Internals> internals, K key, - int hash) { - super(key, QueueHolder.queue); - this.internals = internals; - this.hash = hash; - } - - public K getKey() { - return get(); - } - - public void finalizeReferent() { - internals.removeEntry(this); - } - - // The code below is exactly the same for each entry type. - - final Internals> internals; - final int hash; - volatile ValueReference valueReference = computing(); - - public ValueReference getValueReference() { - return valueReference; - } - public void setValueReference( - ValueReference valueReference) { - this.valueReference = valueReference; - } - public void valueReclaimed() { - internals.removeEntry(this, null); - } - public ReferenceEntry getNext() { - return null; - } - public int getHash() { - return hash; - } - } - - private static class LinkedSoftEntry extends SoftEntry { - LinkedSoftEntry(Internals> internals, - K key, int hash, ReferenceEntry next) { - super(internals, key, hash); - this.next = next; - } - - final ReferenceEntry next; - - @Override public ReferenceEntry getNext() { - return next; - } - } - - /** - * Used for weakly-referenced keys. - */ - private static class WeakEntry extends FinalizableWeakReference - implements ReferenceEntry { - WeakEntry(Internals> internals, K key, - int hash) { - super(key, QueueHolder.queue); - this.internals = internals; - this.hash = hash; - } - - public K getKey() { - return get(); - } - - public void finalizeReferent() { - internals.removeEntry(this); - } - - // The code below is exactly the same for each entry type. - - final Internals> internals; - final int hash; - volatile ValueReference valueReference = computing(); - - public ValueReference getValueReference() { - return valueReference; - } - public void setValueReference( - ValueReference valueReference) { - this.valueReference = valueReference; - } - public void valueReclaimed() { - internals.removeEntry(this, null); - } - public ReferenceEntry getNext() { - return null; - } - public int getHash() { - return hash; - } - } - - private static class LinkedWeakEntry extends WeakEntry { - LinkedWeakEntry(Internals> internals, - K key, int hash, ReferenceEntry next) { - super(internals, key, hash); - this.next = next; - } - - final ReferenceEntry next; - - @Override public ReferenceEntry getNext() { - return next; - } - } - - /** References a weak value. */ - private static class WeakValueReference - extends FinalizableWeakReference - implements ValueReference { - final ReferenceEntry entry; - - WeakValueReference(V referent, ReferenceEntry entry) { - super(referent, QueueHolder.queue); - this.entry = entry; - } - - public void finalizeReferent() { - entry.valueReclaimed(); - } - - public ValueReference copyFor( - ReferenceEntry entry) { - return new WeakValueReference(get(), entry); - } - - public V waitForValue() { - return get(); - } - } - - /** References a soft value. */ - private static class SoftValueReference - extends FinalizableSoftReference - implements ValueReference { - final ReferenceEntry entry; - - SoftValueReference(V referent, ReferenceEntry entry) { - super(referent, QueueHolder.queue); - this.entry = entry; - } - - public void finalizeReferent() { - entry.valueReclaimed(); - } - - public ValueReference copyFor( - ReferenceEntry entry) { - return new SoftValueReference(get(), entry); - } - - public V waitForValue() { - return get(); - } - } - - /** References a strong value. */ - private static class StrongValueReference - implements ValueReference { - final V referent; - - StrongValueReference(V referent) { - this.referent = referent; - } - - public V get() { - return referent; - } - - public ValueReference copyFor( - ReferenceEntry entry) { - return this; - } - - public V waitForValue() { - return get(); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Maps.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Maps.java deleted file mode 100644 index 188e7b737f6..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Maps.java +++ /dev/null @@ -1,1317 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Function; -import org.elasticsearch.util.base.Joiner.MapJoiner; -import org.elasticsearch.util.base.Objects; -import org.elasticsearch.util.base.Predicate; -import org.elasticsearch.util.base.Predicates; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.*; -import java.util.Map.Entry; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Static utility methods pertaining to {@link Map} instances. Also see this - * class's counterparts {@link Lists} and {@link Sets}. - * - * @author Kevin Bourrillion - * @author Mike Bostock - * @author Isaac Shum - */ -@GwtCompatible -public final class Maps { - private Maps() {} - - /** - * Creates a mutable, empty {@code HashMap} instance. - * - *

Note: if mutability is not required, use {@link - * ImmutableMap#of()} instead. - * - *

Note: if {@code K} is an {@code enum} type, use {@link - * #newEnumMap} instead. - * - * @return a new, empty {@code HashMap} - */ - public static HashMap newHashMap() { - return new HashMap(); - } - - /** - * Creates a {@code HashMap} instance with enough capacity to hold the - * specified number of elements without rehashing. - * - * @param expectedSize the expected size - * @return a new, empty {@code HashMap} with enough - * capacity to hold {@code expectedSize} elements without rehashing - * @throws IllegalArgumentException if {@code expectedSize} is negative - */ - public static HashMap newHashMapWithExpectedSize( - int expectedSize) { - /* - * The HashMap is constructed with an initialCapacity that's greater than - * expectedSize. The larger value is necessary because HashMap resizes - * its internal array if the map size exceeds loadFactor * initialCapacity. - */ - return new HashMap(capacity(expectedSize)); - } - - /** - * Returns an appropriate value for the "capacity" (in reality, "minimum - * table size") parameter of a {@link HashMap} constructor, such that the - * resulting table will be between 25% and 50% full when it contains - * {@code expectedSize} entries. - * - * @throws IllegalArgumentException if {@code expectedSize} is negative - */ - static int capacity(int expectedSize) { - checkArgument(expectedSize >= 0); - return Math.max(expectedSize * 2, 16); - } - - /** - * Creates a mutable {@code HashMap} instance with the same mappings as - * the specified map. - * - *

Note: if mutability is not required, use {@link - * ImmutableMap#copyOf(Map)} instead. - * - *

Note: if {@code K} is an {@link Enum} type, use {@link - * #newEnumMap} instead. - * - * @param map the mappings to be placed in the new map - * @return a new {@code HashMap} initialized with the mappings from - * {@code map} - */ - public static HashMap newHashMap( - Map map) { - return new HashMap(map); - } - - /** - * Creates a mutable, empty, insertion-ordered {@code LinkedHashMap} - * instance. - * - *

Note: if mutability is not required, use {@link - * ImmutableMap#of()} instead. - * - * @return a new, empty {@code LinkedHashMap} - */ - public static LinkedHashMap newLinkedHashMap() { - return new LinkedHashMap(); - } - - /** - * Creates a mutable, insertion-ordered {@code LinkedHashMap} instance - * with the same mappings as the specified map. - * - *

Note: if mutability is not required, use {@link - * ImmutableMap#copyOf(Map)} instead. - * - * @param map the mappings to be placed in the new map - * @return a new, {@code LinkedHashMap} initialized with the - * mappings from {@code map} - */ - public static LinkedHashMap - newLinkedHashMap(Map map) { - return new LinkedHashMap(map); - } - - /** - * Creates a mutable, empty {@code TreeMap} instance using the natural - * ordering of its elements. - * - *

Note: if mutability is not required, use {@link - * ImmutableSortedMap#of()} instead. - * - * @return a new, empty {@code TreeMap} - */ - @SuppressWarnings("unchecked") // eclipse doesn't like the raw Comparable - public static TreeMap newTreeMap() { - return new TreeMap(); - } - - /** - * Creates a mutable {@code TreeMap} instance with the same mappings as - * the specified map and using the same ordering as the specified map. - * - *

Note: if mutability is not required, use {@link - * ImmutableSortedMap#copyOfSorted(SortedMap)} instead. - * - * @param map the sorted map whose mappings are to be placed in the new map - * and whose comparator is to be used to sort the new map - * @return a new {@code TreeMap} initialized with the mappings from {@code - * map} and using the comparator of {@code map} - */ - public static TreeMap newTreeMap(SortedMap map) { - return new TreeMap(map); - } - - /** - * Creates a mutable, empty {@code TreeMap} instance using the given - * comparator. - * - *

Note: if mutability is not required, use {@code - * ImmutableSortedMap.orderedBy(comparator).build()} instead. - * - * @param comparator the comparator to sort the keys with - * @return a new, empty {@code TreeMap} - */ - public static TreeMap newTreeMap( - @Nullable Comparator comparator) { - // Ideally, the extra type parameter "C" shouldn't be necessary. It is a - // work-around of a compiler type inference quirk that prevents the - // following code from being compiled: - // Comparator> comparator = null; - // Map, String> map = newTreeMap(comparator); - return new TreeMap(comparator); - } - - /** - * Creates an {@code EnumMap} instance. - * - * @param type the key type for this map - * @return a new, empty {@code EnumMap} - */ - public static , V> EnumMap newEnumMap(Class type) { - return new EnumMap(checkNotNull(type)); - } - - /** - * Creates an {@code EnumMap} with the same mappings as the specified map. - * - * @param map the map from which to initialize this {@code EnumMap} - * @return a new {@code EnumMap} initialized with the mappings from {@code - * map} - * @throws IllegalArgumentException if {@code m} is not an {@code EnumMap} - * instance and contains no mappings - */ - public static , V> EnumMap newEnumMap( - Map map) { - return new EnumMap(map); - } - - /** - * Creates an {@code IdentityHashMap} instance. - * - * @return a new, empty {@code IdentityHashMap} - */ - public static IdentityHashMap newIdentityHashMap() { - return new IdentityHashMap(); - } - - /** - * Returns a synchronized (thread-safe) bimap backed by the specified bimap. - * In order to guarantee serial access, it is critical that all access - * to the backing bimap is accomplished through the returned bimap. - * - *

It is imperative that the user manually synchronize on the returned map - * when accessing any of its collection views:

   {@code
-   *
-   *   BiMap map = Maps.synchronizedBiMap(
-   *       HashBiMap.create());
-   *    ...
-   *   Set set = map.keySet();  // Needn't be in synchronized block
-   *    ...
-   *   synchronized (map) {  // Synchronizing on map, not set!
-   *     Iterator it = set.iterator(); // Must be in synchronized block
-   *     while (it.hasNext()) {
-   *       foo(it.next());
-   *     }
-   *   }}
- * - * Failure to follow this advice may result in non-deterministic behavior. - * - *

The returned bimap will be serializable if the specified bimap is - * serializable. - * - * @param bimap the bimap to be wrapped in a synchronized view - * @return a sychronized view of the specified bimap - */ - public static BiMap synchronizedBiMap(BiMap bimap) { - return Synchronized.biMap(bimap, null); - } - - /** - * Computes the difference between two maps. This difference is an immutable - * snapshot of the state of the maps at the time this method is called. It - * will never change, even if the maps change at a later time. - * - *

Since this method uses {@code HashMap} instances internally, the keys of - * the supplied maps must be well-behaved with respect to - * {@link Object#equals} and {@link Object#hashCode}. - * - *

Note:If you only need to know whether two maps have the same - * mappings, call {@code left.equals(right)} instead of this method. - * - * @param left the map to treat as the "left" map for purposes of comparison - * @param right the map to treat as the "right" map for purposes of comparison - * @return the difference between the two maps - */ - public static MapDifference difference( - Map left, Map right) { - Map onlyOnLeft = newHashMap(); - Map onlyOnRight = new HashMap(right); // will whittle it down - Map onBoth = newHashMap(); - Map> differences = newHashMap(); - boolean eq = true; - - for (Entry entry : left.entrySet()) { - K leftKey = entry.getKey(); - V leftValue = entry.getValue(); - if (right.containsKey(leftKey)) { - V rightValue = onlyOnRight.remove(leftKey); - if (Objects.equal(leftValue, rightValue)) { - onBoth.put(leftKey, leftValue); - } else { - eq = false; - differences.put(leftKey, new ValueDifferenceImpl( - leftValue, rightValue)); - } - } else { - eq = false; - onlyOnLeft.put(leftKey, leftValue); - } - } - - boolean areEqual = eq && onlyOnRight.isEmpty(); - return new MapDifferenceImpl( - areEqual, onlyOnLeft, onlyOnRight, onBoth, differences); - } - - private static class MapDifferenceImpl - implements MapDifference { - final boolean areEqual; - final Map onlyOnLeft; - final Map onlyOnRight; - final Map onBoth; - final Map> differences; - - MapDifferenceImpl(boolean areEqual, Map onlyOnLeft, - Map onlyOnRight, Map onBoth, - Map> differences) { - this.areEqual = areEqual; - this.onlyOnLeft = Collections.unmodifiableMap(onlyOnLeft); - this.onlyOnRight = Collections.unmodifiableMap(onlyOnRight); - this.onBoth = Collections.unmodifiableMap(onBoth); - this.differences = Collections.unmodifiableMap(differences); - } - - public boolean areEqual() { - return areEqual; - } - - public Map entriesOnlyOnLeft() { - return onlyOnLeft; - } - - public Map entriesOnlyOnRight() { - return onlyOnRight; - } - - public Map entriesInCommon() { - return onBoth; - } - - public Map> entriesDiffering() { - return differences; - } - - @Override public boolean equals(Object object) { - if (object == this) { - return true; - } - if (object instanceof MapDifference) { - MapDifference other = (MapDifference) object; - return entriesOnlyOnLeft().equals(other.entriesOnlyOnLeft()) - && entriesOnlyOnRight().equals(other.entriesOnlyOnRight()) - && entriesInCommon().equals(other.entriesInCommon()) - && entriesDiffering().equals(other.entriesDiffering()); - } - return false; - } - - @Override public int hashCode() { - return Objects.hashCode(entriesOnlyOnLeft(), entriesOnlyOnRight(), - entriesInCommon(), entriesDiffering()); - } - - @Override public String toString() { - if (areEqual) { - return "equal"; - } - - StringBuilder result = new StringBuilder("not equal"); - if (!onlyOnLeft.isEmpty()) { - result.append(": only on left=").append(onlyOnLeft); - } - if (!onlyOnRight.isEmpty()) { - result.append(": only on right=").append(onlyOnRight); - } - if (!differences.isEmpty()) { - result.append(": value differences=").append(differences); - } - return result.toString(); - } - } - - static class ValueDifferenceImpl - implements MapDifference.ValueDifference { - - private final V left; - private final V right; - - ValueDifferenceImpl(@Nullable V left, @Nullable V right) { - this.left = left; - this.right = right; - } - - public V leftValue() { - return left; - } - - public V rightValue() { - return right; - } - - @Override public boolean equals(@Nullable Object object) { - if (object instanceof MapDifference.ValueDifference) { - MapDifference.ValueDifference that = - (MapDifference.ValueDifference) object; - return Objects.equal(this.left, that.leftValue()) - && Objects.equal(this.right, that.rightValue()); - } - return false; - } - - @Override public int hashCode() { - return Objects.hashCode(left, right); - } - - @Override public String toString() { - return "(" + left + ", " + right + ")"; - } - } - - /** - * Returns an immutable map for which the {@link Map#values} are the given - * elements in the given order, and each key is the product of invoking a - * supplied function on its corresponding value. - * - * @param values the values to use when constructing the {@code Map} - * @param keyFunction the function used to produce the key for each value - * @return a map mapping the result of evaluating the function {@code - * keyFunction} on each value in the input collection to that value - * @throws IllegalArgumentException if {@code keyFunction} produces the same - * key for more than one value in the input collection - * @throws NullPointerException if any elements of {@code values} is null, or - * if {@code keyFunction} produces {@code null} for any value - */ - // TODO: consider returning a bimap, whose inverse view does lookups by - // invoking the function. - public static ImmutableMap uniqueIndex( - Iterable values, Function keyFunction) { - checkNotNull(keyFunction); - ImmutableMap.Builder builder = ImmutableMap.builder(); - for (V value : values) { - builder.put(keyFunction.apply(value), value); - } - return builder.build(); - } - - /** - * Creates an {@code ImmutableMap} from a {@code Properties} - * instance. Properties normally derive from {@code Map}, but - * they typically contain strings, which is awkward. This method lets you get - * a plain-old-{@code Map} out of a {@code Properties}. - * - * @param properties a {@code Properties} object to be converted - * @return an immutable map containing all the entries in - * {@code properties} - * @throws ClassCastException if any key in {@code Properties} is not a - * {@code String} - * @throws NullPointerException if any key or value in {@code Properties} is - * null. - */ - public static ImmutableMap - fromProperties(Properties properties) { - ImmutableMap.Builder builder = ImmutableMap.builder(); - - for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - builder.put(key, properties.getProperty(key)); - } - - return builder.build(); - } - - /** - * Returns an immutable map entry with the specified key and value. The {@link - * Entry#setValue} operation throws an {@link UnsupportedOperationException}. - * - *

The returned entry is serializable. - * - * @param key the key to be associated with the returned entry - * @param value the value to be associated with the returned entry - */ - public static Entry immutableEntry( - @Nullable final K key, @Nullable final V value) { - return new ImmutableEntry(key, value); - } - - /** - * Returns an unmodifiable view of the specified set of entries. The {@link - * Entry#setValue} operation throws an {@link UnsupportedOperationException}, - * as do any operations that would modify the returned set. - * - * @param entrySet the entries for which to return an unmodifiable view - * @return an unmodifiable view of the entries - */ - static Set> unmodifiableEntrySet( - final Set> entrySet) { - return new UnmodifiableEntrySet(Collections.unmodifiableSet( - entrySet)); - } - - /** - * Returns an unmodifiable view of the specified map entry. The {@link - * Entry#setValue} operation throws an {@link UnsupportedOperationException}. - * This also has the side-effect of redefining {@code equals} to comply with - * the Entry contract, to avoid a possible nefarious implementation of - * equals. - * - * @param entry the entry for which to return an unmodifiable view - * @return an unmodifiable view of the entry - */ - private static Entry unmodifiableEntry(final Entry entry) { - checkNotNull(entry); - return new AbstractMapEntry() { - @Override public K getKey() { - return entry.getKey(); - } - @Override public V getValue() { - return entry.getValue(); - } - }; - } - - /** @see Multimaps#unmodifiableEntries */ - static class UnmodifiableEntries - extends ForwardingCollection> { - private final Collection> entries; - - UnmodifiableEntries(Collection> entries) { - this.entries = entries; - } - - @Override protected Collection> delegate() { - return entries; - } - - @Override public Iterator> iterator() { - final Iterator> delegate = super.iterator(); - return new ForwardingIterator>() { - @Override public Entry next() { - return unmodifiableEntry(super.next()); - } - @Override protected Iterator> delegate() { - return delegate; - } - }; - } - - // See java.util.Collections.UnmodifiableEntrySet for details on attacks. - - @Override public Object[] toArray() { - return ObjectArrays.toArrayImpl(this); - } - - @Override public T[] toArray(T[] array) { - return ObjectArrays.toArrayImpl(this, array); - } - - @Override public boolean contains(Object o) { - return containsEntryImpl(delegate(), o); - } - - @Override public boolean containsAll(Collection c) { - return Collections2.containsAll(this, c); - } - } - - /** @see Maps#unmodifiableEntrySet(Set) */ - static class UnmodifiableEntrySet - extends UnmodifiableEntries - implements Set> { - UnmodifiableEntrySet(Set> entries) { - super(entries); - } - - // See java.util.Collections.UnmodifiableEntrySet for details on attacks. - - @Override public boolean equals(@Nullable Object object) { - return Collections2.setEquals(this, object); - } - - @Override public int hashCode() { - return Sets.hashCodeImpl(this); - } - } - - /** - * Returns an unmodifiable view of the specified bimap. This method allows - * modules to provide users with "read-only" access to internal bimaps. Query - * operations on the returned bimap "read through" to the specified bimap, and - * attemps to modify the returned map, whether direct or via its collection - * views, result in an {@code UnsupportedOperationException}. - * - *

The returned bimap will be serializable if the specified bimap is - * serializable. - * - * @param bimap the bimap for which an unmodifiable view is to be returned - * @return an unmodifiable view of the specified bimap - */ - public static BiMap unmodifiableBiMap( - BiMap bimap) { - return new UnmodifiableBiMap(bimap, null); - } - - /** @see Maps#unmodifiableBiMap(BiMap) */ - private static class UnmodifiableBiMap - extends ForwardingMap implements BiMap, Serializable { - - final Map unmodifiableMap; - final BiMap delegate; - transient BiMap inverse; - transient Set values; - - UnmodifiableBiMap(BiMap delegate, - @Nullable BiMap inverse) { - unmodifiableMap = Collections.unmodifiableMap(delegate); - this.delegate = delegate; - this.inverse = inverse; - } - - @Override protected Map delegate() { - return unmodifiableMap; - } - - public V forcePut(K key, V value) { - throw new UnsupportedOperationException(); - } - - public BiMap inverse() { - BiMap result = inverse; - return (result == null) - ? inverse = new UnmodifiableBiMap(delegate.inverse(), this) - : result; - } - - @Override public Set values() { - Set result = values; - return (result == null) - ? values = Collections.unmodifiableSet(delegate.values()) - : result; - } - - private static final long serialVersionUID = 0; - } - - /** - * Implements {@code Collection.contains} safely for forwarding collections of - * map entries. If {@code o} is an instance of {@code Map.Entry}, it is - * wrapped using {@link #unmodifiableEntry} to protect against a possible - * nefarious equals method. - * - *

Note that {@code c} is the backing (delegate) collection, rather than - * the forwarding collection. - * - * @param c the delegate (unwrapped) collection of map entries - * @param o the object that might be contained in {@code c} - * @return {@code true} if {@code c} contains {@code o} - */ - static boolean containsEntryImpl(Collection> c, Object o) { - if (!(o instanceof Entry)) { - return false; - } - return c.contains(unmodifiableEntry((Entry) o)); - } - - /** - * Implements {@code Collection.remove} safely for forwarding collections of - * map entries. If {@code o} is an instance of {@code Map.Entry}, it is - * wrapped using {@link #unmodifiableEntry} to protect against a possible - * nefarious equals method. - * - *

Note that {@code c} is backing (delegate) collection, rather than the - * forwarding collection. - * - * @param c the delegate (unwrapped) collection of map entries - * @param o the object to remove from {@code c} - * @return {@code true} if {@code c} was changed - */ - static boolean removeEntryImpl(Collection> c, Object o) { - if (!(o instanceof Entry)) { - return false; - } - return c.remove(unmodifiableEntry((Entry) o)); - } - - /** - * Returns a view of a map where each value is transformed by a function. All - * other properties of the map, such as iteration order, are left intact. For - * example, the code: - *

   {@code
-   *
-   *   Map map = ImmutableMap.of("a", 4, "b", 9);
-   *   Function sqrt = new Function() {
-   *     public Double apply(Integer in) {
-   *       return Math.sqrt((int) in);
-   *     }
-   *   };
-   *   Map transformed = Maps.transformValues(sqrt, map);
-   *   System.out.println(transformed);}
- * - * ... prints {@code {a=2.0, b=3.0}}. - * - *

Changes in the underlying map are reflected in this view. Conversely, - * this view supports removal operations, and these are reflected in the - * underlying map. - * - *

It's acceptable for the underlying map to contain null keys, and even - * null values provided that the function is capable of accepting null input. - * The transformed map might contain null values, if the function sometimes - * gives a null result. - * - *

The returned map is not thread-safe or serializable, even if the - * underlying map is. - * - *

The function is applied lazily, invoked when needed. This is necessary - * for the returned map to be a view, but it means that the function will be - * applied many times for bulk operations like {@link Map#containsValue} and - * {@code Map.toString()}. For this to perform well, {@code function} should - * be fast. To avoid lazy evaluation when the returned map doesn't need to be - * a view, copy the returned map into a new map of your choosing. - */ - public static Map transformValues( - Map fromMap, Function function) { - return new TransformedValuesMap(fromMap, function); - } - - private static class TransformedValuesMap - extends AbstractMap { - final Map fromMap; - final Function function; - - TransformedValuesMap(Map fromMap, Function function) - { - this.fromMap = checkNotNull(fromMap); - this.function = checkNotNull(function); - } - - @Override public int size() { - return fromMap.size(); - } - - @Override public boolean containsKey(Object key) { - return fromMap.containsKey(key); - } - - @Override public V2 get(Object key) { - V1 value = fromMap.get(key); - return (value != null || fromMap.containsKey(key)) - ? function.apply(value) : null; - } - - @Override public V2 remove(Object key) { - return fromMap.containsKey(key) - ? function.apply(fromMap.remove(key)) - : null; - } - - @Override public void clear() { - fromMap.clear(); - } - - EntrySet entrySet; - - @Override public Set> entrySet() { - EntrySet result = entrySet; - if (result == null) { - entrySet = result = new EntrySet(); - } - return result; - } - - class EntrySet extends AbstractSet> { - @Override public int size() { - return TransformedValuesMap.this.size(); - } - - @Override public Iterator> iterator() { - final Iterator> mapIterator - = fromMap.entrySet().iterator(); - - return new Iterator>() { - public boolean hasNext() { - return mapIterator.hasNext(); - } - - public Entry next() { - final Entry entry = mapIterator.next(); - return new AbstractMapEntry() { - @Override public K getKey() { - return entry.getKey(); - } - @Override public V2 getValue() { - return function.apply(entry.getValue()); - } - }; - } - - public void remove() { - mapIterator.remove(); - } - }; - } - - @Override public void clear() { - fromMap.clear(); - } - - @Override public boolean contains(Object o) { - if (!(o instanceof Entry)) { - return false; - } - Entry entry = (Entry) o; - Object entryKey = entry.getKey(); - Object entryValue = entry.getValue(); - V2 mapValue = TransformedValuesMap.this.get(entryKey); - if (mapValue != null) { - return mapValue.equals(entryValue); - } - return entryValue == null && containsKey(entryKey); - } - - @Override public boolean remove(Object o) { - if (contains(o)) { - Entry entry = (Entry) o; - Object key = entry.getKey(); - fromMap.remove(key); - return true; - } - return false; - } - } - } - - /** - * Returns a map containing the mappings in {@code unfiltered} whose keys - * satisfy a predicate. The returned map is a live view of {@code unfiltered}; - * changes to one affect the other. - * - *

The resulting map's {@code keySet()}, {@code entrySet()}, and {@code - * values()} views have iterators that don't support {@code remove()}, but all - * other methods are supported by the map and its views. The map's {@code - * put()} and {@code putAll()} methods throw an {@link - * IllegalArgumentException} if a key that doesn't satisfy the predicate is - * provided. - * - *

When methods such as {@code removeAll()} and {@code clear()} are called - * on the filtered map or its views, only mappings whose keys satisfy the - * filter will be removed from the underlying map. - * - *

The returned map isn't threadsafe or serializable, even if {@code - * unfiltered} is. - * - *

Many of the filtered map's methods, such as {@code size()}, - * iterate across every key/value mapping in the underlying map and determine - * which satisfy the filter. When a live view is not needed, it may be - * faster to copy the filtered map and use the copy. - */ - public static Map filterKeys( - Map unfiltered, final Predicate keyPredicate) { - checkNotNull(keyPredicate); - Predicate> entryPredicate = new Predicate>() { - public boolean apply(Entry input) { - return keyPredicate.apply(input.getKey()); - } - }; - return (unfiltered instanceof AbstractFilteredMap) - ? filterFiltered((AbstractFilteredMap) unfiltered, entryPredicate) - : new FilteredKeyMap( - checkNotNull(unfiltered), keyPredicate, entryPredicate); - } - - /** - * Returns a map containing the mappings in {@code unfiltered} whose values - * satisfy a predicate. The returned map is a live view of {@code unfiltered}; - * changes to one affect the other. - * - *

The resulting map's {@code keySet()}, {@code entrySet()}, and {@code - * values()} views have iterators that don't support {@code remove()}, but all - * other methods are supported by the map and its views. The {@link Map#put}, - * {@link Map#putAll}, and {@link Entry#setValue} methods throw an {@link - * IllegalArgumentException} if a value that doesn't satisfy the predicate is - * provided. - * - *

When methods such as {@code removeAll()} and {@code clear()} are called - * on the filtered map or its views, only mappings whose values satisfy the - * filter will be removed from the underlying map. - * - *

The returned map isn't threadsafe or serializable, even if {@code - * unfiltered} is. - * - *

Many of the filtered map's methods, such as {@code size()}, - * iterate across every key/value mapping in the underlying map and determine - * which satisfy the filter. When a live view is not needed, it may be - * faster to copy the filtered map and use the copy. - */ - public static Map filterValues( - Map unfiltered, final Predicate valuePredicate) { - checkNotNull(valuePredicate); - Predicate> entryPredicate = new Predicate>() { - public boolean apply(Entry input) { - return valuePredicate.apply(input.getValue()); - } - }; - return filterEntries(unfiltered, entryPredicate); - } - - /** - * Returns a map containing the mappings in {@code unfiltered} that satisfy a - * predicate. The returned map is a live view of {@code unfiltered}; changes - * to one affect the other. - * - *

The resulting map's {@code keySet()}, {@code entrySet()}, and {@code - * values()} views have iterators that don't support {@code remove()}, but all - * other methods are supported by the map and its views. The map's {@code - * put()} and {@code putAll()} methods throw an {@link - * IllegalArgumentException} if a key/value pair that doesn't satisfy the - * predicate is provided. Similarly, the map's entries have a {@link - * Entry#setValue} method that throws an {@link IllegalArgumentException} when - * the existing key and the provided value don't satisfy the predicate. - * - *

When methods such as {@code removeAll()} and {@code clear()} are called - * on the filtered map or its views, only mappings that satisfy the filter - * will be removed from the underlying map. - * - *

The returned map isn't threadsafe or serializable, even if {@code - * unfiltered} is. - * - *

Many of the filtered map's methods, such as {@code size()}, - * iterate across every key/value mapping in the underlying map and determine - * which satisfy the filter. When a live view is not needed, it may be - * faster to copy the filtered map and use the copy. - */ - public static Map filterEntries( - Map unfiltered, Predicate> entryPredicate) { - checkNotNull(entryPredicate); - return (unfiltered instanceof AbstractFilteredMap) - ? filterFiltered((AbstractFilteredMap) unfiltered, entryPredicate) - : new FilteredEntryMap(checkNotNull(unfiltered), entryPredicate); - } - - /** - * Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when - * filtering a filtered map. - */ - private static Map filterFiltered( - AbstractFilteredMap map, - Predicate> entryPredicate) { - Predicate> predicate - = Predicates.and(map.predicate, entryPredicate); - return new FilteredEntryMap(map.unfiltered, predicate); - } - - private static abstract class AbstractFilteredMap - extends AbstractMap { - - final Map unfiltered; - final Predicate> predicate; - - AbstractFilteredMap(Map unfiltered, - Predicate> predicate) { - this.unfiltered = unfiltered; - this.predicate = predicate; - } - - boolean apply(Object key, V value) { - // This method is called only when the key is in the map, implying that - // key is a K. - @SuppressWarnings("unchecked") - K k = (K) key; - return predicate.apply(Maps.immutableEntry(k, value)); - } - - @Override public V put(K key, V value) { - checkArgument(apply(key, value)); - return unfiltered.put(key, value); - } - - @Override public void putAll(Map map) { - for (Entry entry : map.entrySet()) { - checkArgument(apply(entry.getKey(), entry.getValue())); - } - unfiltered.putAll(map); - } - - @Override public boolean containsKey(Object key) { - return unfiltered.containsKey(key) && apply(key, unfiltered.get(key)); - } - - @Override public V get(Object key) { - V value = unfiltered.get(key); - return ((value != null) && apply(key, value)) ? value : null; - } - - @Override public boolean isEmpty() { - return entrySet().isEmpty(); - } - - @Override public V remove(Object key) { - return containsKey(key) ? unfiltered.remove(key) : null; - } - - Collection values; - - @Override public Collection values() { - Collection result = values; - return (result == null) ? values = new Values() : result; - } - - class Values extends AbstractCollection { - @Override public Iterator iterator() { - final Iterator> entryIterator = entrySet().iterator(); - return new UnmodifiableIterator() { - public boolean hasNext() { - return entryIterator.hasNext(); - } - public V next() { - return entryIterator.next().getValue(); - } - }; - } - - @Override public int size() { - return entrySet().size(); - } - - @Override public void clear() { - entrySet().clear(); - } - - @Override public boolean isEmpty() { - return entrySet().isEmpty(); - } - - @Override public boolean remove(Object o) { - Iterator> iterator = unfiltered.entrySet().iterator(); - while (iterator.hasNext()) { - Entry entry = iterator.next(); - if (Objects.equal(o, entry.getValue()) && predicate.apply(entry)) { - iterator.remove(); - return true; - } - } - return false; - } - - @Override public boolean removeAll(Collection collection) { - checkNotNull(collection); - boolean changed = false; - Iterator> iterator = unfiltered.entrySet().iterator(); - while (iterator.hasNext()) { - Entry entry = iterator.next(); - if (collection.contains(entry.getValue()) && predicate.apply(entry)) { - iterator.remove(); - changed = true; - } - } - return changed; - } - - @Override public boolean retainAll(Collection collection) { - checkNotNull(collection); - boolean changed = false; - Iterator> iterator = unfiltered.entrySet().iterator(); - while (iterator.hasNext()) { - Entry entry = iterator.next(); - if (!collection.contains(entry.getValue()) - && predicate.apply(entry)) { - iterator.remove(); - changed = true; - } - } - return changed; - } - - @Override public Object[] toArray() { - // creating an ArrayList so filtering happens once - return Lists.newArrayList(iterator()).toArray(); - } - - @Override public T[] toArray(T[] array) { - return Lists.newArrayList(iterator()).toArray(array); - } - } - } - - private static class FilteredKeyMap extends AbstractFilteredMap { - Predicate keyPredicate; - - FilteredKeyMap(Map unfiltered, Predicate keyPredicate, - Predicate> entryPredicate) { - super(unfiltered, entryPredicate); - this.keyPredicate = keyPredicate; - } - - Set> entrySet; - - @Override public Set> entrySet() { - Set> result = entrySet; - return (result == null) - ? entrySet = Sets.filter(unfiltered.entrySet(), predicate) - : result; - } - - Set keySet; - - @Override public Set keySet() { - Set result = keySet; - return (result == null) - ? keySet = Sets.filter(unfiltered.keySet(), keyPredicate) - : result; - } - - // The cast is called only when the key is in the unfiltered map, implying - // that key is a K. - @SuppressWarnings("unchecked") - @Override public boolean containsKey(Object key) { - return unfiltered.containsKey(key) && keyPredicate.apply((K) key); - } - } - - private static class FilteredEntryMap - extends AbstractFilteredMap { - /** - * Entries in this set satisfy the predicate, but they don't validate the - * input to {@code Entry.setValue()}. - */ - final Set> filteredEntrySet; - - FilteredEntryMap(Map unfiltered, - Predicate> entryPredicate) { - super(unfiltered, entryPredicate); - filteredEntrySet = Sets.filter(unfiltered.entrySet(), predicate); - } - - Set> entrySet; - - @Override public Set> entrySet() { - Set> result = entrySet; - return (result == null) ? entrySet = new EntrySet() : result; - } - - private class EntrySet extends ForwardingSet> { - @Override protected Set> delegate() { - return filteredEntrySet; - } - - @Override public Iterator> iterator() { - final Iterator> iterator = filteredEntrySet.iterator(); - return new UnmodifiableIterator>() { - public boolean hasNext() { - return iterator.hasNext(); - } - public Entry next() { - final Entry entry = iterator.next(); - return new ForwardingMapEntry() { - @Override protected Entry delegate() { - return entry; - } - @Override public V setValue(V value) { - checkArgument(apply(entry.getKey(), value)); - return super.setValue(value); - } - }; - } - }; - } - } - - Set keySet; - - @Override public Set keySet() { - Set result = keySet; - return (result == null) ? keySet = new KeySet() : result; - } - - private class KeySet extends AbstractSet { - @Override public Iterator iterator() { - final Iterator> iterator = filteredEntrySet.iterator(); - return new UnmodifiableIterator() { - public boolean hasNext() { - return iterator.hasNext(); - } - public K next() { - return iterator.next().getKey(); - } - }; - } - - @Override public int size() { - return filteredEntrySet.size(); - } - - @Override public void clear() { - filteredEntrySet.clear(); - } - - @Override public boolean contains(Object o) { - return containsKey(o); - } - - @Override public boolean remove(Object o) { - if (containsKey(o)) { - unfiltered.remove(o); - return true; - } - return false; - } - - @Override public boolean removeAll(Collection collection) { - checkNotNull(collection); // for GWT - boolean changed = false; - for (Object obj : collection) { - changed |= remove(obj); - } - return changed; - } - - @Override public boolean retainAll(Collection collection) { - checkNotNull(collection); // for GWT - boolean changed = false; - Iterator> iterator = unfiltered.entrySet().iterator(); - while (iterator.hasNext()) { - Entry entry = iterator.next(); - if (!collection.contains(entry.getKey()) && predicate.apply(entry)) { - iterator.remove(); - changed = true; - } - } - return changed; - } - - @Override public Object[] toArray() { - // creating an ArrayList so filtering happens once - return Lists.newArrayList(iterator()).toArray(); - } - - @Override public T[] toArray(T[] array) { - return Lists.newArrayList(iterator()).toArray(array); - } - } - } - - /** - * {@code AbstractMap} extension that implements {@link #isEmpty()} as {@code - * entrySet().isEmpty()} instead of {@code size() == 0} to speed up - * implementations where {@code size()} is O(n), and it delegates the {@code - * isEmpty()} methods of its key set and value collection to this - * implementation. - */ - @GwtCompatible - abstract static class ImprovedAbstractMap - extends AbstractMap { - - /** - * Creates the entry set to be returned by {@link #entrySet()}. This method - * is invoked at most once on a given map, at the time when {@code - * entrySet} is first called. - */ - protected abstract Set> createEntrySet(); - - private transient Set> entrySet; - - @Override public Set> entrySet() { - Set> result = entrySet; - if (result == null) { - entrySet = result = createEntrySet(); - } - return result; - } - - private transient Set keySet; - - @Override public Set keySet() { - Set result = keySet; - if (result == null) { - final Set delegate = super.keySet(); - keySet = result = new ForwardingSet() { - @Override protected Set delegate() { - return delegate; - } - - @Override public boolean isEmpty() { - return ImprovedAbstractMap.this.isEmpty(); - } - }; - } - return result; - } - - private transient Collection values; - - @Override public Collection values() { - Collection result = values; - if (result == null) { - final Collection delegate = super.values(); - values = result = new ForwardingCollection() { - @Override protected Collection delegate() { - return delegate; - } - - @Override public boolean isEmpty() { - return ImprovedAbstractMap.this.isEmpty(); - } - }; - } - return result; - } - - /** - * Returns {@code true} if this map contains no key-value mappings. - * - *

The implementation returns {@code entrySet().isEmpty()}. - * - * @return {@code true} if this map contains no key-value mappings - */ - @Override public boolean isEmpty() { - return entrySet().isEmpty(); - } - } - - static final MapJoiner standardJoiner - = Collections2.standardJoiner.withKeyValueSeparator("="); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multimap.java deleted file mode 100644 index e5ebe65e92b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multimap.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -/** - * A collection similar to a {@code Map}, but which may associate multiple - * values with a single key. If you call {@link #put} twice, with the same key - * but different values, the multimap contains mappings from the key to both - * values. - * - *

The methods {@link #get}, {@link #keySet}, {@link #keys}, {@link #values}, - * {@link #entries}, and {@link #asMap} return collections that are views of the - * multimap. If the multimap is modifiable, updating it can change the contents - * of those collections, and updating the collections will change the multimap. - * In contrast, {@link #replaceValues} and {@link #removeAll} return collections - * that are independent of subsequent multimap changes. - * - *

Depending on the implementation, a multimap may or may not allow duplicate - * key-value pairs. In other words, the multimap contents after adding the same - * key and value twice varies between implementations. In multimaps allowing - * duplicates, the multimap will contain two mappings, and {@code get} will - * return a collection that includes the value twice. In multimaps not - * supporting duplicates, the multimap will contain a single mapping from the - * key to the value, and {@code get} will return a collection that includes the - * value once. - * - *

All methods that alter the multimap are optional, and the views returned - * by the multimap may or may not be modifiable. When modification isn't - * supported, those methods will throw an {@link UnsupportedOperationException}. - * - * @author Jared Levy - * @param the type of keys maintained by this multimap - * @param the type of mapped values - */ -@GwtCompatible -public interface Multimap { - // Query Operations - - /** Returns the number of key-value pairs in the multimap. */ - int size(); - - /** Returns {@code true} if the multimap contains no key-value pairs. */ - boolean isEmpty(); - - /** - * Returns {@code true} if the multimap contains any values for the specified - * key. - * - * @param key key to search for in multimap - */ - boolean containsKey(@Nullable Object key); - - /** - * Returns {@code true} if the multimap contains the specified value for any - * key. - * - * @param value value to search for in multimap - */ - boolean containsValue(@Nullable Object value); - - /** - * Returns {@code true} if the multimap contains the specified key-value pair. - * - * @param key key to search for in multimap - * @param value value to search for in multimap - */ - boolean containsEntry(@Nullable Object key, @Nullable Object value); - - // Modification Operations - - /** - * Stores a key-value pair in the multimap. - * - *

Some multimap implementations allow duplicate key-value pairs, in which - * case {@code put} always adds a new key-value pair and increases the - * multimap size by 1. Other implementations prohibit duplicates, and storing - * a key-value pair that's already in the multimap has no effect. - * - * @param key key to store in the multimap - * @param value value to store in the multimap - * @return {@code true} if the method increased the size of the multimap, or - * {@code false} if the multimap already contained the key-value pair and - * doesn't allow duplicates - */ - boolean put(@Nullable K key, @Nullable V value); - - /** - * Removes a key-value pair from the multimap. - * - * @param key key of entry to remove from the multimap - * @param value value of entry to remove the multimap - * @return {@code true} if the multimap changed - */ - boolean remove(@Nullable Object key, @Nullable Object value); - - // Bulk Operations - - /** - * Stores a collection of values with the same key. - * - * @param key key to store in the multimap - * @param values values to store in the multimap - * @return {@code true} if the multimap changed - */ - boolean putAll(@Nullable K key, Iterable values); - - /** - * Copies all of another multimap's key-value pairs into this multimap. The - * order in which the mappings are added is determined by - * {@code multimap.entries()}. - * - * @param multimap mappings to store in this multimap - * @return {@code true} if the multimap changed - */ - boolean putAll(Multimap multimap); - - /** - * Stores a collection of values with the same key, replacing any existing - * values for that key. - * - * @param key key to store in the multimap - * @param values values to store in the multimap - * @return the collection of replaced values, or an empty collection if no - * values were previously associated with the key. The collection - * may be modifiable, but updating it will have no effect on the - * multimap. - */ - Collection replaceValues(@Nullable K key, Iterable values); - - /** - * Removes all values associated with a given key. - * - * @param key key of entries to remove from the multimap - * @return the collection of removed values, or an empty collection if no - * values were associated with the provided key. The collection - * may be modifiable, but updating it will have no effect on the - * multimap. - */ - Collection removeAll(@Nullable Object key); - - /** - * Removes all key-value pairs from the multimap. - */ - void clear(); - - // Views - - /** - * Returns a collection view of all values associated with a key. If no - * mappings in the multimap have the provided key, an empty collection is - * returned. - * - *

Changes to the returned collection will update the underlying multimap, - * and vice versa. - * - * @param key key to search for in multimap - * @return the collection of values that the key maps to - */ - Collection get(@Nullable K key); - - /** - * Returns the set of all keys, each appearing once in the returned set. - * Changes to the returned set will update the underlying multimap, and vice - * versa. - * - * @return the collection of distinct keys - */ - Set keySet(); - - /** - * Returns a collection, which may contain duplicates, of all keys. The number - * of times of key appears in the returned multiset equals the number of - * mappings the key has in the multimap. Changes to the returned multiset will - * update the underlying multimap, and vice versa. - * - * @return a multiset with keys corresponding to the distinct keys of the - * multimap and frequencies corresponding to the number of values that - * each key maps to - */ - Multiset keys(); - - /** - * Returns a collection of all values in the multimap. Changes to the returned - * collection will update the underlying multimap, and vice versa. - * - * @return collection of values, which may include the same value multiple - * times if it occurs in multiple mappings - */ - Collection values(); - - /** - * Returns a collection of all key-value pairs. Changes to the returned - * collection will update the underlying multimap, and vice versa. The entries - * collection does not support the {@code add} or {@code addAll} operations. - * - * @return collection of map entries consisting of key-value pairs - */ - Collection> entries(); - - /** - * Returns a map view that associates each key with the corresponding values - * in the multimap. Changes to the returned map, such as element removal, - * will update the underlying multimap. The map does not support - * {@code setValue()} on its entries, {@code put}, or {@code putAll}. - * - *

The collections returned by {@code asMap().get(Object)} have the same - * behavior as those returned by {@link #get}. - * - * @return a map view from a key to its collection of values - */ - Map> asMap(); - - // Comparison and hashing - - /** - * Compares the specified object with this multimap for equality. Two - * multimaps are equal when their map views, as returned by {@link #asMap}, - * are also equal. - * - *

In general, two multimaps with identical key-value mappings may or may - * not be equal, depending on the implementation. For example, two - * {@link SetMultimap} instances with the same key-value mappings are equal, - * but equality of two {@link ListMultimap} instances depends on the ordering - * of the values for each key. - * - *

A non-empty {@link SetMultimap} cannot be equal to a non-empty - * {@link ListMultimap}, since their {@link #asMap} views contain unequal - * collections as values. However, any two empty multimaps are equal, because - * they both have empty {@link #asMap} views. - */ - boolean equals(@Nullable Object obj); - - /** - * Returns the hash code for this multimap. - * - *

The hash code of a multimap is defined as the hash code of the map view, - * as returned by {@link Multimap#asMap}. - */ - int hashCode(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multimaps.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multimaps.java deleted file mode 100644 index b92b6688d56..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multimaps.java +++ /dev/null @@ -1,1216 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Function; -import org.elasticsearch.util.base.Joiner; -import org.elasticsearch.util.base.Joiner.MapJoiner; -import org.elasticsearch.util.base.Preconditions; -import org.elasticsearch.util.base.Supplier; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.*; -import java.util.Map.Entry; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Provides static methods acting on or generating a {@code Multimap}. - * - * @author Jared Levy - * @author Robert Konigsberg - * @author Mike Bostock - */ -@GwtCompatible -public final class Multimaps { - private Multimaps() {} - - /** - * Creates a new {@code Multimap} that uses the provided map and factory. It - * can generate a multimap based on arbitrary {@link Map} and - * {@link Collection} classes. - * - *

The {@code factory}-generated and {@code map} classes determine the - * multimap iteration order. They also specify the behavior of the - * {@code equals}, {@code hashCode}, and {@code toString} methods for the - * multimap and its returned views. However, the multimap's {@code get} - * method returns instances of a different class than {@code factory.get()} - * does. - * - *

The multimap is serializable if {@code map}, {@code factory}, the - * collections generated by {@code factory}, and the multimap contents are all - * serializable. - * - *

The multimap is not threadsafe when any concurrent operations update the - * multimap, even if {@code map} and the instances generated by - * {@code factory} are. Concurrent read operations will work correctly. To - * allow concurrent update operations, wrap the multimap with a call to - * {@link #synchronizedMultimap}. - * - *

Call this method only when the simpler methods - * {@link ArrayListMultimap#create()}, {@link HashMultimap#create()}, - * {@link LinkedHashMultimap#create()}, {@link LinkedListMultimap#create()}, - * {@link TreeMultimap#create()}, and - * {@link TreeMultimap#create(Comparator, Comparator)} won't suffice. - * - *

Note: the multimap assumes complete ownership over of {@code map} and - * the collections returned by {@code factory}. Those objects should not be - * manually updated and they should not use soft, weak, or phantom references. - * - * @param map place to store the mapping from each key to its corresponding - * values - * @param factory supplier of new, empty collections that will each hold all - * values for a given key - * @throws IllegalArgumentException if {@code map} is not empty - */ - public static Multimap newMultimap(Map> map, - final Supplier> factory) { - return new CustomMultimap(map, factory); - } - - private static class CustomMultimap extends AbstractMultimap { - transient Supplier> factory; - - CustomMultimap(Map> map, - Supplier> factory) { - super(map); - this.factory = checkNotNull(factory); - } - - @Override protected Collection createCollection() { - return factory.get(); - } - - // can't use Serialization writeMultimap and populateMultimap methods since - // there's no way to generate the empty backing map. - - /** @serialData the factory and the backing map */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(factory); - stream.writeObject(backingMap()); - } - - @SuppressWarnings("unchecked") // reading data stored by writeObject - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - factory = (Supplier>) stream.readObject(); - Map> map = (Map>) stream.readObject(); - setMap(map); - } - - private static final long serialVersionUID = 0; - } - - /** - * Creates a new {@code ListMultimap} that uses the provided map and factory. - * It can generate a multimap based on arbitrary {@link Map} and {@link List} - * classes. - * - *

The {@code factory}-generated and {@code map} classes determine the - * multimap iteration order. They also specify the behavior of the - * {@code equals}, {@code hashCode}, and {@code toString} methods for the - * multimap and its returned views. The multimap's {@code get}, {@code - * removeAll}, and {@code replaceValues} methods return {@code RandomAccess} - * lists if the factory does. However, the multimap's {@code get} method - * returns instances of a different class than does {@code factory.get()}. - * - *

The multimap is serializable if {@code map}, {@code factory}, the - * lists generated by {@code factory}, and the multimap contents are all - * serializable. - * - *

The multimap is not threadsafe when any concurrent operations update the - * multimap, even if {@code map} and the instances generated by - * {@code factory} are. Concurrent read operations will work correctly. To - * allow concurrent update operations, wrap the multimap with a call to - * {@link #synchronizedListMultimap}. - * - *

Call this method only when the simpler methods - * {@link ArrayListMultimap#create()} and {@link LinkedListMultimap#create()} - * won't suffice. - * - *

Note: the multimap assumes complete ownership over of {@code map} and - * the lists returned by {@code factory}. Those objects should not be manually - * updated and they should not use soft, weak, or phantom references. - * - * @param map place to store the mapping from each key to its corresponding - * values - * @param factory supplier of new, empty lists that will each hold all values - * for a given key - * @throws IllegalArgumentException if {@code map} is not empty - */ - public static ListMultimap newListMultimap( - Map> map, final Supplier> factory) { - return new CustomListMultimap(map, factory); - } - - private static class CustomListMultimap - extends AbstractListMultimap { - transient Supplier> factory; - - CustomListMultimap(Map> map, - Supplier> factory) { - super(map); - this.factory = checkNotNull(factory); - } - - @Override protected List createCollection() { - return factory.get(); - } - - /** @serialData the factory and the backing map */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(factory); - stream.writeObject(backingMap()); - } - - @SuppressWarnings("unchecked") // reading data stored by writeObject - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - factory = (Supplier>) stream.readObject(); - Map> map = (Map>) stream.readObject(); - setMap(map); - } - - private static final long serialVersionUID = 0; - } - - /** - * Creates a new {@code SetMultimap} that uses the provided map and factory. - * It can generate a multimap based on arbitrary {@link Map} and {@link Set} - * classes. - * - *

The {@code factory}-generated and {@code map} classes determine the - * multimap iteration order. They also specify the behavior of the - * {@code equals}, {@code hashCode}, and {@code toString} methods for the - * multimap and its returned views. However, the multimap's {@code get} - * method returns instances of a different class than {@code factory.get()} - * does. - * - *

The multimap is serializable if {@code map}, {@code factory}, the - * sets generated by {@code factory}, and the multimap contents are all - * serializable. - * - *

The multimap is not threadsafe when any concurrent operations update the - * multimap, even if {@code map} and the instances generated by - * {@code factory} are. Concurrent read operations will work correctly. To - * allow concurrent update operations, wrap the multimap with a call to - * {@link #synchronizedSetMultimap}. - * - *

Call this method only when the simpler methods - * {@link HashMultimap#create()}, {@link LinkedHashMultimap#create()}, - * {@link TreeMultimap#create()}, and - * {@link TreeMultimap#create(Comparator, Comparator)} won't suffice. - * - *

Note: the multimap assumes complete ownership over of {@code map} and - * the sets returned by {@code factory}. Those objects should not be manually - * updated and they should not use soft, weak, or phantom references. - * - * @param map place to store the mapping from each key to its corresponding - * values - * @param factory supplier of new, empty sets that will each hold all values - * for a given key - * @throws IllegalArgumentException if {@code map} is not empty - */ - public static SetMultimap newSetMultimap( - Map> map, final Supplier> factory) { - return new CustomSetMultimap(map, factory); - } - - private static class CustomSetMultimap - extends AbstractSetMultimap { - transient Supplier> factory; - - CustomSetMultimap(Map> map, - Supplier> factory) { - super(map); - this.factory = checkNotNull(factory); - } - - @Override protected Set createCollection() { - return factory.get(); - } - - /** @serialData the factory and the backing map */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(factory); - stream.writeObject(backingMap()); - } - - @SuppressWarnings("unchecked") // reading data stored by writeObject - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - factory = (Supplier>) stream.readObject(); - Map> map = (Map>) stream.readObject(); - setMap(map); - } - - private static final long serialVersionUID = 0; - } - - /** - * Creates a new {@code SortedSetMultimap} that uses the provided map and - * factory. It can generate a multimap based on arbitrary {@link Map} and - * {@link SortedSet} classes. - * - *

The {@code factory}-generated and {@code map} classes determine the - * multimap iteration order. They also specify the behavior of the - * {@code equals}, {@code hashCode}, and {@code toString} methods for the - * multimap and its returned views. However, the multimap's {@code get} - * method returns instances of a different class than {@code factory.get()} - * does. - * - *

The multimap is serializable if {@code map}, {@code factory}, the - * sets generated by {@code factory}, and the multimap contents are all - * serializable. - * - *

The multimap is not threadsafe when any concurrent operations update the - * multimap, even if {@code map} and the instances generated by - * {@code factory} are. Concurrent read operations will work correctly. To - * allow concurrent update operations, wrap the multimap with a call to - * {@link #synchronizedSortedSetMultimap}. - * - *

Call this method only when the simpler methods - * {@link TreeMultimap#create()} and - * {@link TreeMultimap#create(Comparator, Comparator)} won't suffice. - * - *

Note: the multimap assumes complete ownership over of {@code map} and - * the sets returned by {@code factory}. Those objects should not be manually - * updated and they should not use soft, weak, or phantom references. - * - * @param map place to store the mapping from each key to its corresponding - * values - * @param factory supplier of new, empty sorted sets that will each hold - * all values for a given key - * @throws IllegalArgumentException if {@code map} is not empty - */ - public static SortedSetMultimap newSortedSetMultimap( - Map> map, - final Supplier> factory) { - return new CustomSortedSetMultimap(map, factory); - } - - private static class CustomSortedSetMultimap - extends AbstractSortedSetMultimap { - transient Supplier> factory; - transient Comparator valueComparator; - - CustomSortedSetMultimap(Map> map, - Supplier> factory) { - super(map); - this.factory = checkNotNull(factory); - valueComparator = factory.get().comparator(); - } - - @Override protected SortedSet createCollection() { - return factory.get(); - } - - /*@Override*/ public Comparator valueComparator() { - return valueComparator; - } - - /** @serialData the factory and the backing map */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(factory); - stream.writeObject(backingMap()); - } - - @SuppressWarnings("unchecked") // reading data stored by writeObject - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - factory = (Supplier>) stream.readObject(); - valueComparator = factory.get().comparator(); - Map> map = (Map>) stream.readObject(); - setMap(map); - } - - private static final long serialVersionUID = 0; - } - - /** - * Copies each key-value mapping in {@code source} into {@code dest}, with - * its key and value reversed. - * - * @param source any multimap - * @param dest the multimap to copy into; usually empty - * @return {@code dest} - */ - public static > M invertFrom( - Multimap source, M dest) { - for (Map.Entry entry : source.entries()) { - dest.put(entry.getValue(), entry.getKey()); - } - return dest; - } - - /** - * Returns a synchronized (thread-safe) multimap backed by the specified - * multimap. In order to guarantee serial access, it is critical that - * all access to the backing multimap is accomplished through the - * returned multimap. - * - *

It is imperative that the user manually synchronize on the returned - * multimap when accessing any of its collection views:

  {@code
-   *
-   *  Multimap m = Multimaps.synchronizedMultimap(
-   *      HashMultimap.create());
-   *  ...
-   *  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. - * - *

Note that the generated multimap's {@link Multimap#removeAll} and - * {@link Multimap#replaceValues} methods return collections that aren't - * synchronized. - * - *

The returned multimap will be serializable if the specified multimap is - * serializable. - * - * @param multimap the multimap to be wrapped in a synchronized view - * @return a synchronized view of the specified multimap - */ - public static Multimap synchronizedMultimap( - Multimap multimap) { - return Synchronized.multimap(multimap, null); - } - - /** - * Returns an unmodifiable view of the specified multimap. Query operations on - * the returned multimap "read through" to the specified multimap, and - * attempts to modify the returned multimap, either directly or through the - * multimap's views, result in an {@code UnsupportedOperationException}. - * - *

Note that the generated multimap's {@link Multimap#removeAll} and - * {@link Multimap#replaceValues} methods return collections that are - * modifiable. - * - *

The returned multimap will be serializable if the specified multimap is - * serializable. - * - * @param delegate the multimap for which an unmodifiable view is to be - * returned - * @return an unmodifiable view of the specified multimap - */ - public static Multimap unmodifiableMultimap( - Multimap delegate) { - return new UnmodifiableMultimap(delegate); - } - - private static class UnmodifiableMultimap - extends ForwardingMultimap implements Serializable { - final Multimap delegate; - transient Collection> entries; - transient Multiset keys; - transient Set keySet; - transient Collection values; - transient Map> map; - - UnmodifiableMultimap(final Multimap delegate) { - this.delegate = delegate; - } - - @Override protected Multimap delegate() { - return delegate; - } - - @Override public void clear() { - throw new UnsupportedOperationException(); - } - - @Override public Map> asMap() { - Map> result = map; - if (result == null) { - final Map> unmodifiableMap - = Collections.unmodifiableMap(delegate.asMap()); - map = result = new ForwardingMap>() { - @Override protected Map> delegate() { - return unmodifiableMap; - } - - Set>> entrySet; - - @Override public Set>> entrySet() { - Set>> result = entrySet; - return (result == null) - ? entrySet - = unmodifiableAsMapEntries(unmodifiableMap.entrySet()) - : result; - } - - @Override public Collection get(Object key) { - Collection collection = unmodifiableMap.get(key); - return (collection == null) - ? null : unmodifiableValueCollection(collection); - } - - Collection> asMapValues; - - @Override public Collection> values() { - Collection> result = asMapValues; - return (result == null) - ? asMapValues - = new UnmodifiableAsMapValues(unmodifiableMap.values()) - : result; - } - - @Override public boolean containsValue(Object o) { - return values().contains(o); - } - }; - } - return result; - } - - @Override public Collection> entries() { - Collection> result = entries; - if (result == null) { - entries = result = unmodifiableEntries(delegate.entries()); - } - return result; - } - - @Override public Collection get(K key) { - return unmodifiableValueCollection(delegate.get(key)); - } - - @Override public Multiset keys() { - Multiset result = keys; - if (result == null) { - keys = result = Multisets.unmodifiableMultiset(delegate.keys()); - } - return result; - } - - @Override public Set keySet() { - Set result = keySet; - if (result == null) { - keySet = result = Collections.unmodifiableSet(delegate.keySet()); - } - return result; - } - - @Override public boolean put(K key, V value) { - throw new UnsupportedOperationException(); - } - - @Override public boolean putAll(K key, - @SuppressWarnings("hiding") Iterable values) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean putAll(Multimap multimap) { - throw new UnsupportedOperationException(); - } - - @Override public boolean remove(Object key, Object value) { - throw new UnsupportedOperationException(); - } - - @Override public Collection removeAll(Object key) { - throw new UnsupportedOperationException(); - } - - @Override public Collection replaceValues(K key, - @SuppressWarnings("hiding") Iterable values) { - throw new UnsupportedOperationException(); - } - - @Override public Collection values() { - Collection result = values; - if (result == null) { - values = result = Collections.unmodifiableCollection(delegate.values()); - } - return result; - } - - private static final long serialVersionUID = 0; - } - - private static class UnmodifiableAsMapValues - extends ForwardingCollection> { - final Collection> delegate; - UnmodifiableAsMapValues(Collection> delegate) { - this.delegate = Collections.unmodifiableCollection(delegate); - } - @Override protected Collection> delegate() { - return delegate; - } - @Override public Iterator> iterator() { - final Iterator> iterator = delegate.iterator(); - return new Iterator>() { - public boolean hasNext() { - return iterator.hasNext(); - } - public Collection next() { - return unmodifiableValueCollection(iterator.next()); - } - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - @Override public Object[] toArray() { - return ObjectArrays.toArrayImpl(this); - } - @Override public T[] toArray(T[] array) { - return ObjectArrays.toArrayImpl(this, array); - } - @Override public boolean contains(Object o) { - return Iterators.contains(iterator(), o); - } - @Override public boolean containsAll(Collection c) { - return Collections2.containsAll(this, c); - } - } - - private static class UnmodifiableListMultimap - extends UnmodifiableMultimap implements ListMultimap { - UnmodifiableListMultimap(ListMultimap delegate) { - super(delegate); - } - @Override public ListMultimap delegate() { - return (ListMultimap) super.delegate(); - } - @Override public List get(K key) { - return Collections.unmodifiableList(delegate().get(key)); - } - @Override public List removeAll(Object key) { - throw new UnsupportedOperationException(); - } - @Override public List replaceValues( - K key, @SuppressWarnings("hiding") Iterable values) { - throw new UnsupportedOperationException(); - } - private static final long serialVersionUID = 0; - } - - private static class UnmodifiableSetMultimap - extends UnmodifiableMultimap implements SetMultimap { - UnmodifiableSetMultimap(SetMultimap delegate) { - super(delegate); - } - @Override public SetMultimap delegate() { - return (SetMultimap) super.delegate(); - } - @Override public Set get(K key) { - /* - * Note that this doesn't return a SortedSet when delegate is a - * SortedSetMultiset, unlike (SortedSet) super.get(). - */ - return Collections.unmodifiableSet(delegate().get(key)); - } - @Override public Set> entries() { - return Maps.unmodifiableEntrySet(delegate().entries()); - } - @Override public Set removeAll(Object key) { - throw new UnsupportedOperationException(); - } - @Override public Set replaceValues( - K key, @SuppressWarnings("hiding") Iterable values) { - throw new UnsupportedOperationException(); - } - private static final long serialVersionUID = 0; - } - - private static class UnmodifiableSortedSetMultimap - extends UnmodifiableSetMultimap implements SortedSetMultimap { - UnmodifiableSortedSetMultimap(SortedSetMultimap delegate) { - super(delegate); - } - @Override public SortedSetMultimap delegate() { - return (SortedSetMultimap) super.delegate(); - } - @Override public SortedSet get(K key) { - return Collections.unmodifiableSortedSet(delegate().get(key)); - } - @Override public SortedSet removeAll(Object key) { - throw new UnsupportedOperationException(); - } - @Override public SortedSet replaceValues( - K key, @SuppressWarnings("hiding") Iterable values) { - throw new UnsupportedOperationException(); - } - public Comparator valueComparator() { - return delegate().valueComparator(); - } - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) {@code SetMultimap} backed by the - * specified multimap. - * - *

You must follow the warnings described in {@link #synchronizedMultimap}. - * - *

The returned multimap will be serializable if the specified multimap is - * serializable. - * - * @param multimap the multimap to be wrapped - * @return a synchronized view of the specified multimap - */ - public static SetMultimap synchronizedSetMultimap( - SetMultimap multimap) { - return Synchronized.setMultimap(multimap, null); - } - - /** - * Returns an unmodifiable view of the specified {@code SetMultimap}. Query - * operations on the returned multimap "read through" to the specified - * multimap, and attempts to modify the returned multimap, either directly or - * through the multimap's views, result in an - * {@code UnsupportedOperationException}. - * - *

Note that the generated multimap's {@link Multimap#removeAll} and - * {@link Multimap#replaceValues} methods return collections that are - * modifiable. - * - *

The returned multimap will be serializable if the specified multimap is - * serializable. - * - * @param delegate the multimap for which an unmodifiable view is to be - * returned - * @return an unmodifiable view of the specified multimap - */ - public static SetMultimap unmodifiableSetMultimap( - SetMultimap delegate) { - return new UnmodifiableSetMultimap(delegate); - } - - /** - * Returns a synchronized (thread-safe) {@code SortedSetMultimap} backed by - * the specified multimap. - * - *

You must follow the warnings described in {@link #synchronizedMultimap}. - * - *

The returned multimap will be serializable if the specified multimap is - * serializable. - * - * @param multimap the multimap to be wrapped - * @return a synchronized view of the specified multimap - */ - public static SortedSetMultimap - synchronizedSortedSetMultimap(SortedSetMultimap multimap) { - return Synchronized.sortedSetMultimap(multimap, null); - } - - /** - * Returns an unmodifiable view of the specified {@code SortedSetMultimap}. - * Query operations on the returned multimap "read through" to the specified - * multimap, and attempts to modify the returned multimap, either directly or - * through the multimap's views, result in an - * {@code UnsupportedOperationException}. - * - *

Note that the generated multimap's {@link Multimap#removeAll} and - * {@link Multimap#replaceValues} methods return collections that are - * modifiable. - * - *

The returned multimap will be serializable if the specified multimap is - * serializable. - * - * @param delegate the multimap for which an unmodifiable view is to be - * returned - * @return an unmodifiable view of the specified multimap - */ - public static SortedSetMultimap unmodifiableSortedSetMultimap( - SortedSetMultimap delegate) { - return new UnmodifiableSortedSetMultimap(delegate); - } - - /** - * Returns a synchronized (thread-safe) {@code ListMultimap} backed by the - * specified multimap. - * - *

You must follow the warnings described in {@link #synchronizedMultimap}. - * - * @param multimap the multimap to be wrapped - * @return a synchronized view of the specified multimap - */ - public static ListMultimap synchronizedListMultimap( - ListMultimap multimap) { - return Synchronized.listMultimap(multimap, null); - } - - /** - * Returns an unmodifiable view of the specified {@code ListMultimap}. Query - * operations on the returned multimap "read through" to the specified - * multimap, and attempts to modify the returned multimap, either directly or - * through the multimap's views, result in an - * {@code UnsupportedOperationException}. - * - *

Note that the generated multimap's {@link Multimap#removeAll} and - * {@link Multimap#replaceValues} methods return collections that are - * modifiable. - * - *

The returned multimap will be serializable if the specified multimap is - * serializable. - * - * @param delegate the multimap for which an unmodifiable view is to be - * returned - * @return an unmodifiable view of the specified multimap - */ - public static ListMultimap unmodifiableListMultimap( - ListMultimap delegate) { - return new UnmodifiableListMultimap(delegate); - } - - /** - * Returns an unmodifiable view of the specified collection, preserving the - * interface for instances of {@code SortedSet}, {@code Set}, {@code List} and - * {@code Collection}, in that order of preference. - * - * @param collection the collection for which to return an unmodifiable view - * @return an unmodifiable view of the collection - */ - private static Collection unmodifiableValueCollection( - Collection collection) { - if (collection instanceof SortedSet) { - return Collections.unmodifiableSortedSet((SortedSet) collection); - } else if (collection instanceof Set) { - return Collections.unmodifiableSet((Set) collection); - } else if (collection instanceof List) { - return Collections.unmodifiableList((List) collection); - } - return Collections.unmodifiableCollection(collection); - } - - /** - * Returns an unmodifiable view of the specified multimap {@code asMap} entry. - * The {@link Entry#setValue} operation throws an {@link - * UnsupportedOperationException}, and the collection returned by {@code - * getValue} is also an unmodifiable (type-preserving) view. This also has the - * side-effect of redefining equals to comply with the Map.Entry contract, and - * to avoid a possible nefarious implementation of equals. - * - * @param entry the entry for which to return an unmodifiable view - * @return an unmodifiable view of the entry - */ - private static Map.Entry> unmodifiableAsMapEntry( - final Map.Entry> entry) { - checkNotNull(entry); - return new AbstractMapEntry>() { - @Override public K getKey() { - return entry.getKey(); - } - - @Override public Collection getValue() { - return unmodifiableValueCollection(entry.getValue()); - } - }; - } - - /** - * Returns an unmodifiable view of the specified collection of entries. The - * {@link Entry#setValue} operation throws an {@link - * UnsupportedOperationException}. If the specified collection is a {@code - * Set}, the returned collection is also a {@code Set}. - * - * @param entries the entries for which to return an unmodifiable view - * @return an unmodifiable view of the entries - */ - private static Collection> unmodifiableEntries( - Collection> entries) { - if (entries instanceof Set) { - return Maps.unmodifiableEntrySet((Set>) entries); - } - return new Maps.UnmodifiableEntries( - Collections.unmodifiableCollection(entries)); - } - - /** - * Returns an unmodifiable view of the specified set of {@code asMap} entries. - * The {@link Entry#setValue} operation throws an {@link - * UnsupportedOperationException}, as do any operations that attempt to modify - * the returned collection. - * - * @param asMapEntries the {@code asMap} entries for which to return an - * unmodifiable view - * @return an unmodifiable view of the collection entries - */ - private static Set>> unmodifiableAsMapEntries( - Set>> asMapEntries) { - return new UnmodifiableAsMapEntries( - Collections.unmodifiableSet(asMapEntries)); - } - - /** @see Multimaps#unmodifiableAsMapEntries */ - static class UnmodifiableAsMapEntries - extends ForwardingSet>> { - private final Set>> delegate; - UnmodifiableAsMapEntries(Set>> delegate) { - this.delegate = delegate; - } - - @Override protected Set>> delegate() { - return delegate; - } - - @Override public Iterator>> iterator() { - final Iterator>> iterator = delegate.iterator(); - return new ForwardingIterator>>() { - @Override protected Iterator>> delegate() { - return iterator; - } - @Override public Entry> next() { - return unmodifiableAsMapEntry(iterator.next()); - } - }; - } - - @Override public Object[] toArray() { - return ObjectArrays.toArrayImpl(this); - } - - @Override public T[] toArray(T[] array) { - return ObjectArrays.toArrayImpl(this, array); - } - - @Override public boolean contains(Object o) { - return Maps.containsEntryImpl(delegate(), o); - } - - @Override public boolean containsAll(Collection c) { - return Collections2.containsAll(this, c); - } - - @Override public boolean equals(@Nullable Object object) { - return Collections2.setEquals(this, object); - } - } - - /** - * Returns a multimap view of the specified map. The multimap is backed by the - * map, so changes to the map are reflected in the multimap, and vice versa. - * If the map is modified while an iteration over one of the multimap's - * collection views is in progress (except through the iterator's own {@code - * remove} operation, or through the {@code setValue} operation on a map entry - * returned by the iterator), the results of the iteration are undefined. - * - *

The multimap supports mapping removal, which removes the corresponding - * mapping from the map. It does not support any operations which might add - * mappings, such as {@code put}, {@code putAll} or {@code replaceValues}. - * - *

The returned multimap will be serializable if the specified map is - * serializable. - * - * @param map the backing map for the returned multimap view - */ - public static SetMultimap forMap(Map map) { - return new MapMultimap(map); - } - - /** @see Multimaps#forMap */ - private static class MapMultimap - implements SetMultimap, Serializable { - final Map map; - transient Map> asMap; - - MapMultimap(Map map) { - this.map = checkNotNull(map); - } - - public int size() { - return map.size(); - } - - public boolean isEmpty() { - return map.isEmpty(); - } - - public boolean containsKey(Object key) { - return map.containsKey(key); - } - - public boolean containsValue(Object value) { - return map.containsValue(value); - } - - public boolean containsEntry(Object key, Object value) { - return map.entrySet().contains(Maps.immutableEntry(key, value)); - } - - public Set get(final K key) { - return new AbstractSet() { - @Override public Iterator iterator() { - return new Iterator() { - int i; - - public boolean hasNext() { - return (i == 0) && map.containsKey(key); - } - - public V next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - i++; - return map.get(key); - } - - public void remove() { - checkState(i == 1); - i = -1; - map.remove(key); - } - }; - } - - @Override public int size() { - return map.containsKey(key) ? 1 : 0; - } - }; - } - - public boolean put(K key, V value) { - throw new UnsupportedOperationException(); - } - - public boolean putAll(K key, Iterable values) { - throw new UnsupportedOperationException(); - } - - public boolean putAll(Multimap multimap) { - throw new UnsupportedOperationException(); - } - - public Set replaceValues(K key, Iterable values) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object key, Object value) { - return map.entrySet().remove(Maps.immutableEntry(key, value)); - } - - public Set removeAll(Object key) { - Set values = new HashSet(2); - if (!map.containsKey(key)) { - return values; - } - values.add(map.remove(key)); - return values; - } - - public void clear() { - map.clear(); - } - - public Set keySet() { - return map.keySet(); - } - - public Multiset keys() { - return Multisets.forSet(map.keySet()); - } - - public Collection values() { - return map.values(); - } - - public Set> entries() { - return map.entrySet(); - } - - public Map> asMap() { - Map> result = asMap; - if (result == null) { - asMap = result = new AsMap(); - } - return result; - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof Multimap) { - Multimap that = (Multimap) object; - return this.size() == that.size() && asMap().equals(that.asMap()); - } - return false; - } - - @Override public int hashCode() { - return map.hashCode(); - } - - private static final MapJoiner joiner - = Joiner.on("], ").withKeyValueSeparator("=[").useForNull("null"); - - @Override public String toString() { - if (map.isEmpty()) { - return "{}"; - } - StringBuilder builder = new StringBuilder(map.size() * 16).append('{'); - joiner.appendTo(builder, map); - return builder.append("]}").toString(); - } - - /** @see MapMultimap#asMap */ - class AsMapEntries extends AbstractSet>> { - @Override public int size() { - return map.size(); - } - - @Override public Iterator>> iterator() { - return new Iterator>>() { - final Iterator keys = map.keySet().iterator(); - - public boolean hasNext() { - return keys.hasNext(); - } - public Entry> next() { - final K key = keys.next(); - return new AbstractMapEntry>() { - @Override public K getKey() { - return key; - } - @Override public Collection getValue() { - return get(key); - } - }; - } - public void remove() { - keys.remove(); - } - }; - } - - @Override public boolean contains(Object o) { - if (!(o instanceof Entry)) { - return false; - } - Entry entry = (Entry) o; - if (!(entry.getValue() instanceof Set)) { - return false; - } - Set set = (Set) entry.getValue(); - return (set.size() == 1) - && containsEntry(entry.getKey(), set.iterator().next()); - } - - @Override public boolean remove(Object o) { - if (!(o instanceof Entry)) { - return false; - } - Entry entry = (Entry) o; - if (!(entry.getValue() instanceof Set)) { - return false; - } - Set set = (Set) entry.getValue(); - return (set.size() == 1) - && map.entrySet().remove( - Maps.immutableEntry(entry.getKey(), set.iterator().next())); - } - } - - /** @see MapMultimap#asMap */ - class AsMap extends Maps.ImprovedAbstractMap> { - @Override protected Set>> createEntrySet() { - return new AsMapEntries(); - } - - // The following methods are included for performance. - - @Override public boolean containsKey(Object key) { - return map.containsKey(key); - } - - @SuppressWarnings("unchecked") - @Override public Collection get(Object key) { - Collection collection = MapMultimap.this.get((K) key); - return collection.isEmpty() ? null : collection; - } - - @Override public Collection remove(Object key) { - Collection collection = removeAll(key); - return collection.isEmpty() ? null : collection; - } - } - private static final long serialVersionUID = 7845222491160860175L; - } - - /** - * Creates an index {@code ImmutableMultimap} that contains the results of - * applying a specified function to each item in an {@code Iterable} of - * values. Each value will be stored as a value in the resulting multimap, - * yielding a multimap with the same size as the input iterable. The key used - * to store that value in the multimap will be the result of calling the - * function on that value. The resulting multimap is created as an immutable - * snapshot, it does not reflect subsequent changes on the input - * iterable. - * - *

For example,

  {@code
-   *
-   *  List badGuys
-   *      = Arrays.asList("Inky", "Blinky", "Pinky", "Pinky", "Clyde");
-   *  Function stringLengthFunction = ...;
-   *  Multimap index
-   *      = Multimaps.index(badGuys, stringLengthFunction);
-   *  System.out.println(index);}
- * - * prints
  {@code
-   *
-   *  {4=[Inky], 5=[Pinky, Pinky, Clyde], 6=[Blinky]}}
- * - *

The returned multimap is serializable if its keys and values are all - * serializable. - * - * @param values the values to use when constructing the {@code - * ImmutableMultimap} - * @param keyFunction the function used to produce the key for each value - * @return {@code ImmutableMultimap} mapping the result of evaluating the - * function {@code keyFunction} on each value in the input collection to - * that value - * @throws NullPointerException if any of the following cases is true:

    - *
  • {@code values} is null - *
  • {@code keyFunction} is null - *
  • An element in {@code values} is null - *
  • {@code keyFunction} returns null for any element of {@code values} - *
- */ - public static ImmutableListMultimap index( - Iterable values, Function keyFunction) { - checkNotNull(keyFunction); - ImmutableListMultimap.Builder builder - = ImmutableListMultimap.builder(); - for (V value : values) { - Preconditions.checkNotNull(value, values); - builder.put(keyFunction.apply(value), value); - } - return builder.build(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multiset.java deleted file mode 100644 index 678addec1ba..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multiset.java +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.*; - -/** - * A collection that supports order-independent equality, like {@link Set}, but - * may have duplicate elements. A multiset is also sometimes called a - * bag. - * - *

Elements of a multiset that are equal to one another (see "Note on - * element equivalence", below) are referred to as occurrences of the - * same single element. The total number of occurrences of an element in a - * multiset is called the count of that element (the terms "frequency" - * and "multiplicity" are equivalent, but not used in this API). Since the count - * of an element is represented as an {@code int}, a multiset may never contain - * more than {@link Integer#MAX_VALUE} occurrences of any one element. - * - *

{@code Multiset} refines the specifications of several methods from - * {@code Collection}. It also defines an additional query operation, {@link - * #count}, which returns the count of an element. There are five new - * bulk-modification operations, for example {@link #add(Object, int)}, to add - * or remove multiple occurrences of an element at once, or to set the count of - * an element to a specific value. These modification operations are optional, - * but implementations which support the standard collection operations {@link - * #add(Object)} or {@link #remove(Object)} are encouraged to implement the - * related methods as well. Finally, two collection views are provided: {@link - * #elementSet} contains the distinct elements of the multiset "with duplicates - * collapsed", and {@link #entrySet} is similar but contains {@link Entry - * Multiset.Entry} instances, each providing both a distinct element and the - * count of that element. - * - *

In addition to these required methods, implementations of {@code - * Multiset} are expected to provide two {@code static} creation methods: - * {@code create()}, returning an empty multiset, and {@code - * create(Iterable)}, returning a multiset containing the - * given initial elements. This is simply a refinement of {@code Collection}'s - * constructor recommendations, reflecting the new developments of Java 5. - * - *

As with other collection types, the modification operations are optional, - * and should throw {@link UnsupportedOperationException} when they are not - * implemented. Most implementations should support either all add operations - * or none of them, all removal operations or none of them, and if and only if - * all of these are supported, the {@code setCount} methods as well. - * - *

A multiset uses {@link Object#equals} to determine whether two instances - * should be considered "the same," unless specified otherwise by the - * implementation. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -public interface Multiset extends Collection { - // Query Operations - - /** - * Returns the number of occurrences of an element in this multiset (the - * count of the element). Note that for an {@link Object#equals}-based - * multiset, this gives the same result as {@link Collections#frequency} - * (which would presumably perform more poorly). - * - *

Note: the utility method {@link Iterables#frequency} generalizes - * this operation; it correctly delegates to this method when dealing with a - * multiset, but it can also accept any other iterable type. - * - * @param element the element to count occurrences of - * @return the number of occurrences of the element in this multiset; possibly - * zero but never negative - */ - int count(@Nullable Object element); - - // Bulk Operations - - /** - * Adds a number of occurrences of an element to this multiset. Note that if - * {@code occurrences == 1}, this method has the identical effect to {@link - * #add(Object)}. This method is functionally equivalent (except in the case - * of overflow) to the call {@code addAll(Collections.nCopies(element, - * occurrences))}, which would presumably perform much more poorly. - * - * @param element the element to add occurrences of; may be {@code null} only - * if explicitly allowed by the implementation - * @param occurrences the number of occurrences of the element to add. May be - * zero, in which case no change will be made. - * @return the count of the element before the operation; possibly zero - * @throws IllegalArgumentException if {@code occurrences} is negative, or if - * this operation would result in more than {@link Integer#MAX_VALUE} - * occurrences of the element - * @throws NullPointerException if {@code element} is null and this - * implementation does not permit null elements. Note that if {@code - * occurrences} is zero, the implementation may opt to return normally. - */ - int add(@Nullable E element, int occurrences); - - /** - * Removes a number of occurrences of the specified element from this - * multiset. If the multiset contains fewer than this number of occurrences to - * begin with, all occurrences will be removed. Note that if - * {@code occurrences == 1}, this is functionally equivalent to the call - * {@code remove(element)}. - * - * @param element the element to conditionally remove occurrences of - * @param occurrences the number of occurrences of the element to remove. May - * be zero, in which case no change will be made. - * @return the count of the element before the operation; possibly zero - * @throws IllegalArgumentException if {@code occurrences} is negative - */ - int remove(@Nullable Object element, int occurrences); - - /** - * Adds or removes the necessary occurrences of an element such that the - * element attains the desired count. - * - * @param element the element to add or remove occurrences of; may be null - * only if explicitly allowed by the implementation - * @param count the desired count of the element in this multiset - * @return the count of the element before the operation; possibly zero - * @throws IllegalArgumentException if {@code count} is negative - * @throws NullPointerException if {@code element} is null and this - * implementation does not permit null elements. Note that if {@code - * count} is zero, the implementor may optionally return zero instead. - */ - int setCount(E element, int count); - - /** - * Conditionally sets the count of an element to a new value, as described in - * {@link #setCount(Object, int)}, provided that the element has the expected - * current count. If the current count is not {@code oldCount}, no change is - * made. - * - * @param element the element to conditionally set the count of; may be null - * only if explicitly allowed by the implementation - * @param oldCount the expected present count of the element in this multiset - * @param newCount the desired count of the element in this multiset - * @return {@code true} if the condition for modification was met. This - * implies that the multiset was indeed modified, unless - * {@code oldCount == newCount}. - * @throws IllegalArgumentException if {@code oldCount} or {@code newCount} is - * negative - * @throws NullPointerException if {@code element} is null and the - * implementation does not permit null elements. Note that if {@code - * oldCount} and {@code newCount} are both zero, the implementor may - * optionally return {@code true} instead. - */ - boolean setCount(E element, int oldCount, int newCount); - - // Views - - /** - * Returns the set of distinct elements contained in this multiset. The - * element set is backed by the same data as the multiset, so any change to - * either is immediately reflected in the other. The order of the elements in - * the element set is unspecified. - * - *

If the element set supports any removal operations, these necessarily - * cause all occurrences of the removed element(s) to be removed from - * the multiset. Implementations are not expected to support the add - * operations, although this is possible. - * - *

A common use for the element set is to find the number of distinct - * elements in the multiset: {@code elementSet().size()}. - * - * @return a view of the set of distinct elements in this multiset - */ - Set elementSet(); - - /** - * Returns a view of the contents of this multiset, grouped into {@code - * Multiset.Entry} instances, each providing an element of the multiset and - * the count of that element. This set contains exactly one entry for each - * distinct element in the multiset (thus it always has the same size as the - * {@link #elementSet}). The order of the elements in the element set is - * unspecified. - * - *

The entry set is backed by the same data as the multiset, so any change - * to either is immediately reflected in the other. However, multiset changes - * may or may not be reflected in any {@code Entry} instances already - * retrieved from the entry set (this is implementation-dependent). - * Furthermore, implementations are not required to support modifications to - * the entry set at all, and the {@code Entry} instances themselves don't - * even have methods for modification. See the specific implementation class - * for more details on how its entry set handles modifications. - * - * @return a set of entries representing the data of this multiset - */ - Set> entrySet(); - - /** - * An unmodifiable element-count pair for a multiset. The {@link - * Multiset#entrySet} method returns a view of the multiset whose elements - * are of this class. A multiset implementation may return Entry instances - * that are either live "read-through" views to the Multiset, or immutable - * snapshots. Note that this type is unrelated to the similarly-named type - * {@code Map.Entry}. - */ - interface Entry { - - /** - * Returns the multiset element corresponding to this entry. Multiple calls - * to this method always return the same instance. - * - * @return the element corresponding to this entry - */ - E getElement(); - - /** - * Returns the count of the associated element in the underlying multiset. - * This count may either be an unchanging snapshot of the count at the time - * the entry was retrieved, or a live view of the current count of the - * element in the multiset, depending on the implementation. Note that in - * the former case, this method can never return zero, while in the latter, - * it will return zero if all occurrences of the element were since removed - * from the multiset. - * - * @return the count of the element; never negative - */ - int getCount(); - - /** - * {@inheritDoc} - * - *

Returns {@code true} if the given object is also a multiset entry and - * the two entries represent the same element and count. More formally, two - * entries {@code a} and {@code b} are equal if: - * - *

  ((a.getElement() == null)
-     *      ? (b.getElement() == null) : a.getElement().equals(b.getElement()))
-     *    && (a.getCount() == b.getCount())
- */ - // TODO: check this wrt TreeMultiset? - boolean equals(Object o); - - /** - * {@inheritDoc} - * - *

The hash code of a multiset entry for element {@code element} and - * count {@code count} is defined as: - * - *

  (element == null ? 0 : element.hashCode()) ^ count
- */ - int hashCode(); - - /** - * Returns the canonical string representation of this entry, defined as - * follows. If the count for this entry is one, this is simply the string - * representation of the corresponding element. Otherwise, it is the string - * representation of the element, followed by the three characters {@code - * " x "} (space, letter x, space), followed by the count. - */ - String toString(); - } - - // Comparison and hashing - - /** - * Compares the specified object with this multiset for equality. Returns - * {@code true} if the given object is also a multiset and contains equal - * elements with equal counts, regardless of order. - */ - // TODO: caveats about equivalence-relation? - boolean equals(@Nullable Object object); - - /** - * Returns the hash code for this multiset. This is defined as the sum of - * - *
  (element == null ? 0 : element.hashCode()) ^ count(element)
- * - * over all distinct elements in the multiset. It follows that a multiset and - * its entry set always have the same hash code. - */ - int hashCode(); - - /** - * {@inheritDoc} - * - *

It is recommended, though not mandatory, that this method return the - * result of invoking {@link #toString} on the {@link #entrySet}, yielding a - * result such as - *

-   *     [a x 3, c, d x 2, e]
-   * 
- */ - String toString(); - - // Refined Collection Methods - - /** - * {@inheritDoc} - * - *

Elements that occur multiple times in the multiset will appear - * multiple times in this iterator, though not necessarily sequentially. - */ - Iterator iterator(); - - /** - * Determines whether this multiset contains the specified element. - * - *

This method refines {@link Collection#contains} to further specify that - * it may not throw an exception in response to {@code element} being - * null or of the wrong type. - * - * @param element the element to check for - * @return {@code true} if this multiset contains at least one occurrence of - * the element - */ - boolean contains(@Nullable Object element); - - /** - * Returns {@code true} if this multiset contains at least one occurrence of - * each element in the specified collection. - * - *

This method refines {@link Collection#containsAll} to further specify - * that it may not throw an exception in response to any of {@code - * elements} being null or of the wrong type. - * - *

Note: this method does not take into account the occurrence - * count of an element in the two collections; it may still return {@code - * true} even if {@code elements} contains several occurrences of an element - * and this multiset contains only one. This is no different than any other - * collection type like {@link List}, but it may be unexpected to the user of - * a multiset. - * - * @param elements the collection of elements to be checked for containment in - * this multiset - * @return {@code true} if this multiset contains at least one occurrence of - * each element contained in {@code elements} - * @throws NullPointerException if {@code elements} is null - */ - boolean containsAll(Collection elements); - - /** - * Adds a single occurrence of the specified element to this multiset. - * - *

This method refines {@link Collection#add}, which only ensures - * the presence of the element, to further specify that a successful call must - * always increment the count of the element, and the overall size of the - * collection, by one. - * - * @param element the element to add one occurrence of; may be null only if - * explicitly allowed by the implementation - * @return {@code true} always, since this call is required to modify the - * multiset, unlike other {@link Collection} types - * @throws NullPointerException if {@code element} is null and this - * implementation does not permit null elements - * @throws IllegalArgumentException if {@link Integer#MAX_VALUE} occurrences - * of {@code element} are already contained in this multiset - */ - boolean add(E element); - - /** - * Removes a single occurrence of the specified element from this - * multiset, if present. - * - *

This method refines {@link Collection#remove} to further specify that it - * may not throw an exception in response to {@code element} being null - * or of the wrong type. - * - * @param element the element to remove one occurrence of - * @return {@code true} if an occurrence was found and removed - */ - boolean remove(@Nullable Object element); - - /** - * {@inheritDoc} - * - *

This method refines {@link Collection#removeAll} to further specify that - * it may not throw an exception in response to any of {@code elements} - * being null or of the wrong type. - */ - boolean removeAll(Collection c); - - /** - * {@inheritDoc} - * - *

This method refines {@link Collection#retainAll} to further specify that - * it may not throw an exception in response to any of {@code elements} - * being null or of the wrong type. - */ - boolean retainAll(Collection c); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multisets.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multisets.java deleted file mode 100644 index 11c2ed5e15b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Multisets.java +++ /dev/null @@ -1,392 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Objects; - -import javax.annotation.Nullable; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Provides static utility methods for creating and working with {@link - * Multiset} instances. - * - * @author Kevin Bourrillion - * @author Mike Bostock - */ -@GwtCompatible -public final class Multisets { - private Multisets() {} - - /** - * Returns an unmodifiable view of the specified multiset. Query operations on - * the returned multiset "read through" to the specified multiset, and - * attempts to modify the returned multiset result in an - * {@link UnsupportedOperationException}. - * - *

The returned multiset will be serializable if the specified multiset is - * serializable. - * - * @param multiset the multiset for which an unmodifiable view is to be - * generated - * @return an unmodifiable view of the multiset - */ - public static Multiset unmodifiableMultiset( - Multiset multiset) { - return new UnmodifiableMultiset(multiset); - } - - private static class UnmodifiableMultiset - extends ForwardingMultiset implements Serializable { - final Multiset delegate; - - UnmodifiableMultiset(Multiset delegate) { - this.delegate = delegate; - } - - @SuppressWarnings("unchecked") - @Override protected Multiset delegate() { - // This is safe because all non-covariant methods are overriden - return (Multiset) delegate; - } - - transient Set elementSet; - - @Override public Set elementSet() { - Set es = elementSet; - return (es == null) - ? elementSet = Collections.unmodifiableSet(delegate.elementSet()) - : es; - } - - transient Set> entrySet; - - @SuppressWarnings("unchecked") - @Override public Set> entrySet() { - Set> es = entrySet; - return (es == null) - // Safe because the returned set is made unmodifiable and Entry - // itself is readonly - ? entrySet = (Set) Collections.unmodifiableSet(delegate.entrySet()) - : es; - } - - @SuppressWarnings("unchecked") - @Override public Iterator iterator() { - // Safe because the returned Iterator is made unmodifiable - return (Iterator) Iterators.unmodifiableIterator(delegate.iterator()); - } - - @Override public boolean add(E element) { - throw new UnsupportedOperationException(); - } - - @Override public int add(E element, int occurences) { - throw new UnsupportedOperationException(); - } - - @Override public boolean addAll(Collection elementsToAdd) { - throw new UnsupportedOperationException(); - } - - @Override public boolean remove(Object element) { - throw new UnsupportedOperationException(); - } - - @Override public int remove(Object element, int occurrences) { - throw new UnsupportedOperationException(); - } - - @Override public boolean removeAll(Collection elementsToRemove) { - throw new UnsupportedOperationException(); - } - - @Override public boolean retainAll(Collection elementsToRetain) { - throw new UnsupportedOperationException(); - } - - @Override public void clear() { - throw new UnsupportedOperationException(); - } - - @Override public int setCount(E element, int count) { - throw new UnsupportedOperationException(); - } - - @Override public boolean setCount(E element, int oldCount, int newCount) { - throw new UnsupportedOperationException(); - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns an immutable multiset entry with the specified element and count. - * - * @param e the element to be associated with the returned entry - * @param n the count to be associated with the returned entry - * @throws IllegalArgumentException if {@code n} is negative - */ - public static Multiset.Entry immutableEntry( - @Nullable final E e, final int n) { - checkArgument(n >= 0); - return new AbstractEntry() { - public E getElement() { - return e; - } - public int getCount() { - return n; - } - }; - } - - /** - * Returns a multiset view of the specified set. The multiset is backed by the - * set, so changes to the set are reflected in the multiset, and vice versa. - * If the set is modified while an iteration over the multiset is in progress - * (except through the iterator's own {@code remove} operation) the results of - * the iteration are undefined. - * - *

The multiset supports element removal, which removes the corresponding - * element from the set. It does not support the {@code add} or {@code addAll} - * operations, nor does it support the use of {@code setCount} to add - * elements. - * - *

The returned multiset will be serializable if the specified set is - * serializable. The multiset is threadsafe if the set is threadsafe. - * - * @param set the backing set for the returned multiset view - */ - static Multiset forSet(Set set) { - return new SetMultiset(set); - } - - /** @see Multisets#forSet */ - private static class SetMultiset extends ForwardingCollection - implements Multiset, Serializable { - final Set delegate; - - SetMultiset(Set set) { - delegate = checkNotNull(set); - } - - @Override protected Set delegate() { - return delegate; - } - - public int count(Object element) { - return delegate.contains(element) ? 1 : 0; - } - - public int add(E element, int occurrences) { - throw new UnsupportedOperationException(); - } - - public int remove(Object element, int occurrences) { - if (occurrences == 0) { - return count(element); - } - checkArgument(occurrences > 0); - return delegate.remove(element) ? 1 : 0; - } - - transient Set elementSet; - - public Set elementSet() { - Set es = elementSet; - return (es == null) ? elementSet = new ElementSet() : es; - } - - transient Set> entrySet; - - public Set> entrySet() { - Set> es = entrySet; - return (es == null) ? entrySet = new EntrySet() : es; - } - - @Override public boolean add(E o) { - throw new UnsupportedOperationException(); - } - - @Override public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public int setCount(E element, int count) { - checkNonnegative(count, "count"); - - if (count == count(element)) { - return count; - } else if (count == 0) { - remove(element); - return 1; - } else { - throw new UnsupportedOperationException(); - } - } - - public boolean setCount(E element, int oldCount, int newCount) { - return setCountImpl(this, element, oldCount, newCount); - } - - @Override public boolean equals(@Nullable Object object) { - if (object instanceof Multiset) { - Multiset that = (Multiset) object; - return this.size() == that.size() && delegate.equals(that.elementSet()); - } - return false; - } - - @Override public int hashCode() { - int sum = 0; - for (E e : this) { - sum += ((e == null) ? 0 : e.hashCode()) ^ 1; - } - return sum; - } - - /** @see SetMultiset#elementSet */ - class ElementSet extends ForwardingSet { - @Override protected Set delegate() { - return delegate; - } - - @Override public boolean add(E o) { - throw new UnsupportedOperationException(); - } - - @Override public boolean addAll(Collection c) { - throw new UnsupportedOperationException(); - } - } - - /** @see SetMultiset#entrySet */ - class EntrySet extends AbstractSet> { - @Override public int size() { - return delegate.size(); - } - @Override public Iterator> iterator() { - return new Iterator>() { - final Iterator elements = delegate.iterator(); - - public boolean hasNext() { - return elements.hasNext(); - } - public Entry next() { - return immutableEntry(elements.next(), 1); - } - public void remove() { - elements.remove(); - } - }; - } - // TODO: faster contains, remove - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns the expected number of distinct elements given the specified - * elements. The number of distinct elements is only computed if {@code - * elements} is an instance of {@code Multiset}; otherwise the default value - * of 11 is returned. - */ - static int inferDistinctElements(Iterable elements) { - if (elements instanceof Multiset) { - return ((Multiset) elements).elementSet().size(); - } - return 11; // initial capacity will be rounded up to 16 - } - - /** - * Implementation of the {@code equals}, {@code hashCode}, and - * {@code toString} methods of {@link Multiset.Entry}. - */ - abstract static class AbstractEntry implements Multiset.Entry { - /** - * Indicates whether an object equals this entry, following the behavior - * specified in {@link Multiset.Entry#equals}. - */ - @Override public boolean equals(@Nullable Object object) { - if (object instanceof Multiset.Entry) { - Multiset.Entry that = (Multiset.Entry) object; - return this.getCount() == that.getCount() - && Objects.equal(this.getElement(), that.getElement()); - } - return false; - } - - /** - * Return this entry's hash code, following the behavior specified in - * {@link Multiset.Entry#hashCode}. - */ - @Override public int hashCode() { - E e = getElement(); - return ((e == null) ? 0 : e.hashCode()) ^ getCount(); - } - - /** - * Returns a string representation of this multiset entry. The string - * representation consists of the associated element if the associated count - * is one, and otherwise the associated element followed by the characters - * " x " (space, x and space) followed by the count. Elements and counts are - * converted to strings as by {@code String.valueOf}. - */ - @Override public String toString() { - String text = String.valueOf(getElement()); - int n = getCount(); - return (n == 1) ? text : (text + " x " + n); - } - } - - static int setCountImpl(Multiset self, E element, int count) { - checkNonnegative(count, "count"); - - int oldCount = self.count(element); - - int delta = count - oldCount; - if (delta > 0) { - self.add(element, delta); - } else if (delta < 0) { - self.remove(element, -delta); - } - - return oldCount; - } - - static boolean setCountImpl( - Multiset self, E element, int oldCount, int newCount) { - checkNonnegative(oldCount, "oldCount"); - checkNonnegative(newCount, "newCount"); - - if (self.count(element) == oldCount) { - self.setCount(element, newCount); - return true; - } else { - return false; - } - } - - static void checkNonnegative(int count, String name) { - checkArgument(count >= 0, "%s cannot be negative: %s", name, count); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MutableClassToInstanceMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MutableClassToInstanceMap.java deleted file mode 100644 index a2e447ce7dc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/MutableClassToInstanceMap.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import java.util.HashMap; -import java.util.Map; - -/** - * A mutable class-to-instance map backed by an arbitrary user-provided map. - * See also {@link ImmutableClassToInstanceMap}. - * - * @author Kevin Bourrillion - */ -public final class MutableClassToInstanceMap - extends ConstrainedMap, B> - implements ClassToInstanceMap { - - /** - * Returns a new {@code MutableClassToInstanceMap} instance backed by a {@link - * HashMap} using the default initial capacity and load factor. - */ - public static MutableClassToInstanceMap create() { - return new MutableClassToInstanceMap( - new HashMap, B>()); - } - - /** - * Returns a new {@code MutableClassToInstanceMap} instance backed by a given - * empty {@code backingMap}. The caller surrenders control of the backing map, - * and thus should not allow any direct references to it to remain accessible. - */ - public static MutableClassToInstanceMap create( - Map, B> backingMap) { - return new MutableClassToInstanceMap(backingMap); - } - - private MutableClassToInstanceMap(Map, B> delegate) { - super(delegate, VALUE_CAN_BE_CAST_TO_KEY); - } - - private static final MapConstraint, Object> VALUE_CAN_BE_CAST_TO_KEY - = new MapConstraint, Object>() { - public void checkKeyValue(Class key, Object value) { - cast(key, value); - } - }; - - public T putInstance(Class type, T value) { - return cast(type, put(type, value)); - } - - public T getInstance(Class type) { - return cast(type, get(type)); - } - - // Default access so that ImmutableClassToInstanceMap can share it - static T cast(Class type, B value) { - // TODO: this should eventually use common.primitives.Primitives.wrap() - return wrap(type).cast(value); - } - - // safe because both Long.class and long.class are of type Class - @SuppressWarnings("unchecked") - private static Class wrap(Class c) { - return c.isPrimitive() ? (Class) PRIMITIVES_TO_WRAPPERS.get(c) : c; - } - - private static final Map, Class> PRIMITIVES_TO_WRAPPERS - = new ImmutableMap.Builder, Class>() - .put(boolean.class, Boolean.class) - .put(byte.class, Byte.class) - .put(char.class, Character.class) - .put(double.class, Double.class) - .put(float.class, Float.class) - .put(int.class, Integer.class) - .put(long.class, Long.class) - .put(short.class, Short.class) - .put(void.class, Void.class) - .build(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NaturalOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NaturalOrdering.java deleted file mode 100644 index 50e4c5c5100..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NaturalOrdering.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.Serializable; -import java.util.Collections; -import java.util.List; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** An ordering that uses the natural order of the values. */ -@GwtCompatible(serializable = true) -@SuppressWarnings("unchecked") // TODO: the right way to explain this?? -final class NaturalOrdering - extends Ordering implements Serializable { - static final NaturalOrdering INSTANCE = new NaturalOrdering(); - - public int compare(Comparable left, Comparable right) { - checkNotNull(right); // left null is caught later - if (left == right) { - return 0; - } - - @SuppressWarnings("unchecked") // we're permitted to throw CCE - int result = left.compareTo(right); - return result; - } - - @SuppressWarnings("unchecked") // TODO: the right way to explain this?? - @Override public Ordering reverse() { - return (Ordering) ReverseNaturalOrdering.INSTANCE; - } - - // Override to remove a level of indirection from inner loop - @SuppressWarnings("unchecked") // TODO: the right way to explain this?? - @Override public int binarySearch( - List sortedList, Comparable key) { - return Collections.binarySearch((List) sortedList, key); - } - - // Override to remove a level of indirection from inner loop - @Override public List sortedCopy( - Iterable iterable) { - List list = Lists.newArrayList(iterable); - Collections.sort(list); - return list; - } - - // preserving singleton-ness gives equals()/hashCode() for free - private Object readResolve() { - return INSTANCE; - } - - @Override public String toString() { - return "Ordering.natural()"; - } - - private NaturalOrdering() {} - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullOutputException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullOutputException.java deleted file mode 100644 index f5e4bd01518..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullOutputException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -/** - * Thrown when a computer function returns null. This subclass exists so - * that our ReferenceCache adapter can differentiate null output from null - * keys, but we don't want to make this public otherwise. - * - * @author Bob Lee - */ -class NullOutputException extends NullPointerException { - public NullOutputException(String s) { - super(s); - } - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullsFirstOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullsFirstOrdering.java deleted file mode 100644 index 4320b22b7a2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullsFirstOrdering.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; - -/** An ordering that treats {@code null} as less than all other values. */ -@GwtCompatible(serializable = true) -final class NullsFirstOrdering extends Ordering implements Serializable { - final Ordering ordering; - - NullsFirstOrdering(Ordering ordering) { - this.ordering = ordering; - } - - public int compare(T left, T right) { - if (left == right) { - return 0; - } - if (left == null) { - return RIGHT_IS_GREATER; - } - if (right == null) { - return LEFT_IS_GREATER; - } - return ordering.compare(left, right); - } - - @Override public Ordering reverse() { - // ordering.reverse() might be optimized, so let it do its thing - return ordering.reverse().nullsLast(); - } - - @SuppressWarnings("unchecked") // still need the right way to explain this - @Override public Ordering nullsFirst() { - return (Ordering) this; - } - - @Override public Ordering nullsLast() { - return ordering.nullsLast(); - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof NullsFirstOrdering) { - NullsFirstOrdering that = (NullsFirstOrdering) object; - return this.ordering.equals(that.ordering); - } - return false; - } - - @Override public int hashCode() { - return ordering.hashCode() ^ 957692532; // meaningless - } - - @Override public String toString() { - return ordering + ".nullsFirst()"; - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullsLastOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullsLastOrdering.java deleted file mode 100644 index 6d4503e0f6b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/NullsLastOrdering.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; - -/** An ordering that treats {@code null} as greater than all other values. */ -@GwtCompatible(serializable = true) -final class NullsLastOrdering extends Ordering implements Serializable { - final Ordering ordering; - - NullsLastOrdering(Ordering ordering) { - this.ordering = ordering; - } - - public int compare(T left, T right) { - if (left == right) { - return 0; - } - if (left == null) { - return LEFT_IS_GREATER; - } - if (right == null) { - return RIGHT_IS_GREATER; - } - return ordering.compare(left, right); - } - - @Override public Ordering reverse() { - // ordering.reverse() might be optimized, so let it do its thing - return ordering.reverse().nullsFirst(); - } - - @Override public Ordering nullsFirst() { - return ordering.nullsFirst(); - } - - @SuppressWarnings("unchecked") // still need the right way to explain this - @Override public Ordering nullsLast() { - return (Ordering) this; - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof NullsLastOrdering) { - NullsLastOrdering that = (NullsLastOrdering) object; - return this.ordering.equals(that.ordering); - } - return false; - } - - @Override public int hashCode() { - return ordering.hashCode() ^ -921210296; // meaningless - } - - @Override public String toString() { - return ordering + ".nullsLast()"; - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ObjectArrays.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ObjectArrays.java deleted file mode 100644 index b9a4a13d581..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ObjectArrays.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; - -import javax.annotation.Nullable; -import java.util.Collection; - -/** - * Static utility methods pertaining to object arrays. - * - * @author Kevin Bourrillion - */ -@GwtCompatible -public final class ObjectArrays { - private ObjectArrays() {} - - /** - * Returns a new array of the given length with the specified component type. - * - * @param type the component type - * @param length the length of the new array - */ - @GwtIncompatible("Array.newInstance(Class, int)") - @SuppressWarnings("unchecked") - public static T[] newArray(Class type, int length) { - return Platform.newArray(type, length); - } - - /** - * Returns a new array of the given length with the same type as a reference - * array. - * - * @param reference any array of the desired type - * @param length the length of the new array - */ - public static T[] newArray(T[] reference, int length) { - return Platform.newArray(reference, length); - } - - /** - * Returns a new array that contains the concatenated contents of two arrays. - * - * @param first the first array of elements to concatenate - * @param second the second array of elements to concatenate - * @param type the component type of the returned array - */ - @GwtIncompatible("Array.newInstance(Class, int)") - public static T[] concat(T[] first, T[] second, Class type) { - T[] result = newArray(type, first.length + second.length); - System.arraycopy(first, 0, result, 0, first.length); - System.arraycopy(second, 0, result, first.length, second.length); - return result; - } - - /** - * Returns a new array that prepends {@code element} to {@code array}. - * - * @param element the element to prepend to the front of {@code array} - * @param array the array of elements to append - * @return an array whose size is one larger than {@code array}, with - * {@code element} occupying the first position, and the - * elements of {@code array} occupying the remaining elements. - */ - public static T[] concat(@Nullable T element, T[] array) { - T[] result = newArray(array, array.length + 1); - result[0] = element; - System.arraycopy(array, 0, result, 1, array.length); - return result; - } - - /** - * Returns a new array that appends {@code element} to {@code array}. - * - * @param array the array of elements to prepend - * @param element the element to append to the end - * @return an array whose size is one larger than {@code array}, with - * the same contents as {@code array}, plus {@code element} occupying the - * last position. - */ - public static T[] concat(T[] array, @Nullable T element) { - T[] result = arraysCopyOf(array, array.length + 1); - result[array.length] = element; - return result; - } - - /** GWT safe version of Arrays.copyOf. */ - private static T[] arraysCopyOf(T[] original, int newLength) { - T[] copy = newArray(original, newLength); - System.arraycopy( - original, 0, copy, 0, Math.min(original.length, newLength)); - return copy; - } - - /** - * Returns an array containing all of the elements in the specified - * collection; the runtime type of the returned array is that of the specified - * array. If the collection fits in the specified array, it is returned - * therein. Otherwise, a new array is allocated with the runtime type of the - * specified array and the size of the specified collection. - * - *

If the collection fits in the specified array with room to spare (i.e., - * the array has more elements than the 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 the collection only if the - * caller knows that the collection does not contain any null elements. - * - *

This method returns the elements in the order they are returned by the - * collection's iterator. - * - *

TODO: Support concurrent collections whose size can change while the - * method is running. - * - * @param c the collection for which to return an array of elements - * @param array the array in which to place the collection elements - * @throws ArrayStoreException if the runtime type of the specified array is - * not a supertype of the runtime type of every element in the specified - * collection - */ - static T[] toArrayImpl(Collection c, T[] array) { - int size = c.size(); - if (array.length < size) { - array = newArray(array, size); - } - fillArray(c, array); - if (array.length > size) { - array[size] = null; - } - return array; - } - - /** - * Returns an array containing all of the elements in the specified - * collection. This method returns the elements in the order they are returned - * by the collection's iterator. The returned array is "safe" in that no - * references to it are maintained by the collection. The caller is thus free - * to modify the returned array. - * - *

This method assumes that the collection size doesn't change while the - * method is running. - * - *

TODO: Support concurrent collections whose size can change while the - * method is running. - * - * @param c the collection for which to return an array of elements - */ - static Object[] toArrayImpl(Collection c) { - return fillArray(c, new Object[c.size()]); - } - - private static Object[] fillArray(Iterable elements, Object[] array) { - int i = 0; - for (Object element : elements) { - array[i++] = element; - } - return array; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Ordering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Ordering.java deleted file mode 100644 index 4838ba602fb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Ordering.java +++ /dev/null @@ -1,470 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.VisibleForTesting; -import org.elasticsearch.util.base.Function; - -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * A comparator with added methods to support common functions. For example: - *

   {@code
- *
- *   if (Ordering.from(comparator).reverse().isOrdered(list)) { ... }}
- * - *

The {@link #from(Comparator)} method returns the equivalent {@code - * Ordering} instance for a pre-existing comparator. You can also skip the - * comparator step and extend {@code Ordering} directly:

   {@code
- *
- *   Ordering byLengthOrdering = new Ordering() {
- *     public int compare(String left, String right) {
- *       return Ints.compare(left.length(), right.length());
- *     }
- *   };}
- * - * Except as noted, the orderings returned by the factory methods of this - * class are serializable if and only if the provided instances that back them - * are. For example, if {@code ordering} and {@code function} can themselves be - * serialized, then {@code ordering.onResultOf(function)} can as well. - * - * @author Jesse Wilson - * @author Kevin Bourrillion - */ -@GwtCompatible -public abstract class Ordering implements Comparator { - // Static factories - - /** - * Returns a serializable ordering that uses the natural order of the values. - * The ordering throws a {@link NullPointerException} when passed a null - * parameter. - * - *

The type specification is {@code }, instead of - * the technically correct {@code >}, to - * support legacy types from before Java 5. - */ - @GwtCompatible(serializable = true) - @SuppressWarnings("unchecked") // TODO: the right way to explain this?? - public static Ordering natural() { - return (Ordering) NaturalOrdering.INSTANCE; - } - - /** - * Returns an ordering for a pre-existing {@code comparator}. Note - * that if the comparator is not pre-existing, and you don't require - * serialization, you can subclass {@code Ordering} and implement its - * {@link #compare(Object, Object) compare} method instead. - * - * @param comparator the comparator that defines the order - */ - @GwtCompatible(serializable = true) - public static Ordering from(Comparator comparator) { - return (comparator instanceof Ordering) - ? (Ordering) comparator - : new ComparatorOrdering(comparator); - } - - /** - * Simply returns its argument. - * - * @deprecated no need to use this - */ - @GwtCompatible(serializable = true) - @Deprecated public static Ordering from(Ordering ordering) { - return checkNotNull(ordering); - } - - /** - * Returns an ordering that compares objects according to the order in - * which they appear in the given list. Only objects present in the list - * (according to {@link Object#equals}) may be compared. This comparator - * imposes a "partial ordering" over the type {@code T}. Subsequent changes - * to the {@code valuesInOrder} list will have no effect on the returned - * comparator. Null values in the list are not supported. - * - *

The returned comparator throws an {@link ClassCastException} when it - * receives an input parameter that isn't among the provided values. - * - *

The generated comparator is serializable if all the provided values are - * serializable. - * - * @param valuesInOrder the values that the returned comparator will be able - * to compare, in the order the comparator should induce - * @return the comparator described above - * @throws NullPointerException if any of the provided values is null - * @throws IllegalArgumentException if {@code valuesInOrder} contains any - * duplicate values (according to {@link Object#equals}) - */ - @GwtCompatible(serializable = true) - public static Ordering explicit(List valuesInOrder) { - return new ExplicitOrdering(valuesInOrder); - } - - /** - * Returns an ordering that compares objects according to the order in - * which they are given to this method. Only objects present in the argument - * list (according to {@link Object#equals}) may be compared. This comparator - * imposes a "partial ordering" over the type {@code T}. Null values in the - * argument list are not supported. - * - *

The returned comparator throws a {@link ClassCastException} when it - * receives an input parameter that isn't among the provided values. - * - *

The generated comparator is serializable if all the provided values are - * serializable. - * - * @param leastValue the value which the returned comparator should consider - * the "least" of all values - * @param remainingValuesInOrder the rest of the values that the returned - * comparator will be able to compare, in the order the comparator should - * follow - * @return the comparator described above - * @throws NullPointerException if any of the provided values is null - * @throws IllegalArgumentException if any duplicate values (according to - * {@link Object#equals(Object)}) are present among the method arguments - */ - @GwtCompatible(serializable = true) - public static Ordering explicit( - T leastValue, T... remainingValuesInOrder) { - return explicit(Lists.asList(leastValue, remainingValuesInOrder)); - } - - /** - * Exception thrown by a {@link Ordering#explicit(List)} or {@link - * Ordering#explicit(Object, Object[])} comparator when comparing a value - * outside the set of values it can compare. Extending {@link - * ClassCastException} may seem odd, but it is required. - */ - // TODO: consider making this exception type public. or consider getting rid - // of it. - @VisibleForTesting - static class IncomparableValueException extends ClassCastException { - final Object value; - - IncomparableValueException(Object value) { - super("Cannot compare value: " + value); - this.value = value; - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns an ordering that compares objects by the natural ordering of their - * string representations as returned by {@code toString()}. It does not - * support null values. - * - *

The comparator is serializable. - */ - @GwtCompatible(serializable = true) - public static Ordering usingToString() { - return UsingToStringOrdering.INSTANCE; - } - - /** - * Returns an ordering which tries each given comparator in order until a - * non-zero result is found, returning that result, and returning zero only if - * all comparators return zero. The returned ordering is based on the state of - * the {@code comparators} iterable at the time it was provided to this - * method. - * - *

The returned ordering is equivalent to that produced using {@code - * Ordering.from(comp1).compound(comp2).compound(comp3) . . .}. - * - *

Warning: Supplying an argument with undefined iteration order, - * such as a {@link HashSet}, will produce non-deterministic results. - * - * @param comparators the comparators to try in order - */ - @GwtCompatible(serializable = true) - public static Ordering compound( - Iterable> comparators) { - return new CompoundOrdering(comparators); - } - - /** - * Constructs a new instance of this class (only invokable by the subclass - * constructor, typically implicit). - */ - protected Ordering() {} - - // Non-static factories - - /** - * Returns an ordering which first uses the ordering {@code this}, but which - * in the event of a "tie", then delegates to {@code secondaryComparator}. - * For example, to sort a bug list first by status and second by priority, you - * might use {@code byStatus.compound(byPriority)}. For a compound ordering - * with three or more components, simply chain multiple calls to this method. - * - *

An ordering produced by this method, or a chain of calls to this method, - * is equivalent to one created using {@link Ordering#compound(Iterable)} on - * the same component comparators. - */ - @GwtCompatible(serializable = true) - public Ordering compound( - Comparator secondaryComparator) { - return new CompoundOrdering(this, checkNotNull(secondaryComparator)); - } - - /** - * Returns the reverse of this ordering; the {@code Ordering} equivalent to - * {@link Collections#reverseOrder(Comparator)}. - */ - // type parameter lets us avoid the extra in statements like: - // Ordering o = Ordering.natural().reverse(); - @GwtCompatible(serializable = true) - public Ordering reverse() { - return new ReverseOrdering(this); - } - - /** - * Returns a new ordering on {@code F} which orders elements by first applying - * a function to them, then comparing those results using {@code this}. For - * example, to compare objects by their string forms, in a case-insensitive - * manner, use:

   {@code
-   *
-   *   Ordering.from(String.CASE_INSENSITIVE_ORDER)
-   *       .onResultOf(Functions.toStringFunction())}
- */ - @GwtCompatible(serializable = true) - public Ordering onResultOf(Function function) { - return new ByFunctionOrdering(function, this); - } - - /** - * Returns an ordering that treats {@code null} as less than all other values - * and uses {@code this} to compare non-null values. - */ - // type parameter lets us avoid the extra in statements like: - // Ordering o = Ordering.natural().nullsFirst(); - @GwtCompatible(serializable = true) - public Ordering nullsFirst() { - return new NullsFirstOrdering(this); - } - - /** - * Returns an ordering that treats {@code null} as greater than all other - * values and uses this ordering to compare non-null values. - */ - // type parameter lets us avoid the extra in statements like: - // Ordering o = Ordering.natural().nullsLast(); - @GwtCompatible(serializable = true) - public Ordering nullsLast() { - return new NullsLastOrdering(this); - } - - /** - * {@link Collections#binarySearch(List, Object, Comparator) Searches} - * {@code sortedList} for {@code key} using the binary search algorithm. The - * list must be sorted using this ordering. - * - * @param sortedList the list to be searched - * @param key the key to be searched for - */ - public int binarySearch(List sortedList, T key) { - return Collections.binarySearch(sortedList, key, this); - } - - /** - * Returns a copy of the given iterable sorted by this ordering. The input is - * not modified. The returned list is modifiable, serializable, and has random - * access. - * - *

Unlike {@link Sets#newTreeSet(Iterable)}, this method does not collapse - * elements that compare as zero, and the resulting collection does not - * maintain its own sort order. - * - * @param iterable the elements to be copied and sorted - * @return a new list containing the given elements in sorted order - */ - public List sortedCopy(Iterable iterable) { - List list = Lists.newArrayList(iterable); - Collections.sort(list, this); - return list; - } - - /** - * Returns {@code true} if each element in {@code iterable} after the first is - * greater than or equal to the element that preceded it, according to this - * ordering. Note that this is always true when the iterable has fewer than - * two elements. - */ - public boolean isOrdered(Iterable iterable) { - Iterator it = iterable.iterator(); - if (it.hasNext()) { - T prev = it.next(); - while (it.hasNext()) { - T next = it.next(); - if (compare(prev, next) > 0) { - return false; - } - prev = next; - } - } - return true; - } - - /** - * Returns {@code true} if each element in {@code iterable} after the first is - * strictly greater than the element that preceded it, according to - * this ordering. Note that this is always true when the iterable has fewer - * than two elements. - */ - public boolean isStrictlyOrdered(Iterable iterable) { - Iterator it = iterable.iterator(); - if (it.hasNext()) { - T prev = it.next(); - while (it.hasNext()) { - T next = it.next(); - if (compare(prev, next) >= 0) { - return false; - } - prev = next; - } - } - return true; - } - - /** - * Returns the largest of the specified values according to this ordering. If - * there are multiple largest values, the first of those is returned. - * - * @param iterable the iterable whose maximum element is to be determined - * @throws NoSuchElementException if {@code iterable} is empty - * @throws ClassCastException if the parameters are not mutually - * comparable under this ordering. - */ - public E max(Iterable iterable) { - Iterator iterator = iterable.iterator(); - - // let this throw NoSuchElementException as necessary - E maxSoFar = iterator.next(); - - while (iterator.hasNext()) { - maxSoFar = max(maxSoFar, iterator.next()); - } - - return maxSoFar; - } - - /** - * Returns the largest of the specified values according to this ordering. If - * there are multiple largest values, the first of those is returned. - * - * @param a value to compare, returned if greater than or equal to the rest. - * @param b value to compare - * @param c value to compare - * @param rest values to compare - * @throws ClassCastException if the parameters are not mutually - * comparable under this ordering. - */ - public E max(E a, E b, E c, E... rest) { - E maxSoFar = max(max(a, b), c); - - for (E r : rest) { - maxSoFar = max(maxSoFar, r); - } - - return maxSoFar; - } - - /** - * Returns the larger of the two values according to this ordering. If the - * values compare as 0, the first is returned. - * - *

Implementation note: this method is invoked by the default - * implementations of the other {@code max} overloads, so overriding it will - * affect their behavior. - * - * @param a value to compare, returned if greater than or equal to b. - * @param b value to compare. - * @throws ClassCastException if the parameters are not mutually - * comparable under this ordering. - */ - public E max(E a, E b) { - return compare(a, b) >= 0 ? a : b; - } - - /** - * Returns the smallest of the specified values according to this ordering. If - * there are multiple smallest values, the first of those is returned. - * - * @param iterable the iterable whose minimum element is to be determined - * @throws NoSuchElementException if {@code iterable} is empty - * @throws ClassCastException if the parameters are not mutually - * comparable under this ordering. - */ - public E min(Iterable iterable) { - Iterator iterator = iterable.iterator(); - - // let this throw NoSuchElementException as necessary - E minSoFar = iterator.next(); - - while (iterator.hasNext()) { - minSoFar = min(minSoFar, iterator.next()); - } - - return minSoFar; - } - - /** - * Returns the smallest of the specified values according to this ordering. If - * there are multiple smallest values, the first of those is returned. - * - * @param a value to compare, returned if less than or equal to the rest. - * @param b value to compare - * @param c value to compare - * @param rest values to compare - * @throws ClassCastException if the parameters are not mutually - * comparable under this ordering. - */ - public E min(E a, E b, E c, E... rest) { - E minSoFar = min(min(a, b), c); - - for (E r : rest) { - minSoFar = min(minSoFar, r); - } - - return minSoFar; - } - - /** - * Returns the smaller of the two values according to this ordering. If the - * values compare as 0, the first is returned. - * - *

Implementation note: this method is invoked by the default - * implementations of the other {@code min} overloads, so overriding it will - * affect their behavior. - * - * @param a value to compare, returned if less than or equal to b. - * @param b value to compare. - * @throws ClassCastException if the parameters are not mutually - * comparable under this ordering. - */ - public E min(E a, E b) { - return compare(a, b) <= 0 ? a : b; - } - - // Never make these public - static final int LEFT_IS_GREATER = 1; - static final int RIGHT_IS_GREATER = -1; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/PeekingIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/PeekingIterator.java deleted file mode 100644 index e9dbfb3e8bf..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/PeekingIterator.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** - * An iterator that supports a one-element lookahead while iterating. - * - * @author Mick Killianey - */ -@GwtCompatible -public interface PeekingIterator extends Iterator { - /** - * Returns the next element in the iteration, without advancing the iteration. - * - *

Calls to {@code peek()} should not change the state of the iteration, - * except that it may prevent removal of the most recent element via - * {@link #remove()}. - * - * @throws NoSuchElementException if the iteration has no more elements - * according to {@link #hasNext()} - */ - E peek(); - - /** - * {@inheritDoc} - * - *

The objects returned by consecutive calls to {@link #peek()} then {@link - * #next()} are guaranteed to be equal to each other. - */ - E next(); - - /** - * {@inheritDoc} - * - *

Implementations may or may not support removal when a call to {@link - * #peek()} has occurred since the most recent call to {@link #next()}. - * - * @throws IllegalStateException if there has been a call to {@link #peek()} - * since the most recent call to {@link #next()} and this implementation - * does not support this sequence of calls (optional) - */ - void remove(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Platform.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Platform.java deleted file mode 100644 index 652f1ca7747..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Platform.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; - -import java.lang.reflect.Array; -import java.util.List; - -/** - * Methods factored out so that they can be emulated differently in GWT. - * - * @author Hayward Chan - */ -@GwtCompatible(emulated = true) -class Platform { - - /** - * Calls {@link List#subList(int, int)}. Factored out so that it can be - * emulated in GWT. - * - *

This method is not supported in GWT yet. See - * GWT issue 1791 - */ - @GwtIncompatible("List.subList") - static List subList(List list, int fromIndex, int toIndex) { - return list.subList(fromIndex, toIndex); - } - - /** - * Calls {@link Class#isInstance(Object)}. Factored out so that it can be - * emulated in GWT. - */ - @GwtIncompatible("Class.isInstance") - static boolean isInstance(Class clazz, Object obj) { - return clazz.isInstance(obj); - } - - /** - * Clone the given array using {@link Object#clone()}. It is factored out so - * that it can be emulated in GWT. - */ - static T[] clone(T[] array) { - return array.clone(); - } - - /** - * Returns a new array of the given length with the specified component type. - * - * @param type the component type - * @param length the length of the new array - */ - @GwtIncompatible("Array.newInstance(Class, int)") - @SuppressWarnings("unchecked") - static T[] newArray(Class type, int length) { - return (T[]) Array.newInstance(type, length); - } - - /** - * Returns a new array of the given length with the same type as a reference - * array. - * - * @param reference any array of the desired type - * @param length the length of the new array - */ - static T[] newArray(T[] reference, int length) { - Class type = reference.getClass().getComponentType(); - - // the cast is safe because - // result.getClass() == reference.getClass().getComponentType() - @SuppressWarnings("unchecked") - T[] result = (T[]) Array.newInstance(type, length); - return result; - } - - private Platform() {} -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableBiMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableBiMap.java deleted file mode 100644 index af78b271955..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableBiMap.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -/** - * Bimap with one or more mappings. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // uses writeReplace(), not default serialization -class RegularImmutableBiMap extends ImmutableBiMap { - final transient ImmutableMap delegate; - final transient ImmutableBiMap inverse; - - RegularImmutableBiMap(ImmutableMap delegate) { - this.delegate = delegate; - - ImmutableMap.Builder builder = ImmutableMap.builder(); - for (Entry entry : delegate.entrySet()) { - builder.put(entry.getValue(), entry.getKey()); - } - ImmutableMap backwardMap = builder.build(); - this.inverse = new RegularImmutableBiMap(backwardMap, this); - } - - RegularImmutableBiMap(ImmutableMap delegate, - ImmutableBiMap inverse) { - this.delegate = delegate; - this.inverse = inverse; - } - - @Override ImmutableMap delegate() { - return delegate; - } - - @Override public ImmutableBiMap inverse() { - return inverse; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableList.java deleted file mode 100644 index f0f10544217..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableList.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Preconditions; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.ListIterator; -import java.util.NoSuchElementException; - -/** - * Implementation of {@link ImmutableList} with one or more elements. - * - * @author Kevin Bourrillion - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // uses writeReplace(), not default serialization -final class RegularImmutableList extends ImmutableList { - private final transient int offset; - private final transient int size; - private final transient Object[] array; - - RegularImmutableList(Object[] array, int offset, int size) { - this.offset = offset; - this.size = size; - this.array = array; - } - - RegularImmutableList(Object[] array) { - this(array, 0, array.length); - } - - public int size() { - return size; - } - - @Override public boolean isEmpty() { - return false; - } - - @Override public boolean contains(Object target) { - return indexOf(target) != -1; - } - - // The fake cast to E is safe because the creation methods only allow E's - @SuppressWarnings("unchecked") - @Override public UnmodifiableIterator iterator() { - return (UnmodifiableIterator) Iterators.forArray(array, offset, size); - } - - @Override public Object[] toArray() { - Object[] newArray = new Object[size()]; - System.arraycopy(array, offset, newArray, 0, size); - return newArray; - } - - @Override public T[] toArray(T[] other) { - if (other.length < size) { - other = ObjectArrays.newArray(other, size); - } else if (other.length > size) { - other[size] = null; - } - System.arraycopy(array, offset, other, 0, size); - return other; - } - - // The fake cast to E is safe because the creation methods only allow E's - @SuppressWarnings("unchecked") - public E get(int index) { - Preconditions.checkElementIndex(index, size); - return (E) array[index + offset]; - } - - @Override public int indexOf(Object target) { - if (target != null) { - for (int i = offset; i < offset + size; i++) { - if (array[i].equals(target)) { - return i - offset; - } - } - } - return -1; - } - - @Override public int lastIndexOf(Object target) { - if (target != null) { - for (int i = offset + size - 1; i >= offset; i--) { - if (array[i].equals(target)) { - return i - offset; - } - } - } - return -1; - } - - @Override public ImmutableList subList(int fromIndex, int toIndex) { - Preconditions.checkPositionIndexes(fromIndex, toIndex, size); - return (fromIndex == toIndex) - ? ImmutableList.of() - : new RegularImmutableList( - array, offset + fromIndex, toIndex - fromIndex); - } - - public ListIterator listIterator() { - return listIterator(0); - } - - public ListIterator listIterator(final int start) { - Preconditions.checkPositionIndex(start, size); - - return new ListIterator() { - int index = start; - - public boolean hasNext() { - return index < size; - } - public boolean hasPrevious() { - return index > 0; - } - - public int nextIndex() { - return index; - } - public int previousIndex() { - return index - 1; - } - - public E next() { - E result; - try { - result = get(index); - } catch (IndexOutOfBoundsException rethrown) { - throw new NoSuchElementException(); - } - index++; - return result; - } - public E previous() { - E result; - try { - result = get(index - 1); - } catch (IndexOutOfBoundsException rethrown) { - throw new NoSuchElementException(); - } - index--; - return result; - } - - public void set(E o) { - throw new UnsupportedOperationException(); - } - public void add(E o) { - throw new UnsupportedOperationException(); - } - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (!(object instanceof List)) { - return false; - } - - List that = (List) object; - if (this.size() != that.size()) { - return false; - } - - int index = offset; - if (object instanceof RegularImmutableList) { - RegularImmutableList other = (RegularImmutableList) object; - for (int i = other.offset; i < other.offset + other.size; i++) { - if (!array[index++].equals(other.array[i])) { - return false; - } - } - } else { - for (Object element : that) { - if (!array[index++].equals(element)) { - return false; - } - } - } - return true; - } - - @Override public int hashCode() { - // not caching hash code since it could change if the elements are mutable - // in a way that modifies their hash codes - int hashCode = 1; - for (int i = offset; i < offset + size; i++) { - hashCode = 31 * hashCode + array[i].hashCode(); - } - return hashCode; - } - - @Override public String toString() { - StringBuilder sb = new StringBuilder(size() * 16); - sb.append('[').append(array[offset]); - for (int i = offset + 1; i < offset + size; i++) { - sb.append(", ").append(array[i]); - } - return sb.append(']').toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableMap.java deleted file mode 100644 index 712fe31e4ec..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableMap.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.collect.ImmutableSet.ArrayImmutableSet; -import org.elasticsearch.util.collect.ImmutableSet.TransformedImmutableSet; - -/** - * Implementation of {@link ImmutableMap} with two or more entries. - * - * @author Jesse Wilson - * @author Kevin Bourrillion - */ -@GwtCompatible(serializable = true) -final class RegularImmutableMap extends ImmutableMap { - - private final transient Entry[] entries; // entries in insertion order - private final transient Object[] table; // alternating keys and values - // 'and' with an int then shift to get a table index - private final transient int mask; - private final transient int keySetHashCode; - - RegularImmutableMap(Entry... immutableEntries) { - // each of our 6 callers carefully put only Entrys into the array! - @SuppressWarnings("unchecked") - Entry[] tmp = (Entry[]) immutableEntries; - this.entries = tmp; - - int tableSize = Hashing.chooseTableSize(immutableEntries.length); - table = new Object[tableSize * 2]; - mask = tableSize - 1; - - int keySetHashCodeMutable = 0; - for (Entry entry : this.entries) { - K key = entry.getKey(); - int keyHashCode = key.hashCode(); - for (int i = Hashing.smear(keyHashCode); true; i++) { - int index = (i & mask) * 2; - Object existing = table[index]; - if (existing == null) { - V value = entry.getValue(); - table[index] = key; - table[index + 1] = value; - keySetHashCodeMutable += keyHashCode; - break; - } else if (existing.equals(key)) { - throw new IllegalArgumentException("duplicate key: " + key); - } - } - } - keySetHashCode = keySetHashCodeMutable; - } - - @Override public V get(Object key) { - if (key == null) { - return null; - } - for (int i = Hashing.smear(key.hashCode()); true; i++) { - int index = (i & mask) * 2; - Object candidate = table[index]; - if (candidate == null) { - return null; - } - if (candidate.equals(key)) { - // we're careful to store only V's at odd indices - @SuppressWarnings("unchecked") - V value = (V) table[index + 1]; - return value; - } - } - } - - public int size() { - return entries.length; - } - - @Override public boolean isEmpty() { - return false; - } - - @Override public boolean containsValue(Object value) { - if (value == null) { - return false; - } - for (Entry entry : entries) { - if (entry.getValue().equals(value)) { - return true; - } - } - return false; - } - - // TODO: Serialization of the map views should serialize the map, and - // deserialization should call entrySet(), keySet(), or values() on the - // deserialized map. The views are serializable since the Immutable* classes - // are. - - private transient ImmutableSet> entrySet; - - @Override public ImmutableSet> entrySet() { - ImmutableSet> es = entrySet; - return (es == null) ? (entrySet = new EntrySet(this)) : es; - } - - @SuppressWarnings("serial") // uses writeReplace(), not default serialization - private static class EntrySet extends ArrayImmutableSet> { - final transient RegularImmutableMap map; - - EntrySet(RegularImmutableMap map) { - super(map.entries); - this.map = map; - } - - @Override public boolean contains(Object target) { - if (target instanceof Entry) { - Entry entry = (Entry) target; - V mappedValue = map.get(entry.getKey()); - return mappedValue != null && mappedValue.equals(entry.getValue()); - } - return false; - } - } - - private transient ImmutableSet keySet; - - @Override public ImmutableSet keySet() { - ImmutableSet ks = keySet; - return (ks == null) ? (keySet = new KeySet(this)) : ks; - } - - @SuppressWarnings("serial") // uses writeReplace(), not default serialization - private static class KeySet - extends TransformedImmutableSet, K> { - final RegularImmutableMap map; - - KeySet(RegularImmutableMap map) { - super(map.entries, map.keySetHashCode); - this.map = map; - } - - @Override K transform(Entry element) { - return element.getKey(); - } - - @Override public boolean contains(Object target) { - return map.containsKey(target); - } - } - - private transient ImmutableCollection values; - - @Override public ImmutableCollection values() { - ImmutableCollection v = values; - return (v == null) ? (values = new Values(this)) : v; - } - - @SuppressWarnings("serial") // uses writeReplace(), not default serialization - private static class Values extends ImmutableCollection { - final RegularImmutableMap map; - - Values(RegularImmutableMap map) { - this.map = map; - } - - public int size() { - return map.entries.length; - } - - @Override public UnmodifiableIterator iterator() { - return new AbstractIterator() { - int index = 0; - @Override protected V computeNext() { - return (index < map.entries.length) - ? map.entries[index++].getValue() - : endOfData(); - } - }; - } - - @Override public boolean contains(Object target) { - return map.containsValue(target); - } - } - - @Override public String toString() { - StringBuilder result = new StringBuilder(size() * 16).append('{'); - Collections2.standardJoiner.appendTo(result, entries); - return result.append('}').toString(); - } - - // This class is never actually serialized directly, but we have to make the - // warning go away (and suppressing would suppress for all nested classes too) - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableSet.java deleted file mode 100644 index 4ff1542b00b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableSet.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.VisibleForTesting; -import org.elasticsearch.util.collect.ImmutableSet.ArrayImmutableSet; - -/** - * Implementation of {@link ImmutableSet} with two or more elements. - * - * @author Kevin Bourrillion - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // uses writeReplace(), not default serialization -final class RegularImmutableSet extends ArrayImmutableSet { - // the same elements in hashed positions (plus nulls) - @VisibleForTesting final transient Object[] table; - // 'and' with an int to get a valid table index. - private final transient int mask; - private final transient int hashCode; - - RegularImmutableSet( - Object[] elements, int hashCode, Object[] table, int mask) { - super(elements); - this.table = table; - this.mask = mask; - this.hashCode = hashCode; - } - - @Override public boolean contains(Object target) { - if (target == null) { - return false; - } - for (int i = Hashing.smear(target.hashCode()); true; i++) { - Object candidate = table[i & mask]; - if (candidate == null) { - return false; - } - if (candidate.equals(target)) { - return true; - } - } - } - - @Override public int hashCode() { - return hashCode; - } - - @Override boolean isHashCodeFast() { - return true; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableSortedSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableSortedSet.java deleted file mode 100644 index 429e386ac09..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/RegularImmutableSortedSet.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.*; - -/** - * An empty immutable sorted set with one or more elements. - * TODO: Consider creating a separate class for a single-element sorted set. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") -final class RegularImmutableSortedSet - extends ImmutableSortedSet { - - private final Object[] elements; - /** - * The index of the first element that's in the sorted set (inclusive - * index). - */ - private final int fromIndex; - /** - * The index after the last element that's in the sorted set (exclusive - * index). - */ - private final int toIndex; - - RegularImmutableSortedSet(Object[] elements, - Comparator comparator) { - super(comparator); - this.elements = elements; - this.fromIndex = 0; - this.toIndex = elements.length; - } - - RegularImmutableSortedSet(Object[] elements, - Comparator comparator, int fromIndex, int toIndex) { - super(comparator); - this.elements = elements; - this.fromIndex = fromIndex; - this.toIndex = toIndex; - } - - // The factory methods ensure that every element is an E. - @SuppressWarnings("unchecked") - @Override public UnmodifiableIterator iterator() { - return (UnmodifiableIterator) - Iterators.forArray(elements, fromIndex, size()); - } - - @Override public boolean isEmpty() { - return false; - } - - public int size() { - return toIndex - fromIndex; - } - - @Override public boolean contains(Object o) { - if (o == null) { - return false; - } - try { - return binarySearch(o) >= 0; - } catch (ClassCastException e) { - return false; - } - } - - @Override public boolean containsAll(Collection targets) { - // TODO: For optimal performance, use a binary search when - // targets.size() < size() / log(size()) - if (!hasSameComparator(targets, comparator()) || (targets.size() <= 1)) { - return super.containsAll(targets); - } - - /* - * If targets is a sorted set with the same comparator, containsAll can - * run in O(n) time stepping through the two collections. - */ - int i = fromIndex; - Iterator iterator = targets.iterator(); - Object target = iterator.next(); - - while (true) { - if (i >= toIndex) { - return false; - } - - int cmp = unsafeCompare(elements[i], target); - - if (cmp < 0) { - i++; - } else if (cmp == 0) { - if (!iterator.hasNext()) { - return true; - } - target = iterator.next(); - i++; - } else if (cmp > 0) { - return false; - } - } - } - - private int binarySearch(Object key) { - int lower = fromIndex; - int upper = toIndex - 1; - - while (lower <= upper) { - int middle = lower + (upper - lower) / 2; - int c = unsafeCompare(key, elements[middle]); - if (c < 0) { - upper = middle - 1; - } else if (c > 0) { - lower = middle + 1; - } else { - return middle; - } - } - - return -lower - 1; - } - - @Override public Object[] toArray() { - Object[] array = new Object[size()]; - System.arraycopy(elements, fromIndex, array, 0, size()); - return array; - } - - // TODO: Move to ObjectArrays (same code in ImmutableList). - @Override public T[] toArray(T[] array) { - int size = size(); - if (array.length < size) { - array = ObjectArrays.newArray(array, size); - } else if (array.length > size) { - array[size] = null; - } - System.arraycopy(elements, fromIndex, array, 0, size); - return array; - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (!(object instanceof Set)) { - return false; - } - - Set that = (Set) object; - if (size() != that.size()) { - return false; - } - - if (hasSameComparator(that, comparator)) { - Iterator iterator = that.iterator(); - try { - for (int i = fromIndex; i < toIndex; i++) { - Object otherElement = iterator.next(); - if (otherElement == null - || unsafeCompare(elements[i], otherElement) != 0) { - return false; - } - } - return true; - } catch (ClassCastException e) { - return false; - } catch (NoSuchElementException e) { - return false; // concurrent change to other set - } - } - return this.containsAll(that); - } - - @Override public int hashCode() { - // not caching hash code since it could change if the elements are mutable - // in a way that modifies their hash codes - int hash = 0; - for (int i = fromIndex; i < toIndex; i++) { - hash += elements[i].hashCode(); - } - return hash; - } - - // The factory methods ensure that every element is an E. - @SuppressWarnings("unchecked") - public E first() { - return (E) elements[fromIndex]; - } - - // The factory methods ensure that every element is an E. - @SuppressWarnings("unchecked") - public E last() { - return (E) elements[toIndex - 1]; - } - - @Override ImmutableSortedSet headSetImpl(E toElement) { - return createSubset(fromIndex, findSubsetIndex(toElement)); - } - - @Override ImmutableSortedSet subSetImpl(E fromElement, E toElement) { - return createSubset( - findSubsetIndex(fromElement), findSubsetIndex(toElement)); - } - - @Override ImmutableSortedSet tailSetImpl(E fromElement) { - return createSubset(findSubsetIndex(fromElement), toIndex); - } - - private int findSubsetIndex(E element) { - int index = binarySearch(element); - return (index >= 0) ? index : (-index - 1); - } - - private ImmutableSortedSet createSubset( - int newFromIndex, int newToIndex) { - if (newFromIndex < newToIndex) { - return new RegularImmutableSortedSet(elements, comparator, - newFromIndex, newToIndex); - } else { - return emptySet(comparator); - } - } - - @Override boolean hasPartialArray() { - return (fromIndex != 0) || (toIndex != elements.length); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ReverseNaturalOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ReverseNaturalOrdering.java deleted file mode 100644 index c3cda323e54..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ReverseNaturalOrdering.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.Serializable; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** An ordering that uses the reverse of the natural order of the values. */ -@GwtCompatible(serializable = true) -@SuppressWarnings("unchecked") // TODO: the right way to explain this?? -final class ReverseNaturalOrdering - extends Ordering implements Serializable { - static final ReverseNaturalOrdering INSTANCE = new ReverseNaturalOrdering(); - - public int compare(Comparable left, Comparable right) { - checkNotNull(left); // right null is caught later - if (left == right) { - return 0; - } - - @SuppressWarnings("unchecked") // we're permitted to throw CCE - int result = right.compareTo(left); - return result; - } - - @Override public Ordering reverse() { - return Ordering.natural(); - } - - // Override the six min/max methods to "hoist" delegation outside loops - - @Override public E min(E a, E b) { - return NaturalOrdering.INSTANCE.max(a, b); - } - - @Override public E min(E a, E b, E c, E... rest) { - return NaturalOrdering.INSTANCE.max(a, b, c, rest); - } - - @Override public E min(Iterable iterable) { - return NaturalOrdering.INSTANCE.max(iterable); - } - - @Override public E max(E a, E b) { - return NaturalOrdering.INSTANCE.min(a, b); - } - - @Override public E max(E a, E b, E c, E... rest) { - return NaturalOrdering.INSTANCE.min(a, b, c, rest); - } - - @Override public E max(Iterable iterable) { - return NaturalOrdering.INSTANCE.min(iterable); - } - - // preserving singleton-ness gives equals()/hashCode() for free - private Object readResolve() { - return INSTANCE; - } - - @Override public String toString() { - return "Ordering.natural().reverse()"; - } - - private ReverseNaturalOrdering() {} - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ReverseOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ReverseOrdering.java deleted file mode 100644 index e89986b1cf3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/ReverseOrdering.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.Serializable; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** An ordering that uses the reverse of a given order. */ -@GwtCompatible(serializable = true) -final class ReverseOrdering extends Ordering implements Serializable { - final Ordering forwardOrder; - - ReverseOrdering(Ordering forwardOrder) { - this.forwardOrder = checkNotNull(forwardOrder); - } - - public int compare(T a, T b) { - return forwardOrder.compare(b, a); - } - - @SuppressWarnings("unchecked") // how to explain? - @Override public Ordering reverse() { - return (Ordering) forwardOrder; - } - - // Override the six min/max methods to "hoist" delegation outside loops - - @Override public E min(E a, E b) { - return forwardOrder.max(a, b); - } - - @Override public E min(E a, E b, E c, E... rest) { - return forwardOrder.max(a, b, c, rest); - } - - @Override public E min(Iterable iterable) { - return forwardOrder.max(iterable); - } - - @Override public E max(E a, E b) { - return forwardOrder.min(a, b); - } - - @Override public E max(E a, E b, E c, E... rest) { - return forwardOrder.min(a, b, c, rest); - } - - @Override public E max(Iterable iterable) { - return forwardOrder.min(iterable); - } - - @Override public int hashCode() { - return -forwardOrder.hashCode(); - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof ReverseOrdering) { - ReverseOrdering that = (ReverseOrdering) object; - return this.forwardOrder.equals(that.forwardOrder); - } - return false; - } - - @Override public String toString() { - return forwardOrder + ".reverse()"; - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Serialization.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Serialization.java deleted file mode 100644 index e44a741f18e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Serialization.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.lang.reflect.Field; -import java.util.Collection; -import java.util.Map; - -/** - * Provides static methods for serializing collection classes. - * - *

This class assists the implementation of collection classes. Do not use - * this class to serialize collections that are defined elsewhere. - * - * @author Jared Levy - */ -@GwtCompatible(emulated = true) // Accessible but not supported in GWT. -final class Serialization { - private Serialization() {} - - /** - * Reads a count corresponding to a serialized map, multiset, or multimap. It - * returns the size of a map serialized by {@link - * #writeMap(Map, ObjectOutputStream)}, the number of distinct elements in a - * multiset serialized by {@link - * #writeMultiset(Multiset, ObjectOutputStream)}, or the number of distinct - * keys in a multimap serialized by {@link - * #writeMultimap(Multimap, ObjectOutputStream)}. - * - *

The returned count may be used to construct an empty collection of the - * appropriate capacity before calling any of the {@code populate} methods. - */ - @GwtIncompatible("java.io.ObjectInputStream") - public static int readCount(ObjectInputStream stream) throws IOException { - return stream.readInt(); - } - - /** - * Stores the contents of a map in an output stream, as part of serialization. - * It does not support concurrent maps whose content may change while the - * method is running. - * - *

The serialized output consists of the number of entries, first key, - * first value, second key, second value, and so on. - */ - @GwtIncompatible("java.io.ObjectOutputStream") - public static void writeMap(Map map, ObjectOutputStream stream) - throws IOException { - stream.writeInt(map.size()); - for (Map.Entry entry : map.entrySet()) { - stream.writeObject(entry.getKey()); - stream.writeObject(entry.getValue()); - } - } - - /** - * Populates a map by reading an input stream, as part of deserialization. - * See {@link #writeMap} for the data format. - */ - @GwtIncompatible("java.io.ObjectInputStream") - public static void populateMap(Map map, ObjectInputStream stream) - throws IOException, ClassNotFoundException { - int size = stream.readInt(); - populateMap(map, stream, size); - } - - /** - * Populates a map by reading an input stream, as part of deserialization. - * See {@link #writeMap} for the data format. The size is determined by a - * prior call to {@link #readCount}. - */ - @GwtIncompatible("java.io.ObjectInputStream") - public static void populateMap(Map map, ObjectInputStream stream, - int size) throws IOException, ClassNotFoundException { - for (int i = 0; i < size; i++) { - @SuppressWarnings("unchecked") // reading data stored by writeMap - K key = (K) stream.readObject(); - @SuppressWarnings("unchecked") // reading data stored by writeMap - V value = (V) stream.readObject(); - map.put(key, value); - } - } - - /** - * Stores the contents of a multiset in an output stream, as part of - * serialization. It does not support concurrent multisets whose content may - * change while the method is running. - * - *

The serialized output consists of the number of distinct elements, the - * first element, its count, the second element, its count, and so on. - */ - @GwtIncompatible("java.io.ObjectOutputStream") - public static void writeMultiset( - Multiset multiset, ObjectOutputStream stream) throws IOException { - int entryCount = multiset.entrySet().size(); - stream.writeInt(entryCount); - for (Multiset.Entry entry : multiset.entrySet()) { - stream.writeObject(entry.getElement()); - stream.writeInt(entry.getCount()); - } - } - - /** - * Populates a multiset by reading an input stream, as part of - * deserialization. See {@link #writeMultiset} for the data format. - */ - @GwtIncompatible("java.io.ObjectInputStream") - public static void populateMultiset( - Multiset multiset, ObjectInputStream stream) - throws IOException, ClassNotFoundException { - int distinctElements = stream.readInt(); - populateMultiset(multiset, stream, distinctElements); - } - - /** - * Populates a multiset by reading an input stream, as part of - * deserialization. See {@link #writeMultiset} for the data format. The number - * of distinct elements is determined by a prior call to {@link #readCount}. - */ - @GwtIncompatible("java.io.ObjectInputStream") - public static void populateMultiset( - Multiset multiset, ObjectInputStream stream, int distinctElements) - throws IOException, ClassNotFoundException { - for (int i = 0; i < distinctElements; i++) { - @SuppressWarnings("unchecked") // reading data stored by writeMultiset - E element = (E) stream.readObject(); - int count = stream.readInt(); - multiset.add(element, count); - } - } - - /** - * Stores the contents of a multimap in an output stream, as part of - * serialization. It does not support concurrent multimaps whose content may - * change while the method is running. The {@link Multimap#asMap} view - * determines the ordering in which data is written to the stream. - * - *

The serialized output consists of the number of distinct keys, and then - * for each distinct key: the key, the number of values for that key, and the - * key's values. - */ - @GwtIncompatible("java.io.ObjectOutputStream") - public static void writeMultimap( - Multimap multimap, ObjectOutputStream stream) throws IOException { - stream.writeInt(multimap.asMap().size()); - for (Map.Entry> entry : multimap.asMap().entrySet()) { - stream.writeObject(entry.getKey()); - stream.writeInt(entry.getValue().size()); - for (V value : entry.getValue()) { - stream.writeObject(value); - } - } - } - - /** - * Populates a multimap by reading an input stream, as part of - * deserialization. See {@link #writeMultimap} for the data format. - */ - @GwtIncompatible("java.io.ObjectInputStream") - public static void populateMultimap( - Multimap multimap, ObjectInputStream stream) - throws IOException, ClassNotFoundException { - int distinctKeys = stream.readInt(); - populateMultimap(multimap, stream, distinctKeys); - } - - /** - * Populates a multimap by reading an input stream, as part of - * deserialization. See {@link #writeMultimap} for the data format. The number - * of distinct keys is determined by a prior call to {@link #readCount}. - */ - @GwtIncompatible("java.io.ObjectInputStream") - public static void populateMultimap( - Multimap multimap, ObjectInputStream stream, int distinctKeys) - throws IOException, ClassNotFoundException { - for (int i = 0; i < distinctKeys; i++) { - @SuppressWarnings("unchecked") // reading data stored by writeMultimap - K key = (K) stream.readObject(); - Collection values = multimap.get(key); - int valueCount = stream.readInt(); - for (int j = 0; j < valueCount; j++) { - @SuppressWarnings("unchecked") // reading data stored by writeMultimap - V value = (V) stream.readObject(); - values.add(value); - } - } - } - - // Secret sauce for setting final fields; don't make it public. - @GwtIncompatible("java.lang.reflect.Field") - static FieldSetter getFieldSetter( - final Class clazz, String fieldName) { - try { - Field field = clazz.getDeclaredField(fieldName); - return new FieldSetter(field); - } catch (NoSuchFieldException e) { - throw new AssertionError(e); // programmer error - } - } - - // Secret sauce for setting final fields; don't make it public. - @GwtCompatible(emulated = true) // Accessible but not supported in GWT. - static final class FieldSetter { - private final Field field; - - private FieldSetter(Field field) { - this.field = field; - field.setAccessible(true); - } - - @GwtIncompatible("java.lang.reflect.Field") - void set(T instance, Object value) { - try { - field.set(instance, value); - } catch (IllegalAccessException impossible) { - throw new AssertionError(impossible); - } - } - - @GwtIncompatible("java.lang.reflect.Field") - void set(T instance, int value) { - try { - field.set(instance, value); - } catch (IllegalAccessException impossible) { - throw new AssertionError(impossible); - } - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SetMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SetMultimap.java deleted file mode 100644 index 59fedc3b669..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SetMultimap.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -/** - * A {@code Multimap} that cannot hold duplicate key-value pairs. Adding a - * key-value pair that's already in the multimap has no effect. - * - *

The {@link #get}, {@link #removeAll}, and {@link #replaceValues} methods - * each return a {@link Set} of values, while {@link #entries} returns a {@code - * Set} of map entries. Though the method signature doesn't say so explicitly, - * the map returned by {@link #asMap} has {@code Set} values. - * - * @author Jared Levy - */ -@GwtCompatible -public interface SetMultimap extends Multimap { - /** - * {@inheritDoc} - * - *

Because a {@code SetMultimap} has unique values for a given key, this - * method returns a {@link Set}, instead of the {@link java.util.Collection} - * specified in the {@link Multimap} interface. - */ - Set get(@Nullable K key); - - /** - * {@inheritDoc} - * - *

Because a {@code SetMultimap} has unique values for a given key, this - * method returns a {@link Set}, instead of the {@link java.util.Collection} - * specified in the {@link Multimap} interface. - */ - Set removeAll(@Nullable Object key); - - /** - * {@inheritDoc} - * - *

Because a {@code SetMultimap} has unique values for a given key, this - * method returns a {@link Set}, instead of the {@link java.util.Collection} - * specified in the {@link Multimap} interface. - * - *

Any duplicates in {@code values} will be stored in the multimap once. - */ - Set replaceValues(K key, Iterable values); - - /** - * {@inheritDoc} - * - *

Because a {@code SetMultimap} has unique values for a given key, this - * method returns a {@link Set}, instead of the {@link java.util.Collection} - * specified in the {@link Multimap} interface. - */ - Set> entries(); - - /** - * {@inheritDoc} - * - *

Though the method signature doesn't say so explicitly, the returned map - * has {@link Set} values. - */ - Map> asMap(); - - /** - * Compares the specified object to this multimap for equality. - * - *

Two {@code SetMultimap} instances are equal if, for each key, they - * contain the same values. Equality does not depend on the ordering of keys - * or values. - */ - boolean equals(@Nullable Object obj); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Sets.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Sets.java deleted file mode 100644 index 8165532898f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Sets.java +++ /dev/null @@ -1,714 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Predicate; -import org.elasticsearch.util.base.Predicates; -import org.elasticsearch.util.collect.Collections2.FilteredCollection; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Static utility methods pertaining to {@link Set} instances. Also see this - * class's counterparts {@link Lists} and {@link Maps}. - * - * @author Kevin Bourrillion - * @author Jared Levy - */ -@GwtCompatible -public final class Sets { - private Sets() {} - - /** - * Returns an immutable set instance containing the given enum elements. - * Internally, the returned set will be backed by an {@link EnumSet}. - * - *

The iteration order of the returned set follows the enum's iteration - * order, not the order in which the elements are provided to the method. - * - * @param anElement one of the elements the set should contain - * @param otherElements the rest of the elements the set should contain - * @return an immutable set containing those elements, minus duplicates - */ - // http://code.google.com/p/google-web-toolkit/issues/detail?id=3028 - @GwtCompatible(serializable = true) - public static > ImmutableSet immutableEnumSet( - E anElement, E... otherElements) { - return new ImmutableEnumSet(EnumSet.of(anElement, otherElements)); - } - - /** - * Returns an immutable set instance containing the given enum elements. - * Internally, the returned set will be backed by an {@link EnumSet}. - * - *

The iteration order of the returned set follows the enum's iteration - * order, not the order in which the elements appear in the given collection. - * - * @param elements the elements, all of the same {@code enum} type, that the - * set should contain - * @return an immutable set containing those elements, minus duplicates - */ - // http://code.google.com/p/google-web-toolkit/issues/detail?id=3028 - @GwtCompatible(serializable = true) - public static > ImmutableSet immutableEnumSet( - Iterable elements) { - Iterator iterator = elements.iterator(); - if (!iterator.hasNext()) { - return ImmutableSet.of(); - } - if (elements instanceof EnumSet) { - EnumSet enumSetClone = EnumSet.copyOf((EnumSet) elements); - return new ImmutableEnumSet(enumSetClone); - } - E first = iterator.next(); - EnumSet set = EnumSet.of(first); - while (iterator.hasNext()) { - set.add(iterator.next()); - } - return new ImmutableEnumSet(set); - } - - /** - * Returns a new {@code EnumSet} instance containing the given elements. - * Unlike {@link EnumSet#copyOf(Collection)}, this method does not produce an - * exception on an empty collection, and it may be called on any iterable, not - * just a {@code Collection}. - */ - public static > EnumSet newEnumSet(Iterable iterable, - Class elementType) { - /* - * TODO: noneOf() and addAll() will both throw NullPointerExceptions when - * appropriate. However, NullPointerTester will fail on this method because - * it passes in Class.class instead of an enum type. This means that, when - * iterable is null but elementType is not, noneOf() will throw a - * ClassCastException before addAll() has a chance to throw a - * NullPointerException. NullPointerTester considers this a failure. - * Ideally the test would be fixed, but it would require a special case for - * Class where E extends Enum. Until that happens (if ever), leave - * checkNotNull() here. For now, contemplate the irony that checking - * elementType, the problem argument, is harmful, while checking iterable, - * the innocent bystander, is effective. - */ - checkNotNull(iterable); - EnumSet set = EnumSet.noneOf(elementType); - Iterables.addAll(set, iterable); - return set; - } - - // HashSet - - /** - * Creates a mutable, empty {@code HashSet} instance. - * - *

Note: if mutability is not required, use {@link - * ImmutableSet#of()} instead. - * - *

Note: if {@code E} is an {@link Enum} type, use {@link - * EnumSet#noneOf} instead. - * - * @return a new, empty {@code HashSet} - */ - public static HashSet newHashSet() { - return new HashSet(); - } - - /** - * Creates a mutable {@code HashSet} instance containing the given - * elements in unspecified order. - * - *

Note: if mutability is not required and the elements are - * non-null, use {@link ImmutableSet#of(Object[])} instead. - * - *

Note: if {@code E} is an {@link Enum} type, use {@link - * EnumSet#of(Enum, Enum[])} instead. - * - * @param elements the elements that the set should contain - * @return a new {@code HashSet} containing those elements (minus duplicates) - */ - public static HashSet newHashSet(E... elements) { - int capacity = Maps.capacity(elements.length); - HashSet set = new HashSet(capacity); - Collections.addAll(set, elements); - return set; - } - - /** - * Creates an empty {@code HashSet} instance with enough capacity to hold the - * specified number of elements without rehashing. - * - * @param expectedSize the expected size - * @return a new, empty {@code HashSet} with enough capacity to hold {@code - * expectedSize} elements without rehashing - * @throws IllegalArgumentException if {@code expectedSize} is negative - */ - public static HashSet newHashSetWithExpectedSize(int expectedSize) { - return new HashSet(Maps.capacity(expectedSize)); - } - - /** - * Creates a mutable {@code HashSet} instance containing the given - * elements in unspecified order. - * - *

Note: if mutability is not required and the elements are - * non-null, use {@link ImmutableSet#copyOf(Iterable)} instead. - * - *

Note: if {@code E} is an {@link Enum} type, use - * {@link #newEnumSet(Iterable, Class)} instead. - * - * @param elements the elements that the set should contain - * @return a new {@code HashSet} containing those elements (minus duplicates) - */ - public static HashSet newHashSet(Iterable elements) { - if (elements instanceof Collection) { - @SuppressWarnings("unchecked") - Collection collection = (Collection) elements; - return new HashSet(collection); - } else { - return newHashSet(elements.iterator()); - } - } - - /** - * Creates a mutable {@code HashSet} instance containing the given - * elements in unspecified order. - * - *

Note: if mutability is not required and the elements are - * non-null, use {@link ImmutableSet#copyOf(Iterable)} instead. - * - *

Note: if {@code E} is an {@link Enum} type, you should create an - * {@link EnumSet} instead. - * - * @param elements the elements that the set should contain - * @return a new {@code HashSet} containing those elements (minus duplicates) - */ - public static HashSet newHashSet(Iterator elements) { - HashSet set = newHashSet(); - while (elements.hasNext()) { - set.add(elements.next()); - } - return set; - } - - // LinkedHashSet - - /** - * Creates a mutable, empty {@code LinkedHashSet} instance. - * - *

Note: if mutability is not required, use {@link - * ImmutableSet#of()} instead. - * - * @return a new, empty {@code LinkedHashSet} - */ - public static LinkedHashSet newLinkedHashSet() { - return new LinkedHashSet(); - } - - /** - * Creates a mutable {@code LinkedHashSet} instance containing the - * given elements in order. - * - *

Note: if mutability is not required and the elements are - * non-null, use {@link ImmutableSet#copyOf(Iterable)} instead. - * - * @param elements the elements that the set should contain, in order - * @return a new {@code LinkedHashSet} containing those elements (minus - * duplicates) - */ - public static LinkedHashSet newLinkedHashSet( - Iterable elements) { - if (elements instanceof Collection) { - @SuppressWarnings("unchecked") - Collection collection = (Collection) elements; - return new LinkedHashSet(collection); - } else { - LinkedHashSet set = newLinkedHashSet(); - for (E element : elements) { - set.add(element); - } - return set; - } - } - - // TreeSet - - /** - * Creates a mutable, empty {@code TreeSet} instance sorted by the - * natural sort ordering of its elements. - * - *

Note: if mutability is not required, use {@link - * ImmutableSortedSet#of()} instead. - * - * @return a new, empty {@code TreeSet} - */ - @SuppressWarnings("unchecked") // allow ungenerified Comparable types - public static TreeSet newTreeSet() { - return new TreeSet(); - } - - /** - * Creates a mutable {@code TreeSet} instance containing the given - * elements sorted by their natural ordering. - * - *

Note: if mutability is not required, use {@link - * ImmutableSortedSet#copyOf(Iterable)} instead. - * - *

Note: If {@code elements} is a {@code SortedSet} with an explicit - * comparator, this method has different behavior than - * {@link TreeSet#TreeSet(SortedSet)}, which returns a {@code TreeSet} with - * that comparator. - * - * @param elements the elements that the set should contain - * @return a new {@code TreeSet} containing those elements (minus duplicates) - */ - @SuppressWarnings("unchecked") // allow ungenerified Comparable types - public static TreeSet newTreeSet( - Iterable elements) { - TreeSet set = newTreeSet(); - for (E element : elements) { - set.add(element); - } - return set; - } - - /** - * Creates a mutable, empty {@code TreeSet} instance with the given - * comparator. - * - *

Note: if mutability is not required, use {@code - * ImmutableSortedSet.orderedBy(comparator).build()} instead. - * - * @param comparator the comparator to use to sort the set - * @return a new, empty {@code TreeSet} - * @throws NullPointerException if {@code comparator} is null - */ - public static TreeSet newTreeSet(Comparator comparator) { - return new TreeSet(checkNotNull(comparator)); - } - - /** - * Creates an {@code EnumSet} consisting of all enum values that are not in - * the specified collection. If the collection is an {@link EnumSet}, this - * method has the same behavior as {@link EnumSet#complementOf}. Otherwise, - * the specified collection must contain at least one element, in order to - * determine the element type. If the collection could be empty, use - * {@link #complementOf(Collection, Class)} instead of this method. - * - * @param collection the collection whose complement should be stored in the - * enum set - * @return a new, modifiable {@code EnumSet} containing all values of the enum - * that aren't present in the given collection - * @throws IllegalArgumentException if {@code collection} is not an - * {@code EnumSet} instance and contains no elements - */ - public static > EnumSet complementOf( - Collection collection) { - if (collection instanceof EnumSet) { - return EnumSet.complementOf((EnumSet) collection); - } - checkArgument(!collection.isEmpty(), - "collection is empty; use the other version of this method"); - Class type = collection.iterator().next().getDeclaringClass(); - return makeComplementByHand(collection, type); - } - - /** - * Creates an {@code EnumSet} consisting of all enum values that are not in - * the specified collection. This is equivalent to - * {@link EnumSet#complementOf}, but can act on any input collection, as long - * as the elements are of enum type. - * - * @param collection the collection whose complement should be stored in the - * {@code EnumSet} - * @param type the type of the elements in the set - * @return a new, modifiable {@code EnumSet} initially containing all the - * values of the enum not present in the given collection - */ - public static > EnumSet complementOf( - Collection collection, Class type) { - checkNotNull(collection); - return (collection instanceof EnumSet) - ? EnumSet.complementOf((EnumSet) collection) - : makeComplementByHand(collection, type); - } - - private static > EnumSet makeComplementByHand( - Collection collection, Class type) { - EnumSet result = EnumSet.allOf(type); - result.removeAll(collection); - return result; - } - - /* - * Regarding newSetForMap() and SetFromMap: - * - * Written by Doug Lea with assistance from members of JCP JSR-166 - * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain - */ - - /** - * Returns a set backed by the specified map. The resulting set displays - * the same ordering, concurrency, and performance characteristics as the - * backing map. In essence, this factory method provides a {@link Set} - * implementation corresponding to any {@link Map} implementation. There is no - * need to use this method on a {@link Map} implementation that already has a - * corresponding {@link Set} implementation (such as {@link HashMap} or - * {@link TreeMap}). - * - *

Each method invocation on the set returned by this method results in - * exactly one method invocation on the backing map or its keySet - * view, with one exception. The addAll method is implemented as a - * sequence of put invocations on the backing map. - * - *

The specified map must be empty at the time this method is invoked, - * and should not be accessed directly after this method returns. These - * conditions are ensured if the map is created empty, passed directly - * to this method, and no reference to the map is retained, as illustrated - * in the following code fragment:

  {@code
-   *
-   *  Set identityHashSet = Sets.newSetFromMap(
-   *      new IdentityHashMap());}
-   *
-   * This method has the same behavior as the JDK 6 method
-   * {@code Collections.newSetFromMap()}. The returned set is serializable if
-   * the backing map is.
-   *
-   * @param map the backing map
-   * @return the set backed by the map
-   * @throws IllegalArgumentException if map is not empty
-   */
-  public static  Set newSetFromMap(Map map) {
-    return new SetFromMap(map);
-  }
-
-  private static class SetFromMap extends AbstractSet
-      implements Set, Serializable {
-    private final Map m; // The backing map
-    private transient Set s; // Its keySet
-
-    SetFromMap(Map map) {
-      checkArgument(map.isEmpty(), "Map is non-empty");
-      m = map;
-      s = map.keySet();
-    }
-
-    @Override public void clear() {
-      m.clear();
-    }
-    @Override public int size() {
-      return m.size();
-    }
-    @Override public boolean isEmpty() {
-      return m.isEmpty();
-    }
-    @Override public boolean contains(Object o) {
-      return m.containsKey(o);
-    }
-    @Override public boolean remove(Object o) {
-      return m.remove(o) != null;
-    }
-    @Override public boolean add(E e) {
-      return m.put(e, Boolean.TRUE) == null;
-    }
-    @Override public Iterator iterator() {
-      return s.iterator();
-    }
-    @Override public Object[] toArray() {
-      return s.toArray();
-    }
-    @Override public  T[] toArray(T[] a) {
-      return s.toArray(a);
-    }
-    @Override public String toString() {
-      return s.toString();
-    }
-    @Override public int hashCode() {
-      return s.hashCode();
-    }
-    @Override public boolean equals(@Nullable Object object) {
-      return this == object || this.s.equals(object);
-    }
-    @Override public boolean containsAll(Collection c) {
-      return s.containsAll(c);
-    }
-    @Override public boolean removeAll(Collection c) {
-      return s.removeAll(c);
-    }
-    @Override public boolean retainAll(Collection c) {
-      return s.retainAll(c);
-    }
-
-    // addAll is the only inherited implementation
-
-    static final long serialVersionUID = 0;
-
-    private void readObject(ObjectInputStream stream)
-        throws IOException, ClassNotFoundException {
-      stream.defaultReadObject();
-      s = m.keySet();
-    }
-  }
-
-  /**
-   * An unmodifiable view of a set which may be backed by other sets; this view
-   * will change as the backing sets do. Contains methods to copy the data into
-   * a new set which will then remain stable. There is usually no reason to
-   * retain a reference of type {@code SetView}; typically, you either use it
-   * as a plain {@link Set}, or immediately invoke {@link #immutableCopy} or
-   * {@link #copyInto} and forget the {@code SetView} itself.
-   */
-  public abstract static class SetView extends AbstractSet {
-    private SetView() {} // no subclasses but our own
-
-    /**
-     * Returns an immutable copy of the current contents of this set view.
-     * Does not support null elements.
-     *
-     * 

Warning: this may have unexpected results if a backing set of - * this view uses a nonstandard notion of equivalence, for example if it is - * a {@link TreeSet} using a comparator that is inconsistent with {@link - * Object#equals(Object)}. - */ - public ImmutableSet immutableCopy() { - return ImmutableSet.copyOf(this); - } - - /** - * Copies the current contents of this set view into an existing set. This - * method has equivalent behavior to {@code set.addAll(this)}, assuming that - * all the sets involved are based on the same notion of equivalence. - */ - // Note: S should logically extend Set but can't due to either - // some javac bug or some weirdness in the spec, not sure which. - public > S copyInto(S set) { - set.addAll(this); - return set; - } - } - - /** - * Returns an unmodifiable view of the union of two sets. The returned - * set contains all elements that are contained in either backing set. - * Iterating over the returned set iterates first over all the elements of - * {@code set1}, then over each element of {@code set2}, in order, that is not - * contained in {@code set1}. - * - *

Results are undefined if {@code set1} and {@code set2} are sets based on - * different equivalence relations (as {@link HashSet}, {@link TreeSet}, and - * the {@link Map#keySet} of an {@link IdentityHashMap} all are). - * - *

Note: The returned view performs better when {@code set1} is the - * smaller of the two sets. If you have reason to believe one of your sets - * will generally be smaller than the other, pass it first. - */ - public static SetView union( - final Set set1, final Set set2) { - checkNotNull(set1, "set1"); - checkNotNull(set2, "set2"); - - // TODO: once we have OrderedIterators, check if these are compatible - // sorted sets and use that instead if so - - final Set set2minus1 = difference(set2, set1); - - return new SetView() { - @Override public int size() { - return set1.size() + set2minus1.size(); - } - @Override public boolean isEmpty() { - return set1.isEmpty() && set2.isEmpty(); - } - @Override public Iterator iterator() { - return Iterators.unmodifiableIterator( - Iterators.concat(set1.iterator(), set2minus1.iterator())); - } - @Override public boolean contains(Object object) { - return set1.contains(object) || set2.contains(object); - } - @Override public > S copyInto(S set) { - set.addAll(set1); - set.addAll(set2); - return set; - } - @Override public ImmutableSet immutableCopy() { - return new ImmutableSet.Builder() - .addAll(set1).addAll(set2).build(); - } - }; - } - - /** - * Returns an unmodifiable view of the intersection of two sets. The - * returned set contains all elements that are contained by both backing sets. - * The iteration order of the returned set matches that of {@code set1}. - * - *

Results are undefined if {@code set1} and {@code set2} are sets based - * on different equivalence relations (as {@code HashSet}, {@code TreeSet}, - * and the keySet of an {@code IdentityHashMap} all are). - * - *

Note: The returned view performs slightly better when {@code - * set1} is the smaller of the two sets. If you have reason to believe one of - * your sets will generally be smaller than the other, pass it first. - * Unfortunately, since this method sets the generic type of the returned set - * based on the type of the first set passed, this could in rare cases force - * you to make a cast, for example:

  {@code
-   *
-   *  Set aFewBadObjects = ...
-   *  Set manyBadStrings = ...
-   *
-   *  // impossible for a non-String to be in the intersection
-   *  SuppressWarnings("unchecked")
-   *  Set badStrings = (Set) Sets.intersection(
-   *      aFewBadObjects, manyBadStrings);}
-   *
-   * This is unfortunate, but should come up only very rarely.
-   */
-  public static  SetView intersection(
-      final Set set1, final Set set2) {
-    checkNotNull(set1, "set1");
-    checkNotNull(set2, "set2");
-
-    // TODO: once we have OrderedIterators, check if these are compatible
-    // sorted sets and use that instead if so
-
-    final Predicate inSet2 = Predicates.in(set2);
-    return new SetView() {
-      @Override public Iterator iterator() {
-        return Iterators.filter(set1.iterator(), inSet2);
-      }
-      @Override public int size() {
-        return Iterators.size(iterator());
-      }
-      @Override public boolean isEmpty() {
-        return !iterator().hasNext();
-      }
-      @Override public boolean contains(Object object) {
-        return set1.contains(object) && set2.contains(object);
-      }
-      @Override public boolean containsAll(Collection collection) {
-        return set1.containsAll(collection)
-            && set2.containsAll(collection);
-      }
-    };
-  }
-
-  /**
-   * Returns an unmodifiable view of the difference of two sets. The
-   * returned set contains all elements that are contained by {@code set1} and
-   * not contained by {@code set2}. {@code set2} may also contain elements not
-   * present in {@code set1}; these are simply ignored. The iteration order of
-   * the returned set matches that of {@code set1}.
-   *
-   * 

Results are undefined if {@code set1} and {@code set2} are sets based - * on different equivalence relations (as {@code HashSet}, {@code TreeSet}, - * and the keySet of an {@code IdentityHashMap} all are). - */ - public static SetView difference( - final Set set1, final Set set2) { - checkNotNull(set1, "set1"); - checkNotNull(set2, "set2"); - - // TODO: once we have OrderedIterators, check if these are compatible - // sorted sets and use that instead if so - - final Predicate notInSet2 = Predicates.not(Predicates.in(set2)); - return new SetView() { - @Override public Iterator iterator() { - return Iterators.filter(set1.iterator(), notInSet2); - } - @Override public int size() { - return Iterators.size(iterator()); - } - @Override public boolean isEmpty() { - return set2.containsAll(set1); - } - @Override public boolean contains(Object element) { - return set1.contains(element) && !set2.contains(element); - } - }; - } - - /** - * Returns the elements of {@code unfiltered} that satisfy a predicate. The - * returned set is a live view of {@code unfiltered}; changes to one affect - * the other. - * - *

The resulting set's iterator does not support {@code remove()}, but all - * other set methods are supported. The set's {@code add()} and - * {@code addAll()} methods throw an {@link IllegalArgumentException} if an - * element that doesn't satisfy the predicate is provided. When methods such - * as {@code removeAll()} and {@code clear()} are called on the filtered set, - * only elements that satisfy the filter will be removed from the underlying - * collection. - * - *

The returned set isn't threadsafe or serializable, even if - * {@code unfiltered} is. - * - *

Many of the filtered set's methods, such as {@code size()}, iterate - * across every element in the underlying set and determine which elements - * satisfy the filter. When a live view is not needed, it may be faster - * to copy {@code Iterables.filter(unfiltered, predicate)} and use the copy. - */ - public static Set filter( - Set unfiltered, Predicate predicate) { - if (unfiltered instanceof FilteredSet) { - // Support clear(), removeAll(), and retainAll() when filtering a filtered - // collection. - FilteredSet filtered = (FilteredSet) unfiltered; - Predicate combinedPredicate - = Predicates.and(filtered.predicate, predicate); - return new FilteredSet( - (Set) filtered.unfiltered, combinedPredicate); - } - - return new FilteredSet( - checkNotNull(unfiltered), checkNotNull(predicate)); - } - - private static class FilteredSet extends FilteredCollection - implements Set { - FilteredSet(Set unfiltered, Predicate predicate) { - super(unfiltered, predicate); - } - - @Override public boolean equals(@Nullable Object object) { - return Collections2.setEquals(this, object); - } - - @Override public int hashCode() { - return hashCodeImpl(this); - } - } - - /** - * Calculates and returns the hash code of {@code s}. - */ - static int hashCodeImpl(Set s) { - int hashCode = 0; - for (Object o : s) { - hashCode += o != null ? o.hashCode() : 0; - } - return hashCode; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableList.java deleted file mode 100644 index 26c4a6a348f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableList.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Preconditions; - -import javax.annotation.Nullable; -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Implementation of {@link ImmutableList} with exactly one element. - * - * @author Hayward Chan - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // uses writeReplace(), not default serialization -final class SingletonImmutableList extends ImmutableList { - final transient E element; - - SingletonImmutableList(E element) { - this.element = checkNotNull(element); - } - - public E get(int index) { - Preconditions.checkElementIndex(index, 1); - return element; - } - - @Override public int indexOf(@Nullable Object object) { - return element.equals(object) ? 0 : -1; - } - - @Override public UnmodifiableIterator iterator() { - return Iterators.singletonIterator(element); - } - - @Override public int lastIndexOf(@Nullable Object object) { - return element.equals(object) ? 0 : -1; - } - - public ListIterator listIterator() { - return listIterator(0); - } - - public ListIterator listIterator(final int start) { - // suboptimal but not worth optimizing. - return Collections.singletonList(element).listIterator(start); - } - - public int size() { - return 1; - } - - @Override public ImmutableList subList(int fromIndex, int toIndex) { - Preconditions.checkPositionIndexes(fromIndex, toIndex, 1); - return (fromIndex == toIndex) ? ImmutableList.of() : this; - } - - @Override public boolean contains(@Nullable Object object) { - return element.equals(object); - } - - @Override public boolean equals(Object object) { - if (object == this) { - return true; - } - if (object instanceof List) { - List that = (List) object; - return that.size() == 1 && element.equals(that.get(0)); - } - return false; - } - - @Override public int hashCode() { - // not caching hash code since it could change if the element is mutable - // in a way that modifies its hash code. - return 31 + element.hashCode(); - } - - @Override public boolean isEmpty() { - return false; - } - - @Override public Object[] toArray() { - return new Object[] { element }; - } - - @Override public T[] toArray(T[] array) { - if (array.length == 0) { - array = ObjectArrays.newArray(array, 1); - } else if (array.length > 1) { - array[1] = null; - } - // Writes will produce ArrayStoreException when the toArray() doc requires. - Object[] objectArray = array; - objectArray[0] = element; - return array; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableMap.java deleted file mode 100644 index e9999cb2586..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableMap.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.Map; - -/** - * Implementation of {@link ImmutableMap} with exactly one entry. - * - * @author Jesse Wilson - * @author Kevin Bourrillion - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // uses writeReplace(), not default serialization -final class SingletonImmutableMap extends ImmutableMap { - final transient K singleKey; - final transient V singleValue; - - private transient Entry entry; - - SingletonImmutableMap(K singleKey, V singleValue) { - this.singleKey = singleKey; - this.singleValue = singleValue; - } - - SingletonImmutableMap(Entry entry) { - this.entry = entry; - this.singleKey = entry.getKey(); - this.singleValue = entry.getValue(); - } - - private Entry entry() { - Entry e = entry; - return (e == null) - ? (entry = Maps.immutableEntry(singleKey, singleValue)) : e; - } - - @Override public V get(Object key) { - return singleKey.equals(key) ? singleValue : null; - } - - public int size() { - return 1; - } - - @Override public boolean isEmpty() { - return false; - } - - @Override public boolean containsKey(Object key) { - return singleKey.equals(key); - } - - @Override public boolean containsValue(Object value) { - return singleValue.equals(value); - } - - private transient ImmutableSet> entrySet; - - @Override public ImmutableSet> entrySet() { - ImmutableSet> es = entrySet; - return (es == null) ? (entrySet = ImmutableSet.of(entry())) : es; - } - - private transient ImmutableSet keySet; - - @Override public ImmutableSet keySet() { - ImmutableSet ks = keySet; - return (ks == null) ? (keySet = ImmutableSet.of(singleKey)) : ks; - } - - private transient ImmutableCollection values; - - @Override public ImmutableCollection values() { - ImmutableCollection v = values; - return (v == null) ? (values = new Values(singleValue)) : v; - } - - @SuppressWarnings("serial") // uses writeReplace(), not default serialization - private static class Values extends ImmutableCollection { - final V singleValue; - - Values(V singleValue) { - this.singleValue = singleValue; - } - - @Override public boolean contains(Object object) { - return singleValue.equals(object); - } - - @Override public boolean isEmpty() { - return false; - } - - public int size() { - return 1; - } - - @Override public UnmodifiableIterator iterator() { - return Iterators.singletonIterator(singleValue); - } - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof Map) { - Map that = (Map) object; - if (that.size() != 1) { - return false; - } - Entry entry = that.entrySet().iterator().next(); - return singleKey.equals(entry.getKey()) - && singleValue.equals(entry.getValue()); - } - return false; - } - - @Override public int hashCode() { - return singleKey.hashCode() ^ singleValue.hashCode(); - } - - @Override public String toString() { - return new StringBuilder() - .append('{') - .append(singleKey.toString()) - .append('=') - .append(singleValue.toString()) - .append('}') - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableSet.java deleted file mode 100644 index 23ab925f12b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SingletonImmutableSet.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.base.Preconditions; - -import javax.annotation.Nullable; -import java.util.Set; - -/** - * Implementation of {@link ImmutableSet} with exactly one element. - * - * @author Kevin Bourrillion - * @author Nick Kralevich - */ -@GwtCompatible(serializable = true) -@SuppressWarnings("serial") // uses writeReplace(), not default serialization -final class SingletonImmutableSet extends ImmutableSet { - final transient E element; - - // Non-volatile because: - // - Integer is immutable and thus thread-safe; - // - no problems if one thread overwrites the cachedHashCode from another. - private transient Integer cachedHashCode; - - SingletonImmutableSet(E element) { - this.element = Preconditions.checkNotNull(element); - } - - SingletonImmutableSet(E element, int hashCode) { - // Guaranteed to be non-null by the presence of the pre-computed hash code. - this.element = element; - cachedHashCode = hashCode; - } - - public int size() { - return 1; - } - - @Override public boolean isEmpty() { - return false; - } - - @Override public boolean contains(Object target) { - return element.equals(target); - } - - @Override public UnmodifiableIterator iterator() { - return Iterators.singletonIterator(element); - } - - @Override public Object[] toArray() { - return new Object[] { element }; - } - - @SuppressWarnings({"unchecked"}) - @Override public T[] toArray(T[] array) { - if (array.length == 0) { - array = ObjectArrays.newArray(array, 1); - } else if (array.length > 1) { - array[1] = null; - } - // Writes will produce ArrayStoreException when the toArray() doc requires. - Object[] objectArray = array; - objectArray[0] = element; - return array; - } - - @Override public boolean equals(@Nullable Object object) { - if (object == this) { - return true; - } - if (object instanceof Set) { - Set that = (Set) object; - return that.size() == 1 && element.equals(that.iterator().next()); - } - return false; - } - - @Override public final int hashCode() { - Integer code = cachedHashCode; - if (code == null) { - return cachedHashCode = element.hashCode(); - } - return code; - } - - @Override boolean isHashCodeFast() { - return false; - } - - @Override public String toString() { - String elementToString = element.toString(); - return new StringBuilder(elementToString.length() + 2) - .append('[') - .append(elementToString) - .append(']') - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SortedSetMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SortedSetMultimap.java deleted file mode 100644 index 5611489c180..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/SortedSetMultimap.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.util.*; - -/** - * A {@code SetMultimap} whose set of values for a given key are kept sorted; - * that is, they comprise a {@link SortedSet}. It cannot hold duplicate - * key-value pairs; adding a key-value pair that's already in the multimap has - * no effect. This interface does not specify the ordering of the multimap's - * keys. - * - *

The {@link #get}, {@link #removeAll}, and {@link #replaceValues} methods - * each return a {@link SortedSet} of values, while {@link Multimap#entries()} - * returns a {@link Set} of map entries. Though the method signature doesn't say - * so explicitly, the map returned by {@link #asMap} has {@code SortedSet} - * values. - * - * @author Jared Levy - */ -@GwtCompatible -public interface SortedSetMultimap extends SetMultimap { - /** - * Returns a collection view of all values associated with a key. If no - * mappings in the multimap have the provided key, an empty collection is - * returned. - * - *

Changes to the returned collection will update the underlying multimap, - * and vice versa. - * - *

Because a {@code SortedSetMultimap} has unique sorted values for a given - * key, this method returns a {@link SortedSet}, instead of the - * {@link java.util.Collection} specified in the {@link Multimap} interface. - */ - SortedSet get(@Nullable K key); - - /** - * Removes all values associated with a given key. - * - *

Because a {@code SortedSetMultimap} has unique sorted values for a given - * key, this method returns a {@link SortedSet}, instead of the - * {@link java.util.Collection} specified in the {@link Multimap} interface. - */ - SortedSet removeAll(@Nullable Object key); - - /** - * Stores a collection of values with the same key, replacing any existing - * values for that key. - * - *

Because a {@code SortedSetMultimap} has unique sorted values for a given - * key, this method returns a {@link SortedSet}, instead of the - * {@link java.util.Collection} specified in the {@link Multimap} interface. - * - *

Any duplicates in {@code values} will be stored in the multimap once. - */ - SortedSet replaceValues(K key, Iterable values); - - /** - * Returns a map view that associates each key with the corresponding values - * in the multimap. Changes to the returned map, such as element removal, - * will update the underlying multimap. The map never supports - * {@code setValue()} on the map entries, {@code put}, or {@code putAll}. - * - *

The collections returned by {@code asMap().get(Object)} have the same - * behavior as those returned by {@link #get}. - * - *

Though the method signature doesn't say so explicitly, the returned map - * has {@link SortedSet} values. - */ - Map> asMap(); - - /** - * Returns the comparator that orders the multimap values, with a {@code null} - * indicating that natural ordering is used. - */ - Comparator valueComparator(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Synchronized.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Synchronized.java deleted file mode 100644 index fdcbfb2b6a1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/Synchronized.java +++ /dev/null @@ -1,1358 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; -import org.elasticsearch.util.annotations.GwtIncompatible; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Synchronized collection views. The returned synchronized collection views are - * serializable if the backing collection and the mutex are serializable. - * - *

If a {@code null} is passed as the {@code mutex} parameter to any of this - * class's top-level methods or inner class constructors, the created object - * uses itself as the synchronization mutex. - * - *

This class should be used by other collection classes only. - * - * @author Mike Bostock - * @author Jared Levy - */ -@GwtCompatible -final class Synchronized { - private Synchronized() {} - - /** Abstract base class for synchronized views. */ - static class SynchronizedObject implements Serializable { - private final Object delegate; - protected final Object mutex; - - public SynchronizedObject(Object delegate, @Nullable Object mutex) { - this.delegate = checkNotNull(delegate); - this.mutex = (mutex == null) ? this : mutex; - } - - protected Object delegate() { - return delegate; - } - - // No equals and hashCode; see ForwardingObject for details. - - @Override public String toString() { - synchronized (mutex) { - return delegate.toString(); - } - } - - // Serialization invokes writeObject only when it's private. - // The SynchronizedObject subclasses don't need a writeObject method since - // they don't contain any non-transient member variables, while the - // following writeObject() handles the SynchronizedObject members. - - private void writeObject(ObjectOutputStream stream) throws IOException { - synchronized (mutex) { - stream.defaultWriteObject(); - } - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) collection backed by the specified - * collection using the specified mutex. 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 specified - * mutex when iterating over the returned collection:

  {@code
-   *
-   *  Collection s = Synchronized.collection(
-   *      new HashSet(), mutex);
-   *  ...
-   *  synchronized (mutex) {
-   *    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. - * - * @param collection the collection to be wrapped in a synchronized view - * @return a synchronized view of the specified collection - */ - static Collection collection( - Collection collection, @Nullable Object mutex) { - return new SynchronizedCollection(collection, mutex); - } - - /** @see Synchronized#collection */ - static class SynchronizedCollection extends SynchronizedObject - implements Collection { - public SynchronizedCollection( - Collection delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - @SuppressWarnings("unchecked") - @Override protected Collection delegate() { - return (Collection) super.delegate(); - } - - public boolean add(E e) { - synchronized (mutex) { - return delegate().add(e); - } - } - - public boolean addAll(Collection c) { - synchronized (mutex) { - return delegate().addAll(c); - } - } - - public void clear() { - synchronized (mutex) { - delegate().clear(); - } - } - - public boolean contains(Object o) { - synchronized (mutex) { - return delegate().contains(o); - } - } - - public boolean containsAll(Collection c) { - synchronized (mutex) { - return delegate().containsAll(c); - } - } - - public boolean isEmpty() { - synchronized (mutex) { - return delegate().isEmpty(); - } - } - - public Iterator iterator() { - return delegate().iterator(); // manually synchronized - } - - public boolean remove(Object o) { - synchronized (mutex) { - return delegate().remove(o); - } - } - - public boolean removeAll(Collection c) { - synchronized (mutex) { - return delegate().removeAll(c); - } - } - - public boolean retainAll(Collection c) { - synchronized (mutex) { - return delegate().retainAll(c); - } - } - - public int size() { - synchronized (mutex) { - return delegate().size(); - } - } - - public Object[] toArray() { - synchronized (mutex) { - return delegate().toArray(); - } - } - - public T[] toArray(T[] a) { - synchronized (mutex) { - return delegate().toArray(a); - } - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) set backed by the specified set using - * the specified mutex. 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 specified - * mutex when iterating over the returned set:

  {@code
-   *
-   *  Set s = Synchronized.set(new HashSet(), mutex);
-   *  ...
-   *  synchronized (mutex) {
-   *    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. - * - * @param set the set to be wrapped in a synchronized view - * @return a synchronized view of the specified set - */ - public static Set set(Set set, @Nullable Object mutex) { - return new SynchronizedSet(set, mutex); - } - - /** @see Synchronized#set */ - static class SynchronizedSet extends SynchronizedCollection - implements Set { - public SynchronizedSet(Set delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - @Override protected Set delegate() { - return (Set) super.delegate(); - } - - @Override public boolean equals(Object o) { - if (o == this) { - return true; - } - synchronized (mutex) { - return delegate().equals(o); - } - } - - @Override public int hashCode() { - synchronized (mutex) { - return delegate().hashCode(); - } - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) sorted set backed by the specified - * sorted set using the specified mutex. In order to guarantee serial access, - * it is critical that all access to the backing sorted set is - * accomplished through the returned sorted set. - * - *

It is imperative that the user manually synchronize on the specified - * mutex when iterating over the returned sorted set:

  {@code
-   *
-   *  SortedSet s = Synchronized.sortedSet(
-   *      new TreeSet(), mutex);
-   *  ...
-   *  synchronized (mutex) {
-   *    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. - * - * @param set the sorted set to be wrapped in a synchronized view - * @return a synchronized view of the specified sorted set - */ - static SortedSet sortedSet(SortedSet set, @Nullable Object mutex) { - return new SynchronizedSortedSet(set, mutex); - } - - /** @see Synchronized#sortedSet */ - static class SynchronizedSortedSet extends SynchronizedSet - implements SortedSet { - public SynchronizedSortedSet( - SortedSet delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - @Override protected SortedSet delegate() { - return (SortedSet) super.delegate(); - } - - public Comparator comparator() { - synchronized (mutex) { - return delegate().comparator(); - } - } - - public SortedSet subSet(E fromElement, E toElement) { - synchronized (mutex) { - return sortedSet(delegate().subSet(fromElement, toElement), mutex); - } - } - - public SortedSet headSet(E toElement) { - synchronized (mutex) { - return sortedSet(delegate().headSet(toElement), mutex); - } - } - - public SortedSet tailSet(E fromElement) { - synchronized (mutex) { - return sortedSet(delegate().tailSet(fromElement), mutex); - } - } - - public E first() { - synchronized (mutex) { - return delegate().first(); - } - } - - public E last() { - synchronized (mutex) { - return delegate().last(); - } - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) list backed by the specified list - * using the specified mutex. 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 specified - * mutex when iterating over the returned list:

  {@code
-   *
-   *  List l = Synchronized.list(new ArrayList(), mutex);
-   *  ...
-   *  synchronized (mutex) {
-   *    Iterator i = l.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 implements {@link RandomAccess} if the specified list - * implements {@code RandomAccess}. - * - * @param list the list to be wrapped in a synchronized view - * @return a synchronized view of the specified list - */ - static List list(List list, @Nullable Object mutex) { - return (list instanceof RandomAccess) - ? new SynchronizedRandomAccessList(list, mutex) - : new SynchronizedList(list, mutex); - } - - /** @see Synchronized#list */ - static class SynchronizedList extends SynchronizedCollection - implements List { - public SynchronizedList(List delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - @Override protected List delegate() { - return (List) super.delegate(); - } - - public void add(int index, E element) { - synchronized (mutex) { - delegate().add(index, element); - } - } - - public boolean addAll(int index, Collection c) { - synchronized (mutex) { - return delegate().addAll(index, c); - } - } - - public E get(int index) { - synchronized (mutex) { - return delegate().get(index); - } - } - - public int indexOf(Object o) { - synchronized (mutex) { - return delegate().indexOf(o); - } - } - - public int lastIndexOf(Object o) { - synchronized (mutex) { - return delegate().lastIndexOf(o); - } - } - - public ListIterator listIterator() { - return delegate().listIterator(); // manually synchronized - } - - public ListIterator listIterator(int index) { - return delegate().listIterator(index); // manually synchronized - } - - public E remove(int index) { - synchronized (mutex) { - return delegate().remove(index); - } - } - - public E set(int index, E element) { - synchronized (mutex) { - return delegate().set(index, element); - } - } - - @GwtIncompatible("List.subList") - public List subList(int fromIndex, int toIndex) { - synchronized (mutex) { - return list(Platform.subList(delegate(), fromIndex, toIndex), mutex); - } - } - - @Override public boolean equals(Object o) { - if (o == this) { - return true; - } - synchronized (mutex) { - return delegate().equals(o); - } - } - - @Override public int hashCode() { - synchronized (mutex) { - return delegate().hashCode(); - } - } - - private static final long serialVersionUID = 0; - } - - /** @see Synchronized#list */ - static class SynchronizedRandomAccessList extends SynchronizedList - implements RandomAccess { - public SynchronizedRandomAccessList(List list, @Nullable Object mutex) { - super(list, mutex); - } - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) multiset backed by the specified - * multiset using the specified mutex. In order to guarantee serial access, it - * is critical that all access to the backing multiset is accomplished - * through the returned multiset. - * - *

It is imperative that the user manually synchronize on the specified - * mutex when iterating over the returned multiset:

  {@code
-   *
-   *  Multiset s = Synchronized.multiset(
-   *      HashMultiset.create(), mutex);
-   *  ...
-   *  synchronized (mutex) {
-   *    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. - * - * @param multiset the multiset to be wrapped - * @return a synchronized view of the specified multiset - */ - private static Multiset multiset( - Multiset multiset, @Nullable Object mutex) { - return new SynchronizedMultiset(multiset, mutex); - } - - /** @see Synchronized#multiset */ - static class SynchronizedMultiset extends SynchronizedCollection - implements Multiset { - private transient Set elementSet; - private transient Set> entrySet; - - public SynchronizedMultiset(Multiset delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - @Override protected Multiset delegate() { - return (Multiset) super.delegate(); - } - - public int count(Object o) { - synchronized (mutex) { - return delegate().count(o); - } - } - - public int add(E e, int n) { - synchronized (mutex) { - return delegate().add(e, n); - } - } - - public int remove(Object o, int n) { - synchronized (mutex) { - return delegate().remove(o, n); - } - } - - public int setCount(E element, int count) { - synchronized (mutex) { - return delegate().setCount(element, count); - } - } - - public boolean setCount(E element, int oldCount, int newCount) { - synchronized (mutex) { - return delegate().setCount(element, oldCount, newCount); - } - } - - public Set elementSet() { - synchronized (mutex) { - if (elementSet == null) { - elementSet = typePreservingSet(delegate().elementSet(), mutex); - } - return elementSet; - } - } - - public Set> entrySet() { - synchronized (mutex) { - if (entrySet == null) { - entrySet = typePreservingSet(delegate().entrySet(), mutex); - } - return entrySet; - } - } - - @Override public boolean equals(Object o) { - if (o == this) { - return true; - } - synchronized (mutex) { - return delegate().equals(o); - } - } - - @Override public int hashCode() { - synchronized (mutex) { - return delegate().hashCode(); - } - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) multimap backed by the specified - * multimap using the specified mutex. In order to guarantee serial access, it - * is critical that all access to the backing multimap is accomplished - * through the returned multimap. - * - *

It is imperative that the user manually synchronize on the specified - * mutex when accessing any of the return multimap's collection views: - *

  {@code
-   *
-   *  Multimap m = Synchronized.multimap(
-   *      HashMultimap.create(), mutex);
-   *  ...
-   *  Set s = m.keySet();  // Needn't be in synchronized block
-   *  ...
-   *  synchronized (mutex) {
-   *    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. - * - * @param multimap the multimap to be wrapped in a synchronized view - * @return a synchronized view of the specified multimap - */ - public static Multimap multimap( - Multimap multimap, @Nullable Object mutex) { - return new SynchronizedMultimap(multimap, mutex); - } - - /** @see Synchronized#multimap */ - private static class SynchronizedMultimap extends SynchronizedObject - implements Multimap { - transient Set keySet; - transient Collection valuesCollection; - transient Collection> entries; - transient Map> asMap; - transient Multiset keys; - - @SuppressWarnings("unchecked") - @Override protected Multimap delegate() { - return (Multimap) super.delegate(); - } - - SynchronizedMultimap(Multimap delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - public int size() { - synchronized (mutex) { - return delegate().size(); - } - } - - public boolean isEmpty() { - synchronized (mutex) { - return delegate().isEmpty(); - } - } - - public boolean containsKey(Object key) { - synchronized (mutex) { - return delegate().containsKey(key); - } - } - - public boolean containsValue(Object value) { - synchronized (mutex) { - return delegate().containsValue(value); - } - } - - public boolean containsEntry(Object key, Object value) { - synchronized (mutex) { - return delegate().containsEntry(key, value); - } - } - - public Collection get(K key) { - synchronized (mutex) { - return typePreservingCollection(delegate().get(key), mutex); - } - } - - public boolean put(K key, V value) { - synchronized (mutex) { - return delegate().put(key, value); - } - } - - public boolean putAll(K key, Iterable values) { - synchronized (mutex) { - return delegate().putAll(key, values); - } - } - - public boolean putAll(Multimap multimap) { - synchronized (mutex) { - return delegate().putAll(multimap); - } - } - - public Collection replaceValues(K key, Iterable values) { - synchronized (mutex) { - return delegate().replaceValues(key, values); // copy not synchronized - } - } - - public boolean remove(Object key, Object value) { - synchronized (mutex) { - return delegate().remove(key, value); - } - } - - public Collection removeAll(Object key) { - synchronized (mutex) { - return delegate().removeAll(key); // copy not synchronized - } - } - - public void clear() { - synchronized (mutex) { - delegate().clear(); - } - } - - public Set keySet() { - synchronized (mutex) { - if (keySet == null) { - keySet = typePreservingSet(delegate().keySet(), mutex); - } - return keySet; - } - } - - public Collection values() { - synchronized (mutex) { - if (valuesCollection == null) { - valuesCollection = collection(delegate().values(), mutex); - } - return valuesCollection; - } - } - - public Collection> entries() { - synchronized (mutex) { - if (entries == null) { - entries = typePreservingCollection(delegate().entries(), mutex); - } - return entries; - } - } - - public Map> asMap() { - synchronized (mutex) { - if (asMap == null) { - asMap = new SynchronizedAsMap(delegate().asMap(), mutex); - } - return asMap; - } - } - - public Multiset keys() { - synchronized (mutex) { - if (keys == null) { - keys = multiset(delegate().keys(), mutex); - } - return keys; - } - } - - @Override public boolean equals(Object o) { - if (o == this) { - return true; - } - synchronized (mutex) { - return delegate().equals(o); - } - } - - @Override public int hashCode() { - synchronized (mutex) { - return delegate().hashCode(); - } - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) list multimap backed by the specified - * multimap using the specified mutex. - * - *

You must follow the warnings described for {@link #multimap}. - * - * @param multimap the multimap to be wrapped in a synchronized view - * @return a synchronized view of the specified multimap - */ - public static ListMultimap listMultimap( - ListMultimap multimap, @Nullable Object mutex) { - return new SynchronizedListMultimap(multimap, mutex); - } - - /** @see Synchronized#listMultimap */ - private static class SynchronizedListMultimap - extends SynchronizedMultimap implements ListMultimap { - SynchronizedListMultimap( - ListMultimap delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - @Override protected ListMultimap delegate() { - return (ListMultimap) super.delegate(); - } - @Override public List get(K key) { - synchronized (mutex) { - return list(delegate().get(key), mutex); - } - } - @Override public List removeAll(Object key) { - synchronized (mutex) { - return delegate().removeAll(key); // copy not synchronized - } - } - @Override public List replaceValues( - K key, Iterable values) { - synchronized (mutex) { - return delegate().replaceValues(key, values); // copy not synchronized - } - } - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) set multimap backed by the specified - * multimap using the specified mutex. - * - *

You must follow the warnings described for {@link #multimap}. - * - * @param multimap the multimap to be wrapped in a synchronized view - * @return a synchronized view of the specified multimap - */ - public static SetMultimap setMultimap( - SetMultimap multimap, @Nullable Object mutex) { - return new SynchronizedSetMultimap(multimap, mutex); - } - - /** @see Synchronized#setMultimap */ - private static class SynchronizedSetMultimap - extends SynchronizedMultimap implements SetMultimap { - transient Set> entrySet; - SynchronizedSetMultimap( - SetMultimap delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - @Override protected SetMultimap delegate() { - return (SetMultimap) super.delegate(); - } - @Override public Set get(K key) { - synchronized (mutex) { - return set(delegate().get(key), mutex); - } - } - @Override public Set removeAll(Object key) { - synchronized (mutex) { - return delegate().removeAll(key); // copy not synchronized - } - } - @Override public Set replaceValues( - K key, Iterable values) { - synchronized (mutex) { - return delegate().replaceValues(key, values); // copy not synchronized - } - } - @Override public Set> entries() { - synchronized (mutex) { - if (entrySet == null) { - entrySet = set(delegate().entries(), mutex); - } - return entrySet; - } - } - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) sorted set multimap backed by the - * specified multimap using the specified mutex. - * - *

You must follow the warnings described for {@link #multimap}. - * - * @param multimap the multimap to be wrapped in a synchronized view - * @return a synchronized view of the specified multimap - */ - public static SortedSetMultimap sortedSetMultimap( - SortedSetMultimap multimap, @Nullable Object mutex) { - return new SynchronizedSortedSetMultimap(multimap, mutex); - } - - /** @see Synchronized#sortedSetMultimap */ - private static class SynchronizedSortedSetMultimap - extends SynchronizedSetMultimap implements SortedSetMultimap { - SynchronizedSortedSetMultimap( - SortedSetMultimap delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - @Override protected SortedSetMultimap delegate() { - return (SortedSetMultimap) super.delegate(); - } - @Override public SortedSet get(K key) { - synchronized (mutex) { - return sortedSet(delegate().get(key), mutex); - } - } - @Override public SortedSet removeAll(Object key) { - synchronized (mutex) { - return delegate().removeAll(key); // copy not synchronized - } - } - @Override public SortedSet replaceValues( - K key, Iterable values) { - synchronized (mutex) { - return delegate().replaceValues(key, values); // copy not synchronized - } - } - public Comparator valueComparator() { - synchronized (mutex) { - return delegate().valueComparator(); - } - } - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) collection backed by the specified - * collection using the specified mutex. 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 specified - * mutex when iterating over the returned collection:

  {@code
-   *
-   *  Collection s = Synchronized.typePreservingCollection(
-   *      new HashSet(), mutex);
-   *  ...
-   *  synchronized (mutex) {
-   *    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. - * - *

If the specified collection is a {@code SortedSet}, {@code Set} or - * {@code List}, this method will behave identically to {@link #sortedSet}, - * {@link #set} or {@link #list} respectively, in that order of specificity. - * - * @param collection the collection to be wrapped in a synchronized view - * @return a synchronized view of the specified collection - */ - private static Collection typePreservingCollection( - Collection collection, @Nullable Object mutex) { - if (collection instanceof SortedSet) { - return sortedSet((SortedSet) collection, mutex); - } else if (collection instanceof Set) { - return set((Set) collection, mutex); - } else if (collection instanceof List) { - return list((List) collection, mutex); - } else { - return collection(collection, mutex); - } - } - - /** - * Returns a synchronized (thread-safe) set backed by the specified set using - * the specified mutex. 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 specified - * mutex when iterating over the returned collection:

  {@code
-   *
-   *  Set s = Synchronized.typePreservingSet(
-   *      new HashSet(), mutex);
-   *  ...
-   *  synchronized (mutex) {
-   *    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. - * - *

If the specified collection is a {@code SortedSet} this method will - * behave identically to {@link #sortedSet}. - * - * @param set the set to be wrapped in a synchronized view - * @return a synchronized view of the specified set - */ - public static Set typePreservingSet( - Set set, @Nullable Object mutex) { - if (set instanceof SortedSet) { - return sortedSet((SortedSet) set, mutex); - } else { - return set(set, mutex); - } - } - - /** @see Synchronized#multimap */ - static class SynchronizedAsMapEntries - extends SynchronizedSet>> { - public SynchronizedAsMapEntries( - Set>> delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - @Override public Iterator>> iterator() { - // Must be manually synchronized. - final Iterator>> iterator = super.iterator(); - return new ForwardingIterator>>() { - @Override protected Iterator>> delegate() { - return iterator; - } - - @Override public Map.Entry> next() { - final Map.Entry> entry = iterator.next(); - return new ForwardingMapEntry>() { - @Override protected Map.Entry> delegate() { - return entry; - } - @Override public Collection getValue() { - return typePreservingCollection(entry.getValue(), mutex); - } - }; - } - }; - } - - // See Collections.CheckedMap.CheckedEntrySet for details on attacks. - - @Override public Object[] toArray() { - synchronized (mutex) { - return ObjectArrays.toArrayImpl(delegate()); - } - } - @Override public T[] toArray(T[] array) { - synchronized (mutex) { - return ObjectArrays.toArrayImpl(delegate(), array); - } - } - @Override public boolean contains(Object o) { - synchronized (mutex) { - return Maps.containsEntryImpl(delegate(), o); - } - } - @Override public boolean containsAll(Collection c) { - synchronized (mutex) { - return Collections2.containsAll(delegate(), c); - } - } - @Override public boolean equals(Object o) { - if (o == this) { - return true; - } - synchronized (mutex) { - return Collections2.setEquals(delegate(), o); - } - } - @Override public boolean remove(Object o) { - synchronized (mutex) { - return Maps.removeEntryImpl(delegate(), o); - } - } - @Override public boolean removeAll(Collection c) { - synchronized (mutex) { - return Iterators.removeAll(delegate().iterator(), c); - } - } - @Override public boolean retainAll(Collection c) { - synchronized (mutex) { - return Iterators.retainAll(delegate().iterator(), c); - } - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) map backed by the specified map using - * the specified mutex. 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 specified - * mutex when accessing any of the return map's collection views: - *

  {@code
-   *
-   *  Map m = Synchronized.map(
-   *      new HashMap(), mutex);
-   *  ...
-   *  Set s = m.keySet();  // Needn't be in synchronized block
-   *  ...
-   *  synchronized (mutex) {
-   *    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. - * - * @param map the map to be wrapped in a synchronized view - * @return a synchronized view of the specified map - */ - public static Map map(Map map, @Nullable Object mutex) { - return new SynchronizedMap(map, mutex); - } - - /** @see Synchronized#map */ - static class SynchronizedMap extends SynchronizedObject - implements Map { - private transient Set keySet; - private transient Collection values; - private transient Set> entrySet; - - public SynchronizedMap(Map delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - @SuppressWarnings("unchecked") - @Override protected Map delegate() { - return (Map) super.delegate(); - } - - public void clear() { - synchronized (mutex) { - delegate().clear(); - } - } - - public boolean containsKey(Object key) { - synchronized (mutex) { - return delegate().containsKey(key); - } - } - - public boolean containsValue(Object value) { - synchronized (mutex) { - return delegate().containsValue(value); - } - } - - public Set> entrySet() { - synchronized (mutex) { - if (entrySet == null) { - entrySet = set(delegate().entrySet(), mutex); - } - return entrySet; - } - } - - public V get(Object key) { - synchronized (mutex) { - return delegate().get(key); - } - } - - public boolean isEmpty() { - synchronized (mutex) { - return delegate().isEmpty(); - } - } - - public Set keySet() { - synchronized (mutex) { - if (keySet == null) { - keySet = set(delegate().keySet(), mutex); - } - return keySet; - } - } - - public V put(K key, V value) { - synchronized (mutex) { - return delegate().put(key, value); - } - } - - public void putAll(Map map) { - synchronized (mutex) { - delegate().putAll(map); - } - } - - public V remove(Object key) { - synchronized (mutex) { - return delegate().remove(key); - } - } - - public int size() { - synchronized (mutex) { - return delegate().size(); - } - } - - public Collection values() { - synchronized (mutex) { - if (values == null) { - values = collection(delegate().values(), mutex); - } - return values; - } - } - - @Override public boolean equals(Object o) { - if (o == this) { - return true; - } - synchronized (mutex) { - return delegate().equals(o); - } - } - - @Override public int hashCode() { - synchronized (mutex) { - return delegate().hashCode(); - } - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a synchronized (thread-safe) bimap backed by the specified bimap - * using the specified mutex. In order to guarantee serial access, it is - * critical that all access to the backing bimap is accomplished - * through the returned bimap. - * - *

It is imperative that the user manually synchronize on the specified - * mutex when accessing any of the return bimap's collection views: - *

  {@code
-   *
-   *  BiMap m = Synchronized.biMap(
-   *      HashBiMap.create(), mutex);
-   *  ...
-   *  Set s = m.keySet();  // Needn't be in synchronized block
-   *  ...
-   *  synchronized (mutex) {
-   *    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. - * - * @param bimap the bimap to be wrapped in a synchronized view - * @return a synchronized view of the specified bimap - */ - public static BiMap biMap( - BiMap bimap, @Nullable Object mutex) { - return new SynchronizedBiMap(bimap, mutex, null); - } - - /** @see Synchronized#biMap */ - static class SynchronizedBiMap extends SynchronizedMap - implements BiMap, Serializable { - private transient Set valueSet; - private transient BiMap inverse; - - public SynchronizedBiMap( - BiMap delegate, @Nullable Object mutex, - @Nullable BiMap inverse) { - super(delegate, mutex); - this.inverse = inverse; - } - - @Override protected BiMap delegate() { - return (BiMap) super.delegate(); - } - - @Override public Set values() { - synchronized (mutex) { - if (valueSet == null) { - valueSet = set(delegate().values(), mutex); - } - return valueSet; - } - } - - public V forcePut(K key, V value) { - synchronized (mutex) { - return delegate().forcePut(key, value); - } - } - - public BiMap inverse() { - synchronized (mutex) { - if (inverse == null) { - inverse - = new SynchronizedBiMap(delegate().inverse(), mutex, this); - } - return inverse; - } - } - - private static final long serialVersionUID = 0; - } - - /** @see SynchronizedMultimap#asMap */ - static class SynchronizedAsMap - extends SynchronizedMap> { - private transient Set>> asMapEntrySet; - private transient Collection> asMapValues; - - public SynchronizedAsMap( - Map> delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - @Override public Collection get(Object key) { - synchronized (mutex) { - Collection collection = super.get(key); - return (collection == null) ? null - : typePreservingCollection(collection, mutex); - } - } - - @Override public Set>> entrySet() { - synchronized (mutex) { - if (asMapEntrySet == null) { - asMapEntrySet = new SynchronizedAsMapEntries( - delegate().entrySet(), mutex); - } - return asMapEntrySet; - } - } - - @Override public Collection> values() { - synchronized (mutex) { - if (asMapValues == null) { - asMapValues - = new SynchronizedAsMapValues(delegate().values(), mutex); - } - return asMapValues; - } - } - - @Override public boolean containsValue(Object o) { - // values() and its contains() method are both synchronized. - return values().contains(o); - } - - private static final long serialVersionUID = 0; - } - - /** @see SynchronizedMultimap#asMap */ - static class SynchronizedAsMapValues - extends SynchronizedCollection> { - SynchronizedAsMapValues( - Collection> delegate, @Nullable Object mutex) { - super(delegate, mutex); - } - - @Override public Iterator> iterator() { - // Must be manually synchronized. - final Iterator> iterator = super.iterator(); - return new ForwardingIterator>() { - @Override protected Iterator> delegate() { - return iterator; - } - @Override public Collection next() { - return typePreservingCollection(iterator.next(), mutex); - } - }; - } - - private static final long serialVersionUID = 0; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/TreeMultimap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/TreeMultimap.java deleted file mode 100644 index 47ed50852c7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/TreeMultimap.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.*; - -import static org.elasticsearch.util.base.Preconditions.*; - -/** - * Implementation of {@code Multimap} whose keys and values are ordered by - * their natural ordering or by supplied comparators. In all cases, this - * implementation uses {@link Comparable#compareTo} or {@link - * Comparator#compare} instead of {@link Object#equals} to determine - * equivalence of instances. - * - *

Warning: The comparators or comparables used must be consistent - * with equals as explained by the {@link Comparable} class specification. - * Otherwise, the resulting multiset will violate the general contract of {@link - * SetMultimap}, which it is specified in terms of {@link Object#equals}. - * - *

The collections returned by {@code keySet} and {@code asMap} iterate - * through the keys according to the key comparator ordering or the natural - * ordering of the keys. Similarly, {@code get}, {@code removeAll}, and {@code - * replaceValues} return collections that iterate through the values according - * to the value comparator ordering or the natural ordering of the values. The - * collections generated by {@code entries}, {@code keys}, and {@code values} - * iterate across the keys according to the above key ordering, and for each - * key they iterate across the values according to the value ordering. - * - *

The multimap does not store duplicate key-value pairs. Adding a new - * key-value pair equal to an existing key-value pair has no effect. - * - *

Depending on the comparators, null keys and values may or may not be - * supported. The natural ordering does not support nulls. All optional multimap - * methods are supported, and all returned views are modifiable. - * - *

This class is not threadsafe when any concurrent operations update the - * multimap. Concurrent read operations will work correctly. To allow concurrent - * update operations, wrap your multimap with a call to {@link - * Multimaps#synchronizedSortedSetMultimap}. - * - * @author Jared Levy - */ -@GwtCompatible(serializable = true) -public class TreeMultimap extends AbstractSortedSetMultimap { - private transient Comparator keyComparator; - private transient Comparator valueComparator; - - /** - * Creates an empty {@code TreeMultimap} ordered by the natural ordering of - * its keys and values. - */ - @SuppressWarnings("unchecked") // eclipse doesn't like the raw Comparable - public static - TreeMultimap create() { - return new TreeMultimap(Ordering.natural(), Ordering.natural()); - } - - /** - * Creates an empty {@code TreeMultimap} instance using explicit comparators. - * Neither comparator may be null; use {@link Ordering#natural()} to specify - * natural order. - * - * @param keyComparator the comparator that determines the key ordering - * @param valueComparator the comparator that determines the value ordering - */ - public static TreeMultimap create( - Comparator keyComparator, - Comparator valueComparator) { - return new TreeMultimap(checkNotNull(keyComparator), - checkNotNull(valueComparator)); - } - - /** - * Constructs a {@code TreeMultimap}, ordered by the natural ordering of its - * keys and values, with the same mappings as the specified multimap. - * - * @param multimap the multimap whose contents are copied to this multimap - */ - @SuppressWarnings("unchecked") // eclipse doesn't like the raw Comparable - public static - TreeMultimap create(Multimap multimap) { - return new TreeMultimap(Ordering.natural(), Ordering.natural(), - multimap); - } - - // Used by the TreeMultimap serialization test. - TreeMultimap() { - this(null, null); - } - - // Must be package-private so multimaps with null comparators can be - // serialized (which can be created with Multimaps.newTreeMultimap()). Once - // that method is removed, this constructor can be made private. - TreeMultimap(@Nullable Comparator keyComparator, - @Nullable Comparator valueComparator) { - super((keyComparator == null) - ? new TreeMap>() - : new TreeMap>(keyComparator)); - this.keyComparator = keyComparator; - this.valueComparator = valueComparator; - } - - private TreeMultimap(Comparator keyComparator, - Comparator valueComparator, - Multimap multimap) { - this(keyComparator, valueComparator); - putAll(multimap); - } - - /** - * {@inheritDoc} - * - *

Creates an empty {@code TreeSet} for a collection of values for one key. - * - * @return a new {@code TreeSet} containing a collection of values for one - * key - */ - @Override SortedSet createCollection() { - return (valueComparator == null) - ? new TreeSet() : new TreeSet(valueComparator); - } - - /** - * Returns the comparator that orders the multimap keys. - */ - public Comparator keyComparator() { - return keyComparator; - } - - public Comparator valueComparator() { - return valueComparator; - } - - /** - * {@inheritDoc} - * - *

Because a {@code TreeMultimap} has unique sorted keys, this method - * returns a {@link SortedSet}, instead of the {@link Set} specified in the - * {@link Multimap} interface. - */ - @Override public SortedSet keySet() { - return (SortedSet) super.keySet(); - } - - /** - * {@inheritDoc} - * - *

Because a {@code TreeMultimap} has unique sorted keys, this method - * returns a {@link SortedMap}, instead of the {@link java.util.Map} specified - * in the {@link Multimap} interface. - */ - @Override public SortedMap> asMap() { - return (SortedMap>) super.asMap(); - } - - /** - * @serialData key comparator, value comparator, number of distinct keys, and - * then for each distinct key: the key, number of values for that key, and - * key values - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(keyComparator()); - stream.writeObject(valueComparator()); - Serialization.writeMultimap(this, stream); - } - - @SuppressWarnings("unchecked") // reading data stored by writeObject - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - keyComparator = (Comparator) stream.readObject(); - valueComparator = (Comparator) stream.readObject(); - setMap(new TreeMap>(keyComparator)); - Serialization.populateMultimap(this, stream); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/TreeMultiset.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/TreeMultiset.java deleted file mode 100644 index 4c826515305..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/TreeMultiset.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * A multiset which maintains the ordering of its elements, according to either - * their natural order or an explicit {@link Comparator}. In all cases, this - * implementation uses {@link Comparable#compareTo} or {@link - * Comparator#compare} instead of {@link Object#equals} to determine - * equivalence of instances. - * - *

Warning: The comparison must be consistent with equals as - * explained by the {@link Comparable} class specification. Otherwise, the - * resulting multiset will violate the {@link Collection} contract, which it is - * specified in terms of {@link Object#equals}. - * - * @author Neal Kanodia - * @author Jared Levy - */ -@GwtCompatible -@SuppressWarnings("serial") // we're overriding default serialization -public final class TreeMultiset extends AbstractMapBasedMultiset { - - /** - * Creates a new, empty multiset, sorted according to the elements' natural - * order. All elements inserted into the multiset must implement the - * {@code Comparable} interface. Furthermore, all such elements must be - * mutually comparable: {@code e1.compareTo(e2)} must not throw a - * {@code ClassCastException} for any elements {@code e1} and {@code e2} in - * the multiset. If the user attempts to add an element to the multiset that - * violates this constraint (for example, the user attempts to add a string - * element to a set whose elements are integers), the {@code add(Object)} - * call will throw a {@code ClassCastException}. - * - *

The type specification is {@code }, instead of the - * more specific {@code >}, to support - * classes defined without generics. - */ - @SuppressWarnings("unchecked") // eclipse doesn't like the raw Comparable - public static TreeMultiset create() { - return new TreeMultiset(); - } - - /** - * Creates a new, empty multiset, sorted according to the specified - * comparator. All elements inserted into the multiset must be mutually - * comparable by the specified comparator: {@code comparator.compare(e1, - * e2)} must not throw a {@code ClassCastException} for any elements {@code - * e1} and {@code e2} in the multiset. If the user attempts to add an element - * to the multiset that violates this constraint, the {@code add(Object)} call - * will throw a {@code ClassCastException}. - * - * @param comparator the comparator that will be used to sort this multiset. A - * null value indicates that the elements' natural ordering should - * be used. - */ - public static TreeMultiset create(Comparator comparator) { - return new TreeMultiset(comparator); - } - - /** - * Creates an empty multiset containing the given initial elements, sorted - * according to the elements' natural order. - * - *

The type specification is {@code }, instead of the - * more specific {@code >}, to support - * classes defined without generics. - */ - @SuppressWarnings("unchecked") // eclipse doesn't like the raw Comparable - public static TreeMultiset create( - Iterable elements) { - TreeMultiset multiset = create(); - Iterables.addAll(multiset, elements); - return multiset; - } - - private TreeMultiset() { - super(new TreeMap()); - } - - private TreeMultiset(Comparator comparator) { - super(new TreeMap(comparator)); - } - - /** - * {@inheritDoc} - * - *

In {@code TreeMultiset}, the return type of this method is narrowed - * from {@link Set} to {@link SortedSet}. - */ - @Override public SortedSet elementSet() { - return (SortedSet) super.elementSet(); - } - - @Override public int count(@Nullable Object element) { - try { - return super.count(element); - } catch (NullPointerException e) { - return 0; - } catch (ClassCastException e) { - return 0; - } - } - - @Override Set createElementSet() { - return new SortedMapBasedElementSet( - (SortedMap) backingMap()); - } - - private class SortedMapBasedElementSet extends MapBasedElementSet - implements SortedSet { - - SortedMapBasedElementSet(SortedMap map) { - super(map); - } - - SortedMap sortedMap() { - return (SortedMap) getMap(); - } - - public Comparator comparator() { - return sortedMap().comparator(); - } - - public E first() { - return sortedMap().firstKey(); - } - - public E last() { - return sortedMap().lastKey(); - } - - public SortedSet headSet(E toElement) { - return new SortedMapBasedElementSet(sortedMap().headMap(toElement)); - } - - public SortedSet subSet(E fromElement, E toElement) { - return new SortedMapBasedElementSet( - sortedMap().subMap(fromElement, toElement)); - } - - public SortedSet tailSet(E fromElement) { - return new SortedMapBasedElementSet(sortedMap().tailMap(fromElement)); - } - - @Override public boolean remove(Object element) { - try { - return super.remove(element); - } catch (NullPointerException e) { - return false; - } catch (ClassCastException e) { - return false; - } - } - } - - /* - * TODO: Decide whether entrySet() should return entries with an equals() - * method that calls the comparator to compare the two keys. If that change - * is made, AbstractMultiset.equals() can simply check whether two multisets - * have equal entry sets. - */ - - /** - * @serialData the comparator, the number of distinct elements, the first - * element, its count, the second element, its count, and so on - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - stream.writeObject(elementSet().comparator()); - Serialization.writeMultiset(this, stream); - } - - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - @SuppressWarnings("unchecked") // reading data stored by writeObject - Comparator comparator - = (Comparator) stream.readObject(); - setBackingMap(new TreeMap(comparator)); - Serialization.populateMultiset(this, stream); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/UnmodifiableIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/UnmodifiableIterator.java deleted file mode 100644 index c484aa99d21..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/UnmodifiableIterator.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.util.Iterator; - -/** - * An iterator that does not support {@link #remove}. - * - * @author Jared Levy - */ -@GwtCompatible -public abstract class UnmodifiableIterator implements Iterator { - /** - * Guaranteed to throw an exception and leave the underlying data unmodified. - * - * @throws UnsupportedOperationException always - */ - public final void remove() { - throw new UnsupportedOperationException(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/UsingToStringOrdering.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/UsingToStringOrdering.java deleted file mode 100644 index 531c19dcf62..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/UsingToStringOrdering.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.collect; - -import org.elasticsearch.util.annotations.GwtCompatible; - -import java.io.Serializable; - -/** An ordering that uses the reverse of the natural order of the values. */ -@GwtCompatible(serializable = true) -final class UsingToStringOrdering - extends Ordering implements Serializable { - static final UsingToStringOrdering INSTANCE = new UsingToStringOrdering(); - - public int compare(Object left, Object right) { - return left.toString().compareTo(right.toString()); - } - - // preserve singleton-ness, so equals() and hashCode() work correctly - private Object readResolve() { - return INSTANCE; - } - - @Override public String toString() { - return "Ordering.usingToString()"; - } - - private UsingToStringOrdering() {} - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/package-info.java deleted file mode 100644 index e7ccd9e59f5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/collect/package-info.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * This package contains generic collection interfaces and implementations, and - * other utilities for working with collections. - * - *

Collection Types

- * - *
- *
{@link org.elasticsearch.util.collect.Multimap} - *
A new type, which is similar to {@link java.util.Map}, but may contain - * multiple entries with the same key. Some behaviors of - * {@link org.elasticsearch.util.collect.Multimap} are left unspecified and are - * provided only by the subtypes mentioned below. - * - *
{@link org.elasticsearch.util.collect.SetMultimap} - *
An extension of {@link org.elasticsearch.util.collect.Multimap} which has - * order-independent equality and does not allow duplicate entries; that is, - * while a key may appear twice in a {@code SetMultimap}, each must map to a - * different value. {@code SetMultimap} takes its name from the fact that - * the {@linkplain org.elasticsearch.util.collect.SetMultimap#get collection of - * values} associated with a given key fulfills the {@link java.util.Set} - * contract. - * - *
{@link org.elasticsearch.util.collect.ListMultimap} - *
An extension of {@link org.elasticsearch.util.collect.Multimap} which permits - * duplicate entries, supports random access of values for a particular key, - * and has partially order-dependent equality as defined by - * {@link org.elasticsearch.util.collect.ListMultimap#equals(Object)}. {@code - * ListMultimap} takes its name from the fact that the {@linkplain - * org.elasticsearch.util.collect.ListMultimap#get collection of values} - * associated with a given key fulfills the {@link java.util.List} contract. - * - *
{@link org.elasticsearch.util.collect.SortedSetMultimap} - *
An extension of {@link org.elasticsearch.util.collect.SetMultimap} for which - * the {@linkplain org.elasticsearch.util.collect.SortedSetMultimap#get - * collection values} associated with a given key is a - * {@link java.util.SortedSet}. - * - *
{@link org.elasticsearch.util.collect.Multiset} - *
An extension of {@link java.util.Collection} that may contain duplicate - * values like a {@link java.util.List}, yet has order-independent equality - * like a {@link java.util.Set}. One typical use for a multiset is to - * represent a histogram. - * - *
{@link org.elasticsearch.util.collect.BiMap} - *
An extension of {@link java.util.Map} that guarantees the uniqueness of - * its values as well as that of its keys. This is sometimes called an - * "invertible map," since the restriction on values enables it to support - * an {@linkplain org.elasticsearch.util.collect.BiMap#inverse inverse view} -- - * which is another instance of {@code BiMap}. - * - *
{@link org.elasticsearch.util.collect.ClassToInstanceMap} - *
An extension of {@link java.util.Map} that associates a raw type with an - * instance of that type. - *
- * - *

Collection Implementations

- * - *

of {@link java.util.List}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableList} - * - * - *

of {@link java.util.Set}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableSet} - * - * - *

of {@link java.util.SortedSet}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableSortedSet} - *
- * - *

of {@link java.util.Map}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableMap} - *
{@link org.elasticsearch.util.collect.MapMaker} (produced by) - * - * - *

of {@link java.util.SortedMap}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableSortedMap} - *
- * - *

of {@link org.elasticsearch.util.collect.Multimap}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableMultimap} - *
{@link org.elasticsearch.util.collect.Multimaps#newMultimap} - *
- * - *

of {@link org.elasticsearch.util.collect.ListMultimap}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableListMultimap} - *
{@link org.elasticsearch.util.collect.ArrayListMultimap} - *
{@link org.elasticsearch.util.collect.LinkedListMultimap} - *
{@link org.elasticsearch.util.collect.Multimaps#newListMultimap} - *
- * - *

of {@link org.elasticsearch.util.collect.SetMultimap}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableSetMultimap} - *
{@link org.elasticsearch.util.collect.HashMultimap} - *
{@link org.elasticsearch.util.collect.LinkedHashMultimap} - *
{@link org.elasticsearch.util.collect.TreeMultimap} - *
{@link org.elasticsearch.util.collect.Multimaps#newSetMultimap} - *
{@link org.elasticsearch.util.collect.Multimaps#newSortedSetMultimap} - *
- * - *

of {@link org.elasticsearch.util.collect.Multiset}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableMultiset} - *
{@link org.elasticsearch.util.collect.ConcurrentHashMultiset} - *
{@link org.elasticsearch.util.collect.HashMultiset} - *
{@link org.elasticsearch.util.collect.LinkedHashMultiset} - *
{@link org.elasticsearch.util.collect.TreeMultiset} - *
{@link org.elasticsearch.util.collect.EnumMultiset} - *
- * - *

of {@link org.elasticsearch.util.collect.BiMap}

- *
- *
{@link org.elasticsearch.util.collect.HashBiMap} - *
{@link org.elasticsearch.util.collect.EnumBiMap} - *
{@link org.elasticsearch.util.collect.EnumHashBiMap} - *
- * - *

of {@link org.elasticsearch.util.collect.ClassToInstanceMap}

- *
- *
{@link org.elasticsearch.util.collect.ImmutableClassToInstanceMap} - *
{@link org.elasticsearch.util.collect.MutableClassToInstanceMap} - *
- * - *

Skeletal implementations

- *
- *
{@link org.elasticsearch.util.collect.AbstractIterator} - *
{@link org.elasticsearch.util.collect.UnmodifiableIterator} - *
- * - *

Utilities

- * - *
- *
{@link org.elasticsearch.util.collect.Collections2} - *
{@link org.elasticsearch.util.collect.Iterators} - *
{@link org.elasticsearch.util.collect.Iterables} - *
{@link org.elasticsearch.util.collect.Lists} - *
{@link org.elasticsearch.util.collect.Maps} - *
{@link org.elasticsearch.util.collect.Ordering} - *
{@link org.elasticsearch.util.collect.Sets} - *
{@link org.elasticsearch.util.collect.Multisets} - *
{@link org.elasticsearch.util.collect.Multimaps} - *
{@link org.elasticsearch.util.collect.ObjectArrays} - *
- - *

Forwarding collections

- * - *
- *
{@link org.elasticsearch.util.collect.ForwardingCollection } - *
{@link org.elasticsearch.util.collect.ForwardingConcurrentMap } - *
{@link org.elasticsearch.util.collect.ForwardingIterator } - *
{@link org.elasticsearch.util.collect.ForwardingList } - *
{@link org.elasticsearch.util.collect.ForwardingListIterator } - *
{@link org.elasticsearch.util.collect.ForwardingMap } - *
{@link org.elasticsearch.util.collect.ForwardingMapEntry } - *
{@link org.elasticsearch.util.collect.ForwardingMultimap } - *
{@link org.elasticsearch.util.collect.ForwardingMultiset } - *
{@link org.elasticsearch.util.collect.ForwardingObject } - *
{@link org.elasticsearch.util.collect.ForwardingQueue } - *
{@link org.elasticsearch.util.collect.ForwardingSet } - *
{@link org.elasticsearch.util.collect.ForwardingSortedMap } - *
{@link org.elasticsearch.util.collect.ForwardingSortedSet } - *
- */ -package org.elasticsearch.util.collect; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/concurrent/DynamicExecutors.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/concurrent/DynamicExecutors.java index 0ed02ece3f5..9eb72f53568 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/concurrent/DynamicExecutors.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/concurrent/DynamicExecutors.java @@ -19,7 +19,7 @@ package org.elasticsearch.util.concurrent; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.settings.Settings; import java.util.concurrent.*; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/Decorators.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/Decorators.java deleted file mode 100644 index 3f8d20d4891..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/Decorators.java +++ /dev/null @@ -1,478 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - - -import org.elasticsearch.util.gnu.trove.decorator.*; - -import java.util.Map; -import java.util.Set; - - -/** - * This is a static utility class that provides functions for simplifying creation of - * decorators. - * - * @author Robert D. Eden - * @since Trove 2.1 - */ -public class Decorators { - // Hide the constructor - - private Decorators() { - } - - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TDoubleDoubleHashMap map) { - return new TDoubleDoubleHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TDoubleFloatHashMap map) { - return new TDoubleFloatHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TDoubleIntHashMap map) { - return new TDoubleIntHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TDoubleLongHashMap map) { - return new TDoubleLongHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TDoubleByteHashMap map) { - return new TDoubleByteHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TDoubleShortHashMap map) { - return new TDoubleShortHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TFloatDoubleHashMap map) { - return new TFloatDoubleHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TFloatFloatHashMap map) { - return new TFloatFloatHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TFloatIntHashMap map) { - return new TFloatIntHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TFloatLongHashMap map) { - return new TFloatLongHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TFloatByteHashMap map) { - return new TFloatByteHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TFloatShortHashMap map) { - return new TFloatShortHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TIntDoubleHashMap map) { - return new TIntDoubleHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TIntFloatHashMap map) { - return new TIntFloatHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TIntIntHashMap map) { - return new TIntIntHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TIntLongHashMap map) { - return new TIntLongHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TIntByteHashMap map) { - return new TIntByteHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TIntShortHashMap map) { - return new TIntShortHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TLongDoubleHashMap map) { - return new TLongDoubleHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TLongFloatHashMap map) { - return new TLongFloatHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TLongIntHashMap map) { - return new TLongIntHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TLongLongHashMap map) { - return new TLongLongHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TLongByteHashMap map) { - return new TLongByteHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TLongShortHashMap map) { - return new TLongShortHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TByteDoubleHashMap map) { - return new TByteDoubleHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TByteFloatHashMap map) { - return new TByteFloatHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TByteIntHashMap map) { - return new TByteIntHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TByteLongHashMap map) { - return new TByteLongHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TByteByteHashMap map) { - return new TByteByteHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TByteShortHashMap map) { - return new TByteShortHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TShortDoubleHashMap map) { - return new TShortDoubleHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TShortFloatHashMap map) { - return new TShortFloatHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TShortIntHashMap map) { - return new TShortIntHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TShortLongHashMap map) { - return new TShortLongHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TShortByteHashMap map) { - return new TShortByteHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TShortShortHashMap map) { - return new TShortShortHashMapDecorator(map); - } - - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TObjectDoubleHashMap map) { - return new TObjectDoubleHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TObjectFloatHashMap map) { - return new TObjectFloatHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TObjectIntHashMap map) { - return new TObjectIntHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TObjectLongHashMap map) { - return new TObjectLongHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TObjectByteHashMap map) { - return new TObjectByteHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TObjectShortHashMap map) { - return new TObjectShortHashMapDecorator(map); - } - - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TDoubleObjectHashMap map) { - return new TDoubleObjectHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TFloatObjectHashMap map) { - return new TFloatObjectHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TIntObjectHashMap map) { - return new TIntObjectHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TLongObjectHashMap map) { - return new TLongObjectHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TByteObjectHashMap map) { - return new TByteObjectHashMapDecorator(map); - } - - /** - * Wrap the given map in a decorator that uses the standard {@link java.util.Map Map} - * interface. - */ - public static Map wrap(TShortObjectHashMap map) { - return new TShortObjectHashMapDecorator(map); - } - - - /** - * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} - * interface. - */ - public static Set wrap(TDoubleHashSet set) { - return new TDoubleHashSetDecorator(set); - } - - /** - * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} - * interface. - */ - public static Set wrap(TFloatHashSet set) { - return new TFloatHashSetDecorator(set); - } - - /** - * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} - * interface. - */ - public static Set wrap(TIntHashSet set) { - return new TIntHashSetDecorator(set); - } - - /** - * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} - * interface. - */ - public static Set wrap(TLongHashSet set) { - return new TLongHashSetDecorator(set); - } - - /** - * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} - * interface. - */ - public static Set wrap(TByteHashSet set) { - return new TByteHashSetDecorator(set); - } - - /** - * Wrap the given set in a decorator that uses the standard {@link java.util.Set Set} - * interface. - */ - public static Set wrap(TShortHashSet set) { - return new TShortHashSetDecorator(set); - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/HashFunctions.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/HashFunctions.java deleted file mode 100644 index 08601a2281b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/HashFunctions.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -/** - * 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) { - // Multiply by prime to make sure hash can't be negative (see Knuth v3, p. 515-516) - return value * 31; - } - - /** - * Returns a hashcode for the specified value. - * - * @return a hash code value for the specified value. - */ - public static int hash(long value) { - // Multiply by prime to make sure hash can't be negative (see Knuth v3, p. 515-516) - return ((int) (value ^ (value >>> 32))) * 31; - } - - /** - * 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)}. - */ - static int fastCeil(float v) { - int possible_result = (int) v; - if (v - possible_result > 0) possible_result++; - return possible_result; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/PrimeFinder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/PrimeFinder.java deleted file mode 100644 index 1c819e56f9b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/PrimeFinder.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/SerializationProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/SerializationProcedure.java deleted file mode 100644 index 53c97cdd9bc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/SerializationProcedure.java +++ /dev/null @@ -1,715 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.IOException; -import java.io.ObjectOutput; - - -/** - * Implementation of the variously typed procedure interfaces that supports - * writing the arguments to the procedure out on an ObjectOutputStream. - * In the case of two-argument procedures, the arguments are written out - * in the order received. - *

- *

- * Any IOException is trapped here so that it can be rethrown in a writeObject - * method. - *

- *

- * Created: Sun Jul 7 00:14:18 2002 - * - * @author Eric D. Friedman - * @version $Id: SerializationProcedure.java,v 1.5 2006/11/10 23:27:54 robeden Exp $ - */ - -class SerializationProcedure implements TDoubleDoubleProcedure, - TDoubleFloatProcedure, - TDoubleIntProcedure, - TDoubleLongProcedure, - TDoubleShortProcedure, - TDoubleByteProcedure, - TDoubleObjectProcedure, - TDoubleProcedure, - TFloatDoubleProcedure, - TFloatFloatProcedure, - TFloatIntProcedure, - TFloatLongProcedure, - TFloatShortProcedure, - TFloatByteProcedure, - TFloatObjectProcedure, - TFloatProcedure, - TIntDoubleProcedure, - TIntFloatProcedure, - TIntIntProcedure, - TIntLongProcedure, - TIntShortProcedure, - TIntByteProcedure, - TIntObjectProcedure, - TIntProcedure, - TLongDoubleProcedure, - TLongFloatProcedure, - TLongIntProcedure, - TLongLongProcedure, - TLongShortProcedure, - TLongByteProcedure, - TLongObjectProcedure, - TLongProcedure, - TShortDoubleProcedure, - TShortFloatProcedure, - TShortIntProcedure, - TShortLongProcedure, - TShortShortProcedure, - TShortByteProcedure, - TShortObjectProcedure, - TShortProcedure, - TByteDoubleProcedure, - TByteFloatProcedure, - TByteIntProcedure, - TByteLongProcedure, - TByteShortProcedure, - TByteByteProcedure, - TByteObjectProcedure, - TByteProcedure, - TObjectDoubleProcedure, - TObjectFloatProcedure, - TObjectIntProcedure, - TObjectLongProcedure, - TObjectShortProcedure, - TObjectByteProcedure, - TObjectObjectProcedure, - TObjectProcedure { - - private final ObjectOutput stream; - IOException exception; - - SerializationProcedure(ObjectOutput stream) { - this.stream = stream; - } - - public boolean execute(byte val) { - try { - stream.writeByte(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(short val) { - try { - stream.writeShort(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(int val) { - try { - stream.writeInt(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(double val) { - try { - stream.writeDouble(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(long val) { - try { - stream.writeLong(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(float val) { - try { - stream.writeFloat(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(Object val) { - try { - stream.writeObject(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(Object key, Object val) { - try { - stream.writeObject(key); - stream.writeObject(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(Object key, byte val) { - try { - stream.writeObject(key); - stream.writeByte(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(Object key, short val) { - try { - stream.writeObject(key); - stream.writeShort(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(Object key, int val) { - try { - stream.writeObject(key); - stream.writeInt(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(Object key, long val) { - try { - stream.writeObject(key); - stream.writeLong(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(Object key, double val) { - try { - stream.writeObject(key); - stream.writeDouble(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(Object key, float val) { - try { - stream.writeObject(key); - stream.writeFloat(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(int key, byte val) { - try { - stream.writeInt(key); - stream.writeByte(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(int key, short val) { - try { - stream.writeInt(key); - stream.writeShort(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(int key, Object val) { - try { - stream.writeInt(key); - stream.writeObject(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(int key, int val) { - try { - stream.writeInt(key); - stream.writeInt(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(int key, long val) { - try { - stream.writeInt(key); - stream.writeLong(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(int key, double val) { - try { - stream.writeInt(key); - stream.writeDouble(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(int key, float val) { - try { - stream.writeInt(key); - stream.writeFloat(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(long key, Object val) { - try { - stream.writeLong(key); - stream.writeObject(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(long key, byte val) { - try { - stream.writeLong(key); - stream.writeByte(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(long key, short val) { - try { - stream.writeLong(key); - stream.writeShort(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(long key, int val) { - try { - stream.writeLong(key); - stream.writeInt(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(long key, long val) { - try { - stream.writeLong(key); - stream.writeLong(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(long key, double val) { - try { - stream.writeLong(key); - stream.writeDouble(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(long key, float val) { - try { - stream.writeLong(key); - stream.writeFloat(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(double key, Object val) { - try { - stream.writeDouble(key); - stream.writeObject(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(double key, byte val) { - try { - stream.writeDouble(key); - stream.writeByte(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(double key, short val) { - try { - stream.writeDouble(key); - stream.writeShort(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(double key, int val) { - try { - stream.writeDouble(key); - stream.writeInt(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(double key, long val) { - try { - stream.writeDouble(key); - stream.writeLong(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(double key, double val) { - try { - stream.writeDouble(key); - stream.writeDouble(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(double key, float val) { - try { - stream.writeDouble(key); - stream.writeFloat(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(float key, Object val) { - try { - stream.writeFloat(key); - stream.writeObject(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(float key, byte val) { - try { - stream.writeFloat(key); - stream.writeByte(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(float key, short val) { - try { - stream.writeFloat(key); - stream.writeShort(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(float key, int val) { - try { - stream.writeFloat(key); - stream.writeInt(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(float key, long val) { - try { - stream.writeFloat(key); - stream.writeLong(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(float key, double val) { - try { - stream.writeFloat(key); - stream.writeDouble(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(float key, float val) { - try { - stream.writeFloat(key); - stream.writeFloat(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(byte key, Object val) { - try { - stream.writeByte(key); - stream.writeObject(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(byte key, byte val) { - try { - stream.writeByte(key); - stream.writeByte(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(byte key, short val) { - try { - stream.writeByte(key); - stream.writeShort(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(byte key, int val) { - try { - stream.writeByte(key); - stream.writeInt(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(byte key, long val) { - try { - stream.writeByte(key); - stream.writeLong(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(byte key, double val) { - try { - stream.writeByte(key); - stream.writeDouble(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(byte key, float val) { - try { - stream.writeByte(key); - stream.writeFloat(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(short key, Object val) { - try { - stream.writeShort(key); - stream.writeObject(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(short key, byte val) { - try { - stream.writeShort(key); - stream.writeByte(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(short key, short val) { - try { - stream.writeShort(key); - stream.writeShort(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(short key, int val) { - try { - stream.writeShort(key); - stream.writeInt(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(short key, long val) { - try { - stream.writeShort(key); - stream.writeLong(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(short key, double val) { - try { - stream.writeShort(key); - stream.writeDouble(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } - - public boolean execute(short key, float val) { - try { - stream.writeShort(key); - stream.writeFloat(val); - } catch (IOException e) { - this.exception = e; - return false; - } - return true; - } -}// SerializationProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteArrayList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteArrayList.java deleted file mode 100644 index 964f49a281e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteArrayList.java +++ /dev/null @@ -1,935 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; -import java.util.Random; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * A resizable, array-backed list of byte primitives. - *

- * Created: Sat Dec 29 14:21:12 2001 - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TByteArrayList implements Externalizable, Cloneable { - 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 = 10; - - /** - * Creates a new TByteArrayList instance with the - * default capacity. - */ - public TByteArrayList() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TByteArrayList instance with the - * specified capacity. - * - * @param capacity an int value - */ - public TByteArrayList(int capacity) { - _data = new byte[capacity]; - _pos = 0; - } - - /** - * Creates a new TByteArrayList instance whose - * capacity is the greater of the length of values and - * DEFAULT_CAPACITY and whose initial contents are the specified - * values. - * - * @param values an byte[] value - */ - public TByteArrayList(byte[] values) { - this(Math.max(values.length, DEFAULT_CAPACITY)); - add(values); - } - - // 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. - * - * @param capacity an int value - */ - 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; - } - } - - /** - * Returns the number of values in the list. - * - * @return the number of values in the list. - */ - public int size() { - return _pos; - } - - /** - * Tests whether this list contains any values. - * - * @return true if the list is empty. - */ - 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()]; - toNativeArray(tmp, 0, tmp.length); - _data = tmp; - } - } - - // modifying - - /** - * Adds val to the end of the list, growing as needed. - * - * @param val an byte value - */ - public void add(byte val) { - ensureCapacity(_pos + 1); - _data[_pos++] = 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) { - add(vals, 0, vals.length); - } - - /** - * 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) { - ensureCapacity(_pos + length); - System.arraycopy(vals, offset, _data, _pos, length); - _pos += 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) { - 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++; - } - - /** - * 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) { - insert(offset, values, 0, values.length); - } - - /** - * 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) { - 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; - } - - /** - * Returns the value at the specified offset. - * - * @param offset an int value - * @return an byte value - */ - 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. - * - * @param offset an int value - * @return an byte value - */ - public byte getQuick(int offset) { - return _data[offset]; - } - - /** - * Sets the value at the specified offset. - * - * @param offset an int value - * @param val an byte value - */ - public void set(int offset, byte val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - _data[offset] = val; - } - - /** - * 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 getSet(int offset, byte val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - byte old = _data[offset]; - _data[offset] = val; - return old; - } - - /** - * 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) { - set(offset, values, 0, values.length); - } - - /** - * 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) { - 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. - * - * @param offset an int value - * @param val an byte value - */ - public void setQuick(int offset, byte val) { - _data[offset] = val; - } - - /** - * Flushes the internal state of the list, resetting the capacity - * to the default. - */ - public void clear() { - clear(DEFAULT_CAPACITY); - } - - /** - * Flushes the internal state of the list, setting the capacity of - * the empty list to capacity. - * - * @param capacity an int value - */ - 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 clear} method if you want to recyle a list without - * allocating new backing arrays. - * - * @see #clear - */ - public void reset() { - _pos = 0; - fill((byte) 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 clear} method if you want to recyle a list - * without allocating new backing arrays. This method differs - * from {@link #reset reset} in that it does not clear the old - * values in the backing array. Thus, it is possible for {@link - * #getQuick getQuick} to return stale data if this method is used - * and the caller is careless about bounds checking. - * - * @see #reset - * @see #clear - * @see #getQuick - */ - public void resetQuick() { - _pos = 0; - } - - /** - * Removes the value at offset from the list. - * - * @param offset an int value - * @return the value previously stored at offset. - */ - public byte remove(int offset) { - byte old = get(offset); - remove(offset, 1); - return old; - } - - /** - * 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) { - 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 - } - - /** - * Transform each value in the list using the specified function. - * - * @param function a TByteFunction value - */ - public void transformValues(TByteFunction function) { - for (int i = _pos; i-- > 0;) { - _data[i] = function.execute(_data[i]); - } - } - - /** - * Reverse the order of the elements in the list. - */ - public void reverse() { - reverse(0, _pos); - } - - /** - * 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) { - 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); - } - } - - /** - * Shuffle the elements of the list using the specified random - * number generator. - * - * @param rand a Random value - */ - 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 final void swap(int i, int j) { - byte tmp = _data[i]; - _data[i] = _data[j]; - _data[j] = tmp; - } - - // copying - - /** - * Returns a clone of this list. Since this is a primitive - * collection, this will be a deep clone. - * - * @return a deep clone of the list. - */ - public Object clone() { - TByteArrayList list = null; - try { - list = (TByteArrayList) super.clone(); - list._data = toNativeArray(); - } catch (CloneNotSupportedException e) { - // it's supported - } // end of try-catch - return list; - } - - - /** - * 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 TByteArrayList 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; - } - - - /** - * Copies the contents of the list into a native array. - * - * @return an byte[] value - */ - public byte[] toNativeArray() { - return toNativeArray(0, _pos); - } - - /** - * 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[] toNativeArray(int offset, int len) { - byte[] rv = new byte[len]; - toNativeArray(rv, offset, len); - return rv; - } - - /** - * Copies a slice of the list into a native array. - * - * @param dest the array to copy into. - * @param offset the offset of the first value to copy - * @param len the number of values to copy. - */ - public void toNativeArray(byte[] dest, int offset, int len) { - if (len == 0) { - return; // nothing to copy - } - if (offset < 0 || offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - System.arraycopy(_data, offset, dest, 0, len); - } - - // comparing - - /** - * Compares this list to another list, value by value. - * - * @param other the object to compare against - * @return true if other is a TByteArrayList and has exactly the - * same values. - */ - public boolean equals(Object other) { - if (other == this) { - return true; - } else if (other instanceof TByteArrayList) { - TByteArrayList that = (TByteArrayList) other; - if (that.size() != this.size()) { - return false; - } else { - for (int i = _pos; i-- > 0;) { - if (this._data[i] != that._data[i]) { - return false; - } - } - return true; - } - } else { - return false; - } - } - - public int hashCode() { - int h = 0; - for (int i = _pos; i-- > 0;) { - h = 37 * h + HashFunctions.hash(_data[i]); - } - return h; - } - - // procedures - - /** - * 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. - */ - public boolean forEach(TByteProcedure procedure) { - for (int i = 0; i < _pos; i++) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - /** - * 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) { - for (int i = _pos; i-- > 0;) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - // sorting - - /** - * Sort the values in the list (ascending) using the Sun quicksort - * implementation. - * - * @see java.util.Arrays#sort - */ - public void sort() { - Arrays.sort(_data, 0, _pos); - } - - /** - * 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) { - Arrays.sort(_data, fromIndex, toIndex); - } - - // filling - - /** - * Fills every slot in the list with the specified value. - * - * @param val the value to use when filling - */ - public void fill(byte val) { - Arrays.fill(_data, 0, _pos, 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) { - if (toIndex > _pos) { - ensureCapacity(toIndex); - _pos = toIndex; - } - Arrays.fill(_data, fromIndex, toIndex, val); - } - - // searching - - /** - * 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) { - return binarySearch(value, 0, _pos); - } - - /** - * 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) { - 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. - } - - /** - * 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) { - return indexOf(0, 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) { - for (int i = offset; i < _pos; i++) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * 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) { - return lastIndexOf(_pos, 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) { - for (int i = offset; i-- > 0;) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * Searches the list for value - * - * @param value an byte value - * @return true if value is in the list. - */ - public boolean contains(byte value) { - return lastIndexOf(value) >= 0; - } - - /** - * 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 TByteArrayList 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; - } - - /** - * 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 TByteArrayList 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; - } - - /** - * Finds the maximum value in the list. - * - * @return the largest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - /** - * Finds the minimum value in the list. - * - * @return the smallest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - // stringification - - /** - * Returns a String representation of the list, front to back. - * - * @return a String value - */ - 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(); - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(1); - - // POSITION - out.writeInt(_pos); - - // ENTRIES - int len = _pos; - out.writeInt(_pos); // Written twice for backwards compatability with - // version 0 - for (int i = 0; i < len; i++) { - out.writeByte(_data[i]); - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // POSITION - _pos = in.readInt(); - - // ENTRIES - int len = in.readInt(); - _data = new byte[len]; - for (int i = 0; i < len; i++) { - _data[i] = in.readByte(); - } - } -} // TByteArrayList diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteHashMap.java deleted file mode 100644 index c445067c4e8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for byte keys and byte values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TByteByteHashMap extends TByteHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TByteByteProcedure PUT_ALL_PROC = new TByteByteProcedure() { - public boolean execute(byte key, byte value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteByteHashMap(TByteHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TByteByteHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteByteHashMap(int initialCapacity, TByteHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TByteByteHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TByteByteHashMap(int initialCapacity, float loadFactor, TByteHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TByteByteHashMap m = (TByteByteHashMap) super.clone(); - m._values = (byte[]) this._values.clone(); - return m; - } - - /** - * @return a TByteByteIterator with access to this map's keys and values - */ - public TByteByteIterator iterator() { - return new TByteByteIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new byte[capacity]; - return capacity; - } - - /** - * 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 (byte)0 if none was found. - */ - public byte put(byte key, byte value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (byte)0 if none was found. - */ - public byte putIfAbsent(byte key, byte value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private byte doPut(byte key, byte value, int index) { - byte previousState; - byte previous = (byte) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TByteByteHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an byte value - * @return the value of key or (byte)0 if no such mapping exists. - */ - public byte get(byte key) { - int index = index(key); - return index < 0 ? (byte) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - byte[] keys = _set; - byte[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (byte) 0); - Arrays.fill(_values, 0, _values.length, (byte) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an byte value - * @return an byte value, or (byte)0 if no mapping for key exists - */ - public byte remove(byte key) { - byte prev = (byte) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TByteByteHashMap)) { - return false; - } - TByteByteHashMap that = (TByteByteHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TByteByteProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(byte key, byte value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TByteByteProcedure { - private final TByteByteHashMap _otherMap; - - EqProcedure(TByteByteHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(byte key, byte value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two bytes for equality. - */ - private final boolean eq(byte v1, byte v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (byte) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public byte[] getValues() { - byte[] vals = new byte[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public byte[] keys(byte[] a) { - int size = size(); - if (a.length < size) { - a = (byte[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - byte[] k = (byte[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - byte[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TByteFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (byte) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public byte adjustOrPutValue(final byte key, final byte adjust_amount, final byte put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - byte key = in.readByte(); - byte val = in.readByte(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TByteByteProcedure() { - private boolean first = true; - - 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(); - } -} // TByteByteHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteIterator.java deleted file mode 100644 index 27d02b25175..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TByteByteIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TByteByteHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TByteByteIterator(TByteByteHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - byte old = value(); - _map._values[_index] = val; - return old; - } -}// TByteByteIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteProcedure.java deleted file mode 100644 index 214aefb1c00..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteByteProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type byte and byte. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TByteByteProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleHashMap.java deleted file mode 100644 index 8b70c91af5b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for byte keys and double values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TByteDoubleHashMap extends TByteHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TByteDoubleProcedure PUT_ALL_PROC = new TByteDoubleProcedure() { - public boolean execute(byte key, double value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteDoubleHashMap(TByteHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TByteDoubleHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteDoubleHashMap(int initialCapacity, TByteHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TByteDoubleHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TByteDoubleHashMap(int initialCapacity, float loadFactor, TByteHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TByteDoubleHashMap m = (TByteDoubleHashMap) super.clone(); - m._values = (double[]) this._values.clone(); - return m; - } - - /** - * @return a TByteDoubleIterator with access to this map's keys and values - */ - public TByteDoubleIterator iterator() { - return new TByteDoubleIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new double[capacity]; - return capacity; - } - - /** - * 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 (byte)0 if none was found. - */ - public double put(byte key, double value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (byte)0 if none was found. - */ - public double putIfAbsent(byte key, double value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private double doPut(byte key, double value, int index) { - byte previousState; - double previous = (double) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TByteDoubleHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an byte value - * @return the value of key or (byte)0 if no such mapping exists. - */ - public double get(byte key) { - int index = index(key); - return index < 0 ? (double) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - byte[] keys = _set; - double[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (byte) 0); - Arrays.fill(_values, 0, _values.length, (double) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an byte value - * @return an double value, or (byte)0 if no mapping for key exists - */ - public double remove(byte key) { - double prev = (double) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TByteDoubleHashMap)) { - return false; - } - TByteDoubleHashMap that = (TByteDoubleHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TByteDoubleProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(byte key, double value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TByteDoubleProcedure { - private final TByteDoubleHashMap _otherMap; - - EqProcedure(TByteDoubleHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(byte key, double value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two doubles for equality. - */ - private final boolean eq(double v1, double v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (double) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public double[] getValues() { - double[] vals = new double[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public byte[] keys(byte[] a) { - int size = size(); - if (a.length < size) { - a = (byte[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - byte[] k = (byte[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - double[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TDoubleFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (double) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public double adjustOrPutValue(final byte key, final double adjust_amount, final double put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - byte key = in.readByte(); - double val = in.readDouble(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TByteDoubleProcedure() { - private boolean first = true; - - 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(); - } -} // TByteDoubleHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleIterator.java deleted file mode 100644 index 3753757272b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TByteDoubleIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TByteDoubleHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TByteDoubleIterator(TByteDoubleHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - double old = value(); - _map._values[_index] = val; - return old; - } -}// TByteDoubleIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleProcedure.java deleted file mode 100644 index 913aa8075df..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteDoubleProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type byte and double. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TByteDoubleProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatHashMap.java deleted file mode 100644 index aa8b2570efc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for byte keys and float values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TByteFloatHashMap extends TByteHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TByteFloatProcedure PUT_ALL_PROC = new TByteFloatProcedure() { - public boolean execute(byte key, float value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteFloatHashMap(TByteHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TByteFloatHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteFloatHashMap(int initialCapacity, TByteHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TByteFloatHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TByteFloatHashMap(int initialCapacity, float loadFactor, TByteHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TByteFloatHashMap m = (TByteFloatHashMap) super.clone(); - m._values = (float[]) this._values.clone(); - return m; - } - - /** - * @return a TByteFloatIterator with access to this map's keys and values - */ - public TByteFloatIterator iterator() { - return new TByteFloatIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new float[capacity]; - return capacity; - } - - /** - * 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 (byte)0 if none was found. - */ - public float put(byte key, float value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (byte)0 if none was found. - */ - public float putIfAbsent(byte key, float value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private float doPut(byte key, float value, int index) { - byte previousState; - float previous = (float) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TByteFloatHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an byte value - * @return the value of key or (byte)0 if no such mapping exists. - */ - public float get(byte key) { - int index = index(key); - return index < 0 ? (float) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - byte[] keys = _set; - float[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (byte) 0); - Arrays.fill(_values, 0, _values.length, (float) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an byte value - * @return an float value, or (byte)0 if no mapping for key exists - */ - public float remove(byte key) { - float prev = (float) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TByteFloatHashMap)) { - return false; - } - TByteFloatHashMap that = (TByteFloatHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TByteFloatProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(byte key, float value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TByteFloatProcedure { - private final TByteFloatHashMap _otherMap; - - EqProcedure(TByteFloatHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(byte key, float value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two floats for equality. - */ - private final boolean eq(float v1, float v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (float) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public float[] getValues() { - float[] vals = new float[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public byte[] keys(byte[] a) { - int size = size(); - if (a.length < size) { - a = (byte[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - byte[] k = (byte[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - float[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TFloatFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (float) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public float adjustOrPutValue(final byte key, final float adjust_amount, final float put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - byte key = in.readByte(); - float val = in.readFloat(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TByteFloatProcedure() { - private boolean first = true; - - 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(); - } -} // TByteFloatHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatIterator.java deleted file mode 100644 index 27b7b1214d9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TByteFloatIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TByteFloatHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TByteFloatIterator(TByteFloatHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - float old = value(); - _map._values[_index] = val; - return old; - } -}// TByteFloatIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatProcedure.java deleted file mode 100644 index 4b8201bc778..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFloatProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type byte and float. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TByteFloatProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFunction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFunction.java deleted file mode 100644 index 78fbc029628..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteFunction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for functions that accept and return one byte primitive. - *

- * Created: Mon Nov 5 22:19:36 2001 - * - * @author Eric D. Friedman - * @version $Id: PFunction.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TByteFunction { - /** - * Execute this function with value - * - * @param value a byte input - * @return a byte result - */ - public byte execute(byte value); -}// TByteFunction diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHash.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHash.java deleted file mode 100644 index e24c0ede49d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHash.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: PHash.template,v 1.2 2007/06/29 22:39:46 robeden Exp $ - */ - -abstract public class TByteHash extends TPrimitiveHash implements TByteHashingStrategy { - - /** - * the set of bytes - */ - protected transient byte[] _set; - - /** - * strategy used to hash values in this collection - */ - protected TByteHashingStrategy _hashingStrategy; - - /** - * Creates a new TByteHash instance with the default - * capacity and load factor. - */ - public TByteHash() { - super(); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * Creates a new TByteHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteHash(TByteHashingStrategy strategy) { - super(); - this._hashingStrategy = strategy; - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteHash(int initialCapacity, TByteHashingStrategy strategy) { - super(initialCapacity); - this._hashingStrategy = strategy; - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TByteHash(int initialCapacity, float loadFactor, TByteHashingStrategy strategy) { - super(initialCapacity, loadFactor); - this._hashingStrategy = strategy; - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TByteHash h = (TByteHash) super.clone(); - h._set = (byte[]) this._set.clone(); - return h; - } - - /** - * 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 = 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 - */ - protected void removeAt(int index) { - _set[index] = (byte) 0; - 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 = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - // see Knuth, p. 529 - probe = 1 + (hash % (length - 2)); - - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)); - } - - return states[index] == FREE ? -1 : index; - } - - /** - * 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 insertionIndex(byte val) { - int hash, probe, index, length; - - final byte[] states = _states; - final byte[] set = _set; - length = states.length; - hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] == FREE) { - return index; // empty, all done - } else if (states[index] == FULL && set[index] == val) { - 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 (states[index] != REMOVED) { - // starting at the natural offset, probe until we find an - // offset that isn't full. - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] == FULL && set[index] != val); - } - - // 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 (states[index] == REMOVED) { - int firstRemoved = index; - while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - index -= probe; - if (index < 0) { - index += length; - } - } - return states[index] == FULL ? -index - 1 : firstRemoved; - } - // if it's full, the key is already stored - return states[index] == FULL ? -index - 1 : index; - } - } - - /** - * Default implementation of TByteHashingStrategy: - * delegates hashing to HashFunctions.hash(byte). - * - * @param val the value to hash - * @return the hashcode. - */ - public final int computeHashCode(byte val) { - return HashFunctions.hash(val); - } -} // TByteHash diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHashSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHashSet.java deleted file mode 100644 index 02c874f7a40..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHashSet.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed set implementation for byte primitives. - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TByteHashSet extends TByteHash implements 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 TByteHashSet 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 TByteHashSet(int initialCapacity, float loadFactor) { - super(initialCapacity, loadFactor); - } - - /** - * Creates a new TByteHashSet instance containing the - * elements of array. - * - * @param array an array of byte primitives - */ - public TByteHashSet(byte[] array) { - this(array.length); - addAll(array); - } - - /** - * Creates a new TByteHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteHashSet(TByteHashingStrategy strategy) { - super(strategy); - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteHashSet(int initialCapacity, TByteHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TByteHashSet(int initialCapacity, float loadFactor, TByteHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * Creates a new TByteHashSet instance containing the - * elements of array. - * - * @param array an array of byte primitives - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteHashSet(byte[] array, TByteHashingStrategy strategy) { - this(array.length, strategy); - addAll(array); - } - - /** - * @return a TByteIterator with access to the values in this set - */ - public TByteIterator iterator() { - return new TByteIterator(this); - } - - /** - * Inserts a value into the set. - * - * @param val an byte value - * @return true if the set was modified by the add operation - */ - public boolean add(byte val) { - int index = insertionIndex(val); - - if (index < 0) { - return false; // already present in set, nothing to add - } - - byte previousState = _states[index]; - _set[index] = val; - _states[index] = FULL; - postInsertHook(previousState == FREE); - - return true; // yes, we added something - } - - /** - * Expands the set to accommodate new values. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _states[index] = FULL; - } - } - } - - /** - * Returns a new array containing the values in the set. - * - * @return an byte[] value - */ - public byte[] toArray() { - byte[] result = new byte[size()]; - 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; - } - - /** - * Empties the set. - */ - public void clear() { - super.clear(); - byte[] set = _set; - byte[] states = _states; - - for (int i = set.length; i-- > 0;) { - set[i] = (byte) 0; - states[i] = FREE; - } - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TByteHashSet)) { - return false; - } - final TByteHashSet that = (TByteHashSet) other; - if (that.size() != this.size()) { - return false; - } - return forEach(new TByteProcedure() { - public final boolean execute(byte value) { - return that.contains(value); - } - }); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEach(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TByteProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(byte key) { - h += _hashingStrategy.computeHashCode(key); - return true; - } - } - - /** - * Removes val from the set. - * - * @param val an byte value - * @return true if the set was modified by the remove operation. - */ - public boolean remove(byte val) { - int index = index(val); - if (index >= 0) { - removeAt(index); - return true; - } - return false; - } - - /** - * Tests the set to determine if all of the elements in - * array are present. - * - * @param array an array of byte primitives. - * @return true if all elements were present in the set. - */ - public boolean containsAll(byte[] array) { - for (int i = array.length; i-- > 0;) { - if (!contains(array[i])) { - return false; - } - } - return true; - } - - /** - * Adds all of the elements in array to the set. - * - * @param array an array of byte primitives. - * @return true if the set was modified by the add all operation. - */ - public boolean addAll(byte[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (add(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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. - */ - public boolean removeAll(byte[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (remove(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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 - */ - 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)) { - remove(set[i]); - changed = true; - } - } - return changed; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEach(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - - // ENTRIES - setUp(size); - while (size-- > 0) { - byte val = in.readByte(); - add(val); - } - } -} // TByteHashSet diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHashingStrategy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHashingStrategy.java deleted file mode 100644 index 65a1128f3b4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteHashingStrategy.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Serializable; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface to support pluggable hashing strategies in maps and sets. - * Implementors can use this interface to make the trove hashing - * algorithms use an optimal strategy when computing hashcodes. - *

- * Created: Sun Nov 4 08:56:06 2001 - * - * @author Eric D. Friedman - * @version $Id: PHashingStrategy.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TByteHashingStrategy extends Serializable { - /** - * Computes a hash code for the specified byte. Implementors - * can use the byte's own value or a custom scheme designed to - * minimize collisions for a known set of input. - * - * @param val byte for which the hashcode is to be computed - * @return the hashCode - */ - public int computeHashCode(byte val); -} // TByteHashingStrategy diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntHashMap.java deleted file mode 100644 index 4cf714fd38d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for byte keys and int values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TByteIntHashMap extends TByteHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TByteIntProcedure PUT_ALL_PROC = new TByteIntProcedure() { - public boolean execute(byte key, int value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteIntHashMap(TByteHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TByteIntHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteIntHashMap(int initialCapacity, TByteHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TByteIntHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TByteIntHashMap(int initialCapacity, float loadFactor, TByteHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TByteIntHashMap m = (TByteIntHashMap) super.clone(); - m._values = (int[]) this._values.clone(); - return m; - } - - /** - * @return a TByteIntIterator with access to this map's keys and values - */ - public TByteIntIterator iterator() { - return new TByteIntIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new int[capacity]; - return capacity; - } - - /** - * 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 (byte)0 if none was found. - */ - public int put(byte key, int value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (byte)0 if none was found. - */ - public int putIfAbsent(byte key, int value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private int doPut(byte key, int value, int index) { - byte previousState; - int previous = (int) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TByteIntHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an byte value - * @return the value of key or (byte)0 if no such mapping exists. - */ - public int get(byte key) { - int index = index(key); - return index < 0 ? (int) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - byte[] keys = _set; - int[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (byte) 0); - Arrays.fill(_values, 0, _values.length, (int) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an byte value - * @return an int value, or (byte)0 if no mapping for key exists - */ - public int remove(byte key) { - int prev = (int) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TByteIntHashMap)) { - return false; - } - TByteIntHashMap that = (TByteIntHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TByteIntProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(byte key, int value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TByteIntProcedure { - private final TByteIntHashMap _otherMap; - - EqProcedure(TByteIntHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(byte key, int value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two ints for equality. - */ - private final boolean eq(int v1, int v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (int) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public int[] getValues() { - int[] vals = new int[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public byte[] keys(byte[] a) { - int size = size(); - if (a.length < size) { - a = (byte[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - byte[] k = (byte[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - int[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TIntFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (int) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public int adjustOrPutValue(final byte key, final int adjust_amount, final int put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - byte key = in.readByte(); - int val = in.readInt(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TByteIntProcedure() { - private boolean first = true; - - 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(); - } -} // TByteIntHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntIterator.java deleted file mode 100644 index aea8aa1e7c8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TByteIntIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TByteIntHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TByteIntIterator(TByteIntHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - int old = value(); - _map._values[_index] = val; - return old; - } -}// TByteIntIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntProcedure.java deleted file mode 100644 index efd3d462b92..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIntProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type byte and int. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TByteIntProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIterator.java deleted file mode 100644 index cd7a4885fb1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteIterator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Iterator for byte collections. - * - * @author Eric D. Friedman - * @version $Id: PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TByteIterator extends TPrimitiveIterator { - /** - * the collection on which the iterator operates - */ - private final TByteHash _hash; - - /** - * Creates a TByteIterator for the elements in the specified collection. - */ - public TByteIterator(TByteHash hash) { - super(hash); - this._hash = hash; - } - - /** - * Advances the iterator to the next element in the underlying collection - * and returns it. - * - * @return the next byte in the collection - * @throws NoSuchElementException if the iterator is already exhausted - */ - public byte next() { - moveToNextIndex(); - return _hash._set[_index]; - } -}// TByteIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongHashMap.java deleted file mode 100644 index 2f971ba9b4b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for byte keys and long values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TByteLongHashMap extends TByteHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TByteLongProcedure PUT_ALL_PROC = new TByteLongProcedure() { - public boolean execute(byte key, long value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteLongHashMap(TByteHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TByteLongHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteLongHashMap(int initialCapacity, TByteHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TByteLongHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TByteLongHashMap(int initialCapacity, float loadFactor, TByteHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TByteLongHashMap m = (TByteLongHashMap) super.clone(); - m._values = (long[]) this._values.clone(); - return m; - } - - /** - * @return a TByteLongIterator with access to this map's keys and values - */ - public TByteLongIterator iterator() { - return new TByteLongIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new long[capacity]; - return capacity; - } - - /** - * 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 (byte)0 if none was found. - */ - public long put(byte key, long value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (byte)0 if none was found. - */ - public long putIfAbsent(byte key, long value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private long doPut(byte key, long value, int index) { - byte previousState; - long previous = (long) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TByteLongHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an byte value - * @return the value of key or (byte)0 if no such mapping exists. - */ - public long get(byte key) { - int index = index(key); - return index < 0 ? (long) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - byte[] keys = _set; - long[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (byte) 0); - Arrays.fill(_values, 0, _values.length, (long) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an byte value - * @return an long value, or (byte)0 if no mapping for key exists - */ - public long remove(byte key) { - long prev = (long) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TByteLongHashMap)) { - return false; - } - TByteLongHashMap that = (TByteLongHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TByteLongProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(byte key, long value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TByteLongProcedure { - private final TByteLongHashMap _otherMap; - - EqProcedure(TByteLongHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(byte key, long value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two longs for equality. - */ - private final boolean eq(long v1, long v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (long) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public long[] getValues() { - long[] vals = new long[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public byte[] keys(byte[] a) { - int size = size(); - if (a.length < size) { - a = (byte[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - byte[] k = (byte[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - long[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TLongFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (long) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public long adjustOrPutValue(final byte key, final long adjust_amount, final long put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - byte key = in.readByte(); - long val = in.readLong(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TByteLongProcedure() { - private boolean first = true; - - 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(); - } -} // TByteLongHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongIterator.java deleted file mode 100644 index 8df153f45eb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TByteLongIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TByteLongHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TByteLongIterator(TByteLongHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - long old = value(); - _map._values[_index] = val; - return old; - } -}// TByteLongIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongProcedure.java deleted file mode 100644 index a96b639da6c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteLongProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type byte and long. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TByteLongProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectHashMap.java deleted file mode 100644 index 91f97d53e4a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectHashMap.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TByteObjectHashMap extends TByteHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TByteObjectProcedure PUT_ALL_PROC = new TByteObjectProcedure() { - public boolean execute(byte key, V value) { - put(key, value); - return true; - } - }; - - - /** - * the values of the map - */ - protected transient V[] _values; - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TByteObjectHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteObjectHashMap(TByteHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TByteObjectHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteObjectHashMap(int initialCapacity, TByteHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TByteObjectHashMap(int initialCapacity, float loadFactor, TByteHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public TByteObjectHashMap clone() { - TByteObjectHashMap m = (TByteObjectHashMap) super.clone(); - m._values = (V[]) this._values.clone(); - return m; - } - - /** - * @return a TByteObjectIterator with access to this map's keys and values - */ - public TByteObjectIterator iterator() { - return new TByteObjectIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = (V[]) new Object[capacity]; - return capacity; - } - - /** - * 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 {@code null} if none was found. - */ - public V put(byte key, V value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 Object value - * @return the previous value associated with key, - * or {@code null} if none was found. - */ - public V putIfAbsent(byte key, V value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private V doPut(byte key, V value, int index) { - byte previousState; - V previous = null; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TByteObjectHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an byte value - * @return the value of key or (byte)0 if no such mapping exists. - */ - public V get(byte key) { - int index = index(key); - return index < 0 ? null : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - byte[] keys = _set; - Object[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (byte) 0); - Arrays.fill(_values, 0, _values.length, null); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an byte value - * @return an Object value or (byte)0 if no such mapping exists. - */ - 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; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TByteObjectHashMap)) { - return false; - } - TByteObjectHashMap that = (TByteObjectHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TByteObjectProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(byte key, Object value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TByteObjectProcedure { - private final TByteObjectHashMap _otherMap; - - EqProcedure(TByteObjectHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(byte key, Object value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two objects for equality. - */ - private final boolean eq(Object o1, Object o2) { - return o1 == o2 || ((o1 != null) && o1.equals(o2)); - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = null; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - * @see #getValues(Object[]) - */ - public Object[] getValues() { - 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; - } - - /** - * Return the values of the map; the runtime type of the returned array is that of - * the specified array. - * - * @param a the array into which the elements of this collection are to be - * stored, if it is big enough; otherwise, a new array of the same - * runtime type is allocated for this purpose. - * @return an array containing the elements of this collection - * @throws ArrayStoreException the runtime type of the specified array is - * not a supertype of the runtime type of every element in this - * collection. - * @throws NullPointerException if the specified array is null. - * @see #getValues() - */ - public T[] getValues(T[] a) { - if (a.length < _size) { - a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), - _size); - } - - V[] v = _values; - byte[] states = _states; - - for (int i = v.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = (T) v[i]; - } - } - return a; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public byte[] keys(byte[] a) { - int size = size(); - if (a.length < size) { - a = (byte[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - byte[] k = (byte[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(V 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 && - val == 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; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * Executes procedure for each key/value entry in the - * map. - * - * @param procedure a TOByteObjectProcedure value - * @return false if the loop over the entries terminated because - * the procedure returned false for some entry. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TObjectFunction value - */ - 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]); - } - } - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - 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); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TByteObjectProcedure() { - private boolean first = true; - - 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectIterator.java deleted file mode 100644 index 64d100b79b7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: P2OIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TByteObjectIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TByteObjectHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TByteObjectIterator(TByteObjectHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - V old = value(); - _map._values[_index] = val; - return old; - } -}// TByteObjectIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectProcedure.java deleted file mode 100644 index 0659fc0f396..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteObjectProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type byte and Object. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2OProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TByteObjectProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteProcedure.java deleted file mode 100644 index 174ed81f9ff..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteProcedure.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures with one byte parameter. - *

- * Created: Mon Nov 5 21:45:49 2001 - * - * @author Eric D. Friedman - * @version $Id: PProcedure.template,v 1.2 2007/11/01 16:08:14 robeden Exp $ - */ - -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); -}// TByteProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortHashMap.java deleted file mode 100644 index 5c52b883419..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for byte keys and short values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TByteShortHashMap extends TByteHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TByteShortProcedure PUT_ALL_PROC = new TByteShortProcedure() { - public boolean execute(byte key, short value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteShortHashMap(TByteHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TByteShortHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TByteShortHashMap(int initialCapacity, TByteHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TByteShortHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TByteShortHashMap(int initialCapacity, float loadFactor, TByteHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TByteShortHashMap m = (TByteShortHashMap) super.clone(); - m._values = (short[]) this._values.clone(); - return m; - } - - /** - * @return a TByteShortIterator with access to this map's keys and values - */ - public TByteShortIterator iterator() { - return new TByteShortIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new short[capacity]; - return capacity; - } - - /** - * 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 (byte)0 if none was found. - */ - public short put(byte key, short value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (byte)0 if none was found. - */ - public short putIfAbsent(byte key, short value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private short doPut(byte key, short value, int index) { - byte previousState; - short previous = (short) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TByteShortHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an byte value - * @return the value of key or (byte)0 if no such mapping exists. - */ - public short get(byte key) { - int index = index(key); - return index < 0 ? (short) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - byte[] keys = _set; - short[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (byte) 0); - Arrays.fill(_values, 0, _values.length, (short) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an byte value - * @return an short value, or (byte)0 if no mapping for key exists - */ - public short remove(byte key) { - short prev = (short) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TByteShortHashMap)) { - return false; - } - TByteShortHashMap that = (TByteShortHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TByteShortProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(byte key, short value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TByteShortProcedure { - private final TByteShortHashMap _otherMap; - - EqProcedure(TByteShortHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(byte key, short value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two shorts for equality. - */ - private final boolean eq(short v1, short v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (short) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public short[] getValues() { - short[] vals = new short[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public byte[] keys(byte[] a) { - int size = size(); - if (a.length < size) { - a = (byte[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - byte[] k = (byte[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - short[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TShortFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (short) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public short adjustOrPutValue(final byte key, final short adjust_amount, final short put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - byte key = in.readByte(); - short val = in.readShort(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TByteShortProcedure() { - private boolean first = true; - - 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(); - } -} // TByteShortHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortIterator.java deleted file mode 100644 index 193bbee5946..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TByteShortIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TByteShortHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TByteShortIterator(TByteShortHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - short old = value(); - _map._values[_index] = val; - return old; - } -}// TByteShortIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortProcedure.java deleted file mode 100644 index 2941284fa76..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteShortProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type byte and short. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TByteShortProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteStack.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteStack.java deleted file mode 100644 index 578f415885b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TByteStack.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -/** - * A stack of byte primitives, backed by a TByteArrayList. - * - * @author Eric D. Friedman, Rob Eden - * @version $Id: PStack.template,v 1.2 2007/02/28 23:03:57 robeden Exp $ - */ - -public class TByteStack { - - /** - * the list used to hold the stack values. - */ - protected TByteArrayList _list; - - public static final int DEFAULT_CAPACITY = TByteArrayList.DEFAULT_CAPACITY; - - /** - * Creates a new TByteStack instance with the default - * capacity. - */ - public TByteStack() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TByteStack instance with the - * specified capacity. - * - * @param capacity the initial depth of the stack - */ - public TByteStack(int capacity) { - _list = new TByteArrayList(capacity); - } - - /** - * Pushes the value onto the top of the stack. - * - * @param val an byte value - */ - public void push(byte val) { - _list.add(val); - } - - /** - * Removes and returns the value at the top of the stack. - * - * @return an byte value - */ - public byte pop() { - return _list.remove(_list.size() - 1); - } - - /** - * Returns the value at the top of the stack. - * - * @return an byte value - */ - public byte peek() { - return _list.get(_list.size() - 1); - } - - /** - * Returns the current depth of the stack. - */ - public int size() { - return _list.size(); - } - - /** - * Clears the stack, reseting its capacity to the default. - */ - public void clear() { - _list.clear(DEFAULT_CAPACITY); - } - - /** - * Clears the stack without releasing its internal capacity allocation. - */ - public void reset() { - _list.reset(); - } - - /** - * 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[] toNativeArray() { - return _list.toNativeArray(); - } - - /** - * 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 toNativeArray(byte[] dest) { - _list.toNativeArray(dest, 0, size()); - } -} // TByteStack diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleArrayList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleArrayList.java deleted file mode 100644 index 35780f46674..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleArrayList.java +++ /dev/null @@ -1,935 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; -import java.util.Random; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * A resizable, array-backed list of double primitives. - *

- * Created: Sat Dec 29 14:21:12 2001 - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TDoubleArrayList implements Externalizable, Cloneable { - 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 = 10; - - /** - * Creates a new TDoubleArrayList instance with the - * default capacity. - */ - public TDoubleArrayList() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TDoubleArrayList instance with the - * specified capacity. - * - * @param capacity an int value - */ - public TDoubleArrayList(int capacity) { - _data = new double[capacity]; - _pos = 0; - } - - /** - * Creates a new TDoubleArrayList instance whose - * capacity is the greater of the length of values and - * DEFAULT_CAPACITY and whose initial contents are the specified - * values. - * - * @param values an double[] value - */ - public TDoubleArrayList(double[] values) { - this(Math.max(values.length, DEFAULT_CAPACITY)); - add(values); - } - - // sizing - - /** - * Grow the internal array as needed to accommodate the specified - * number of elements. The size of the array doubles on each - * resize unless capacity requires more than twice the - * current capacity. - * - * @param capacity an int value - */ - 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; - } - } - - /** - * Returns the number of values in the list. - * - * @return the number of values in the list. - */ - public int size() { - return _pos; - } - - /** - * Tests whether this list contains any values. - * - * @return true if the list is empty. - */ - 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()]; - toNativeArray(tmp, 0, tmp.length); - _data = tmp; - } - } - - // modifying - - /** - * Adds val to the end of the list, growing as needed. - * - * @param val an double value - */ - public void add(double val) { - ensureCapacity(_pos + 1); - _data[_pos++] = 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) { - add(vals, 0, vals.length); - } - - /** - * 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) { - ensureCapacity(_pos + length); - System.arraycopy(vals, offset, _data, _pos, length); - _pos += 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) { - 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++; - } - - /** - * 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) { - insert(offset, values, 0, values.length); - } - - /** - * 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) { - 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; - } - - /** - * Returns the value at the specified offset. - * - * @param offset an int value - * @return an double value - */ - 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. - * - * @param offset an int value - * @return an double value - */ - public double getQuick(int offset) { - return _data[offset]; - } - - /** - * Sets the value at the specified offset. - * - * @param offset an int value - * @param val an double value - */ - public void set(int offset, double val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - _data[offset] = val; - } - - /** - * 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 getSet(int offset, double val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - double old = _data[offset]; - _data[offset] = val; - return old; - } - - /** - * 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) { - set(offset, values, 0, values.length); - } - - /** - * 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) { - 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. - * - * @param offset an int value - * @param val an double value - */ - public void setQuick(int offset, double val) { - _data[offset] = val; - } - - /** - * Flushes the internal state of the list, resetting the capacity - * to the default. - */ - public void clear() { - clear(DEFAULT_CAPACITY); - } - - /** - * Flushes the internal state of the list, setting the capacity of - * the empty list to capacity. - * - * @param capacity an int value - */ - 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 clear} method if you want to recyle a list without - * allocating new backing arrays. - * - * @see #clear - */ - public void reset() { - _pos = 0; - fill((double) 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 clear} method if you want to recyle a list - * without allocating new backing arrays. This method differs - * from {@link #reset reset} in that it does not clear the old - * values in the backing array. Thus, it is possible for {@link - * #getQuick getQuick} to return stale data if this method is used - * and the caller is careless about bounds checking. - * - * @see #reset - * @see #clear - * @see #getQuick - */ - public void resetQuick() { - _pos = 0; - } - - /** - * Removes the value at offset from the list. - * - * @param offset an int value - * @return the value previously stored at offset. - */ - public double remove(int offset) { - double old = get(offset); - remove(offset, 1); - return old; - } - - /** - * 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) { - 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 - } - - /** - * Transform each value in the list using the specified function. - * - * @param function a TDoubleFunction value - */ - public void transformValues(TDoubleFunction function) { - for (int i = _pos; i-- > 0;) { - _data[i] = function.execute(_data[i]); - } - } - - /** - * Reverse the order of the elements in the list. - */ - public void reverse() { - reverse(0, _pos); - } - - /** - * 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) { - 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); - } - } - - /** - * Shuffle the elements of the list using the specified random - * number generator. - * - * @param rand a Random value - */ - 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 final void swap(int i, int j) { - double tmp = _data[i]; - _data[i] = _data[j]; - _data[j] = tmp; - } - - // copying - - /** - * Returns a clone of this list. Since this is a primitive - * collection, this will be a deep clone. - * - * @return a deep clone of the list. - */ - public Object clone() { - TDoubleArrayList list = null; - try { - list = (TDoubleArrayList) super.clone(); - list._data = toNativeArray(); - } catch (CloneNotSupportedException e) { - // it's supported - } // end of try-catch - return list; - } - - - /** - * 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 TDoubleArrayList 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; - } - - - /** - * Copies the contents of the list into a native array. - * - * @return an double[] value - */ - public double[] toNativeArray() { - return toNativeArray(0, _pos); - } - - /** - * 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[] toNativeArray(int offset, int len) { - double[] rv = new double[len]; - toNativeArray(rv, offset, len); - return rv; - } - - /** - * Copies a slice of the list into a native array. - * - * @param dest the array to copy into. - * @param offset the offset of the first value to copy - * @param len the number of values to copy. - */ - public void toNativeArray(double[] dest, int offset, int len) { - if (len == 0) { - return; // nothing to copy - } - if (offset < 0 || offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - System.arraycopy(_data, offset, dest, 0, len); - } - - // comparing - - /** - * Compares this list to another list, value by value. - * - * @param other the object to compare against - * @return true if other is a TDoubleArrayList and has exactly the - * same values. - */ - public boolean equals(Object other) { - if (other == this) { - return true; - } else if (other instanceof TDoubleArrayList) { - TDoubleArrayList that = (TDoubleArrayList) other; - if (that.size() != this.size()) { - return false; - } else { - for (int i = _pos; i-- > 0;) { - if (this._data[i] != that._data[i]) { - return false; - } - } - return true; - } - } else { - return false; - } - } - - public int hashCode() { - int h = 0; - for (int i = _pos; i-- > 0;) { - h = 37 * h + HashFunctions.hash(_data[i]); - } - return h; - } - - // procedures - - /** - * 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. - */ - public boolean forEach(TDoubleProcedure procedure) { - for (int i = 0; i < _pos; i++) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - /** - * 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) { - for (int i = _pos; i-- > 0;) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - // sorting - - /** - * Sort the values in the list (ascending) using the Sun quicksort - * implementation. - * - * @see java.util.Arrays#sort - */ - public void sort() { - Arrays.sort(_data, 0, _pos); - } - - /** - * 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) { - Arrays.sort(_data, fromIndex, toIndex); - } - - // filling - - /** - * Fills every slot in the list with the specified value. - * - * @param val the value to use when filling - */ - public void fill(double val) { - Arrays.fill(_data, 0, _pos, 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) { - if (toIndex > _pos) { - ensureCapacity(toIndex); - _pos = toIndex; - } - Arrays.fill(_data, fromIndex, toIndex, val); - } - - // searching - - /** - * 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) { - return binarySearch(value, 0, _pos); - } - - /** - * 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) { - 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. - } - - /** - * 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) { - return indexOf(0, 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) { - for (int i = offset; i < _pos; i++) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * 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) { - return lastIndexOf(_pos, 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) { - for (int i = offset; i-- > 0;) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * Searches the list for value - * - * @param value an double value - * @return true if value is in the list. - */ - public boolean contains(double value) { - return lastIndexOf(value) >= 0; - } - - /** - * 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 TDoubleArrayList 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; - } - - /** - * 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 TDoubleArrayList 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; - } - - /** - * Finds the maximum value in the list. - * - * @return the largest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - /** - * Finds the minimum value in the list. - * - * @return the smallest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - // stringification - - /** - * Returns a String representation of the list, front to back. - * - * @return a String value - */ - 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(); - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(1); - - // POSITION - out.writeInt(_pos); - - // ENTRIES - int len = _pos; - out.writeInt(_pos); // Written twice for backwards compatability with - // version 0 - for (int i = 0; i < len; i++) { - out.writeDouble(_data[i]); - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // POSITION - _pos = in.readInt(); - - // ENTRIES - int len = in.readInt(); - _data = new double[len]; - for (int i = 0; i < len; i++) { - _data[i] = in.readDouble(); - } - } -} // TDoubleArrayList diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteHashMap.java deleted file mode 100644 index 33538828fe7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for double keys and byte values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TDoubleByteHashMap extends TDoubleHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TDoubleByteProcedure PUT_ALL_PROC = new TDoubleByteProcedure() { - public boolean execute(double key, byte value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleByteHashMap(TDoubleHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TDoubleByteHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleByteHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TDoubleByteHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TDoubleByteHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TDoubleByteHashMap m = (TDoubleByteHashMap) super.clone(); - m._values = (byte[]) this._values.clone(); - return m; - } - - /** - * @return a TDoubleByteIterator with access to this map's keys and values - */ - public TDoubleByteIterator iterator() { - return new TDoubleByteIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new byte[capacity]; - return capacity; - } - - /** - * 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 (double)0 if none was found. - */ - public byte put(double key, byte value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (double)0 if none was found. - */ - public byte putIfAbsent(double key, byte value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private byte doPut(double key, byte value, int index) { - byte previousState; - byte previous = (byte) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TDoubleByteHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an double value - * @return the value of key or (double)0 if no such mapping exists. - */ - public byte get(double key) { - int index = index(key); - return index < 0 ? (byte) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - double[] keys = _set; - byte[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (double) 0); - Arrays.fill(_values, 0, _values.length, (byte) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an double value - * @return an byte value, or (double)0 if no mapping for key exists - */ - public byte remove(double key) { - byte prev = (byte) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TDoubleByteHashMap)) { - return false; - } - TDoubleByteHashMap that = (TDoubleByteHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TDoubleByteProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(double key, byte value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TDoubleByteProcedure { - private final TDoubleByteHashMap _otherMap; - - EqProcedure(TDoubleByteHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(double key, byte value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two bytes for equality. - */ - private final boolean eq(byte v1, byte v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (byte) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public byte[] getValues() { - byte[] vals = new byte[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public double[] keys(double[] a) { - int size = size(); - if (a.length < size) { - a = (double[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - double[] k = (double[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - byte[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TByteFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (byte) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public byte adjustOrPutValue(final double key, final byte adjust_amount, final byte put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - double key = in.readDouble(); - byte val = in.readByte(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TDoubleByteProcedure() { - private boolean first = true; - - 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(); - } -} // TDoubleByteHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteIterator.java deleted file mode 100644 index ffb82a59776..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TDoubleByteIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TDoubleByteHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TDoubleByteIterator(TDoubleByteHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - byte old = value(); - _map._values[_index] = val; - return old; - } -}// TDoubleByteIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteProcedure.java deleted file mode 100644 index 93337159081..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleByteProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type double and byte. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TDoubleByteProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleHashMap.java deleted file mode 100644 index 82bb05f9714..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for double keys and double values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TDoubleDoubleHashMap extends TDoubleHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TDoubleDoubleProcedure PUT_ALL_PROC = new TDoubleDoubleProcedure() { - public boolean execute(double key, double value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleDoubleHashMap(TDoubleHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TDoubleDoubleHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleDoubleHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TDoubleDoubleHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TDoubleDoubleHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TDoubleDoubleHashMap m = (TDoubleDoubleHashMap) super.clone(); - m._values = (double[]) this._values.clone(); - return m; - } - - /** - * @return a TDoubleDoubleIterator with access to this map's keys and values - */ - public TDoubleDoubleIterator iterator() { - return new TDoubleDoubleIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new double[capacity]; - return capacity; - } - - /** - * 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 (double)0 if none was found. - */ - public double put(double key, double value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (double)0 if none was found. - */ - public double putIfAbsent(double key, double value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private double doPut(double key, double value, int index) { - byte previousState; - double previous = (double) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TDoubleDoubleHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an double value - * @return the value of key or (double)0 if no such mapping exists. - */ - public double get(double key) { - int index = index(key); - return index < 0 ? (double) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - double[] keys = _set; - double[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (double) 0); - Arrays.fill(_values, 0, _values.length, (double) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an double value - * @return an double value, or (double)0 if no mapping for key exists - */ - public double remove(double key) { - double prev = (double) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TDoubleDoubleHashMap)) { - return false; - } - TDoubleDoubleHashMap that = (TDoubleDoubleHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TDoubleDoubleProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(double key, double value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TDoubleDoubleProcedure { - private final TDoubleDoubleHashMap _otherMap; - - EqProcedure(TDoubleDoubleHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(double key, double value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two doubles for equality. - */ - private final boolean eq(double v1, double v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (double) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public double[] getValues() { - double[] vals = new double[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public double[] keys(double[] a) { - int size = size(); - if (a.length < size) { - a = (double[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - double[] k = (double[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - double[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TDoubleFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (double) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public double adjustOrPutValue(final double key, final double adjust_amount, final double put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - double key = in.readDouble(); - double val = in.readDouble(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TDoubleDoubleProcedure() { - private boolean first = true; - - 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(); - } -} // TDoubleDoubleHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleIterator.java deleted file mode 100644 index 74dce7adb5a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TDoubleDoubleIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TDoubleDoubleHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TDoubleDoubleIterator(TDoubleDoubleHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - double old = value(); - _map._values[_index] = val; - return old; - } -}// TDoubleDoubleIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleProcedure.java deleted file mode 100644 index b0f7033fb8e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleDoubleProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type double and double. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TDoubleDoubleProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatHashMap.java deleted file mode 100644 index f9572b02a12..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for double keys and float values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TDoubleFloatHashMap extends TDoubleHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TDoubleFloatProcedure PUT_ALL_PROC = new TDoubleFloatProcedure() { - public boolean execute(double key, float value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleFloatHashMap(TDoubleHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TDoubleFloatHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleFloatHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TDoubleFloatHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TDoubleFloatHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TDoubleFloatHashMap m = (TDoubleFloatHashMap) super.clone(); - m._values = (float[]) this._values.clone(); - return m; - } - - /** - * @return a TDoubleFloatIterator with access to this map's keys and values - */ - public TDoubleFloatIterator iterator() { - return new TDoubleFloatIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new float[capacity]; - return capacity; - } - - /** - * 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 (double)0 if none was found. - */ - public float put(double key, float value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (double)0 if none was found. - */ - public float putIfAbsent(double key, float value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private float doPut(double key, float value, int index) { - byte previousState; - float previous = (float) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TDoubleFloatHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an double value - * @return the value of key or (double)0 if no such mapping exists. - */ - public float get(double key) { - int index = index(key); - return index < 0 ? (float) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - double[] keys = _set; - float[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (double) 0); - Arrays.fill(_values, 0, _values.length, (float) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an double value - * @return an float value, or (double)0 if no mapping for key exists - */ - public float remove(double key) { - float prev = (float) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TDoubleFloatHashMap)) { - return false; - } - TDoubleFloatHashMap that = (TDoubleFloatHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TDoubleFloatProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(double key, float value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TDoubleFloatProcedure { - private final TDoubleFloatHashMap _otherMap; - - EqProcedure(TDoubleFloatHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(double key, float value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two floats for equality. - */ - private final boolean eq(float v1, float v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (float) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public float[] getValues() { - float[] vals = new float[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public double[] keys(double[] a) { - int size = size(); - if (a.length < size) { - a = (double[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - double[] k = (double[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - float[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TFloatFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (float) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public float adjustOrPutValue(final double key, final float adjust_amount, final float put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - double key = in.readDouble(); - float val = in.readFloat(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TDoubleFloatProcedure() { - private boolean first = true; - - 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(); - } -} // TDoubleFloatHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatIterator.java deleted file mode 100644 index 8b88f88b6e8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TDoubleFloatIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TDoubleFloatHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TDoubleFloatIterator(TDoubleFloatHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - float old = value(); - _map._values[_index] = val; - return old; - } -}// TDoubleFloatIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatProcedure.java deleted file mode 100644 index f917ff7ea5c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFloatProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type double and float. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TDoubleFloatProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFunction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFunction.java deleted file mode 100644 index 68e16c5060b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleFunction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for functions that accept and return one double primitive. - *

- * Created: Mon Nov 5 22:19:36 2001 - * - * @author Eric D. Friedman - * @version $Id: PFunction.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TDoubleFunction { - /** - * Execute this function with value - * - * @param value a double input - * @return a double result - */ - public double execute(double value); -}// TDoubleFunction diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHash.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHash.java deleted file mode 100644 index 8375e316eef..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHash.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: PHash.template,v 1.2 2007/06/29 22:39:46 robeden Exp $ - */ - -abstract public class TDoubleHash extends TPrimitiveHash implements TDoubleHashingStrategy { - - /** - * the set of doubles - */ - protected transient double[] _set; - - /** - * strategy used to hash values in this collection - */ - protected TDoubleHashingStrategy _hashingStrategy; - - /** - * Creates a new TDoubleHash instance with the default - * capacity and load factor. - */ - public TDoubleHash() { - super(); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * Creates a new TDoubleHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleHash(TDoubleHashingStrategy strategy) { - super(); - this._hashingStrategy = strategy; - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleHash(int initialCapacity, TDoubleHashingStrategy strategy) { - super(initialCapacity); - this._hashingStrategy = strategy; - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TDoubleHash(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { - super(initialCapacity, loadFactor); - this._hashingStrategy = strategy; - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TDoubleHash h = (TDoubleHash) super.clone(); - h._set = (double[]) this._set.clone(); - return h; - } - - /** - * 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 = 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 - */ - protected void removeAt(int index) { - _set[index] = (double) 0; - 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 = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - // see Knuth, p. 529 - probe = 1 + (hash % (length - 2)); - - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)); - } - - return states[index] == FREE ? -1 : index; - } - - /** - * 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 insertionIndex(double val) { - int hash, probe, index, length; - - final byte[] states = _states; - final double[] set = _set; - length = states.length; - hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] == FREE) { - return index; // empty, all done - } else if (states[index] == FULL && set[index] == val) { - 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 (states[index] != REMOVED) { - // starting at the natural offset, probe until we find an - // offset that isn't full. - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] == FULL && set[index] != val); - } - - // 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 (states[index] == REMOVED) { - int firstRemoved = index; - while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - index -= probe; - if (index < 0) { - index += length; - } - } - return states[index] == FULL ? -index - 1 : firstRemoved; - } - // if it's full, the key is already stored - return states[index] == FULL ? -index - 1 : index; - } - } - - /** - * Default implementation of TDoubleHashingStrategy: - * delegates hashing to HashFunctions.hash(double). - * - * @param val the value to hash - * @return the hashcode. - */ - public final int computeHashCode(double val) { - return HashFunctions.hash(val); - } -} // TDoubleHash diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHashSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHashSet.java deleted file mode 100644 index 372149bb5c2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHashSet.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed set implementation for double primitives. - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TDoubleHashSet extends TDoubleHash implements 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 TDoubleHashSet 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 TDoubleHashSet(int initialCapacity, float loadFactor) { - super(initialCapacity, loadFactor); - } - - /** - * Creates a new TDoubleHashSet instance containing the - * elements of array. - * - * @param array an array of double primitives - */ - public TDoubleHashSet(double[] array) { - this(array.length); - addAll(array); - } - - /** - * Creates a new TDoubleHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleHashSet(TDoubleHashingStrategy strategy) { - super(strategy); - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleHashSet(int initialCapacity, TDoubleHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TDoubleHashSet(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * Creates a new TDoubleHashSet instance containing the - * elements of array. - * - * @param array an array of double primitives - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleHashSet(double[] array, TDoubleHashingStrategy strategy) { - this(array.length, strategy); - addAll(array); - } - - /** - * @return a TDoubleIterator with access to the values in this set - */ - public TDoubleIterator iterator() { - return new TDoubleIterator(this); - } - - /** - * Inserts a value into the set. - * - * @param val an double value - * @return true if the set was modified by the add operation - */ - public boolean add(double val) { - int index = insertionIndex(val); - - if (index < 0) { - return false; // already present in set, nothing to add - } - - byte previousState = _states[index]; - _set[index] = val; - _states[index] = FULL; - postInsertHook(previousState == FREE); - - return true; // yes, we added something - } - - /** - * Expands the set to accommodate new values. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _states[index] = FULL; - } - } - } - - /** - * Returns a new array containing the values in the set. - * - * @return an double[] value - */ - public double[] toArray() { - double[] result = new double[size()]; - 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; - } - - /** - * Empties the set. - */ - public void clear() { - super.clear(); - double[] set = _set; - byte[] states = _states; - - for (int i = set.length; i-- > 0;) { - set[i] = (double) 0; - states[i] = FREE; - } - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TDoubleHashSet)) { - return false; - } - final TDoubleHashSet that = (TDoubleHashSet) other; - if (that.size() != this.size()) { - return false; - } - return forEach(new TDoubleProcedure() { - public final boolean execute(double value) { - return that.contains(value); - } - }); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEach(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TDoubleProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(double key) { - h += _hashingStrategy.computeHashCode(key); - return true; - } - } - - /** - * Removes val from the set. - * - * @param val an double value - * @return true if the set was modified by the remove operation. - */ - public boolean remove(double val) { - int index = index(val); - if (index >= 0) { - removeAt(index); - return true; - } - return false; - } - - /** - * Tests the set to determine if all of the elements in - * array are present. - * - * @param array an array of double primitives. - * @return true if all elements were present in the set. - */ - public boolean containsAll(double[] array) { - for (int i = array.length; i-- > 0;) { - if (!contains(array[i])) { - return false; - } - } - return true; - } - - /** - * Adds all of the elements in array to the set. - * - * @param array an array of double primitives. - * @return true if the set was modified by the add all operation. - */ - public boolean addAll(double[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (add(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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. - */ - public boolean removeAll(double[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (remove(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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 - */ - 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)) { - remove(set[i]); - changed = true; - } - } - return changed; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEach(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - - // ENTRIES - setUp(size); - while (size-- > 0) { - double val = in.readDouble(); - add(val); - } - } -} // TDoubleHashSet diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHashingStrategy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHashingStrategy.java deleted file mode 100644 index b891383205c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleHashingStrategy.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Serializable; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface to support pluggable hashing strategies in maps and sets. - * Implementors can use this interface to make the trove hashing - * algorithms use an optimal strategy when computing hashcodes. - *

- * Created: Sun Nov 4 08:56:06 2001 - * - * @author Eric D. Friedman - * @version $Id: PHashingStrategy.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TDoubleHashingStrategy extends Serializable { - /** - * Computes a hash code for the specified double. Implementors - * can use the double's own value or a custom scheme designed to - * minimize collisions for a known set of input. - * - * @param val double for which the hashcode is to be computed - * @return the hashCode - */ - public int computeHashCode(double val); -} // TDoubleHashingStrategy diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntHashMap.java deleted file mode 100644 index 53086ef3d16..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for double keys and int values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TDoubleIntHashMap extends TDoubleHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TDoubleIntProcedure PUT_ALL_PROC = new TDoubleIntProcedure() { - public boolean execute(double key, int value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleIntHashMap(TDoubleHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TDoubleIntHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleIntHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TDoubleIntHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TDoubleIntHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TDoubleIntHashMap m = (TDoubleIntHashMap) super.clone(); - m._values = (int[]) this._values.clone(); - return m; - } - - /** - * @return a TDoubleIntIterator with access to this map's keys and values - */ - public TDoubleIntIterator iterator() { - return new TDoubleIntIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new int[capacity]; - return capacity; - } - - /** - * 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 (double)0 if none was found. - */ - public int put(double key, int value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (double)0 if none was found. - */ - public int putIfAbsent(double key, int value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private int doPut(double key, int value, int index) { - byte previousState; - int previous = (int) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TDoubleIntHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an double value - * @return the value of key or (double)0 if no such mapping exists. - */ - public int get(double key) { - int index = index(key); - return index < 0 ? (int) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - double[] keys = _set; - int[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (double) 0); - Arrays.fill(_values, 0, _values.length, (int) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an double value - * @return an int value, or (double)0 if no mapping for key exists - */ - public int remove(double key) { - int prev = (int) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TDoubleIntHashMap)) { - return false; - } - TDoubleIntHashMap that = (TDoubleIntHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TDoubleIntProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(double key, int value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TDoubleIntProcedure { - private final TDoubleIntHashMap _otherMap; - - EqProcedure(TDoubleIntHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(double key, int value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two ints for equality. - */ - private final boolean eq(int v1, int v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (int) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public int[] getValues() { - int[] vals = new int[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public double[] keys(double[] a) { - int size = size(); - if (a.length < size) { - a = (double[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - double[] k = (double[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - int[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TIntFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (int) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public int adjustOrPutValue(final double key, final int adjust_amount, final int put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - double key = in.readDouble(); - int val = in.readInt(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TDoubleIntProcedure() { - private boolean first = true; - - 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(); - } -} // TDoubleIntHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntIterator.java deleted file mode 100644 index f1ba0bd1d54..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TDoubleIntIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TDoubleIntHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TDoubleIntIterator(TDoubleIntHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - int old = value(); - _map._values[_index] = val; - return old; - } -}// TDoubleIntIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntProcedure.java deleted file mode 100644 index b05f3b9c312..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIntProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type double and int. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TDoubleIntProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIterator.java deleted file mode 100644 index 0bcaf8b3f0a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleIterator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Iterator for double collections. - * - * @author Eric D. Friedman - * @version $Id: PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TDoubleIterator extends TPrimitiveIterator { - /** - * the collection on which the iterator operates - */ - private final TDoubleHash _hash; - - /** - * Creates a TDoubleIterator for the elements in the specified collection. - */ - public TDoubleIterator(TDoubleHash hash) { - super(hash); - this._hash = hash; - } - - /** - * Advances the iterator to the next element in the underlying collection - * and returns it. - * - * @return the next double in the collection - * @throws NoSuchElementException if the iterator is already exhausted - */ - public double next() { - moveToNextIndex(); - return _hash._set[_index]; - } -}// TDoubleIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongHashMap.java deleted file mode 100644 index a94edd2df97..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for double keys and long values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TDoubleLongHashMap extends TDoubleHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TDoubleLongProcedure PUT_ALL_PROC = new TDoubleLongProcedure() { - public boolean execute(double key, long value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleLongHashMap(TDoubleHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TDoubleLongHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleLongHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TDoubleLongHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TDoubleLongHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TDoubleLongHashMap m = (TDoubleLongHashMap) super.clone(); - m._values = (long[]) this._values.clone(); - return m; - } - - /** - * @return a TDoubleLongIterator with access to this map's keys and values - */ - public TDoubleLongIterator iterator() { - return new TDoubleLongIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new long[capacity]; - return capacity; - } - - /** - * 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 (double)0 if none was found. - */ - public long put(double key, long value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (double)0 if none was found. - */ - public long putIfAbsent(double key, long value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private long doPut(double key, long value, int index) { - byte previousState; - long previous = (long) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TDoubleLongHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an double value - * @return the value of key or (double)0 if no such mapping exists. - */ - public long get(double key) { - int index = index(key); - return index < 0 ? (long) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - double[] keys = _set; - long[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (double) 0); - Arrays.fill(_values, 0, _values.length, (long) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an double value - * @return an long value, or (double)0 if no mapping for key exists - */ - public long remove(double key) { - long prev = (long) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TDoubleLongHashMap)) { - return false; - } - TDoubleLongHashMap that = (TDoubleLongHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TDoubleLongProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(double key, long value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TDoubleLongProcedure { - private final TDoubleLongHashMap _otherMap; - - EqProcedure(TDoubleLongHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(double key, long value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two longs for equality. - */ - private final boolean eq(long v1, long v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (long) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public long[] getValues() { - long[] vals = new long[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public double[] keys(double[] a) { - int size = size(); - if (a.length < size) { - a = (double[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - double[] k = (double[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - long[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TLongFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (long) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public long adjustOrPutValue(final double key, final long adjust_amount, final long put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - double key = in.readDouble(); - long val = in.readLong(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TDoubleLongProcedure() { - private boolean first = true; - - 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(); - } -} // TDoubleLongHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongIterator.java deleted file mode 100644 index 1381215d528..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TDoubleLongIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TDoubleLongHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TDoubleLongIterator(TDoubleLongHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - long old = value(); - _map._values[_index] = val; - return old; - } -}// TDoubleLongIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongProcedure.java deleted file mode 100644 index 4f45c6422be..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleLongProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type double and long. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TDoubleLongProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectHashMap.java deleted file mode 100644 index 07b317eca3f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectHashMap.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TDoubleObjectHashMap extends TDoubleHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TDoubleObjectProcedure PUT_ALL_PROC = new TDoubleObjectProcedure() { - public boolean execute(double key, V value) { - put(key, value); - return true; - } - }; - - - /** - * the values of the map - */ - protected transient V[] _values; - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TDoubleObjectHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleObjectHashMap(TDoubleHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TDoubleObjectHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleObjectHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TDoubleObjectHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public TDoubleObjectHashMap clone() { - TDoubleObjectHashMap m = (TDoubleObjectHashMap) super.clone(); - m._values = (V[]) this._values.clone(); - return m; - } - - /** - * @return a TDoubleObjectIterator with access to this map's keys and values - */ - public TDoubleObjectIterator iterator() { - return new TDoubleObjectIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = (V[]) new Object[capacity]; - return capacity; - } - - /** - * 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 {@code null} if none was found. - */ - public V put(double key, V value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 Object value - * @return the previous value associated with key, - * or {@code null} if none was found. - */ - public V putIfAbsent(double key, V value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private V doPut(double key, V value, int index) { - byte previousState; - V previous = null; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TDoubleObjectHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an double value - * @return the value of key or (double)0 if no such mapping exists. - */ - public V get(double key) { - int index = index(key); - return index < 0 ? null : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - double[] keys = _set; - Object[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (double) 0); - Arrays.fill(_values, 0, _values.length, null); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an double value - * @return an Object value or (double)0 if no such mapping exists. - */ - 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; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TDoubleObjectHashMap)) { - return false; - } - TDoubleObjectHashMap that = (TDoubleObjectHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TDoubleObjectProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(double key, Object value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TDoubleObjectProcedure { - private final TDoubleObjectHashMap _otherMap; - - EqProcedure(TDoubleObjectHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(double key, Object value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two objects for equality. - */ - private final boolean eq(Object o1, Object o2) { - return o1 == o2 || ((o1 != null) && o1.equals(o2)); - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = null; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - * @see #getValues(Object[]) - */ - public Object[] getValues() { - 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; - } - - /** - * Return the values of the map; the runtime type of the returned array is that of - * the specified array. - * - * @param a the array into which the elements of this collection are to be - * stored, if it is big enough; otherwise, a new array of the same - * runtime type is allocated for this purpose. - * @return an array containing the elements of this collection - * @throws ArrayStoreException the runtime type of the specified array is - * not a supertype of the runtime type of every element in this - * collection. - * @throws NullPointerException if the specified array is null. - * @see #getValues() - */ - public T[] getValues(T[] a) { - if (a.length < _size) { - a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), - _size); - } - - V[] v = _values; - byte[] states = _states; - - for (int i = v.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = (T) v[i]; - } - } - return a; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public double[] keys(double[] a) { - int size = size(); - if (a.length < size) { - a = (double[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - double[] k = (double[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(V 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 && - val == 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; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * Executes procedure for each key/value entry in the - * map. - * - * @param procedure a TODoubleObjectProcedure value - * @return false if the loop over the entries terminated because - * the procedure returned false for some entry. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TObjectFunction value - */ - 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]); - } - } - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // 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); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TDoubleObjectProcedure() { - private boolean first = true; - - 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectIterator.java deleted file mode 100644 index 8c57c01d45f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: P2OIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TDoubleObjectIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TDoubleObjectHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TDoubleObjectIterator(TDoubleObjectHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - V old = value(); - _map._values[_index] = val; - return old; - } -}// TDoubleObjectIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectProcedure.java deleted file mode 100644 index 89354ac38c3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleObjectProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type double and Object. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2OProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TDoubleObjectProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleProcedure.java deleted file mode 100644 index bf4d31bd19f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleProcedure.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures with one double parameter. - *

- * Created: Mon Nov 5 21:45:49 2001 - * - * @author Eric D. Friedman - * @version $Id: PProcedure.template,v 1.2 2007/11/01 16:08:14 robeden Exp $ - */ - -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); -}// TDoubleProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortHashMap.java deleted file mode 100644 index 87fdfeef035..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for double keys and short values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TDoubleShortHashMap extends TDoubleHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TDoubleShortProcedure PUT_ALL_PROC = new TDoubleShortProcedure() { - public boolean execute(double key, short value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleShortHashMap(TDoubleHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TDoubleShortHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TDoubleShortHashMap(int initialCapacity, TDoubleHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TDoubleShortHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TDoubleShortHashMap(int initialCapacity, float loadFactor, TDoubleHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TDoubleShortHashMap m = (TDoubleShortHashMap) super.clone(); - m._values = (short[]) this._values.clone(); - return m; - } - - /** - * @return a TDoubleShortIterator with access to this map's keys and values - */ - public TDoubleShortIterator iterator() { - return new TDoubleShortIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new short[capacity]; - return capacity; - } - - /** - * 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 (double)0 if none was found. - */ - public short put(double key, short value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (double)0 if none was found. - */ - public short putIfAbsent(double key, short value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private short doPut(double key, short value, int index) { - byte previousState; - short previous = (short) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TDoubleShortHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an double value - * @return the value of key or (double)0 if no such mapping exists. - */ - public short get(double key) { - int index = index(key); - return index < 0 ? (short) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - double[] keys = _set; - short[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (double) 0); - Arrays.fill(_values, 0, _values.length, (short) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an double value - * @return an short value, or (double)0 if no mapping for key exists - */ - public short remove(double key) { - short prev = (short) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TDoubleShortHashMap)) { - return false; - } - TDoubleShortHashMap that = (TDoubleShortHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TDoubleShortProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(double key, short value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TDoubleShortProcedure { - private final TDoubleShortHashMap _otherMap; - - EqProcedure(TDoubleShortHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(double key, short value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two shorts for equality. - */ - private final boolean eq(short v1, short v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (short) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public short[] getValues() { - short[] vals = new short[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public double[] keys(double[] a) { - int size = size(); - if (a.length < size) { - a = (double[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - double[] k = (double[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - short[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TShortFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (short) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public short adjustOrPutValue(final double key, final short adjust_amount, final short put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - double key = in.readDouble(); - short val = in.readShort(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TDoubleShortProcedure() { - private boolean first = true; - - 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(); - } -} // TDoubleShortHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortIterator.java deleted file mode 100644 index 66c2f6e3805..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TDoubleShortIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TDoubleShortHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TDoubleShortIterator(TDoubleShortHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - short old = value(); - _map._values[_index] = val; - return old; - } -}// TDoubleShortIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortProcedure.java deleted file mode 100644 index d597d7cd0fb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleShortProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type double and short. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TDoubleShortProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleStack.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleStack.java deleted file mode 100644 index a44b130f7b3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TDoubleStack.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -/** - * A stack of double primitives, backed by a TDoubleArrayList. - * - * @author Eric D. Friedman, Rob Eden - * @version $Id: PStack.template,v 1.2 2007/02/28 23:03:57 robeden Exp $ - */ - -public class TDoubleStack { - - /** - * the list used to hold the stack values. - */ - protected TDoubleArrayList _list; - - public static final int DEFAULT_CAPACITY = TDoubleArrayList.DEFAULT_CAPACITY; - - /** - * Creates a new TDoubleStack instance with the default - * capacity. - */ - public TDoubleStack() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TDoubleStack instance with the - * specified capacity. - * - * @param capacity the initial depth of the stack - */ - public TDoubleStack(int capacity) { - _list = new TDoubleArrayList(capacity); - } - - /** - * Pushes the value onto the top of the stack. - * - * @param val an double value - */ - public void push(double val) { - _list.add(val); - } - - /** - * Removes and returns the value at the top of the stack. - * - * @return an double value - */ - public double pop() { - return _list.remove(_list.size() - 1); - } - - /** - * Returns the value at the top of the stack. - * - * @return an double value - */ - public double peek() { - return _list.get(_list.size() - 1); - } - - /** - * Returns the current depth of the stack. - */ - public int size() { - return _list.size(); - } - - /** - * Clears the stack, reseting its capacity to the default. - */ - public void clear() { - _list.clear(DEFAULT_CAPACITY); - } - - /** - * Clears the stack without releasing its internal capacity allocation. - */ - public void reset() { - _list.reset(); - } - - /** - * 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[] toNativeArray() { - return _list.toNativeArray(); - } - - /** - * 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 toNativeArray(double[] dest) { - _list.toNativeArray(dest, 0, size()); - } -} // TDoubleStack diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatArrayList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatArrayList.java deleted file mode 100644 index bdd6e7d6481..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatArrayList.java +++ /dev/null @@ -1,935 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; -import java.util.Random; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * A resizable, array-backed list of float primitives. - *

- * Created: Sat Dec 29 14:21:12 2001 - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TFloatArrayList implements Externalizable, Cloneable { - 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 = 10; - - /** - * Creates a new TFloatArrayList instance with the - * default capacity. - */ - public TFloatArrayList() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TFloatArrayList instance with the - * specified capacity. - * - * @param capacity an int value - */ - public TFloatArrayList(int capacity) { - _data = new float[capacity]; - _pos = 0; - } - - /** - * Creates a new TFloatArrayList instance whose - * capacity is the greater of the length of values and - * DEFAULT_CAPACITY and whose initial contents are the specified - * values. - * - * @param values an float[] value - */ - public TFloatArrayList(float[] values) { - this(Math.max(values.length, DEFAULT_CAPACITY)); - add(values); - } - - // sizing - - /** - * Grow the internal array as needed to accommodate the specified - * number of elements. The size of the array floats on each - * resize unless capacity requires more than twice the - * current capacity. - * - * @param capacity an int value - */ - 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; - } - } - - /** - * Returns the number of values in the list. - * - * @return the number of values in the list. - */ - public int size() { - return _pos; - } - - /** - * Tests whether this list contains any values. - * - * @return true if the list is empty. - */ - 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()]; - toNativeArray(tmp, 0, tmp.length); - _data = tmp; - } - } - - // modifying - - /** - * Adds val to the end of the list, growing as needed. - * - * @param val an float value - */ - public void add(float val) { - ensureCapacity(_pos + 1); - _data[_pos++] = 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) { - add(vals, 0, vals.length); - } - - /** - * 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) { - ensureCapacity(_pos + length); - System.arraycopy(vals, offset, _data, _pos, length); - _pos += 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) { - 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++; - } - - /** - * 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) { - insert(offset, values, 0, values.length); - } - - /** - * 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) { - 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; - } - - /** - * Returns the value at the specified offset. - * - * @param offset an int value - * @return an float value - */ - 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. - * - * @param offset an int value - * @return an float value - */ - public float getQuick(int offset) { - return _data[offset]; - } - - /** - * Sets the value at the specified offset. - * - * @param offset an int value - * @param val an float value - */ - public void set(int offset, float val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - _data[offset] = val; - } - - /** - * 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 getSet(int offset, float val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - float old = _data[offset]; - _data[offset] = val; - return old; - } - - /** - * 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) { - set(offset, values, 0, values.length); - } - - /** - * 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) { - 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. - * - * @param offset an int value - * @param val an float value - */ - public void setQuick(int offset, float val) { - _data[offset] = val; - } - - /** - * Flushes the internal state of the list, resetting the capacity - * to the default. - */ - public void clear() { - clear(DEFAULT_CAPACITY); - } - - /** - * Flushes the internal state of the list, setting the capacity of - * the empty list to capacity. - * - * @param capacity an int value - */ - 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 clear} method if you want to recyle a list without - * allocating new backing arrays. - * - * @see #clear - */ - public void reset() { - _pos = 0; - fill((float) 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 clear} method if you want to recyle a list - * without allocating new backing arrays. This method differs - * from {@link #reset reset} in that it does not clear the old - * values in the backing array. Thus, it is possible for {@link - * #getQuick getQuick} to return stale data if this method is used - * and the caller is careless about bounds checking. - * - * @see #reset - * @see #clear - * @see #getQuick - */ - public void resetQuick() { - _pos = 0; - } - - /** - * Removes the value at offset from the list. - * - * @param offset an int value - * @return the value previously stored at offset. - */ - public float remove(int offset) { - float old = get(offset); - remove(offset, 1); - return old; - } - - /** - * 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) { - 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 - } - - /** - * Transform each value in the list using the specified function. - * - * @param function a TFloatFunction value - */ - public void transformValues(TFloatFunction function) { - for (int i = _pos; i-- > 0;) { - _data[i] = function.execute(_data[i]); - } - } - - /** - * Reverse the order of the elements in the list. - */ - public void reverse() { - reverse(0, _pos); - } - - /** - * 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) { - 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); - } - } - - /** - * Shuffle the elements of the list using the specified random - * number generator. - * - * @param rand a Random value - */ - 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 final void swap(int i, int j) { - float tmp = _data[i]; - _data[i] = _data[j]; - _data[j] = tmp; - } - - // copying - - /** - * Returns a clone of this list. Since this is a primitive - * collection, this will be a deep clone. - * - * @return a deep clone of the list. - */ - public Object clone() { - TFloatArrayList list = null; - try { - list = (TFloatArrayList) super.clone(); - list._data = toNativeArray(); - } catch (CloneNotSupportedException e) { - // it's supported - } // end of try-catch - return list; - } - - - /** - * 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 TFloatArrayList 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; - } - - - /** - * Copies the contents of the list into a native array. - * - * @return an float[] value - */ - public float[] toNativeArray() { - return toNativeArray(0, _pos); - } - - /** - * 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[] toNativeArray(int offset, int len) { - float[] rv = new float[len]; - toNativeArray(rv, offset, len); - return rv; - } - - /** - * Copies a slice of the list into a native array. - * - * @param dest the array to copy into. - * @param offset the offset of the first value to copy - * @param len the number of values to copy. - */ - public void toNativeArray(float[] dest, int offset, int len) { - if (len == 0) { - return; // nothing to copy - } - if (offset < 0 || offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - System.arraycopy(_data, offset, dest, 0, len); - } - - // comparing - - /** - * Compares this list to another list, value by value. - * - * @param other the object to compare against - * @return true if other is a TFloatArrayList and has exactly the - * same values. - */ - public boolean equals(Object other) { - if (other == this) { - return true; - } else if (other instanceof TFloatArrayList) { - TFloatArrayList that = (TFloatArrayList) other; - if (that.size() != this.size()) { - return false; - } else { - for (int i = _pos; i-- > 0;) { - if (this._data[i] != that._data[i]) { - return false; - } - } - return true; - } - } else { - return false; - } - } - - public int hashCode() { - int h = 0; - for (int i = _pos; i-- > 0;) { - h = 37 * h + HashFunctions.hash(_data[i]); - } - return h; - } - - // procedures - - /** - * 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. - */ - public boolean forEach(TFloatProcedure procedure) { - for (int i = 0; i < _pos; i++) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - /** - * 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) { - for (int i = _pos; i-- > 0;) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - // sorting - - /** - * Sort the values in the list (ascending) using the Sun quicksort - * implementation. - * - * @see java.util.Arrays#sort - */ - public void sort() { - Arrays.sort(_data, 0, _pos); - } - - /** - * 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) { - Arrays.sort(_data, fromIndex, toIndex); - } - - // filling - - /** - * Fills every slot in the list with the specified value. - * - * @param val the value to use when filling - */ - public void fill(float val) { - Arrays.fill(_data, 0, _pos, 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) { - if (toIndex > _pos) { - ensureCapacity(toIndex); - _pos = toIndex; - } - Arrays.fill(_data, fromIndex, toIndex, val); - } - - // searching - - /** - * 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) { - return binarySearch(value, 0, _pos); - } - - /** - * 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) { - 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. - } - - /** - * 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) { - return indexOf(0, 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) { - for (int i = offset; i < _pos; i++) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * 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) { - return lastIndexOf(_pos, 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) { - for (int i = offset; i-- > 0;) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * Searches the list for value - * - * @param value an float value - * @return true if value is in the list. - */ - public boolean contains(float value) { - return lastIndexOf(value) >= 0; - } - - /** - * 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 TFloatArrayList 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; - } - - /** - * 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 TFloatArrayList 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; - } - - /** - * Finds the maximum value in the list. - * - * @return the largest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - /** - * Finds the minimum value in the list. - * - * @return the smallest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - // stringification - - /** - * Returns a String representation of the list, front to back. - * - * @return a String value - */ - 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(); - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(1); - - // POSITION - out.writeInt(_pos); - - // ENTRIES - int len = _pos; - out.writeInt(_pos); // Written twice for backwards compatability with - // version 0 - for (int i = 0; i < len; i++) { - out.writeFloat(_data[i]); - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // POSITION - _pos = in.readInt(); - - // ENTRIES - int len = in.readInt(); - _data = new float[len]; - for (int i = 0; i < len; i++) { - _data[i] = in.readFloat(); - } - } -} // TFloatArrayList diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteHashMap.java deleted file mode 100644 index f4d6621d9a2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for float keys and byte values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TFloatByteHashMap extends TFloatHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TFloatByteProcedure PUT_ALL_PROC = new TFloatByteProcedure() { - public boolean execute(float key, byte value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatByteHashMap(TFloatHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TFloatByteHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatByteHashMap(int initialCapacity, TFloatHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TFloatByteHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TFloatByteHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TFloatByteHashMap m = (TFloatByteHashMap) super.clone(); - m._values = (byte[]) this._values.clone(); - return m; - } - - /** - * @return a TFloatByteIterator with access to this map's keys and values - */ - public TFloatByteIterator iterator() { - return new TFloatByteIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new byte[capacity]; - return capacity; - } - - /** - * 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 (float)0 if none was found. - */ - public byte put(float key, byte value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (float)0 if none was found. - */ - public byte putIfAbsent(float key, byte value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private byte doPut(float key, byte value, int index) { - byte previousState; - byte previous = (byte) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TFloatByteHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an float value - * @return the value of key or (float)0 if no such mapping exists. - */ - public byte get(float key) { - int index = index(key); - return index < 0 ? (byte) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - float[] keys = _set; - byte[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (float) 0); - Arrays.fill(_values, 0, _values.length, (byte) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an float value - * @return an byte value, or (float)0 if no mapping for key exists - */ - public byte remove(float key) { - byte prev = (byte) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TFloatByteHashMap)) { - return false; - } - TFloatByteHashMap that = (TFloatByteHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TFloatByteProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(float key, byte value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TFloatByteProcedure { - private final TFloatByteHashMap _otherMap; - - EqProcedure(TFloatByteHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(float key, byte value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two bytes for equality. - */ - private final boolean eq(byte v1, byte v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (byte) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public byte[] getValues() { - byte[] vals = new byte[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public float[] keys(float[] a) { - int size = size(); - if (a.length < size) { - a = (float[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - float[] k = (float[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - byte[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TByteFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (byte) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public byte adjustOrPutValue(final float key, final byte adjust_amount, final byte put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - float key = in.readFloat(); - byte val = in.readByte(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TFloatByteProcedure() { - private boolean first = true; - - 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(); - } -} // TFloatByteHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteIterator.java deleted file mode 100644 index afaeb042d51..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TFloatByteIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TFloatByteHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TFloatByteIterator(TFloatByteHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - byte old = value(); - _map._values[_index] = val; - return old; - } -}// TFloatByteIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteProcedure.java deleted file mode 100644 index f9fd012c1bc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatByteProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type float and byte. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TFloatByteProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleHashMap.java deleted file mode 100644 index 74ab9c87a76..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for float keys and double values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TFloatDoubleHashMap extends TFloatHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TFloatDoubleProcedure PUT_ALL_PROC = new TFloatDoubleProcedure() { - public boolean execute(float key, double value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatDoubleHashMap(TFloatHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TFloatDoubleHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatDoubleHashMap(int initialCapacity, TFloatHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TFloatDoubleHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TFloatDoubleHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TFloatDoubleHashMap m = (TFloatDoubleHashMap) super.clone(); - m._values = (double[]) this._values.clone(); - return m; - } - - /** - * @return a TFloatDoubleIterator with access to this map's keys and values - */ - public TFloatDoubleIterator iterator() { - return new TFloatDoubleIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new double[capacity]; - return capacity; - } - - /** - * 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 (float)0 if none was found. - */ - public double put(float key, double value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (float)0 if none was found. - */ - public double putIfAbsent(float key, double value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private double doPut(float key, double value, int index) { - byte previousState; - double previous = (double) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TFloatDoubleHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an float value - * @return the value of key or (float)0 if no such mapping exists. - */ - public double get(float key) { - int index = index(key); - return index < 0 ? (double) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - float[] keys = _set; - double[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (float) 0); - Arrays.fill(_values, 0, _values.length, (double) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an float value - * @return an double value, or (float)0 if no mapping for key exists - */ - public double remove(float key) { - double prev = (double) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TFloatDoubleHashMap)) { - return false; - } - TFloatDoubleHashMap that = (TFloatDoubleHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TFloatDoubleProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(float key, double value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TFloatDoubleProcedure { - private final TFloatDoubleHashMap _otherMap; - - EqProcedure(TFloatDoubleHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(float key, double value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two doubles for equality. - */ - private final boolean eq(double v1, double v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (double) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public double[] getValues() { - double[] vals = new double[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public float[] keys(float[] a) { - int size = size(); - if (a.length < size) { - a = (float[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - float[] k = (float[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - double[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TDoubleFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (double) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public double adjustOrPutValue(final float key, final double adjust_amount, final double put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - float key = in.readFloat(); - double val = in.readDouble(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TFloatDoubleProcedure() { - private boolean first = true; - - 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(); - } -} // TFloatDoubleHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleIterator.java deleted file mode 100644 index 53de0f0e55a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TFloatDoubleIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TFloatDoubleHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TFloatDoubleIterator(TFloatDoubleHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - double old = value(); - _map._values[_index] = val; - return old; - } -}// TFloatDoubleIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleProcedure.java deleted file mode 100644 index ff18ac7621f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatDoubleProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type float and double. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TFloatDoubleProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatHashMap.java deleted file mode 100644 index f2fbda538b9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for float keys and float values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TFloatFloatHashMap extends TFloatHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TFloatFloatProcedure PUT_ALL_PROC = new TFloatFloatProcedure() { - public boolean execute(float key, float value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatFloatHashMap(TFloatHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TFloatFloatHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatFloatHashMap(int initialCapacity, TFloatHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TFloatFloatHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TFloatFloatHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TFloatFloatHashMap m = (TFloatFloatHashMap) super.clone(); - m._values = (float[]) this._values.clone(); - return m; - } - - /** - * @return a TFloatFloatIterator with access to this map's keys and values - */ - public TFloatFloatIterator iterator() { - return new TFloatFloatIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new float[capacity]; - return capacity; - } - - /** - * 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 (float)0 if none was found. - */ - public float put(float key, float value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (float)0 if none was found. - */ - public float putIfAbsent(float key, float value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private float doPut(float key, float value, int index) { - byte previousState; - float previous = (float) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TFloatFloatHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an float value - * @return the value of key or (float)0 if no such mapping exists. - */ - public float get(float key) { - int index = index(key); - return index < 0 ? (float) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - float[] keys = _set; - float[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (float) 0); - Arrays.fill(_values, 0, _values.length, (float) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an float value - * @return an float value, or (float)0 if no mapping for key exists - */ - public float remove(float key) { - float prev = (float) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TFloatFloatHashMap)) { - return false; - } - TFloatFloatHashMap that = (TFloatFloatHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TFloatFloatProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(float key, float value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TFloatFloatProcedure { - private final TFloatFloatHashMap _otherMap; - - EqProcedure(TFloatFloatHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(float key, float value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two floats for equality. - */ - private final boolean eq(float v1, float v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (float) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public float[] getValues() { - float[] vals = new float[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public float[] keys(float[] a) { - int size = size(); - if (a.length < size) { - a = (float[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - float[] k = (float[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - float[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TFloatFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (float) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public float adjustOrPutValue(final float key, final float adjust_amount, final float put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - float key = in.readFloat(); - float val = in.readFloat(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TFloatFloatProcedure() { - private boolean first = true; - - 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(); - } -} // TFloatFloatHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatIterator.java deleted file mode 100644 index e4942ab80e3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TFloatFloatIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TFloatFloatHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TFloatFloatIterator(TFloatFloatHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - float old = value(); - _map._values[_index] = val; - return old; - } -}// TFloatFloatIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatProcedure.java deleted file mode 100644 index 97a717778c5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFloatProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type float and float. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TFloatFloatProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFunction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFunction.java deleted file mode 100644 index 39370f238d9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatFunction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for functions that accept and return one float primitive. - *

- * Created: Mon Nov 5 22:19:36 2001 - * - * @author Eric D. Friedman - * @version $Id: PFunction.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TFloatFunction { - /** - * Execute this function with value - * - * @param value a float input - * @return a float result - */ - public float execute(float value); -}// TFloatFunction diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHash.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHash.java deleted file mode 100644 index c59e65b370a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHash.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: PHash.template,v 1.2 2007/06/29 22:39:46 robeden Exp $ - */ - -abstract public class TFloatHash extends TPrimitiveHash implements TFloatHashingStrategy { - - /** - * the set of floats - */ - protected transient float[] _set; - - /** - * strategy used to hash values in this collection - */ - protected TFloatHashingStrategy _hashingStrategy; - - /** - * Creates a new TFloatHash instance with the default - * capacity and load factor. - */ - public TFloatHash() { - super(); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * Creates a new TFloatHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatHash(TFloatHashingStrategy strategy) { - super(); - this._hashingStrategy = strategy; - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatHash(int initialCapacity, TFloatHashingStrategy strategy) { - super(initialCapacity); - this._hashingStrategy = strategy; - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TFloatHash(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { - super(initialCapacity, loadFactor); - this._hashingStrategy = strategy; - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TFloatHash h = (TFloatHash) super.clone(); - h._set = (float[]) this._set.clone(); - return h; - } - - /** - * 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 = 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 - */ - protected void removeAt(int index) { - _set[index] = (float) 0; - 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 = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - // see Knuth, p. 529 - probe = 1 + (hash % (length - 2)); - - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)); - } - - return states[index] == FREE ? -1 : index; - } - - /** - * 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 insertionIndex(float val) { - int hash, probe, index, length; - - final byte[] states = _states; - final float[] set = _set; - length = states.length; - hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] == FREE) { - return index; // empty, all done - } else if (states[index] == FULL && set[index] == val) { - 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 (states[index] != REMOVED) { - // starting at the natural offset, probe until we find an - // offset that isn't full. - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] == FULL && set[index] != val); - } - - // 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 (states[index] == REMOVED) { - int firstRemoved = index; - while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - index -= probe; - if (index < 0) { - index += length; - } - } - return states[index] == FULL ? -index - 1 : firstRemoved; - } - // if it's full, the key is already stored - return states[index] == FULL ? -index - 1 : index; - } - } - - /** - * Default implementation of TFloatHashingStrategy: - * delegates hashing to HashFunctions.hash(float). - * - * @param val the value to hash - * @return the hashcode. - */ - public final int computeHashCode(float val) { - return HashFunctions.hash(val); - } -} // TFloatHash diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHashSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHashSet.java deleted file mode 100644 index 77166396982..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHashSet.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed set implementation for float primitives. - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TFloatHashSet extends TFloatHash implements 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 TFloatHashSet 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 TFloatHashSet(int initialCapacity, float loadFactor) { - super(initialCapacity, loadFactor); - } - - /** - * Creates a new TFloatHashSet instance containing the - * elements of array. - * - * @param array an array of float primitives - */ - public TFloatHashSet(float[] array) { - this(array.length); - addAll(array); - } - - /** - * Creates a new TFloatHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatHashSet(TFloatHashingStrategy strategy) { - super(strategy); - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatHashSet(int initialCapacity, TFloatHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TFloatHashSet(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * Creates a new TFloatHashSet instance containing the - * elements of array. - * - * @param array an array of float primitives - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatHashSet(float[] array, TFloatHashingStrategy strategy) { - this(array.length, strategy); - addAll(array); - } - - /** - * @return a TFloatIterator with access to the values in this set - */ - public TFloatIterator iterator() { - return new TFloatIterator(this); - } - - /** - * Inserts a value into the set. - * - * @param val an float value - * @return true if the set was modified by the add operation - */ - public boolean add(float val) { - int index = insertionIndex(val); - - if (index < 0) { - return false; // already present in set, nothing to add - } - - byte previousState = _states[index]; - _set[index] = val; - _states[index] = FULL; - postInsertHook(previousState == FREE); - - return true; // yes, we added something - } - - /** - * Expands the set to accommodate new values. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _states[index] = FULL; - } - } - } - - /** - * Returns a new array containing the values in the set. - * - * @return an float[] value - */ - public float[] toArray() { - float[] result = new float[size()]; - 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; - } - - /** - * Empties the set. - */ - public void clear() { - super.clear(); - float[] set = _set; - byte[] states = _states; - - for (int i = set.length; i-- > 0;) { - set[i] = (float) 0; - states[i] = FREE; - } - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TFloatHashSet)) { - return false; - } - final TFloatHashSet that = (TFloatHashSet) other; - if (that.size() != this.size()) { - return false; - } - return forEach(new TFloatProcedure() { - public final boolean execute(float value) { - return that.contains(value); - } - }); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEach(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TFloatProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(float key) { - h += _hashingStrategy.computeHashCode(key); - return true; - } - } - - /** - * Removes val from the set. - * - * @param val an float value - * @return true if the set was modified by the remove operation. - */ - public boolean remove(float val) { - int index = index(val); - if (index >= 0) { - removeAt(index); - return true; - } - return false; - } - - /** - * Tests the set to determine if all of the elements in - * array are present. - * - * @param array an array of float primitives. - * @return true if all elements were present in the set. - */ - public boolean containsAll(float[] array) { - for (int i = array.length; i-- > 0;) { - if (!contains(array[i])) { - return false; - } - } - return true; - } - - /** - * Adds all of the elements in array to the set. - * - * @param array an array of float primitives. - * @return true if the set was modified by the add all operation. - */ - public boolean addAll(float[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (add(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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. - */ - public boolean removeAll(float[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (remove(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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 - */ - 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)) { - remove(set[i]); - changed = true; - } - } - return changed; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEach(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - - // ENTRIES - setUp(size); - while (size-- > 0) { - float val = in.readFloat(); - add(val); - } - } -} // TFloatHashSet diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHashingStrategy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHashingStrategy.java deleted file mode 100644 index 06886eb365a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatHashingStrategy.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Serializable; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface to support pluggable hashing strategies in maps and sets. - * Implementors can use this interface to make the trove hashing - * algorithms use an optimal strategy when computing hashcodes. - *

- * Created: Sun Nov 4 08:56:06 2001 - * - * @author Eric D. Friedman - * @version $Id: PHashingStrategy.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TFloatHashingStrategy extends Serializable { - /** - * Computes a hash code for the specified float. Implementors - * can use the float's own value or a custom scheme designed to - * minimize collisions for a known set of input. - * - * @param val float for which the hashcode is to be computed - * @return the hashCode - */ - public int computeHashCode(float val); -} // TFloatHashingStrategy diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntHashMap.java deleted file mode 100644 index f042f3f169e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for float keys and int values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TFloatIntHashMap extends TFloatHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TFloatIntProcedure PUT_ALL_PROC = new TFloatIntProcedure() { - public boolean execute(float key, int value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatIntHashMap(TFloatHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TFloatIntHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatIntHashMap(int initialCapacity, TFloatHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TFloatIntHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TFloatIntHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TFloatIntHashMap m = (TFloatIntHashMap) super.clone(); - m._values = (int[]) this._values.clone(); - return m; - } - - /** - * @return a TFloatIntIterator with access to this map's keys and values - */ - public TFloatIntIterator iterator() { - return new TFloatIntIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new int[capacity]; - return capacity; - } - - /** - * 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 (float)0 if none was found. - */ - public int put(float key, int value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (float)0 if none was found. - */ - public int putIfAbsent(float key, int value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private int doPut(float key, int value, int index) { - byte previousState; - int previous = (int) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TFloatIntHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an float value - * @return the value of key or (float)0 if no such mapping exists. - */ - public int get(float key) { - int index = index(key); - return index < 0 ? (int) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - float[] keys = _set; - int[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (float) 0); - Arrays.fill(_values, 0, _values.length, (int) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an float value - * @return an int value, or (float)0 if no mapping for key exists - */ - public int remove(float key) { - int prev = (int) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TFloatIntHashMap)) { - return false; - } - TFloatIntHashMap that = (TFloatIntHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TFloatIntProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(float key, int value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TFloatIntProcedure { - private final TFloatIntHashMap _otherMap; - - EqProcedure(TFloatIntHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(float key, int value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two ints for equality. - */ - private final boolean eq(int v1, int v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (int) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public int[] getValues() { - int[] vals = new int[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public float[] keys(float[] a) { - int size = size(); - if (a.length < size) { - a = (float[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - float[] k = (float[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - int[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TIntFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (int) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public int adjustOrPutValue(final float key, final int adjust_amount, final int put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - float key = in.readFloat(); - int val = in.readInt(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TFloatIntProcedure() { - private boolean first = true; - - 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(); - } -} // TFloatIntHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntIterator.java deleted file mode 100644 index a713f775342..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TFloatIntIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TFloatIntHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TFloatIntIterator(TFloatIntHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - int old = value(); - _map._values[_index] = val; - return old; - } -}// TFloatIntIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntProcedure.java deleted file mode 100644 index ece899ea6d6..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIntProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type float and int. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TFloatIntProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIterator.java deleted file mode 100644 index 3ca08a167eb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatIterator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Iterator for float collections. - * - * @author Eric D. Friedman - * @version $Id: PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TFloatIterator extends TPrimitiveIterator { - /** - * the collection on which the iterator operates - */ - private final TFloatHash _hash; - - /** - * Creates a TFloatIterator for the elements in the specified collection. - */ - public TFloatIterator(TFloatHash hash) { - super(hash); - this._hash = hash; - } - - /** - * Advances the iterator to the next element in the underlying collection - * and returns it. - * - * @return the next float in the collection - * @throws NoSuchElementException if the iterator is already exhausted - */ - public float next() { - moveToNextIndex(); - return _hash._set[_index]; - } -}// TFloatIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongHashMap.java deleted file mode 100644 index 792932cc84d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for float keys and long values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TFloatLongHashMap extends TFloatHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TFloatLongProcedure PUT_ALL_PROC = new TFloatLongProcedure() { - public boolean execute(float key, long value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatLongHashMap(TFloatHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TFloatLongHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatLongHashMap(int initialCapacity, TFloatHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TFloatLongHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TFloatLongHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TFloatLongHashMap m = (TFloatLongHashMap) super.clone(); - m._values = (long[]) this._values.clone(); - return m; - } - - /** - * @return a TFloatLongIterator with access to this map's keys and values - */ - public TFloatLongIterator iterator() { - return new TFloatLongIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new long[capacity]; - return capacity; - } - - /** - * 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 (float)0 if none was found. - */ - public long put(float key, long value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (float)0 if none was found. - */ - public long putIfAbsent(float key, long value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private long doPut(float key, long value, int index) { - byte previousState; - long previous = (long) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TFloatLongHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an float value - * @return the value of key or (float)0 if no such mapping exists. - */ - public long get(float key) { - int index = index(key); - return index < 0 ? (long) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - float[] keys = _set; - long[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (float) 0); - Arrays.fill(_values, 0, _values.length, (long) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an float value - * @return an long value, or (float)0 if no mapping for key exists - */ - public long remove(float key) { - long prev = (long) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TFloatLongHashMap)) { - return false; - } - TFloatLongHashMap that = (TFloatLongHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TFloatLongProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(float key, long value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TFloatLongProcedure { - private final TFloatLongHashMap _otherMap; - - EqProcedure(TFloatLongHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(float key, long value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two longs for equality. - */ - private final boolean eq(long v1, long v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (long) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public long[] getValues() { - long[] vals = new long[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public float[] keys(float[] a) { - int size = size(); - if (a.length < size) { - a = (float[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - float[] k = (float[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - long[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TLongFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (long) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public long adjustOrPutValue(final float key, final long adjust_amount, final long put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - float key = in.readFloat(); - long val = in.readLong(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TFloatLongProcedure() { - private boolean first = true; - - 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(); - } -} // TFloatLongHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongIterator.java deleted file mode 100644 index cd853082e04..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TFloatLongIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TFloatLongHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TFloatLongIterator(TFloatLongHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - long old = value(); - _map._values[_index] = val; - return old; - } -}// TFloatLongIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongProcedure.java deleted file mode 100644 index f89d5cbb71b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatLongProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type float and long. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TFloatLongProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectHashMap.java deleted file mode 100644 index c0d99216ecd..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectHashMap.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TFloatObjectHashMap extends TFloatHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TFloatObjectProcedure PUT_ALL_PROC = new TFloatObjectProcedure() { - public boolean execute(float key, V value) { - put(key, value); - return true; - } - }; - - - /** - * the values of the map - */ - protected transient V[] _values; - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TFloatObjectHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatObjectHashMap(TFloatHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TFloatObjectHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatObjectHashMap(int initialCapacity, TFloatHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TFloatObjectHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public TFloatObjectHashMap clone() { - TFloatObjectHashMap m = (TFloatObjectHashMap) super.clone(); - m._values = (V[]) this._values.clone(); - return m; - } - - /** - * @return a TFloatObjectIterator with access to this map's keys and values - */ - public TFloatObjectIterator iterator() { - return new TFloatObjectIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = (V[]) new Object[capacity]; - return capacity; - } - - /** - * 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 {@code null} if none was found. - */ - public V put(float key, V value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 Object value - * @return the previous value associated with key, - * or {@code null} if none was found. - */ - public V putIfAbsent(float key, V value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private V doPut(float key, V value, int index) { - byte previousState; - V previous = null; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TFloatObjectHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an float value - * @return the value of key or (float)0 if no such mapping exists. - */ - public V get(float key) { - int index = index(key); - return index < 0 ? null : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - float[] keys = _set; - Object[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (float) 0); - Arrays.fill(_values, 0, _values.length, null); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an float value - * @return an Object value or (float)0 if no such mapping exists. - */ - 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; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TFloatObjectHashMap)) { - return false; - } - TFloatObjectHashMap that = (TFloatObjectHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TFloatObjectProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(float key, Object value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TFloatObjectProcedure { - private final TFloatObjectHashMap _otherMap; - - EqProcedure(TFloatObjectHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(float key, Object value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two objects for equality. - */ - private final boolean eq(Object o1, Object o2) { - return o1 == o2 || ((o1 != null) && o1.equals(o2)); - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = null; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - * @see #getValues(Object[]) - */ - public Object[] getValues() { - 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; - } - - /** - * Return the values of the map; the runtime type of the returned array is that of - * the specified array. - * - * @param a the array into which the elements of this collection are to be - * stored, if it is big enough; otherwise, a new array of the same - * runtime type is allocated for this purpose. - * @return an array containing the elements of this collection - * @throws ArrayStoreException the runtime type of the specified array is - * not a supertype of the runtime type of every element in this - * collection. - * @throws NullPointerException if the specified array is null. - * @see #getValues() - */ - public T[] getValues(T[] a) { - if (a.length < _size) { - a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), - _size); - } - - V[] v = _values; - byte[] states = _states; - - for (int i = v.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = (T) v[i]; - } - } - return a; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public float[] keys(float[] a) { - int size = size(); - if (a.length < size) { - a = (float[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - float[] k = (float[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(V 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 && - val == 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; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * Executes procedure for each key/value entry in the - * map. - * - * @param procedure a TOFloatObjectProcedure value - * @return false if the loop over the entries terminated because - * the procedure returned false for some entry. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TObjectFunction value - */ - 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]); - } - } - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // 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); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TFloatObjectProcedure() { - private boolean first = true; - - 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectIterator.java deleted file mode 100644 index 63c454c1279..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: P2OIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TFloatObjectIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TFloatObjectHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TFloatObjectIterator(TFloatObjectHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - V old = value(); - _map._values[_index] = val; - return old; - } -}// TFloatObjectIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectProcedure.java deleted file mode 100644 index 2bc79123441..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatObjectProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type float and Object. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2OProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TFloatObjectProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatProcedure.java deleted file mode 100644 index 938e053e8e1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatProcedure.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures with one float parameter. - *

- * Created: Mon Nov 5 21:45:49 2001 - * - * @author Eric D. Friedman - * @version $Id: PProcedure.template,v 1.2 2007/11/01 16:08:14 robeden Exp $ - */ - -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); -}// TFloatProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortHashMap.java deleted file mode 100644 index 46d57905478..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for float keys and short values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TFloatShortHashMap extends TFloatHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TFloatShortProcedure PUT_ALL_PROC = new TFloatShortProcedure() { - public boolean execute(float key, short value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatShortHashMap(TFloatHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TFloatShortHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TFloatShortHashMap(int initialCapacity, TFloatHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TFloatShortHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TFloatShortHashMap(int initialCapacity, float loadFactor, TFloatHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TFloatShortHashMap m = (TFloatShortHashMap) super.clone(); - m._values = (short[]) this._values.clone(); - return m; - } - - /** - * @return a TFloatShortIterator with access to this map's keys and values - */ - public TFloatShortIterator iterator() { - return new TFloatShortIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new short[capacity]; - return capacity; - } - - /** - * 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 (float)0 if none was found. - */ - public short put(float key, short value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (float)0 if none was found. - */ - public short putIfAbsent(float key, short value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private short doPut(float key, short value, int index) { - byte previousState; - short previous = (short) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TFloatShortHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an float value - * @return the value of key or (float)0 if no such mapping exists. - */ - public short get(float key) { - int index = index(key); - return index < 0 ? (short) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - float[] keys = _set; - short[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (float) 0); - Arrays.fill(_values, 0, _values.length, (short) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an float value - * @return an short value, or (float)0 if no mapping for key exists - */ - public short remove(float key) { - short prev = (short) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TFloatShortHashMap)) { - return false; - } - TFloatShortHashMap that = (TFloatShortHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TFloatShortProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(float key, short value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TFloatShortProcedure { - private final TFloatShortHashMap _otherMap; - - EqProcedure(TFloatShortHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(float key, short value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two shorts for equality. - */ - private final boolean eq(short v1, short v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (short) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public short[] getValues() { - short[] vals = new short[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public float[] keys(float[] a) { - int size = size(); - if (a.length < size) { - a = (float[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - float[] k = (float[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - short[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TShortFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (short) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public short adjustOrPutValue(final float key, final short adjust_amount, final short put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - float key = in.readFloat(); - short val = in.readShort(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TFloatShortProcedure() { - private boolean first = true; - - 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(); - } -} // TFloatShortHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortIterator.java deleted file mode 100644 index 33835a693c7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TFloatShortIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TFloatShortHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TFloatShortIterator(TFloatShortHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - short old = value(); - _map._values[_index] = val; - return old; - } -}// TFloatShortIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortProcedure.java deleted file mode 100644 index 3d06316051d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatShortProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type float and short. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TFloatShortProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatStack.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatStack.java deleted file mode 100644 index ee1be7741c2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TFloatStack.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -/** - * A stack of float primitives, backed by a TFloatArrayList. - * - * @author Eric D. Friedman, Rob Eden - * @version $Id: PStack.template,v 1.2 2007/02/28 23:03:57 robeden Exp $ - */ - -public class TFloatStack { - - /** - * the list used to hold the stack values. - */ - protected TFloatArrayList _list; - - public static final int DEFAULT_CAPACITY = TFloatArrayList.DEFAULT_CAPACITY; - - /** - * Creates a new TFloatStack instance with the default - * capacity. - */ - public TFloatStack() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TFloatStack instance with the - * specified capacity. - * - * @param capacity the initial depth of the stack - */ - public TFloatStack(int capacity) { - _list = new TFloatArrayList(capacity); - } - - /** - * Pushes the value onto the top of the stack. - * - * @param val an float value - */ - public void push(float val) { - _list.add(val); - } - - /** - * Removes and returns the value at the top of the stack. - * - * @return an float value - */ - public float pop() { - return _list.remove(_list.size() - 1); - } - - /** - * Returns the value at the top of the stack. - * - * @return an float value - */ - public float peek() { - return _list.get(_list.size() - 1); - } - - /** - * Returns the current depth of the stack. - */ - public int size() { - return _list.size(); - } - - /** - * Clears the stack, reseting its capacity to the default. - */ - public void clear() { - _list.clear(DEFAULT_CAPACITY); - } - - /** - * Clears the stack without releasing its internal capacity allocation. - */ - public void reset() { - _list.reset(); - } - - /** - * 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[] toNativeArray() { - return _list.toNativeArray(); - } - - /** - * 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 toNativeArray(float[] dest) { - _list.toNativeArray(dest, 0, size()); - } -} // TFloatStack diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THash.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THash.java deleted file mode 100644 index fddc42d7783..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THash.java +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; - - -/** - * 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) - * @version $Id: THash.java,v 1.14 2008/10/08 16:39:10 robeden Exp $ - */ - -abstract public class THash implements Cloneable, Externalizable { - static final long serialVersionUID = -1792948471915530295L; - - /** - * the load above which rehashing occurs. - */ - protected static final float DEFAULT_LOAD_FACTOR = 0.5f; - - /** - * 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_INITIAL_CAPACITY = 10; - - - /** - * 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 - */ - private transient boolean _autoCompactTemporaryDisable = false; - - - /** - * Creates a new THash instance with the default - * capacity and load factor. - */ - public THash() { - this(DEFAULT_INITIAL_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)); - } - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException cnse) { - return null; // it's supported - } - } - - /** - * 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 protected 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(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(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. - */ - public void setAutoCompactionFactor(float factor) { - if (factor < 0) { - throw new IllegalArgumentException("Factor must be >= 0: " + factor); - } - - _autoCompactionFactor = factor; - } - - /** - * @see #setAutoCompactionFactor - */ - 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}. - */ - protected 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. - */ - protected 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 - */ - private 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. - */ - private 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. - */ - 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; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // LOAD FACTOR - out.writeFloat(_loadFactor); - - // AUTO COMPACTION LOAD FACTOR - out.writeFloat(_autoCompactionFactor); - } - - 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_INITIAL_CAPACITY / _loadFactor)); - } - } -}// THash diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashIterator.java deleted file mode 100644 index 947216a7d79..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashIterator.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -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.

- */ -abstract class THashIterator extends TIterator implements Iterator { - private final TObjectHash _object_hash; - - /** - * Create an instance of THashIterator over the values of the TObjectHash - */ - public THashIterator(TObjectHash hash) { - super(hash); - _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. - */ - public V next() { - moveToNextIndex(); - return objectAtIndex(_index); - } - - /** - * 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashMap.java deleted file mode 100644 index 1a65d10f82e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashMap.java +++ /dev/null @@ -1,824 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -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 - * @version $Id: THashMap.java,v 1.33 2008/05/08 17:42:55 robeden Exp $ - */ -public class THashMap extends TObjectHash implements Map, 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare objects. - */ - public THashMap(TObjectHashingStrategy strategy) { - super(strategy); - } - - /** - * 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 default load factor. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare objects. - */ - public THashMap(int initialCapacity, TObjectHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 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 strategy used to compute hash codes and to compare objects. - */ - public THashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare objects. - */ - public THashMap(Map map, TObjectHashingStrategy strategy) { - this(map.size(), strategy); - putAll(map); - } - - /** - * @return a shallow clone of this collection - */ - public THashMap clone() { - THashMap m = (THashMap) super.clone(); - m._values = this._values.clone(); - return m; - } - - /** - * initialize the value array of the map. - * - * @param initialCapacity an int value - * @return an int value - */ - protected 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. - */ - public V put(K key, V value) { - int index = insertionIndex(key); - return doPut(key, 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. - */ - public V putIfAbsent(K key, V value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private V doPut(K key, V value, int index) { - V previous = null; - Object oldKey; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - oldKey = _set[index]; - _set[index] = key; - _values[index] = value; - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - - return previous; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - 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)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TObjectObjectProcedure() { - private boolean first = true; - - 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; - } - - public final boolean execute(K key, V value) { - h += _hashingStrategy.computeHashCode(key) ^ (value == null ? 0 : value.hashCode()); - return true; - } - } - - private static final class EqProcedure implements TObjectObjectProcedure { - private final Map _otherMap; - - EqProcedure(Map otherMap) { - _otherMap = otherMap; - } - - 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. - */ - 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. - */ - 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. - */ - 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. - */ - 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 - */ - 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 - */ - protected void rehash(int newCapacity) { - int oldCapacity = _set.length; - Object oldKeys[] = _set; - V oldVals[] = _values; - - _set = new Object[newCapacity]; - Arrays.fill(_set, FREE); - _values = (V[]) new Object[newCapacity]; - - for (int i = oldCapacity; i-- > 0;) { - if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { - Object o = oldKeys[i]; - int index = insertionIndex((K) o); - if (index < 0) { - throwObjectContractViolation(_set[(-index - 1)], o); - } - _set[index] = o; - _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. - */ - public V get(Object key) { - int index = index((K) key); - return index < 0 ? null : _values[index]; - } - - /** - * Empties the map. - */ - 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 - */ - public V remove(Object key) { - V prev = null; - int index = index((K) 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 - */ - protected 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 - */ - public Collection values() { - return new ValueView(); - } - - /** - * returns a Set view on the keys of the map. - * - * @return a Set value - */ - public Set keySet() { - return new KeyView(); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - 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 - */ - 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] || val.equals(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 - */ - public boolean containsKey(Object key) { - return contains(key); - } - - /** - * copies the key/value mappings in map into this map. - * - * @param map a Map value - */ - public void putAll(Map map) { - ensureCapacity(map.size()); - // could optimize this for cases when map instanceof THashMap - for (Iterator> i = map.entrySet().iterator(); i.hasNext();) { - Map.Entry e = i.next(); - put(e.getKey(), e.getValue()); - } - } - - /** - * a view onto the values of the map. - */ - protected class ValueView extends MapBackedView { - public Iterator iterator() { - return new THashIterator(THashMap.this) { - protected V objectAtIndex(int index) { - return _values[index]; - } - }; - } - - public boolean containsElement(V value) { - return containsValue(value); - } - - 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] && values[i].equals(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 THashIterator> { - EntryIterator(THashMap map) { - super(map); - } - - public Entry objectAtIndex(final int index) { - return new Entry((K) _set[index], _values[index], index); - } - } - - public Iterator> iterator() { - return new EntryIterator(THashMap.this); - } - - 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 && val.equals(_values[index]))) { - removeAt(index); // clear key,state; adjust size - return true; - } - } - return false; - } - - public boolean containsElement(Map.Entry entry) { - Object val = get(keyForEntry(entry)); - Object entryValue = entry.getValue(); - return entryValue == val || - (null != val && val.equals(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 { - - public abstract Iterator iterator(); - - public abstract boolean removeElement(E key); - - public abstract boolean containsElement(E key); - - public boolean contains(Object key) { - return containsElement((E) key); - } - - public boolean remove(Object o) { - return removeElement((E) o); - } - - public boolean containsAll(Collection collection) { - for (Iterator i = collection.iterator(); i.hasNext();) { - if (!contains(i.next())) { - return false; - } - } - return true; - } - - public void clear() { - THashMap.this.clear(); - } - - public boolean add(E obj) { - throw new UnsupportedOperationException(); - } - - public int size() { - return THashMap.this.size(); - } - - public Object[] toArray() { - Object[] result = new Object[size()]; - Iterator e = iterator(); - for (int i = 0; e.hasNext(); i++) - result[i] = e.next(); - return result; - } - - 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; - } - - public boolean isEmpty() { - return THashMap.this.isEmpty(); - } - - public boolean addAll(Collection collection) { - throw new UnsupportedOperationException(); - } - - 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; - } - } - - /** - * a view onto the keys of the map. - */ - protected class KeyView extends MapBackedView { - public Iterator iterator() { - return new TObjectHashIterator(THashMap.this); - } - - public boolean removeElement(K key) { - return null != THashMap.this.remove(key); - } - - 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; - } - - void setKey(K aKey) { - this.key = aKey; - } - - void setValue0(V aValue) { - this.val = aValue; - } - - public K getKey() { - return key; - } - - public V getValue() { - return val; - } - - public V setValue(V o) { - if (_values[index] != val) { - throw new ConcurrentModificationException(); - } - _values[index] = o; - o = val; // need to return previous value - val = o; // update this entry's value, in case - // setValue is called again - return o; - } - - 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 : e1.getKey().equals(e2.getKey())) - && (e1.getValue() == null ? e2.getValue() == null : e1.getValue().equals(e2.getValue())); - } - return false; - } - - public int hashCode() { - return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); - } - } - - - 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 - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashSet.java deleted file mode 100644 index 1b4bc62f400..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/THashSet.java +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -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. - *

- * Created: Sat Nov 3 10:38:17 2001 - * - * @author Eric D. Friedman - * @version $Id: THashSet.java,v 1.21 2008/10/07 20:33:56 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare objects. - */ - public THashSet(TObjectHashingStrategy 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 THashSet(int initialCapacity) { - super(initialCapacity); - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare objects. - */ - public THashSet(int initialCapacity, TObjectHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 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 strategy used to compute hash codes and to compare objects. - */ - public THashSet(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * Creates a new THashSet instance containing the - * elements of collection. - * - * @param collection a Collection value - */ - public THashSet(Collection collection) { - this(collection.size()); - addAll(collection); - } - - /** - * Creates a new THashSet instance containing the - * elements of collection. - * - * @param collection a Collection value - * @param strategy used to compute hash codes and to compare objects. - */ - public THashSet(Collection collection, TObjectHashingStrategy strategy) { - this(collection.size(), strategy); - addAll(collection); - } - - /** - * Inserts a value into the set. - * - * @param obj an Object value - * @return true if the set was modified by the add operation - */ - public boolean add(E obj) { - int index = insertionIndex(obj); - - if (index < 0) { - return false; // already present in set, nothing to add - } - - Object old = _set[index]; - _set[index] = obj; - - postInsertHook(old == FREE); - return true; // yes, we added something - } - - 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); - } - - 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; - } - - public final boolean execute(E key) { - h += _hashingStrategy.computeHashCode(key); - return true; - } - } - - /** - * Expands the set to accommodate new values. - * - * @param newCapacity an int value - */ - protected void rehash(int newCapacity) { - int oldCapacity = _set.length; - Object oldSet[] = _set; - - _set = new Object[newCapacity]; - Arrays.fill(_set, FREE); - - for (int i = oldCapacity; i-- > 0;) { - if (oldSet[i] != FREE && oldSet[i] != REMOVED) { - E o = (E) oldSet[i]; - int index = insertionIndex(o); - if (index < 0) { // everyone pays for this because some people can't RTFM - throwObjectContractViolation(_set[(-index - 1)], o); - } - _set[index] = o; - } - } - } - - /** - * Returns a new array containing the objects in the set. - * - * @return an Object[] value - */ - public Object[] toArray() { - Object[] result = new Object[size()]; - forEach(new ToObjectArrayProcedure(result)); - return result; - } - - /** - * Returns a typed array of the objects in the set. - * - * @param a an Object[] value - * @return an Object[] value - */ - public T[] toArray(T[] a) { - int size = size(); - if (a.length < size) - a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); - - forEach(new ToObjectArrayProcedure(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. - */ - 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. - */ - public boolean remove(Object obj) { - int index = index((E) 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 - */ - public Iterator 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. - */ - 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. - */ - 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. - */ - 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 - */ - public boolean retainAll(Collection collection) { - boolean changed = false; - int size = size(); - Iterator it; - - it = iterator(); - while (size-- > 0) { - if (!collection.contains(it.next())) { - it.remove(); - changed = true; - } - } - return changed; - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEach(new TObjectProcedure() { - private boolean first = true; - - public boolean execute(Object value) { - if (first) first = false; - else buf.append(","); - - buf.append(value); - return true; - } - }); - buf.append("}"); - return buf.toString(); - } - - - 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 - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEach(writeProcedure)) { - throw writeProcedure.exception; - } - } - - 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntArrayList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntArrayList.java deleted file mode 100644 index 96f4b69a062..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntArrayList.java +++ /dev/null @@ -1,935 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; -import java.util.Random; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * A resizable, array-backed list of int primitives. - *

- * Created: Sat Dec 29 14:21:12 2001 - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TIntArrayList implements Externalizable, Cloneable { - 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 = 10; - - /** - * Creates a new TIntArrayList instance with the - * default capacity. - */ - public TIntArrayList() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TIntArrayList instance with the - * specified capacity. - * - * @param capacity an int value - */ - public TIntArrayList(int capacity) { - _data = new int[capacity]; - _pos = 0; - } - - /** - * Creates a new TIntArrayList instance whose - * capacity is the greater of the length of values and - * DEFAULT_CAPACITY and whose initial contents are the specified - * values. - * - * @param values an int[] value - */ - public TIntArrayList(int[] values) { - this(Math.max(values.length, DEFAULT_CAPACITY)); - add(values); - } - - // sizing - - /** - * Grow the internal array as needed to accommodate the specified - * number of elements. The size of the array ints on each - * resize unless capacity requires more than twice the - * current capacity. - * - * @param capacity an int value - */ - 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; - } - } - - /** - * Returns the number of values in the list. - * - * @return the number of values in the list. - */ - public int size() { - return _pos; - } - - /** - * Tests whether this list contains any values. - * - * @return true if the list is empty. - */ - 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()]; - toNativeArray(tmp, 0, tmp.length); - _data = tmp; - } - } - - // modifying - - /** - * Adds val to the end of the list, growing as needed. - * - * @param val an int value - */ - public void add(int val) { - ensureCapacity(_pos + 1); - _data[_pos++] = 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) { - add(vals, 0, vals.length); - } - - /** - * 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) { - ensureCapacity(_pos + length); - System.arraycopy(vals, offset, _data, _pos, length); - _pos += 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) { - 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++; - } - - /** - * 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) { - insert(offset, values, 0, values.length); - } - - /** - * 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) { - 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; - } - - /** - * Returns the value at the specified offset. - * - * @param offset an int value - * @return an int value - */ - 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. - * - * @param offset an int value - * @return an int value - */ - public int getQuick(int offset) { - return _data[offset]; - } - - /** - * Sets the value at the specified offset. - * - * @param offset an int value - * @param val an int value - */ - public void set(int offset, int val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - _data[offset] = val; - } - - /** - * 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 getSet(int offset, int val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - int old = _data[offset]; - _data[offset] = val; - return old; - } - - /** - * 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) { - set(offset, values, 0, values.length); - } - - /** - * 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) { - 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. - * - * @param offset an int value - * @param val an int value - */ - public void setQuick(int offset, int val) { - _data[offset] = val; - } - - /** - * Flushes the internal state of the list, resetting the capacity - * to the default. - */ - public void clear() { - clear(DEFAULT_CAPACITY); - } - - /** - * Flushes the internal state of the list, setting the capacity of - * the empty list to capacity. - * - * @param capacity an int value - */ - 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 clear} method if you want to recyle a list without - * allocating new backing arrays. - * - * @see #clear - */ - public void reset() { - _pos = 0; - fill((int) 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 clear} method if you want to recyle a list - * without allocating new backing arrays. This method differs - * from {@link #reset reset} in that it does not clear the old - * values in the backing array. Thus, it is possible for {@link - * #getQuick getQuick} to return stale data if this method is used - * and the caller is careless about bounds checking. - * - * @see #reset - * @see #clear - * @see #getQuick - */ - public void resetQuick() { - _pos = 0; - } - - /** - * Removes the value at offset from the list. - * - * @param offset an int value - * @return the value previously stored at offset. - */ - public int remove(int offset) { - int old = get(offset); - remove(offset, 1); - return old; - } - - /** - * 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) { - 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 - } - - /** - * Transform each value in the list using the specified function. - * - * @param function a TIntFunction value - */ - public void transformValues(TIntFunction function) { - for (int i = _pos; i-- > 0;) { - _data[i] = function.execute(_data[i]); - } - } - - /** - * Reverse the order of the elements in the list. - */ - public void reverse() { - reverse(0, _pos); - } - - /** - * 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) { - 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); - } - } - - /** - * Shuffle the elements of the list using the specified random - * number generator. - * - * @param rand a Random value - */ - 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 final void swap(int i, int j) { - int tmp = _data[i]; - _data[i] = _data[j]; - _data[j] = tmp; - } - - // copying - - /** - * Returns a clone of this list. Since this is a primitive - * collection, this will be a deep clone. - * - * @return a deep clone of the list. - */ - public Object clone() { - TIntArrayList list = null; - try { - list = (TIntArrayList) super.clone(); - list._data = toNativeArray(); - } catch (CloneNotSupportedException e) { - // it's supported - } // end of try-catch - return list; - } - - - /** - * 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 TIntArrayList 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; - } - - - /** - * Copies the contents of the list into a native array. - * - * @return an int[] value - */ - public int[] toNativeArray() { - return toNativeArray(0, _pos); - } - - /** - * 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[] toNativeArray(int offset, int len) { - int[] rv = new int[len]; - toNativeArray(rv, offset, len); - return rv; - } - - /** - * Copies a slice of the list into a native array. - * - * @param dest the array to copy into. - * @param offset the offset of the first value to copy - * @param len the number of values to copy. - */ - public void toNativeArray(int[] dest, int offset, int len) { - if (len == 0) { - return; // nothing to copy - } - if (offset < 0 || offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - System.arraycopy(_data, offset, dest, 0, len); - } - - // comparing - - /** - * Compares this list to another list, value by value. - * - * @param other the object to compare against - * @return true if other is a TIntArrayList and has exactly the - * same values. - */ - public boolean equals(Object other) { - if (other == this) { - return true; - } else if (other instanceof TIntArrayList) { - TIntArrayList that = (TIntArrayList) other; - if (that.size() != this.size()) { - return false; - } else { - for (int i = _pos; i-- > 0;) { - if (this._data[i] != that._data[i]) { - return false; - } - } - return true; - } - } else { - return false; - } - } - - public int hashCode() { - int h = 0; - for (int i = _pos; i-- > 0;) { - h = 37 * h + HashFunctions.hash(_data[i]); - } - return h; - } - - // procedures - - /** - * 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. - */ - public boolean forEach(TIntProcedure procedure) { - for (int i = 0; i < _pos; i++) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - /** - * 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) { - for (int i = _pos; i-- > 0;) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - // sorting - - /** - * Sort the values in the list (ascending) using the Sun quicksort - * implementation. - * - * @see java.util.Arrays#sort - */ - public void sort() { - Arrays.sort(_data, 0, _pos); - } - - /** - * 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) { - Arrays.sort(_data, fromIndex, toIndex); - } - - // filling - - /** - * Fills every slot in the list with the specified value. - * - * @param val the value to use when filling - */ - public void fill(int val) { - Arrays.fill(_data, 0, _pos, 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) { - if (toIndex > _pos) { - ensureCapacity(toIndex); - _pos = toIndex; - } - Arrays.fill(_data, fromIndex, toIndex, val); - } - - // searching - - /** - * 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) { - return binarySearch(value, 0, _pos); - } - - /** - * 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) { - 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. - } - - /** - * 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) { - return indexOf(0, 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) { - for (int i = offset; i < _pos; i++) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * 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) { - return lastIndexOf(_pos, 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) { - for (int i = offset; i-- > 0;) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * Searches the list for value - * - * @param value an int value - * @return true if value is in the list. - */ - public boolean contains(int value) { - return lastIndexOf(value) >= 0; - } - - /** - * 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 TIntArrayList 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; - } - - /** - * 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 TIntArrayList 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; - } - - /** - * Finds the maximum value in the list. - * - * @return the largest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - /** - * Finds the minimum value in the list. - * - * @return the smallest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - // stringification - - /** - * Returns a String representation of the list, front to back. - * - * @return a String value - */ - 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(); - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(1); - - // POSITION - out.writeInt(_pos); - - // ENTRIES - int len = _pos; - out.writeInt(_pos); // Written twice for backwards compatability with - // version 0 - for (int i = 0; i < len; i++) { - out.writeInt(_data[i]); - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // POSITION - _pos = 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteHashMap.java deleted file mode 100644 index 6e030471893..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for int keys and byte values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TIntByteHashMap extends TIntHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TIntByteProcedure PUT_ALL_PROC = new TIntByteProcedure() { - public boolean execute(int key, byte value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntByteHashMap(TIntHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TIntByteHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntByteHashMap(int initialCapacity, TIntHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TIntByteHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TIntByteHashMap(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TIntByteHashMap m = (TIntByteHashMap) super.clone(); - m._values = (byte[]) this._values.clone(); - return m; - } - - /** - * @return a TIntByteIterator with access to this map's keys and values - */ - public TIntByteIterator iterator() { - return new TIntByteIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new byte[capacity]; - return capacity; - } - - /** - * 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 (int)0 if none was found. - */ - public byte put(int key, byte value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (int)0 if none was found. - */ - public byte putIfAbsent(int key, byte value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private byte doPut(int key, byte value, int index) { - byte previousState; - byte previous = (byte) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TIntByteHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an int value - * @return the value of key or (int)0 if no such mapping exists. - */ - public byte get(int key) { - int index = index(key); - return index < 0 ? (byte) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - int[] keys = _set; - byte[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (int) 0); - Arrays.fill(_values, 0, _values.length, (byte) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an int value - * @return an byte value, or (int)0 if no mapping for key exists - */ - public byte remove(int key) { - byte prev = (byte) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TIntByteHashMap)) { - return false; - } - TIntByteHashMap that = (TIntByteHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TIntByteProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(int key, byte value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TIntByteProcedure { - private final TIntByteHashMap _otherMap; - - EqProcedure(TIntByteHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(int key, byte value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two bytes for equality. - */ - private final boolean eq(byte v1, byte v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (byte) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public byte[] getValues() { - byte[] vals = new byte[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public int[] keys(int[] a) { - int size = size(); - if (a.length < size) { - a = (int[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - int[] k = (int[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - byte[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TByteFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (byte) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public byte adjustOrPutValue(final int key, final byte adjust_amount, final byte put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - int key = in.readInt(); - byte val = in.readByte(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TIntByteProcedure() { - private boolean first = true; - - 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(); - } -} // TIntByteHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteIterator.java deleted file mode 100644 index c8f9f2a0fd5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TIntByteIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TIntByteHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TIntByteIterator(TIntByteHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - byte old = value(); - _map._values[_index] = val; - return old; - } -}// TIntByteIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteProcedure.java deleted file mode 100644 index c3060f7b0d9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntByteProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type int and byte. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TIntByteProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleHashMap.java deleted file mode 100644 index feb08170a99..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for int keys and double values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TIntDoubleHashMap extends TIntHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TIntDoubleProcedure PUT_ALL_PROC = new TIntDoubleProcedure() { - public boolean execute(int key, double value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntDoubleHashMap(TIntHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TIntDoubleHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntDoubleHashMap(int initialCapacity, TIntHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TIntDoubleHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TIntDoubleHashMap(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TIntDoubleHashMap m = (TIntDoubleHashMap) super.clone(); - m._values = (double[]) this._values.clone(); - return m; - } - - /** - * @return a TIntDoubleIterator with access to this map's keys and values - */ - public TIntDoubleIterator iterator() { - return new TIntDoubleIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new double[capacity]; - return capacity; - } - - /** - * 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 (int)0 if none was found. - */ - public double put(int key, double value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (int)0 if none was found. - */ - public double putIfAbsent(int key, double value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private double doPut(int key, double value, int index) { - byte previousState; - double previous = (double) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TIntDoubleHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an int value - * @return the value of key or (int)0 if no such mapping exists. - */ - public double get(int key) { - int index = index(key); - return index < 0 ? (double) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - int[] keys = _set; - double[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (int) 0); - Arrays.fill(_values, 0, _values.length, (double) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an int value - * @return an double value, or (int)0 if no mapping for key exists - */ - public double remove(int key) { - double prev = (double) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TIntDoubleHashMap)) { - return false; - } - TIntDoubleHashMap that = (TIntDoubleHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TIntDoubleProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(int key, double value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TIntDoubleProcedure { - private final TIntDoubleHashMap _otherMap; - - EqProcedure(TIntDoubleHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(int key, double value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two doubles for equality. - */ - private final boolean eq(double v1, double v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (double) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public double[] getValues() { - double[] vals = new double[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public int[] keys(int[] a) { - int size = size(); - if (a.length < size) { - a = (int[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - int[] k = (int[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - double[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TDoubleFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (double) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public double adjustOrPutValue(final int key, final double adjust_amount, final double put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - int key = in.readInt(); - double val = in.readDouble(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TIntDoubleProcedure() { - private boolean first = true; - - 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(); - } -} // TIntDoubleHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleIterator.java deleted file mode 100644 index 6c46f10f55c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TIntDoubleIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TIntDoubleHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TIntDoubleIterator(TIntDoubleHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - double old = value(); - _map._values[_index] = val; - return old; - } -}// TIntDoubleIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleProcedure.java deleted file mode 100644 index 261146b8703..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntDoubleProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type int and double. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TIntDoubleProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatHashMap.java deleted file mode 100644 index 559a6e0c2c0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for int keys and float values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TIntFloatHashMap extends TIntHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TIntFloatProcedure PUT_ALL_PROC = new TIntFloatProcedure() { - public boolean execute(int key, float value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntFloatHashMap(TIntHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TIntFloatHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntFloatHashMap(int initialCapacity, TIntHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TIntFloatHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TIntFloatHashMap(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TIntFloatHashMap m = (TIntFloatHashMap) super.clone(); - m._values = (float[]) this._values.clone(); - return m; - } - - /** - * @return a TIntFloatIterator with access to this map's keys and values - */ - public TIntFloatIterator iterator() { - return new TIntFloatIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new float[capacity]; - return capacity; - } - - /** - * 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 (int)0 if none was found. - */ - public float put(int key, float value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (int)0 if none was found. - */ - public float putIfAbsent(int key, float value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private float doPut(int key, float value, int index) { - byte previousState; - float previous = (float) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TIntFloatHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an int value - * @return the value of key or (int)0 if no such mapping exists. - */ - public float get(int key) { - int index = index(key); - return index < 0 ? (float) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - int[] keys = _set; - float[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (int) 0); - Arrays.fill(_values, 0, _values.length, (float) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an int value - * @return an float value, or (int)0 if no mapping for key exists - */ - public float remove(int key) { - float prev = (float) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TIntFloatHashMap)) { - return false; - } - TIntFloatHashMap that = (TIntFloatHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TIntFloatProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(int key, float value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TIntFloatProcedure { - private final TIntFloatHashMap _otherMap; - - EqProcedure(TIntFloatHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(int key, float value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two floats for equality. - */ - private final boolean eq(float v1, float v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (float) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public float[] getValues() { - float[] vals = new float[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public int[] keys(int[] a) { - int size = size(); - if (a.length < size) { - a = (int[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - int[] k = (int[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - float[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TFloatFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (float) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public float adjustOrPutValue(final int key, final float adjust_amount, final float put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - int key = in.readInt(); - float val = in.readFloat(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TIntFloatProcedure() { - private boolean first = true; - - 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(); - } -} // TIntFloatHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatIterator.java deleted file mode 100644 index 8db542e11c9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TIntFloatIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TIntFloatHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TIntFloatIterator(TIntFloatHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - float old = value(); - _map._values[_index] = val; - return old; - } -}// TIntFloatIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatProcedure.java deleted file mode 100644 index b07522ed630..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFloatProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type int and float. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TIntFloatProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFunction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFunction.java deleted file mode 100644 index 3e063234adb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntFunction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for functions that accept and return one int primitive. - *

- * Created: Mon Nov 5 22:19:36 2001 - * - * @author Eric D. Friedman - * @version $Id: PFunction.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TIntFunction { - /** - * Execute this function with value - * - * @param value a int input - * @return a int result - */ - public int execute(int value); -}// TIntFunction diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHash.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHash.java deleted file mode 100644 index df71c205e78..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHash.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: PHash.template,v 1.2 2007/06/29 22:39:46 robeden Exp $ - */ - -abstract public class TIntHash extends TPrimitiveHash implements TIntHashingStrategy { - - /** - * the set of ints - */ - protected transient int[] _set; - - /** - * strategy used to hash values in this collection - */ - protected TIntHashingStrategy _hashingStrategy; - - /** - * Creates a new TIntHash instance with the default - * capacity and load factor. - */ - public TIntHash() { - super(); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * Creates a new TIntHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntHash(TIntHashingStrategy strategy) { - super(); - this._hashingStrategy = strategy; - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntHash(int initialCapacity, TIntHashingStrategy strategy) { - super(initialCapacity); - this._hashingStrategy = strategy; - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TIntHash(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { - super(initialCapacity, loadFactor); - this._hashingStrategy = strategy; - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TIntHash h = (TIntHash) super.clone(); - h._set = (int[]) this._set.clone(); - return h; - } - - /** - * 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 = 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 - */ - protected void removeAt(int index) { - _set[index] = (int) 0; - 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 = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - // see Knuth, p. 529 - probe = 1 + (hash % (length - 2)); - - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)); - } - - return states[index] == FREE ? -1 : index; - } - - /** - * 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 insertionIndex(int val) { - int hash, probe, index, length; - - final byte[] states = _states; - final int[] set = _set; - length = states.length; - hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] == FREE) { - return index; // empty, all done - } else if (states[index] == FULL && set[index] == val) { - 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 (states[index] != REMOVED) { - // starting at the natural offset, probe until we find an - // offset that isn't full. - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] == FULL && set[index] != val); - } - - // 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 (states[index] == REMOVED) { - int firstRemoved = index; - while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - index -= probe; - if (index < 0) { - index += length; - } - } - return states[index] == FULL ? -index - 1 : firstRemoved; - } - // if it's full, the key is already stored - return states[index] == FULL ? -index - 1 : index; - } - } - - /** - * Default implementation of TIntHashingStrategy: - * delegates hashing to HashFunctions.hash(int). - * - * @param val the value to hash - * @return the hashcode. - */ - public final int computeHashCode(int val) { - return HashFunctions.hash(val); - } -} // TIntHash diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHashSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHashSet.java deleted file mode 100644 index c9ae62bf6dd..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHashSet.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed set implementation for int primitives. - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TIntHashSet extends TIntHash implements 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 TIntHashSet 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 TIntHashSet(int initialCapacity, float loadFactor) { - super(initialCapacity, loadFactor); - } - - /** - * Creates a new TIntHashSet instance containing the - * elements of array. - * - * @param array an array of int primitives - */ - public TIntHashSet(int[] array) { - this(array.length); - addAll(array); - } - - /** - * Creates a new TIntHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntHashSet(TIntHashingStrategy strategy) { - super(strategy); - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntHashSet(int initialCapacity, TIntHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TIntHashSet(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * Creates a new TIntHashSet instance containing the - * elements of array. - * - * @param array an array of int primitives - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntHashSet(int[] array, TIntHashingStrategy strategy) { - this(array.length, strategy); - addAll(array); - } - - /** - * @return a TIntIterator with access to the values in this set - */ - public TIntIterator iterator() { - return new TIntIterator(this); - } - - /** - * Inserts a value into the set. - * - * @param val an int value - * @return true if the set was modified by the add operation - */ - public boolean add(int val) { - int index = insertionIndex(val); - - if (index < 0) { - return false; // already present in set, nothing to add - } - - byte previousState = _states[index]; - _set[index] = val; - _states[index] = FULL; - postInsertHook(previousState == FREE); - - return true; // yes, we added something - } - - /** - * Expands the set to accommodate new values. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _states[index] = FULL; - } - } - } - - /** - * Returns a new array containing the values in the set. - * - * @return an int[] value - */ - public int[] toArray() { - int[] result = new int[size()]; - 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; - } - - /** - * Empties the set. - */ - public void clear() { - super.clear(); - int[] set = _set; - byte[] states = _states; - - for (int i = set.length; i-- > 0;) { - set[i] = (int) 0; - states[i] = FREE; - } - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TIntHashSet)) { - return false; - } - final TIntHashSet that = (TIntHashSet) other; - if (that.size() != this.size()) { - return false; - } - return forEach(new TIntProcedure() { - public final boolean execute(int value) { - return that.contains(value); - } - }); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEach(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TIntProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(int key) { - h += _hashingStrategy.computeHashCode(key); - return true; - } - } - - /** - * Removes val from the set. - * - * @param val an int value - * @return true if the set was modified by the remove operation. - */ - public boolean remove(int val) { - int index = index(val); - if (index >= 0) { - removeAt(index); - return true; - } - return false; - } - - /** - * Tests the set to determine if all of the elements in - * array are present. - * - * @param array an array of int primitives. - * @return true if all elements were present in the set. - */ - public boolean containsAll(int[] array) { - for (int i = array.length; i-- > 0;) { - if (!contains(array[i])) { - return false; - } - } - return true; - } - - /** - * Adds all of the elements in array to the set. - * - * @param array an array of int primitives. - * @return true if the set was modified by the add all operation. - */ - public boolean addAll(int[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (add(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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. - */ - public boolean removeAll(int[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (remove(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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 - */ - 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)) { - remove(set[i]); - changed = true; - } - } - return changed; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEach(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - - // ENTRIES - setUp(size); - while (size-- > 0) { - int val = in.readInt(); - add(val); - } - } -} // TIntHashSet diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHashingStrategy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHashingStrategy.java deleted file mode 100644 index b877730cac3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntHashingStrategy.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Serializable; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface to support pluggable hashing strategies in maps and sets. - * Implementors can use this interface to make the trove hashing - * algorithms use an optimal strategy when computing hashcodes. - *

- * Created: Sun Nov 4 08:56:06 2001 - * - * @author Eric D. Friedman - * @version $Id: PHashingStrategy.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TIntHashingStrategy extends Serializable { - /** - * Computes a hash code for the specified int. Implementors - * can use the int's own value or a custom scheme designed to - * minimize collisions for a known set of input. - * - * @param val int for which the hashcode is to be computed - * @return the hashCode - */ - public int computeHashCode(int val); -} // TIntHashingStrategy diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntHashMap.java deleted file mode 100644 index d63cacccc2c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for int keys and int values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TIntIntHashMap extends TIntHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TIntIntProcedure PUT_ALL_PROC = new TIntIntProcedure() { - public boolean execute(int key, int value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntIntHashMap(TIntHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TIntIntHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntIntHashMap(int initialCapacity, TIntHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TIntIntHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TIntIntHashMap(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TIntIntHashMap m = (TIntIntHashMap) super.clone(); - m._values = (int[]) this._values.clone(); - return m; - } - - /** - * @return a TIntIntIterator with access to this map's keys and values - */ - public TIntIntIterator iterator() { - return new TIntIntIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new int[capacity]; - return capacity; - } - - /** - * 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 (int)0 if none was found. - */ - public int put(int key, int value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (int)0 if none was found. - */ - public int putIfAbsent(int key, int value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private int doPut(int key, int value, int index) { - byte previousState; - int previous = (int) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TIntIntHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an int value - * @return the value of key or (int)0 if no such mapping exists. - */ - public int get(int key) { - int index = index(key); - return index < 0 ? (int) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - int[] keys = _set; - int[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (int) 0); - Arrays.fill(_values, 0, _values.length, (int) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an int value - * @return an int value, or (int)0 if no mapping for key exists - */ - public int remove(int key) { - int prev = (int) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TIntIntHashMap)) { - return false; - } - TIntIntHashMap that = (TIntIntHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TIntIntProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(int key, int value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TIntIntProcedure { - private final TIntIntHashMap _otherMap; - - EqProcedure(TIntIntHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(int key, int value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two ints for equality. - */ - private final boolean eq(int v1, int v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (int) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public int[] getValues() { - int[] vals = new int[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public int[] keys(int[] a) { - int size = size(); - if (a.length < size) { - a = (int[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - int[] k = (int[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - int[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TIntFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (int) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public int adjustOrPutValue(final int key, final int adjust_amount, final int put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - int key = in.readInt(); - int val = in.readInt(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TIntIntProcedure() { - private boolean first = true; - - 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(); - } -} // TIntIntHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntIterator.java deleted file mode 100644 index de97baa707b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TIntIntIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TIntIntHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TIntIntIterator(TIntIntHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - int old = value(); - _map._values[_index] = val; - return old; - } -}// TIntIntIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntProcedure.java deleted file mode 100644 index 5a4890bad6a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIntProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type int and int. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TIntIntProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIterator.java deleted file mode 100644 index db3b82f7bc0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntIterator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Iterator for int collections. - * - * @author Eric D. Friedman - * @version $Id: PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TIntIterator extends TPrimitiveIterator { - /** - * the collection on which the iterator operates - */ - private final TIntHash _hash; - - /** - * Creates a TIntIterator for the elements in the specified collection. - */ - public TIntIterator(TIntHash hash) { - super(hash); - this._hash = hash; - } - - /** - * Advances the iterator to the next element in the underlying collection - * and returns it. - * - * @return the next int in the collection - * @throws NoSuchElementException if the iterator is already exhausted - */ - public int next() { - moveToNextIndex(); - return _hash._set[_index]; - } -}// TIntIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongHashMap.java deleted file mode 100644 index eecfa9f9d60..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for int keys and long values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TIntLongHashMap extends TIntHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TIntLongProcedure PUT_ALL_PROC = new TIntLongProcedure() { - public boolean execute(int key, long value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntLongHashMap(TIntHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TIntLongHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntLongHashMap(int initialCapacity, TIntHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TIntLongHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TIntLongHashMap(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TIntLongHashMap m = (TIntLongHashMap) super.clone(); - m._values = (long[]) this._values.clone(); - return m; - } - - /** - * @return a TIntLongIterator with access to this map's keys and values - */ - public TIntLongIterator iterator() { - return new TIntLongIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new long[capacity]; - return capacity; - } - - /** - * 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 (int)0 if none was found. - */ - public long put(int key, long value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (int)0 if none was found. - */ - public long putIfAbsent(int key, long value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private long doPut(int key, long value, int index) { - byte previousState; - long previous = (long) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TIntLongHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an int value - * @return the value of key or (int)0 if no such mapping exists. - */ - public long get(int key) { - int index = index(key); - return index < 0 ? (long) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - int[] keys = _set; - long[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (int) 0); - Arrays.fill(_values, 0, _values.length, (long) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an int value - * @return an long value, or (int)0 if no mapping for key exists - */ - public long remove(int key) { - long prev = (long) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TIntLongHashMap)) { - return false; - } - TIntLongHashMap that = (TIntLongHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TIntLongProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(int key, long value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TIntLongProcedure { - private final TIntLongHashMap _otherMap; - - EqProcedure(TIntLongHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(int key, long value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two longs for equality. - */ - private final boolean eq(long v1, long v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (long) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public long[] getValues() { - long[] vals = new long[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public int[] keys(int[] a) { - int size = size(); - if (a.length < size) { - a = (int[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - int[] k = (int[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - long[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TLongFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (long) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public long adjustOrPutValue(final int key, final long adjust_amount, final long put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - int key = in.readInt(); - long val = in.readLong(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TIntLongProcedure() { - private boolean first = true; - - 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(); - } -} // TIntLongHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongIterator.java deleted file mode 100644 index 69d59cffeb8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TIntLongIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TIntLongHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TIntLongIterator(TIntLongHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - long old = value(); - _map._values[_index] = val; - return old; - } -}// TIntLongIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongProcedure.java deleted file mode 100644 index dd0a0b3ee95..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntLongProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type int and long. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TIntLongProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectHashMap.java deleted file mode 100644 index 499ca659ae3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectHashMap.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TIntObjectHashMap extends TIntHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TIntObjectProcedure PUT_ALL_PROC = new TIntObjectProcedure() { - public boolean execute(int key, V value) { - put(key, value); - return true; - } - }; - - - /** - * the values of the map - */ - protected transient V[] _values; - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TIntObjectHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntObjectHashMap(TIntHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TIntObjectHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntObjectHashMap(int initialCapacity, TIntHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TIntObjectHashMap(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public TIntObjectHashMap clone() { - TIntObjectHashMap m = (TIntObjectHashMap) super.clone(); - m._values = (V[]) this._values.clone(); - return m; - } - - /** - * @return a TIntObjectIterator with access to this map's keys and values - */ - public TIntObjectIterator iterator() { - return new TIntObjectIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = (V[]) new Object[capacity]; - return capacity; - } - - /** - * Inserts a key/value pair into the map. - * - * @param key an int value - * @param value an Object value - * @return the previous value associated with key, - * or {@code null} if none was found. - */ - public V put(int key, V value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 Object value - * @return the previous value associated with key, - * or {@code null} if none was found. - */ - public V putIfAbsent(int key, V value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private V doPut(int key, V value, int index) { - byte previousState; - V previous = null; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TIntObjectHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an int value - * @return the value of key or (int)0 if no such mapping exists. - */ - public V get(int key) { - int index = index(key); - return index < 0 ? null : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - int[] keys = _set; - Object[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (int) 0); - Arrays.fill(_values, 0, _values.length, null); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an int value - * @return an Object value or (int)0 if no such mapping exists. - */ - 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; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TIntObjectHashMap)) { - return false; - } - TIntObjectHashMap that = (TIntObjectHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TIntObjectProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(int key, Object value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TIntObjectProcedure { - private final TIntObjectHashMap _otherMap; - - EqProcedure(TIntObjectHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(int key, Object value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two objects for equality. - */ - private final boolean eq(Object o1, Object o2) { - return o1 == o2 || ((o1 != null) && o1.equals(o2)); - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = null; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - * @see #getValues(Object[]) - */ - public Object[] getValues() { - 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; - } - - /** - * Return the values of the map; the runtime type of the returned array is that of - * the specified array. - * - * @param a the array into which the elements of this collection are to be - * stored, if it is big enough; otherwise, a new array of the same - * runtime type is allocated for this purpose. - * @return an array containing the elements of this collection - * @throws ArrayStoreException the runtime type of the specified array is - * not a supertype of the runtime type of every element in this - * collection. - * @throws NullPointerException if the specified array is null. - * @see #getValues() - */ - public T[] getValues(T[] a) { - if (a.length < _size) { - a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), - _size); - } - - V[] v = _values; - byte[] states = _states; - - for (int i = v.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = (T) v[i]; - } - } - return a; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public int[] keys(int[] a) { - int size = size(); - if (a.length < size) { - a = (int[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - int[] k = (int[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(V 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 && - val == 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; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * Executes procedure for each key/value entry in the - * map. - * - * @param procedure a TOIntObjectProcedure value - * @return false if the loop over the entries terminated because - * the procedure returned false for some entry. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TObjectFunction value - */ - 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]); - } - } - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // 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); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TIntObjectProcedure() { - private boolean first = true; - - 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectIterator.java deleted file mode 100644 index 67e63fb04ac..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: P2OIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TIntObjectIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TIntObjectHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TIntObjectIterator(TIntObjectHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - V old = value(); - _map._values[_index] = val; - return old; - } -}// TIntObjectIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectProcedure.java deleted file mode 100644 index c14e332bd87..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntObjectProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type int and Object. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2OProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TIntObjectProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntProcedure.java deleted file mode 100644 index a0a4391d425..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntProcedure.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures with one int parameter. - *

- * Created: Mon Nov 5 21:45:49 2001 - * - * @author Eric D. Friedman - * @version $Id: PProcedure.template,v 1.2 2007/11/01 16:08:14 robeden Exp $ - */ - -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); -}// TIntProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortHashMap.java deleted file mode 100644 index 5c8a5b5228e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for int keys and short values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TIntShortHashMap extends TIntHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TIntShortProcedure PUT_ALL_PROC = new TIntShortProcedure() { - public boolean execute(int key, short value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntShortHashMap(TIntHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TIntShortHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TIntShortHashMap(int initialCapacity, TIntHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TIntShortHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TIntShortHashMap(int initialCapacity, float loadFactor, TIntHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TIntShortHashMap m = (TIntShortHashMap) super.clone(); - m._values = (short[]) this._values.clone(); - return m; - } - - /** - * @return a TIntShortIterator with access to this map's keys and values - */ - public TIntShortIterator iterator() { - return new TIntShortIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new short[capacity]; - return capacity; - } - - /** - * 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 (int)0 if none was found. - */ - public short put(int key, short value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (int)0 if none was found. - */ - public short putIfAbsent(int key, short value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private short doPut(int key, short value, int index) { - byte previousState; - short previous = (short) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TIntShortHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an int value - * @return the value of key or (int)0 if no such mapping exists. - */ - public short get(int key) { - int index = index(key); - return index < 0 ? (short) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - int[] keys = _set; - short[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (int) 0); - Arrays.fill(_values, 0, _values.length, (short) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an int value - * @return an short value, or (int)0 if no mapping for key exists - */ - public short remove(int key) { - short prev = (short) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TIntShortHashMap)) { - return false; - } - TIntShortHashMap that = (TIntShortHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TIntShortProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(int key, short value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TIntShortProcedure { - private final TIntShortHashMap _otherMap; - - EqProcedure(TIntShortHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(int key, short value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two shorts for equality. - */ - private final boolean eq(short v1, short v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (short) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public short[] getValues() { - short[] vals = new short[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public int[] keys(int[] a) { - int size = size(); - if (a.length < size) { - a = (int[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - int[] k = (int[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - short[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TShortFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (short) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public short adjustOrPutValue(final int key, final short adjust_amount, final short put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - int key = in.readInt(); - short val = in.readShort(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TIntShortProcedure() { - private boolean first = true; - - 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(); - } -} // TIntShortHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortIterator.java deleted file mode 100644 index b51bd221f91..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TIntShortIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TIntShortHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TIntShortIterator(TIntShortHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - short old = value(); - _map._values[_index] = val; - return old; - } -}// TIntShortIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortProcedure.java deleted file mode 100644 index fb0c96e1591..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntShortProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type int and short. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TIntShortProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntStack.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntStack.java deleted file mode 100644 index 68c41f33286..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIntStack.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -/** - * A stack of int primitives, backed by a TIntArrayList. - * - * @author Eric D. Friedman, Rob Eden - * @version $Id: PStack.template,v 1.2 2007/02/28 23:03:57 robeden Exp $ - */ - -public class TIntStack { - - /** - * the list used to hold the stack values. - */ - protected TIntArrayList _list; - - public static final int DEFAULT_CAPACITY = TIntArrayList.DEFAULT_CAPACITY; - - /** - * Creates a new TIntStack instance with the default - * capacity. - */ - public TIntStack() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TIntStack instance with the - * specified capacity. - * - * @param capacity the initial depth of the stack - */ - public TIntStack(int capacity) { - _list = new TIntArrayList(capacity); - } - - /** - * Pushes the value onto the top of the stack. - * - * @param val an int value - */ - public void push(int val) { - _list.add(val); - } - - /** - * Removes and returns the value at the top of the stack. - * - * @return an int value - */ - public int pop() { - return _list.remove(_list.size() - 1); - } - - /** - * Returns the value at the top of the stack. - * - * @return an int value - */ - public int peek() { - return _list.get(_list.size() - 1); - } - - /** - * Returns the current depth of the stack. - */ - public int size() { - return _list.size(); - } - - /** - * Clears the stack, reseting its capacity to the default. - */ - public void clear() { - _list.clear(DEFAULT_CAPACITY); - } - - /** - * Clears the stack without releasing its internal capacity allocation. - */ - public void reset() { - _list.reset(); - } - - /** - * 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[] toNativeArray() { - return _list.toNativeArray(); - } - - /** - * 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 toNativeArray(int[] dest) { - _list.toNativeArray(dest, 0, size()); - } -} // TIntStack diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIterator.java deleted file mode 100644 index 93878c98f8d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TIterator.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.util.ConcurrentModificationException; -import java.util.NoSuchElementException; - -/** - * Abstract iterator class for THash implementations. This class provides some - * of the common iterator operations (hasNext(), remove()) and allows subclasses - * to define the mechanism(s) for advancing the iterator and returning data. - * - * @author Eric D. Friedman - * @version $Id: TIterator.java,v 1.3 2007/06/29 20:03:10 robeden Exp $ - */ -abstract class TIterator { - /** - * 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 TIterator over the specified THash. - */ - public TIterator(THash hash) { - _hash = hash; - _expectedSize = _hash.size(); - _index = _hash.capacity(); - } - - /** - * Returns true if the iterator can be advanced past its current - * location. - * - * @return a boolean value - */ - 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. - */ - 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 - */ - abstract protected int nextIndex(); -} // TIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkable.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkable.java deleted file mode 100644 index 9f888e78933..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkable.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Serializable; - - -/** - * Interface for Objects which can be inserted into a TLinkedList. - *

- *

- * Created: Sat Nov 10 15:23:41 2001 - *

- * - * @author Eric D. Friedman - * @version $Id: TLinkable.java,v 1.2 2001/12/03 00:16:25 ericdf Exp $ - * @see org.elasticsearch.util.gnu.trove.TLinkedList - */ - -public interface TLinkable extends Serializable { - - /** - * Returns the linked list node after this one. - * - * @return a TLinkable value - */ - public TLinkable getNext(); - - /** - * Returns the linked list node before this one. - * - * @return a TLinkable value - */ - public TLinkable getPrevious(); - - /** - * Sets the linked list node after this one. - * - * @param linkable a TLinkable value - */ - public void setNext(TLinkable linkable); - - /** - * Sets the linked list node before this one. - * - * @param linkable a TLinkable value - */ - public void setPrevious(TLinkable linkable); -}// TLinkable diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkableAdapter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkableAdapter.java deleted file mode 100644 index 11e4c5d753c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkableAdapter.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -/** - * Adapter for TLinkable interface which implements the interface and can - * therefore be extended trivially to create TLinkable objects without - * having to implement the obvious. - *

- *

- * Created: Thurs Nov 15 16:25:00 2001 - *

- * - * @author Jason Baldridge - * @version $Id: TLinkableAdapter.java,v 1.1 2006/11/10 23:27:56 robeden Exp $ - * @see org.elasticsearch.util.gnu.trove.TLinkedList - */ - -public class TLinkableAdapter implements TLinkable { - TLinkable _previous, _next; - - /** - * Returns the linked list node after this one. - * - * @return a TLinkable value - */ - public TLinkable getNext() { - return _next; - } - - /** - * Returns the linked list node before this one. - * - * @return a TLinkable value - */ - public TLinkable getPrevious() { - return _previous; - } - - /** - * Sets the linked list node after this one. - * - * @param linkable a TLinkable value - */ - public void setNext(TLinkable linkable) { - _next = linkable; - } - - /** - * Sets the linked list node before this one. - * - * @param linkable a TLinkable value - */ - public void setPrevious(TLinkable linkable) { - _previous = linkable; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkedList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkedList.java deleted file mode 100644 index 03dc0402ee3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLinkedList.java +++ /dev/null @@ -1,749 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.AbstractSequentialList; -import java.util.ListIterator; -import java.util.NoSuchElementException; - -/** - * 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 List implement the TLinkable - * interface.

- *

- *

The limitations are that you cannot put the same object into - * more than one list or more than once in the same list. You must - * also ensure that you only remove objects that are actually in the - * list. That is, if you have an object A and lists l1 and l2, you - * must ensure that you invoke List.remove(A) on the correct list. It - * is also forbidden to invoke List.remove() with an unaffiliated - * TLinkable (one that belongs to no list): this will destroy the list - * you invoke it on.

- *

- *

- * Created: Sat Nov 10 15:25:10 2001 - *

- * - * @author Eric D. Friedman - * @version $Id: TLinkedList.java,v 1.15 2009/03/31 19:43:14 robeden Exp $ - * @see org.elasticsearch.util.gnu.trove.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 - */ - public ListIterator listIterator(int index) { - return new IteratorImpl(index); - } - - /** - * Returns the number of elements in the list. - * - * @return an int value - */ - 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 - */ - 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 - */ - 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. - */ - 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 - */ - 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 (T link = _head, tmp = null; link != null; i++) { - o[i] = link; - tmp = link; - link = (T) link.getNext(); - tmp.setNext(null); // clear the links - tmp.setPrevious(null); - } - _size = 0; // clear the list - _head = _tail = null; - return o; - } - - /** - * A linear search for o in the list. - * - * @param o an Object value - * @return a boolean value - */ - public boolean contains(Object o) { - for (TLinkable link = _head; link != null; link = link.getNext()) { - if (o.equals(link)) { - return true; - } - } - return false; - } - - - /** - * {@inheritDoc} - */ - @Override - 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 = (T) node.getPrevious(); - position--; - } - - return node; - } else { - int position = 0; - T node = _head; - - while (position < index) { - node = (T) 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. - */ - public T getNext(T current) { - return (T) 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. - */ - public T getPrevious(T current) { - return (T) current.getPrevious(); - } - - - /** - * Remove and return the first element in the list. - * - * @return an Object value - */ - public T removeFirst() { - T o = _head; - - if (o == null) return null; - - T n = (T) 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 - */ - public T removeLast() { - T o = _tail; - - if (o == null) return null; - - T prev = (T) 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 - */ - protected void insert(int index, T linkable) { - T newLink = linkable; - - if (_size == 0) { - _head = _tail = newLink; // first insertion - } else if (index == 0) { - newLink.setNext(_head); // insert at front - _head.setPrevious(newLink); - _head = newLink; - } else if (index == _size) { // insert at back - _tail.setNext(newLink); - newLink.setPrevious(_tail); - _tail = newLink; - } else { - T node = get(index); - - T before = (T) 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 - */ - public boolean remove(Object o) { - if (o instanceof TLinkable) { - T p, n; - TLinkable link = (TLinkable) o; - - p = (T) link.getPrevious(); - n = (T) 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 { - TLinkable 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 { - TLinkable 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. - */ - public boolean forEachValue(TObjectProcedure procedure) { - T node = _head; - while (node != null) { - boolean keep_going = procedure.execute(node); - if (!keep_going) return false; - - node = (T) node.getNext(); - } - - return true; - } - - - 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); - } - - 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 - */ - 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 = (T) _next.getNext(); - } - } else { - int pos = _size - 1; - for (_next = _tail; pos > position; pos--) { - _next = (T) _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 - */ - 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 - */ - public final boolean hasNext() { - return _nextIndex != _size; - } - - /** - * True if a call to previous() will return a value. - * - * @return a boolean value - */ - 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 - */ - public final T next() { - if (_nextIndex == _size) { - throw new NoSuchElementException(); - } - - _lastReturned = _next; - _next = (T) _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 - */ - 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. - */ - public final T previous() { - if (_nextIndex == 0) { - throw new NoSuchElementException(); - } - - if (_nextIndex == _size) { - _lastReturned = _next = _tail; - } else { - _lastReturned = _next = (T) _next.getPrevious(); - } - - _nextIndex--; - return _lastReturned; - } - - /** - * Returns the previous element's index. - * - * @return an int value - */ - 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. - */ - public final void remove() { - if (_lastReturned == null) { - throw new IllegalStateException("must invoke next or previous before invoking remove"); - } - - if (_lastReturned != _next) { - _nextIndex--; - } - _next = (T) _lastReturned.getNext(); - TLinkedList.this.remove(_lastReturned); - _lastReturned = null; - } - - /** - * Replaces the current element in the list with - * linkable - * - * @param linkable an object of type TLinkable - */ - public final void set(T linkable) { - if (_lastReturned == null) { - throw new IllegalStateException(); - } - T l = linkable; - - // need to check both, since this could be the only - // element in the list. - if (_lastReturned == _head) { - _head = l; - } - - if (_lastReturned == _tail) { - _tail = l; - } - - swap(_lastReturned, l); - _lastReturned = l; - } - - /** - * 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 p = (T) from.getPrevious(); - T n = (T) from.getNext(); - - if (null != p) { - to.setPrevious(p); - p.setNext(to); - } - if (null != n) { - to.setNext(n); - n.setPrevious(to); - } - from.setNext(null); - from.setPrevious(null); - } - } -} // TLinkedList diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongArrayList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongArrayList.java deleted file mode 100644 index 29aa3844bc6..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongArrayList.java +++ /dev/null @@ -1,935 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; -import java.util.Random; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * A resizable, array-backed list of long primitives. - *

- * Created: Sat Dec 29 14:21:12 2001 - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TLongArrayList implements Externalizable, Cloneable { - 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 = 10; - - /** - * Creates a new TLongArrayList instance with the - * default capacity. - */ - public TLongArrayList() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TLongArrayList instance with the - * specified capacity. - * - * @param capacity an int value - */ - public TLongArrayList(int capacity) { - _data = new long[capacity]; - _pos = 0; - } - - /** - * Creates a new TLongArrayList instance whose - * capacity is the greater of the length of values and - * DEFAULT_CAPACITY and whose initial contents are the specified - * values. - * - * @param values an long[] value - */ - public TLongArrayList(long[] values) { - this(Math.max(values.length, DEFAULT_CAPACITY)); - add(values); - } - - // sizing - - /** - * Grow the internal array as needed to accommodate the specified - * number of elements. The size of the array longs on each - * resize unless capacity requires more than twice the - * current capacity. - * - * @param capacity an int value - */ - 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; - } - } - - /** - * Returns the number of values in the list. - * - * @return the number of values in the list. - */ - public int size() { - return _pos; - } - - /** - * Tests whether this list contains any values. - * - * @return true if the list is empty. - */ - 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()]; - toNativeArray(tmp, 0, tmp.length); - _data = tmp; - } - } - - // modifying - - /** - * Adds val to the end of the list, growing as needed. - * - * @param val an long value - */ - public void add(long val) { - ensureCapacity(_pos + 1); - _data[_pos++] = 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) { - add(vals, 0, vals.length); - } - - /** - * 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) { - ensureCapacity(_pos + length); - System.arraycopy(vals, offset, _data, _pos, length); - _pos += 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) { - 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++; - } - - /** - * 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) { - insert(offset, values, 0, values.length); - } - - /** - * 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) { - 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; - } - - /** - * Returns the value at the specified offset. - * - * @param offset an int value - * @return an long value - */ - 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. - * - * @param offset an int value - * @return an long value - */ - public long getQuick(int offset) { - return _data[offset]; - } - - /** - * Sets the value at the specified offset. - * - * @param offset an int value - * @param val an long value - */ - public void set(int offset, long val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - _data[offset] = val; - } - - /** - * 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 getSet(int offset, long val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - long old = _data[offset]; - _data[offset] = val; - return old; - } - - /** - * 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) { - set(offset, values, 0, values.length); - } - - /** - * 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) { - 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. - * - * @param offset an int value - * @param val an long value - */ - public void setQuick(int offset, long val) { - _data[offset] = val; - } - - /** - * Flushes the internal state of the list, resetting the capacity - * to the default. - */ - public void clear() { - clear(DEFAULT_CAPACITY); - } - - /** - * Flushes the internal state of the list, setting the capacity of - * the empty list to capacity. - * - * @param capacity an int value - */ - 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 clear} method if you want to recyle a list without - * allocating new backing arrays. - * - * @see #clear - */ - public void reset() { - _pos = 0; - fill((long) 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 clear} method if you want to recyle a list - * without allocating new backing arrays. This method differs - * from {@link #reset reset} in that it does not clear the old - * values in the backing array. Thus, it is possible for {@link - * #getQuick getQuick} to return stale data if this method is used - * and the caller is careless about bounds checking. - * - * @see #reset - * @see #clear - * @see #getQuick - */ - public void resetQuick() { - _pos = 0; - } - - /** - * Removes the value at offset from the list. - * - * @param offset an int value - * @return the value previously stored at offset. - */ - public long remove(int offset) { - long old = get(offset); - remove(offset, 1); - return old; - } - - /** - * 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) { - 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 - } - - /** - * Transform each value in the list using the specified function. - * - * @param function a TLongFunction value - */ - public void transformValues(TLongFunction function) { - for (int i = _pos; i-- > 0;) { - _data[i] = function.execute(_data[i]); - } - } - - /** - * Reverse the order of the elements in the list. - */ - public void reverse() { - reverse(0, _pos); - } - - /** - * 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) { - 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); - } - } - - /** - * Shuffle the elements of the list using the specified random - * number generator. - * - * @param rand a Random value - */ - 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 final void swap(int i, int j) { - long tmp = _data[i]; - _data[i] = _data[j]; - _data[j] = tmp; - } - - // copying - - /** - * Returns a clone of this list. Since this is a primitive - * collection, this will be a deep clone. - * - * @return a deep clone of the list. - */ - public Object clone() { - TLongArrayList list = null; - try { - list = (TLongArrayList) super.clone(); - list._data = toNativeArray(); - } catch (CloneNotSupportedException e) { - // it's supported - } // end of try-catch - return list; - } - - - /** - * 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 TLongArrayList 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; - } - - - /** - * Copies the contents of the list into a native array. - * - * @return an long[] value - */ - public long[] toNativeArray() { - return toNativeArray(0, _pos); - } - - /** - * 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[] toNativeArray(int offset, int len) { - long[] rv = new long[len]; - toNativeArray(rv, offset, len); - return rv; - } - - /** - * Copies a slice of the list into a native array. - * - * @param dest the array to copy into. - * @param offset the offset of the first value to copy - * @param len the number of values to copy. - */ - public void toNativeArray(long[] dest, int offset, int len) { - if (len == 0) { - return; // nothing to copy - } - if (offset < 0 || offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - System.arraycopy(_data, offset, dest, 0, len); - } - - // comparing - - /** - * Compares this list to another list, value by value. - * - * @param other the object to compare against - * @return true if other is a TLongArrayList and has exactly the - * same values. - */ - public boolean equals(Object other) { - if (other == this) { - return true; - } else if (other instanceof TLongArrayList) { - TLongArrayList that = (TLongArrayList) other; - if (that.size() != this.size()) { - return false; - } else { - for (int i = _pos; i-- > 0;) { - if (this._data[i] != that._data[i]) { - return false; - } - } - return true; - } - } else { - return false; - } - } - - public int hashCode() { - int h = 0; - for (int i = _pos; i-- > 0;) { - h = 37 * h + HashFunctions.hash(_data[i]); - } - return h; - } - - // procedures - - /** - * 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. - */ - public boolean forEach(TLongProcedure procedure) { - for (int i = 0; i < _pos; i++) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - /** - * 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) { - for (int i = _pos; i-- > 0;) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - // sorting - - /** - * Sort the values in the list (ascending) using the Sun quicksort - * implementation. - * - * @see java.util.Arrays#sort - */ - public void sort() { - Arrays.sort(_data, 0, _pos); - } - - /** - * 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) { - Arrays.sort(_data, fromIndex, toIndex); - } - - // filling - - /** - * Fills every slot in the list with the specified value. - * - * @param val the value to use when filling - */ - public void fill(long val) { - Arrays.fill(_data, 0, _pos, 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) { - if (toIndex > _pos) { - ensureCapacity(toIndex); - _pos = toIndex; - } - Arrays.fill(_data, fromIndex, toIndex, val); - } - - // searching - - /** - * 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) { - return binarySearch(value, 0, _pos); - } - - /** - * 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) { - 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. - } - - /** - * 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) { - return indexOf(0, 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) { - for (int i = offset; i < _pos; i++) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * 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) { - return lastIndexOf(_pos, 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) { - for (int i = offset; i-- > 0;) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * Searches the list for value - * - * @param value an long value - * @return true if value is in the list. - */ - public boolean contains(long value) { - return lastIndexOf(value) >= 0; - } - - /** - * 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 TLongArrayList 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; - } - - /** - * 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 TLongArrayList 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; - } - - /** - * Finds the maximum value in the list. - * - * @return the largest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - /** - * Finds the minimum value in the list. - * - * @return the smallest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - // stringification - - /** - * Returns a String representation of the list, front to back. - * - * @return a String value - */ - 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(); - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(1); - - // POSITION - out.writeInt(_pos); - - // ENTRIES - int len = _pos; - out.writeInt(_pos); // Written twice for backwards compatability with - // version 0 - for (int i = 0; i < len; i++) { - out.writeLong(_data[i]); - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // POSITION - _pos = in.readInt(); - - // ENTRIES - int len = in.readInt(); - _data = new long[len]; - for (int i = 0; i < len; i++) { - _data[i] = in.readLong(); - } - } -} // TLongArrayList diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteHashMap.java deleted file mode 100644 index 45e38ab7d0d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for long keys and byte values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TLongByteHashMap extends TLongHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TLongByteProcedure PUT_ALL_PROC = new TLongByteProcedure() { - public boolean execute(long key, byte value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongByteHashMap(TLongHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TLongByteHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongByteHashMap(int initialCapacity, TLongHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TLongByteHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TLongByteHashMap(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TLongByteHashMap m = (TLongByteHashMap) super.clone(); - m._values = (byte[]) this._values.clone(); - return m; - } - - /** - * @return a TLongByteIterator with access to this map's keys and values - */ - public TLongByteIterator iterator() { - return new TLongByteIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new byte[capacity]; - return capacity; - } - - /** - * 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 (long)0 if none was found. - */ - public byte put(long key, byte value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (long)0 if none was found. - */ - public byte putIfAbsent(long key, byte value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private byte doPut(long key, byte value, int index) { - byte previousState; - byte previous = (byte) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TLongByteHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an long value - * @return the value of key or (long)0 if no such mapping exists. - */ - public byte get(long key) { - int index = index(key); - return index < 0 ? (byte) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - long[] keys = _set; - byte[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (long) 0); - Arrays.fill(_values, 0, _values.length, (byte) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an long value - * @return an byte value, or (long)0 if no mapping for key exists - */ - public byte remove(long key) { - byte prev = (byte) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TLongByteHashMap)) { - return false; - } - TLongByteHashMap that = (TLongByteHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TLongByteProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(long key, byte value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TLongByteProcedure { - private final TLongByteHashMap _otherMap; - - EqProcedure(TLongByteHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(long key, byte value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two bytes for equality. - */ - private final boolean eq(byte v1, byte v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (byte) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public byte[] getValues() { - byte[] vals = new byte[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public long[] keys(long[] a) { - int size = size(); - if (a.length < size) { - a = (long[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - long[] k = (long[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - byte[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TByteFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (byte) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public byte adjustOrPutValue(final long key, final byte adjust_amount, final byte put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - long key = in.readLong(); - byte val = in.readByte(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TLongByteProcedure() { - private boolean first = true; - - 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(); - } -} // TLongByteHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteIterator.java deleted file mode 100644 index 6a1c476927b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TLongByteIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TLongByteHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TLongByteIterator(TLongByteHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - byte old = value(); - _map._values[_index] = val; - return old; - } -}// TLongByteIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteProcedure.java deleted file mode 100644 index c7150b1e3f1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongByteProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type long and byte. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TLongByteProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleHashMap.java deleted file mode 100644 index 09384ea4d9c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for long keys and double values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TLongDoubleHashMap extends TLongHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TLongDoubleProcedure PUT_ALL_PROC = new TLongDoubleProcedure() { - public boolean execute(long key, double value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongDoubleHashMap(TLongHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TLongDoubleHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongDoubleHashMap(int initialCapacity, TLongHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TLongDoubleHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TLongDoubleHashMap(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TLongDoubleHashMap m = (TLongDoubleHashMap) super.clone(); - m._values = (double[]) this._values.clone(); - return m; - } - - /** - * @return a TLongDoubleIterator with access to this map's keys and values - */ - public TLongDoubleIterator iterator() { - return new TLongDoubleIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new double[capacity]; - return capacity; - } - - /** - * 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 (long)0 if none was found. - */ - public double put(long key, double value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (long)0 if none was found. - */ - public double putIfAbsent(long key, double value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private double doPut(long key, double value, int index) { - byte previousState; - double previous = (double) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TLongDoubleHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an long value - * @return the value of key or (long)0 if no such mapping exists. - */ - public double get(long key) { - int index = index(key); - return index < 0 ? (double) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - long[] keys = _set; - double[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (long) 0); - Arrays.fill(_values, 0, _values.length, (double) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an long value - * @return an double value, or (long)0 if no mapping for key exists - */ - public double remove(long key) { - double prev = (double) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TLongDoubleHashMap)) { - return false; - } - TLongDoubleHashMap that = (TLongDoubleHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TLongDoubleProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(long key, double value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TLongDoubleProcedure { - private final TLongDoubleHashMap _otherMap; - - EqProcedure(TLongDoubleHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(long key, double value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two doubles for equality. - */ - private final boolean eq(double v1, double v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (double) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public double[] getValues() { - double[] vals = new double[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public long[] keys(long[] a) { - int size = size(); - if (a.length < size) { - a = (long[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - long[] k = (long[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - double[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TDoubleFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (double) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public double adjustOrPutValue(final long key, final double adjust_amount, final double put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - long key = in.readLong(); - double val = in.readDouble(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TLongDoubleProcedure() { - private boolean first = true; - - 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(); - } -} // TLongDoubleHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleIterator.java deleted file mode 100644 index 7a7120d315f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TLongDoubleIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TLongDoubleHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TLongDoubleIterator(TLongDoubleHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - double old = value(); - _map._values[_index] = val; - return old; - } -}// TLongDoubleIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleProcedure.java deleted file mode 100644 index 320a71a1cbc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongDoubleProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type long and double. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TLongDoubleProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatHashMap.java deleted file mode 100644 index 03c408bfb6c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for long keys and float values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TLongFloatHashMap extends TLongHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TLongFloatProcedure PUT_ALL_PROC = new TLongFloatProcedure() { - public boolean execute(long key, float value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongFloatHashMap(TLongHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TLongFloatHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongFloatHashMap(int initialCapacity, TLongHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TLongFloatHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TLongFloatHashMap(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TLongFloatHashMap m = (TLongFloatHashMap) super.clone(); - m._values = (float[]) this._values.clone(); - return m; - } - - /** - * @return a TLongFloatIterator with access to this map's keys and values - */ - public TLongFloatIterator iterator() { - return new TLongFloatIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new float[capacity]; - return capacity; - } - - /** - * 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 (long)0 if none was found. - */ - public float put(long key, float value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (long)0 if none was found. - */ - public float putIfAbsent(long key, float value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private float doPut(long key, float value, int index) { - byte previousState; - float previous = (float) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TLongFloatHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an long value - * @return the value of key or (long)0 if no such mapping exists. - */ - public float get(long key) { - int index = index(key); - return index < 0 ? (float) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - long[] keys = _set; - float[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (long) 0); - Arrays.fill(_values, 0, _values.length, (float) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an long value - * @return an float value, or (long)0 if no mapping for key exists - */ - public float remove(long key) { - float prev = (float) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TLongFloatHashMap)) { - return false; - } - TLongFloatHashMap that = (TLongFloatHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TLongFloatProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(long key, float value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TLongFloatProcedure { - private final TLongFloatHashMap _otherMap; - - EqProcedure(TLongFloatHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(long key, float value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two floats for equality. - */ - private final boolean eq(float v1, float v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (float) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public float[] getValues() { - float[] vals = new float[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public long[] keys(long[] a) { - int size = size(); - if (a.length < size) { - a = (long[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - long[] k = (long[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - float[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TFloatFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (float) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public float adjustOrPutValue(final long key, final float adjust_amount, final float put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - long key = in.readLong(); - float val = in.readFloat(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TLongFloatProcedure() { - private boolean first = true; - - 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(); - } -} // TLongFloatHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatIterator.java deleted file mode 100644 index fecb59c90ff..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TLongFloatIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TLongFloatHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TLongFloatIterator(TLongFloatHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - float old = value(); - _map._values[_index] = val; - return old; - } -}// TLongFloatIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatProcedure.java deleted file mode 100644 index ae720f84f4e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFloatProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type long and float. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TLongFloatProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFunction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFunction.java deleted file mode 100644 index 33582da9e42..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongFunction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for functions that accept and return one long primitive. - *

- * Created: Mon Nov 5 22:19:36 2001 - * - * @author Eric D. Friedman - * @version $Id: PFunction.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TLongFunction { - /** - * Execute this function with value - * - * @param value a long input - * @return a long result - */ - public long execute(long value); -}// TLongFunction diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHash.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHash.java deleted file mode 100644 index 21a4613f3a4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHash.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: PHash.template,v 1.2 2007/06/29 22:39:46 robeden Exp $ - */ - -abstract public class TLongHash extends TPrimitiveHash implements TLongHashingStrategy { - - /** - * the set of longs - */ - protected transient long[] _set; - - /** - * strategy used to hash values in this collection - */ - protected TLongHashingStrategy _hashingStrategy; - - /** - * Creates a new TLongHash instance with the default - * capacity and load factor. - */ - public TLongHash() { - super(); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * Creates a new TLongHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongHash(TLongHashingStrategy strategy) { - super(); - this._hashingStrategy = strategy; - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongHash(int initialCapacity, TLongHashingStrategy strategy) { - super(initialCapacity); - this._hashingStrategy = strategy; - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TLongHash(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { - super(initialCapacity, loadFactor); - this._hashingStrategy = strategy; - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TLongHash h = (TLongHash) super.clone(); - h._set = (long[]) this._set.clone(); - return h; - } - - /** - * 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 = 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 - */ - protected void removeAt(int index) { - _set[index] = (long) 0; - 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 = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - // see Knuth, p. 529 - probe = 1 + (hash % (length - 2)); - - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)); - } - - return states[index] == FREE ? -1 : index; - } - - /** - * 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 insertionIndex(long val) { - int hash, probe, index, length; - - final byte[] states = _states; - final long[] set = _set; - length = states.length; - hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] == FREE) { - return index; // empty, all done - } else if (states[index] == FULL && set[index] == val) { - 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 (states[index] != REMOVED) { - // starting at the natural offset, probe until we find an - // offset that isn't full. - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] == FULL && set[index] != val); - } - - // 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 (states[index] == REMOVED) { - int firstRemoved = index; - while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - index -= probe; - if (index < 0) { - index += length; - } - } - return states[index] == FULL ? -index - 1 : firstRemoved; - } - // if it's full, the key is already stored - return states[index] == FULL ? -index - 1 : index; - } - } - - /** - * Default implementation of TLongHashingStrategy: - * delegates hashing to HashFunctions.hash(long). - * - * @param val the value to hash - * @return the hashcode. - */ - public final int computeHashCode(long val) { - return HashFunctions.hash(val); - } -} // TLongHash diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHashSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHashSet.java deleted file mode 100644 index c7339be6e13..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHashSet.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed set implementation for long primitives. - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TLongHashSet extends TLongHash implements 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 TLongHashSet 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 TLongHashSet(int initialCapacity, float loadFactor) { - super(initialCapacity, loadFactor); - } - - /** - * Creates a new TLongHashSet instance containing the - * elements of array. - * - * @param array an array of long primitives - */ - public TLongHashSet(long[] array) { - this(array.length); - addAll(array); - } - - /** - * Creates a new TLongHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongHashSet(TLongHashingStrategy strategy) { - super(strategy); - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongHashSet(int initialCapacity, TLongHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TLongHashSet(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * Creates a new TLongHashSet instance containing the - * elements of array. - * - * @param array an array of long primitives - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongHashSet(long[] array, TLongHashingStrategy strategy) { - this(array.length, strategy); - addAll(array); - } - - /** - * @return a TLongIterator with access to the values in this set - */ - public TLongIterator iterator() { - return new TLongIterator(this); - } - - /** - * Inserts a value into the set. - * - * @param val an long value - * @return true if the set was modified by the add operation - */ - public boolean add(long val) { - int index = insertionIndex(val); - - if (index < 0) { - return false; // already present in set, nothing to add - } - - byte previousState = _states[index]; - _set[index] = val; - _states[index] = FULL; - postInsertHook(previousState == FREE); - - return true; // yes, we added something - } - - /** - * Expands the set to accommodate new values. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _states[index] = FULL; - } - } - } - - /** - * Returns a new array containing the values in the set. - * - * @return an long[] value - */ - public long[] toArray() { - long[] result = new long[size()]; - 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; - } - - /** - * Empties the set. - */ - public void clear() { - super.clear(); - long[] set = _set; - byte[] states = _states; - - for (int i = set.length; i-- > 0;) { - set[i] = (long) 0; - states[i] = FREE; - } - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TLongHashSet)) { - return false; - } - final TLongHashSet that = (TLongHashSet) other; - if (that.size() != this.size()) { - return false; - } - return forEach(new TLongProcedure() { - public final boolean execute(long value) { - return that.contains(value); - } - }); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEach(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TLongProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(long key) { - h += _hashingStrategy.computeHashCode(key); - return true; - } - } - - /** - * Removes val from the set. - * - * @param val an long value - * @return true if the set was modified by the remove operation. - */ - public boolean remove(long val) { - int index = index(val); - if (index >= 0) { - removeAt(index); - return true; - } - return false; - } - - /** - * Tests the set to determine if all of the elements in - * array are present. - * - * @param array an array of long primitives. - * @return true if all elements were present in the set. - */ - public boolean containsAll(long[] array) { - for (int i = array.length; i-- > 0;) { - if (!contains(array[i])) { - return false; - } - } - return true; - } - - /** - * Adds all of the elements in array to the set. - * - * @param array an array of long primitives. - * @return true if the set was modified by the add all operation. - */ - public boolean addAll(long[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (add(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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. - */ - public boolean removeAll(long[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (remove(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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 - */ - 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)) { - remove(set[i]); - changed = true; - } - } - return changed; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEach(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - - // ENTRIES - setUp(size); - while (size-- > 0) { - long val = in.readLong(); - add(val); - } - } -} // TLongHashSet diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHashingStrategy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHashingStrategy.java deleted file mode 100644 index eaeb09d7b56..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongHashingStrategy.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Serializable; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface to support pluggable hashing strategies in maps and sets. - * Implementors can use this interface to make the trove hashing - * algorithms use an optimal strategy when computing hashcodes. - *

- * Created: Sun Nov 4 08:56:06 2001 - * - * @author Eric D. Friedman - * @version $Id: PHashingStrategy.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TLongHashingStrategy extends Serializable { - /** - * Computes a hash code for the specified long. Implementors - * can use the long's own value or a custom scheme designed to - * minimize collisions for a known set of input. - * - * @param val long for which the hashcode is to be computed - * @return the hashCode - */ - public int computeHashCode(long val); -} // TLongHashingStrategy diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntHashMap.java deleted file mode 100644 index 03e3a0af0e7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for long keys and int values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TLongIntHashMap extends TLongHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TLongIntProcedure PUT_ALL_PROC = new TLongIntProcedure() { - public boolean execute(long key, int value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongIntHashMap(TLongHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TLongIntHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongIntHashMap(int initialCapacity, TLongHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TLongIntHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TLongIntHashMap(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TLongIntHashMap m = (TLongIntHashMap) super.clone(); - m._values = (int[]) this._values.clone(); - return m; - } - - /** - * @return a TLongIntIterator with access to this map's keys and values - */ - public TLongIntIterator iterator() { - return new TLongIntIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new int[capacity]; - return capacity; - } - - /** - * 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 (long)0 if none was found. - */ - public int put(long key, int value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (long)0 if none was found. - */ - public int putIfAbsent(long key, int value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private int doPut(long key, int value, int index) { - byte previousState; - int previous = (int) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TLongIntHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an long value - * @return the value of key or (long)0 if no such mapping exists. - */ - public int get(long key) { - int index = index(key); - return index < 0 ? (int) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - long[] keys = _set; - int[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (long) 0); - Arrays.fill(_values, 0, _values.length, (int) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an long value - * @return an int value, or (long)0 if no mapping for key exists - */ - public int remove(long key) { - int prev = (int) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TLongIntHashMap)) { - return false; - } - TLongIntHashMap that = (TLongIntHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TLongIntProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(long key, int value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TLongIntProcedure { - private final TLongIntHashMap _otherMap; - - EqProcedure(TLongIntHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(long key, int value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two ints for equality. - */ - private final boolean eq(int v1, int v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (int) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public int[] getValues() { - int[] vals = new int[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public long[] keys(long[] a) { - int size = size(); - if (a.length < size) { - a = (long[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - long[] k = (long[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - int[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TIntFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (int) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public int adjustOrPutValue(final long key, final int adjust_amount, final int put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - long key = in.readLong(); - int val = in.readInt(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TLongIntProcedure() { - private boolean first = true; - - 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(); - } -} // TLongIntHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntIterator.java deleted file mode 100644 index 765a3bfe8be..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TLongIntIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TLongIntHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TLongIntIterator(TLongIntHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - int old = value(); - _map._values[_index] = val; - return old; - } -}// TLongIntIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntProcedure.java deleted file mode 100644 index 2973913997b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIntProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type long and int. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TLongIntProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIterator.java deleted file mode 100644 index d0c75891d5a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongIterator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Iterator for long collections. - * - * @author Eric D. Friedman - * @version $Id: PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TLongIterator extends TPrimitiveIterator { - /** - * the collection on which the iterator operates - */ - private final TLongHash _hash; - - /** - * Creates a TLongIterator for the elements in the specified collection. - */ - public TLongIterator(TLongHash hash) { - super(hash); - this._hash = hash; - } - - /** - * Advances the iterator to the next element in the underlying collection - * and returns it. - * - * @return the next long in the collection - * @throws NoSuchElementException if the iterator is already exhausted - */ - public long next() { - moveToNextIndex(); - return _hash._set[_index]; - } -}// TLongIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongHashMap.java deleted file mode 100644 index 9b99a72faf9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for long keys and long values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TLongLongHashMap extends TLongHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TLongLongProcedure PUT_ALL_PROC = new TLongLongProcedure() { - public boolean execute(long key, long value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongLongHashMap(TLongHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TLongLongHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongLongHashMap(int initialCapacity, TLongHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TLongLongHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TLongLongHashMap(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TLongLongHashMap m = (TLongLongHashMap) super.clone(); - m._values = (long[]) this._values.clone(); - return m; - } - - /** - * @return a TLongLongIterator with access to this map's keys and values - */ - public TLongLongIterator iterator() { - return new TLongLongIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new long[capacity]; - return capacity; - } - - /** - * 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 (long)0 if none was found. - */ - public long put(long key, long value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (long)0 if none was found. - */ - public long putIfAbsent(long key, long value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private long doPut(long key, long value, int index) { - byte previousState; - long previous = (long) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TLongLongHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an long value - * @return the value of key or (long)0 if no such mapping exists. - */ - public long get(long key) { - int index = index(key); - return index < 0 ? (long) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - long[] keys = _set; - long[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (long) 0); - Arrays.fill(_values, 0, _values.length, (long) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an long value - * @return an long value, or (long)0 if no mapping for key exists - */ - public long remove(long key) { - long prev = (long) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TLongLongHashMap)) { - return false; - } - TLongLongHashMap that = (TLongLongHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TLongLongProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(long key, long value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TLongLongProcedure { - private final TLongLongHashMap _otherMap; - - EqProcedure(TLongLongHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(long key, long value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two longs for equality. - */ - private final boolean eq(long v1, long v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (long) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public long[] getValues() { - long[] vals = new long[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public long[] keys(long[] a) { - int size = size(); - if (a.length < size) { - a = (long[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - long[] k = (long[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - long[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TLongFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (long) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public long adjustOrPutValue(final long key, final long adjust_amount, final long put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - long key = in.readLong(); - long val = in.readLong(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TLongLongProcedure() { - private boolean first = true; - - 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(); - } -} // TLongLongHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongIterator.java deleted file mode 100644 index 5ba2424f2c5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TLongLongIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TLongLongHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TLongLongIterator(TLongLongHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - long old = value(); - _map._values[_index] = val; - return old; - } -}// TLongLongIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongProcedure.java deleted file mode 100644 index 42bf8718c51..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongLongProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type long and long. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TLongLongProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectHashMap.java deleted file mode 100644 index 57515e9d8a9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectHashMap.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TLongObjectHashMap extends TLongHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TLongObjectProcedure PUT_ALL_PROC = new TLongObjectProcedure() { - public boolean execute(long key, V value) { - put(key, value); - return true; - } - }; - - - /** - * the values of the map - */ - protected transient V[] _values; - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TLongObjectHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongObjectHashMap(TLongHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TLongObjectHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongObjectHashMap(int initialCapacity, TLongHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TLongObjectHashMap(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public TLongObjectHashMap clone() { - TLongObjectHashMap m = (TLongObjectHashMap) super.clone(); - m._values = (V[]) this._values.clone(); - return m; - } - - /** - * @return a TLongObjectIterator with access to this map's keys and values - */ - public TLongObjectIterator iterator() { - return new TLongObjectIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = (V[]) new Object[capacity]; - return capacity; - } - - /** - * 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 {@code null} if none was found. - */ - public V put(long key, V value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 Object value - * @return the previous value associated with key, - * or {@code null} if none was found. - */ - public V putIfAbsent(long key, V value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private V doPut(long key, V value, int index) { - byte previousState; - V previous = null; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TLongObjectHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an long value - * @return the value of key or (long)0 if no such mapping exists. - */ - public V get(long key) { - int index = index(key); - return index < 0 ? null : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - long[] keys = _set; - Object[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (long) 0); - Arrays.fill(_values, 0, _values.length, null); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an long value - * @return an Object value or (long)0 if no such mapping exists. - */ - 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; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TLongObjectHashMap)) { - return false; - } - TLongObjectHashMap that = (TLongObjectHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TLongObjectProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(long key, Object value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TLongObjectProcedure { - private final TLongObjectHashMap _otherMap; - - EqProcedure(TLongObjectHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(long key, Object value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two objects for equality. - */ - private final boolean eq(Object o1, Object o2) { - return o1 == o2 || ((o1 != null) && o1.equals(o2)); - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = null; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - * @see #getValues(Object[]) - */ - public Object[] getValues() { - 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; - } - - /** - * Return the values of the map; the runtime type of the returned array is that of - * the specified array. - * - * @param a the array into which the elements of this collection are to be - * stored, if it is big enough; otherwise, a new array of the same - * runtime type is allocated for this purpose. - * @return an array containing the elements of this collection - * @throws ArrayStoreException the runtime type of the specified array is - * not a supertype of the runtime type of every element in this - * collection. - * @throws NullPointerException if the specified array is null. - * @see #getValues() - */ - public T[] getValues(T[] a) { - if (a.length < _size) { - a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), - _size); - } - - V[] v = _values; - byte[] states = _states; - - for (int i = v.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = (T) v[i]; - } - } - return a; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public long[] keys(long[] a) { - int size = size(); - if (a.length < size) { - a = (long[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - long[] k = (long[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(V 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 && - val == 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; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * Executes procedure for each key/value entry in the - * map. - * - * @param procedure a TOLongObjectProcedure value - * @return false if the loop over the entries terminated because - * the procedure returned false for some entry. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TObjectFunction value - */ - 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]); - } - } - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // 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); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TLongObjectProcedure() { - private boolean first = true; - - 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectIterator.java deleted file mode 100644 index 049a8cbc74f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: P2OIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TLongObjectIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TLongObjectHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TLongObjectIterator(TLongObjectHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - V old = value(); - _map._values[_index] = val; - return old; - } -}// TLongObjectIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectProcedure.java deleted file mode 100644 index 7385736f0d1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongObjectProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type long and Object. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2OProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TLongObjectProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongProcedure.java deleted file mode 100644 index 30c293c5a89..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongProcedure.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures with one long parameter. - *

- * Created: Mon Nov 5 21:45:49 2001 - * - * @author Eric D. Friedman - * @version $Id: PProcedure.template,v 1.2 2007/11/01 16:08:14 robeden Exp $ - */ - -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); -}// TLongProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortHashMap.java deleted file mode 100644 index 160f06b293d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for long keys and short values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TLongShortHashMap extends TLongHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TLongShortProcedure PUT_ALL_PROC = new TLongShortProcedure() { - public boolean execute(long key, short value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongShortHashMap(TLongHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TLongShortHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TLongShortHashMap(int initialCapacity, TLongHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TLongShortHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TLongShortHashMap(int initialCapacity, float loadFactor, TLongHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TLongShortHashMap m = (TLongShortHashMap) super.clone(); - m._values = (short[]) this._values.clone(); - return m; - } - - /** - * @return a TLongShortIterator with access to this map's keys and values - */ - public TLongShortIterator iterator() { - return new TLongShortIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new short[capacity]; - return capacity; - } - - /** - * 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 (long)0 if none was found. - */ - public short put(long key, short value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (long)0 if none was found. - */ - public short putIfAbsent(long key, short value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private short doPut(long key, short value, int index) { - byte previousState; - short previous = (short) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TLongShortHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an long value - * @return the value of key or (long)0 if no such mapping exists. - */ - public short get(long key) { - int index = index(key); - return index < 0 ? (short) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - long[] keys = _set; - short[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (long) 0); - Arrays.fill(_values, 0, _values.length, (short) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an long value - * @return an short value, or (long)0 if no mapping for key exists - */ - public short remove(long key) { - short prev = (short) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TLongShortHashMap)) { - return false; - } - TLongShortHashMap that = (TLongShortHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TLongShortProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(long key, short value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TLongShortProcedure { - private final TLongShortHashMap _otherMap; - - EqProcedure(TLongShortHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(long key, short value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two shorts for equality. - */ - private final boolean eq(short v1, short v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (short) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public short[] getValues() { - short[] vals = new short[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public long[] keys(long[] a) { - int size = size(); - if (a.length < size) { - a = (long[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - long[] k = (long[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - short[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TShortFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (short) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public short adjustOrPutValue(final long key, final short adjust_amount, final short put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - long key = in.readLong(); - short val = in.readShort(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TLongShortProcedure() { - private boolean first = true; - - 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(); - } -} // TLongShortHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortIterator.java deleted file mode 100644 index ddd43e799a0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TLongShortIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TLongShortHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TLongShortIterator(TLongShortHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - short old = value(); - _map._values[_index] = val; - return old; - } -}// TLongShortIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortProcedure.java deleted file mode 100644 index 75e0c74f2e2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongShortProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type long and short. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TLongShortProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongStack.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongStack.java deleted file mode 100644 index 0f87182d39c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TLongStack.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -/** - * A stack of long primitives, backed by a TLongArrayList. - * - * @author Eric D. Friedman, Rob Eden - * @version $Id: PStack.template,v 1.2 2007/02/28 23:03:57 robeden Exp $ - */ - -public class TLongStack { - - /** - * the list used to hold the stack values. - */ - protected TLongArrayList _list; - - public static final int DEFAULT_CAPACITY = TLongArrayList.DEFAULT_CAPACITY; - - /** - * Creates a new TLongStack instance with the default - * capacity. - */ - public TLongStack() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TLongStack instance with the - * specified capacity. - * - * @param capacity the initial depth of the stack - */ - public TLongStack(int capacity) { - _list = new TLongArrayList(capacity); - } - - /** - * Pushes the value onto the top of the stack. - * - * @param val an long value - */ - public void push(long val) { - _list.add(val); - } - - /** - * Removes and returns the value at the top of the stack. - * - * @return an long value - */ - public long pop() { - return _list.remove(_list.size() - 1); - } - - /** - * Returns the value at the top of the stack. - * - * @return an long value - */ - public long peek() { - return _list.get(_list.size() - 1); - } - - /** - * Returns the current depth of the stack. - */ - public int size() { - return _list.size(); - } - - /** - * Clears the stack, reseting its capacity to the default. - */ - public void clear() { - _list.clear(DEFAULT_CAPACITY); - } - - /** - * Clears the stack without releasing its internal capacity allocation. - */ - public void reset() { - _list.reset(); - } - - /** - * 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[] toNativeArray() { - return _list.toNativeArray(); - } - - /** - * 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 toNativeArray(long[] dest) { - _list.toNativeArray(dest, 0, size()); - } -} // TLongStack diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteHashMap.java deleted file mode 100644 index 96afa8858d9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteHashMap.java +++ /dev/null @@ -1,631 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TObjectByteHashMap extends TObjectHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TObjectByteProcedure PUT_ALL_PROC = new TObjectByteProcedure() { - public boolean execute(K key, byte value) { - put(key, value); - return true; - } - }; - - /** - * the values of the map - */ - protected transient byte[] _values; - - /** - * Creates a new TObjectByteHashMap instance with the default - * capacity and load factor. - */ - public TObjectByteHashMap() { - super(); - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TObjectByteHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectByteHashMap(TObjectHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TObjectByteHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectByteHashMap(int initialCapacity, TObjectHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TObjectByteHashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return an iterator over the entries in this map - */ - public TObjectByteIterator iterator() { - return new TObjectByteIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new byte[capacity]; - return capacity; - } - - /** - * 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 (byte)0 if none was found. - */ - public byte put(K key, byte value) { - int index = insertionIndex(key); - return doPut(key, 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 byte value - * @return the previous value associated with key, - * or (byte)0 if none was found. - */ - public byte putIfAbsent(K key, byte value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private byte doPut(K key, byte value, int index) { - byte previous = (byte) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - K oldKey = (K) _set[index]; - _set[index] = key; - _values[index] = value; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - return previous; - } - - - /** - * 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(TObjectByteHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - protected void rehash(int newCapacity) { - int oldCapacity = _set.length; - K oldKeys[] = (K[]) _set; - byte oldVals[] = _values; - - _set = new Object[newCapacity]; - Arrays.fill(_set, FREE); - _values = new byte[newCapacity]; - - for (int i = oldCapacity; i-- > 0;) { - if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { - K o = oldKeys[i]; - int index = insertionIndex(o); - if (index < 0) { - throwObjectContractViolation(_set[(-index - 1)], o); - } - _set[index] = o; - _values[index] = oldVals[i]; - } - } - } - - /** - * retrieves the value for key - * - * @param key an Object value - * @return the value of key or (byte)0 if no such mapping exists. - */ - public byte get(K key) { - int index = index(key); - return index < 0 ? (byte) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - Object[] keys = _set; - byte[] vals = _values; - - Arrays.fill(_set, 0, _set.length, FREE); - Arrays.fill(_values, 0, _values.length, (byte) 0); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return an byte value or (byte)0 if no such mapping exists. - */ - public byte remove(K key) { - byte prev = (byte) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TObjectByteHashMap)) { - return false; - } - TObjectByteHashMap that = (TObjectByteHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - /** - * {@inheritDoc} - */ - @Override - public TObjectByteHashMap clone() { - TObjectByteHashMap clone = (TObjectByteHashMap) super.clone(); - clone._values = new byte[_values.length]; - System.arraycopy(_values, 0, clone._values, 0, clone._values.length); - - return clone; - } - - - private static final class EqProcedure implements TObjectByteProcedure { - private final TObjectByteHashMap _otherMap; - - EqProcedure(TObjectByteHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(Object key, byte value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two bytes for equality. - */ - private final boolean eq(byte v1, byte v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public byte[] getValues() { - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - public Object[] keys() { - Object[] keys = new Object[size()]; - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - keys[j++] = k[i]; - } - } - return keys; - } - - /** - * returns the keys of the map. - * - * @param a 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 runtime type is allocated for this purpose. - * @return a Set value - */ - public K[] keys(K[] a) { - int size = size(); - if (a.length < size) { - a = (K[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - 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; - } - - - /** - * checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(K key) { - return contains(key); - } - - /** - * 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) { - 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. - */ - 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. - */ - public boolean forEachEntry(TObjectByteProcedure procedure) { - K[] keys = (K[]) _set; - byte[] values = _values; - for (int i = keys.length; i-- > 0;) { - if (keys[i] != FREE - && keys[i] != REMOVED - && !procedure.execute(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. - */ - public boolean retainEntries(TObjectByteProcedure procedure) { - boolean modified = false; - 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 - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (byte) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public byte adjustOrPutValue(final K key, final byte adjust_amount, final byte put_amount) { - int index = insertionIndex(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; - } - - K oldKey = (K) _set[index]; - _set[index] = key; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - K key = (K) in.readObject(); - byte val = in.readByte(); - put(key, val); - } - } - - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TObjectByteProcedure() { - private boolean first = true; - - public boolean execute(K 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(); - } -} // TObjectByteHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteIterator.java deleted file mode 100644 index a6b152c5edf..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteIterator.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.util.ConcurrentModificationException; - -////////////////////////////////////////////////// -// 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 - * @version $Id: O2PIterator.template,v 1.3 2007/01/22 16:56:39 robeden Exp $ - */ - -public class TObjectByteIterator extends TIterator { - private final TObjectByteHashMap _map; - - public TObjectByteIterator(TObjectByteHashMap map) { - super(map); - this._map = map; - } - - /** - * Returns the index of the next value in the data structure - * or a negative value if the iterator is exhausted. - * - * @return an byte value - */ - protected final int nextIndex() { - if (_expectedSize != _hash.size()) { - throw new ConcurrentModificationException(); - } - - Object[] set = _map._set; - int i = _index; - while (i-- > 0 && (set[i] == null || set[i] == TObjectHash.REMOVED || - set[i] == TObjectHash.FREE)) ; - return i; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return (K) _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - byte old = value(); - _map._values[_index] = val; - return old; - } -}// TObjectByteIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteProcedure.java deleted file mode 100644 index a269dbf364e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectByteProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type Object and byte. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: O2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TObjectByteProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleHashMap.java deleted file mode 100644 index 51ad45d238b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleHashMap.java +++ /dev/null @@ -1,631 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TObjectDoubleHashMap extends TObjectHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TObjectDoubleProcedure PUT_ALL_PROC = new TObjectDoubleProcedure() { - public boolean execute(K key, double value) { - put(key, value); - return true; - } - }; - - /** - * the values of the map - */ - protected transient double[] _values; - - /** - * Creates a new TObjectDoubleHashMap instance with the default - * capacity and load factor. - */ - public TObjectDoubleHashMap() { - super(); - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TObjectDoubleHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectDoubleHashMap(TObjectHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TObjectDoubleHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectDoubleHashMap(int initialCapacity, TObjectHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TObjectDoubleHashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return an iterator over the entries in this map - */ - public TObjectDoubleIterator iterator() { - return new TObjectDoubleIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new double[capacity]; - return capacity; - } - - /** - * 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 (double)0 if none was found. - */ - public double put(K key, double value) { - int index = insertionIndex(key); - return doPut(key, 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 double value - * @return the previous value associated with key, - * or (double)0 if none was found. - */ - public double putIfAbsent(K key, double value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private double doPut(K key, double value, int index) { - double previous = (double) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - K oldKey = (K) _set[index]; - _set[index] = key; - _values[index] = value; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - return previous; - } - - - /** - * 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(TObjectDoubleHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - protected void rehash(int newCapacity) { - int oldCapacity = _set.length; - K oldKeys[] = (K[]) _set; - double oldVals[] = _values; - - _set = new Object[newCapacity]; - Arrays.fill(_set, FREE); - _values = new double[newCapacity]; - - for (int i = oldCapacity; i-- > 0;) { - if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { - K o = oldKeys[i]; - int index = insertionIndex(o); - if (index < 0) { - throwObjectContractViolation(_set[(-index - 1)], o); - } - _set[index] = o; - _values[index] = oldVals[i]; - } - } - } - - /** - * retrieves the value for key - * - * @param key an Object value - * @return the value of key or (double)0 if no such mapping exists. - */ - public double get(K key) { - int index = index(key); - return index < 0 ? (double) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - Object[] keys = _set; - double[] vals = _values; - - Arrays.fill(_set, 0, _set.length, FREE); - Arrays.fill(_values, 0, _values.length, (double) 0); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return an double value or (double)0 if no such mapping exists. - */ - public double remove(K key) { - double prev = (double) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TObjectDoubleHashMap)) { - return false; - } - TObjectDoubleHashMap that = (TObjectDoubleHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - /** - * {@inheritDoc} - */ - @Override - public TObjectDoubleHashMap clone() { - TObjectDoubleHashMap clone = (TObjectDoubleHashMap) super.clone(); - clone._values = new double[_values.length]; - System.arraycopy(_values, 0, clone._values, 0, clone._values.length); - - return clone; - } - - - private static final class EqProcedure implements TObjectDoubleProcedure { - private final TObjectDoubleHashMap _otherMap; - - EqProcedure(TObjectDoubleHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(Object key, double value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two doubles for equality. - */ - private final boolean eq(double v1, double v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public double[] getValues() { - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - public Object[] keys() { - Object[] keys = new Object[size()]; - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - keys[j++] = k[i]; - } - } - return keys; - } - - /** - * returns the keys of the map. - * - * @param a 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 runtime type is allocated for this purpose. - * @return a Set value - */ - public K[] keys(K[] a) { - int size = size(); - if (a.length < size) { - a = (K[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - 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; - } - - - /** - * checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(K key) { - return contains(key); - } - - /** - * 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) { - 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. - */ - 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. - */ - public boolean forEachEntry(TObjectDoubleProcedure procedure) { - K[] keys = (K[]) _set; - double[] values = _values; - for (int i = keys.length; i-- > 0;) { - if (keys[i] != FREE - && keys[i] != REMOVED - && !procedure.execute(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. - */ - public boolean retainEntries(TObjectDoubleProcedure procedure) { - boolean modified = false; - 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 - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (double) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public double adjustOrPutValue(final K key, final double adjust_amount, final double put_amount) { - int index = insertionIndex(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; - } - - K oldKey = (K) _set[index]; - _set[index] = key; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - K key = (K) in.readObject(); - double val = in.readDouble(); - put(key, val); - } - } - - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TObjectDoubleProcedure() { - private boolean first = true; - - public boolean execute(K 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(); - } -} // TObjectDoubleHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleIterator.java deleted file mode 100644 index e8dc0ec98a0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleIterator.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.util.ConcurrentModificationException; - -////////////////////////////////////////////////// -// 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 - * @version $Id: O2PIterator.template,v 1.3 2007/01/22 16:56:39 robeden Exp $ - */ - -public class TObjectDoubleIterator extends TIterator { - private final TObjectDoubleHashMap _map; - - public TObjectDoubleIterator(TObjectDoubleHashMap map) { - super(map); - this._map = map; - } - - /** - * Returns the index of the next value in the data structure - * or a negative value if the iterator is exhausted. - * - * @return an double value - */ - protected final int nextIndex() { - if (_expectedSize != _hash.size()) { - throw new ConcurrentModificationException(); - } - - Object[] set = _map._set; - int i = _index; - while (i-- > 0 && (set[i] == null || set[i] == TObjectHash.REMOVED || - set[i] == TObjectHash.FREE)) ; - return i; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return (K) _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - double old = value(); - _map._values[_index] = val; - return old; - } -}// TObjectDoubleIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleProcedure.java deleted file mode 100644 index a7c416e02cc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectDoubleProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type Object and double. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: O2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TObjectDoubleProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatHashMap.java deleted file mode 100644 index 3037f3bf383..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatHashMap.java +++ /dev/null @@ -1,631 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TObjectFloatHashMap extends TObjectHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TObjectFloatProcedure PUT_ALL_PROC = new TObjectFloatProcedure() { - public boolean execute(K key, float value) { - put(key, value); - return true; - } - }; - - /** - * the values of the map - */ - protected transient float[] _values; - - /** - * Creates a new TObjectFloatHashMap instance with the default - * capacity and load factor. - */ - public TObjectFloatHashMap() { - super(); - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TObjectFloatHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectFloatHashMap(TObjectHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TObjectFloatHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectFloatHashMap(int initialCapacity, TObjectHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TObjectFloatHashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return an iterator over the entries in this map - */ - public TObjectFloatIterator iterator() { - return new TObjectFloatIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new float[capacity]; - return capacity; - } - - /** - * 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 (float)0 if none was found. - */ - public float put(K key, float value) { - int index = insertionIndex(key); - return doPut(key, 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 float value - * @return the previous value associated with key, - * or (float)0 if none was found. - */ - public float putIfAbsent(K key, float value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private float doPut(K key, float value, int index) { - float previous = (float) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - K oldKey = (K) _set[index]; - _set[index] = key; - _values[index] = value; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - return previous; - } - - - /** - * 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(TObjectFloatHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - protected void rehash(int newCapacity) { - int oldCapacity = _set.length; - K oldKeys[] = (K[]) _set; - float oldVals[] = _values; - - _set = new Object[newCapacity]; - Arrays.fill(_set, FREE); - _values = new float[newCapacity]; - - for (int i = oldCapacity; i-- > 0;) { - if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { - K o = oldKeys[i]; - int index = insertionIndex(o); - if (index < 0) { - throwObjectContractViolation(_set[(-index - 1)], o); - } - _set[index] = o; - _values[index] = oldVals[i]; - } - } - } - - /** - * retrieves the value for key - * - * @param key an Object value - * @return the value of key or (float)0 if no such mapping exists. - */ - public float get(K key) { - int index = index(key); - return index < 0 ? (float) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - Object[] keys = _set; - float[] vals = _values; - - Arrays.fill(_set, 0, _set.length, FREE); - Arrays.fill(_values, 0, _values.length, (float) 0); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return an float value or (float)0 if no such mapping exists. - */ - public float remove(K key) { - float prev = (float) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TObjectFloatHashMap)) { - return false; - } - TObjectFloatHashMap that = (TObjectFloatHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - /** - * {@inheritDoc} - */ - @Override - public TObjectFloatHashMap clone() { - TObjectFloatHashMap clone = (TObjectFloatHashMap) super.clone(); - clone._values = new float[_values.length]; - System.arraycopy(_values, 0, clone._values, 0, clone._values.length); - - return clone; - } - - - private static final class EqProcedure implements TObjectFloatProcedure { - private final TObjectFloatHashMap _otherMap; - - EqProcedure(TObjectFloatHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(Object key, float value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two floats for equality. - */ - private final boolean eq(float v1, float v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public float[] getValues() { - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - public Object[] keys() { - Object[] keys = new Object[size()]; - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - keys[j++] = k[i]; - } - } - return keys; - } - - /** - * returns the keys of the map. - * - * @param a 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 runtime type is allocated for this purpose. - * @return a Set value - */ - public K[] keys(K[] a) { - int size = size(); - if (a.length < size) { - a = (K[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - 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; - } - - - /** - * checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(K key) { - return contains(key); - } - - /** - * 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) { - 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. - */ - 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. - */ - public boolean forEachEntry(TObjectFloatProcedure procedure) { - K[] keys = (K[]) _set; - float[] values = _values; - for (int i = keys.length; i-- > 0;) { - if (keys[i] != FREE - && keys[i] != REMOVED - && !procedure.execute(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. - */ - public boolean retainEntries(TObjectFloatProcedure procedure) { - boolean modified = false; - 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 - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (float) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public float adjustOrPutValue(final K key, final float adjust_amount, final float put_amount) { - int index = insertionIndex(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; - } - - K oldKey = (K) _set[index]; - _set[index] = key; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - K key = (K) in.readObject(); - float val = in.readFloat(); - put(key, val); - } - } - - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TObjectFloatProcedure() { - private boolean first = true; - - public boolean execute(K 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(); - } -} // TObjectFloatHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatIterator.java deleted file mode 100644 index da1e73c299e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatIterator.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.util.ConcurrentModificationException; - -////////////////////////////////////////////////// -// 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 - * @version $Id: O2PIterator.template,v 1.3 2007/01/22 16:56:39 robeden Exp $ - */ - -public class TObjectFloatIterator extends TIterator { - private final TObjectFloatHashMap _map; - - public TObjectFloatIterator(TObjectFloatHashMap map) { - super(map); - this._map = map; - } - - /** - * Returns the index of the next value in the data structure - * or a negative value if the iterator is exhausted. - * - * @return an float value - */ - protected final int nextIndex() { - if (_expectedSize != _hash.size()) { - throw new ConcurrentModificationException(); - } - - Object[] set = _map._set; - int i = _index; - while (i-- > 0 && (set[i] == null || set[i] == TObjectHash.REMOVED || - set[i] == TObjectHash.FREE)) ; - return i; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return (K) _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - float old = value(); - _map._values[_index] = val; - return old; - } -}// TObjectFloatIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatProcedure.java deleted file mode 100644 index b657b9d94a7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFloatProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type Object and float. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: O2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TObjectFloatProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFunction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFunction.java deleted file mode 100644 index 3e4731565d9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectFunction.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -/** - * 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.3 2006/11/10 23:27:56 robeden 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHash.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHash.java deleted file mode 100644 index d33d399a337..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHash.java +++ /dev/null @@ -1,378 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -/** - * An open addressed hashing implementation for Object types. - *

- * Created: Sun Nov 4 08:56:06 2001 - * - * @author Eric D. Friedman - * @version $Id: TObjectHash.java,v 1.27 2009/06/01 22:14:44 robeden Exp $ - */ -abstract public class TObjectHash extends THash - implements TObjectHashingStrategy { - - static final long serialVersionUID = -3461112548087185871L; - - - /** - * the set of Objects - */ - protected transient Object[] _set; - - /** - * the strategy used to hash objects in this collection. - */ - protected TObjectHashingStrategy _hashingStrategy; - - protected static final Object REMOVED = new Object(), FREE = new Object(); - - /** - * Creates a new TObjectHash instance with the - * default capacity and load factor. - */ - public TObjectHash() { - super(); - this._hashingStrategy = this; - } - - /** - * Creates a new TObjectHash instance with the - * default capacity and load factor and a custom hashing strategy. - * - * @param strategy used to compute hash codes and to compare objects. - */ - public TObjectHash(TObjectHashingStrategy strategy) { - super(); - this._hashingStrategy = strategy; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * Creates a new TObjectHash instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. Uses the specified custom - * hashing strategy. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare objects. - */ - public TObjectHash(int initialCapacity, TObjectHashingStrategy strategy) { - super(initialCapacity); - this._hashingStrategy = strategy; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * Creates a new TObjectHash instance with a prime - * value at or near the specified capacity and load factor. Uses - * the specified custom hashing strategy. - * - * @param initialCapacity used to find a prime capacity for the table. - * @param loadFactor used to calculate the threshold over which - * rehashing takes place. - * @param strategy used to compute hash codes and to compare objects. - */ - public TObjectHash(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { - super(initialCapacity, loadFactor); - this._hashingStrategy = strategy; - } - - /** - * @return a shallow clone of this collection - */ - public TObjectHash clone() { - TObjectHash h = (TObjectHash) super.clone(); - h._set = (Object[]) this._set.clone(); - return h; - } - - protected int capacity() { - return _set.length; - } - - 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 - */ - protected 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. - */ - 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 - */ - public boolean contains(Object obj) { - return index((T) 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(T obj) { - final TObjectHashingStrategy hashing_strategy = _hashingStrategy; - - final Object[] set = _set; - final int length = set.length; - final int hash = hashing_strategy.computeHashCode(obj) & 0x7fffffff; - int index = hash % length; - Object cur = set[index]; - - if (cur == FREE) return -1; - - // NOTE: here it has to be REMOVED or FULL (some user-given value) - if (cur == REMOVED || !hashing_strategy.equals((T) cur, obj)) { - // see Knuth, p. 529 - final int probe = 1 + (hash % (length - 2)); - - do { - index -= probe; - if (index < 0) { - index += length; - } - cur = set[index]; - } while (cur != FREE - && (cur == REMOVED || !_hashingStrategy.equals((T) cur, obj))); - } - - return cur == FREE ? -1 : index; - } - - /** - * Locates the index at which obj can be inserted. if - * there is already a value equal()ing obj in the set, - * returns that value's index as -index - 1. - * - * @param obj an Object value - * @return the index of a FREE slot at which obj can be inserted - * or, if obj is already stored in the hash, the negative value of - * that index, minus 1: -index -1. - */ - protected int insertionIndex(T obj) { - final TObjectHashingStrategy hashing_strategy = _hashingStrategy; - - final Object[] set = _set; - final int length = set.length; - final int hash = hashing_strategy.computeHashCode(obj) & 0x7fffffff; - int index = hash % length; - Object cur = set[index]; - - if (cur == FREE) { - return index; // empty, all done - } else if (cur != REMOVED && hashing_strategy.equals((T) cur, obj)) { - return -index - 1; // already stored - } else { // already FULL or REMOVED, must probe - // compute the double hash - final int 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 (cur != REMOVED) { - // starting at the natural offset, probe until we find an - // offset that isn't full. - do { - index -= probe; - if (index < 0) { - index += length; - } - cur = set[index]; - } while (cur != FREE - && cur != REMOVED - && !hashing_strategy.equals((T) cur, obj)); - } - - // 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 (cur == REMOVED) { - int firstRemoved = index; - while (cur != FREE - && (cur == REMOVED || !hashing_strategy.equals((T) cur, obj))) { - index -= probe; - if (index < 0) { - index += length; - } - cur = set[index]; - } - // NOTE: cur cannot == REMOVED in this block - return (cur != FREE) ? -index - 1 : firstRemoved; - } - // if it's full, the key is already stored - // NOTE: cur cannot equal REMOVE here (would have retuned already (see above) - return (cur != FREE) ? -index - 1 : index; - } - } - - /** - * This is the default implementation of TObjectHashingStrategy: - * it delegates hashing to the Object's hashCode method. - * - * @param o for which the hashcode is to be computed - * @return the hashCode - * @see Object#hashCode() - */ - public final int computeHashCode(T o) { - return o == null ? 0 : o.hashCode(); - } - - /** - * This is the default implementation of TObjectHashingStrategy: - * it delegates equality comparisons to the first parameter's - * equals() method. - * - * @param o1 an Object value - * @param o2 an Object value - * @return true if the objects are equal - * @see Object#equals(Object) - */ - public final boolean equals(T o1, T o2) { - return o1 == null ? o2 == null : o1.equals(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. - * @throws IllegalArgumentException the whole point of this method. - */ - protected final void throwObjectContractViolation(Object o1, Object o2) - throws IllegalArgumentException { - throw 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 =" + o1 - + "; object #2 =" + o2); - } - - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - super.writeExternal(out); - - // VERSION - out.writeByte(0); - - // HASHING STRATEGY - if (_hashingStrategy == this) out.writeObject(null); - else out.writeObject(_hashingStrategy); - } - - @Override - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - super.readExternal(in); - - // VERSION - in.readByte(); - - // HASHING STRATEGY - //noinspection unchecked - _hashingStrategy = (TObjectHashingStrategy) in.readObject(); - if (_hashingStrategy == null) _hashingStrategy = this; - } -} // TObjectHash diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHashIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHashIterator.java deleted file mode 100644 index 5f3296ae950..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHashIterator.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -/** - * Created: Wed Nov 28 21:30:53 2001 - * - * @author Eric D. Friedman - * @version $Id: TObjectHashIterator.java,v 1.2 2006/11/10 23:27:56 robeden Exp $ - */ - -class TObjectHashIterator extends THashIterator { - protected final TObjectHash _objectHash; - - public TObjectHashIterator(TObjectHash hash) { - super(hash); - _objectHash = hash; - } - - protected E objectAtIndex(int index) { - return (E) _objectHash._set[index]; - } - -} // TObjectHashIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHashingStrategy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHashingStrategy.java deleted file mode 100644 index b74c9c8fdde..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectHashingStrategy.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -import java.io.Serializable; - -/** - * Interface to support pluggable hashing strategies in maps and sets. - * Implementors 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. - *

- * Created: Sat Aug 17 10:52:32 2002 - * - * @author Eric Friedman - * @version $Id: TObjectHashingStrategy.java,v 1.3 2007/06/11 15:26:44 robeden Exp $ - */ - -public interface TObjectHashingStrategy extends Serializable { - - /** - * Computes a hash code for the specified object. Implementors - * 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 implementors 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); -} // TObjectHashingStrategy diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIdentityHashingStrategy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIdentityHashingStrategy.java deleted file mode 100644 index f330ebde36c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIdentityHashingStrategy.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -/** - * This object hashing strategy uses the System.identityHashCode - * method to provide identity hash codes. These are identical to the - * value produced by Object.hashCode(), even when the type of the - * object being hashed overrides that method. - *

- * Created: Sat Aug 17 11:13:15 2002 - * - * @author Eric Friedman - * @version $Id: TObjectIdentityHashingStrategy.java,v 1.4 2007/06/11 15:26:44 robeden Exp $ - */ - -public final class TObjectIdentityHashingStrategy implements TObjectHashingStrategy { - /** - * Delegates hash code computation to the System.identityHashCode(Object) method. - * - * @param object for which the hashcode is to be computed - * @return the hashCode - */ - public final int computeHashCode(T object) { - return System.identityHashCode(object); - } - - /** - * Compares object references for equality. - * - * @param o1 an Object value - * @param o2 an Object value - * @return true if o1 == o2 - */ - public final boolean equals(T o1, T o2) { - return o1 == o2; - } -} // TObjectIdentityHashingStrategy diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntHashMap.java deleted file mode 100644 index ec39bba3789..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntHashMap.java +++ /dev/null @@ -1,631 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TObjectIntHashMap extends TObjectHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TObjectIntProcedure PUT_ALL_PROC = new TObjectIntProcedure() { - public boolean execute(K key, int value) { - put(key, value); - return true; - } - }; - - /** - * the values of the map - */ - protected transient int[] _values; - - /** - * Creates a new TObjectIntHashMap instance with the default - * capacity and load factor. - */ - public TObjectIntHashMap() { - super(); - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TObjectIntHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectIntHashMap(TObjectHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TObjectIntHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectIntHashMap(int initialCapacity, TObjectHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TObjectIntHashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return an iterator over the entries in this map - */ - public TObjectIntIterator iterator() { - return new TObjectIntIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new int[capacity]; - return capacity; - } - - /** - * Inserts a key/value pair into the map. - * - * @param key an Object value - * @param value an int value - * @return the previous value associated with key, - * or (int)0 if none was found. - */ - public int put(K key, int value) { - int index = insertionIndex(key); - return doPut(key, 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 int value - * @return the previous value associated with key, - * or (int)0 if none was found. - */ - public int putIfAbsent(K key, int value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private int doPut(K key, int value, int index) { - int previous = (int) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - K oldKey = (K) _set[index]; - _set[index] = key; - _values[index] = value; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - return previous; - } - - - /** - * 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(TObjectIntHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - protected void rehash(int newCapacity) { - int oldCapacity = _set.length; - K oldKeys[] = (K[]) _set; - int oldVals[] = _values; - - _set = new Object[newCapacity]; - Arrays.fill(_set, FREE); - _values = new int[newCapacity]; - - for (int i = oldCapacity; i-- > 0;) { - if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { - K o = oldKeys[i]; - int index = insertionIndex(o); - if (index < 0) { - throwObjectContractViolation(_set[(-index - 1)], o); - } - _set[index] = o; - _values[index] = oldVals[i]; - } - } - } - - /** - * retrieves the value for key - * - * @param key an Object value - * @return the value of key or (int)0 if no such mapping exists. - */ - public int get(K key) { - int index = index(key); - return index < 0 ? (int) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - Object[] keys = _set; - int[] vals = _values; - - Arrays.fill(_set, 0, _set.length, FREE); - Arrays.fill(_values, 0, _values.length, (int) 0); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return an int value or (int)0 if no such mapping exists. - */ - public int remove(K key) { - int prev = (int) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TObjectIntHashMap)) { - return false; - } - TObjectIntHashMap that = (TObjectIntHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - /** - * {@inheritDoc} - */ - @Override - public TObjectIntHashMap clone() { - TObjectIntHashMap clone = (TObjectIntHashMap) super.clone(); - clone._values = new int[_values.length]; - System.arraycopy(_values, 0, clone._values, 0, clone._values.length); - - return clone; - } - - - private static final class EqProcedure implements TObjectIntProcedure { - private final TObjectIntHashMap _otherMap; - - EqProcedure(TObjectIntHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(Object key, int value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two ints for equality. - */ - private final boolean eq(int v1, int v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public int[] getValues() { - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - public Object[] keys() { - Object[] keys = new Object[size()]; - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - keys[j++] = k[i]; - } - } - return keys; - } - - /** - * returns the keys of the map. - * - * @param a 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 runtime type is allocated for this purpose. - * @return a Set value - */ - public K[] keys(K[] a) { - int size = size(); - if (a.length < size) { - a = (K[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - 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; - } - - - /** - * checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(K key) { - return contains(key); - } - - /** - * 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) { - 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. - */ - 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. - */ - public boolean forEachEntry(TObjectIntProcedure procedure) { - K[] keys = (K[]) _set; - int[] values = _values; - for (int i = keys.length; i-- > 0;) { - if (keys[i] != FREE - && keys[i] != REMOVED - && !procedure.execute(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. - */ - public boolean retainEntries(TObjectIntProcedure procedure) { - boolean modified = false; - 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 - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (int) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public int adjustOrPutValue(final K key, final int adjust_amount, final int put_amount) { - int index = insertionIndex(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; - } - - K oldKey = (K) _set[index]; - _set[index] = key; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - K key = (K) in.readObject(); - int val = in.readInt(); - put(key, val); - } - } - - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TObjectIntProcedure() { - private boolean first = true; - - public boolean execute(K 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(); - } -} // TObjectIntHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntIterator.java deleted file mode 100644 index 0d4903b6c1e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntIterator.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.util.ConcurrentModificationException; - -////////////////////////////////////////////////// -// 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 - * @version $Id: O2PIterator.template,v 1.3 2007/01/22 16:56:39 robeden Exp $ - */ - -public class TObjectIntIterator extends TIterator { - private final TObjectIntHashMap _map; - - public TObjectIntIterator(TObjectIntHashMap map) { - super(map); - this._map = map; - } - - /** - * Returns the index of the next value in the data structure - * or a negative value if the iterator is exhausted. - * - * @return an int value - */ - protected final int nextIndex() { - if (_expectedSize != _hash.size()) { - throw new ConcurrentModificationException(); - } - - Object[] set = _map._set; - int i = _index; - while (i-- > 0 && (set[i] == null || set[i] == TObjectHash.REMOVED || - set[i] == TObjectHash.FREE)) ; - return i; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return (K) _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - int old = value(); - _map._values[_index] = val; - return old; - } -}// TObjectIntIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntProcedure.java deleted file mode 100644 index d361dd53ee5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectIntProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type Object and int. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: O2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TObjectIntProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongHashMap.java deleted file mode 100644 index 23fa7d9c61a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongHashMap.java +++ /dev/null @@ -1,631 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TObjectLongHashMap extends TObjectHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TObjectLongProcedure PUT_ALL_PROC = new TObjectLongProcedure() { - public boolean execute(K key, long value) { - put(key, value); - return true; - } - }; - - /** - * the values of the map - */ - protected transient long[] _values; - - /** - * Creates a new TObjectLongHashMap instance with the default - * capacity and load factor. - */ - public TObjectLongHashMap() { - super(); - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TObjectLongHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectLongHashMap(TObjectHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TObjectLongHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectLongHashMap(int initialCapacity, TObjectHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TObjectLongHashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return an iterator over the entries in this map - */ - public TObjectLongIterator iterator() { - return new TObjectLongIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new long[capacity]; - return capacity; - } - - /** - * 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 (long)0 if none was found. - */ - public long put(K key, long value) { - int index = insertionIndex(key); - return doPut(key, 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 long value - * @return the previous value associated with key, - * or (long)0 if none was found. - */ - public long putIfAbsent(K key, long value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private long doPut(K key, long value, int index) { - long previous = (long) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - K oldKey = (K) _set[index]; - _set[index] = key; - _values[index] = value; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - return previous; - } - - - /** - * 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(TObjectLongHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - protected void rehash(int newCapacity) { - int oldCapacity = _set.length; - K oldKeys[] = (K[]) _set; - long oldVals[] = _values; - - _set = new Object[newCapacity]; - Arrays.fill(_set, FREE); - _values = new long[newCapacity]; - - for (int i = oldCapacity; i-- > 0;) { - if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { - K o = oldKeys[i]; - int index = insertionIndex(o); - if (index < 0) { - throwObjectContractViolation(_set[(-index - 1)], o); - } - _set[index] = o; - _values[index] = oldVals[i]; - } - } - } - - /** - * retrieves the value for key - * - * @param key an Object value - * @return the value of key or (long)0 if no such mapping exists. - */ - public long get(K key) { - int index = index(key); - return index < 0 ? (long) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - Object[] keys = _set; - long[] vals = _values; - - Arrays.fill(_set, 0, _set.length, FREE); - Arrays.fill(_values, 0, _values.length, (long) 0); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return an long value or (long)0 if no such mapping exists. - */ - public long remove(K key) { - long prev = (long) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TObjectLongHashMap)) { - return false; - } - TObjectLongHashMap that = (TObjectLongHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - /** - * {@inheritDoc} - */ - @Override - public TObjectLongHashMap clone() { - TObjectLongHashMap clone = (TObjectLongHashMap) super.clone(); - clone._values = new long[_values.length]; - System.arraycopy(_values, 0, clone._values, 0, clone._values.length); - - return clone; - } - - - private static final class EqProcedure implements TObjectLongProcedure { - private final TObjectLongHashMap _otherMap; - - EqProcedure(TObjectLongHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(Object key, long value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two longs for equality. - */ - private final boolean eq(long v1, long v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public long[] getValues() { - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - public Object[] keys() { - Object[] keys = new Object[size()]; - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - keys[j++] = k[i]; - } - } - return keys; - } - - /** - * returns the keys of the map. - * - * @param a 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 runtime type is allocated for this purpose. - * @return a Set value - */ - public K[] keys(K[] a) { - int size = size(); - if (a.length < size) { - a = (K[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - 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; - } - - - /** - * checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(K key) { - return contains(key); - } - - /** - * 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) { - 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. - */ - 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. - */ - public boolean forEachEntry(TObjectLongProcedure procedure) { - K[] keys = (K[]) _set; - long[] values = _values; - for (int i = keys.length; i-- > 0;) { - if (keys[i] != FREE - && keys[i] != REMOVED - && !procedure.execute(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. - */ - public boolean retainEntries(TObjectLongProcedure procedure) { - boolean modified = false; - 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 - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (long) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public long adjustOrPutValue(final K key, final long adjust_amount, final long put_amount) { - int index = insertionIndex(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; - } - - K oldKey = (K) _set[index]; - _set[index] = key; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - K key = (K) in.readObject(); - long val = in.readLong(); - put(key, val); - } - } - - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TObjectLongProcedure() { - private boolean first = true; - - public boolean execute(K 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(); - } -} // TObjectLongHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongIterator.java deleted file mode 100644 index a5b125c604e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongIterator.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.util.ConcurrentModificationException; - -////////////////////////////////////////////////// -// 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 - * @version $Id: O2PIterator.template,v 1.3 2007/01/22 16:56:39 robeden Exp $ - */ - -public class TObjectLongIterator extends TIterator { - private final TObjectLongHashMap _map; - - public TObjectLongIterator(TObjectLongHashMap map) { - super(map); - this._map = map; - } - - /** - * Returns the index of the next value in the data structure - * or a negative value if the iterator is exhausted. - * - * @return an long value - */ - protected final int nextIndex() { - if (_expectedSize != _hash.size()) { - throw new ConcurrentModificationException(); - } - - Object[] set = _map._set; - int i = _index; - while (i-- > 0 && (set[i] == null || set[i] == TObjectHash.REMOVED || - set[i] == TObjectHash.FREE)) ; - return i; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return (K) _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - long old = value(); - _map._values[_index] = val; - return old; - } -}// TObjectLongIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongProcedure.java deleted file mode 100644 index 3db1eb8296d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectLongProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type Object and long. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: O2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TObjectLongProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectObjectProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectObjectProcedure.java deleted file mode 100644 index 31b31ae9598..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectObjectProcedure.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -/** - * 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.3 2006/11/10 23:27:57 robeden 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectProcedure.java deleted file mode 100644 index 87bff1d3be0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectProcedure.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -/** - * 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.4 2007/11/01 16:08:14 robeden 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortHashMap.java deleted file mode 100644 index 7d5c89f26eb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortHashMap.java +++ /dev/null @@ -1,631 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TObjectShortHashMap extends TObjectHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TObjectShortProcedure PUT_ALL_PROC = new TObjectShortProcedure() { - public boolean execute(K key, short value) { - put(key, value); - return true; - } - }; - - /** - * the values of the map - */ - protected transient short[] _values; - - /** - * Creates a new TObjectShortHashMap instance with the default - * capacity and load factor. - */ - public TObjectShortHashMap() { - super(); - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TObjectShortHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectShortHashMap(TObjectHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TObjectShortHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TObjectShortHashMap(int initialCapacity, TObjectHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TObjectShortHashMap(int initialCapacity, float loadFactor, TObjectHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return an iterator over the entries in this map - */ - public TObjectShortIterator iterator() { - return new TObjectShortIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new short[capacity]; - return capacity; - } - - /** - * 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 (short)0 if none was found. - */ - public short put(K key, short value) { - int index = insertionIndex(key); - return doPut(key, 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 short value - * @return the previous value associated with key, - * or (short)0 if none was found. - */ - public short putIfAbsent(K key, short value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private short doPut(K key, short value, int index) { - short previous = (short) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - K oldKey = (K) _set[index]; - _set[index] = key; - _values[index] = value; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - return previous; - } - - - /** - * 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(TObjectShortHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - protected void rehash(int newCapacity) { - int oldCapacity = _set.length; - K oldKeys[] = (K[]) _set; - short oldVals[] = _values; - - _set = new Object[newCapacity]; - Arrays.fill(_set, FREE); - _values = new short[newCapacity]; - - for (int i = oldCapacity; i-- > 0;) { - if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { - K o = oldKeys[i]; - int index = insertionIndex(o); - if (index < 0) { - throwObjectContractViolation(_set[(-index - 1)], o); - } - _set[index] = o; - _values[index] = oldVals[i]; - } - } - } - - /** - * retrieves the value for key - * - * @param key an Object value - * @return the value of key or (short)0 if no such mapping exists. - */ - public short get(K key) { - int index = index(key); - return index < 0 ? (short) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - Object[] keys = _set; - short[] vals = _values; - - Arrays.fill(_set, 0, _set.length, FREE); - Arrays.fill(_values, 0, _values.length, (short) 0); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return an short value or (short)0 if no such mapping exists. - */ - public short remove(K key) { - short prev = (short) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TObjectShortHashMap)) { - return false; - } - TObjectShortHashMap that = (TObjectShortHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - /** - * {@inheritDoc} - */ - @Override - public TObjectShortHashMap clone() { - TObjectShortHashMap clone = (TObjectShortHashMap) super.clone(); - clone._values = new short[_values.length]; - System.arraycopy(_values, 0, clone._values, 0, clone._values.length); - - return clone; - } - - - private static final class EqProcedure implements TObjectShortProcedure { - private final TObjectShortHashMap _otherMap; - - EqProcedure(TObjectShortHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(Object key, short value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two shorts for equality. - */ - private final boolean eq(short v1, short v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public short[] getValues() { - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - public Object[] keys() { - Object[] keys = new Object[size()]; - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - keys[j++] = k[i]; - } - } - return keys; - } - - /** - * returns the keys of the map. - * - * @param a 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 runtime type is allocated for this purpose. - * @return a Set value - */ - public K[] keys(K[] a) { - int size = size(); - if (a.length < size) { - a = (K[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - K[] k = (K[]) _set; - - for (int i = k.length, j = 0; i-- > 0;) { - if (k[i] != FREE && k[i] != REMOVED) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - 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; - } - - - /** - * checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(K key) { - return contains(key); - } - - /** - * 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) { - 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. - */ - 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. - */ - public boolean forEachEntry(TObjectShortProcedure procedure) { - K[] keys = (K[]) _set; - short[] values = _values; - for (int i = keys.length; i-- > 0;) { - if (keys[i] != FREE - && keys[i] != REMOVED - && !procedure.execute(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. - */ - public boolean retainEntries(TObjectShortProcedure procedure) { - boolean modified = false; - 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 - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (short) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public short adjustOrPutValue(final K key, final short adjust_amount, final short put_amount) { - int index = insertionIndex(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; - } - - K oldKey = (K) _set[index]; - _set[index] = key; - - if (isNewMapping) { - postInsertHook(oldKey == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - K key = (K) in.readObject(); - short val = in.readShort(); - put(key, val); - } - } - - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TObjectShortProcedure() { - private boolean first = true; - - public boolean execute(K 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(); - } -} // TObjectShortHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortIterator.java deleted file mode 100644 index 65b83ce8ca5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortIterator.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.util.ConcurrentModificationException; - -////////////////////////////////////////////////// -// 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 - * @version $Id: O2PIterator.template,v 1.3 2007/01/22 16:56:39 robeden Exp $ - */ - -public class TObjectShortIterator extends TIterator { - private final TObjectShortHashMap _map; - - public TObjectShortIterator(TObjectShortHashMap map) { - super(map); - this._map = map; - } - - /** - * Returns the index of the next value in the data structure - * or a negative value if the iterator is exhausted. - * - * @return an short value - */ - protected final int nextIndex() { - if (_expectedSize != _hash.size()) { - throw new ConcurrentModificationException(); - } - - Object[] set = _map._set; - int i = _index; - while (i-- > 0 && (set[i] == null || set[i] == TObjectHash.REMOVED || - set[i] == TObjectHash.FREE)) ; - return i; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return (K) _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - short old = value(); - _map._values[_index] = val; - return old; - } -}// TObjectShortIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortProcedure.java deleted file mode 100644 index 9906d1a93cf..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TObjectShortProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type Object and short. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: O2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TObjectShortProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TPrimitiveHash.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TPrimitiveHash.java deleted file mode 100644 index f447847b2b4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TPrimitiveHash.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -/** - * 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. - *

- * Created: Fri Jan 11 18:55:16 2002 - * - * @author Eric D. Friedman - * @version $Id: TPrimitiveHash.java,v 1.5 2008/10/08 16:39:10 robeden Exp $ - */ - -abstract public class TPrimitiveHash extends THash { - /** - * flags indicating whether each position in the hash is - * FREE, FULL, or REMOVED - */ - protected transient byte[] _states; - - /* constants used for state flags */ - - /** - * flag indicating that a slot in the hashtable is available - */ - protected static final byte FREE = 0; - - /** - * flag indicating that a slot in the hashtable is occupied - */ - protected static final byte FULL = 1; - - /** - * flag indicating that the value of a slot in the hashtable - * was deleted - */ - protected 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(); - _loadFactor = loadFactor; - setUp(HashFunctions.fastCeil(initialCapacity / loadFactor)); - } - - public Object clone() { - TPrimitiveHash h = (TPrimitiveHash) super.clone(); - h._states = (byte[]) this._states.clone(); - return h; - } - - /** - * 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. - */ - protected int capacity() { - return _states.length; - } - - /** - * Delete the record at index. - * - * @param index an int value - */ - 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 - */ - protected int setUp(int initialCapacity) { - int capacity; - - capacity = super.setUp(initialCapacity); - _states = new byte[capacity]; - return capacity; - } -} // TPrimitiveHash diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TPrimitiveIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TPrimitiveIterator.java deleted file mode 100644 index c5b32f0ac42..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TPrimitiveIterator.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.util.ConcurrentModificationException; - -/** - * 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.

- */ -abstract class TPrimitiveIterator extends TIterator { - /** - * the collection on which this iterator operates. - */ - protected final TPrimitiveHash _hash; - - /** - * Creates a TPrimitiveIterator for the specified collection. - */ - public TPrimitiveIterator(TPrimitiveHash hash) { - super(hash); - _hash = hash; - } - - /** - * 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(); - } - - byte[] states = _hash._states; - int i = _index; - while (i-- > 0 && (states[i] != TPrimitiveHash.FULL)) ; - return i; - } - -} // TPrimitiveIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortArrayList.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortArrayList.java deleted file mode 100644 index ad48b58b970..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortArrayList.java +++ /dev/null @@ -1,935 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; -import java.util.Random; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * A resizable, array-backed list of short primitives. - *

- * Created: Sat Dec 29 14:21:12 2001 - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TShortArrayList implements Externalizable, Cloneable { - 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 = 10; - - /** - * Creates a new TShortArrayList instance with the - * default capacity. - */ - public TShortArrayList() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TShortArrayList instance with the - * specified capacity. - * - * @param capacity an int value - */ - public TShortArrayList(int capacity) { - _data = new short[capacity]; - _pos = 0; - } - - /** - * Creates a new TShortArrayList instance whose - * capacity is the greater of the length of values and - * DEFAULT_CAPACITY and whose initial contents are the specified - * values. - * - * @param values an short[] value - */ - public TShortArrayList(short[] values) { - this(Math.max(values.length, DEFAULT_CAPACITY)); - add(values); - } - - // sizing - - /** - * Grow the internal array as needed to accommodate the specified - * number of elements. The size of the array shorts on each - * resize unless capacity requires more than twice the - * current capacity. - * - * @param capacity an int value - */ - 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; - } - } - - /** - * Returns the number of values in the list. - * - * @return the number of values in the list. - */ - public int size() { - return _pos; - } - - /** - * Tests whether this list contains any values. - * - * @return true if the list is empty. - */ - 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()]; - toNativeArray(tmp, 0, tmp.length); - _data = tmp; - } - } - - // modifying - - /** - * Adds val to the end of the list, growing as needed. - * - * @param val an short value - */ - public void add(short val) { - ensureCapacity(_pos + 1); - _data[_pos++] = 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) { - add(vals, 0, vals.length); - } - - /** - * 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) { - ensureCapacity(_pos + length); - System.arraycopy(vals, offset, _data, _pos, length); - _pos += 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) { - 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++; - } - - /** - * 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) { - insert(offset, values, 0, values.length); - } - - /** - * 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) { - 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; - } - - /** - * Returns the value at the specified offset. - * - * @param offset an int value - * @return an short value - */ - 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. - * - * @param offset an int value - * @return an short value - */ - public short getQuick(int offset) { - return _data[offset]; - } - - /** - * Sets the value at the specified offset. - * - * @param offset an int value - * @param val an short value - */ - public void set(int offset, short val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - _data[offset] = val; - } - - /** - * 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 getSet(int offset, short val) { - if (offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - short old = _data[offset]; - _data[offset] = val; - return old; - } - - /** - * 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) { - set(offset, values, 0, values.length); - } - - /** - * 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) { - 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. - * - * @param offset an int value - * @param val an short value - */ - public void setQuick(int offset, short val) { - _data[offset] = val; - } - - /** - * Flushes the internal state of the list, resetting the capacity - * to the default. - */ - public void clear() { - clear(DEFAULT_CAPACITY); - } - - /** - * Flushes the internal state of the list, setting the capacity of - * the empty list to capacity. - * - * @param capacity an int value - */ - 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 clear} method if you want to recyle a list without - * allocating new backing arrays. - * - * @see #clear - */ - public void reset() { - _pos = 0; - fill((short) 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 clear} method if you want to recyle a list - * without allocating new backing arrays. This method differs - * from {@link #reset reset} in that it does not clear the old - * values in the backing array. Thus, it is possible for {@link - * #getQuick getQuick} to return stale data if this method is used - * and the caller is careless about bounds checking. - * - * @see #reset - * @see #clear - * @see #getQuick - */ - public void resetQuick() { - _pos = 0; - } - - /** - * Removes the value at offset from the list. - * - * @param offset an int value - * @return the value previously stored at offset. - */ - public short remove(int offset) { - short old = get(offset); - remove(offset, 1); - return old; - } - - /** - * 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) { - 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 - } - - /** - * Transform each value in the list using the specified function. - * - * @param function a TShortFunction value - */ - public void transformValues(TShortFunction function) { - for (int i = _pos; i-- > 0;) { - _data[i] = function.execute(_data[i]); - } - } - - /** - * Reverse the order of the elements in the list. - */ - public void reverse() { - reverse(0, _pos); - } - - /** - * 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) { - 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); - } - } - - /** - * Shuffle the elements of the list using the specified random - * number generator. - * - * @param rand a Random value - */ - 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 final void swap(int i, int j) { - short tmp = _data[i]; - _data[i] = _data[j]; - _data[j] = tmp; - } - - // copying - - /** - * Returns a clone of this list. Since this is a primitive - * collection, this will be a deep clone. - * - * @return a deep clone of the list. - */ - public Object clone() { - TShortArrayList list = null; - try { - list = (TShortArrayList) super.clone(); - list._data = toNativeArray(); - } catch (CloneNotSupportedException e) { - // it's supported - } // end of try-catch - return list; - } - - - /** - * 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 TShortArrayList 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; - } - - - /** - * Copies the contents of the list into a native array. - * - * @return an short[] value - */ - public short[] toNativeArray() { - return toNativeArray(0, _pos); - } - - /** - * 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[] toNativeArray(int offset, int len) { - short[] rv = new short[len]; - toNativeArray(rv, offset, len); - return rv; - } - - /** - * Copies a slice of the list into a native array. - * - * @param dest the array to copy into. - * @param offset the offset of the first value to copy - * @param len the number of values to copy. - */ - public void toNativeArray(short[] dest, int offset, int len) { - if (len == 0) { - return; // nothing to copy - } - if (offset < 0 || offset >= _pos) { - throw new ArrayIndexOutOfBoundsException(offset); - } - System.arraycopy(_data, offset, dest, 0, len); - } - - // comparing - - /** - * Compares this list to another list, value by value. - * - * @param other the object to compare against - * @return true if other is a TShortArrayList and has exactly the - * same values. - */ - public boolean equals(Object other) { - if (other == this) { - return true; - } else if (other instanceof TShortArrayList) { - TShortArrayList that = (TShortArrayList) other; - if (that.size() != this.size()) { - return false; - } else { - for (int i = _pos; i-- > 0;) { - if (this._data[i] != that._data[i]) { - return false; - } - } - return true; - } - } else { - return false; - } - } - - public int hashCode() { - int h = 0; - for (int i = _pos; i-- > 0;) { - h = 37 * h + HashFunctions.hash(_data[i]); - } - return h; - } - - // procedures - - /** - * 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. - */ - public boolean forEach(TShortProcedure procedure) { - for (int i = 0; i < _pos; i++) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - /** - * 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) { - for (int i = _pos; i-- > 0;) { - if (!procedure.execute(_data[i])) { - return false; - } - } - return true; - } - - // sorting - - /** - * Sort the values in the list (ascending) using the Sun quicksort - * implementation. - * - * @see java.util.Arrays#sort - */ - public void sort() { - Arrays.sort(_data, 0, _pos); - } - - /** - * 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) { - Arrays.sort(_data, fromIndex, toIndex); - } - - // filling - - /** - * Fills every slot in the list with the specified value. - * - * @param val the value to use when filling - */ - public void fill(short val) { - Arrays.fill(_data, 0, _pos, 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) { - if (toIndex > _pos) { - ensureCapacity(toIndex); - _pos = toIndex; - } - Arrays.fill(_data, fromIndex, toIndex, val); - } - - // searching - - /** - * 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) { - return binarySearch(value, 0, _pos); - } - - /** - * 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) { - 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. - } - - /** - * 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) { - return indexOf(0, 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) { - for (int i = offset; i < _pos; i++) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * 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) { - return lastIndexOf(_pos, 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) { - for (int i = offset; i-- > 0;) { - if (_data[i] == value) { - return i; - } - } - return -1; - } - - /** - * Searches the list for value - * - * @param value an short value - * @return true if value is in the list. - */ - public boolean contains(short value) { - return lastIndexOf(value) >= 0; - } - - /** - * 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 TShortArrayList 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; - } - - /** - * 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 TShortArrayList 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; - } - - /** - * Finds the maximum value in the list. - * - * @return the largest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - /** - * Finds the minimum value in the list. - * - * @return the smallest value in the list. - * @throws IllegalStateException if the list is empty - */ - 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; - } - - // stringification - - /** - * Returns a String representation of the list, front to back. - * - * @return a String value - */ - 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(); - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(1); - - // POSITION - out.writeInt(_pos); - - // ENTRIES - int len = _pos; - out.writeInt(_pos); // Written twice for backwards compatability with - // version 0 - for (int i = 0; i < len; i++) { - out.writeShort(_data[i]); - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // POSITION - _pos = in.readInt(); - - // ENTRIES - int len = in.readInt(); - _data = new short[len]; - for (int i = 0; i < len; i++) { - _data[i] = in.readShort(); - } - } -} // TShortArrayList diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteHashMap.java deleted file mode 100644 index 947058ad61f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for short keys and byte values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TShortByteHashMap extends TShortHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TShortByteProcedure PUT_ALL_PROC = new TShortByteProcedure() { - public boolean execute(short key, byte value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortByteHashMap(TShortHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TShortByteHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortByteHashMap(int initialCapacity, TShortHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TShortByteHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TShortByteHashMap(int initialCapacity, float loadFactor, TShortHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TShortByteHashMap m = (TShortByteHashMap) super.clone(); - m._values = (byte[]) this._values.clone(); - return m; - } - - /** - * @return a TShortByteIterator with access to this map's keys and values - */ - public TShortByteIterator iterator() { - return new TShortByteIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new byte[capacity]; - return capacity; - } - - /** - * 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 (short)0 if none was found. - */ - public byte put(short key, byte value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (short)0 if none was found. - */ - public byte putIfAbsent(short key, byte value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private byte doPut(short key, byte value, int index) { - byte previousState; - byte previous = (byte) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TShortByteHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an short value - * @return the value of key or (short)0 if no such mapping exists. - */ - public byte get(short key) { - int index = index(key); - return index < 0 ? (byte) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - short[] keys = _set; - byte[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (short) 0); - Arrays.fill(_values, 0, _values.length, (byte) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an short value - * @return an byte value, or (short)0 if no mapping for key exists - */ - public byte remove(short key) { - byte prev = (byte) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TShortByteHashMap)) { - return false; - } - TShortByteHashMap that = (TShortByteHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TShortByteProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(short key, byte value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TShortByteProcedure { - private final TShortByteHashMap _otherMap; - - EqProcedure(TShortByteHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(short key, byte value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two bytes for equality. - */ - private final boolean eq(byte v1, byte v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (byte) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public byte[] getValues() { - byte[] vals = new byte[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public short[] keys(short[] a) { - int size = size(); - if (a.length < size) { - a = (short[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - short[] k = (short[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - byte[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TByteFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (byte) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public byte adjustOrPutValue(final short key, final byte adjust_amount, final byte put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - short key = in.readShort(); - byte val = in.readByte(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TShortByteProcedure() { - private boolean first = true; - - 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(); - } -} // TShortByteHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteIterator.java deleted file mode 100644 index 696a6267754..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TShortByteIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TShortByteHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TShortByteIterator(TShortByteHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - byte old = value(); - _map._values[_index] = val; - return old; - } -}// TShortByteIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteProcedure.java deleted file mode 100644 index c53062c8a1b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortByteProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type short and byte. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TShortByteProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleHashMap.java deleted file mode 100644 index 91677f6401b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for short keys and double values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TShortDoubleHashMap extends TShortHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TShortDoubleProcedure PUT_ALL_PROC = new TShortDoubleProcedure() { - public boolean execute(short key, double value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortDoubleHashMap(TShortHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TShortDoubleHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortDoubleHashMap(int initialCapacity, TShortHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TShortDoubleHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TShortDoubleHashMap(int initialCapacity, float loadFactor, TShortHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TShortDoubleHashMap m = (TShortDoubleHashMap) super.clone(); - m._values = (double[]) this._values.clone(); - return m; - } - - /** - * @return a TShortDoubleIterator with access to this map's keys and values - */ - public TShortDoubleIterator iterator() { - return new TShortDoubleIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new double[capacity]; - return capacity; - } - - /** - * 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 (short)0 if none was found. - */ - public double put(short key, double value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (short)0 if none was found. - */ - public double putIfAbsent(short key, double value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private double doPut(short key, double value, int index) { - byte previousState; - double previous = (double) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TShortDoubleHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an short value - * @return the value of key or (short)0 if no such mapping exists. - */ - public double get(short key) { - int index = index(key); - return index < 0 ? (double) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - short[] keys = _set; - double[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (short) 0); - Arrays.fill(_values, 0, _values.length, (double) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an short value - * @return an double value, or (short)0 if no mapping for key exists - */ - public double remove(short key) { - double prev = (double) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TShortDoubleHashMap)) { - return false; - } - TShortDoubleHashMap that = (TShortDoubleHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TShortDoubleProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(short key, double value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TShortDoubleProcedure { - private final TShortDoubleHashMap _otherMap; - - EqProcedure(TShortDoubleHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(short key, double value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two doubles for equality. - */ - private final boolean eq(double v1, double v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (double) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public double[] getValues() { - double[] vals = new double[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public short[] keys(short[] a) { - int size = size(); - if (a.length < size) { - a = (short[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - short[] k = (short[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - double[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TDoubleFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (double) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public double adjustOrPutValue(final short key, final double adjust_amount, final double put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - short key = in.readShort(); - double val = in.readDouble(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TShortDoubleProcedure() { - private boolean first = true; - - 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(); - } -} // TShortDoubleHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleIterator.java deleted file mode 100644 index 6bb3331197a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TShortDoubleIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TShortDoubleHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TShortDoubleIterator(TShortDoubleHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - double old = value(); - _map._values[_index] = val; - return old; - } -}// TShortDoubleIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleProcedure.java deleted file mode 100644 index ca4ce24f8bf..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortDoubleProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type short and double. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TShortDoubleProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatHashMap.java deleted file mode 100644 index de590752663..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for short keys and float values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TShortFloatHashMap extends TShortHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TShortFloatProcedure PUT_ALL_PROC = new TShortFloatProcedure() { - public boolean execute(short key, float value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortFloatHashMap(TShortHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TShortFloatHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortFloatHashMap(int initialCapacity, TShortHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TShortFloatHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TShortFloatHashMap(int initialCapacity, float loadFactor, TShortHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TShortFloatHashMap m = (TShortFloatHashMap) super.clone(); - m._values = (float[]) this._values.clone(); - return m; - } - - /** - * @return a TShortFloatIterator with access to this map's keys and values - */ - public TShortFloatIterator iterator() { - return new TShortFloatIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new float[capacity]; - return capacity; - } - - /** - * 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 (short)0 if none was found. - */ - public float put(short key, float value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (short)0 if none was found. - */ - public float putIfAbsent(short key, float value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private float doPut(short key, float value, int index) { - byte previousState; - float previous = (float) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TShortFloatHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an short value - * @return the value of key or (short)0 if no such mapping exists. - */ - public float get(short key) { - int index = index(key); - return index < 0 ? (float) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - short[] keys = _set; - float[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (short) 0); - Arrays.fill(_values, 0, _values.length, (float) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an short value - * @return an float value, or (short)0 if no mapping for key exists - */ - public float remove(short key) { - float prev = (float) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TShortFloatHashMap)) { - return false; - } - TShortFloatHashMap that = (TShortFloatHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TShortFloatProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(short key, float value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TShortFloatProcedure { - private final TShortFloatHashMap _otherMap; - - EqProcedure(TShortFloatHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(short key, float value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two floats for equality. - */ - private final boolean eq(float v1, float v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (float) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public float[] getValues() { - float[] vals = new float[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public short[] keys(short[] a) { - int size = size(); - if (a.length < size) { - a = (short[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - short[] k = (short[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - float[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TFloatFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (float) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public float adjustOrPutValue(final short key, final float adjust_amount, final float put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - short key = in.readShort(); - float val = in.readFloat(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TShortFloatProcedure() { - private boolean first = true; - - 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(); - } -} // TShortFloatHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatIterator.java deleted file mode 100644 index 42625b98d16..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TShortFloatIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TShortFloatHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TShortFloatIterator(TShortFloatHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - float old = value(); - _map._values[_index] = val; - return old; - } -}// TShortFloatIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatProcedure.java deleted file mode 100644 index ba515d87090..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFloatProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type short and float. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TShortFloatProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFunction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFunction.java deleted file mode 100644 index c4bec475628..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortFunction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for functions that accept and return one short primitive. - *

- * Created: Mon Nov 5 22:19:36 2001 - * - * @author Eric D. Friedman - * @version $Id: PFunction.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TShortFunction { - /** - * Execute this function with value - * - * @param value a short input - * @return a short result - */ - public short execute(short value); -}// TShortFunction diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHash.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHash.java deleted file mode 100644 index 82736851eb4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHash.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: PHash.template,v 1.2 2007/06/29 22:39:46 robeden Exp $ - */ - -abstract public class TShortHash extends TPrimitiveHash implements TShortHashingStrategy { - - /** - * the set of shorts - */ - protected transient short[] _set; - - /** - * strategy used to hash values in this collection - */ - protected TShortHashingStrategy _hashingStrategy; - - /** - * Creates a new TShortHash instance with the default - * capacity and load factor. - */ - public TShortHash() { - super(); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * 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); - this._hashingStrategy = this; - } - - /** - * Creates a new TShortHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortHash(TShortHashingStrategy strategy) { - super(); - this._hashingStrategy = strategy; - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortHash(int initialCapacity, TShortHashingStrategy strategy) { - super(initialCapacity); - this._hashingStrategy = strategy; - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TShortHash(int initialCapacity, float loadFactor, TShortHashingStrategy strategy) { - super(initialCapacity, loadFactor); - this._hashingStrategy = strategy; - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TShortHash h = (TShortHash) super.clone(); - h._set = (short[]) this._set.clone(); - return h; - } - - /** - * 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 = 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 - */ - protected void removeAt(int index) { - _set[index] = (short) 0; - 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 = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - // see Knuth, p. 529 - probe = 1 + (hash % (length - 2)); - - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)); - } - - return states[index] == FREE ? -1 : index; - } - - /** - * 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 insertionIndex(short val) { - int hash, probe, index, length; - - final byte[] states = _states; - final short[] set = _set; - length = states.length; - hash = _hashingStrategy.computeHashCode(val) & 0x7fffffff; - index = hash % length; - - if (states[index] == FREE) { - return index; // empty, all done - } else if (states[index] == FULL && set[index] == val) { - 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 (states[index] != REMOVED) { - // starting at the natural offset, probe until we find an - // offset that isn't full. - do { - index -= probe; - if (index < 0) { - index += length; - } - } while (states[index] == FULL && set[index] != val); - } - - // 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 (states[index] == REMOVED) { - int firstRemoved = index; - while (states[index] != FREE && - (states[index] == REMOVED || set[index] != val)) { - index -= probe; - if (index < 0) { - index += length; - } - } - return states[index] == FULL ? -index - 1 : firstRemoved; - } - // if it's full, the key is already stored - return states[index] == FULL ? -index - 1 : index; - } - } - - /** - * Default implementation of TShortHashingStrategy: - * delegates hashing to HashFunctions.hash(short). - * - * @param val the value to hash - * @return the hashcode. - */ - public final int computeHashCode(short val) { - return HashFunctions.hash(val); - } -} // TShortHash diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHashSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHashSet.java deleted file mode 100644 index a7b8c0e8a14..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHashSet.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed set implementation for short primitives. - * - * @author Eric D. Friedman - * @author Rob Eden - */ - -public class TShortHashSet extends TShortHash implements 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 TShortHashSet 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 TShortHashSet(int initialCapacity, float loadFactor) { - super(initialCapacity, loadFactor); - } - - /** - * Creates a new TShortHashSet instance containing the - * elements of array. - * - * @param array an array of short primitives - */ - public TShortHashSet(short[] array) { - this(array.length); - addAll(array); - } - - /** - * Creates a new TShortHash instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortHashSet(TShortHashingStrategy strategy) { - super(strategy); - } - - /** - * 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 - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortHashSet(int initialCapacity, TShortHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TShortHashSet(int initialCapacity, float loadFactor, TShortHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * Creates a new TShortHashSet instance containing the - * elements of array. - * - * @param array an array of short primitives - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortHashSet(short[] array, TShortHashingStrategy strategy) { - this(array.length, strategy); - addAll(array); - } - - /** - * @return a TShortIterator with access to the values in this set - */ - public TShortIterator iterator() { - return new TShortIterator(this); - } - - /** - * Inserts a value into the set. - * - * @param val an short value - * @return true if the set was modified by the add operation - */ - public boolean add(short val) { - int index = insertionIndex(val); - - if (index < 0) { - return false; // already present in set, nothing to add - } - - byte previousState = _states[index]; - _set[index] = val; - _states[index] = FULL; - postInsertHook(previousState == FREE); - - return true; // yes, we added something - } - - /** - * Expands the set to accommodate new values. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _states[index] = FULL; - } - } - } - - /** - * Returns a new array containing the values in the set. - * - * @return an short[] value - */ - public short[] toArray() { - short[] result = new short[size()]; - 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; - } - - /** - * Empties the set. - */ - public void clear() { - super.clear(); - short[] set = _set; - byte[] states = _states; - - for (int i = set.length; i-- > 0;) { - set[i] = (short) 0; - states[i] = FREE; - } - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TShortHashSet)) { - return false; - } - final TShortHashSet that = (TShortHashSet) other; - if (that.size() != this.size()) { - return false; - } - return forEach(new TShortProcedure() { - public final boolean execute(short value) { - return that.contains(value); - } - }); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEach(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TShortProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(short key) { - h += _hashingStrategy.computeHashCode(key); - return true; - } - } - - /** - * Removes val from the set. - * - * @param val an short value - * @return true if the set was modified by the remove operation. - */ - public boolean remove(short val) { - int index = index(val); - if (index >= 0) { - removeAt(index); - return true; - } - return false; - } - - /** - * Tests the set to determine if all of the elements in - * array are present. - * - * @param array an array of short primitives. - * @return true if all elements were present in the set. - */ - public boolean containsAll(short[] array) { - for (int i = array.length; i-- > 0;) { - if (!contains(array[i])) { - return false; - } - } - return true; - } - - /** - * Adds all of the elements in array to the set. - * - * @param array an array of short primitives. - * @return true if the set was modified by the add all operation. - */ - public boolean addAll(short[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (add(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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. - */ - public boolean removeAll(short[] array) { - boolean changed = false; - for (int i = array.length; i-- > 0;) { - if (remove(array[i])) { - changed = true; - } - } - return changed; - } - - /** - * 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 - */ - 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)) { - remove(set[i]); - changed = true; - } - } - return changed; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEach(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - - // ENTRIES - setUp(size); - while (size-- > 0) { - short val = in.readShort(); - add(val); - } - } -} // TShortHashSet diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHashingStrategy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHashingStrategy.java deleted file mode 100644 index 54dbc620f8a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortHashingStrategy.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Serializable; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface to support pluggable hashing strategies in maps and sets. - * Implementors can use this interface to make the trove hashing - * algorithms use an optimal strategy when computing hashcodes. - *

- * Created: Sun Nov 4 08:56:06 2001 - * - * @author Eric D. Friedman - * @version $Id: PHashingStrategy.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public interface TShortHashingStrategy extends Serializable { - /** - * Computes a hash code for the specified short. Implementors - * can use the short's own value or a custom scheme designed to - * minimize collisions for a known set of input. - * - * @param val short for which the hashcode is to be computed - * @return the hashCode - */ - public int computeHashCode(short val); -} // TShortHashingStrategy diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntHashMap.java deleted file mode 100644 index f29b84567eb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for short keys and int values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TShortIntHashMap extends TShortHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TShortIntProcedure PUT_ALL_PROC = new TShortIntProcedure() { - public boolean execute(short key, int value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortIntHashMap(TShortHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TShortIntHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortIntHashMap(int initialCapacity, TShortHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TShortIntHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TShortIntHashMap(int initialCapacity, float loadFactor, TShortHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TShortIntHashMap m = (TShortIntHashMap) super.clone(); - m._values = (int[]) this._values.clone(); - return m; - } - - /** - * @return a TShortIntIterator with access to this map's keys and values - */ - public TShortIntIterator iterator() { - return new TShortIntIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new int[capacity]; - return capacity; - } - - /** - * 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 (short)0 if none was found. - */ - public int put(short key, int value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (short)0 if none was found. - */ - public int putIfAbsent(short key, int value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private int doPut(short key, int value, int index) { - byte previousState; - int previous = (int) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TShortIntHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an short value - * @return the value of key or (short)0 if no such mapping exists. - */ - public int get(short key) { - int index = index(key); - return index < 0 ? (int) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - short[] keys = _set; - int[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (short) 0); - Arrays.fill(_values, 0, _values.length, (int) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an short value - * @return an int value, or (short)0 if no mapping for key exists - */ - public int remove(short key) { - int prev = (int) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TShortIntHashMap)) { - return false; - } - TShortIntHashMap that = (TShortIntHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TShortIntProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(short key, int value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TShortIntProcedure { - private final TShortIntHashMap _otherMap; - - EqProcedure(TShortIntHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(short key, int value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two ints for equality. - */ - private final boolean eq(int v1, int v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (int) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public int[] getValues() { - int[] vals = new int[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public short[] keys(short[] a) { - int size = size(); - if (a.length < size) { - a = (short[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - short[] k = (short[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - int[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TIntFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (int) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public int adjustOrPutValue(final short key, final int adjust_amount, final int put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - short key = in.readShort(); - int val = in.readInt(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TShortIntProcedure() { - private boolean first = true; - - 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(); - } -} // TShortIntHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntIterator.java deleted file mode 100644 index aad56061aab..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TShortIntIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TShortIntHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TShortIntIterator(TShortIntHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - int old = value(); - _map._values[_index] = val; - return old; - } -}// TShortIntIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntProcedure.java deleted file mode 100644 index eb2333bb2b8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIntProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type short and int. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TShortIntProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIterator.java deleted file mode 100644 index 7c954d8ae28..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortIterator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Iterator for short collections. - * - * @author Eric D. Friedman - * @version $Id: PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TShortIterator extends TPrimitiveIterator { - /** - * the collection on which the iterator operates - */ - private final TShortHash _hash; - - /** - * Creates a TShortIterator for the elements in the specified collection. - */ - public TShortIterator(TShortHash hash) { - super(hash); - this._hash = hash; - } - - /** - * Advances the iterator to the next element in the underlying collection - * and returns it. - * - * @return the next short in the collection - * @throws NoSuchElementException if the iterator is already exhausted - */ - public short next() { - moveToNextIndex(); - return _hash._set[_index]; - } -}// TShortIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongHashMap.java deleted file mode 100644 index 9ebcdd78d7d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for short keys and long values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TShortLongHashMap extends TShortHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TShortLongProcedure PUT_ALL_PROC = new TShortLongProcedure() { - public boolean execute(short key, long value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortLongHashMap(TShortHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TShortLongHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortLongHashMap(int initialCapacity, TShortHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TShortLongHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TShortLongHashMap(int initialCapacity, float loadFactor, TShortHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TShortLongHashMap m = (TShortLongHashMap) super.clone(); - m._values = (long[]) this._values.clone(); - return m; - } - - /** - * @return a TShortLongIterator with access to this map's keys and values - */ - public TShortLongIterator iterator() { - return new TShortLongIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new long[capacity]; - return capacity; - } - - /** - * 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 (short)0 if none was found. - */ - public long put(short key, long value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (short)0 if none was found. - */ - public long putIfAbsent(short key, long value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private long doPut(short key, long value, int index) { - byte previousState; - long previous = (long) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TShortLongHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an short value - * @return the value of key or (short)0 if no such mapping exists. - */ - public long get(short key) { - int index = index(key); - return index < 0 ? (long) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - short[] keys = _set; - long[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (short) 0); - Arrays.fill(_values, 0, _values.length, (long) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an short value - * @return an long value, or (short)0 if no mapping for key exists - */ - public long remove(short key) { - long prev = (long) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TShortLongHashMap)) { - return false; - } - TShortLongHashMap that = (TShortLongHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TShortLongProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(short key, long value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TShortLongProcedure { - private final TShortLongHashMap _otherMap; - - EqProcedure(TShortLongHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(short key, long value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two longs for equality. - */ - private final boolean eq(long v1, long v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (long) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public long[] getValues() { - long[] vals = new long[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public short[] keys(short[] a) { - int size = size(); - if (a.length < size) { - a = (short[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - short[] k = (short[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - long[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TLongFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (long) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public long adjustOrPutValue(final short key, final long adjust_amount, final long put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - short key = in.readShort(); - long val = in.readLong(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TShortLongProcedure() { - private boolean first = true; - - 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(); - } -} // TShortLongHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongIterator.java deleted file mode 100644 index 92b4dfc01a8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TShortLongIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TShortLongHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TShortLongIterator(TShortLongHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - long old = value(); - _map._values[_index] = val; - return old; - } -}// TShortLongIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongProcedure.java deleted file mode 100644 index 3b6e072ee02..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortLongProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type short and long. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TShortLongProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectHashMap.java deleted file mode 100644 index 69ba02a60b7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectHashMap.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// 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 - */ -public class TShortObjectHashMap extends TShortHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TShortObjectProcedure PUT_ALL_PROC = new TShortObjectProcedure() { - public boolean execute(short key, V value) { - put(key, value); - return true; - } - }; - - - /** - * the values of the map - */ - protected transient V[] _values; - - /** - * 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); - } - - /** - * 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); - } - - /** - * Creates a new TShortObjectHashMap instance with the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortObjectHashMap(TShortHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TShortObjectHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortObjectHashMap(int initialCapacity, TShortHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * 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 strategy used to compute hash codes and to compare keys. - */ - public TShortObjectHashMap(int initialCapacity, float loadFactor, TShortHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public TShortObjectHashMap clone() { - TShortObjectHashMap m = (TShortObjectHashMap) super.clone(); - m._values = (V[]) this._values.clone(); - return m; - } - - /** - * @return a TShortObjectIterator with access to this map's keys and values - */ - public TShortObjectIterator iterator() { - return new TShortObjectIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = (V[]) new Object[capacity]; - return capacity; - } - - /** - * 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 {@code null} if none was found. - */ - public V put(short key, V value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 Object value - * @return the previous value associated with key, - * or {@code null} if none was found. - */ - public V putIfAbsent(short key, V value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private V doPut(short key, V value, int index) { - byte previousState; - V previous = null; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TShortObjectHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an short value - * @return the value of key or (short)0 if no such mapping exists. - */ - public V get(short key) { - int index = index(key); - return index < 0 ? null : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - short[] keys = _set; - Object[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (short) 0); - Arrays.fill(_values, 0, _values.length, null); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an short value - * @return an Object value or (short)0 if no such mapping exists. - */ - 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; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TShortObjectHashMap)) { - return false; - } - TShortObjectHashMap that = (TShortObjectHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TShortObjectProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(short key, Object value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TShortObjectProcedure { - private final TShortObjectHashMap _otherMap; - - EqProcedure(TShortObjectHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(short key, Object value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two objects for equality. - */ - private final boolean eq(Object o1, Object o2) { - return o1 == o2 || ((o1 != null) && o1.equals(o2)); - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = null; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - * @see #getValues(Object[]) - */ - public Object[] getValues() { - 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; - } - - /** - * Return the values of the map; the runtime type of the returned array is that of - * the specified array. - * - * @param a the array into which the elements of this collection are to be - * stored, if it is big enough; otherwise, a new array of the same - * runtime type is allocated for this purpose. - * @return an array containing the elements of this collection - * @throws ArrayStoreException the runtime type of the specified array is - * not a supertype of the runtime type of every element in this - * collection. - * @throws NullPointerException if the specified array is null. - * @see #getValues() - */ - public T[] getValues(T[] a) { - if (a.length < _size) { - a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), - _size); - } - - V[] v = _values; - byte[] states = _states; - - for (int i = v.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = (T) v[i]; - } - } - return a; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public short[] keys(short[] a) { - int size = size(); - if (a.length < size) { - a = (short[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - short[] k = (short[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(V 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 && - val == 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; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * Executes procedure for each key/value entry in the - * map. - * - * @param procedure a TOShortObjectProcedure value - * @return false if the loop over the entries terminated because - * the procedure returned false for some entry. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TObjectFunction value - */ - 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]); - } - } - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // 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); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TShortObjectProcedure() { - private boolean first = true; - - 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/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectIterator.java deleted file mode 100644 index eb3b539b482..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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 - * @version $Id: P2OIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TShortObjectIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TShortObjectHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TShortObjectIterator(TShortObjectHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - V old = value(); - _map._values[_index] = val; - return old; - } -}// TShortObjectIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectProcedure.java deleted file mode 100644 index 63b7c9d7881..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortObjectProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type short and Object. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2OProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TShortObjectProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortProcedure.java deleted file mode 100644 index e5227769552..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortProcedure.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures with one short parameter. - *

- * Created: Mon Nov 5 21:45:49 2001 - * - * @author Eric D. Friedman - * @version $Id: PProcedure.template,v 1.2 2007/11/01 16:08:14 robeden Exp $ - */ - -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); -}// TShortProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortHashMap.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortHashMap.java deleted file mode 100644 index 1cfe5d70cf3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortHashMap.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * An open addressed Map implementation for short keys and short values. - *

- * Created: Sun Nov 4 08:52:45 2001 - * - * @author Eric D. Friedman - */ -public class TShortShortHashMap extends TShortHash implements Externalizable { - static final long serialVersionUID = 1L; - - private final TShortShortProcedure PUT_ALL_PROC = new TShortShortProcedure() { - public boolean execute(short key, short value) { - put(key, value); - return true; - } - }; - - - /** - * 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 the default - * capacity and load factor. - * - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortShortHashMap(TShortHashingStrategy strategy) { - super(strategy); - } - - /** - * Creates a new TShortShortHashMap instance whose capacity - * is the next highest prime above initialCapacity + 1 - * unless that value is already prime. - * - * @param initialCapacity an int value - * @param strategy used to compute hash codes and to compare keys. - */ - public TShortShortHashMap(int initialCapacity, TShortHashingStrategy strategy) { - super(initialCapacity, strategy); - } - - /** - * Creates a new TShortShortHashMap 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 strategy used to compute hash codes and to compare keys. - */ - public TShortShortHashMap(int initialCapacity, float loadFactor, TShortHashingStrategy strategy) { - super(initialCapacity, loadFactor, strategy); - } - - /** - * @return a deep clone of this collection - */ - public Object clone() { - TShortShortHashMap m = (TShortShortHashMap) super.clone(); - m._values = (short[]) this._values.clone(); - return m; - } - - /** - * @return a TShortShortIterator with access to this map's keys and values - */ - public TShortShortIterator iterator() { - return new TShortShortIterator(this); - } - - /** - * 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 = super.setUp(initialCapacity); - _values = new short[capacity]; - return capacity; - } - - /** - * 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 (short)0 if none was found. - */ - public short put(short key, short value) { - int index = insertionIndex(key); - return doPut(key, value, index); - } - - /** - * 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 (short)0 if none was found. - */ - public short putIfAbsent(short key, short value) { - int index = insertionIndex(key); - if (index < 0) - return _values[-index - 1]; - return doPut(key, value, index); - } - - private short doPut(short key, short value, int index) { - byte previousState; - short previous = (short) 0; - boolean isNewMapping = true; - if (index < 0) { - index = -index - 1; - previous = _values[index]; - isNewMapping = false; - } - previousState = _states[index]; - _set[index] = key; - _states[index] = FULL; - _values[index] = value; - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return previous; - } - - - /** - * 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(TShortShortHashMap map) { - map.forEachEntry(PUT_ALL_PROC); - } - - - /** - * rehashes the map to the new capacity. - * - * @param newCapacity an int value - */ - 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 = insertionIndex(o); - _set[index] = o; - _values[index] = oldVals[i]; - _states[index] = FULL; - } - } - } - - /** - * retrieves the value for key - * - * @param key an short value - * @return the value of key or (short)0 if no such mapping exists. - */ - public short get(short key) { - int index = index(key); - return index < 0 ? (short) 0 : _values[index]; - } - - /** - * Empties the map. - */ - public void clear() { - super.clear(); - short[] keys = _set; - short[] vals = _values; - byte[] states = _states; - - Arrays.fill(_set, 0, _set.length, (short) 0); - Arrays.fill(_values, 0, _values.length, (short) 0); - Arrays.fill(_states, 0, _states.length, FREE); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an short value - * @return an short value, or (short)0 if no mapping for key exists - */ - public short remove(short key) { - short prev = (short) 0; - int index = index(key); - if (index >= 0) { - prev = _values[index]; - removeAt(index); // clear key,state; adjust size - } - return prev; - } - - /** - * Compares this map with another map for equality of their stored - * entries. - * - * @param other an Object value - * @return a boolean value - */ - public boolean equals(Object other) { - if (!(other instanceof TShortShortHashMap)) { - return false; - } - TShortShortHashMap that = (TShortShortHashMap) other; - if (that.size() != this.size()) { - return false; - } - return forEachEntry(new EqProcedure(that)); - } - - public int hashCode() { - HashProcedure p = new HashProcedure(); - forEachEntry(p); - return p.getHashCode(); - } - - private final class HashProcedure implements TShortShortProcedure { - private int h = 0; - - public int getHashCode() { - return h; - } - - public final boolean execute(short key, short value) { - h += (_hashingStrategy.computeHashCode(key) ^ HashFunctions.hash(value)); - return true; - } - } - - private static final class EqProcedure implements TShortShortProcedure { - private final TShortShortHashMap _otherMap; - - EqProcedure(TShortShortHashMap otherMap) { - _otherMap = otherMap; - } - - public final boolean execute(short key, short value) { - int index = _otherMap.index(key); - if (index >= 0 && eq(value, _otherMap.get(key))) { - return true; - } - return false; - } - - /** - * Compare two shorts for equality. - */ - private final boolean eq(short v1, short v2) { - return v1 == v2; - } - - } - - /** - * removes the mapping at index from the map. - * - * @param index an int value - */ - protected void removeAt(int index) { - _values[index] = (short) 0; - super.removeAt(index); // clear key, state; adjust size - } - - /** - * Returns the values of the map. - * - * @return a Collection value - */ - public short[] getValues() { - short[] vals = new short[size()]; - 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; - } - - /** - * returns the keys of the map. - * - * @return a Set value - */ - 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; - } - - /** - * returns the keys of the map. - * - * @param a 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 a Set value - */ - public short[] keys(short[] a) { - int size = size(); - if (a.length < size) { - a = (short[]) java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - } - - short[] k = (short[]) _set; - byte[] states = _states; - - for (int i = k.length, j = 0; i-- > 0;) { - if (states[i] == FULL) { - a[j++] = k[i]; - } - } - return a; - } - - /** - * 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) { - byte[] states = _states; - short[] vals = _values; - - for (int i = vals.length; i-- > 0;) { - if (states[i] == FULL && val == vals[i]) { - return true; - } - } - return false; - } - - - /** - * 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 contains(key); - } - - /** - * 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) { - 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. - */ - 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; - } - - /** - * 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) { - 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; - } - - /** - * 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) { - 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; - } - - /** - * Transform the values in this map using function. - * - * @param function a TShortFunction value - */ - 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]); - } - } - } - - /** - * 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) { - return adjustValue(key, (short) 1); - } - - /** - * 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) { - int index = index(key); - if (index < 0) { - return false; - } else { - _values[index] += amount; - return true; - } - } - - /** - * 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 - * @since 2.0b1 - */ - public short adjustOrPutValue(final short key, final short adjust_amount, final short put_amount) { - int index = insertionIndex(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]; - _set[index] = key; - _states[index] = FULL; - - if (isNewMapping) { - postInsertHook(previousState == FREE); - } - - return newValue; - } - - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // NUMBER OF ENTRIES - out.writeInt(_size); - - // ENTRIES - SerializationProcedure writeProcedure = new SerializationProcedure(out); - if (!forEachEntry(writeProcedure)) { - throw writeProcedure.exception; - } - } - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // NUMBER OF ENTRIES - int size = in.readInt(); - setUp(size); - - // ENTRIES - while (size-- > 0) { - short key = in.readShort(); - short val = in.readShort(); - put(key, val); - } - } - - public String toString() { - final StringBuilder buf = new StringBuilder("{"); - forEachEntry(new TShortShortProcedure() { - private boolean first = true; - - 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(); - } -} // TShortShortHashMap diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortIterator.java deleted file mode 100644 index 8e1a2e77a77..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortIterator.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// 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());
- * }
- * 
- * - * @author Eric D. Friedman - * @version $Id: P2PIterator.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -public class TShortShortIterator extends TPrimitiveIterator { - /** - * the collection being iterated over - */ - private final TShortShortHashMap _map; - - /** - * Creates an iterator over the specified map - */ - public TShortShortIterator(TShortShortHashMap map) { - super(map); - this._map = map; - } - - /** - * Moves the iterator forward to the next entry in the underlying map. - * - * @throws java.util.NoSuchElementException - * if the iterator is already exhausted - */ - public void advance() { - moveToNextIndex(); - } - - /** - * 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() { - return _map._set[_index]; - } - - /** - * 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() { - return _map._values[_index]; - } - - /** - * 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) { - short old = value(); - _map._values[_index] = val; - return old; - } -}// TShortShortIterator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortProcedure.java deleted file mode 100644 index 2b59d0640ed..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortShortProcedure.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -////////////////////////////////////////////////// -// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // -////////////////////////////////////////////////// - - -/** - * Interface for procedures that take two parameters of type short and short. - *

- * Created: Mon Nov 5 22:03:30 2001 - * - * @author Eric D. Friedman - * @version $Id: P2PProcedure.template,v 1.1 2006/11/10 23:28:00 robeden Exp $ - */ - -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); -}// TShortShortProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortStack.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortStack.java deleted file mode 100644 index a73ec56db8b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/TShortStack.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -package org.elasticsearch.util.gnu.trove; - -/** - * A stack of short primitives, backed by a TShortArrayList. - * - * @author Eric D. Friedman, Rob Eden - * @version $Id: PStack.template,v 1.2 2007/02/28 23:03:57 robeden Exp $ - */ - -public class TShortStack { - - /** - * the list used to hold the stack values. - */ - protected TShortArrayList _list; - - public static final int DEFAULT_CAPACITY = TShortArrayList.DEFAULT_CAPACITY; - - /** - * Creates a new TShortStack instance with the default - * capacity. - */ - public TShortStack() { - this(DEFAULT_CAPACITY); - } - - /** - * Creates a new TShortStack instance with the - * specified capacity. - * - * @param capacity the initial depth of the stack - */ - public TShortStack(int capacity) { - _list = new TShortArrayList(capacity); - } - - /** - * Pushes the value onto the top of the stack. - * - * @param val an short value - */ - public void push(short val) { - _list.add(val); - } - - /** - * Removes and returns the value at the top of the stack. - * - * @return an short value - */ - public short pop() { - return _list.remove(_list.size() - 1); - } - - /** - * Returns the value at the top of the stack. - * - * @return an short value - */ - public short peek() { - return _list.get(_list.size() - 1); - } - - /** - * Returns the current depth of the stack. - */ - public int size() { - return _list.size(); - } - - /** - * Clears the stack, reseting its capacity to the default. - */ - public void clear() { - _list.clear(DEFAULT_CAPACITY); - } - - /** - * Clears the stack without releasing its internal capacity allocation. - */ - public void reset() { - _list.reset(); - } - - /** - * 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[] toNativeArray() { - return _list.toNativeArray(); - } - - /** - * 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 toNativeArray(short[] dest) { - _list.toNativeArray(dest, 0, size()); - } -} // TShortStack diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/ToObjectArrayProcedure.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/ToObjectArrayProcedure.java deleted file mode 100644 index 12f28b3c517..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/ToObjectArrayProcedure.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove; - -/** - * 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: ToObjectArrayProcedure.java,v 1.2 2006/11/10 23:27:57 robeden Exp $ - */ - -final class ToObjectArrayProcedure implements TObjectProcedure { - private final T[] target; - private int pos = 0; - - public ToObjectArrayProcedure(final T[] target) { - this.target = target; - } - - public final boolean execute(T value) { - target[pos++] = value; - return true; - } -} // ToObjectArrayProcedure diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteByteHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteByteHashMapDecorator.java deleted file mode 100644 index 2f505387fbf..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteByteHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TByteByteHashMap; -import org.elasticsearch.util.gnu.trove.TByteByteIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TByteByteHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TByteByteHashMap 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 Rob Eden - */ -public class TByteByteHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TByteByteHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TByteByteHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TByteByteHashMapDecorator(TByteByteHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TByteByteHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TByteByteHashMapDecorator clone() { - try { - TByteByteHashMapDecorator copy = (TByteByteHashMapDecorator) super.clone(); - copy._map = (TByteByteHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Byte put(Byte key, Byte value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Byte get(Byte key) { - byte k = unwrapKey(key); - byte v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Byte(0) if it was not found in the map - */ - public Byte remove(Byte key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TByteByteHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TByteByteHashMapDecorator.this.containsKey(k) - && TByteByteHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TByteByteIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Byte key = wrapKey(it.key()); - final Byte v = wrapValue(it.value()); - return new Map.Entry() { - private Byte val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Byte getKey() { - return key; - } - - public Byte getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Byte setValue(Byte value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Byte o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TByteByteHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TByteByteHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TByteByteHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteDoubleHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteDoubleHashMapDecorator.java deleted file mode 100644 index 7575ec1036d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteDoubleHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TByteDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TByteDoubleIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TByteDoubleHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TByteDoubleHashMap 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 Rob Eden - */ -public class TByteDoubleHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TByteDoubleHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TByteDoubleHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TByteDoubleHashMapDecorator(TByteDoubleHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TByteDoubleHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TByteDoubleHashMapDecorator clone() { - try { - TByteDoubleHashMapDecorator copy = (TByteDoubleHashMapDecorator) super.clone(); - copy._map = (TByteDoubleHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Double put(Byte key, Double value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Double get(Byte key) { - byte k = unwrapKey(key); - double v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Double(0) if it was not found in the map - */ - public Double remove(Byte key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TByteDoubleHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TByteDoubleHashMapDecorator.this.containsKey(k) - && TByteDoubleHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TByteDoubleIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Byte key = wrapKey(it.key()); - final Double v = wrapValue(it.value()); - return new Map.Entry() { - private Double val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Byte getKey() { - return key; - } - - public Double getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Double setValue(Double value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Double o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TByteDoubleHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TByteDoubleHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TByteDoubleHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteFloatHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteFloatHashMapDecorator.java deleted file mode 100644 index 0da46db28c5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteFloatHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TByteFloatHashMap; -import org.elasticsearch.util.gnu.trove.TByteFloatIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TByteFloatHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TByteFloatHashMap 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 Rob Eden - */ -public class TByteFloatHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TByteFloatHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TByteFloatHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TByteFloatHashMapDecorator(TByteFloatHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TByteFloatHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TByteFloatHashMapDecorator clone() { - try { - TByteFloatHashMapDecorator copy = (TByteFloatHashMapDecorator) super.clone(); - copy._map = (TByteFloatHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Float put(Byte key, Float value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Float get(Byte key) { - byte k = unwrapKey(key); - float v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Float(0) if it was not found in the map - */ - public Float remove(Byte key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TByteFloatHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TByteFloatHashMapDecorator.this.containsKey(k) - && TByteFloatHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TByteFloatIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Byte key = wrapKey(it.key()); - final Float v = wrapValue(it.value()); - return new Map.Entry() { - private Float val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Byte getKey() { - return key; - } - - public Float getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Float setValue(Float value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Float o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TByteFloatHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TByteFloatHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TByteFloatHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteHashSetDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteHashSetDecorator.java deleted file mode 100644 index 5306cb7d021..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteHashSetDecorator.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TByteHashSet; -import org.elasticsearch.util.gnu.trove.TByteIterator; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -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 TByteHashSet conform to the java.util.Set API. - * This class simply decorates an underlying TByteHashSet 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 - */ -public class TByteHashSetDecorator extends AbstractSet - implements Set, Externalizable { - - /** - * the wrapped primitive set - */ - protected TByteHashSet _set; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TByteHashSetDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive set. - */ - public TByteHashSetDecorator(TByteHashSet set) { - super(); - this._set = set; - } - - - /** - * Returns a reference to the set wrapped by this decorator. - */ - public TByteHashSet getSet() { - return _set; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TByteHashSetDecorator clone() { - try { - TByteHashSetDecorator copy = (TByteHashSetDecorator) super.clone(); - copy._set = (TByteHashSet) _set.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable - } - } - - /** - * Inserts a value into the set. - * - * @param value true if the set was modified by the insertion - */ - public boolean add(Byte value) { - return _set.add(unwrap(value)); - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return true if the sets are identical - */ - 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 = unwrap(val); - 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. - */ - public void clear() { - this._set.clear(); - } - - /** - * Deletes a value from the set. - * - * @param value an Object value - * @return true if the set was modified - */ - public boolean remove(Object value) { - return _set.remove(unwrap(value)); - } - - /** - * Creates an iterator over the values of the set. - * - * @return an iterator with support for removals in the underlying set - */ - public Iterator iterator() { - return new Iterator() { - private final TByteIterator it = _set.iterator(); - - public Byte next() { - return wrap(it.next()); - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - /** - * Returns the number of entries in the set. - * - * @return the set's size. - */ - public int size() { - return this._set.size(); - } - - /** - * Indicates whether set has any entries. - * - * @return true if the set is empty - */ - public boolean isEmpty() { - return size() == 0; - } - - /** - * Wraps a value - * - * @param k value in the underlying set - * @return an Object representation of the value - */ - protected Byte wrap(byte k) { - return Byte.valueOf(k); - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected byte unwrap(Object value) { - return ((Byte) value).byteValue(); - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // SET - _set = (TByteHashSet) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // SET - out.writeObject(_set); - } -} // TByteHashSetDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteIntHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteIntHashMapDecorator.java deleted file mode 100644 index 17197077caf..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteIntHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TByteIntHashMap; -import org.elasticsearch.util.gnu.trove.TByteIntIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TByteIntHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TByteIntHashMap 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 Rob Eden - */ -public class TByteIntHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TByteIntHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TByteIntHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TByteIntHashMapDecorator(TByteIntHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TByteIntHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TByteIntHashMapDecorator clone() { - try { - TByteIntHashMapDecorator copy = (TByteIntHashMapDecorator) super.clone(); - copy._map = (TByteIntHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Integer put(Byte key, Integer value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Integer get(Byte key) { - byte k = unwrapKey(key); - int v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Integer remove(Byte key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TByteIntHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TByteIntHashMapDecorator.this.containsKey(k) - && TByteIntHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TByteIntIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Byte key = wrapKey(it.key()); - final Integer v = wrapValue(it.value()); - return new Map.Entry() { - private Integer val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Byte getKey() { - return key; - } - - public Integer getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Integer setValue(Integer value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Integer o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TByteIntHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TByteIntHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TByteIntHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteLongHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteLongHashMapDecorator.java deleted file mode 100644 index 3dcf5c7d792..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteLongHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TByteLongHashMap; -import org.elasticsearch.util.gnu.trove.TByteLongIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TByteLongHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TByteLongHashMap 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 Rob Eden - */ -public class TByteLongHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TByteLongHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TByteLongHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TByteLongHashMapDecorator(TByteLongHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TByteLongHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TByteLongHashMapDecorator clone() { - try { - TByteLongHashMapDecorator copy = (TByteLongHashMapDecorator) super.clone(); - copy._map = (TByteLongHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Long put(Byte key, Long value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Long get(Byte key) { - byte k = unwrapKey(key); - long v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Long(0) if it was not found in the map - */ - public Long remove(Byte key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TByteLongHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TByteLongHashMapDecorator.this.containsKey(k) - && TByteLongHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TByteLongIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Byte key = wrapKey(it.key()); - final Long v = wrapValue(it.value()); - return new Map.Entry() { - private Long val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Byte getKey() { - return key; - } - - public Long getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Long setValue(Long value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Long o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TByteLongHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TByteLongHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TByteLongHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteObjectHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteObjectHashMapDecorator.java deleted file mode 100644 index 702887fd9dc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteObjectHashMapDecorator.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TByteObjectHashMap; -import org.elasticsearch.util.gnu.trove.TByteObjectIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TByteObjectHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TByteObjectHashMap 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 - */ -public class TByteObjectHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TByteObjectHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TByteObjectHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TByteObjectHashMapDecorator(TByteObjectHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TByteObjectHashMap getMap() { - return _map; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TByteObjectHashMapDecorator clone() { - try { - TByteObjectHashMapDecorator copy = (TByteObjectHashMapDecorator) super.clone(); - copy._map = (TByteObjectHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public V put(Byte key, V value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public V get(Object key) { - return _map.get(unwrapKey(key)); - } - - - /** - * Empties the map. - */ - 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 - */ - public V remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TByteObjectHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TByteObjectHashMapDecorator.this.containsKey(k) && - TByteObjectHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TByteObjectIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Byte key = wrapKey(it.key()); - final V v = wrapValue(it.value()); - return new Map.Entry() { - private V val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Byte getKey() { - return key; - } - - public V getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public V setValue(V value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Map.Entry o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TByteObjectHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _map.containsValue(unwrapValue((V) val)); - } - - /** - * Checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o value in the underlying map - * @return an Object representation of the value - */ - protected final V wrapValue(V o) { - return o; - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected final V unwrapValue(V value) { - return value; - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TByteObjectHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TByteObjectHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteShortHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteShortHashMapDecorator.java deleted file mode 100644 index c6c1847e849..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TByteShortHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TByteShortHashMap; -import org.elasticsearch.util.gnu.trove.TByteShortIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TByteShortHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TByteShortHashMap 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 Rob Eden - */ -public class TByteShortHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TByteShortHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TByteShortHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TByteShortHashMapDecorator(TByteShortHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TByteShortHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TByteShortHashMapDecorator clone() { - try { - TByteShortHashMapDecorator copy = (TByteShortHashMapDecorator) super.clone(); - copy._map = (TByteShortHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Short put(Byte key, Short value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Short get(Byte key) { - byte k = unwrapKey(key); - short v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Short(0) if it was not found in the map - */ - public Short remove(Byte key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TByteShortHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TByteShortHashMapDecorator.this.containsKey(k) - && TByteShortHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TByteShortIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Byte key = wrapKey(it.key()); - final Short v = wrapValue(it.value()); - return new Map.Entry() { - private Short val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Byte getKey() { - return key; - } - - public Short getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Short setValue(Short value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Short o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TByteShortHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TByteShortHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TByteShortHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleByteHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleByteHashMapDecorator.java deleted file mode 100644 index 6f896f953c2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleByteHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TDoubleByteHashMap; -import org.elasticsearch.util.gnu.trove.TDoubleByteIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TDoubleByteHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TDoubleByteHashMap 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 Rob Eden - */ -public class TDoubleByteHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TDoubleByteHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TDoubleByteHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TDoubleByteHashMapDecorator(TDoubleByteHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TDoubleByteHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TDoubleByteHashMapDecorator clone() { - try { - TDoubleByteHashMapDecorator copy = (TDoubleByteHashMapDecorator) super.clone(); - copy._map = (TDoubleByteHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Byte put(Double key, Byte value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Byte get(Double key) { - double k = unwrapKey(key); - byte v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Byte(0) if it was not found in the map - */ - public Byte remove(Double key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TDoubleByteHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TDoubleByteHashMapDecorator.this.containsKey(k) - && TDoubleByteHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TDoubleByteIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Double key = wrapKey(it.key()); - final Byte v = wrapValue(it.value()); - return new Map.Entry() { - private Byte val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Double getKey() { - return key; - } - - public Byte getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Byte setValue(Byte value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Byte o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TDoubleByteHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TDoubleByteHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TDoubleByteHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleDoubleHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleDoubleHashMapDecorator.java deleted file mode 100644 index 92d6ac56596..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleDoubleHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TDoubleDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TDoubleDoubleIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TDoubleDoubleHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TDoubleDoubleHashMap 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 Rob Eden - */ -public class TDoubleDoubleHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TDoubleDoubleHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TDoubleDoubleHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TDoubleDoubleHashMapDecorator(TDoubleDoubleHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TDoubleDoubleHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TDoubleDoubleHashMapDecorator clone() { - try { - TDoubleDoubleHashMapDecorator copy = (TDoubleDoubleHashMapDecorator) super.clone(); - copy._map = (TDoubleDoubleHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Double put(Double key, Double value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Double get(Double key) { - double k = unwrapKey(key); - double v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Double(0) if it was not found in the map - */ - public Double remove(Double key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TDoubleDoubleHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TDoubleDoubleHashMapDecorator.this.containsKey(k) - && TDoubleDoubleHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TDoubleDoubleIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Double key = wrapKey(it.key()); - final Double v = wrapValue(it.value()); - return new Map.Entry() { - private Double val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Double getKey() { - return key; - } - - public Double getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Double setValue(Double value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Double o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TDoubleDoubleHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TDoubleDoubleHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TDoubleDoubleHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleFloatHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleFloatHashMapDecorator.java deleted file mode 100644 index 66abb2ae499..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleFloatHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TDoubleFloatHashMap; -import org.elasticsearch.util.gnu.trove.TDoubleFloatIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TDoubleFloatHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TDoubleFloatHashMap 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 Rob Eden - */ -public class TDoubleFloatHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TDoubleFloatHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TDoubleFloatHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TDoubleFloatHashMapDecorator(TDoubleFloatHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TDoubleFloatHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TDoubleFloatHashMapDecorator clone() { - try { - TDoubleFloatHashMapDecorator copy = (TDoubleFloatHashMapDecorator) super.clone(); - copy._map = (TDoubleFloatHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Float put(Double key, Float value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Float get(Double key) { - double k = unwrapKey(key); - float v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Float(0) if it was not found in the map - */ - public Float remove(Double key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TDoubleFloatHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TDoubleFloatHashMapDecorator.this.containsKey(k) - && TDoubleFloatHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TDoubleFloatIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Double key = wrapKey(it.key()); - final Float v = wrapValue(it.value()); - return new Map.Entry() { - private Float val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Double getKey() { - return key; - } - - public Float getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Float setValue(Float value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Float o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TDoubleFloatHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TDoubleFloatHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TDoubleFloatHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleHashSetDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleHashSetDecorator.java deleted file mode 100644 index 291b43ea23f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleHashSetDecorator.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TDoubleHashSet; -import org.elasticsearch.util.gnu.trove.TDoubleIterator; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -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 TDoubleHashSet conform to the java.util.Set API. - * This class simply decorates an underlying TDoubleHashSet 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 - */ -public class TDoubleHashSetDecorator extends AbstractSet - implements Set, Externalizable { - - /** - * the wrapped primitive set - */ - protected TDoubleHashSet _set; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TDoubleHashSetDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive set. - */ - public TDoubleHashSetDecorator(TDoubleHashSet set) { - super(); - this._set = set; - } - - - /** - * Returns a reference to the set wrapped by this decorator. - */ - public TDoubleHashSet getSet() { - return _set; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TDoubleHashSetDecorator clone() { - try { - TDoubleHashSetDecorator copy = (TDoubleHashSetDecorator) super.clone(); - copy._set = (TDoubleHashSet) _set.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable - } - } - - /** - * Inserts a value into the set. - * - * @param value true if the set was modified by the insertion - */ - public boolean add(Double value) { - return _set.add(unwrap(value)); - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return true if the sets are identical - */ - 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 = unwrap(val); - 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. - */ - public void clear() { - this._set.clear(); - } - - /** - * Deletes a value from the set. - * - * @param value an Object value - * @return true if the set was modified - */ - public boolean remove(Object value) { - return _set.remove(unwrap(value)); - } - - /** - * Creates an iterator over the values of the set. - * - * @return an iterator with support for removals in the underlying set - */ - public Iterator iterator() { - return new Iterator() { - private final TDoubleIterator it = _set.iterator(); - - public Double next() { - return wrap(it.next()); - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - /** - * Returns the number of entries in the set. - * - * @return the set's size. - */ - public int size() { - return this._set.size(); - } - - /** - * Indicates whether set has any entries. - * - * @return true if the set is empty - */ - public boolean isEmpty() { - return size() == 0; - } - - /** - * Wraps a value - * - * @param k value in the underlying set - * @return an Object representation of the value - */ - protected Double wrap(double k) { - return Double.valueOf(k); - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected double unwrap(Object value) { - return ((Double) value).doubleValue(); - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // SET - _set = (TDoubleHashSet) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // SET - out.writeObject(_set); - } -} // TDoubleHashSetDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleIntHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleIntHashMapDecorator.java deleted file mode 100644 index 909b1d19493..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleIntHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TDoubleIntHashMap; -import org.elasticsearch.util.gnu.trove.TDoubleIntIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TDoubleIntHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TDoubleIntHashMap 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 Rob Eden - */ -public class TDoubleIntHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TDoubleIntHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TDoubleIntHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TDoubleIntHashMapDecorator(TDoubleIntHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TDoubleIntHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TDoubleIntHashMapDecorator clone() { - try { - TDoubleIntHashMapDecorator copy = (TDoubleIntHashMapDecorator) super.clone(); - copy._map = (TDoubleIntHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Integer put(Double key, Integer value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Integer get(Double key) { - double k = unwrapKey(key); - int v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Integer remove(Double key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TDoubleIntHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TDoubleIntHashMapDecorator.this.containsKey(k) - && TDoubleIntHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TDoubleIntIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Double key = wrapKey(it.key()); - final Integer v = wrapValue(it.value()); - return new Map.Entry() { - private Integer val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Double getKey() { - return key; - } - - public Integer getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Integer setValue(Integer value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Integer o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TDoubleIntHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TDoubleIntHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TDoubleIntHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleLongHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleLongHashMapDecorator.java deleted file mode 100644 index e482cecfc10..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleLongHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TDoubleLongHashMap; -import org.elasticsearch.util.gnu.trove.TDoubleLongIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TDoubleLongHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TDoubleLongHashMap 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 Rob Eden - */ -public class TDoubleLongHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TDoubleLongHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TDoubleLongHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TDoubleLongHashMapDecorator(TDoubleLongHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TDoubleLongHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TDoubleLongHashMapDecorator clone() { - try { - TDoubleLongHashMapDecorator copy = (TDoubleLongHashMapDecorator) super.clone(); - copy._map = (TDoubleLongHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Long put(Double key, Long value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Long get(Double key) { - double k = unwrapKey(key); - long v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Long(0) if it was not found in the map - */ - public Long remove(Double key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TDoubleLongHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TDoubleLongHashMapDecorator.this.containsKey(k) - && TDoubleLongHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TDoubleLongIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Double key = wrapKey(it.key()); - final Long v = wrapValue(it.value()); - return new Map.Entry() { - private Long val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Double getKey() { - return key; - } - - public Long getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Long setValue(Long value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Long o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TDoubleLongHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TDoubleLongHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TDoubleLongHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleObjectHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleObjectHashMapDecorator.java deleted file mode 100644 index c23707143f6..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleObjectHashMapDecorator.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TDoubleObjectHashMap; -import org.elasticsearch.util.gnu.trove.TDoubleObjectIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TDoubleObjectHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TDoubleObjectHashMap 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 - */ -public class TDoubleObjectHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TDoubleObjectHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TDoubleObjectHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TDoubleObjectHashMapDecorator(TDoubleObjectHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TDoubleObjectHashMap getMap() { - return _map; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TDoubleObjectHashMapDecorator clone() { - try { - TDoubleObjectHashMapDecorator copy = (TDoubleObjectHashMapDecorator) super.clone(); - copy._map = (TDoubleObjectHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public V put(Double key, V value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public V get(Object key) { - return _map.get(unwrapKey(key)); - } - - - /** - * Empties the map. - */ - 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 - */ - public V remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TDoubleObjectHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TDoubleObjectHashMapDecorator.this.containsKey(k) && - TDoubleObjectHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TDoubleObjectIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Double key = wrapKey(it.key()); - final V v = wrapValue(it.value()); - return new Map.Entry() { - private V val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Double getKey() { - return key; - } - - public V getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public V setValue(V value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Map.Entry o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TDoubleObjectHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _map.containsValue(unwrapValue((V) val)); - } - - /** - * Checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o value in the underlying map - * @return an Object representation of the value - */ - protected final V wrapValue(V o) { - return o; - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected final V unwrapValue(V value) { - return value; - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TDoubleObjectHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TDoubleObjectHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleShortHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleShortHashMapDecorator.java deleted file mode 100644 index 5d5f0dc4c4d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TDoubleShortHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TDoubleShortHashMap; -import org.elasticsearch.util.gnu.trove.TDoubleShortIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TDoubleShortHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TDoubleShortHashMap 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 Rob Eden - */ -public class TDoubleShortHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TDoubleShortHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TDoubleShortHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TDoubleShortHashMapDecorator(TDoubleShortHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TDoubleShortHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TDoubleShortHashMapDecorator clone() { - try { - TDoubleShortHashMapDecorator copy = (TDoubleShortHashMapDecorator) super.clone(); - copy._map = (TDoubleShortHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Short put(Double key, Short value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Short get(Double key) { - double k = unwrapKey(key); - short v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Short(0) if it was not found in the map - */ - public Short remove(Double key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TDoubleShortHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TDoubleShortHashMapDecorator.this.containsKey(k) - && TDoubleShortHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TDoubleShortIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Double key = wrapKey(it.key()); - final Short v = wrapValue(it.value()); - return new Map.Entry() { - private Short val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Double getKey() { - return key; - } - - public Short getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Short setValue(Short value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Short o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TDoubleShortHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TDoubleShortHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TDoubleShortHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatByteHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatByteHashMapDecorator.java deleted file mode 100644 index f13a4b5f7df..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatByteHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TFloatByteHashMap; -import org.elasticsearch.util.gnu.trove.TFloatByteIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TFloatByteHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TFloatByteHashMap 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 Rob Eden - */ -public class TFloatByteHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TFloatByteHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TFloatByteHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TFloatByteHashMapDecorator(TFloatByteHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TFloatByteHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TFloatByteHashMapDecorator clone() { - try { - TFloatByteHashMapDecorator copy = (TFloatByteHashMapDecorator) super.clone(); - copy._map = (TFloatByteHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Byte put(Float key, Byte value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Byte get(Float key) { - float k = unwrapKey(key); - byte v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Byte(0) if it was not found in the map - */ - public Byte remove(Float key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TFloatByteHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TFloatByteHashMapDecorator.this.containsKey(k) - && TFloatByteHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TFloatByteIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Float key = wrapKey(it.key()); - final Byte v = wrapValue(it.value()); - return new Map.Entry() { - private Byte val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Float getKey() { - return key; - } - - public Byte getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Byte setValue(Byte value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Byte o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TFloatByteHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TFloatByteHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TFloatByteHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatDoubleHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatDoubleHashMapDecorator.java deleted file mode 100644 index f07ca079e62..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatDoubleHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TFloatDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TFloatDoubleIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TFloatDoubleHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TFloatDoubleHashMap 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 Rob Eden - */ -public class TFloatDoubleHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TFloatDoubleHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TFloatDoubleHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TFloatDoubleHashMapDecorator(TFloatDoubleHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TFloatDoubleHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TFloatDoubleHashMapDecorator clone() { - try { - TFloatDoubleHashMapDecorator copy = (TFloatDoubleHashMapDecorator) super.clone(); - copy._map = (TFloatDoubleHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Double put(Float key, Double value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Double get(Float key) { - float k = unwrapKey(key); - double v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Double(0) if it was not found in the map - */ - public Double remove(Float key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TFloatDoubleHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TFloatDoubleHashMapDecorator.this.containsKey(k) - && TFloatDoubleHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TFloatDoubleIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Float key = wrapKey(it.key()); - final Double v = wrapValue(it.value()); - return new Map.Entry() { - private Double val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Float getKey() { - return key; - } - - public Double getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Double setValue(Double value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Double o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TFloatDoubleHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TFloatDoubleHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TFloatDoubleHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatFloatHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatFloatHashMapDecorator.java deleted file mode 100644 index 7a45c7f634e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatFloatHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TFloatFloatHashMap; -import org.elasticsearch.util.gnu.trove.TFloatFloatIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TFloatFloatHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TFloatFloatHashMap 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 Rob Eden - */ -public class TFloatFloatHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TFloatFloatHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TFloatFloatHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TFloatFloatHashMapDecorator(TFloatFloatHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TFloatFloatHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TFloatFloatHashMapDecorator clone() { - try { - TFloatFloatHashMapDecorator copy = (TFloatFloatHashMapDecorator) super.clone(); - copy._map = (TFloatFloatHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Float put(Float key, Float value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Float get(Float key) { - float k = unwrapKey(key); - float v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Float(0) if it was not found in the map - */ - public Float remove(Float key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TFloatFloatHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TFloatFloatHashMapDecorator.this.containsKey(k) - && TFloatFloatHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TFloatFloatIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Float key = wrapKey(it.key()); - final Float v = wrapValue(it.value()); - return new Map.Entry() { - private Float val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Float getKey() { - return key; - } - - public Float getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Float setValue(Float value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Float o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TFloatFloatHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TFloatFloatHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TFloatFloatHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatHashSetDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatHashSetDecorator.java deleted file mode 100644 index 3764f1028dc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatHashSetDecorator.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TFloatHashSet; -import org.elasticsearch.util.gnu.trove.TFloatIterator; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -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 TFloatHashSet conform to the java.util.Set API. - * This class simply decorates an underlying TFloatHashSet 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 - */ -public class TFloatHashSetDecorator extends AbstractSet - implements Set, Externalizable { - - /** - * the wrapped primitive set - */ - protected TFloatHashSet _set; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TFloatHashSetDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive set. - */ - public TFloatHashSetDecorator(TFloatHashSet set) { - super(); - this._set = set; - } - - - /** - * Returns a reference to the set wrapped by this decorator. - */ - public TFloatHashSet getSet() { - return _set; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TFloatHashSetDecorator clone() { - try { - TFloatHashSetDecorator copy = (TFloatHashSetDecorator) super.clone(); - copy._set = (TFloatHashSet) _set.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable - } - } - - /** - * Inserts a value into the set. - * - * @param value true if the set was modified by the insertion - */ - public boolean add(Float value) { - return _set.add(unwrap(value)); - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return true if the sets are identical - */ - 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 = unwrap(val); - 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. - */ - public void clear() { - this._set.clear(); - } - - /** - * Deletes a value from the set. - * - * @param value an Object value - * @return true if the set was modified - */ - public boolean remove(Object value) { - return _set.remove(unwrap(value)); - } - - /** - * Creates an iterator over the values of the set. - * - * @return an iterator with support for removals in the underlying set - */ - public Iterator iterator() { - return new Iterator() { - private final TFloatIterator it = _set.iterator(); - - public Float next() { - return wrap(it.next()); - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - /** - * Returns the number of entries in the set. - * - * @return the set's size. - */ - public int size() { - return this._set.size(); - } - - /** - * Indicates whether set has any entries. - * - * @return true if the set is empty - */ - public boolean isEmpty() { - return size() == 0; - } - - /** - * Wraps a value - * - * @param k value in the underlying set - * @return an Object representation of the value - */ - protected Float wrap(float k) { - return Float.valueOf(k); - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected float unwrap(Object value) { - return ((Float) value).floatValue(); - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // SET - _set = (TFloatHashSet) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // SET - out.writeObject(_set); - } -} // TFloatHashSetDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatIntHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatIntHashMapDecorator.java deleted file mode 100644 index 368006fcd22..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatIntHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TFloatIntHashMap; -import org.elasticsearch.util.gnu.trove.TFloatIntIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TFloatIntHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TFloatIntHashMap 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 Rob Eden - */ -public class TFloatIntHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TFloatIntHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TFloatIntHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TFloatIntHashMapDecorator(TFloatIntHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TFloatIntHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TFloatIntHashMapDecorator clone() { - try { - TFloatIntHashMapDecorator copy = (TFloatIntHashMapDecorator) super.clone(); - copy._map = (TFloatIntHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Integer put(Float key, Integer value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Integer get(Float key) { - float k = unwrapKey(key); - int v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Integer remove(Float key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TFloatIntHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TFloatIntHashMapDecorator.this.containsKey(k) - && TFloatIntHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TFloatIntIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Float key = wrapKey(it.key()); - final Integer v = wrapValue(it.value()); - return new Map.Entry() { - private Integer val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Float getKey() { - return key; - } - - public Integer getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Integer setValue(Integer value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Integer o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TFloatIntHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TFloatIntHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TFloatIntHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatLongHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatLongHashMapDecorator.java deleted file mode 100644 index b0bb89849aa..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatLongHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TFloatLongHashMap; -import org.elasticsearch.util.gnu.trove.TFloatLongIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TFloatLongHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TFloatLongHashMap 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 Rob Eden - */ -public class TFloatLongHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TFloatLongHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TFloatLongHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TFloatLongHashMapDecorator(TFloatLongHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TFloatLongHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TFloatLongHashMapDecorator clone() { - try { - TFloatLongHashMapDecorator copy = (TFloatLongHashMapDecorator) super.clone(); - copy._map = (TFloatLongHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Long put(Float key, Long value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Long get(Float key) { - float k = unwrapKey(key); - long v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Long(0) if it was not found in the map - */ - public Long remove(Float key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TFloatLongHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TFloatLongHashMapDecorator.this.containsKey(k) - && TFloatLongHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TFloatLongIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Float key = wrapKey(it.key()); - final Long v = wrapValue(it.value()); - return new Map.Entry() { - private Long val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Float getKey() { - return key; - } - - public Long getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Long setValue(Long value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Long o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TFloatLongHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TFloatLongHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TFloatLongHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatObjectHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatObjectHashMapDecorator.java deleted file mode 100644 index 7060a831dfd..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatObjectHashMapDecorator.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TFloatObjectHashMap; -import org.elasticsearch.util.gnu.trove.TFloatObjectIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TFloatObjectHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TFloatObjectHashMap 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 - */ -public class TFloatObjectHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TFloatObjectHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TFloatObjectHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TFloatObjectHashMapDecorator(TFloatObjectHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TFloatObjectHashMap getMap() { - return _map; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TFloatObjectHashMapDecorator clone() { - try { - TFloatObjectHashMapDecorator copy = (TFloatObjectHashMapDecorator) super.clone(); - copy._map = (TFloatObjectHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public V put(Float key, V value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public V get(Object key) { - return _map.get(unwrapKey(key)); - } - - - /** - * Empties the map. - */ - 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 - */ - public V remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TFloatObjectHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TFloatObjectHashMapDecorator.this.containsKey(k) && - TFloatObjectHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TFloatObjectIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Float key = wrapKey(it.key()); - final V v = wrapValue(it.value()); - return new Map.Entry() { - private V val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Float getKey() { - return key; - } - - public V getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public V setValue(V value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Map.Entry o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TFloatObjectHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _map.containsValue(unwrapValue((V) val)); - } - - /** - * Checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o value in the underlying map - * @return an Object representation of the value - */ - protected final V wrapValue(V o) { - return o; - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected final V unwrapValue(V value) { - return value; - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TFloatObjectHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TFloatObjectHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatShortHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatShortHashMapDecorator.java deleted file mode 100644 index 0dc76e4c61b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TFloatShortHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TFloatShortHashMap; -import org.elasticsearch.util.gnu.trove.TFloatShortIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TFloatShortHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TFloatShortHashMap 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 Rob Eden - */ -public class TFloatShortHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TFloatShortHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TFloatShortHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TFloatShortHashMapDecorator(TFloatShortHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TFloatShortHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TFloatShortHashMapDecorator clone() { - try { - TFloatShortHashMapDecorator copy = (TFloatShortHashMapDecorator) super.clone(); - copy._map = (TFloatShortHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Short put(Float key, Short value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Short get(Float key) { - float k = unwrapKey(key); - short v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Short(0) if it was not found in the map - */ - public Short remove(Float key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TFloatShortHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TFloatShortHashMapDecorator.this.containsKey(k) - && TFloatShortHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TFloatShortIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Float key = wrapKey(it.key()); - final Short v = wrapValue(it.value()); - return new Map.Entry() { - private Short val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Float getKey() { - return key; - } - - public Short getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Short setValue(Short value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Short o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TFloatShortHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TFloatShortHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TFloatShortHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntByteHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntByteHashMapDecorator.java deleted file mode 100644 index d39303aefe9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntByteHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TIntByteHashMap; -import org.elasticsearch.util.gnu.trove.TIntByteIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TIntByteHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TIntByteHashMap 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 Rob Eden - */ -public class TIntByteHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TIntByteHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TIntByteHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TIntByteHashMapDecorator(TIntByteHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TIntByteHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TIntByteHashMapDecorator clone() { - try { - TIntByteHashMapDecorator copy = (TIntByteHashMapDecorator) super.clone(); - copy._map = (TIntByteHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Byte put(Integer key, Byte value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Byte get(Integer key) { - int k = unwrapKey(key); - byte v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Byte(0) if it was not found in the map - */ - public Byte remove(Integer key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TIntByteHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TIntByteHashMapDecorator.this.containsKey(k) - && TIntByteHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TIntByteIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Integer key = wrapKey(it.key()); - final Byte v = wrapValue(it.value()); - return new Map.Entry() { - private Byte val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Integer getKey() { - return key; - } - - public Byte getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Byte setValue(Byte value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Byte o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TIntByteHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TIntByteHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TIntByteHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntDoubleHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntDoubleHashMapDecorator.java deleted file mode 100644 index 528cdeda43c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntDoubleHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TIntDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TIntDoubleIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TIntDoubleHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TIntDoubleHashMap 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 Rob Eden - */ -public class TIntDoubleHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TIntDoubleHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TIntDoubleHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TIntDoubleHashMapDecorator(TIntDoubleHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TIntDoubleHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TIntDoubleHashMapDecorator clone() { - try { - TIntDoubleHashMapDecorator copy = (TIntDoubleHashMapDecorator) super.clone(); - copy._map = (TIntDoubleHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Double put(Integer key, Double value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Double get(Integer key) { - int k = unwrapKey(key); - double v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Double(0) if it was not found in the map - */ - public Double remove(Integer key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TIntDoubleHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TIntDoubleHashMapDecorator.this.containsKey(k) - && TIntDoubleHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TIntDoubleIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Integer key = wrapKey(it.key()); - final Double v = wrapValue(it.value()); - return new Map.Entry() { - private Double val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Integer getKey() { - return key; - } - - public Double getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Double setValue(Double value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Double o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TIntDoubleHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TIntDoubleHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TIntDoubleHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntFloatHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntFloatHashMapDecorator.java deleted file mode 100644 index e88b03c04d7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntFloatHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TIntFloatHashMap; -import org.elasticsearch.util.gnu.trove.TIntFloatIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TIntFloatHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TIntFloatHashMap 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 Rob Eden - */ -public class TIntFloatHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TIntFloatHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TIntFloatHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TIntFloatHashMapDecorator(TIntFloatHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TIntFloatHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TIntFloatHashMapDecorator clone() { - try { - TIntFloatHashMapDecorator copy = (TIntFloatHashMapDecorator) super.clone(); - copy._map = (TIntFloatHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Float put(Integer key, Float value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Float get(Integer key) { - int k = unwrapKey(key); - float v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Float(0) if it was not found in the map - */ - public Float remove(Integer key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TIntFloatHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TIntFloatHashMapDecorator.this.containsKey(k) - && TIntFloatHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TIntFloatIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Integer key = wrapKey(it.key()); - final Float v = wrapValue(it.value()); - return new Map.Entry() { - private Float val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Integer getKey() { - return key; - } - - public Float getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Float setValue(Float value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Float o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TIntFloatHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TIntFloatHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TIntFloatHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntHashSetDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntHashSetDecorator.java deleted file mode 100644 index 9c9b1b3e552..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntHashSetDecorator.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TIntHashSet; -import org.elasticsearch.util.gnu.trove.TIntIterator; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -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 TIntHashSet conform to the java.util.Set API. - * This class simply decorates an underlying TIntHashSet 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 - */ -public class TIntHashSetDecorator extends AbstractSet - implements Set, Externalizable { - - /** - * the wrapped primitive set - */ - protected TIntHashSet _set; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TIntHashSetDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive set. - */ - public TIntHashSetDecorator(TIntHashSet set) { - super(); - this._set = set; - } - - - /** - * Returns a reference to the set wrapped by this decorator. - */ - public TIntHashSet getSet() { - return _set; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TIntHashSetDecorator clone() { - try { - TIntHashSetDecorator copy = (TIntHashSetDecorator) super.clone(); - copy._set = (TIntHashSet) _set.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable - } - } - - /** - * Inserts a value into the set. - * - * @param value true if the set was modified by the insertion - */ - public boolean add(Integer value) { - return _set.add(unwrap(value)); - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return true if the sets are identical - */ - 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 = unwrap(val); - 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. - */ - public void clear() { - this._set.clear(); - } - - /** - * Deletes a value from the set. - * - * @param value an Object value - * @return true if the set was modified - */ - public boolean remove(Object value) { - return _set.remove(unwrap(value)); - } - - /** - * Creates an iterator over the values of the set. - * - * @return an iterator with support for removals in the underlying set - */ - public Iterator iterator() { - return new Iterator() { - private final TIntIterator it = _set.iterator(); - - public Integer next() { - return wrap(it.next()); - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - /** - * Returns the number of entries in the set. - * - * @return the set's size. - */ - public int size() { - return this._set.size(); - } - - /** - * Indicates whether set has any entries. - * - * @return true if the set is empty - */ - public boolean isEmpty() { - return size() == 0; - } - - /** - * Wraps a value - * - * @param k value in the underlying set - * @return an Object representation of the value - */ - protected Integer wrap(int k) { - return Integer.valueOf(k); - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected int unwrap(Object value) { - return ((Integer) value).intValue(); - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // SET - _set = (TIntHashSet) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // SET - out.writeObject(_set); - } -} // TIntHashSetDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntIntHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntIntHashMapDecorator.java deleted file mode 100644 index 40e8602d40b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntIntHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TIntIntHashMap; -import org.elasticsearch.util.gnu.trove.TIntIntIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TIntIntHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TIntIntHashMap 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 Rob Eden - */ -public class TIntIntHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TIntIntHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TIntIntHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TIntIntHashMapDecorator(TIntIntHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TIntIntHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TIntIntHashMapDecorator clone() { - try { - TIntIntHashMapDecorator copy = (TIntIntHashMapDecorator) super.clone(); - copy._map = (TIntIntHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Integer put(Integer key, Integer value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Integer get(Integer key) { - int k = unwrapKey(key); - int v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Integer remove(Integer key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TIntIntHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TIntIntHashMapDecorator.this.containsKey(k) - && TIntIntHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TIntIntIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Integer key = wrapKey(it.key()); - final Integer v = wrapValue(it.value()); - return new Map.Entry() { - private Integer val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Integer getKey() { - return key; - } - - public Integer getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Integer setValue(Integer value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Integer o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TIntIntHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TIntIntHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TIntIntHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntLongHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntLongHashMapDecorator.java deleted file mode 100644 index 3df8cb41f06..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntLongHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TIntLongHashMap; -import org.elasticsearch.util.gnu.trove.TIntLongIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TIntLongHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TIntLongHashMap 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 Rob Eden - */ -public class TIntLongHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TIntLongHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TIntLongHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TIntLongHashMapDecorator(TIntLongHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TIntLongHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TIntLongHashMapDecorator clone() { - try { - TIntLongHashMapDecorator copy = (TIntLongHashMapDecorator) super.clone(); - copy._map = (TIntLongHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Long put(Integer key, Long value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Long get(Integer key) { - int k = unwrapKey(key); - long v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Long(0) if it was not found in the map - */ - public Long remove(Integer key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TIntLongHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TIntLongHashMapDecorator.this.containsKey(k) - && TIntLongHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TIntLongIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Integer key = wrapKey(it.key()); - final Long v = wrapValue(it.value()); - return new Map.Entry() { - private Long val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Integer getKey() { - return key; - } - - public Long getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Long setValue(Long value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Long o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TIntLongHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TIntLongHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TIntLongHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntObjectHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntObjectHashMapDecorator.java deleted file mode 100644 index f8d13acd898..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntObjectHashMapDecorator.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TIntObjectHashMap; -import org.elasticsearch.util.gnu.trove.TIntObjectIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TIntObjectHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TIntObjectHashMap 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 - */ -public class TIntObjectHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TIntObjectHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TIntObjectHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TIntObjectHashMapDecorator(TIntObjectHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TIntObjectHashMap getMap() { - return _map; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TIntObjectHashMapDecorator clone() { - try { - TIntObjectHashMapDecorator copy = (TIntObjectHashMapDecorator) super.clone(); - copy._map = (TIntObjectHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public V put(Integer key, V value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public V get(Object key) { - return _map.get(unwrapKey(key)); - } - - - /** - * Empties the map. - */ - 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 - */ - public V remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TIntObjectHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TIntObjectHashMapDecorator.this.containsKey(k) && - TIntObjectHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TIntObjectIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Integer key = wrapKey(it.key()); - final V v = wrapValue(it.value()); - return new Map.Entry() { - private V val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Integer getKey() { - return key; - } - - public V getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public V setValue(V value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Map.Entry o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TIntObjectHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _map.containsValue(unwrapValue((V) val)); - } - - /** - * Checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o value in the underlying map - * @return an Object representation of the value - */ - protected final V wrapValue(V o) { - return o; - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected final V unwrapValue(V value) { - return value; - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TIntObjectHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TIntObjectHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntShortHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntShortHashMapDecorator.java deleted file mode 100644 index 726e7ab82e2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TIntShortHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TIntShortHashMap; -import org.elasticsearch.util.gnu.trove.TIntShortIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TIntShortHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TIntShortHashMap 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 Rob Eden - */ -public class TIntShortHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TIntShortHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TIntShortHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TIntShortHashMapDecorator(TIntShortHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TIntShortHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TIntShortHashMapDecorator clone() { - try { - TIntShortHashMapDecorator copy = (TIntShortHashMapDecorator) super.clone(); - copy._map = (TIntShortHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Short put(Integer key, Short value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Short get(Integer key) { - int k = unwrapKey(key); - short v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Short(0) if it was not found in the map - */ - public Short remove(Integer key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TIntShortHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TIntShortHashMapDecorator.this.containsKey(k) - && TIntShortHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TIntShortIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Integer key = wrapKey(it.key()); - final Short v = wrapValue(it.value()); - return new Map.Entry() { - private Short val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Integer getKey() { - return key; - } - - public Short getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Short setValue(Short value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Short o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TIntShortHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TIntShortHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TIntShortHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongByteHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongByteHashMapDecorator.java deleted file mode 100644 index dee248eb2ab..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongByteHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TLongByteHashMap; -import org.elasticsearch.util.gnu.trove.TLongByteIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TLongByteHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TLongByteHashMap 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 Rob Eden - */ -public class TLongByteHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TLongByteHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TLongByteHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TLongByteHashMapDecorator(TLongByteHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TLongByteHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TLongByteHashMapDecorator clone() { - try { - TLongByteHashMapDecorator copy = (TLongByteHashMapDecorator) super.clone(); - copy._map = (TLongByteHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Byte put(Long key, Byte value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Byte get(Long key) { - long k = unwrapKey(key); - byte v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Byte(0) if it was not found in the map - */ - public Byte remove(Long key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TLongByteHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TLongByteHashMapDecorator.this.containsKey(k) - && TLongByteHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TLongByteIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Long key = wrapKey(it.key()); - final Byte v = wrapValue(it.value()); - return new Map.Entry() { - private Byte val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Long getKey() { - return key; - } - - public Byte getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Byte setValue(Byte value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Byte o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TLongByteHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TLongByteHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TLongByteHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongDoubleHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongDoubleHashMapDecorator.java deleted file mode 100644 index f0b13f5fa81..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongDoubleHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TLongDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TLongDoubleIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TLongDoubleHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TLongDoubleHashMap 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 Rob Eden - */ -public class TLongDoubleHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TLongDoubleHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TLongDoubleHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TLongDoubleHashMapDecorator(TLongDoubleHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TLongDoubleHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TLongDoubleHashMapDecorator clone() { - try { - TLongDoubleHashMapDecorator copy = (TLongDoubleHashMapDecorator) super.clone(); - copy._map = (TLongDoubleHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Double put(Long key, Double value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Double get(Long key) { - long k = unwrapKey(key); - double v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Double(0) if it was not found in the map - */ - public Double remove(Long key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TLongDoubleHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TLongDoubleHashMapDecorator.this.containsKey(k) - && TLongDoubleHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TLongDoubleIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Long key = wrapKey(it.key()); - final Double v = wrapValue(it.value()); - return new Map.Entry() { - private Double val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Long getKey() { - return key; - } - - public Double getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Double setValue(Double value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Double o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TLongDoubleHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TLongDoubleHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TLongDoubleHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongFloatHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongFloatHashMapDecorator.java deleted file mode 100644 index 922d5549e2b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongFloatHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TLongFloatHashMap; -import org.elasticsearch.util.gnu.trove.TLongFloatIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TLongFloatHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TLongFloatHashMap 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 Rob Eden - */ -public class TLongFloatHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TLongFloatHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TLongFloatHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TLongFloatHashMapDecorator(TLongFloatHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TLongFloatHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TLongFloatHashMapDecorator clone() { - try { - TLongFloatHashMapDecorator copy = (TLongFloatHashMapDecorator) super.clone(); - copy._map = (TLongFloatHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Float put(Long key, Float value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Float get(Long key) { - long k = unwrapKey(key); - float v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Float(0) if it was not found in the map - */ - public Float remove(Long key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TLongFloatHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TLongFloatHashMapDecorator.this.containsKey(k) - && TLongFloatHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TLongFloatIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Long key = wrapKey(it.key()); - final Float v = wrapValue(it.value()); - return new Map.Entry() { - private Float val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Long getKey() { - return key; - } - - public Float getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Float setValue(Float value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Float o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TLongFloatHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TLongFloatHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TLongFloatHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongHashSetDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongHashSetDecorator.java deleted file mode 100644 index 27b8aea889a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongHashSetDecorator.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TLongHashSet; -import org.elasticsearch.util.gnu.trove.TLongIterator; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -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 TLongHashSet conform to the java.util.Set API. - * This class simply decorates an underlying TLongHashSet 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 - */ -public class TLongHashSetDecorator extends AbstractSet - implements Set, Externalizable { - - /** - * the wrapped primitive set - */ - protected TLongHashSet _set; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TLongHashSetDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive set. - */ - public TLongHashSetDecorator(TLongHashSet set) { - super(); - this._set = set; - } - - - /** - * Returns a reference to the set wrapped by this decorator. - */ - public TLongHashSet getSet() { - return _set; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TLongHashSetDecorator clone() { - try { - TLongHashSetDecorator copy = (TLongHashSetDecorator) super.clone(); - copy._set = (TLongHashSet) _set.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable - } - } - - /** - * Inserts a value into the set. - * - * @param value true if the set was modified by the insertion - */ - public boolean add(Long value) { - return _set.add(unwrap(value)); - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return true if the sets are identical - */ - 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 = unwrap(val); - 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. - */ - public void clear() { - this._set.clear(); - } - - /** - * Deletes a value from the set. - * - * @param value an Object value - * @return true if the set was modified - */ - public boolean remove(Object value) { - return _set.remove(unwrap(value)); - } - - /** - * Creates an iterator over the values of the set. - * - * @return an iterator with support for removals in the underlying set - */ - public Iterator iterator() { - return new Iterator() { - private final TLongIterator it = _set.iterator(); - - public Long next() { - return wrap(it.next()); - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - /** - * Returns the number of entries in the set. - * - * @return the set's size. - */ - public int size() { - return this._set.size(); - } - - /** - * Indicates whether set has any entries. - * - * @return true if the set is empty - */ - public boolean isEmpty() { - return size() == 0; - } - - /** - * Wraps a value - * - * @param k value in the underlying set - * @return an Object representation of the value - */ - protected Long wrap(long k) { - return Long.valueOf(k); - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected long unwrap(Object value) { - return ((Long) value).longValue(); - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // SET - _set = (TLongHashSet) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // SET - out.writeObject(_set); - } -} // TLongHashSetDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongIntHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongIntHashMapDecorator.java deleted file mode 100644 index 714970b870a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongIntHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TLongIntHashMap; -import org.elasticsearch.util.gnu.trove.TLongIntIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TLongIntHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TLongIntHashMap 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 Rob Eden - */ -public class TLongIntHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TLongIntHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TLongIntHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TLongIntHashMapDecorator(TLongIntHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TLongIntHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TLongIntHashMapDecorator clone() { - try { - TLongIntHashMapDecorator copy = (TLongIntHashMapDecorator) super.clone(); - copy._map = (TLongIntHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Integer put(Long key, Integer value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Integer get(Long key) { - long k = unwrapKey(key); - int v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Integer remove(Long key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TLongIntHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TLongIntHashMapDecorator.this.containsKey(k) - && TLongIntHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TLongIntIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Long key = wrapKey(it.key()); - final Integer v = wrapValue(it.value()); - return new Map.Entry() { - private Integer val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Long getKey() { - return key; - } - - public Integer getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Integer setValue(Integer value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Integer o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TLongIntHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TLongIntHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TLongIntHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongLongHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongLongHashMapDecorator.java deleted file mode 100644 index fb98fcdd854..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongLongHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TLongLongHashMap; -import org.elasticsearch.util.gnu.trove.TLongLongIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TLongLongHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TLongLongHashMap 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 Rob Eden - */ -public class TLongLongHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TLongLongHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TLongLongHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TLongLongHashMapDecorator(TLongLongHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TLongLongHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TLongLongHashMapDecorator clone() { - try { - TLongLongHashMapDecorator copy = (TLongLongHashMapDecorator) super.clone(); - copy._map = (TLongLongHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Long put(Long key, Long value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Long get(Long key) { - long k = unwrapKey(key); - long v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Long(0) if it was not found in the map - */ - public Long remove(Long key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TLongLongHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TLongLongHashMapDecorator.this.containsKey(k) - && TLongLongHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TLongLongIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Long key = wrapKey(it.key()); - final Long v = wrapValue(it.value()); - return new Map.Entry() { - private Long val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Long getKey() { - return key; - } - - public Long getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Long setValue(Long value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Long o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TLongLongHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TLongLongHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TLongLongHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongObjectHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongObjectHashMapDecorator.java deleted file mode 100644 index 6cf00022843..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongObjectHashMapDecorator.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TLongObjectHashMap; -import org.elasticsearch.util.gnu.trove.TLongObjectIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TLongObjectHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TLongObjectHashMap 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 - */ -public class TLongObjectHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TLongObjectHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TLongObjectHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TLongObjectHashMapDecorator(TLongObjectHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TLongObjectHashMap getMap() { - return _map; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TLongObjectHashMapDecorator clone() { - try { - TLongObjectHashMapDecorator copy = (TLongObjectHashMapDecorator) super.clone(); - copy._map = (TLongObjectHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public V put(Long key, V value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public V get(Object key) { - return _map.get(unwrapKey(key)); - } - - - /** - * Empties the map. - */ - 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 - */ - public V remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TLongObjectHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TLongObjectHashMapDecorator.this.containsKey(k) && - TLongObjectHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TLongObjectIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Long key = wrapKey(it.key()); - final V v = wrapValue(it.value()); - return new Map.Entry() { - private V val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Long getKey() { - return key; - } - - public V getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public V setValue(V value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Map.Entry o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TLongObjectHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _map.containsValue(unwrapValue((V) val)); - } - - /** - * Checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o value in the underlying map - * @return an Object representation of the value - */ - protected final V wrapValue(V o) { - return o; - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected final V unwrapValue(V value) { - return value; - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TLongObjectHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TLongObjectHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongShortHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongShortHashMapDecorator.java deleted file mode 100644 index 7e3bc28b7b7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TLongShortHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TLongShortHashMap; -import org.elasticsearch.util.gnu.trove.TLongShortIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TLongShortHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TLongShortHashMap 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 Rob Eden - */ -public class TLongShortHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TLongShortHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TLongShortHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TLongShortHashMapDecorator(TLongShortHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TLongShortHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TLongShortHashMapDecorator clone() { - try { - TLongShortHashMapDecorator copy = (TLongShortHashMapDecorator) super.clone(); - copy._map = (TLongShortHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Short put(Long key, Short value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Short get(Long key) { - long k = unwrapKey(key); - short v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Short(0) if it was not found in the map - */ - public Short remove(Long key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TLongShortHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TLongShortHashMapDecorator.this.containsKey(k) - && TLongShortHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TLongShortIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Long key = wrapKey(it.key()); - final Short v = wrapValue(it.value()); - return new Map.Entry() { - private Short val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Long getKey() { - return key; - } - - public Short getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Short setValue(Short value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Short o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TLongShortHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TLongShortHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TLongShortHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectByteHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectByteHashMapDecorator.java deleted file mode 100644 index c3ad7fbf3d9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectByteHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TObjectByteHashMap; -import org.elasticsearch.util.gnu.trove.TObjectByteIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TObjectByteHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TObjectByteHashMap 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 - */ -public class TObjectByteHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TObjectByteHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TObjectByteHashMapDecorator() { - } - - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TObjectByteHashMapDecorator(TObjectByteHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TObjectByteHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TObjectByteHashMapDecorator clone() { - try { - TObjectByteHashMapDecorator copy = (TObjectByteHashMapDecorator) super.clone(); - copy._map = (TObjectByteHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Byte put(V key, Byte value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Byte get(Object key) { - V k = unwrapKey(key); - byte v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Byte remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TObjectByteHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TObjectByteHashMapDecorator.this.containsKey(k) && - TObjectByteHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TObjectByteIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final V key = wrapKey(it.key()); - final Byte v = wrapValue(it.value()); - return new Map.Entry() { - private Byte val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry && - ((Map.Entry) o).getKey().equals(key) && - ((Map.Entry) o).getValue().equals(val); - } - - public V getKey() { - return key; - } - - public Byte getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Byte setValue(Byte value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Byte o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TObjectByteHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o key in the underlying map - * @return an Object representation of the key - */ - protected final V wrapKey(Object o) { - return (V) o; - } - - /** - * Unwraps a key - * - * @param key wrapped key - * @return an unwrapped representation of the key - */ - protected final V unwrapKey(Object key) { - return (V) key; - } - - /** - * 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TObjectByteHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TObjectByteHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectDoubleHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectDoubleHashMapDecorator.java deleted file mode 100644 index 93cd1352054..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectDoubleHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TObjectDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TObjectDoubleIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TObjectDoubleHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TObjectDoubleHashMap 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 - */ -public class TObjectDoubleHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TObjectDoubleHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TObjectDoubleHashMapDecorator() { - } - - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TObjectDoubleHashMapDecorator(TObjectDoubleHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TObjectDoubleHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TObjectDoubleHashMapDecorator clone() { - try { - TObjectDoubleHashMapDecorator copy = (TObjectDoubleHashMapDecorator) super.clone(); - copy._map = (TObjectDoubleHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Double put(V key, Double value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Double get(Object key) { - V k = unwrapKey(key); - double v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Double remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TObjectDoubleHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TObjectDoubleHashMapDecorator.this.containsKey(k) && - TObjectDoubleHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TObjectDoubleIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final V key = wrapKey(it.key()); - final Double v = wrapValue(it.value()); - return new Map.Entry() { - private Double val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry && - ((Map.Entry) o).getKey().equals(key) && - ((Map.Entry) o).getValue().equals(val); - } - - public V getKey() { - return key; - } - - public Double getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Double setValue(Double value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Double o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TObjectDoubleHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o key in the underlying map - * @return an Object representation of the key - */ - protected final V wrapKey(Object o) { - return (V) o; - } - - /** - * Unwraps a key - * - * @param key wrapped key - * @return an unwrapped representation of the key - */ - protected final V unwrapKey(Object key) { - return (V) key; - } - - /** - * 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TObjectDoubleHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TObjectDoubleHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectFloatHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectFloatHashMapDecorator.java deleted file mode 100644 index a0fe440c4d0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectFloatHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TObjectFloatHashMap; -import org.elasticsearch.util.gnu.trove.TObjectFloatIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TObjectFloatHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TObjectFloatHashMap 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 - */ -public class TObjectFloatHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TObjectFloatHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TObjectFloatHashMapDecorator() { - } - - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TObjectFloatHashMapDecorator(TObjectFloatHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TObjectFloatHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TObjectFloatHashMapDecorator clone() { - try { - TObjectFloatHashMapDecorator copy = (TObjectFloatHashMapDecorator) super.clone(); - copy._map = (TObjectFloatHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Float put(V key, Float value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Float get(Object key) { - V k = unwrapKey(key); - float v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Float remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TObjectFloatHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TObjectFloatHashMapDecorator.this.containsKey(k) && - TObjectFloatHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TObjectFloatIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final V key = wrapKey(it.key()); - final Float v = wrapValue(it.value()); - return new Map.Entry() { - private Float val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry && - ((Map.Entry) o).getKey().equals(key) && - ((Map.Entry) o).getValue().equals(val); - } - - public V getKey() { - return key; - } - - public Float getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Float setValue(Float value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Float o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TObjectFloatHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o key in the underlying map - * @return an Object representation of the key - */ - protected final V wrapKey(Object o) { - return (V) o; - } - - /** - * Unwraps a key - * - * @param key wrapped key - * @return an unwrapped representation of the key - */ - protected final V unwrapKey(Object key) { - return (V) key; - } - - /** - * 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TObjectFloatHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TObjectFloatHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectIntHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectIntHashMapDecorator.java deleted file mode 100644 index 03ceb8bbcc7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectIntHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TObjectIntHashMap; -import org.elasticsearch.util.gnu.trove.TObjectIntIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TObjectIntHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TObjectIntHashMap 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 - */ -public class TObjectIntHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TObjectIntHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TObjectIntHashMapDecorator() { - } - - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TObjectIntHashMapDecorator(TObjectIntHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TObjectIntHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TObjectIntHashMapDecorator clone() { - try { - TObjectIntHashMapDecorator copy = (TObjectIntHashMapDecorator) super.clone(); - copy._map = (TObjectIntHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Integer put(V key, Integer value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Integer get(Object key) { - V k = unwrapKey(key); - int v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Integer remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TObjectIntHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TObjectIntHashMapDecorator.this.containsKey(k) && - TObjectIntHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TObjectIntIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final V key = wrapKey(it.key()); - final Integer v = wrapValue(it.value()); - return new Map.Entry() { - private Integer val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry && - ((Map.Entry) o).getKey().equals(key) && - ((Map.Entry) o).getValue().equals(val); - } - - public V getKey() { - return key; - } - - public Integer getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Integer setValue(Integer value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Integer o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TObjectIntHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o key in the underlying map - * @return an Object representation of the key - */ - protected final V wrapKey(Object o) { - return (V) o; - } - - /** - * Unwraps a key - * - * @param key wrapped key - * @return an unwrapped representation of the key - */ - protected final V unwrapKey(Object key) { - return (V) key; - } - - /** - * 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TObjectIntHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TObjectIntHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectLongHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectLongHashMapDecorator.java deleted file mode 100644 index d8fa772994d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectLongHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TObjectLongHashMap; -import org.elasticsearch.util.gnu.trove.TObjectLongIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TObjectLongHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TObjectLongHashMap 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 - */ -public class TObjectLongHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TObjectLongHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TObjectLongHashMapDecorator() { - } - - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TObjectLongHashMapDecorator(TObjectLongHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TObjectLongHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TObjectLongHashMapDecorator clone() { - try { - TObjectLongHashMapDecorator copy = (TObjectLongHashMapDecorator) super.clone(); - copy._map = (TObjectLongHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Long put(V key, Long value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Long get(Object key) { - V k = unwrapKey(key); - long v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Long remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TObjectLongHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TObjectLongHashMapDecorator.this.containsKey(k) && - TObjectLongHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TObjectLongIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final V key = wrapKey(it.key()); - final Long v = wrapValue(it.value()); - return new Map.Entry() { - private Long val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry && - ((Map.Entry) o).getKey().equals(key) && - ((Map.Entry) o).getValue().equals(val); - } - - public V getKey() { - return key; - } - - public Long getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Long setValue(Long value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Long o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TObjectLongHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o key in the underlying map - * @return an Object representation of the key - */ - protected final V wrapKey(Object o) { - return (V) o; - } - - /** - * Unwraps a key - * - * @param key wrapped key - * @return an unwrapped representation of the key - */ - protected final V unwrapKey(Object key) { - return (V) key; - } - - /** - * 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TObjectLongHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TObjectLongHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectShortHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectShortHashMapDecorator.java deleted file mode 100644 index 63b4c09029a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TObjectShortHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TObjectShortHashMap; -import org.elasticsearch.util.gnu.trove.TObjectShortIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TObjectShortHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TObjectShortHashMap 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 - */ -public class TObjectShortHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TObjectShortHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TObjectShortHashMapDecorator() { - } - - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TObjectShortHashMapDecorator(TObjectShortHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TObjectShortHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TObjectShortHashMapDecorator clone() { - try { - TObjectShortHashMapDecorator copy = (TObjectShortHashMapDecorator) super.clone(); - copy._map = (TObjectShortHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Short put(V key, Short value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Short get(Object key) { - V k = unwrapKey(key); - short v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Short remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TObjectShortHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TObjectShortHashMapDecorator.this.containsKey(k) && - TObjectShortHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TObjectShortIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final V key = wrapKey(it.key()); - final Short v = wrapValue(it.value()); - return new Map.Entry() { - private Short val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry && - ((Map.Entry) o).getKey().equals(key) && - ((Map.Entry) o).getValue().equals(val); - } - - public V getKey() { - return key; - } - - public Short getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Short setValue(Short value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Short o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TObjectShortHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o key in the underlying map - * @return an Object representation of the key - */ - protected final V wrapKey(Object o) { - return (V) o; - } - - /** - * Unwraps a key - * - * @param key wrapped key - * @return an unwrapped representation of the key - */ - protected final V unwrapKey(Object key) { - return (V) key; - } - - /** - * 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TObjectShortHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TObjectShortHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortByteHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortByteHashMapDecorator.java deleted file mode 100644 index c8eed2c1600..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortByteHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TShortByteHashMap; -import org.elasticsearch.util.gnu.trove.TShortByteIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TShortByteHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TShortByteHashMap 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 Rob Eden - */ -public class TShortByteHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TShortByteHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TShortByteHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TShortByteHashMapDecorator(TShortByteHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TShortByteHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TShortByteHashMapDecorator clone() { - try { - TShortByteHashMapDecorator copy = (TShortByteHashMapDecorator) super.clone(); - copy._map = (TShortByteHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Byte put(Short key, Byte value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Byte get(Short key) { - short k = unwrapKey(key); - byte v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Byte(0) if it was not found in the map - */ - public Byte remove(Short key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TShortByteHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TShortByteHashMapDecorator.this.containsKey(k) - && TShortByteHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TShortByteIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Short key = wrapKey(it.key()); - final Byte v = wrapValue(it.value()); - return new Map.Entry() { - private Byte val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Short getKey() { - return key; - } - - public Byte getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Byte setValue(Byte value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Byte o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TShortByteHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TShortByteHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TShortByteHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortDoubleHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortDoubleHashMapDecorator.java deleted file mode 100644 index 612dab08918..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortDoubleHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TShortDoubleHashMap; -import org.elasticsearch.util.gnu.trove.TShortDoubleIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TShortDoubleHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TShortDoubleHashMap 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 Rob Eden - */ -public class TShortDoubleHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TShortDoubleHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TShortDoubleHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TShortDoubleHashMapDecorator(TShortDoubleHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TShortDoubleHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TShortDoubleHashMapDecorator clone() { - try { - TShortDoubleHashMapDecorator copy = (TShortDoubleHashMapDecorator) super.clone(); - copy._map = (TShortDoubleHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Double put(Short key, Double value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Double get(Short key) { - short k = unwrapKey(key); - double v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Double(0) if it was not found in the map - */ - public Double remove(Short key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TShortDoubleHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TShortDoubleHashMapDecorator.this.containsKey(k) - && TShortDoubleHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TShortDoubleIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Short key = wrapKey(it.key()); - final Double v = wrapValue(it.value()); - return new Map.Entry() { - private Double val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Short getKey() { - return key; - } - - public Double getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Double setValue(Double value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Double o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TShortDoubleHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TShortDoubleHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TShortDoubleHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortFloatHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortFloatHashMapDecorator.java deleted file mode 100644 index eb636fa4900..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortFloatHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TShortFloatHashMap; -import org.elasticsearch.util.gnu.trove.TShortFloatIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TShortFloatHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TShortFloatHashMap 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 Rob Eden - */ -public class TShortFloatHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TShortFloatHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TShortFloatHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TShortFloatHashMapDecorator(TShortFloatHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TShortFloatHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TShortFloatHashMapDecorator clone() { - try { - TShortFloatHashMapDecorator copy = (TShortFloatHashMapDecorator) super.clone(); - copy._map = (TShortFloatHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Float put(Short key, Float value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Float get(Short key) { - short k = unwrapKey(key); - float v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Float(0) if it was not found in the map - */ - public Float remove(Short key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TShortFloatHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TShortFloatHashMapDecorator.this.containsKey(k) - && TShortFloatHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TShortFloatIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Short key = wrapKey(it.key()); - final Float v = wrapValue(it.value()); - return new Map.Entry() { - private Float val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Short getKey() { - return key; - } - - public Float getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Float setValue(Float value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Float o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TShortFloatHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TShortFloatHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TShortFloatHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortHashSetDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortHashSetDecorator.java deleted file mode 100644 index 267c1ee26f6..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortHashSetDecorator.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TShortHashSet; -import org.elasticsearch.util.gnu.trove.TShortIterator; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -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 TShortHashSet conform to the java.util.Set API. - * This class simply decorates an underlying TShortHashSet 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 - */ -public class TShortHashSetDecorator extends AbstractSet - implements Set, Externalizable { - - /** - * the wrapped primitive set - */ - protected TShortHashSet _set; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TShortHashSetDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive set. - */ - public TShortHashSetDecorator(TShortHashSet set) { - super(); - this._set = set; - } - - - /** - * Returns a reference to the set wrapped by this decorator. - */ - public TShortHashSet getSet() { - return _set; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TShortHashSetDecorator clone() { - try { - TShortHashSetDecorator copy = (TShortHashSetDecorator) super.clone(); - copy._set = (TShortHashSet) _set.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable - } - } - - /** - * Inserts a value into the set. - * - * @param value true if the set was modified by the insertion - */ - public boolean add(Short value) { - return _set.add(unwrap(value)); - } - - /** - * Compares this set with another set for equality of their stored - * entries. - * - * @param other an Object value - * @return true if the sets are identical - */ - 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 = unwrap(val); - 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. - */ - public void clear() { - this._set.clear(); - } - - /** - * Deletes a value from the set. - * - * @param value an Object value - * @return true if the set was modified - */ - public boolean remove(Object value) { - return _set.remove(unwrap(value)); - } - - /** - * Creates an iterator over the values of the set. - * - * @return an iterator with support for removals in the underlying set - */ - public Iterator iterator() { - return new Iterator() { - private final TShortIterator it = _set.iterator(); - - public Short next() { - return wrap(it.next()); - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - /** - * Returns the number of entries in the set. - * - * @return the set's size. - */ - public int size() { - return this._set.size(); - } - - /** - * Indicates whether set has any entries. - * - * @return true if the set is empty - */ - public boolean isEmpty() { - return size() == 0; - } - - /** - * Wraps a value - * - * @param k value in the underlying set - * @return an Object representation of the value - */ - protected Short wrap(short k) { - return Short.valueOf(k); - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected short unwrap(Object value) { - return ((Short) value).shortValue(); - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // SET - _set = (TShortHashSet) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // SET - out.writeObject(_set); - } -} // TShortHashSetDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortIntHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortIntHashMapDecorator.java deleted file mode 100644 index 66e9bd1c477..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortIntHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TShortIntHashMap; -import org.elasticsearch.util.gnu.trove.TShortIntIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TShortIntHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TShortIntHashMap 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 Rob Eden - */ -public class TShortIntHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TShortIntHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TShortIntHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TShortIntHashMapDecorator(TShortIntHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TShortIntHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TShortIntHashMapDecorator clone() { - try { - TShortIntHashMapDecorator copy = (TShortIntHashMapDecorator) super.clone(); - copy._map = (TShortIntHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Integer put(Short key, Integer value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Integer get(Short key) { - short k = unwrapKey(key); - int v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - 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 - */ - public Integer remove(Short key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TShortIntHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TShortIntHashMapDecorator.this.containsKey(k) - && TShortIntHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TShortIntIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Short key = wrapKey(it.key()); - final Integer v = wrapValue(it.value()); - return new Map.Entry() { - private Integer val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Short getKey() { - return key; - } - - public Integer getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Integer setValue(Integer value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Integer o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TShortIntHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TShortIntHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TShortIntHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortLongHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortLongHashMapDecorator.java deleted file mode 100644 index eaec110af35..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortLongHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TShortLongHashMap; -import org.elasticsearch.util.gnu.trove.TShortLongIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TShortLongHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TShortLongHashMap 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 Rob Eden - */ -public class TShortLongHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TShortLongHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TShortLongHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TShortLongHashMapDecorator(TShortLongHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TShortLongHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TShortLongHashMapDecorator clone() { - try { - TShortLongHashMapDecorator copy = (TShortLongHashMapDecorator) super.clone(); - copy._map = (TShortLongHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Long put(Short key, Long value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Long get(Short key) { - short k = unwrapKey(key); - long v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Long(0) if it was not found in the map - */ - public Long remove(Short key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TShortLongHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TShortLongHashMapDecorator.this.containsKey(k) - && TShortLongHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TShortLongIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Short key = wrapKey(it.key()); - final Long v = wrapValue(it.value()); - return new Map.Entry() { - private Long val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Short getKey() { - return key; - } - - public Long getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Long setValue(Long value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Long o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TShortLongHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TShortLongHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TShortLongHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortObjectHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortObjectHashMapDecorator.java deleted file mode 100644 index 9ae384cdc25..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortObjectHashMapDecorator.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TShortObjectHashMap; -import org.elasticsearch.util.gnu.trove.TShortObjectIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TShortObjectHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TShortObjectHashMap 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 - */ -public class TShortObjectHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TShortObjectHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TShortObjectHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TShortObjectHashMapDecorator(TShortObjectHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TShortObjectHashMap getMap() { - return _map; - } - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TShortObjectHashMapDecorator clone() { - try { - TShortObjectHashMapDecorator copy = (TShortObjectHashMapDecorator) super.clone(); - copy._map = (TShortObjectHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public V put(Short key, V value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public V get(Object key) { - return _map.get(unwrapKey(key)); - } - - - /** - * Empties the map. - */ - 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 - */ - public V remove(Object key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TShortObjectHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TShortObjectHashMapDecorator.this.containsKey(k) && - TShortObjectHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TShortObjectIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Short key = wrapKey(it.key()); - final V v = wrapValue(it.value()); - return new Map.Entry() { - private V val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Short getKey() { - return key; - } - - public V getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public V setValue(V value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Map.Entry o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TShortObjectHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _map.containsValue(unwrapValue((V) val)); - } - - /** - * Checks for the present of key in the keys of the map. - * - * @param key an Object value - * @return a boolean value - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 o value in the underlying map - * @return an Object representation of the value - */ - protected final V wrapValue(V o) { - return o; - } - - /** - * Unwraps a value - * - * @param value wrapped value - * @return an unwrapped representation of the value - */ - protected final V unwrapValue(V value) { - return value; - } - - - // Implements Externalizable - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TShortObjectHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TShortObjectHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortShortHashMapDecorator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortShortHashMapDecorator.java deleted file mode 100644 index 2bb7e12d348..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/TShortShortHashMapDecorator.java +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Licensed to Elastic Search and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. Elastic Search licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.util.gnu.trove.decorator; - -import org.elasticsearch.util.gnu.trove.TShortShortHashMap; -import org.elasticsearch.util.gnu.trove.TShortShortIterator; - -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! // -////////////////////////////////////////////////// - - -/** - * Wrapper class to make a TShortShortHashMap conform to the java.util.Map API. - * This class simply decorates an underlying TShortShortHashMap 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 Rob Eden - */ -public class TShortShortHashMapDecorator extends AbstractMap - implements Map, Externalizable, Cloneable { - - /** - * the wrapped primitive map - */ - protected TShortShortHashMap _map; - - - /** - * FOR EXTERNALIZATION ONLY!! - */ - public TShortShortHashMapDecorator() { - } - - /** - * Creates a wrapper that decorates the specified primitive map. - */ - public TShortShortHashMapDecorator(TShortShortHashMap map) { - super(); - this._map = map; - } - - - /** - * Returns a reference to the map wrapped by this decorator. - */ - public TShortShortHashMap getMap() { - return _map; - } - - - /** - * Clones the underlying trove collection and returns the clone wrapped in a new - * decorator instance. This is a shallow clone except where primitives are - * concerned. - * - * @return a copy of the receiver - */ - public TShortShortHashMapDecorator clone() { - try { - TShortShortHashMapDecorator copy = (TShortShortHashMapDecorator) super.clone(); - copy._map = (TShortShortHashMap) _map.clone(); - return copy; - } catch (CloneNotSupportedException e) { - // assert(false); - throw new InternalError(); // we are cloneable, so this does not happen - } - } - - /** - * 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. - */ - public Short put(Short key, Short value) { - return wrapValue(_map.put(unwrapKey(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. - */ - public Short get(Short key) { - short k = unwrapKey(key); - short v = _map.get(k); - // 0 may be a false positive since primitive maps - // cannot return null, so we have to do an extra - // check here. - if (v == 0) { - return _map.containsKey(k) ? wrapValue(v) : null; - } else { - return wrapValue(v); - } - } - - - /** - * Empties the map. - */ - public void clear() { - this._map.clear(); - } - - /** - * Deletes a key/value pair from the map. - * - * @param key an Object value - * @return the removed value, or Short(0) if it was not found in the map - */ - public Short remove(Short key) { - return wrapValue(_map.remove(unwrapKey(key))); - } - - /** - * Returns a Set view on the entries of the map. - * - * @return a Set value - */ - public Set> entrySet() { - return new AbstractSet>() { - public int size() { - return _map.size(); - } - - public boolean isEmpty() { - return TShortShortHashMapDecorator.this.isEmpty(); - } - - public boolean contains(Object o) { - if (o instanceof Map.Entry) { - Object k = ((Map.Entry) o).getKey(); - Object v = ((Map.Entry) o).getValue(); - return TShortShortHashMapDecorator.this.containsKey(k) - && TShortShortHashMapDecorator.this.get(k).equals(v); - } else { - return false; - } - } - - public Iterator> iterator() { - return new Iterator>() { - private final TShortShortIterator it = _map.iterator(); - - public Map.Entry next() { - it.advance(); - final Short key = wrapKey(it.key()); - final Short v = wrapValue(it.value()); - return new Map.Entry() { - private Short val = v; - - public boolean equals(Object o) { - return o instanceof Map.Entry - && ((Map.Entry) o).getKey().equals(key) - && ((Map.Entry) o).getValue().equals(val); - } - - public Short getKey() { - return key; - } - - public Short getValue() { - return val; - } - - public int hashCode() { - return key.hashCode() + val.hashCode(); - } - - public Short setValue(Short value) { - val = value; - return put(key, value); - } - }; - } - - public boolean hasNext() { - return it.hasNext(); - } - - public void remove() { - it.remove(); - } - }; - } - - public boolean add(Short o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection> c) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(); - } - - public void clear() { - TShortShortHashMapDecorator.this.clear(); - } - }; - } - - /** - * Checks for the presence of val in the values of the map. - * - * @param val an Object value - * @return a boolean value - */ - public boolean containsValue(Object val) { - return _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 - */ - public boolean containsKey(Object key) { - return _map.containsKey(unwrapKey(key)); - } - - /** - * Returns the number of entries in the map. - * - * @return the map's size. - */ - public int size() { - return this._map.size(); - } - - /** - * Indicates whether map has any entries. - * - * @return true if the map is empty - */ - 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 - */ - 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 - - public void readExternal(ObjectInput in) - throws IOException, ClassNotFoundException { - - // VERSION - in.readByte(); - - // MAP - _map = (TShortShortHashMap) in.readObject(); - } - - - // Implements Externalizable - - public void writeExternal(ObjectOutput out) throws IOException { - // VERSION - out.writeByte(0); - - // MAP - out.writeObject(_map); - } - -} // TShortShortHashMapDecorator diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/package.html b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/package.html deleted file mode 100644 index 2b9296cfdf0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/decorator/package.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - GNU Trove API Documentation - - - -

GNU Trove: Decorators for java.util.{Map,Set} compatability

- -

The classes in this package serve to wrap the Trove primitive - collections so that they can be used in operations that require a - java.util.Map or java.util.Set.

- -

This is form of adaptation is extremely inefficient and - so should only be undertaken as a last resort or when you don't - care about performance (in which case Trove is probably not - appropriate anyway).

- -

The general pattern here is that you "wrap" a Trove collection - with the appropriate decorator object to obtain a java.util.Map or - Set. The implementations do not retain references to the Objects - they accept/return (all calls are delegated to the underlying - trove collection), so you should not rely on object identity - within those collections.

- -

You may extend the decorator classes to use canonical values if - your dataset permits. For some applications, this will help - reduce the cost of (un)wrapping primitive values. Note, however, - that such datasets are probably small/restricted enough that you - should again ask yourself whether Trove is appropriate in the - first place. Caveat programmer. - - -Last modified: Mon Sep 23 22:55:32 PDT 2002 - - - diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/package.html b/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/package.html deleted file mode 100644 index 258186920a5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/gnu/trove/package.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - GNU Trove API Documentation - - - -

Taken AS IS to use in Elastic Search under Trove License, version 2.1.0

- -

GNU Trove: High performance collections for Java.

- -

Objectives

- -

The GNU Trove library has two objectives: -

    - -
  1. Provide "free" (as in "free speech" - and "free beer"), fast, lightweight - implementations of the java.util Collections API. - These implementations are designed to be pluggable - replacements for their JDK equivalents. -
  2. - -
  3. Whenever possible, provide the same collections support - for primitive types. This gap in the JDK is - often addressed by using the "wrapper" classes - (java.lang.Integer, java.lang.Float, etc.) - with Object-based collections. For most applications, - however, collections which store primitives directly will - require less space and yield significant performance gains. -
-

- -

Hashtable techniques

- -

The Trove maps/sets use open addressing instead of the chaining - approach taken by the JDK hashtables. This eliminates the need - to create Map.Entry wrappper objects for every item in a - table and so reduces the O (big-oh) in the performance of - the hashtable algorithm. The size of the tables used in Trove's maps/sets is - always a prime number, improving the probability of an optimal distribution - of entries across the table, and so reducing the the likelihood - of performance-degrading collisions. Trove sets are not - backed by maps, and so using a THashSet does not result in - the allocation of an unused "values" array. -

- -

Hashing strategies

- -

Trove's maps/sets support the use of custom hashing - strategies, allowing you to tune collections based on - characteristics of the input data. This feature also allows you - to define hash functions when it is not feasible to override - Object.hashCode(). For example, the java.lang.String class is - final, and its implementation of hashCode() takes O(n) - time to complete. In some applications, however, it may be - possible for a custom hashing function to save time by skipping - portions of the string that are invariant.

- -

Using java.util.HashMap, it is not possible to use Java - language arrays as keys. For example, this code: -

-    char[] foo, bar;
-    foo = new char[] {'a','b','c'};
-    bar = new char[] {'a','b','c'};
-    System.out.println(foo.hashCode() == bar.hashCode() ? "equal" : "not equal");
-    System.out.println(foo.equals(bar) ? "equal" : "not equal");
-    
- -produces this output: - -
-    not equal
-    not equal
-    
- -And so an entry stored in a java.util.HashMap with foo as a -key could not be retrieved with bar, since there is no way -to override hashCode() or equals() on language array objects. -

- -

In a gnu.trove.THashMap, however, you can implement a TObjectHashingStrategy - to enable hashing on arrays: - -

-    class CharArrayStrategy implements TObjectHashingStrategy {
-        public int computeHashCode(Object o) {
-            char[] c = (char[])o;
-            // use the shift-add-xor class of string hashing functions
-            // cf. Ramakrishna and Zobel, "Performance in Practice of String Hashing Functions"
-            int h = 31; // seed chosen at random
-            for (int i = 0; i < c.length; i++) { // could skip invariants
-                h = h ^ ((h << 5) + (h >> 2) + c[i]); // L=5, R=2 works well for ASCII input
-            }
-            return h;
-        }
-
-        public boolean equals(Object o1, Object o2) {
-            char[] c1 = (char[])o1;
-            char[] c2 = (char[])o2;
-            if (c1.length != c2.length) { // could drop this check for fixed-length keys
-                return false;
-            }
-            for (int i = 0, len = c1.length; i < len; i++) { // could skip invariants
-                if (c1[i] != c2[i]) {
-                    return false;
-                }
-            }
-            return true;
-        }
-    }
-    
-

- -

Iterators in primitive collections

- -

As of release 0.1.7, Trove's primitive mappings include access through Iterators - as well as procedures and functions. The API documentation on those classes - contains several examples showing how these can be used effectively and - explaining why their semantics differ from those of java.util.Iterator.

- -

Miscellaneous

- -

N.B. using Map.entrySet on a Trove Map is supported, but - not encouraged. The reason is that this API requires the creation of - the Map.Entry Objects that all other parts of Trove manage to avoid. - An alternative is to implement the appropriate Procedure - interface and use it to invoke the Map's forEachEntry - API. Map.keySet and Map.values are not - similarly encumbered; nevertheless, the forEachKey, - forEachValue, and transformValues APIs will yield - slightly better performance at the cost of compatibility with the - interface of java.util.Map.

- -
- - -Last modified: Mon Sep 23 18:22:39 PDT 2002 - - - diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncCompletionHandler.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncCompletionHandler.java deleted file mode 100644 index 59c90c19294..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncCompletionHandler.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -/** - * An {@link AsyncHandler} augmented with an {@link #onCompleted(Response)} convenience method which gets called - * when the {@link Response} has been fully received. - * - * @param Type of the value that will be returned by the associated {@link java.util.concurrent.Future} - */ -public abstract class AsyncCompletionHandler implements AsyncHandler { - - private final static ESLogger log = Loggers.getLogger(AsyncCompletionHandlerBase.class); - - private final Collection> bodies = - Collections.synchronizedCollection(new ArrayList>()); - private HttpResponseStatus status; - private HttpResponseHeaders headers; - - /** - * {@inheritDoc} - */ - /* @Override */ - public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { - bodies.add(content); - return STATE.CONTINUE; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public final STATE onStatusReceived(final HttpResponseStatus status) throws Exception { - this.status = status; - return STATE.CONTINUE; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public final STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception { - this.headers = headers; - return STATE.CONTINUE; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public final T onCompleted() throws Exception { - return onCompleted(status == null ? null : status.provider().prepareResponse(status, headers, bodies)); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public void onThrowable(Throwable t) { - if (log.isDebugEnabled()) - log.debug(t.getMessage(), t); - } - - /** - * Invoked once the HTTP response has been fully read. - * - * @param response The {@link Response} - * @return Type of the value that will be returned by the associated {@link java.util.concurrent.Future} - */ - abstract public T onCompleted(Response response) throws Exception; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncCompletionHandlerBase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncCompletionHandlerBase.java deleted file mode 100644 index 40adc0b1abd..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncCompletionHandlerBase.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; - -/** - * Simple {@link AsyncHandler} of type {@link Response} - */ -public class AsyncCompletionHandlerBase extends AsyncCompletionHandler { - - private final static ESLogger log = Loggers.getLogger(AsyncCompletionHandlerBase.class); - - @Override - public Response onCompleted(Response response) throws Exception { - return response; - } - - /* @Override */ - - public void onThrowable(Throwable t) { - if (log.isDebugEnabled()) { - log.debug(t.getMessage(), t); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHandler.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHandler.java deleted file mode 100644 index 0534a7b42ec..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client; - -/** - * An asynchronous handler or callback which gets invoked as soon as some data are available when - * processing an asynchronous response. Callbacks method gets invoked in the following order: - * (1) {@link #onStatusReceived(HttpResponseStatus)} - * (2) {@link #onHeadersReceived(HttpResponseHeaders)} - * (3) {@link #onBodyPartReceived(HttpResponseBodyPart)}, which could be invoked multiple times - * (4) {@link #onCompleted()}, once the response has been fully read. - * - * Interrupting the process of the asynchronous response can be achieved by - * returning a {@link AsyncHandler.STATE#ABORT} at any moment during the - * processing of the asynchronous response. - * - * @param Type of object returned by the {@link java.util.concurrent.Future#get} - */ -public interface AsyncHandler { - - public static enum STATE { - ABORT, CONTINUE - } - - /** - * Invoked when an unexpected exception occurs during the processing of the response - * - * @param t a {@link Throwable} - */ - void onThrowable(Throwable t); - - /** - * Invoked as soon as some response body part are received. - * - * @param bodyPart response's body part. - * @throws Exception - */ - STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception; - - /** - * Invoked as soon as the HTTP status line has been received - * - * @param responseStatus the status code and test of the response - * @throws Exception - */ - STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception; - - /** - * Invoked as soon as the HTTP headers has been received. - * - * @param headers the HTTP headers. - * @throws Exception - */ - STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception; - - /** - * Invoked once the HTTP response has been fully received - * - * @return T Type of the value that will be returned by the associated {@link java.util.concurrent.Future} - * @throws Exception - */ - T onCompleted() throws Exception; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpClient.java deleted file mode 100755 index 5bc733f3b04..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpClient.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.collect.Multimap; -import org.elasticsearch.util.http.client.Request.EntityWriter; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.concurrent.Future; - -/** - * This class support asynchronous and synchronous HTTP request. - * - * To execute synchronous HTTP request, you just need to do - * {@code - * AsyncHttpClient c = new AsyncHttpClient(); - * Future f = c.prepareGet("http://www.ning.com/").execute(); - * } - * - * The code above will block until the response is fully received. To execute asynchronous HTTP request, you - * create an {@link AsyncHandler} or its abstract implementation, {@link org.elasticsearch.util.http.client.AsyncCompletionHandler} - * - * {@code - * AsyncHttpClient c = new AsyncHttpClient(); - * Future f = c.prepareGet("http://www.ning.com/").execute(new AsyncCompletionHandler() { - * - * @Override - * public Response onCompleted(Response response) throws IOException { - * // Do something - * return response; - * } - * - * @Override - * public void onThrowable(Throwable t) { - * } - * }); - * Response response = f.get(); - * - * // We are just interested to retrieve the status code. - * Future f = c.prepareGet("http://www.ning.com/").execute(new AsyncCompletionHandler() { - * - * @Override - * public Integer onCompleted(Response response) throws IOException { - * // Do something - * return response.getStatusCode(); - * } - * - * @Override - * public void onThrowable(Throwable t) { - * } - * }); - * Integer statusCode = f.get(); - * } - * The {@link AsyncCompletionHandler#onCompleted(org.elasticsearch.util.http.client.Response)} will be invoked once the http response has been fully read, which include - * the http headers and the response body. Note that the entire response will be buffered in memory. - * - * You can also have more control about the how the response is asynchronously processed by using a {@link AsyncHandler} - * {@code - * AsyncHttpClient c = new AsyncHttpClient(); - * Future f = c.prepareGet("http://www.ning.com/").execute(new AsyncHandler() { - * private StringBuilder builder = new StringBuilder(); - * - * @Override - * public void onStatusReceived(HttpResponseStatus s) throws Exception { - * // The Status have been read - * // If you don't want to read the headers,body, or stop processing the response - * throw new ResponseComplete(); - * } - * - * @Override - * public void onHeadersReceived(HttpResponseHeaders bodyPart) throws Exception { - * // The headers have been read - * // If you don't want to read the body, or stop processing the response - * throw new ResponseComplete(); - * } - * @Override - * - * public void onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { - * builder.append(new String(bodyPart)); - * } - * - * @Override - * public String onCompleted() throws Exception { - * // Will be invoked once the response has been fully read or a ResponseComplete exception - * // has been thrown. - * return builder.toString(); - * } - * - * @Override - * public void onThrowable(Throwable t) { - * } - * }); - * - * String bodyResponse = f.get(); - * } - * From any {@link HttpContent} sub classses, you can asynchronously process the response status,headers and body and decide when to - * stop the processing the response by throwing a new {link ResponseComplete} at any moment. - * - * This class can also be used without the need of {@link AsyncHandler}

- * {@code - * AsyncHttpClient c = new AsyncHttpClient(); - * Future f = c.prepareGet(TARGET_URL).execute(); - * Response r = f.get(); - * } - * - * Finally, you can configure the AsyncHttpClient using an {@link AsyncHttpClientConfig} instance

- * {@code - * AsyncHttpClient c = new AsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(...).build()); - * Future f = c.prepareGet(TARGET_URL).execute(); - * Response r = f.get(); - * } - * - * An instance of this class will cache every HTTP 1.1 connections and close them when the {@link AsyncHttpClientConfig#getIdleConnectionTimeoutInMs()} - * expires. This object can hold many persistent connections to different host. - */ -public class AsyncHttpClient { - - private final static String DEFAULT_PROVIDER = "org.elasticsearch.util.http.client.providers.NettyAsyncHttpProvider"; - private final AsyncHttpProvider httpProvider; - private final AsyncHttpClientConfig config; - - /** - * Create a new HTTP Asynchronous Client using the default {@link AsyncHttpClientConfig} configuration. The - * default {@link AsyncHttpProvider} will be used ({@link org.elasticsearch.util.http.client.providers.NettyAsyncHttpProvider} - */ - public AsyncHttpClient() { - this(new AsyncHttpClientConfig.Builder().build()); - } - - /** - * Create a new HTTP Asynchronous Client using an implementation of {@link AsyncHttpProvider} and - * the default {@link AsyncHttpClientConfig} configuration. - * - * @param provider a {@link AsyncHttpProvider} - */ - public AsyncHttpClient(AsyncHttpProvider provider) { - this(provider, new AsyncHttpClientConfig.Builder().build()); - } - - /** - * Create a new HTTP Asynchronous Client using a {@link AsyncHttpClientConfig} configuration and the - * {@link #DEFAULT_PROVIDER} - * - * @param config a {@link AsyncHttpClientConfig} - */ - public AsyncHttpClient(AsyncHttpClientConfig config) { - this(loadDefaultProvider(DEFAULT_PROVIDER, config), config); - } - - /** - * Create a new HTTP Asynchronous Client using a {@link AsyncHttpClientConfig} configuration and - * and a {@link AsyncHttpProvider}. - * - * @param config a {@link AsyncHttpClientConfig} - * @param httpProvider a {@link AsyncHttpProvider} - */ - public AsyncHttpClient(AsyncHttpProvider httpProvider, AsyncHttpClientConfig config) { - this.config = config; - this.httpProvider = httpProvider; - } - - /** - * Create a new HTTP Asynchronous Client using a {@link AsyncHttpClientConfig} configuration and - * and a AsyncHttpProvider class' name. - * - * @param config a {@link AsyncHttpClientConfig} - * @param providerClass a {@link AsyncHttpProvider} - */ - public AsyncHttpClient(String providerClass, AsyncHttpClientConfig config) { - this.config = new AsyncHttpClientConfig.Builder().build(); - this.httpProvider = loadDefaultProvider(providerClass, config); - } - - public class BoundRequestBuilder extends RequestBuilderBase { - private BoundRequestBuilder(RequestType type) { - super(BoundRequestBuilder.class, type); - } - - private BoundRequestBuilder(Request prototype) { - super(BoundRequestBuilder.class, prototype); - } - - public Future execute(AsyncHandler handler) throws IOException { - return AsyncHttpClient.this.executeRequest(build(), handler); - } - - public Future execute() throws IOException { - return AsyncHttpClient.this.executeRequest(build(), new AsyncCompletionHandlerBase()); - } - - // Note: For now we keep the delegates in place even though they are not needed - // since otherwise Clojure (and maybe other languages) won't be able to - // access these methods - see Clojure tickets 126 and 259 - - @Override - public BoundRequestBuilder addBodyPart(Part part) throws IllegalArgumentException { - return super.addBodyPart(part); - } - - @Override - public BoundRequestBuilder addCookie(Cookie cookie) { - return super.addCookie(cookie); - } - - @Override - public BoundRequestBuilder addHeader(String name, String value) { - return super.addHeader(name, value); - } - - @Override - public BoundRequestBuilder addParameter(String key, String value) throws IllegalArgumentException { - return super.addParameter(key, value); - } - - @Override - public BoundRequestBuilder addQueryParameter(String name, String value) { - return super.addQueryParameter(name, value); - } - - @Override - public Request build() { - return super.build(); - } - - @Override - public BoundRequestBuilder setBody(byte[] data) throws IllegalArgumentException { - return super.setBody(data); - } - - @Override - public BoundRequestBuilder setBody(EntityWriter dataWriter, long length) throws IllegalArgumentException { - return super.setBody(dataWriter, length); - } - - @Override - public BoundRequestBuilder setBody(EntityWriter dataWriter) { - return super.setBody(dataWriter); - } - - @Override - public BoundRequestBuilder setBody(InputStream stream) throws IllegalArgumentException { - return super.setBody(stream); - } - - @Override - public BoundRequestBuilder setBody(String data) throws IllegalArgumentException { - return super.setBody(data); - } - - @Override - public BoundRequestBuilder setHeader(String name, String value) { - return super.setHeader(name, value); - } - - @Override - public BoundRequestBuilder setHeaders(Headers headers) { - return super.setHeaders(headers); - } - - @Override - public BoundRequestBuilder setParameters(Map parameters) throws IllegalArgumentException { - return super.setParameters(parameters); - } - - @Override - public BoundRequestBuilder setParameters(Multimap parameters) throws IllegalArgumentException { - return super.setParameters(parameters); - } - - @Override - public BoundRequestBuilder setUrl(String url) { - return super.setUrl(url); - } - - @Override - public BoundRequestBuilder setVirtualHost(String virtualHost) { - return super.setVirtualHost(virtualHost); - } - } - - /** - * Return the asynchronouys {@link org.elasticsearch.util.http.client.AsyncHttpProvider} - * - * @return an {@link org.elasticsearch.util.http.client.AsyncHttpProvider} - */ - public AsyncHttpProvider getProvider() { - return httpProvider; - } - - /** - * Close the underlying connections. - */ - public void close() { - httpProvider.close(); - } - - @Override - protected void finalize() throws Throwable { - close(); - super.finalize(); - } - - /** - * Return the {@link org.elasticsearch.util.http.client.AsyncHttpClientConfig} - * - * @return {@link org.elasticsearch.util.http.client.AsyncHttpClientConfig} - */ - public AsyncHttpClientConfig getConfig() { - return config; - } - - /** - * Prepare an HTTP client GET request. - * - * @param url A well formed URL. - * @return {@link RequestBuilder} - */ - public BoundRequestBuilder prepareGet(String url) { - return new BoundRequestBuilder(RequestType.GET).setUrl(url); - } - - /** - * Prepare an HTTP client HEAD request. - * - * @param url A well formed URL. - * @return {@link RequestBuilder} - */ - public BoundRequestBuilder prepareHead(String url) { - return new BoundRequestBuilder(RequestType.HEAD).setUrl(url); - } - - /** - * Prepare an HTTP client POST request. - * - * @param url A well formed URL. - * @return {@link RequestBuilder} - */ - public BoundRequestBuilder preparePost(String url) { - return new BoundRequestBuilder(RequestType.POST).setUrl(url); - } - - /** - * Prepare an HTTP client PUT request. - * - * @param url A well formed URL. - * @return {@link RequestBuilder} - */ - public BoundRequestBuilder preparePut(String url) { - return new BoundRequestBuilder(RequestType.PUT).setUrl(url); - } - - /** - * Prepare an HTTP client DELETE request. - * - * @param url A well formed URL. - * @return {@link RequestBuilder} - */ - public BoundRequestBuilder prepareDelete(String url) { - return new BoundRequestBuilder(RequestType.DELETE).setUrl(url); - } - - /** - * Construct a {@link RequestBuilder} using a {@link Request} - * - * @param request a {@link Request} - * @return {@link RequestBuilder} - */ - public BoundRequestBuilder prepareRequest(Request request) { - return new BoundRequestBuilder(request); - } - - /** - * Execute an HTTP request. - * - * @param request {@link Request} - * @param handler an instance of {@link AsyncHandler} - * @param Type of the value that will be returned by the associated {@link java.util.concurrent.Future} - * @return a {@link Future} of type T - * @throws IOException - */ - public Future executeRequest(Request request, AsyncHandler handler) throws IOException { - return httpProvider.execute(request, handler); - } - - /** - * Execute an HTTP request. - * - * @param request {@link Request} - * @return a {@link Future} of type Response - * @throws IOException - */ - public Future executeRequest(Request request) throws IOException { - return httpProvider.execute(request, new AsyncCompletionHandlerBase()); - } - - @SuppressWarnings("unchecked") - private final static AsyncHttpProvider loadDefaultProvider(String className, AsyncHttpClientConfig config) { - try { - Class> providerClass = (Class>) Thread.currentThread() - .getContextClassLoader().loadClass(className); - return (AsyncHttpProvider) providerClass.getDeclaredConstructor( - new Class[]{AsyncHttpClientConfig.class}).newInstance(new Object[]{config}); - } catch (Throwable t) { - throw new RuntimeException(t); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpClientConfig.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpClientConfig.java deleted file mode 100644 index c4b3ec55f91..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpClientConfig.java +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client; - -import javax.net.ssl.SSLEngine; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; - -/** - * Configuration class to use with a {@link AsyncHttpClient}. System property can be also used to configure this - * object default behavior by doing: - *

- * -Dcom.ning.http.client.AsyncHttpClientConfig.nameOfTheProperty - * ex: - *

- * -Dcom.ning.http.client.AsyncHttpClientConfig.defaultMaxTotalConnections - * -Dcom.ning.http.client.AsyncHttpClientConfig.defaultMaxTotalConnections - * -Dcom.ning.http.client.AsyncHttpClientConfig.defaultMaxConnectionsPerHost - * -Dcom.ning.http.client.AsyncHttpClientConfig.defaultConnectionTimeoutInMS - * -Dcom.ning.http.client.AsyncHttpClientConfig.defaultIdleConnectionTimeoutInMS - * -Dcom.ning.http.client.AsyncHttpClientConfig.defaultRequestTimeoutInMS - * -Dcom.ning.http.client.AsyncHttpClientConfig.defaultRedirectsEnabled - * -Dcom.ning.http.client.AsyncHttpClientConfig.defaultMaxRedirects - */ -public class AsyncHttpClientConfig { - - private final static String ASYNC_CLIENT = AsyncHttpClient.class.getName() + "."; - - private final int maxTotalConnections; - private final int maxConnectionPerHost; - private final int connectionTimeOutInMs; - private final int idleConnectionTimeoutInMs; - private final int requestTimeoutInMs; - private final boolean redirectEnabled; - private final int maxDefaultRedirects; - private final boolean compressionEnabled; - private final String userAgent; - private final boolean keepAlive; - private final ScheduledExecutorService reaper; - private final ExecutorService applicationThreadPool; - private final ProxyServer proxyServer; - private final SSLEngine sslEngine; - - private AsyncHttpClientConfig(int maxTotalConnections, - int maxConnectionPerHost, - int connectionTimeOutInMs, - int idleConnectionTimeoutInMs, - int requestTimeoutInMs, - boolean redirectEnabled, - int maxDefaultRedirects, - boolean compressionEnabled, - String userAgent, - boolean keepAlive, - ScheduledExecutorService reaper, - ExecutorService applicationThreadPool, - ProxyServer proxyServer, - SSLEngine sslEngine) { - - this.maxTotalConnections = maxTotalConnections; - this.maxConnectionPerHost = maxConnectionPerHost; - this.connectionTimeOutInMs = connectionTimeOutInMs; - this.idleConnectionTimeoutInMs = idleConnectionTimeoutInMs; - this.requestTimeoutInMs = requestTimeoutInMs; - this.redirectEnabled = redirectEnabled; - this.maxDefaultRedirects = maxDefaultRedirects; - this.compressionEnabled = compressionEnabled; - this.userAgent = userAgent; - this.keepAlive = keepAlive; - this.sslEngine = sslEngine; - - if (reaper == null) { - this.reaper = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { - public Thread newThread(Runnable r) { - return new Thread(r, "AsyncHttpClient-Reaper"); - } - }); - } else { - this.reaper = reaper; - } - - if (applicationThreadPool == null) { - this.applicationThreadPool = Executors.newCachedThreadPool(); - } else { - this.applicationThreadPool = applicationThreadPool; - } - this.proxyServer = proxyServer; - } - - /** - * A {@link ScheduledExecutorService} used to expire idle connections. - * - * @return {@link ScheduledExecutorService} - */ - public ScheduledExecutorService reaper() { - return reaper; - } - - /** - * Return the maximum number of connections an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can handle. - * - * @return the maximum number of connections an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can handle. - */ - public int getMaxTotalConnections() { - return maxTotalConnections; - } - - /** - * Return the maximum number of connections per hosts an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can handle. - * - * @return the maximum number of connections per host an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can handle. - */ - public int getMaxConnectionPerHost() { - return maxConnectionPerHost; - } - - /** - * Return the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can wait when connecting to a remote host - * - * @return the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can wait when connecting to a remote host - */ - public int getConnectionTimeoutInMs() { - return connectionTimeOutInMs; - } - - /** - * Return the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can stay idle. - * - * @return the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can stay idle. - */ - public int getIdleConnectionTimeoutInMs() { - return idleConnectionTimeoutInMs; - } - - /** - * Return the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} wait for a response - * - * @return the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} wait for a response - */ - public int getRequestTimeoutInMs() { - return requestTimeoutInMs; - } - - /** - * Is HTTP redirect enabled - * - * @return true if enabled. - */ - public boolean isRedirectEnabled() { - return redirectEnabled; - } - - /** - * Get the maximum number of HTTP redirect - * - * @return the maximum number of HTTP redirect - */ - public int getMaxRedirects() { - return maxDefaultRedirects; - } - - /** - * Is HTTP keep-alive enabled. - * - * @return true if keep-alive is enabled - */ - public boolean getKeepAlive() { - return keepAlive; - } - - /** - * Return the USER_AGENT header value - * - * @return the USER_AGENT header value - */ - public String getUserAgent() { - return userAgent; - } - - /** - * Is HTTP compression enabled. - * - * @return true if compression is enabled - */ - public boolean isCompressionEnabled() { - return compressionEnabled; - } - - /** - * Return the {@link java.util.concurrent.ExecutorService} an {@link AsyncHttpClient} use for handling - * asynchronous response. - * - * @return the {@link java.util.concurrent.ExecutorService} an {@link AsyncHttpClient} use for handling - * asynchronous response. - */ - public ExecutorService executorService() { - return applicationThreadPool; - } - - /** - * An instance of {@link org.elasticsearch.util.http.client.ProxyServer} used by an {@link AsyncHttpClient} - * - * @return instance of {@link org.elasticsearch.util.http.client.ProxyServer} - */ - public ProxyServer getProxyServer() { - return proxyServer; - } - - /** - * Return an instance of {@link SSLEngine} used for SSL connection. - * - * @return an instance of {@link SSLEngine} used for SSL connection. - */ - public SSLEngine getSSLEngine() { - return sslEngine; - } - - /** - * Builder for an {@link AsyncHttpClient} - */ - public static class Builder { - private int defaultMaxTotalConnections = Integer.getInteger(ASYNC_CLIENT + "defaultMaxTotalConnections", 2000); - private int defaultMaxConnectionPerHost = Integer.getInteger(ASYNC_CLIENT + "defaultMaxConnectionsPerHost", 2000); - private int defaultConnectionTimeOutInMs = Integer.getInteger(ASYNC_CLIENT + "defaultConnectionTimeoutInMS", 60 * 1000); - private int defaultIdleConnectionTimeoutInMs = Integer.getInteger(ASYNC_CLIENT + "defaultIdleConnectionTimeoutInMS", 60 * 1000); - private int defaultRequestTimeoutInMs = Integer.getInteger(ASYNC_CLIENT + "defaultRequestTimeoutInMS", 60 * 1000); - private boolean redirectEnabled = Boolean.getBoolean(ASYNC_CLIENT + "defaultRedirectsEnabled"); - private int maxDefaultRedirects = Integer.getInteger(ASYNC_CLIENT + "defaultMaxRedirects", 5); - private boolean compressionEnabled = Boolean.getBoolean(ASYNC_CLIENT + "compressionEnabled"); - private String userAgent = System.getProperty(ASYNC_CLIENT + "userAgent", "ES/1.0"); - private boolean keepAlive = true; - private ScheduledExecutorService reaper = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors()); - private ExecutorService applicationThreadPool = Executors.newCachedThreadPool(); - private ProxyServer proxyServer = null; - private SSLEngine sslEngine; - - public Builder() { - } - - /** - * Set the maximum number of connections an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can handle. - * - * @param defaultMaxTotalConnections the maximum number of connections an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can handle. - * @return a {@link Builder} - */ - public Builder setMaximumConnectionsTotal(int defaultMaxTotalConnections) { - this.defaultMaxTotalConnections = defaultMaxTotalConnections; - return this; - } - - /** - * Set the maximum number of connections per hosts an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can handle. - * - * @param defaultMaxConnectionPerHost the maximum number of connections per host an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can handle. - * @return a {@link Builder} - */ - public Builder setMaximumConnectionsPerHost(int defaultMaxConnectionPerHost) { - this.defaultMaxConnectionPerHost = defaultMaxConnectionPerHost; - return this; - } - - /** - * Set the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can wait when connecting to a remote host - * - * @param defaultConnectionTimeOutInMs the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can wait when connecting to a remote host - * @return a {@link Builder} - */ - public Builder setConnectionTimeoutInMs(int defaultConnectionTimeOutInMs) { - this.defaultConnectionTimeOutInMs = defaultConnectionTimeOutInMs; - return this; - } - - /** - * Set the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can stay idle. - * - * @param defaultIdleConnectionTimeoutInMs - * the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} can stay idle. - * @return a {@link Builder} - */ - public Builder setIdleConnectionTimeoutInMs(int defaultIdleConnectionTimeoutInMs) { - this.defaultIdleConnectionTimeoutInMs = defaultIdleConnectionTimeoutInMs; - return this; - } - - /** - * Set the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} wait for a response - * - * @param defaultRequestTimeoutInMs the maximum time in millisecond an {@link org.elasticsearch.util.http.client.AsyncHttpClient} wait for a response - * @return a {@link Builder} - */ - public Builder setRequestTimeoutInMs(int defaultRequestTimeoutInMs) { - this.defaultRequestTimeoutInMs = defaultRequestTimeoutInMs; - return this; - } - - /** - * Set to true to enable HTTP redirect - * - * @param redirectEnabled true if enabled. - * @return a {@link Builder} - */ - public Builder setFollowRedirects(boolean redirectEnabled) { - this.redirectEnabled = redirectEnabled; - return this; - } - - /** - * Set the maximum number of HTTP redirect - * - * @param maxDefaultRedirects the maximum number of HTTP redirect - * @return a {@link Builder} - */ - public Builder setMaximumNumberOfRedirects(int maxDefaultRedirects) { - this.maxDefaultRedirects = maxDefaultRedirects; - return this; - } - - /** - * Enable HTTP compression. - * - * @param compressionEnabled true if compression is enabled - * @return a {@link Builder} - */ - public Builder setCompressionEnabled(boolean compressionEnabled) { - this.compressionEnabled = compressionEnabled; - return this; - } - - /** - * Set the USER_AGENT header value - * - * @param userAgent the USER_AGENT header value - * @return a {@link Builder} - */ - public Builder setUserAgent(String userAgent) { - this.userAgent = userAgent; - return this; - } - - /** - * Set HTTP keep-alive value. - * - * @param keepAlive true if keep-alive is enabled - * @return a {@link Builder} - */ - public Builder setKeepAlive(boolean keepAlive) { - this.keepAlive = keepAlive; - return this; - } - - /** - * Set the{@link ScheduledExecutorService} used to expire idle connections. - * - * @param reaper the{@link ScheduledExecutorService} used to expire idle connections. - * @return a {@link Builder} - */ - public Builder setScheduledExecutorService(ScheduledExecutorService reaper) { - this.reaper = reaper; - return this; - } - - /** - * Set the {@link java.util.concurrent.ExecutorService} an {@link AsyncHttpClient} use for handling - * asynchronous response. - * - * @param applicationThreadPool the {@link java.util.concurrent.ExecutorService} an {@link AsyncHttpClient} use for handling - * asynchronous response. - * @return a {@link Builder} - */ - public Builder setExecutorService(ExecutorService applicationThreadPool) { - this.applicationThreadPool = applicationThreadPool; - return this; - } - - /** - * Set an instance of {@link org.elasticsearch.util.http.client.ProxyServer} used by an {@link AsyncHttpClient} - * - * @param proxyServer instance of {@link org.elasticsearch.util.http.client.ProxyServer} - * @return a {@link Builder} - */ - public Builder setProxyServer(ProxyServer proxyServer) { - this.proxyServer = proxyServer; - return this; - } - - /** - * Set the {@link SSLEngine} for secure connection. - * - * @param sslEngine the {@link SSLEngine} for secure connection - * @return a {@link Builder} - */ - public Builder setSSLEngine(SSLEngine sslEngine) { - this.sslEngine = sslEngine; - return this; - } - - /** - * Build an {@link AsyncHttpClientConfig} - * - * @return an {@link AsyncHttpClientConfig} - */ - public AsyncHttpClientConfig build() { - return new AsyncHttpClientConfig(defaultMaxTotalConnections, - defaultMaxConnectionPerHost, - defaultConnectionTimeOutInMs, - defaultIdleConnectionTimeoutInMs, - defaultRequestTimeoutInMs, - redirectEnabled, - maxDefaultRedirects, - compressionEnabled, - userAgent, - keepAlive, - reaper, - applicationThreadPool, - proxyServer, - sslEngine); - } - - } -} - diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpProvider.java deleted file mode 100644 index 16d78ef21e2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/AsyncHttpProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client; - -import java.io.IOException; -import java.util.Collection; -import java.util.concurrent.Future; - -/** - * Interface to be used when implementing custom asynchronous I/O HTTP client. - * By default, the {@link org.elasticsearch.util.http.client.providers.NettyAsyncHttpProvider} is used. - */ -public interface AsyncHttpProvider { - - /** - * Execute the request and invoke the {@link AsyncHandler} when the response arrive. - * - * @param handler an instance of {@link AsyncHandler} - * @return a {@link java.util.concurrent.Future} of Type T. - * @throws IOException - */ - public Future execute(Request request, AsyncHandler handler) throws IOException; - - /** - * Close the current underlying TCP/HTTP connection.s - */ - public void close(); - - /** - * Prepare a {@link Response} - * - * @param status {@link HttpResponseStatus} - * @param headers {@link HttpResponseHeaders} - * @param bodyParts list of {@link HttpResponseBodyPart} - * @return a {@link Response} - */ - public Response prepareResponse(HttpResponseStatus status, - HttpResponseHeaders headers, - Collection> bodyParts); - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/ByteArrayPart.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/ByteArrayPart.java deleted file mode 100644 index 4e0290133c1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/ByteArrayPart.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -public class ByteArrayPart implements Part { - private String name; - private String fileName; - private byte[] data; - private String mimeType; - private String charSet; - - public ByteArrayPart(String name, String fileName, byte[] data, String mimeType, String charSet) { - this.name = name; - this.fileName = fileName; - this.data = data; - this.mimeType = mimeType; - this.charSet = charSet; - } - - public String getName() { - return name; - } - - public String getFileName() { - return fileName; - } - - public byte[] getData() { - return data; - } - - public String getMimeType() { - return mimeType; - } - - public String getCharSet() { - return charSet; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Cookie.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Cookie.java deleted file mode 100644 index a4508473c4a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Cookie.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -public class Cookie { - private String domain; - private String name; - private String value; - private String path; - private int maxAge; - private boolean secure; - - public Cookie(String domain, String name, String value, String path, int maxAge, boolean secure) { - this.domain = domain; - this.name = name; - this.value = value; - this.path = path; - this.maxAge = maxAge; - this.secure = secure; - } - - public String getDomain() { - return domain; - } - - public String getName() { - return name; - } - - public String getValue() { - return value; - } - - public String getPath() { - return path; - } - - public int getMaxAge() { - return maxAge; - } - - public boolean isSecure() { - return secure; - } - - @Override - public String toString() { - return String.format("Cookie: domain=%s, name=%s, value=%s, path=%s, maxAge=%d, secure=%s", - domain, name, value, path, maxAge, secure); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/FilePart.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/FilePart.java deleted file mode 100644 index 60585ae15f2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/FilePart.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -import java.io.File; - -/** - * A file multipart part. - */ -public class FilePart implements Part { - private String name; - private File file; - private String mimeType; - private String charSet; - - public FilePart(String name, File file, String mimeType, String charSet) { - this.name = name; - this.file = file; - this.mimeType = mimeType; - this.charSet = charSet; - } - - public String getName() { - return name; - } - - public File getFile() { - return file; - } - - public String getMimeType() { - return mimeType; - } - - public String getCharSet() { - return charSet; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/FutureImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/FutureImpl.java deleted file mode 100755 index bac4d575dfc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/FutureImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client; - -import java.util.concurrent.Future; - -/** - * Extended {@link Future} - * - * @param Type of the value that will be returned. - */ -public interface FutureImpl extends Future { - - void done(); - - void abort(Throwable t); - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Headers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Headers.java deleted file mode 100644 index 5dad1a61bc1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Headers.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.http.collection.Pair; - -import java.util.*; - -public class Headers implements Iterable> { - public static final String CONTENT_TYPE = "Content-Type"; - - private List> headers = new ArrayList>(); - - public static Headers unmodifiableHeaders(Headers headers) { - return new UnmodifiableHeaders(headers); - } - - public Headers() { - } - - public Headers(Headers src) { - if (src != null) { - for (Pair header : src) { - add(header); - } - } - } - - public Headers(Map> headers) { - for (Map.Entry> entry : headers.entrySet()) { - for (String value : entry.getValue()) { - add(entry.getKey(), value); - } - } - } - - /** - * Adds the specified header and returns this headers object. - * - * @param name The header name - * @param value The header value - * @return This object - */ - public Headers add(String name, String value) { - headers.add(new Pair(name, value)); - return this; - } - - /** - * Adds the specified header and returns this headers object. - * - * @param header The name / value pair - * @return This object - */ - public Headers add(Pair header) { - headers.add(new Pair(header.getFirst(), header.getSecond())); - return this; - } - - /** - * Adds all headers from the given headers object to this object and returns this headers object. - * - * @param srcHeaders The source headers object - * @return This object - */ - public Headers addAll(Headers srcHeaders) { - for (Pair entry : srcHeaders.headers) { - headers.add(new Pair(entry.getFirst(), entry.getSecond())); - } - return this; - } - - /** - * Convenience method to add a Content-type header - * - * @param contentType content type to set - * @return This object - */ - public Headers addContentTypeHeader(String contentType) { - return add(CONTENT_TYPE, contentType); - } - - /** - * Replaces all existing headers with the header given. - * - * @param header The header name. - * @param value The new header value. - */ - public void replace(final String header, final String value) { - remove(header); - add(header, value); - } - - /** - * {@inheritDoc} - */ - public Iterator> iterator() { - return headers.iterator(); - } - - /** - * Returns the value of first header of the given name. - * - * @param name The header's name - * @return The value - */ - public String getHeaderValue(String name) { - for (Pair header : this) { - if (name.equalsIgnoreCase(header.getFirst())) { - return header.getSecond(); - } - } - return null; - } - - /** - * Returns the values of all header of the given name. - * - * @param name The header name - * @return The values, will not be null - */ - public List getHeaderValues(String name) { - ArrayList values = new ArrayList(); - - for (Pair header : this) { - if (name.equalsIgnoreCase(header.getFirst())) { - values.add(header.getSecond()); - } - } - return values; - } - - /** - * Adds the specified header(s) and returns this headers object. - * - * @param name The header name - * @return This object - */ - public Headers remove(String name) { - for (Iterator> it = headers.iterator(); it.hasNext();) { - Pair header = it.next(); - - if (name.equalsIgnoreCase(header.getFirst())) { - it.remove(); - } - } - return this; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final Headers other = (Headers) obj; - if (headers == null) { - if (other.headers != null) - return false; - } else if (!headers.equals(other.headers)) - return false; - return true; - } - - private static class UnmodifiableHeaders extends Headers { - final Headers headers; - - UnmodifiableHeaders(Headers headers) { - this.headers = headers; - } - - @Override - public Headers add(Pair header) { - throw new UnsupportedOperationException(); - } - - @Override - public Headers add(String name, String value) { - throw new UnsupportedOperationException(); - } - - @Override - public Headers addAll(Headers srcHeaders) { - throw new UnsupportedOperationException(); - } - - @Override - public Headers addContentTypeHeader(String contentType) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object obj) { - return headers.equals(obj); - } - - @Override - public String getHeaderValue(String name) { - return headers.getHeaderValue(name); - } - - @Override - public List getHeaderValues(String name) { - return headers.getHeaderValues(name); - } - - @Override - public Iterator> iterator() { - return headers.iterator(); - } - - @Override - public Headers remove(String name) { - throw new UnsupportedOperationException(); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpContent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpContent.java deleted file mode 100644 index 406048915a9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpContent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.http.url.Url; - -/** - * Base class for callback class used by {@link org.elasticsearch.util.http.client.AsyncHandler} - */ -public class HttpContent { - protected final R response; - protected final AsyncHttpProvider provider; - protected final Url url; - - protected HttpContent(Url url, R response, AsyncHttpProvider provider) { - this.response = response; - this.provider = provider; - this.url = url; - } - - protected final AsyncHttpProvider provider() { - return provider; - } - - public final Url getUrl() { - return url; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseBodyPart.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseBodyPart.java deleted file mode 100644 index a5ac3ccb6bf..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseBodyPart.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.http.url.Url; - -/** - * A callback class used when an HTTP response body is received. - */ -public abstract class HttpResponseBodyPart extends HttpContent { - - public HttpResponseBodyPart(Url url, R response, AsyncHttpProvider provider) { - super(url, response, provider); - } - - /** - * Return the response body's part bytes received. - * - * @return the response body's part bytes received. - */ - abstract public byte[] getBodyPartBytes(); - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseHeaders.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseHeaders.java deleted file mode 100644 index 8f718d33202..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseHeaders.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.http.url.Url; - -/** - * A class that represent the HTTP headers. - */ -public abstract class HttpResponseHeaders extends HttpContent { - - private final boolean traillingHeaders; - - public HttpResponseHeaders(Url url, R response, AsyncHttpProvider provider) { - super(url, response, provider); - this.traillingHeaders = false; - } - - public HttpResponseHeaders(Url url, R response, AsyncHttpProvider provider, boolean traillingHeaders) { - super(url, response, provider); - this.traillingHeaders = traillingHeaders; - - } - - /** - * Return the HTTP header - * - * @return an {@link Headers} - */ - abstract public Headers getHeaders(); - - /** - * Return true is headers has been received after the response body. - * - * @return true is headers has been received after the response body. - */ - public boolean isTraillingHeadersReceived() { - return traillingHeaders; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseStatus.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseStatus.java deleted file mode 100644 index 8ca0d3ccc8f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/HttpResponseStatus.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.http.url.Url; - -/** - * A class that represent the HTTP response' status line (code + text) - */ -public abstract class HttpResponseStatus extends HttpContent { - - public HttpResponseStatus(Url url, R response, AsyncHttpProvider provider) { - super(url, response, provider); - } - - /** - * Return the response status code - * - * @return the response status code - */ - abstract public int getStatusCode(); - - /** - * Return the response status text - * - * @return the response status text - */ - abstract public String getStatusText(); - - /** - * Protocol name from status line. - * - * @return Protocol name. - */ - abstract public String getProtocolName(); - - /** - * Protocol major version. - * - * @return Major version. - */ - abstract public int getProtocolMajorVersion(); - - /** - * Protocol minor version. - * - * @return Minor version. - */ - abstract public int getProtocolMinorVersion(); - - /** - * Full protocol name + version - * - * @return protocol name + version - */ - abstract public String getProtocolText(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/MaxRedirectException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/MaxRedirectException.java deleted file mode 100644 index 09ab9d70dd0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/MaxRedirectException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -/** - * Thrown when the {@link AsyncHttpClientConfig#getMaxRedirects()} has been reached. - */ -public class MaxRedirectException extends Exception { - private static final long serialVersionUID = 1L; - - public MaxRedirectException() { - super(); - } - - public MaxRedirectException(String msg) { - super(msg); - } - - public MaxRedirectException(Throwable cause) { - super(cause); - } - - public MaxRedirectException(String message, Throwable cause) { - super(message, cause); - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Part.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Part.java deleted file mode 100644 index 1c92f8590aa..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Part.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -/** - * Interface for the parts in a multipart request. - */ -public interface Part { - public String getName(); -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/ProxyServer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/ProxyServer.java deleted file mode 100644 index 9db0a9b7baf..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/ProxyServer.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.SocketAddress; - -/** - * Represents a proxy server. - */ -public class ProxyServer { - public enum Protocol { - HTTP("http"), HTTPS("https"); - - private final String protocol; - - private Protocol(final String protocol) { - this.protocol = protocol; - } - - public String getProtocol() { - return protocol; - } - - @Override - public String toString() { - return getProtocol(); - } - } - - private final Protocol protocol; - private final String host; - private int port; - - public ProxyServer(final Protocol protocol, final String host, final int port) { - this.protocol = protocol; - this.host = host; - this.port = port; - } - - public ProxyServer(final String host, final int port) { - this(Protocol.HTTP, host, port); - } - - public Protocol getProtocol() { - return protocol; - } - - public String getProtocolAsString() { - return protocol.toString(); - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - - /** - * Convert from Java java.net.Proxy object. - * - * @param proxy - * @return A ProxyServer object or null if the proxy object can not converted. - */ - public static final ProxyServer fromProxy(final Proxy proxy) { - if (proxy == null || proxy.type() == Proxy.Type.DIRECT) { - return null; - } - - if (proxy.type() != Proxy.Type.HTTP) { - throw new IllegalArgumentException("Only DIRECT and HTTP Proxies are supported!"); - } - - final SocketAddress sa = proxy.address(); - - if (!(sa instanceof InetSocketAddress)) { - throw new IllegalArgumentException("Only Internet Address sockets are supported!"); - } - - InetSocketAddress isa = (InetSocketAddress) sa; - - if (isa.isUnresolved()) { - return new ProxyServer(isa.getHostName(), isa.getPort()); - } else { - return new ProxyServer(isa.getAddress().getHostAddress(), isa.getPort()); - } - } - - @Override - public String toString() { - return String.format("%s://%s:%d", protocol.toString(), host, port); - } -} - diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Request.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Request.java deleted file mode 100644 index a950b6362c5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Request.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.collect.Multimap; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Collection; -import java.util.List; - -public interface Request { - - public static interface EntityWriter { - public void writeEntity(OutputStream out) throws IOException; - } - - public RequestType getType(); - - public String getUrl(); - - public Headers getHeaders(); - - public Collection getCookies(); - - public byte[] getByteData(); - - public String getStringData(); - - public InputStream getStreamData(); - - public EntityWriter getEntityWriter(); - - public long getLength(); - - public Multimap getParams(); - - public List getParts(); - - public String getVirtualHost(); - - public Multimap getQueryParams(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestBuilder.java deleted file mode 100644 index 5823340d156..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestBuilder.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.collect.Multimap; -import org.elasticsearch.util.http.client.Request.EntityWriter; - -import java.io.InputStream; -import java.util.Map; - -/** - * Builder for a {@link Request}. - */ -public class RequestBuilder extends RequestBuilderBase { - public RequestBuilder(RequestType type) { - super(RequestBuilder.class, type); - } - - public RequestBuilder(Request prototype) { - super(RequestBuilder.class, prototype); - } - - // Note: For now we keep the delegates in place even though they are not needed - // since otherwise Clojure (and maybe other languages) won't be able to - // access these methods - see Clojure tickets 126 and 259 - - @Override - public RequestBuilder addBodyPart(Part part) throws IllegalArgumentException { - return super.addBodyPart(part); - } - - @Override - public RequestBuilder addCookie(Cookie cookie) { - return super.addCookie(cookie); - } - - @Override - public RequestBuilder addHeader(String name, String value) { - return super.addHeader(name, value); - } - - @Override - public RequestBuilder addParameter(String key, String value) throws IllegalArgumentException { - return super.addParameter(key, value); - } - - @Override - public RequestBuilder addQueryParameter(String name, String value) { - return super.addQueryParameter(name, value); - } - - @Override - public Request build() { - return super.build(); - } - - @Override - public RequestBuilder setBody(byte[] data) throws IllegalArgumentException { - return super.setBody(data); - } - - @Override - public RequestBuilder setBody(EntityWriter dataWriter, long length) throws IllegalArgumentException { - return super.setBody(dataWriter, length); - } - - @Override - public RequestBuilder setBody(EntityWriter dataWriter) { - return super.setBody(dataWriter); - } - - @Override - public RequestBuilder setBody(InputStream stream) throws IllegalArgumentException { - return super.setBody(stream); - } - - @Override - public RequestBuilder setBody(String data) throws IllegalArgumentException { - return super.setBody(data); - } - - @Override - public RequestBuilder setHeader(String name, String value) { - return super.setHeader(name, value); - } - - @Override - public RequestBuilder setHeaders(Headers headers) { - return super.setHeaders(headers); - } - - @Override - public RequestBuilder setParameters(Map parameters) throws IllegalArgumentException { - return super.setParameters(parameters); - } - - @Override - public RequestBuilder setParameters(Multimap parameters) throws IllegalArgumentException { - return super.setParameters(parameters); - } - - @Override - public RequestBuilder setUrl(String url) { - return super.setUrl(url); - } - - @Override - public RequestBuilder setVirtualHost(String virtualHost) { - return super.setVirtualHost(virtualHost); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestBuilderBase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestBuilderBase.java deleted file mode 100644 index 04ae8630a29..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestBuilderBase.java +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.collect.LinkedListMultimap; -import org.elasticsearch.util.collect.Multimap; -import org.elasticsearch.util.collect.Multimaps; -import org.elasticsearch.util.http.client.Request.EntityWriter; -import org.elasticsearch.util.http.collection.Pair; -import org.elasticsearch.util.http.url.Url; - -import java.io.InputStream; -import java.net.MalformedURLException; -import java.util.*; - -/** - * Builder for {@link Request} - * - * @param - */ -abstract class RequestBuilderBase> { - - private static final class RequestImpl implements Request { - private RequestType type; - private String url; - private Headers headers = new Headers(); - private Collection cookies = new ArrayList(); - private byte[] byteData; - private String stringData; - private InputStream streamData; - private EntityWriter entityWriter; - private Multimap params; - private List parts; - private String virtualHost; - private long length = -1; - public Multimap queryParams; - - public RequestImpl() { - } - - public RequestImpl(Request prototype) { - if (prototype != null) { - this.type = prototype.getType(); - this.url = prototype.getUrl(); - this.headers = new Headers(prototype.getHeaders()); - this.cookies = new ArrayList(prototype.getCookies()); - this.byteData = prototype.getByteData(); - this.stringData = prototype.getStringData(); - this.streamData = prototype.getStreamData(); - this.entityWriter = prototype.getEntityWriter(); - this.params = (prototype.getParams() == null ? null : LinkedListMultimap.create(prototype.getParams())); - this.queryParams = (prototype.getQueryParams() == null ? null : LinkedListMultimap.create(prototype.getQueryParams())); - this.parts = (prototype.getParts() == null ? null : new ArrayList(prototype.getParts())); - this.virtualHost = prototype.getVirtualHost(); - this.length = prototype.getLength(); - } - } - - /* @Override */ - - public RequestType getType() { - return type; - } - - /* @Override */ - - public String getUrl() { - try { - Url url = Url.valueOf(this.url); - - if (queryParams != null) { - - for (Map.Entry entry : queryParams.entries()) { - url.addParameter(entry.getKey(), entry.getValue()); - } - } - - return url.toString(); - } - catch (MalformedURLException e) { - throw new IllegalArgumentException("Illegal URL", e); - } - } - - /* @Override */ - - public Headers getHeaders() { - return Headers.unmodifiableHeaders(headers); - } - - /* @Override */ - - public Collection getCookies() { - return Collections.unmodifiableCollection(cookies); - } - - /* @Override */ - - public byte[] getByteData() { - return byteData; - } - - /* @Override */ - - public String getStringData() { - return stringData; - } - - /* @Override */ - - public InputStream getStreamData() { - return streamData; - } - - /* @Override */ - - public EntityWriter getEntityWriter() { - return entityWriter; - } - - /* @Override */ - - public long getLength() { - return length; - } - - /* @Override */ - - public Multimap getParams() { - return params == null ? null : Multimaps.unmodifiableMultimap(params); - } - - /* @Override */ - - public List getParts() { - return parts == null ? null : Collections.unmodifiableList(parts); - } - - /* @Override */ - - public String getVirtualHost() { - return virtualHost; - } - - public Multimap getQueryParams() { - return queryParams == null ? null : Multimaps.unmodifiableMultimap(queryParams); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(url); - - sb.append("\t"); - sb.append(type); - for (Pair header : headers) { - sb.append("\t"); - sb.append(header.getFirst()); - sb.append(":"); - sb.append(header.getSecond()); - } - - return sb.toString(); - } - } - - private final Class derived; - private final RequestImpl request; - - RequestBuilderBase(Class derived, RequestType type) { - this.derived = derived; - request = new RequestImpl(); - request.type = type; - } - - RequestBuilderBase(Class derived, Request prototype) { - this.derived = derived; - request = new RequestImpl(prototype); - } - - public T setUrl(String url) { - request.url = url; - return derived.cast(this); - } - - public T setVirtualHost(String virtualHost) { - request.virtualHost = virtualHost; - return derived.cast(this); - } - - public T setHeader(String name, String value) { - request.headers.replace(name, value); - return derived.cast(this); - } - - public T addHeader(String name, String value) { - request.headers.add(name, value); - return derived.cast(this); - } - - public T setHeaders(Headers headers) { - request.headers = (headers == null ? new Headers() : new Headers(headers)); - return derived.cast(this); - } - - public T addCookie(Cookie cookie) { - request.cookies.add(cookie); - return derived.cast(this); - } - - private void resetParameters() { - request.params = null; - } - - private void resetNonMultipartData() { - request.byteData = null; - request.stringData = null; - request.streamData = null; - request.entityWriter = null; - request.length = -1; - } - - private void resetMultipartData() { - request.parts = null; - } - - public T setBody(byte[] data) throws IllegalArgumentException { - if ((request.type != RequestType.POST) && (request.type != RequestType.PUT)) { - throw new IllegalArgumentException("Request type has to POST or PUT for content"); - } - resetParameters(); - resetNonMultipartData(); - resetMultipartData(); - request.byteData = data; - return derived.cast(this); - } - - public T setBody(String data) throws IllegalArgumentException { - if ((request.type != RequestType.POST) && (request.type != RequestType.PUT)) { - throw new IllegalArgumentException("Request type has to POST or PUT for content"); - } - resetParameters(); - resetNonMultipartData(); - resetMultipartData(); - request.stringData = data; - return derived.cast(this); - } - - public T setBody(InputStream stream) throws IllegalArgumentException { - if ((request.type != RequestType.POST) && (request.type != RequestType.PUT)) { - throw new IllegalArgumentException("Request type has to POST or PUT for content"); - } - resetParameters(); - resetNonMultipartData(); - resetMultipartData(); - request.streamData = stream; - return derived.cast(this); - } - - public T setBody(EntityWriter dataWriter) { - return setBody(dataWriter, -1); - } - - public T setBody(EntityWriter dataWriter, long length) throws IllegalArgumentException { - if ((request.type != RequestType.POST) && (request.type != RequestType.PUT)) { - throw new IllegalArgumentException("Request type has to POST or PUT for content"); - } - resetParameters(); - resetNonMultipartData(); - resetMultipartData(); - request.entityWriter = dataWriter; - request.length = length; - return derived.cast(this); - } - - public T addQueryParameter(String name, String value) { - if (request.queryParams == null) { - request.queryParams = LinkedListMultimap.create(); - } - request.queryParams.put(name, value); - return derived.cast(this); - } - - public T addParameter(String key, String value) throws IllegalArgumentException { - if ((request.type != RequestType.POST) && (request.type != RequestType.PUT)) { - throw new IllegalArgumentException("Request type has to POST or PUT for form parameters"); - } - resetNonMultipartData(); - resetMultipartData(); - if (request.params == null) { - request.params = LinkedListMultimap.create(); - } - request.params.put(key, value); - return derived.cast(this); - } - - public T setParameters(Multimap parameters) throws IllegalArgumentException { - if ((request.type != RequestType.POST) && (request.type != RequestType.PUT)) { - throw new IllegalArgumentException("Request type has to POST or PUT for form parameters"); - } - resetNonMultipartData(); - resetMultipartData(); - request.params = LinkedListMultimap.create(parameters); - return derived.cast(this); - } - - public T setParameters(Map parameters) throws IllegalArgumentException { - if ((request.type != RequestType.POST) && (request.type != RequestType.PUT)) { - throw new IllegalArgumentException("Request type has to POST or PUT for form parameters"); - } - resetNonMultipartData(); - resetMultipartData(); - request.params = LinkedListMultimap.create(Multimaps.forMap(parameters)); - return derived.cast(this); - } - - public T addBodyPart(Part part) throws IllegalArgumentException { - if ((request.type != RequestType.POST) && (request.type != RequestType.PUT)) { - throw new IllegalArgumentException("Request type has to POST or PUT for parts"); - } - resetParameters(); - resetNonMultipartData(); - if (request.parts == null) { - request.parts = new ArrayList(); - } - request.parts.add(part); - return derived.cast(this); - } - - public Request build() { - if ((request.length < 0) && (request.streamData == null) && - ((request.type == RequestType.POST) || (request.type == RequestType.PUT))) { - String contentLength = request.headers.getHeaderValue("Content-Length"); - - if (contentLength != null) { - try { - request.length = Long.parseLong(contentLength); - } - catch (NumberFormatException e) { - // NoOp -- we wdn't specify length so it will be chunked? - } - } - } - return request; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestType.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestType.java deleted file mode 100644 index b2f85fcad58..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/RequestType.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -public enum RequestType { - GET, - POST, - PUT, - DELETE, - HEAD -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Response.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Response.java deleted file mode 100644 index 46cd344afea..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/Response.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -import org.elasticsearch.util.http.url.Url; - -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.util.List; - -/** - * Represents the asynchronous HTTP response callback for an {@link org.elasticsearch.util.http.client.AsyncCompletionHandler} - */ -public interface Response { - /** - * Returns the status code for the request. - * - * @return The status code - */ - public int getStatusCode(); - - /** - * Returns the status text for the request. - * - * @return The status text - */ - public String getStatusText(); - - /** - * Returns an input stream for the response body. Note that you should not try to get this more than once, - * and that you should not close the stream. - * - * @return The input stream - * @throws java.io.IOException - */ - public InputStream getResponseBodyAsStream() throws IOException; - - /** - * Returns the first maxLength bytes of the response body as a string. Note that this does not check - * whether the content type is actually a textual one, but it will use the charset if present in the content - * type header. - * - * @param maxLength The maximum number of bytes to read - * @return The response body - * @throws java.io.IOException - */ - public String getResponseBodyExcerpt(int maxLength) throws IOException; - - /** - * Return the entire response body as a String. - * - * @return the entire response body as a String. - * @throws IOException - */ - public String getResponseBody() throws IOException; - - /** - * Return the request {@link Url}. Note that if the request got redirected, the value of the {@link Url} will be - * the last valid redirect url. - * - * @return the request {@link Url}. - * @throws MalformedURLException - */ - public Url getUrl() throws MalformedURLException; - - /** - * Return the content-type header value. - * - * @return the content-type header value. - */ - public String getContentType(); - - /** - * Return the response header - * - * @return the response header - */ - public String getHeader(String name); - - /** - * Return a {@link List} of the response header value. - * - * @return the response header - */ - public List getHeaders(String name); - - public Headers getHeaders(); - - /** - * Return true if the response redirects to another object. - * - * @return True if the response redirects to another object. - */ - boolean isRedirected(); - - /** - * Subclasses SHOULD implement toString() in a way that identifies the request for logging. - * - * @return The textual representation - */ - public String toString(); - - /** - * Return the list of {@link Cookie}. - */ - public List getCookies(); -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/StringPart.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/StringPart.java deleted file mode 100644 index 861a6c470bc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/StringPart.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client; - -/** - * A string multipart part. - */ -public class StringPart implements Part { - private String name; - private String value; - - public StringPart(String name, String value) { - this.name = name; - this.value = value; - } - - public String getName() { - return name; - } - - public String getValue() { - return value; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyAsyncHttpProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyAsyncHttpProvider.java deleted file mode 100644 index e01c1bd651f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyAsyncHttpProvider.java +++ /dev/null @@ -1,776 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client.providers; - -import org.elasticsearch.util.collect.Multimap; -import org.elasticsearch.util.http.client.*; -import org.elasticsearch.util.http.client.AsyncHandler.STATE; -import org.elasticsearch.util.http.client.Cookie; -import org.elasticsearch.util.http.client.HttpResponseStatus; -import org.elasticsearch.util.http.collection.Pair; -import org.elasticsearch.util.http.multipart.ByteArrayPartSource; -import org.elasticsearch.util.http.multipart.MultipartRequestEntity; -import org.elasticsearch.util.http.multipart.PartSource; -import org.elasticsearch.util.http.url.Url; -import org.elasticsearch.util.http.url.Url.Protocol; -import org.elasticsearch.util.http.util.SslUtils; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.jboss.netty.bootstrap.ClientBootstrap; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBufferOutputStream; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.*; -import org.jboss.netty.channel.group.ChannelGroup; -import org.jboss.netty.channel.group.DefaultChannelGroup; -import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; -import org.jboss.netty.handler.codec.http.*; -import org.jboss.netty.handler.ssl.SslHandler; -import org.jboss.netty.handler.timeout.IdleStateEvent; -import org.jboss.netty.handler.timeout.IdleStateHandler; -import org.jboss.netty.util.HashedWheelTimer; -import org.jboss.netty.util.internal.ConcurrentHashMap; - -import javax.net.ssl.SSLEngine; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.ConnectException; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.URI; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.jboss.netty.channel.Channels.*; - -public class NettyAsyncHttpProvider extends SimpleChannelUpstreamHandler implements AsyncHttpProvider { - - private final static ESLogger log = Loggers.getLogger(NettyAsyncHttpProvider.class); - private final ClientBootstrap bootstrap; - private final static int MAX_BUFFERRED_BYTES = 8192; - - private final AsyncHttpClientConfig config; - - private final ConcurrentHashMap connectionsPool = new ConcurrentHashMap(); - - private volatile int maxConnectionsPerHost; - private final HashedWheelTimer timer = new HashedWheelTimer(); - - private final AtomicBoolean isClose = new AtomicBoolean(false); - - private final NioClientSocketChannelFactory socketChannelFactory; - - private final ChannelGroup openChannels = new DefaultChannelGroup("asyncHttpClient"); - - public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { - socketChannelFactory = new NioClientSocketChannelFactory( - Executors.newCachedThreadPool(), - config.executorService()); - bootstrap = new ClientBootstrap(socketChannelFactory); - this.config = config; - } - - void configure(final boolean useSSL, final ConnectListener cl) { - - bootstrap.setPipelineFactory(new ChannelPipelineFactory() { - - /* @Override */ - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = pipeline(); - - if (useSSL) { - try { - SSLEngine sslEngine = config.getSSLEngine(); - if (sslEngine == null) { - sslEngine = SslUtils.getSSLEngine(); - } - pipeline.addLast("ssl", new SslHandler(sslEngine)); - } catch (Throwable ex) { - cl.future().abort(ex); - } - } - - pipeline.addLast("codec", new HttpClientCodec()); - - if (config.isCompressionEnabled()) { - pipeline.addLast("inflater", new HttpContentDecompressor()); - } - - IdleStateHandler h = new IdleStateHandler(timer, 0, 0, config.getIdleConnectionTimeoutInMs(), TimeUnit.MILLISECONDS) { - @SuppressWarnings("unused") - public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws MalformedURLException { - e.getChannel().close(); - removeFromCache(ctx, e); - } - }; - pipeline.addLast("timeout", h); - pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); - return pipeline; - } - }); - } - - private Channel lookupInCache(Url url) { - Channel channel = connectionsPool.get(url.getBaseUrl()); - if (channel != null) { - /** - * The Channel will eventually be closed by Netty and will becomes invalid. - * We might suffer a memory leak if we don't scan for closed channel. The - * AsyncHttpClientConfig.reaper() will always make sure those are cleared. - */ - if (channel.isOpen()) { - channel.setReadable(true); - } else { - connectionsPool.remove(url.getBaseUrl()); - } - } - return channel; - } - - /** - * Non Blocking connect. - */ - private final static class ConnectListener implements ChannelFutureListener { - - private final AsyncHttpClientConfig config; - private final AsyncHandler asyncHandler; - private final NettyResponseFuture future; - private final HttpRequest nettyRequest; - - private ConnectListener(AsyncHttpClientConfig config, - AsyncHandler asyncHandler, - NettyResponseFuture future, - HttpRequest nettyRequest) { - this.config = config; - this.asyncHandler = asyncHandler; - this.future = future; - this.nettyRequest = nettyRequest; - } - - public NettyResponseFuture future() { - return future; - } - - public final void operationComplete(ChannelFuture f) throws Exception { - try { - executeRequest(f.getChannel(), asyncHandler, config, future, nettyRequest); - } catch (ConnectException ex) { - future.abort(ex); - } - } - - public static class Builder { - private final AsyncHttpClientConfig config; - private final Request request; - private final AsyncHandler asyncHandler; - private NettyResponseFuture future; - - public Builder(AsyncHttpClientConfig config, Request request, AsyncHandler asyncHandler) { - this.config = config; - this.request = request; - this.asyncHandler = asyncHandler; - this.future = null; - } - - public Builder(AsyncHttpClientConfig config, Request request, AsyncHandler asyncHandler, NettyResponseFuture future) { - this.config = config; - this.request = request; - this.asyncHandler = asyncHandler; - this.future = future; - } - - public ConnectListener build() throws IOException { - - Url url = createUrl(request.getUrl()); - HttpRequest nettyRequest = buildRequest(config, request, url); - - if (log.isDebugEnabled()) - log.debug("Executing the doConnect operation: " + asyncHandler); - - if (future == null) { - future = new NettyResponseFuture(url, request, asyncHandler, - nettyRequest, config.getRequestTimeoutInMs()); - } - return new ConnectListener(config, asyncHandler, future, nettyRequest); - } - } - } - - private final static void executeRequest(final Channel channel, - final AsyncHandler asyncHandler, - final AsyncHttpClientConfig config, - final NettyResponseFuture future, - final HttpRequest nettyRequest) throws ConnectException { - - if (!channel.isConnected()) { - throw new ConnectException("Connection refused to " + channel.getRemoteAddress()); - } - - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(future); - channel.write(nettyRequest); - - try { - future.setReaperFuture(config.reaper().schedule(new Callable() { - public Object call() { - if (!future.isDone() && !future.isCancelled()) { - future.abort(new TimeoutException()); - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(ClosedEvent.class); - channel.close(); - } - return null; - } - - }, config.getRequestTimeoutInMs(), TimeUnit.MILLISECONDS)); - } catch (RejectedExecutionException ex) { - future.abort(ex); - } - } - - private final static HttpRequest buildRequest(AsyncHttpClientConfig config, Request request, Url url) throws IOException { - HttpRequest nettyRequest = null; - switch (request.getType()) { - case GET: - nettyRequest = construct(config, request, HttpMethod.GET, url); - break; - case POST: - nettyRequest = construct(config, request, HttpMethod.POST, url); - break; - case DELETE: - nettyRequest = construct(config, request, HttpMethod.DELETE, url); - break; - case PUT: - nettyRequest = construct(config, request, HttpMethod.PUT, url); - break; - case HEAD: - nettyRequest = construct(config, request, HttpMethod.HEAD, url); - break; - } - return nettyRequest; - } - - private final static Url createUrl(String u) { - URI uri = URI.create(u); - final String scheme = uri.getScheme().toLowerCase(); - if (scheme == null || !scheme.equals("http") && !scheme.equals("https")) { - throw new IllegalArgumentException("The URI scheme, of the URI " + u - + ", must be equal (ignoring case) to 'http'"); - } - - String path = uri.getPath(); - if (path == null) { - throw new IllegalArgumentException("The URI path, of the URI " + uri - + ", must be non-null"); - } else if (path.length() > 0 && path.charAt(0) != '/') { - throw new IllegalArgumentException("The URI path, of the URI " + uri - + ". must start with a '/'"); - } - - int port = uri.getPort(); - if (port == -1) - port = scheme.equals("http") ? 80 : 443; - - return new Url(uri.getScheme(), uri.getHost(), port, uri.getPath(), uri.getQuery()); - } - - @SuppressWarnings("deprecation") - private static HttpRequest construct(AsyncHttpClientConfig config, - Request request, - HttpMethod m, - Url url) throws IOException { - String host = url.getHost(); - - if (request.getVirtualHost() != null) { - host = request.getVirtualHost(); - } - - HttpRequest nettyRequest; - String queryString = url.getQueryString(); - - // does this request have a query string - if (queryString != null) { - nettyRequest = new DefaultHttpRequest( - HttpVersion.HTTP_1_1, m, url.getUri()); - } else { - nettyRequest = new DefaultHttpRequest( - HttpVersion.HTTP_1_1, m, url.getPath()); - } - nettyRequest.setHeader(HttpHeaders.Names.HOST, host + ":" + url.getPort()); - - Headers h = request.getHeaders(); - if (h != null) { - Iterator> i = h.iterator(); - Pair p; - while (i.hasNext()) { - p = i.next(); - if ("host".equalsIgnoreCase(p.getFirst())) { - continue; - } - String key = p.getFirst() == null ? "" : p.getFirst(); - String value = p.getSecond() == null ? "" : p.getSecond(); - - nettyRequest.setHeader(key, value); - } - } - - String ka = config.getKeepAlive() ? "keep-alive" : "close"; - nettyRequest.setHeader(HttpHeaders.Names.CONNECTION, ka); - if (config.getProxyServer() != null) { - nettyRequest.setHeader("Proxy-Connection", ka); - } - - if (config.getUserAgent() != null) { - nettyRequest.setHeader("User-Agent", config.getUserAgent()); - } - - if (request.getCookies() != null && !request.getCookies().isEmpty()) { - CookieEncoder httpCookieEncoder = new CookieEncoder(false); - Iterator ic = request.getCookies().iterator(); - Cookie c; - org.jboss.netty.handler.codec.http.Cookie cookie; - while (ic.hasNext()) { - c = ic.next(); - cookie = new DefaultCookie(c.getName(), c.getValue()); - cookie.setPath(c.getPath()); - cookie.setMaxAge(c.getMaxAge()); - cookie.setDomain(c.getDomain()); - httpCookieEncoder.addCookie(cookie); - } - nettyRequest.setHeader(HttpHeaders.Names.COOKIE, httpCookieEncoder.encode()); - } - - if (config.isCompressionEnabled()) { - nettyRequest.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP); - } - - switch (request.getType()) { - case POST: - case PUT: - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, "0"); - if (request.getByteData() != null) { - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(request.getByteData().length)); - nettyRequest.setContent(ChannelBuffers.copiedBuffer(request.getByteData())); - } else if (request.getStringData() != null) { - // TODO: Not sure we need to reconfigure that one. - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(request.getStringData().length())); - nettyRequest.setContent(ChannelBuffers.copiedBuffer(request.getStringData(), "UTF-8")); - } else if (request.getStreamData() != null) { - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(request.getStreamData().available())); - byte[] b = new byte[(int) request.getStreamData().available()]; - request.getStreamData().read(b); - nettyRequest.setContent(ChannelBuffers.copiedBuffer(b)); - } else if (request.getParams() != null) { - StringBuilder sb = new StringBuilder(); - for (final Entry param : request.getParams().entries()) { - sb.append(param.getKey()); - sb.append("="); - sb.append(param.getValue()); - sb.append("&"); - } - sb.deleteCharAt(sb.length() - 1); - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(sb.length())); - nettyRequest.setContent(ChannelBuffers.copiedBuffer(sb.toString().getBytes())); - - if (request.getHeaders().getHeaderValues(Headers.CONTENT_TYPE).isEmpty() - && request.getHeaders().getHeaderValue(Headers.CONTENT_TYPE) == null) { - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/x-www-form-urlencoded"); - } - - } else if (request.getParts() != null) { - int lenght = computeAndSetContentLength(request, nettyRequest); - - if (lenght == -1) { - lenght = MAX_BUFFERRED_BYTES; - } - - MultipartRequestEntity mre = createMultipartRequestEntity(request.getParts(), request.getParams()); - - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType()); - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(mre.getContentLength())); - - ChannelBuffer b = ChannelBuffers.dynamicBuffer((int) lenght); - mre.writeRequest(new ChannelBufferOutputStream(b)); - nettyRequest.setContent(b); - } else if (request.getEntityWriter() != null) { - int lenght = computeAndSetContentLength(request, nettyRequest); - - if (lenght == -1) { - lenght = MAX_BUFFERRED_BYTES; - } - - ChannelBuffer b = ChannelBuffers.dynamicBuffer((int) lenght); - request.getEntityWriter().writeEntity(new ChannelBufferOutputStream(b)); - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, b.writerIndex()); - nettyRequest.setContent(b); - } - break; - } - - if (nettyRequest.getHeader(HttpHeaders.Names.CONTENT_TYPE) == null) { - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, "txt/html; charset=utf-8"); - } - - if (log.isDebugEnabled()) - log.debug("Constructed request: " + nettyRequest); - return nettyRequest; - } - - public void close() { - isClose.set(true); - connectionsPool.clear(); - openChannels.close(); - timer.stop(); - config.reaper().shutdown(); - config.executorService().shutdown(); - socketChannelFactory.releaseExternalResources(); - bootstrap.releaseExternalResources(); - } - - /* @Override */ - - public Response prepareResponse(final HttpResponseStatus status, - final HttpResponseHeaders headers, - final Collection> bodyParts) { - return new NettyAsyncResponse(status, headers, bodyParts); - } - - /* @Override */ - - public Future execute(final Request request, final AsyncHandler asyncHandler) throws IOException { - return doConnect(request, asyncHandler, null); - } - - private void execute(final Request request, final NettyResponseFuture f) throws IOException { - doConnect(request, f.getAsyncHandler(), f); - return; - } - - private Future doConnect(final Request request, final AsyncHandler asyncHandler, NettyResponseFuture f) throws IOException { - - if (isClose.get()) { - throw new IOException("Closed"); - } - - if (connectionsPool.size() >= config.getMaxTotalConnections()) { - throw new IOException("Too many connections"); - } - Url url = createUrl(request.getUrl()); - - if (log.isDebugEnabled()) - log.debug("Lookup cache: " + url.toString()); - - Channel channel = lookupInCache(url); - if (channel != null && channel.isOpen()) { - HttpRequest nettyRequest = buildRequest(config, request, url); - if (f == null) { - f = new NettyResponseFuture(url, request, asyncHandler, - nettyRequest, config.getRequestTimeoutInMs()); - } - executeRequest(channel, asyncHandler, config, f, nettyRequest); - return f; - } - ConnectListener c = new ConnectListener.Builder(config, request, asyncHandler, f).build(); - configure(url.getProtocol().compareTo(Protocol.HTTPS) == 0, c); - - ChannelFuture channelFuture = null; - try { - if (config.getProxyServer() == null) { - channelFuture = bootstrap.connect(new InetSocketAddress(url.getHost(), url.getPort())); - } else { - channelFuture = bootstrap.connect( - new InetSocketAddress(config.getProxyServer().getHost(), config.getProxyServer().getPort())); - } - bootstrap.setOption("connectTimeout", (int) config.getConnectionTimeoutInMs()); - } catch (Throwable t) { - log.error(t.getMessage(), t); - c.future().abort(t.getCause()); - return c.future(); - } - channelFuture.addListener(c); - openChannels.add(channelFuture.getChannel()); - return c.future(); - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - /** - * Discard in memory bytes if the HttpContent.interrupt() has been invoked. - */ - if (ctx.getAttachment() instanceof DiscardEvent) { - ctx.getChannel().setReadable(false); - return; - } - - NettyResponseFuture future = (NettyResponseFuture) ctx.getAttachment(); - HttpRequest nettyRequest = future.getNettyRequest(); - AsyncHandler handler = future.getAsyncHandler(); - - try { - if (e.getMessage() instanceof HttpResponse) { - HttpResponse response = (HttpResponse) e.getMessage(); - // Required if there is some trailing headers. - future.setHttpResponse(response); - - String ka = response.getHeader("Connection"); - future.setKeepAlive(ka == null || ka.toLowerCase().equals("keep-alive")); - - if (config.isRedirectEnabled() - && (response.getStatus().getCode() == 302 || response.getStatus().getCode() == 301)) { - - if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) { - - String location = response.getHeader(HttpHeaders.Names.LOCATION); - if (location.startsWith("/")) { - location = future.getUrl().getBaseUrl() + location; - } - - Url url = createUrl(location); - RequestBuilder builder = new RequestBuilder(future.getRequest()); - future.setUrl(url); - - ctx.setAttachment(new DiscardEvent()); - try { - ctx.getChannel().setReadable(false); - } catch (Exception ex) { - if (log.isTraceEnabled()) { - log.trace(ex.getMessage(), ex); - } - } - execute(builder.setUrl(url.toString()).build(), future); - return; - } else { - throw new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()); - } - } - - if (log.isDebugEnabled()) { - log.debug("Status: " + response.getStatus()); - log.debug("Version: " + response.getProtocolVersion()); - log.debug("\""); - if (!response.getHeaderNames().isEmpty()) { - for (String name : response.getHeaderNames()) { - log.debug("Header: " + name + " = " + response.getHeaders(name)); - } - log.debug("\""); - } - } - - if (updateStatusAndInterrupt(handler, new ResponseStatus(future.getUrl(), response, this))) { - finishUpdate(future, ctx); - return; - } else if (updateHeadersAndInterrupt(handler, new ResponseHeaders(future.getUrl(), response, this))) { - finishUpdate(future, ctx); - return; - } else if (!response.isChunked()) { - updateBodyAndInterrupt(handler, new ResponseBodyPart(future.getUrl(), response, this)); - finishUpdate(future, ctx); - return; - } - - if (response.getStatus().getCode() != 200 || nettyRequest.getMethod().equals(HttpMethod.HEAD)) { - markAsDoneAndCacheConnection(future, ctx.getChannel()); - } - - } else if (e.getMessage() instanceof HttpChunk) { - HttpChunk chunk = (HttpChunk) e.getMessage(); - - if (handler != null) { - if (updateBodyAndInterrupt(handler, new ResponseBodyPart(future.getUrl(), null, this, chunk)) || chunk.isLast()) { - if (chunk instanceof HttpChunkTrailer) { - updateHeadersAndInterrupt(handler, new ResponseHeaders(future.getUrl(), - future.getHttpResponse(), this, (HttpChunkTrailer) chunk)); - } - finishUpdate(future, ctx); - } - } - } - } catch (Exception t) { - future.abort(t); - finishUpdate(future, ctx); - throw t; - } - } - - public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { - if (log.isDebugEnabled()) - log.debug("Channel closed: " + e.getState().toString()); - if (!isClose.get() && ctx.getAttachment() instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) ctx.getAttachment(); - - if (future != null && !future.isDone() && !future.isCancelled()) { - future.getAsyncHandler().onThrowable(new IOException("No response received. Connection timed out")); - } - } - removeFromCache(ctx, e); - ctx.sendUpstream(e); - } - - private void removeFromCache(ChannelHandlerContext ctx, ChannelEvent e) throws MalformedURLException { - if (ctx.getAttachment() instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) ctx.getAttachment(); - connectionsPool.remove(future.getUrl()); - } - } - - private void markAsDoneAndCacheConnection(final NettyResponseFuture future, final Channel channel) throws MalformedURLException { - if (future.getKeepAlive() && maxConnectionsPerHost++ < config.getMaxConnectionPerHost()) { - connectionsPool.put(future.getUrl().getBaseUrl(), channel); - } else { - connectionsPool.remove(future.getUrl()); - } - future.done(); - } - - private void finishUpdate(NettyResponseFuture future, ChannelHandlerContext ctx) throws IOException { - ctx.setAttachment(new DiscardEvent()); - markAsDoneAndCacheConnection(future, ctx.getChannel()); - - // Catch any unexpected exception when marking the channel. - try { - ctx.getChannel().setReadable(false); - } catch (Exception ex) { - if (log.isTraceEnabled()) { - log.trace(ex.getMessage(), ex); - } - } - } - - @SuppressWarnings("unchecked") - private final boolean updateStatusAndInterrupt(AsyncHandler handler, HttpResponseStatus c) throws Exception { - return (handler.onStatusReceived(c) == STATE.CONTINUE ? false : true); - } - - @SuppressWarnings("unchecked") - private final boolean updateHeadersAndInterrupt(AsyncHandler handler, HttpResponseHeaders c) throws Exception { - return (handler.onHeadersReceived(c) == STATE.CONTINUE ? false : true); - } - - @SuppressWarnings("unchecked") - private final boolean updateBodyAndInterrupt(AsyncHandler handler, HttpResponseBodyPart c) throws Exception { - return (handler.onBodyPartReceived(c) == STATE.CONTINUE ? false : true); - } - - //Simple marker for stopping publishing bytes. - - private final static class DiscardEvent { - } - - //Simple marker for closed events - - private final static class ClosedEvent { - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - Channel ch = e.getChannel(); - Throwable cause = e.getCause(); - - if (log.isDebugEnabled()) - log.debug("I/O Exception during read or doConnect: ", e.getCause()); - if (ctx.getAttachment() instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) ctx.getAttachment(); - - if (future != null) { - future.getAsyncHandler().onThrowable(cause); - } - } - - if (log.isDebugEnabled()) { - log.debug(e.toString()); - log.debug(ch.toString()); - } - } - - private final static int computeAndSetContentLength(Request request, HttpRequest r) { - int lenght = (int) request.getLength(); - if (lenght == -1 && r.getHeader(HttpHeaders.Names.CONTENT_LENGTH) != null) { - lenght = Integer.valueOf(r.getHeader(HttpHeaders.Names.CONTENT_LENGTH)); - } - - if (lenght != -1) { - r.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(lenght)); - } - return lenght; - } - - /** - * Map CommonsHttp Method to Netty Method. - * - * @param type - * @return - */ - private final static HttpMethod map(RequestType type) { - switch (type) { - case GET: - return HttpMethod.GET; - case POST: - return HttpMethod.POST; - case DELETE: - return HttpMethod.DELETE; - case PUT: - return HttpMethod.PUT; - case HEAD: - return HttpMethod.HEAD; - default: - throw new IllegalStateException(); - } - } - - /** - * This is quite ugly as our internal names are duplicated, but we build on top of HTTP Client implementation. - * - * @param params - * @param methodParams - * @return - * @throws java.io.FileNotFoundException - */ - private final static MultipartRequestEntity createMultipartRequestEntity(List params, Multimap methodParams) throws FileNotFoundException { - org.elasticsearch.util.http.multipart.Part[] parts = new org.elasticsearch.util.http.multipart.Part[params.size()]; - int i = 0; - - for (Part part : params) { - if (part instanceof StringPart) { - parts[i] = new org.elasticsearch.util.http.multipart.StringPart(part.getName(), - ((StringPart) part).getValue(), - "UTF-8"); - } else if (part instanceof FilePart) { - parts[i] = new org.elasticsearch.util.http.multipart.FilePart(part.getName(), - ((FilePart) part).getFile(), - ((FilePart) part).getMimeType(), - ((FilePart) part).getCharSet()); - - } else if (part instanceof ByteArrayPart) { - PartSource source = new ByteArrayPartSource(((ByteArrayPart) part).getFileName(), ((ByteArrayPart) part).getData()); - parts[i] = new org.elasticsearch.util.http.multipart.FilePart(part.getName(), - source, - ((ByteArrayPart) part).getMimeType(), - ((ByteArrayPart) part).getCharSet()); - - } else if (part == null) { - throw new NullPointerException("Part cannot be null"); - } else { - throw new IllegalArgumentException(String.format("Unsupported part type for multipart parameter %s", - part.getName())); - } - ++i; - } - return new MultipartRequestEntity(parts, methodParams); - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyAsyncResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyAsyncResponse.java deleted file mode 100644 index 6b2ce6c35c2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyAsyncResponse.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client.providers; - -import org.elasticsearch.util.http.client.*; -import org.elasticsearch.util.http.collection.Pair; -import org.elasticsearch.util.http.url.Url; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBufferInputStream; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.handler.codec.http.HttpResponse; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.util.*; - -/** - * Wrapper around the {@link org.elasticsearch.util.http.client.Response} API. - */ -public class NettyAsyncResponse implements Response { - private final Url url; - private final Collection> bodyParts; - private final HttpResponseHeaders headers; - private final HttpResponseStatus status; - private final List cookies = new ArrayList(); - - public NettyAsyncResponse(HttpResponseStatus status, - HttpResponseHeaders headers, - Collection> bodyParts) { - - this.status = status; - this.headers = headers; - this.bodyParts = bodyParts; - url = status.getUrl(); - } - - /* @Override */ - - public int getStatusCode() { - return status.getStatusCode(); - } - - /* @Override */ - - public String getStatusText() { - return status.getStatusText(); - } - - /* @Override */ - - public String getResponseBody() throws IOException { - String contentType = getContentType(); - String charset = "UTF-8"; - if (contentType != null) { - for (String part : contentType.split(";")) { - if (part.startsWith("charset=")) { - charset = part.substring("charset=".length()); - } - } - } - return contentToString(charset); - } - - String contentToString(String charset) throws UnsupportedEncodingException { - StringBuilder b = new StringBuilder(); - for (HttpResponseBodyPart bp : bodyParts) { - b.append(new String(bp.getBodyPartBytes(), charset)); - } - return b.toString(); - } - - /* @Override */ - - public InputStream getResponseBodyAsStream() throws IOException { - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - for (HttpResponseBodyPart bp : bodyParts) { - // Ugly. TODO - // (1) We must remove the downcast, - // (2) we need a CompositeByteArrayInputStream to avoid - // copying the bytes. - if (bp.getClass().isAssignableFrom(ResponseBodyPart.class)) { - buf.writeBytes(bp.getBodyPartBytes()); - } - } - return new ChannelBufferInputStream(buf); - } - - /* @Override */ - - public String getResponseBodyExcerpt(int maxLength) throws IOException { - String contentType = getContentType(); - String charset = "UTF-8"; - if (contentType != null) { - for (String part : contentType.split(";")) { - if (part.startsWith("charset=")) { - charset = part.substring("charset=".length()); - } - } - } - String response = contentToString(charset); - return response.length() <= maxLength ? response : response.substring(0, maxLength); - } - - /* @Override */ - - public Url getUrl() throws MalformedURLException { - return url; - } - - /* @Override */ - - public String getContentType() { - return headers.getHeaders().getHeaderValue("Content-Type"); - } - - /* @Override */ - - public String getHeader(String name) { - return headers.getHeaders().getHeaderValue(name); - } - - /* @Override */ - - public List getHeaders(String name) { - return headers.getHeaders().getHeaderValues(name); - } - - /* @Override */ - - public Headers getHeaders() { - return headers.getHeaders(); - } - - /* @Override */ - - public boolean isRedirected() { - return (status.getStatusCode() >= 300) && (status.getStatusCode() <= 399); - } - - /* @Override */ - - public List getCookies() { - if (cookies.isEmpty()) { - Iterator> i = headers.getHeaders().iterator(); - Pair p; - while (i.hasNext()) { - p = i.next(); - if (p.getFirst().equalsIgnoreCase("Set-Cookie")) { - String[] fields = p.getSecond().split(";\\s*"); - String[] cookieValue = fields[0].split("="); - String name = cookieValue[0]; - String value = cookieValue[1]; - String expires = "-1"; - String path = null; - String domain = null; - boolean secure = false; // Parse each field - for (int j = 1; j < fields.length; j++) { - if ("secure".equalsIgnoreCase(fields[j])) { - secure = true; - } else if (fields[j].indexOf('=') > 0) { - String[] f = fields[j].split("="); - if ("expires".equalsIgnoreCase(f[0])) { - expires = f[1]; - } else if ("domain".equalsIgnoreCase(f[0])) { - domain = f[1]; - } else if ("path".equalsIgnoreCase(f[0])) { - path = f[1]; - } - } - } - cookies.add(new Cookie(domain, name, value, path, Integer.valueOf(expires), secure)); - } - } - } - return Collections.unmodifiableList(cookies); - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyResponseFuture.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyResponseFuture.java deleted file mode 100755 index e26f3685eb3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/NettyResponseFuture.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client.providers; - -import org.elasticsearch.util.http.client.AsyncHandler; -import org.elasticsearch.util.http.client.FutureImpl; -import org.elasticsearch.util.http.client.Request; -import org.elasticsearch.util.http.url.Url; -import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.codec.http.HttpResponse; - -import java.net.MalformedURLException; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -/** - * A {@link Future} that can be used to track when an asynchronous HTTP request has been fully processed. - * - * @param - */ -public final class NettyResponseFuture implements FutureImpl { - - private final CountDownLatch latch = new CountDownLatch(1); - private final AtomicBoolean isDone = new AtomicBoolean(false); - private final AtomicBoolean isCancelled = new AtomicBoolean(false); - private final AsyncHandler asyncHandler; - private final int responseTimeoutInMs; - private final Request request; - private final HttpRequest nettyRequest; - private final AtomicReference content = new AtomicReference(); - private Url url; - private boolean keepAlive = true; - private HttpResponse httpResponse; - private final AtomicReference exEx = new AtomicReference(); - private final AtomicInteger redirectCount = new AtomicInteger(); - private Future reaperFuture; - - public NettyResponseFuture(Url url, - Request request, - AsyncHandler asyncHandler, - HttpRequest nettyRequest, - int responseTimeoutInMs) { - - this.asyncHandler = asyncHandler; - this.responseTimeoutInMs = responseTimeoutInMs; - this.request = request; - this.nettyRequest = nettyRequest; - this.url = url; - } - - public Url getUrl() throws MalformedURLException { - return url; - } - - public void setUrl(Url url) { - this.url = url; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean isDone() { - return isDone.get(); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean isCancelled() { - return isCancelled.get(); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean cancel(boolean force) { - latch.countDown(); - isCancelled.set(true); - return true; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public V get() throws InterruptedException, ExecutionException { - try { - return get(responseTimeoutInMs, TimeUnit.MILLISECONDS); - } catch (TimeoutException e) { - throw new RuntimeException(e); - } - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException, ExecutionException { - if (!isDone() && !isCancelled()) { - if (!latch.await(l, tu)) { - isCancelled.set(true); - TimeoutException te = new TimeoutException("No response received"); - onThrowable(te); - throw te; - } - isDone.set(true); - - if (exEx.get() != null) { - throw exEx.getAndSet(null); - } - } - return (V) getContent(); - } - - private void onThrowable(Throwable t) { - asyncHandler.onThrowable(t); - } - - V getContent() { - if (content.get() == null) { - try { - content.set(asyncHandler.onCompleted()); - } catch (Throwable ex) { - onThrowable(ex); - throw new RuntimeException(ex); - } - } - return content.get(); - } - - public final void done() { - if (exEx.get() != null) { - return; - } - if (reaperFuture != null) reaperFuture.cancel(true); - isDone.set(true); - getContent(); - latch.countDown(); - } - - public final void abort(final Throwable t) { - if (isDone.get() || isCancelled.get()) return; - - if (reaperFuture != null) reaperFuture.cancel(true); - - if (exEx.get() == null) { - exEx.set(new ExecutionException(t)); - } - asyncHandler.onThrowable(t); - isDone.set(true); - latch.countDown(); - } - - public final Request getRequest() { - return request; - } - - public final HttpRequest getNettyRequest() { - return nettyRequest; - } - - public final AsyncHandler getAsyncHandler() { - return asyncHandler; - } - - public final boolean getKeepAlive() { - return keepAlive; - } - - public final void setKeepAlive(final boolean keepAlive) { - this.keepAlive = keepAlive; - } - - public final HttpResponse getHttpResponse() { - return httpResponse; - } - - public final void setHttpResponse(final HttpResponse httpResponse) { - this.httpResponse = httpResponse; - } - - public int incrementAndGetCurrentRedirectCount() { - return redirectCount.incrementAndGet(); - } - - public void setReaperFuture(Future reaperFuture) { - this.reaperFuture = reaperFuture; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseBodyPart.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseBodyPart.java deleted file mode 100644 index 435803139ba..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseBodyPart.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client.providers; - -import org.elasticsearch.util.http.client.AsyncHttpProvider; -import org.elasticsearch.util.http.client.HttpResponseBodyPart; -import org.elasticsearch.util.http.url.Url; -import org.jboss.netty.handler.codec.http.HttpChunk; -import org.jboss.netty.handler.codec.http.HttpResponse; - -/** - * A callback class used when an HTTP response body is received. - */ -public class ResponseBodyPart extends HttpResponseBodyPart { - - private final HttpChunk chunk; - - public ResponseBodyPart(Url url, HttpResponse response, AsyncHttpProvider provider) { - super(url, response, provider); - this.chunk = null; - } - - public ResponseBodyPart(Url url, HttpResponse response, AsyncHttpProvider provider, HttpChunk chunk) { - super(url, response, provider); - this.chunk = chunk; - } - - /** - * Return the response body's part bytes received. - * - * @return the response body's part bytes received. - */ - public byte[] getBodyPartBytes() { - if (chunk != null) { - return chunk.getContent().array(); - } else { - return response.getContent().array(); - } - } - - protected HttpChunk chunk() { - return chunk; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseHeaders.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseHeaders.java deleted file mode 100644 index 34766b274d2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseHeaders.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.client.providers; - -import org.elasticsearch.util.http.client.AsyncHttpProvider; -import org.elasticsearch.util.http.client.Headers; -import org.elasticsearch.util.http.client.HttpResponseHeaders; -import org.elasticsearch.util.http.url.Url; -import org.jboss.netty.handler.codec.http.HttpChunkTrailer; -import org.jboss.netty.handler.codec.http.HttpResponse; - -/** - * A class that represent the HTTP headers. - */ -public class ResponseHeaders extends HttpResponseHeaders { - - private final HttpChunkTrailer trailingHeaders; - - public ResponseHeaders(Url url, HttpResponse response, AsyncHttpProvider provider) { - super(url, response, provider, false); - this.trailingHeaders = null; - - } - - public ResponseHeaders(Url url, HttpResponse response, AsyncHttpProvider provider, HttpChunkTrailer traillingHeaders) { - super(url, response, provider, true); - this.trailingHeaders = traillingHeaders; - } - - /** - * Return the HTTP header - * - * @return an {@link org.elasticsearch.util.http.client.Headers} - */ - public Headers getHeaders() { - Headers h = new Headers(); - for (String s : response.getHeaderNames()) { - for (String header : response.getHeaders(s)) { - h.add(s, header); - } - } - - if (trailingHeaders != null && trailingHeaders.getHeaderNames().size() > 0) { - for (final String s : trailingHeaders.getHeaderNames()) { - for (String header : response.getHeaders(s)) { - h.add(s, header); - } - } - } - - return Headers.unmodifiableHeaders(h); - } - -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseStatus.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseStatus.java deleted file mode 100644 index 9bf763b6b2b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/client/providers/ResponseStatus.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.client.providers; - -import org.elasticsearch.util.http.client.AsyncHttpProvider; -import org.elasticsearch.util.http.client.HttpResponseStatus; -import org.elasticsearch.util.http.url.Url; -import org.jboss.netty.handler.codec.http.HttpResponse; - -/** - * A class that represent the HTTP response' status line (code + text) - */ -public class ResponseStatus extends HttpResponseStatus { - - public ResponseStatus(Url url, HttpResponse response, AsyncHttpProvider provider) { - super(url, response, provider); - } - - /** - * Return the response status code - * - * @return the response status code - */ - public int getStatusCode() { - return response.getStatus().getCode(); - } - - /** - * Return the response status text - * - * @return the response status text - */ - public String getStatusText() { - return response.getStatus().getReasonPhrase(); - } - - @Override - public String getProtocolName() { - return response.getProtocolVersion().getProtocolName(); - } - - @Override - public int getProtocolMajorVersion() { - return response.getProtocolVersion().getMajorVersion(); - } - - @Override - public int getProtocolMinorVersion() { - return response.getProtocolVersion().getMinorVersion(); - } - - @Override - public String getProtocolText() { - return response.getProtocolVersion().getText(); - } - -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/collection/Pair.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/collection/Pair.java deleted file mode 100644 index 236e2e64a07..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/collection/Pair.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.collection; - -import java.io.Serializable; - -public class Pair implements Serializable { - private static final long serialVersionUID = -4403264592023348398L; - private final FirstType firstValue; - private final SecondType secondValue; - - public Pair(FirstType v1, SecondType v2) { - firstValue = v1; - secondValue = v2; - } - - public FirstType getFirst() { - return firstValue; - } - - public SecondType getSecond() { - return secondValue; - } - - public String toString() { - return "Pair(" + firstValue + ", " + secondValue + ")"; - } - - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final Pair pair = (Pair) o; - - return (firstValue != null ? firstValue.equals(pair.firstValue) : pair.firstValue == null) - && (secondValue != null ? secondValue.equals(pair.secondValue) : pair.secondValue == null); - - } - - public int hashCode() { - int result; - result = (firstValue != null ? firstValue.hashCode() : 0); - result = 29 * result + (secondValue != null ? secondValue.hashCode() : 0); - return result; - } - - public static Pair of(K k, V v) { - return new Pair(k, v); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/ByteArrayPartSource.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/ByteArrayPartSource.java deleted file mode 100644 index 84b129c0c02..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/ByteArrayPartSource.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public class ByteArrayPartSource implements PartSource { - - /** - * Name of the source file. - */ - private String fileName; - - /** - * Byte array of the source file. - */ - private byte[] bytes; - - /** - * Constructor for ByteArrayPartSource. - * - * @param fileName the name of the file these bytes represent - * @param bytes the content of this part - */ - public ByteArrayPartSource(String fileName, byte[] bytes) { - - this.fileName = fileName; - this.bytes = bytes; - - } - - /** - * @see PartSource#getLength() - */ - public long getLength() { - return bytes.length; - } - - /** - * @see PartSource#getFileName() - */ - public String getFileName() { - return fileName; - } - - /** - * @see PartSource#createInputStream() - */ - public InputStream createInputStream() throws IOException { - return new ByteArrayInputStream(bytes); - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/FilePart.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/FilePart.java deleted file mode 100644 index 1f3bcaf755d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/FilePart.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; - -import java.io.*; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public class FilePart extends PartBase { - - /** - * Default content encoding of file attachments. - */ - public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream"; - - /** - * Default charset of file attachments. - */ - public static final String DEFAULT_CHARSET = "ISO-8859-1"; - - /** - * Default transfer encoding of file attachments. - */ - public static final String DEFAULT_TRANSFER_ENCODING = "binary"; - - /** - * Log object for this class. - */ - private final static ESLogger LOG = Loggers.getLogger(FilePart.class); - - /** - * Attachment's file name - */ - protected static final String FILE_NAME = "; filename="; - - /** - * Attachment's file name as a byte array - */ - private static final byte[] FILE_NAME_BYTES = - MultipartEncodingUtil.getAsciiBytes(FILE_NAME); - - /** - * Source of the file part. - */ - private PartSource source; - - /** - * FilePart Constructor. - * - * @param name the name for this part - * @param partSource the source for this part - * @param contentType the content type for this part, if null the - * {@link #DEFAULT_CONTENT_TYPE default} is used - * @param charset the charset encoding for this part, if null the - * {@link #DEFAULT_CHARSET default} is used - */ - public FilePart(String name, PartSource partSource, String contentType, String charset) { - - super( - name, - contentType == null ? DEFAULT_CONTENT_TYPE : contentType, - charset == null ? "ISO-8859-1" : charset, - DEFAULT_TRANSFER_ENCODING - ); - - if (partSource == null) { - throw new IllegalArgumentException("Source may not be null"); - } - this.source = partSource; - } - - /** - * FilePart Constructor. - * - * @param name the name for this part - * @param partSource the source for this part - */ - public FilePart(String name, PartSource partSource) { - this(name, partSource, null, null); - } - - /** - * FilePart Constructor. - * - * @param name the name of the file part - * @param file the file to post - * @throws java.io.FileNotFoundException if the file is not a normal - * file or if it is not readable. - */ - public FilePart(String name, File file) - throws FileNotFoundException { - this(name, new FilePartSource(file), null, null); - } - - /** - * FilePart Constructor. - * - * @param name the name of the file part - * @param file the file to post - * @param contentType the content type for this part, if null the - * {@link #DEFAULT_CONTENT_TYPE default} is used - * @param charset the charset encoding for this part, if null the - * {@link #DEFAULT_CHARSET default} is used - * @throws FileNotFoundException if the file is not a normal - * file or if it is not readable. - */ - public FilePart(String name, File file, String contentType, String charset) - throws FileNotFoundException { - this(name, new FilePartSource(file), contentType, charset); - } - - /** - * FilePart Constructor. - * - * @param name the name of the file part - * @param fileName the file name - * @param file the file to post - * @throws FileNotFoundException if the file is not a normal - * file or if it is not readable. - */ - public FilePart(String name, String fileName, File file) - throws FileNotFoundException { - this(name, new FilePartSource(fileName, file), null, null); - } - - /** - * FilePart Constructor. - * - * @param name the name of the file part - * @param fileName the file name - * @param file the file to post - * @param contentType the content type for this part, if null the - * {@link #DEFAULT_CONTENT_TYPE default} is used - * @param charset the charset encoding for this part, if null the - * {@link #DEFAULT_CHARSET default} is used - * @throws FileNotFoundException if the file is not a normal - * file or if it is not readable. - */ - public FilePart(String name, String fileName, File file, String contentType, String charset) - throws FileNotFoundException { - this(name, new FilePartSource(fileName, file), contentType, charset); - } - - /** - * Write the disposition header to the output stream - * - * @param out The output stream - * @throws java.io.IOException If an IO problem occurs - */ - protected void sendDispositionHeader(OutputStream out) - throws IOException { - LOG.trace("enter sendDispositionHeader(OutputStream out)"); - super.sendDispositionHeader(out); - String filename = this.source.getFileName(); - if (filename != null) { - out.write(FILE_NAME_BYTES); - out.write(QUOTE_BYTES); - out.write(MultipartEncodingUtil.getAsciiBytes(filename)); - out.write(QUOTE_BYTES); - } - } - - /** - * Write the data in "source" to the specified stream. - * - * @param out The output stream. - * @throws IOException if an IO problem occurs. - */ - protected void sendData(OutputStream out) throws IOException { - LOG.trace("enter sendData(OutputStream out)"); - if (lengthOfData() == 0) { - - // this file contains no data, so there is nothing to send. - // we don't want to create a zero length buffer as this will - // cause an infinite loop when reading. - LOG.debug("No data to send."); - return; - } - - byte[] tmp = new byte[4096]; - InputStream instream = source.createInputStream(); - try { - int len; - while ((len = instream.read(tmp)) >= 0) { - out.write(tmp, 0, len); - } - } finally { - // we're done with the stream, close it - instream.close(); - } - } - - /** - * Returns the source of the file part. - * - * @return The source. - */ - protected PartSource getSource() { - LOG.trace("enter getSource()"); - return this.source; - } - - /** - * Return the length of the data. - * - * @return The length. - * @throws IOException if an IO problem occurs - */ - protected long lengthOfData() throws IOException { - LOG.trace("enter lengthOfData()"); - return source.getLength(); - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/FilePartSource.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/FilePartSource.java deleted file mode 100644 index fe62676b97f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/FilePartSource.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -import java.io.*; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public class FilePartSource implements PartSource { - - /** - * File part file. - */ - private File file = null; - - /** - * File part file name. - */ - private String fileName = null; - - /** - * Constructor for FilePartSource. - * - * @param file the FilePart source File. - * @throws java.io.FileNotFoundException if the file does not exist or - * cannot be read - */ - public FilePartSource(File file) throws FileNotFoundException { - this.file = file; - if (file != null) { - if (!file.isFile()) { - throw new FileNotFoundException("File is not a normal file."); - } - if (!file.canRead()) { - throw new FileNotFoundException("File is not readable."); - } - this.fileName = file.getName(); - } - } - - /** - * Constructor for FilePartSource. - * - * @param fileName the file name of the FilePart - * @param file the source File for the FilePart - * @throws FileNotFoundException if the file does not exist or - * cannot be read - */ - public FilePartSource(String fileName, File file) - throws FileNotFoundException { - this(file); - if (fileName != null) { - this.fileName = fileName; - } - } - - /** - * Return the length of the file - * - * @return the length of the file. - * @see PartSource#getLength() - */ - public long getLength() { - if (this.file != null) { - return this.file.length(); - } else { - return 0; - } - } - - /** - * Return the current filename - * - * @return the filename. - * @see PartSource#getFileName() - */ - public String getFileName() { - return (fileName == null) ? "noname" : fileName; - } - - /** - * Return a new {@link java.io.FileInputStream} for the current filename. - * - * @return the new input stream. - * @throws java.io.IOException If an IO problem occurs. - * @see PartSource#createInputStream() - */ - public InputStream createInputStream() throws IOException { - if (this.file != null) { - return new FileInputStream(this.file); - } else { - return new ByteArrayInputStream(new byte[]{}); - } - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/MultipartEncodingUtil.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/MultipartEncodingUtil.java deleted file mode 100644 index 70e0828cf72..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/MultipartEncodingUtil.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; - -import java.io.UnsupportedEncodingException; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public class MultipartEncodingUtil { - - /** - * Log object for this class. - */ - private final static ESLogger LOG = Loggers.getLogger(MultipartEncodingUtil.class); - - public static byte[] getAsciiBytes(String data) { - try { - return data.getBytes("US-ASCII"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - - public static String getAsciiString(final byte[] data) { - if (data == null) { - throw new IllegalArgumentException("Parameter may not be null"); - } - - try { - return new String(data, "US-ASCII"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - - public static byte[] getBytes(final String data, String charset) { - - if (data == null) { - throw new IllegalArgumentException("data may not be null"); - } - - if (charset == null || charset.length() == 0) { - throw new IllegalArgumentException("charset may not be null or empty"); - } - - try { - return data.getBytes(charset); - } catch (UnsupportedEncodingException e) { - - if (LOG.isDebugEnabled()) { - LOG.warn("Unsupported encoding: " + charset + ". System encoding used."); - } - - return data.getBytes(); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/MultipartRequestEntity.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/MultipartRequestEntity.java deleted file mode 100644 index 799acc3632e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/MultipartRequestEntity.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -import org.elasticsearch.util.collect.ArrayListMultimap; -import org.elasticsearch.util.collect.Multimap; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Random; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public class MultipartRequestEntity implements RequestEntity { - - private final static ESLogger log = Loggers.getLogger(MultipartRequestEntity.class); - - /** - * The Content-Type for multipart/form-data. - */ - private static final String MULTIPART_FORM_CONTENT_TYPE = "multipart/form-data"; - - /** - * The pool of ASCII chars to be used for generating a multipart boundary. - */ - private static byte[] MULTIPART_CHARS = MultipartEncodingUtil.getAsciiBytes( - "-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); - - /** - * Generates a random multipart boundary string. - * - * @return - */ - private static byte[] generateMultipartBoundary() { - Random rand = new Random(); - byte[] bytes = new byte[rand.nextInt(11) + 30]; // a random size from 30 to 40 - for (int i = 0; i < bytes.length; i++) { - bytes[i] = MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]; - } - return bytes; - } - - /** - * The MIME parts as set by the constructor - */ - protected Part[] parts; - - private byte[] multipartBoundary; - - private Multimap methodParams; - - /** - * Creates a new multipart entity containing the given parts. - * - * @param parts The parts to include. - * @param methodParams The params of the HttpMethod using this entity. - */ - public MultipartRequestEntity(Part[] parts, Multimap methodParams) { - if (parts == null) { - throw new IllegalArgumentException("parts cannot be null"); - } - if (methodParams == null) { - methodParams = ArrayListMultimap.create(); - } - this.parts = parts; - this.methodParams = methodParams; - } - - /** - * Returns the MIME boundary string that is used to demarcate boundaries of - * this part. The first call to this method will implicitly create a new - * boundary string. To create a boundary string first the - * HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise - * a random one is generated. - * - * @return The boundary string of this entity in ASCII encoding. - */ - protected byte[] getMultipartBoundary() { - if (multipartBoundary == null) { - String temp = methodParams.get("").isEmpty() ? null : methodParams.get("").iterator().next(); - if (temp != null) { - multipartBoundary = MultipartEncodingUtil.getAsciiBytes(temp); - } else { - multipartBoundary = generateMultipartBoundary(); - } - } - return multipartBoundary; - } - - /** - * Returns true if all parts are repeatable, false otherwise. - */ - public boolean isRepeatable() { - for (int i = 0; i < parts.length; i++) { - if (!parts[i].isRepeatable()) { - return false; - } - } - return true; - } - - /* (non-Javadoc) - * @see org.apache.commons.httpclient.methods.RequestEntity#writeRequest(java.io.OutputStream) - */ - - public void writeRequest(OutputStream out) throws IOException { - Part.sendParts(out, parts, getMultipartBoundary()); - } - - /* (non-Javadoc) - * @see org.apache.commons.httpclient.methods.RequestEntity#getContentLength() - */ - - public long getContentLength() { - try { - return Part.getLengthOfParts(parts, getMultipartBoundary()); - } catch (Exception e) { - log.error("An exception occurred while getting the length of the parts", e); - return 0; - } - } - - /* (non-Javadoc) - * @see org.apache.commons.httpclient.methods.RequestEntity#getContentType() - */ - - public String getContentType() { - StringBuffer buffer = new StringBuffer(MULTIPART_FORM_CONTENT_TYPE); - buffer.append("; boundary="); - buffer.append(MultipartEncodingUtil.getAsciiString(getMultipartBoundary())); - return buffer.toString(); - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/Part.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/Part.java deleted file mode 100644 index 2932da13317..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/Part.java +++ /dev/null @@ -1,453 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public abstract class Part { - - /** - * Log object for this class. - */ - private final static ESLogger LOG = Loggers.getLogger(Part.class); - - /** - * The boundary - */ - protected static final String BOUNDARY = "----------------314159265358979323846"; - - /** - * The boundary as a byte array. - * - * @deprecated - */ - protected static final byte[] BOUNDARY_BYTES = MultipartEncodingUtil.getAsciiBytes(BOUNDARY); - - /** - * The default boundary to be used if etBoundaryBytes(byte[]) has not - * been called. - */ - private static final byte[] DEFAULT_BOUNDARY_BYTES = BOUNDARY_BYTES; - - /** - * Carriage return/linefeed - */ - protected static final String CRLF = "\r\n"; - - /** - * Carriage return/linefeed as a byte array - */ - protected static final byte[] CRLF_BYTES = MultipartEncodingUtil.getAsciiBytes(CRLF); - - /** - * Content dispostion characters - */ - protected static final String QUOTE = "\""; - - /** - * Content dispostion as a byte array - */ - protected static final byte[] QUOTE_BYTES = - MultipartEncodingUtil.getAsciiBytes(QUOTE); - - /** - * Extra characters - */ - protected static final String EXTRA = "--"; - - /** - * Extra characters as a byte array - */ - protected static final byte[] EXTRA_BYTES = - MultipartEncodingUtil.getAsciiBytes(EXTRA); - - /** - * Content dispostion characters - */ - protected static final String CONTENT_DISPOSITION = "Content-Disposition: form-data; name="; - - /** - * Content dispostion as a byte array - */ - protected static final byte[] CONTENT_DISPOSITION_BYTES = - MultipartEncodingUtil.getAsciiBytes(CONTENT_DISPOSITION); - - /** - * Content type header - */ - protected static final String CONTENT_TYPE = "Content-Type: "; - - /** - * Content type header as a byte array - */ - protected static final byte[] CONTENT_TYPE_BYTES = - MultipartEncodingUtil.getAsciiBytes(CONTENT_TYPE); - - /** - * Content charset - */ - protected static final String CHARSET = "; charset="; - - /** - * Content charset as a byte array - */ - protected static final byte[] CHARSET_BYTES = - MultipartEncodingUtil.getAsciiBytes(CHARSET); - - /** - * Content type header - */ - protected static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding: "; - - /** - * Content type header as a byte array - */ - protected static final byte[] CONTENT_TRANSFER_ENCODING_BYTES = - MultipartEncodingUtil.getAsciiBytes(CONTENT_TRANSFER_ENCODING); - - /** - * Return the boundary string. - * - * @return the boundary string - * @deprecated uses a constant string. Rather use {@link #getPartBoundary} - */ - public static String getBoundary() { - return BOUNDARY; - } - - /** - * The ASCII bytes to use as the multipart boundary. - */ - private byte[] boundaryBytes; - - /** - * Return the name of this part. - * - * @return The name. - */ - public abstract String getName(); - - /** - * Returns the content type of this part. - * - * @return the content type, or null to exclude the content type header - */ - public abstract String getContentType(); - - /** - * Return the character encoding of this part. - * - * @return the character encoding, or null to exclude the character - * encoding header - */ - public abstract String getCharSet(); - - /** - * Return the transfer encoding of this part. - * - * @return the transfer encoding, or null to exclude the transfer encoding header - */ - public abstract String getTransferEncoding(); - - /** - * Gets the part boundary to be used. - * - * @return the part boundary as an array of bytes. - * @since 3.0 - */ - protected byte[] getPartBoundary() { - if (boundaryBytes == null) { - // custom boundary bytes have not been set, use the default. - return DEFAULT_BOUNDARY_BYTES; - } else { - return boundaryBytes; - } - } - - /** - * Sets the part boundary. Only meant to be used by - * {@link Part#sendParts(java.io.OutputStream , Part[], byte[])} - * and {@link Part#getLengthOfParts(Part[], byte[])} - * - * @param boundaryBytes An array of ASCII bytes. - * @since 3.0 - */ - void setPartBoundary(byte[] boundaryBytes) { - this.boundaryBytes = boundaryBytes; - } - - /** - * Tests if this part can be sent more than once. - * - * @return true if {@link #sendData(java.io.OutputStream)} can be successfully called - * more than once. - * @since 3.0 - */ - public boolean isRepeatable() { - return true; - } - - /** - * Write the start to the specified output stream - * - * @param out The output stream - * @throws java.io.IOException If an IO problem occurs. - */ - protected void sendStart(OutputStream out) throws IOException { - LOG.trace("enter sendStart(OutputStream out)"); - out.write(EXTRA_BYTES); - out.write(getPartBoundary()); - out.write(CRLF_BYTES); - } - - /** - * Write the content disposition header to the specified output stream - * - * @param out The output stream - * @throws IOException If an IO problem occurs. - */ - protected void sendDispositionHeader(OutputStream out) throws IOException { - LOG.trace("enter sendDispositionHeader(OutputStream out)"); - out.write(CONTENT_DISPOSITION_BYTES); - out.write(QUOTE_BYTES); - out.write(MultipartEncodingUtil.getAsciiBytes(getName())); - out.write(QUOTE_BYTES); - } - - /** - * Write the content type header to the specified output stream - * - * @param out The output stream - * @throws IOException If an IO problem occurs. - */ - protected void sendContentTypeHeader(OutputStream out) throws IOException { - LOG.trace("enter sendContentTypeHeader(OutputStream out)"); - String contentType = getContentType(); - if (contentType != null) { - out.write(CRLF_BYTES); - out.write(CONTENT_TYPE_BYTES); - out.write(MultipartEncodingUtil.getAsciiBytes(contentType)); - String charSet = getCharSet(); - if (charSet != null) { - out.write(CHARSET_BYTES); - out.write(MultipartEncodingUtil.getAsciiBytes(charSet)); - } - } - } - - /** - * Write the content transfer encoding header to the specified - * output stream - * - * @param out The output stream - * @throws IOException If an IO problem occurs. - */ - protected void sendTransferEncodingHeader(OutputStream out) throws IOException { - LOG.trace("enter sendTransferEncodingHeader(OutputStream out)"); - String transferEncoding = getTransferEncoding(); - if (transferEncoding != null) { - out.write(CRLF_BYTES); - out.write(CONTENT_TRANSFER_ENCODING_BYTES); - out.write(MultipartEncodingUtil.getAsciiBytes(transferEncoding)); - } - } - - /** - * Write the end of the header to the output stream - * - * @param out The output stream - * @throws IOException If an IO problem occurs. - */ - protected void sendEndOfHeader(OutputStream out) throws IOException { - LOG.trace("enter sendEndOfHeader(OutputStream out)"); - out.write(CRLF_BYTES); - out.write(CRLF_BYTES); - } - - /** - * Write the data to the specified output stream - * - * @param out The output stream - * @throws IOException If an IO problem occurs. - */ - protected abstract void sendData(OutputStream out) throws IOException; - - /** - * Return the length of the main content - * - * @return long The length. - * @throws IOException If an IO problem occurs - */ - protected abstract long lengthOfData() throws IOException; - - /** - * Write the end data to the output stream. - * - * @param out The output stream - * @throws IOException If an IO problem occurs. - */ - protected void sendEnd(OutputStream out) throws IOException { - LOG.trace("enter sendEnd(OutputStream out)"); - out.write(CRLF_BYTES); - } - - /** - * Write all the data to the output stream. - * If you override this method make sure to override - * #length() as well - * - * @param out The output stream - * @throws IOException If an IO problem occurs. - */ - public void send(OutputStream out) throws IOException { - LOG.trace("enter send(OutputStream out)"); - sendStart(out); - sendDispositionHeader(out); - sendContentTypeHeader(out); - sendTransferEncodingHeader(out); - sendEndOfHeader(out); - sendData(out); - sendEnd(out); - } - - - /** - * Return the full length of all the data. - * If you override this method make sure to override - * #send(OutputStream) as well - * - * @return long The length. - * @throws IOException If an IO problem occurs - */ - public long length() throws IOException { - LOG.trace("enter length()"); - if (lengthOfData() < 0) { - return -1; - } - ByteArrayOutputStream overhead = new ByteArrayOutputStream(); - sendStart(overhead); - sendDispositionHeader(overhead); - sendContentTypeHeader(overhead); - sendTransferEncodingHeader(overhead); - sendEndOfHeader(overhead); - sendEnd(overhead); - return overhead.size() + lengthOfData(); - } - - /** - * Return a string representation of this object. - * - * @return A string representation of this object. - * @see java.lang.Object#toString() - */ - public String toString() { - return this.getName(); - } - - /** - * Write all parts and the last boundary to the specified output stream. - * - * @param out The stream to write to. - * @param parts The parts to write. - * @throws IOException If an I/O error occurs while writing the parts. - */ - public static void sendParts(OutputStream out, final Part[] parts) - throws IOException { - sendParts(out, parts, DEFAULT_BOUNDARY_BYTES); - } - - /** - * Write all parts and the last boundary to the specified output stream. - * - * @param out The stream to write to. - * @param parts The parts to write. - * @param partBoundary The ASCII bytes to use as the part boundary. - * @throws IOException If an I/O error occurs while writing the parts. - * @since 3.0 - */ - public static void sendParts(OutputStream out, Part[] parts, byte[] partBoundary) - throws IOException { - - if (parts == null) { - throw new IllegalArgumentException("Parts may not be null"); - } - if (partBoundary == null || partBoundary.length == 0) { - throw new IllegalArgumentException("partBoundary may not be empty"); - } - for (int i = 0; i < parts.length; i++) { - // set the part boundary before the part is sent - parts[i].setPartBoundary(partBoundary); - parts[i].send(out); - } - out.write(EXTRA_BYTES); - out.write(partBoundary); - out.write(EXTRA_BYTES); - out.write(CRLF_BYTES); - } - - /** - * Return the total sum of all parts and that of the last boundary - * - * @param parts The parts. - * @return The total length - * @throws IOException If an I/O error occurs while writing the parts. - */ - public static long getLengthOfParts(Part[] parts) - throws IOException { - return getLengthOfParts(parts, DEFAULT_BOUNDARY_BYTES); - } - - /** - * Gets the length of the multipart message including the given parts. - * - * @param parts The parts. - * @param partBoundary The ASCII bytes to use as the part boundary. - * @return The total length - * @throws IOException If an I/O error occurs while writing the parts. - * @since 3.0 - */ - public static long getLengthOfParts(Part[] parts, byte[] partBoundary) throws IOException { - LOG.trace("getLengthOfParts(Parts[])"); - if (parts == null) { - throw new IllegalArgumentException("Parts may not be null"); - } - long total = 0; - for (int i = 0; i < parts.length; i++) { - // set the part boundary before we calculate the part's length - parts[i].setPartBoundary(partBoundary); - long l = parts[i].length(); - if (l < 0) { - return -1; - } - total += l; - } - total += EXTRA_BYTES.length; - total += partBoundary.length; - total += EXTRA_BYTES.length; - total += CRLF_BYTES.length; - return total; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/PartBase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/PartBase.java deleted file mode 100644 index ae1df1a71d3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/PartBase.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public abstract class PartBase extends Part { - - /** - * Name of the file part. - */ - private String name; - - /** - * Content type of the file part. - */ - private String contentType; - - /** - * Content encoding of the file part. - */ - private String charSet; - - /** - * The transfer encoding. - */ - private String transferEncoding; - - /** - * Constructor. - * - * @param name The name of the part - * @param contentType The content type, or null - * @param charSet The character encoding, or null - * @param transferEncoding The transfer encoding, or null - */ - public PartBase(String name, String contentType, String charSet, String transferEncoding) { - - if (name == null) { - throw new IllegalArgumentException("Name must not be null"); - } - this.name = name; - this.contentType = contentType; - this.charSet = charSet; - this.transferEncoding = transferEncoding; - } - - /** - * Returns the name. - * - * @return The name. - */ - public String getName() { - return this.name; - } - - /** - * Returns the content type of this part. - * - * @return String The name. - */ - public String getContentType() { - return this.contentType; - } - - /** - * Return the character encoding of this part. - * - * @return String The name. - */ - public String getCharSet() { - return this.charSet; - } - - /** - * Returns the transfer encoding of this part. - * - * @return String The name. - */ - public String getTransferEncoding() { - return transferEncoding; - } - - /** - * Sets the character encoding. - * - * @param charSet the character encoding, or null to exclude the character - * encoding header - */ - public void setCharSet(String charSet) { - this.charSet = charSet; - } - - /** - * Sets the content type. - * - * @param contentType the content type, or null to exclude the content type header - */ - public void setContentType(String contentType) { - this.contentType = contentType; - } - - /** - * Sets the part name. - * - * @param name - */ - public void setName(String name) { - if (name == null) { - throw new IllegalArgumentException("Name must not be null"); - } - this.name = name; - } - - /** - * Sets the transfer encoding. - * - * @param transferEncoding the transfer encoding, or null to exclude the - * transfer encoding header - */ - public void setTransferEncoding(String transferEncoding) { - this.transferEncoding = transferEncoding; - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/PartSource.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/PartSource.java deleted file mode 100644 index c1029aaf665..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/PartSource.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -import java.io.IOException; -import java.io.InputStream; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public interface PartSource { - - /** - * Gets the number of bytes contained in this source. - * - * @return a value >= 0 - */ - long getLength(); - - /** - * Gets the name of the file this source represents. - * - * @return the fileName used for posting a MultiPart file part - */ - String getFileName(); - - /** - * Gets a new InputStream for reading this source. This method can be - * called more than once and should therefore return a new stream every - * time. - * - * @return a new InputStream - * @throws java.io.IOException if an error occurs when creating the InputStream - */ - InputStream createInputStream() throws IOException; - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/RequestEntity.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/RequestEntity.java deleted file mode 100644 index 7e4905ad30f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/RequestEntity.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public interface RequestEntity { - - /** - * Tests if {@link #writeRequest(java.io.OutputStream)} can be called more than once. - * - * @return true if the entity can be written to {@link java.io.OutputStream} more than once, - * false otherwise. - */ - boolean isRepeatable(); - - /** - * Writes the request entity to the given stream. - * - * @param out - * @throws java.io.IOException - */ - void writeRequest(OutputStream out) throws IOException; - - /** - * Gets the request entity's length. This method should return a non-negative value if the content - * length is known or a negative value if it is not. In the latter case the - * EntityEnclosingMethod will use chunk encoding to - * transmit the request entity. - * - * @return a non-negative value when content length is known or a negative value when content length - * is not known - */ - long getContentLength(); - - /** - * Gets the entity's content type. This content type will be used as the value for the - * "Content-Type" header. - * - * @return the entity's content type - */ - String getContentType(); - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/StringPart.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/StringPart.java deleted file mode 100644 index ebac7e6cb81..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/multipart/StringPart.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.multipart; - -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * This class is an adaptation of the Apache HttpClient implementation - * - * @link http://hc.apache.org/httpclient-3.x/ - */ -public class StringPart extends PartBase { - - /** - * Log object for this class. - */ - private final static ESLogger LOG = Loggers.getLogger(StringPart.class); - - /** - * Default content encoding of string parameters. - */ - public static final String DEFAULT_CONTENT_TYPE = "text/plain"; - - /** - * Default charset of string parameters - */ - public static final String DEFAULT_CHARSET = "US-ASCII"; - - /** - * Default transfer encoding of string parameters - */ - public static final String DEFAULT_TRANSFER_ENCODING = "8bit"; - - /** - * Contents of this StringPart. - */ - private byte[] content; - - /** - * The String value of this part. - */ - private String value; - - /** - * Constructor. - * - * @param name The name of the part - * @param value the string to post - * @param charset the charset to be used to encode the string, if null - * the {@link #DEFAULT_CHARSET default} is used - */ - public StringPart(String name, String value, String charset) { - - super( - name, - DEFAULT_CONTENT_TYPE, - charset == null ? DEFAULT_CHARSET : charset, - DEFAULT_TRANSFER_ENCODING - ); - if (value == null) { - throw new IllegalArgumentException("Value may not be null"); - } - if (value.indexOf(0) != -1) { - // See RFC 2048, 2.8. "8bit Data" - throw new IllegalArgumentException("NULs may not be present in string parts"); - } - this.value = value; - } - - /** - * Constructor. - * - * @param name The name of the part - * @param value the string to post - */ - public StringPart(String name, String value) { - this(name, value, null); - } - - /** - * Gets the content in bytes. Bytes are lazily created to allow the charset to be changed - * after the part is created. - * - * @return the content in bytes - */ - private byte[] getContent() { - if (content == null) { - content = MultipartEncodingUtil.getBytes(value, getCharSet()); - } - return content; - } - - /** - * Writes the data to the given OutputStream. - * - * @param out the OutputStream to write to - * @throws java.io.IOException if there is a write error - */ - protected void sendData(OutputStream out) throws IOException { - LOG.trace("enter sendData(OutputStream)"); - out.write(getContent()); - } - - /** - * Return the length of the data. - * - * @return The length of the data. - * @throws IOException If an IO problem occurs - */ - protected long lengthOfData() throws IOException { - LOG.trace("enter lengthOfData()"); - return getContent().length; - } - - /* (non-Javadoc) - * @see org.apache.commons.httpclient.methods.multipart.BasePart#setCharSet(java.lang.String) - */ - - public void setCharSet(String charSet) { - super.setCharSet(charSet); - this.content = null; - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/package-info.java deleted file mode 100644 index 287c8cd0c88..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/package-info.java +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Ning Async-Client, revision 1fbadf5, date: 2010-05-24. - * - * Changes: - * - * 1. Use elasticsearch google collect. - * 2. Change to use ESLogger instead of log4j. - * 3. AsyncHttpClient: * Change string based provider name - * 4. AsyncHttpClientConfig: Change userAgent to ES - */ -package org.elasticsearch.util.http; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/url/Url.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/url/Url.java deleted file mode 100644 index 323025631b8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/url/Url.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -package org.elasticsearch.util.http.url; - -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class Url implements Cloneable, Serializable { - private static final long serialVersionUID = 2187287725357847401L; - - public enum Protocol { - HTTP(80), - HTTPS(443); - - private int port; - - Protocol(int port) { - this.port = port; - } - - public int getPort() { - return port; - } - } - - private String scheme; - private String host; - private int port; - private String path; - - private Map> params = new LinkedHashMap>(); - - /** - * Constructs a Url object from the given url string. The string is expected to be compliant with the URL RFC - * and all relevant parts need to be properly url-encoded - * - * @param value the string - * @return a url object - * @throws MalformedURLException - */ - public static Url valueOf(String value) - throws MalformedURLException { - URL url = new URL(value); - try { - return new Url(url.getProtocol(), - url.getHost(), - // url.getPort() return -1 rather than default for the protocol/scheme if no port is specified. - url.getPort() > 0 ? url.getPort() : Protocol.valueOf(url.getProtocol().toUpperCase()).getPort(), - URLDecoder.decode(url.getPath(), "UTF-8"), - url.getQuery()); - } - catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e); - } - } - - - /** - * Constructs a Url object from the given url string parts. The parts are expected to be compliant with the URL RFC - * and need to be properly url-encoded - */ - - public static Url valueOf(String scheme, String host, String uri) { - try { - return Url.valueOf(scheme + "://" + host + uri); - } - catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - - /** - * Resolves 'path' with respect to a given base url - */ - public static Url valueOf(Url base, String uri) - throws MalformedURLException { - final Url result; - if (!uri.matches("[\\p{Alpha}][\\p{Alnum}-.+_]+://.+")) { // relative url? - result = base.clone(); - if (uri.startsWith("/")) { // relative to root? - result.setUri(uri); - } else { // relative to current dir - String path = base.getPath(); - - int index = path.lastIndexOf('/'); - if (index != -1) { - path = path.substring(0, index + 1) + uri; - } else { - path = "/" + uri; - } - - result.setUri(path); - } - } else { // uri is absolute - result = Url.valueOf(uri); - } - - return result; - } - - private Url(String scheme, String host, int port, String path, Map> params) { - setScheme(scheme); - setHost(host); - this.port = port; - this.path = path; - this.params = new LinkedHashMap>(params); - } - - - public Url(String scheme, String host, int port, String path, String query) { - setScheme(scheme); - setHost(host); - this.port = port; - this.path = path; - - setQueryString(query); - } - - public String getScheme() { - return scheme; - } - - public void setScheme(String s) { - if (Protocol.valueOf(s.toUpperCase()) == null) { - throw new IllegalArgumentException("Illegal scheme used [" + s + "]"); - } - this.scheme = s; - } - - public Protocol getProtocol() { - return Protocol.valueOf(scheme.toUpperCase()); - } - - /** - * Gets the path part of this url. The value is url-decoded. - * - * @return he path part of this url. The value is url-decoded. - */ - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host.toLowerCase(); - } - - - public void setBaseUrl(String url) { - Pattern pattern = Pattern.compile("([^:]+)://([^:]+)(:([0-9]+))?"); - - Matcher matcher = pattern.matcher(url); - - if (!matcher.matches()) { - throw new IllegalArgumentException("Invalid url: " + url); - } - - setScheme(matcher.group(1)); - setHost(matcher.group(2)); - - String port = matcher.group(4); - if (port != null) { - this.port = Integer.valueOf(port); - } else { - Protocol protocol = getProtocol(); - this.port = protocol.getPort(); - } - } - - public String getBaseUrl() { - StringBuilder builder = new StringBuilder(); - - builder.append(scheme); - builder.append("://"); - builder.append(getLocation()); - - return builder.toString(); - } - - public String getLocation() { - StringBuilder builder = new StringBuilder(host); - int defaultPort; - try { - Protocol protocol = getProtocol(); - defaultPort = protocol.getPort(); - } - catch (Exception e) { - throw new IllegalStateException("Unable to fetch protocol", e); - } - - if (port != defaultPort) { - builder.append(':'); - builder.append(port); - } - - return builder.toString(); - } - - public void setUri(String uri) { - int index = uri.indexOf('?'); - - if (index != -1) { - path = uri.substring(0, index); - String query = uri.substring(index + 1); - setQueryString(query); - } else { - path = uri; - params.clear(); - } - } - - public String getUri() { - StringBuilder builder = new StringBuilder(); - - builder.append(path); - if (!params.isEmpty()) { - builder.append('?'); - builder.append(getQueryString()); - } - - return builder.toString(); - } - - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(getBaseUrl()); - builder.append(getUri()); - - return builder.toString(); - } - - /** - * Return the URL string, but without any parameters - * - * @return a string - */ - public String toStringWithoutParams() { - return new Url(scheme, host, port, path, "").toString(); - } - - - private void parseParameters(String query) { - params.clear(); - if (query != null) { - StringTokenizer tokenizer = new StringTokenizer(query, "&"); - - while (tokenizer.hasMoreElements()) { - String token = tokenizer.nextToken(); - String[] param = token.split("=", 2); - if (param.length > 0) { - String name = param[0]; - String value = param.length > 1 - ? urlDecode(param[1]) - : null; // null case distinguishes between ?name= and ?name - - if (name.length() > 0) { - addParameter(name, value); - } - } - } - } - } - - private String urlDecode(String value) { - try { - return URLDecoder.decode(value, "UTF-8"); - } - catch (UnsupportedEncodingException e) { - // this should not be possible - throw new IllegalStateException("Should never happen: UTF-8 encoding is unsupported.", e); - } - } - - public void setParameter(String name, String value) { - removeParameter(name); - addParameter(name, value); - } - - /** - * reset the parameters list. - */ - public void clearParameters() { - params.clear(); - } - - public void setParameter(String name, Object value) { - setParameter(name, value.toString()); - } - - public void addParameter(String name, String value) { - List list = params.get(name); - if (list == null) { - list = new ArrayList(); - params.put(name, list); - } - list.add(value); - //params.add(new Pair(name, value)); - } - - public String getParameter(String name) { - String result = null; - List list = params.get(name); - if (list != null && list.size() > 0) { - result = list.get(0); - } - return result; - } - - public List getParameters(String name) { - List result = new ArrayList(); - - List list = params.get(name); - if (list != null && list.size() > 0) { - result.addAll(list); - } - - return result; - } - - public Map> getParameters() { - return params; - } - - - public void removeParameter(String name) { - params.remove(name); - } - - public void setQueryString(String query) { - // TODO: don't parse until addParameter/setParameter/removeParameter is called - parseParameters(query); - } - - public String getQueryString() { - // TODO: cache query string - String result = null; - - if (!params.isEmpty()) { - StringBuilder builder = new StringBuilder(); - - for (Iterator>> i = params.entrySet().iterator(); i.hasNext();) { - Map.Entry> param = i.next(); - String name = param.getKey(); - for (Iterator j = param.getValue().iterator(); j.hasNext();) { - String value = j.next(); - builder.append(name); - if (value != null) { - builder.append('='); - try { - builder.append(URLEncoder.encode(value, "UTF-8")); - } - catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e); - } - } - if (j.hasNext()) { - builder.append('&'); - } - } - if (i.hasNext()) { - builder.append('&'); - } - } - - result = builder.toString(); - } - - return result; - } - - - public Url clone() { - return new Url(scheme, host, port, path, params); - } - - public int hashCode() { - return toString().hashCode(); - } - - public boolean equals(Object obj) { - // TODO: we should compare piece by piece. Argument ordering shouldn't affect equality - return obj instanceof Url && toString().equals(obj.toString()); - } - - /** - * Is the given Url string in a valid format? - * - * @param url - * @return true if valid - */ - public static boolean isValidUrl(String url) { - try { - Url.valueOf(url); - return true; - } - catch (MalformedURLException e) { - return false; - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/util/SslUtils.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/util/SslUtils.java deleted file mode 100644 index cb451da1580..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/http/util/SslUtils.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.util.http.util; - -import javax.net.ssl.*; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.GeneralSecurityException; -import java.security.KeyStore; -import java.security.SecureRandom; -import java.security.Security; - -/** - * This class is a copy of http://github.com/sonatype/wagon-ning/raw/master/src/main/java/org/apache/maven/wagon/providers/http/SslUtils.java - */ -public class SslUtils { - - public static SSLEngine getSSLEngine() - throws GeneralSecurityException, IOException { - SSLEngine engine = null; - - SSLContext context = getSSLContext(); - if (context != null) { - engine = context.createSSLEngine(); - engine.setUseClientMode(true); - } - - return engine; - } - - static SSLContext getSSLContext() - throws GeneralSecurityException, IOException { - SSLConfig config = new SSLConfig(); - if (config.keyStoreLocation == null) { - return getLooseSSLContext(); - } else { - return getStrictSSLContext(config); - } - } - - static SSLContext getStrictSSLContext(SSLConfig config) - throws GeneralSecurityException, IOException { - KeyStore keyStore = KeyStore.getInstance(config.keyStoreType); - InputStream keystoreInputStream = new FileInputStream(config.keyStoreLocation); - try { - keyStore.load(keystoreInputStream, (config.keyStorePassword == null) ? null - : config.keyStorePassword.toCharArray()); - } - finally { - keystoreInputStream.close(); - } - - KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(config.keyManagerAlgorithm); - keyManagerFactory.init(keyStore, (config.keyManagerPassword == null) ? null - : config.keyManagerPassword.toCharArray()); - KeyManager[] keyManagers = keyManagerFactory.getKeyManagers(); - - KeyStore trustStore = KeyStore.getInstance(config.trustStoreType); - InputStream truststoreInputStream = new FileInputStream(config.trustStoreLocation); - try { - trustStore.load(truststoreInputStream, (config.trustStorePassword == null) ? null - : config.trustStorePassword.toCharArray()); - } - finally { - truststoreInputStream.close(); - } - - TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(config.trustManagerAlgorithm); - trustManagerFactory.init(trustStore); - TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); - - SSLContext context = SSLContext.getInstance("TLS"); - context.init(keyManagers, trustManagers, null); - - return context; - } - - static SSLContext getLooseSSLContext() - throws GeneralSecurityException { - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(null, new TrustManager[]{LooseTrustManager.INSTANCE}, new SecureRandom()); - return sslContext; - } - - static class LooseTrustManager - implements X509TrustManager { - - public static final LooseTrustManager INSTANCE = new LooseTrustManager(); - - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { - } - - public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { - } - } - - private final static class SSLConfig { - - public String keyStoreLocation; - - public String keyStoreType = "JKS"; - - public String keyStorePassword = "changeit"; - - public String keyManagerAlgorithm = "SunX509"; - - public String keyManagerPassword = "changeit"; - - public String trustStoreLocation; - - public String trustStoreType = "JKS"; - - public String trustStorePassword = "changeit"; - - public String trustManagerAlgorithm = "SunX509"; - - public SSLConfig() { - keyStoreLocation = System.getProperty("javax.net.ssl.keyStore"); - keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword", "changeit"); - keyStoreType = System.getProperty("javax.net.ssl.keyStoreType", KeyStore.getDefaultType()); - keyManagerAlgorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm"); - - if (keyManagerAlgorithm == null) { - keyManagerAlgorithm = "SunX509"; - } - - keyManagerPassword = System.getProperty("javax.net.ssl.keyStorePassword", "changeit"); - - trustStoreLocation = System.getProperty("javax.net.ssl.trustStore"); - if (trustStoreLocation == null) { - trustStoreLocation = keyStoreLocation; - trustStorePassword = keyStorePassword; - trustStoreType = keyStoreType; - } else { - trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword", "changeit"); - trustStoreType = System.getProperty("javax.net.ssl.trustStoreType", KeyStore.getDefaultType()); - } - trustManagerAlgorithm = Security.getProperty("ssl.TrustManagerFactory.algorithm"); - - if (trustManagerAlgorithm == null) { - trustManagerAlgorithm = "SunX509"; - } - } - - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/AbstractModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/AbstractModule.java deleted file mode 100644 index 0517695f641..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/AbstractModule.java +++ /dev/null @@ -1,239 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.binder.AnnotatedBindingBuilder; -import org.elasticsearch.util.inject.binder.AnnotatedConstantBindingBuilder; -import org.elasticsearch.util.inject.binder.LinkedBindingBuilder; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import static org.elasticsearch.util.inject.internal.Preconditions.checkState; -import org.elasticsearch.util.inject.matcher.Matcher; -import org.elasticsearch.util.inject.spi.Message; -import org.elasticsearch.util.inject.spi.TypeConverter; -import org.elasticsearch.util.inject.spi.TypeListener; -import java.lang.annotation.Annotation; - -/** - * A support class for {@link Module}s which reduces repetition and results in - * a more readable configuration. Simply extend this class, implement {@link - * #configure()}, and call the inherited methods which mirror those found in - * {@link Binder}. For example: - * - *
- * public class MyModule extends AbstractModule {
- *   protected void configure() {
- *     bind(Service.class).to(ServiceImpl.class).in(Singleton.class);
- *     bind(CreditCardPaymentService.class);
- *     bind(PaymentService.class).to(CreditCardPaymentService.class);
- *     bindConstant().annotatedWith(Names.named("port")).to(8080);
- *   }
- * }
- * 
- * - * @author crazybob@google.com (Bob Lee) - */ -public abstract class AbstractModule implements Module { - - Binder binder; - - public final synchronized void configure(Binder builder) { - checkState(this.binder == null, "Re-entry is not allowed."); - - this.binder = checkNotNull(builder, "builder"); - try { - configure(); - } - finally { - this.binder = null; - } - } - - /** - * Configures a {@link Binder} via the exposed methods. - */ - protected abstract void configure(); - - /** - * Gets direct access to the underlying {@code Binder}. - */ - protected Binder binder() { - return binder; - } - - /** - * @see Binder#bindScope(Class, Scope) - */ - protected void bindScope(Class scopeAnnotation, - Scope scope) { - binder.bindScope(scopeAnnotation, scope); - } - - /** - * @see Binder#bind(Key) - */ - protected LinkedBindingBuilder bind(Key key) { - return binder.bind(key); - } - - /** - * @see Binder#bind(TypeLiteral) - */ - protected AnnotatedBindingBuilder bind(TypeLiteral typeLiteral) { - return binder.bind(typeLiteral); - } - - /** - * @see Binder#bind(Class) - */ - protected AnnotatedBindingBuilder bind(Class clazz) { - return binder.bind(clazz); - } - - /** - * @see Binder#bindConstant() - */ - protected AnnotatedConstantBindingBuilder bindConstant() { - return binder.bindConstant(); - } - - /** - * @see Binder#install(Module) - */ - protected void install(Module module) { - binder.install(module); - } - - /** - * @see Binder#addError(String, Object[]) - */ - protected void addError(String message, Object... arguments) { - binder.addError(message, arguments); - } - - /** - * @see Binder#addError(Throwable) - */ - protected void addError(Throwable t) { - binder.addError(t); - } - - /** - * @see Binder#addError(Message) - * @since 2.0 - */ - protected void addError(Message message) { - binder.addError(message); - } - - /** - * @see Binder#requestInjection(Object) - * @since 2.0 - */ - protected void requestInjection(Object instance) { - binder.requestInjection(instance); - } - - /** - * @see Binder#requestStaticInjection(Class[]) - */ - protected void requestStaticInjection(Class... types) { - binder.requestStaticInjection(types); - } - - /** - * Adds a dependency from this module to {@code key}. When the injector is - * created, Guice will report an error if {@code key} cannot be injected. - * Note that this requirement may be satisfied by implicit binding, such as - * a public no-arguments constructor. - * - * @since 2.0 - */ - protected void requireBinding(Key key) { - binder.getProvider(key); - } - - /** - * Adds a dependency from this module to {@code type}. When the injector is - * created, Guice will report an error if {@code type} cannot be injected. - * Note that this requirement may be satisfied by implicit binding, such as - * a public no-arguments constructor. - * - * @since 2.0 - */ - protected void requireBinding(Class type) { - binder.getProvider(type); - } - - /** - * @see Binder#getProvider(Key) - * @since 2.0 - */ - protected Provider getProvider(Key key) { - return binder.getProvider(key); - } - - /** - * @see Binder#getProvider(Class) - * @since 2.0 - */ - protected Provider getProvider(Class type) { - return binder.getProvider(type); - } - - /** - * @see Binder#convertToTypes - * @since 2.0 - */ - protected void convertToTypes(Matcher> typeMatcher, - TypeConverter converter) { - binder.convertToTypes(typeMatcher, converter); - } - - /** - * @see Binder#currentStage() - * @since 2.0 - */ - protected Stage currentStage() { - return binder.currentStage(); - } - - /** - * @see Binder#getMembersInjector(Class) - * @since 2.0 - */ - protected MembersInjector getMembersInjector(Class type) { - return binder.getMembersInjector(type); - } - - /** - * @see Binder#getMembersInjector(TypeLiteral) - * @since 2.0 - */ - protected MembersInjector getMembersInjector(TypeLiteral type) { - return binder.getMembersInjector(type); - } - - /** - * @see Binder#bindListener(org.elasticsearch.util.inject.matcher.Matcher, - * org.elasticsearch.util.inject.spi.TypeListener) - * @since 2.0 - */ - protected void bindListener(Matcher> typeMatcher, - TypeListener listener) { - binder.bindListener(typeMatcher, listener); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/AbstractProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/AbstractProcessor.java deleted file mode 100644 index 6ec020ca4c9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/AbstractProcessor.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.Element; -import org.elasticsearch.util.inject.spi.ElementVisitor; -import org.elasticsearch.util.inject.spi.InjectionRequest; -import org.elasticsearch.util.inject.spi.MembersInjectorLookup; -import org.elasticsearch.util.inject.spi.Message; -import org.elasticsearch.util.inject.spi.PrivateElements; -import org.elasticsearch.util.inject.spi.ProviderLookup; -import org.elasticsearch.util.inject.spi.ScopeBinding; -import org.elasticsearch.util.inject.spi.StaticInjectionRequest; -import org.elasticsearch.util.inject.spi.TypeConverterBinding; -import org.elasticsearch.util.inject.spi.TypeListenerBinding; -import java.util.Iterator; -import java.util.List; - -/** - * Abstract base class for creating an injector from module elements. - * - *

Extending classes must return {@code true} from any overridden - * {@code visit*()} methods, in order for the element processor to remove the - * handled element. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -abstract class AbstractProcessor implements ElementVisitor { - - protected Errors errors; - protected InjectorImpl injector; - - protected AbstractProcessor(Errors errors) { - this.errors = errors; - } - - public void process(Iterable isolatedInjectorBuilders) { - for (InjectorShell injectorShell : isolatedInjectorBuilders) { - process(injectorShell.getInjector(), injectorShell.getElements()); - } - } - - public void process(InjectorImpl injector, List elements) { - Errors errorsAnyElement = this.errors; - this.injector = injector; - try { - for (Iterator i = elements.iterator(); i.hasNext(); ) { - Element element = i.next(); - this.errors = errorsAnyElement.withSource(element.getSource()); - Boolean allDone = element.acceptVisitor(this); - if (allDone) { - i.remove(); - } - } - } finally { - this.errors = errorsAnyElement; - this.injector = null; - } - } - - public Boolean visit(Message message) { - return false; - } - - public Boolean visit(ScopeBinding scopeBinding) { - return false; - } - - public Boolean visit(InjectionRequest injectionRequest) { - return false; - } - - public Boolean visit(StaticInjectionRequest staticInjectionRequest) { - return false; - } - - public Boolean visit(TypeConverterBinding typeConverterBinding) { - return false; - } - - public Boolean visit(Binding binding) { - return false; - } - - public Boolean visit(ProviderLookup providerLookup) { - return false; - } - - public Boolean visit(PrivateElements privateElements) { - return false; - } - - public Boolean visit(MembersInjectorLookup lookup) { - return false; - } - - public Boolean visit(TypeListenerBinding binding) { - return false; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Binder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Binder.java deleted file mode 100644 index 0d73d55315f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Binder.java +++ /dev/null @@ -1,376 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.binder.AnnotatedBindingBuilder; -import org.elasticsearch.util.inject.binder.AnnotatedConstantBindingBuilder; -import org.elasticsearch.util.inject.binder.LinkedBindingBuilder; -import org.elasticsearch.util.inject.matcher.Matcher; -import org.elasticsearch.util.inject.spi.Message; -import org.elasticsearch.util.inject.spi.TypeConverter; -import org.elasticsearch.util.inject.spi.TypeListener; -import java.lang.annotation.Annotation; - -/** - * Collects configuration information (primarily bindings) which will be - * used to create an {@link Injector}. Guice provides this object to your - * application's {@link Module} implementors so they may each contribute - * their own bindings and other registrations. - * - *

The Guice Binding EDSL

- * - * Guice uses an embedded domain-specific language, or EDSL, to help you - * create bindings simply and readably. This approach is great for overall - * usability, but it does come with a small cost: it is difficult to - * learn how to use the Binding EDSL by reading - * method-level javadocs. Instead, you should consult the series of - * examples below. To save space, these examples omit the opening - * {@code binder}, just as you will if your module extends - * {@link AbstractModule}. - * - *
- *     bind(ServiceImpl.class);
- * - * This statement does essentially nothing; it "binds the {@code ServiceImpl} - * class to itself" and does not change Guice's default behavior. You may still - * want to use this if you prefer your {@link Module} class to serve as an - * explicit manifest for the services it provides. Also, in rare cases, - * Guice may be unable to validate a binding at injector creation time unless it - * is given explicitly. - * - *
- *     bind(Service.class).to(ServiceImpl.class);
- * - * Specifies that a request for a {@code Service} instance with no binding - * annotations should be treated as if it were a request for a - * {@code ServiceImpl} instance. This overrides the function of any - * {@link ImplementedBy @ImplementedBy} or {@link ProvidedBy @ProvidedBy} - * annotations found on {@code Service}, since Guice will have already - * "moved on" to {@code ServiceImpl} before it reaches the point when it starts - * looking for these annotations. - * - *
- *     bind(Service.class).toProvider(ServiceProvider.class);
- * - * In this example, {@code ServiceProvider} must extend or implement - * {@code Provider}. This binding specifies that Guice should resolve - * an unannotated injection request for {@code Service} by first resolving an - * instance of {@code ServiceProvider} in the regular way, then calling - * {@link Provider#get get()} on the resulting Provider instance to obtain the - * {@code Service} instance. - * - *

The {@link Provider} you use here does not have to be a "factory"; that - * is, a provider which always creates each instance it provides. - * However, this is generally a good practice to follow. You can then use - * Guice's concept of {@link Scope scopes} to guide when creation should happen - * -- "letting Guice work for you". - * - *

- *     bind(Service.class).annotatedWith(Red.class).to(ServiceImpl.class);
- * - * Like the previous example, but only applies to injection requests that use - * the binding annotation {@code @Red}. If your module also includes bindings - * for particular values of the {@code @Red} annotation (see below), - * then this binding will serve as a "catch-all" for any values of {@code @Red} - * that have no exact match in the bindings. - * - *
- *     bind(ServiceImpl.class).in(Singleton.class);
- *     // or, alternatively
- *     bind(ServiceImpl.class).in(Scopes.SINGLETON);
- * - * Either of these statements places the {@code ServiceImpl} class into - * singleton scope. Guice will create only one instance of {@code ServiceImpl} - * and will reuse it for all injection requests of this type. Note that it is - * still possible to bind another instance of {@code ServiceImpl} if the second - * binding is qualified by an annotation as in the previous example. Guice is - * not overly concerned with preventing you from creating multiple - * instances of your "singletons", only with enabling your application to - * share only one instance if that's all you tell Guice you need. - * - *

Note: a scope specified in this way overrides any scope that - * was specified with an annotation on the {@code ServiceImpl} class. - * - *

Besides {@link Singleton}/{@link Scopes#SINGLETON}, there are - * servlet-specific scopes available in - * {@code com.google.inject.servlet.ServletScopes}, and your Modules can - * contribute their own custom scopes for use here as well. - * - *

- *     bind(new TypeLiteral<PaymentService<CreditCard>>() {})
- *         .to(CreditCardPaymentService.class);
- * - * This admittedly odd construct is the way to bind a parameterized type. It - * tells Guice how to honor an injection request for an element of type - * {@code PaymentService}. The class - * {@code CreditCardPaymentService} must implement the - * {@code PaymentService} interface. Guice cannot currently bind or - * inject a generic type, such as {@code Set}; all type parameters must be - * fully specified. - * - *
- *     bind(Service.class).toInstance(new ServiceImpl());
- *     // or, alternatively
- *     bind(Service.class).toInstance(SomeLegacyRegistry.getService());
- * - * In this example, your module itself, not Guice, takes responsibility - * for obtaining a {@code ServiceImpl} instance, then asks Guice to always use - * this single instance to fulfill all {@code Service} injection requests. When - * the {@link Injector} is created, it will automatically perform field - * and method injection for this instance, but any injectable constructor on - * {@code ServiceImpl} is simply ignored. Note that using this approach results - * in "eager loading" behavior that you can't control. - * - *
- *     bindConstant().annotatedWith(ServerHost.class).to(args[0]);
- * - * Sets up a constant binding. Constant injections must always be annotated. - * When a constant binding's value is a string, it is eligile for conversion to - * all primitive types, to {@link Enum#valueOf(Class, String) all enums}, and to - * {@link Class#forName class literals}. Conversions for other types can be - * configured using {@link #convertToTypes(Matcher, TypeConverter) - * convertToTypes()}. - * - *
- *   {@literal @}Color("red") Color red; // A member variable (field)
- *    . . .
- *     red = MyModule.class.getDeclaredField("red").getAnnotation(Color.class);
- *     bind(Service.class).annotatedWith(red).to(RedService.class);
- * - * If your binding annotation has parameters you can apply different bindings to - * different specific values of your annotation. Getting your hands on the - * right instance of the annotation is a bit of a pain -- one approach, shown - * above, is to apply a prototype annotation to a field in your module class, so - * that you can read this annotation instance and give it to Guice. - * - *
- *     bind(Service.class)
- *         .annotatedWith(Names.named("blue"))
- *         .to(BlueService.class);
- * - * Differentiating by names is a common enough use case that we provided a - * standard annotation, {@link org.elasticsearch.util.inject.name.Named @Named}. Because of - * Guice's library support, binding by name is quite easier than in the - * arbitrary binding annotation case we just saw. However, remember that these - * names will live in a single flat namespace with all the other names used in - * your application. - * - *

The above list of examples is far from exhaustive. If you can think of - * how the concepts of one example might coexist with the concepts from another, - * you can most likely weave the two together. If the two concepts make no - * sense with each other, you most likely won't be able to do it. In a few - * cases Guice will let something bogus slip by, and will then inform you of - * the problems at runtime, as soon as you try to create your Injector. - * - *

The other methods of Binder such as {@link #bindScope}, - * {@link #bindInterceptor}, {@link #install}, {@link #requestStaticInjection}, - * {@link #addError} and {@link #currentStage} are not part of the Binding EDSL; - * you can learn how to use these in the usual way, from the method - * documentation. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - * @author kevinb@google.com (Kevin Bourrillion) - */ -public interface Binder { - - /** - * Binds a scope to an annotation. - */ - void bindScope(Class annotationType, Scope scope); - - /** - * See the EDSL examples at {@link Binder}. - */ - LinkedBindingBuilder bind(Key key); - - /** - * See the EDSL examples at {@link Binder}. - */ - AnnotatedBindingBuilder bind(TypeLiteral typeLiteral); - - /** - * See the EDSL examples at {@link Binder}. - */ - AnnotatedBindingBuilder bind(Class type); - - /** - * See the EDSL examples at {@link Binder}. - */ - AnnotatedConstantBindingBuilder bindConstant(); - - /** - * Upon successful creation, the {@link Injector} will inject instance fields - * and methods of the given object. - * - * @param type of instance - * @param instance for which members will be injected - * @since 2.0 - */ - void requestInjection(TypeLiteral type, T instance); - - /** - * Upon successful creation, the {@link Injector} will inject instance fields - * and methods of the given object. - * - * @param instance for which members will be injected - * @since 2.0 - */ - void requestInjection(Object instance); - - /** - * Upon successful creation, the {@link Injector} will inject static fields - * and methods in the given classes. - * - * @param types for which static members will be injected - */ - void requestStaticInjection(Class... types); - - /** - * Uses the given module to configure more bindings. - */ - void install(Module module); - - /** - * Gets the current stage. - */ - Stage currentStage(); - - /** - * Records an error message which will be presented to the user at a later - * time. Unlike throwing an exception, this enable us to continue - * configuring the Injector and discover more errors. Uses {@link - * String#format(String, Object[])} to insert the arguments into the - * message. - */ - void addError(String message, Object... arguments); - - /** - * Records an exception, the full details of which will be logged, and the - * message of which will be presented to the user at a later - * time. If your Module calls something that you worry may fail, you should - * catch the exception and pass it into this. - */ - void addError(Throwable t); - - /** - * Records an error message to be presented to the user at a later time. - * - * @since 2.0 - */ - void addError(Message message); - - /** - * Returns the provider used to obtain instances for the given injection key. - * The returned will not be valid until the {@link Injector} has been - * created. The provider will throw an {@code IllegalStateException} if you - * try to use it beforehand. - * - * @since 2.0 - */ - Provider getProvider(Key key); - - /** - * Returns the provider used to obtain instances for the given injection type. - * The returned provider will not be valid until the {@link Injector} has been - * created. The provider will throw an {@code IllegalStateException} if you - * try to use it beforehand. - * - * @since 2.0 - */ - Provider getProvider(Class type); - - /** - * Returns the members injector used to inject dependencies into methods and fields on instances - * of the given type {@code T}. The returned members injector will not be valid until the main - * {@link Injector} has been created. The members injector will throw an {@code - * IllegalStateException} if you try to use it beforehand. - * - * @param typeLiteral type to get members injector for - * @since 2.0 - */ - MembersInjector getMembersInjector(TypeLiteral typeLiteral); - - /** - * Returns the members injector used to inject dependencies into methods and fields on instances - * of the given type {@code T}. The returned members injector will not be valid until the main - * {@link Injector} has been created. The members injector will throw an {@code - * IllegalStateException} if you try to use it beforehand. - * - * @param type type to get members injector for - * @since 2.0 - */ - MembersInjector getMembersInjector(Class type); - - /** - * Binds a type converter. The injector will use the given converter to - * convert string constants to matching types as needed. - * - * @param typeMatcher matches types the converter can handle - * @param converter converts values - * @since 2.0 - */ - void convertToTypes(Matcher> typeMatcher, - TypeConverter converter); - - /** - * Registers a listener for injectable types. Guice will notify the listener when it encounters - * injectable types matched by the given type matcher. - * - * @param typeMatcher that matches injectable types the listener should be notified of - * @param listener for injectable types matched by typeMatcher - * @since 2.0 - */ - void bindListener(Matcher> typeMatcher, - TypeListener listener); - - /** - * Returns a binder that uses {@code source} as the reference location for - * configuration errors. This is typically a {@link StackTraceElement} - * for {@code .java} source but it could any binding source, such as the - * path to a {@code .properties} file. - * - * @param source any object representing the source location and has a - * concise {@link Object#toString() toString()} value - * @return a binder that shares its configuration with this binder - * @since 2.0 - */ - Binder withSource(Object source); - - /** - * Returns a binder that skips {@code classesToSkip} when identify the - * calling code. The caller's {@link StackTraceElement} is used to locate - * the source of configuration errors. - * - * @param classesToSkip library classes that create bindings on behalf of - * their clients. - * @return a binder that shares its configuration with this binder. - * @since 2.0 - */ - Binder skipSources(Class... classesToSkip); - - /** - * Creates a new private child environment for bindings and other configuration. The returned - * binder can be used to add and configuration information in this environment. See {@link - * PrivateModule} for details. - * - * @return a binder that inherits configuration from this binder. Only exposed configuration on - * the returned binder will be visible to this binder. - * @since 2.0 - */ - PrivateBinder newPrivateBinder(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Binding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Binding.java deleted file mode 100644 index 6382fa12a7f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Binding.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.spi.BindingScopingVisitor; -import org.elasticsearch.util.inject.spi.BindingTargetVisitor; -import org.elasticsearch.util.inject.spi.Element; - -/** - * A mapping from a key (type and optional annotation) to the strategy for getting instances of the - * type. This interface is part of the introspection API and is intended primarily for use by - * tools. - * - *

Bindings are created in several ways: - *

    - *
  • Explicitly in a module, via {@code bind()} and {@code bindConstant()} - * statements: - *
    - *     bind(Service.class).annotatedWith(Red.class).to(ServiceImpl.class);
    - *     bindConstant().annotatedWith(ServerHost.class).to(args[0]);
  • - *
  • Implicitly by the Injector by following a type's {@link ImplementedBy - * pointer} {@link ProvidedBy annotations} or by using its {@link Inject annotated} or - * default constructor.
  • - *
  • By converting a bound instance to a different type.
  • - *
  • For {@link Provider providers}, by delegating to the binding for the provided type.
  • - *
- * - * - *

They exist on both modules and on injectors, and their behaviour is different for each: - *

    - *
  • Module bindings are incomplete and cannot be used to provide instances. - * This is because the applicable scopes and interceptors may not be known until an injector - * is created. From a tool's perspective, module bindings are like the injector's source - * code. They can be inspected or rewritten, but this analysis must be done statically.
  • - *
  • Injector bindings are complete and valid and can be used to provide - * instances. From a tools' perspective, injector bindings are like reflection for an - * injector. They have full runtime information, including the complete graph of injections - * necessary to satisfy a binding.
  • - *
- * - * @param the bound type. The injected is always assignable to this type. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -public interface Binding extends Element { - - /** - * Returns the key for this binding. - */ - Key getKey(); - - /** - * Returns the scoped provider guice uses to fulfill requests for this - * binding. - * - * @throws UnsupportedOperationException when invoked on a {@link Binding} - * created via {@link org.elasticsearch.util.inject.spi.Elements#getElements}. This - * method is only supported on {@link Binding}s returned from an injector. - */ - Provider getProvider(); - - /** - * Accepts a target visitor. Invokes the visitor method specific to this binding's target. - * - * @param visitor to call back on - * @since 2.0 - */ - V acceptTargetVisitor(BindingTargetVisitor visitor); - - /** - * Accepts a scoping visitor. Invokes the visitor method specific to this binding's scoping. - * - * @param visitor to call back on - * @since 2.0 - */ - V acceptScopingVisitor(BindingScopingVisitor visitor); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BindingAnnotation.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BindingAnnotation.java deleted file mode 100644 index e7859e0e9d4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BindingAnnotation.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * Annotates annotations which are used for binding. Only one such annotation - * may apply to a single injection point. You must also annotate binder - * annotations with {@code @Retention(RUNTIME)}. For example: - * - *
- *   {@code @}Retention(RUNTIME)
- *   {@code @}Target({ FIELD, PARAMETER, METHOD })
- *   {@code @}BindingAnnotation
- *   public {@code @}interface Transactional {}
- * 
- * - * @author crazybob@google.com (Bob Lee) - */ -@Target(ANNOTATION_TYPE) -@Retention(RUNTIME) -public @interface BindingAnnotation {} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BindingProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BindingProcessor.java deleted file mode 100644 index ce5787d294e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BindingProcessor.java +++ /dev/null @@ -1,266 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.internal.*; -import org.elasticsearch.util.inject.spi.*; - -import java.util.List; -import java.util.Set; - -/** - * Handles {@link Binder#bind} and {@link Binder#bindConstant} elements. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -class BindingProcessor extends AbstractProcessor { - - private final List creationListeners = Lists.newArrayList(); - private final Initializer initializer; - private final List uninitializedBindings = Lists.newArrayList(); - - BindingProcessor(Errors errors, Initializer initializer) { - super(errors); - this.initializer = initializer; - } - - @Override public Boolean visit(Binding command) { - final Object source = command.getSource(); - - if (Void.class.equals(command.getKey().getRawType())) { - if (command instanceof ProviderInstanceBinding - && ((ProviderInstanceBinding) command).getProviderInstance() instanceof ProviderMethod) { - errors.voidProviderMethod(); - } else { - errors.missingConstantValues(); - } - return true; - } - - final Key key = command.getKey(); - Class rawType = key.getTypeLiteral().getRawType(); - - if (rawType == Provider.class) { - errors.bindingToProvider(); - return true; - } - - validateKey(command.getSource(), command.getKey()); - - final Scoping scoping = Scopes.makeInjectable( - ((BindingImpl) command).getScoping(), injector, errors); - - command.acceptTargetVisitor(new BindingTargetVisitor() { - - public Void visit(InstanceBinding binding) { - Set injectionPoints = binding.getInjectionPoints(); - T instance = binding.getInstance(); - Initializable ref = initializer.requestInjection( - injector, instance, source, injectionPoints); - ConstantFactory factory = new ConstantFactory(ref); - InternalFactory scopedFactory = Scopes.scope(key, injector, factory, scoping); - putBinding(new InstanceBindingImpl(injector, key, source, scopedFactory, injectionPoints, - instance)); - return null; - } - - public Void visit(ProviderInstanceBinding binding) { - Provider provider = binding.getProviderInstance(); - Set injectionPoints = binding.getInjectionPoints(); - Initializable> initializable = initializer - .>requestInjection(injector, provider, source, injectionPoints); - InternalFactory factory = new InternalFactoryToProviderAdapter(initializable, source); - InternalFactory scopedFactory = Scopes.scope(key, injector, factory, scoping); - putBinding(new ProviderInstanceBindingImpl(injector, key, source, scopedFactory, scoping, - provider, injectionPoints)); - return null; - } - - public Void visit(ProviderKeyBinding binding) { - Key> providerKey = binding.getProviderKey(); - BoundProviderFactory boundProviderFactory - = new BoundProviderFactory(injector, providerKey, source); - creationListeners.add(boundProviderFactory); - InternalFactory scopedFactory = Scopes.scope( - key, injector, (InternalFactory) boundProviderFactory, scoping); - putBinding(new LinkedProviderBindingImpl( - injector, key, source, scopedFactory, scoping, providerKey)); - return null; - } - - public Void visit(LinkedKeyBinding binding) { - Key linkedKey = binding.getLinkedKey(); - if (key.equals(linkedKey)) { - errors.recursiveBinding(); - } - - FactoryProxy factory = new FactoryProxy(injector, key, linkedKey, source); - creationListeners.add(factory); - InternalFactory scopedFactory = Scopes.scope(key, injector, factory, scoping); - putBinding( - new LinkedBindingImpl(injector, key, source, scopedFactory, scoping, linkedKey)); - return null; - } - - public Void visit(UntargettedBinding untargetted) { - // Error: Missing implementation. - // Example: bind(Date.class).annotatedWith(Red.class); - // We can't assume abstract types aren't injectable. They may have an - // @ImplementedBy annotation or something. - if (key.hasAnnotationType()) { - errors.missingImplementation(key); - putBinding(invalidBinding(injector, key, source)); - return null; - } - - // This cast is safe after the preceeding check. - final BindingImpl binding; - try { - binding = injector.createUnitializedBinding(key, scoping, source, errors); - putBinding(binding); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - putBinding(invalidBinding(injector, key, source)); - return null; - } - - uninitializedBindings.add(new Runnable() { - public void run() { - try { - ((InjectorImpl) binding.getInjector()).initializeBinding( - binding, errors.withSource(source)); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - } - }); - - return null; - } - - public Void visit(ExposedBinding binding) { - throw new IllegalArgumentException("Cannot apply a non-module element"); - } - - public Void visit(ConvertedConstantBinding binding) { - throw new IllegalArgumentException("Cannot apply a non-module element"); - } - - public Void visit(ConstructorBinding binding) { - throw new IllegalArgumentException("Cannot apply a non-module element"); - } - - public Void visit(ProviderBinding binding) { - throw new IllegalArgumentException("Cannot apply a non-module element"); - } - }); - - return true; - } - - @Override public Boolean visit(PrivateElements privateElements) { - for (Key key : privateElements.getExposedKeys()) { - bindExposed(privateElements, key); - } - return false; // leave the private elements for the PrivateElementsProcessor to handle - } - - private void bindExposed(PrivateElements privateElements, Key key) { - ExposedKeyFactory exposedKeyFactory = new ExposedKeyFactory(key, privateElements); - creationListeners.add(exposedKeyFactory); - putBinding(new ExposedBindingImpl( - injector, privateElements.getExposedSource(key), key, exposedKeyFactory, privateElements)); - } - - private void validateKey(Object source, Key key) { - Annotations.checkForMisplacedScopeAnnotations(key.getRawType(), source, errors); - } - - UntargettedBindingImpl invalidBinding(InjectorImpl injector, Key key, Object source) { - return new UntargettedBindingImpl(injector, key, source); - } - - public void initializeBindings() { - for (Runnable initializer : uninitializedBindings) { - initializer.run(); - } - } - - public void runCreationListeners() { - for (CreationListener creationListener : creationListeners) { - creationListener.notify(errors); - } - } - - private void putBinding(BindingImpl binding) { - Key key = binding.getKey(); - - Class rawType = key.getRawType(); - if (FORBIDDEN_TYPES.contains(rawType)) { - errors.cannotBindToGuiceType(rawType.getSimpleName()); - return; - } - - Binding original = injector.state.getExplicitBinding(key); - if (original != null && !isOkayDuplicate(original, binding)) { - errors.bindingAlreadySet(key, original.getSource()); - return; - } - - // prevent the parent from creating a JIT binding for this key - injector.state.parent().blacklist(key); - injector.state.putBinding(key, binding); - } - - /** - * We tolerate duplicate bindings only if one exposes the other. - * - * @param original the binding in the parent injector (candidate for an exposing binding) - * @param binding the binding to check (candidate for the exposed binding) - */ - private boolean isOkayDuplicate(Binding original, BindingImpl binding) { - if (original instanceof ExposedBindingImpl) { - ExposedBindingImpl exposed = (ExposedBindingImpl) original; - InjectorImpl exposedFrom = (InjectorImpl) exposed.getPrivateElements().getInjector(); - return (exposedFrom == binding.getInjector()); - } - return false; - } - - // It's unfortunate that we have to maintain a blacklist of specific - // classes, but we can't easily block the whole package because of - // all our unit tests. - private static final Set> FORBIDDEN_TYPES = ImmutableSet.of( - AbstractModule.class, - Binder.class, - Binding.class, - Injector.class, - Key.class, - MembersInjector.class, - Module.class, - Provider.class, - Scope.class, - TypeLiteral.class); - // TODO(jessewilson): fix BuiltInModule, then add Stage - - interface CreationListener { - void notify(Errors errors); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BoundProviderFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BoundProviderFactory.java deleted file mode 100644 index eab8faf0166..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/BoundProviderFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.BindingProcessor.CreationListener; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.internal.InternalFactory; -import org.elasticsearch.util.inject.spi.Dependency; - -/** - * Delegates to a custom factory which is also bound in the injector. - */ -class BoundProviderFactory implements InternalFactory, CreationListener { - - private final InjectorImpl injector; - final Key> providerKey; - final Object source; - private InternalFactory> providerFactory; - - BoundProviderFactory( - InjectorImpl injector, - Key> providerKey, - Object source) { - this.injector = injector; - this.providerKey = providerKey; - this.source = source; - } - - public void notify(Errors errors) { - try { - providerFactory = injector.getInternalFactory(providerKey, errors.withSource(source)); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - } - - public T get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException { - errors = errors.withSource(providerKey); - Provider provider = providerFactory.get(errors, context, dependency); - try { - return errors.checkForNull(provider.get(), source, dependency); - } catch(RuntimeException userException) { - throw errors.errorInProvider(userException).toException(); - } - } - - @Override public String toString() { - return providerKey.toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConfigurationException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConfigurationException.java deleted file mode 100644 index acf28ca8eb9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConfigurationException.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.Message; - -import java.util.Collection; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Thrown when a programming error such as a misplaced annotation, illegal binding, or unsupported - * scope is found. Clients should catch this exception, log it, and stop execution. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class ConfigurationException extends RuntimeException { - - private final ImmutableSet messages; - private Object partialValue = null; - - /** Creates a ConfigurationException containing {@code messages}. */ - public ConfigurationException(Iterable messages) { - this.messages = ImmutableSet.copyOf(messages); - initCause(Errors.getOnlyCause(this.messages)); - } - - /** Returns a copy of this configuration exception with the specified partial value. */ - public ConfigurationException withPartialValue(Object partialValue) { - checkState(this.partialValue == null, - "Can't clobber existing partial value %s with %s", this.partialValue, partialValue); - ConfigurationException result = new ConfigurationException(messages); - result.partialValue = partialValue; - return result; - } - - /** Returns messages for the errors that caused this exception. */ - public Collection getErrorMessages() { - return messages; - } - - /** - * Returns a value that was only partially computed due to this exception. The caller can use - * this while collecting additional configuration problems. - * - * @return the partial value, or {@code null} if none was set. The type of the partial value is - * specified by the throwing method. - */ - @SuppressWarnings("unchecked") // this is *extremely* unsafe. We trust the caller here. - public E getPartialValue() { - return (E) partialValue; - } - - @Override public String getMessage() { - return Errors.format("Guice configuration errors", messages); - } - - private static final long serialVersionUID = 0; -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstantFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstantFactory.java deleted file mode 100644 index 40413ea4e60..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstantFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.internal.InternalFactory; -import org.elasticsearch.util.inject.internal.ToStringBuilder; -import org.elasticsearch.util.inject.spi.Dependency; - -/** - * @author crazybob@google.com (Bob Lee) - */ -class ConstantFactory implements InternalFactory { - - private final Initializable initializable; - - public ConstantFactory(Initializable initializable) { - this.initializable = initializable; - } - - public T get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException { - return initializable.get(errors); - } - - public String toString() { - return new ToStringBuilder(ConstantFactory.class) - .add("value", initializable) - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructionProxy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructionProxy.java deleted file mode 100644 index 5835c2fae34..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructionProxy.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.spi.InjectionPoint; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -/** - * Proxies calls to a {@link java.lang.reflect.Constructor} for a class - * {@code T}. - * - * @author crazybob@google.com (Bob Lee) - */ -interface ConstructionProxy { - - /** - * Constructs an instance of {@code T} for the given arguments. - */ - T newInstance(Object... arguments) throws InvocationTargetException; - - /** - * Returns the injection point for this constructor. - */ - InjectionPoint getInjectionPoint(); - - /** - * Returns the injected constructor. If the injected constructor is synthetic (such as generated - * code for method interception), the natural constructor is returned. - */ - Constructor getConstructor(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructionProxyFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructionProxyFactory.java deleted file mode 100644 index 112ce7a4428..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructionProxyFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -/** - * Creates {@link ConstructionProxy} instances. - * - * @author crazybob@google.com (Bob Lee) - */ -interface ConstructionProxyFactory { - - /** - * Gets a construction proxy for the given constructor. - */ - ConstructionProxy create(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorBindingImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorBindingImpl.java deleted file mode 100644 index 08c4024c803..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorBindingImpl.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.internal.*; -import org.elasticsearch.util.inject.spi.BindingTargetVisitor; -import org.elasticsearch.util.inject.spi.ConstructorBinding; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.InjectionPoint; - -import java.util.Set; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -class ConstructorBindingImpl extends BindingImpl implements ConstructorBinding { - - private final Factory factory; - - private ConstructorBindingImpl(Injector injector, Key key, Object source, - InternalFactory scopedFactory, Scoping scoping, Factory factory) { - super(injector, key, source, scopedFactory, scoping); - this.factory = factory; - } - - static ConstructorBindingImpl create( - InjectorImpl injector, Key key, Object source, Scoping scoping) { - Factory factoryFactory = new Factory(); - InternalFactory scopedFactory - = Scopes.scope(key, injector, factoryFactory, scoping); - return new ConstructorBindingImpl( - injector, key, source, scopedFactory, scoping, factoryFactory); - } - - public void initialize(InjectorImpl injector, Errors errors) throws ErrorsException { - factory.constructorInjector = injector.constructors.get(getKey().getTypeLiteral(), errors); - } - - public V acceptTargetVisitor(BindingTargetVisitor visitor) { - checkState(factory.constructorInjector != null, "not initialized"); - return visitor.visit(this); - } - - public InjectionPoint getConstructor() { - checkState(factory.constructorInjector != null, "Binding is not ready"); - return factory.constructorInjector.getConstructionProxy().getInjectionPoint(); - } - - public Set getInjectableMembers() { - checkState(factory.constructorInjector != null, "Binding is not ready"); - return factory.constructorInjector.getInjectableMembers(); - } - - public Set> getDependencies() { - return Dependency.forInjectionPoints(new ImmutableSet.Builder() - .add(getConstructor()) - .addAll(getInjectableMembers()) - .build()); - } - - public void applyTo(Binder binder) { - throw new UnsupportedOperationException("This element represents a synthetic binding."); - } - - @Override public String toString() { - return new ToStringBuilder(ConstructorBinding.class) - .add("key", getKey()) - .add("source", getSource()) - .add("scope", getScoping()) - .toString(); - } - - private static class Factory implements InternalFactory { - private ConstructorInjector constructorInjector; - - @SuppressWarnings("unchecked") - public T get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException { - checkState(constructorInjector != null, "Constructor not ready"); - - // This may not actually be safe because it could return a super type of T (if that's all the - // client needs), but it should be OK in practice thanks to the wonders of erasure. - return (T) constructorInjector.construct(errors, context, dependency.getKey().getRawType()); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorInjector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorInjector.java deleted file mode 100644 index 0d960414676..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorInjector.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.internal.ConstructionContext; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.spi.InjectionPoint; - -import java.lang.reflect.InvocationTargetException; - -/** - * Creates instances using an injectable constructor. After construction, all injectable fields and - * methods are injected. - * - * @author crazybob@google.com (Bob Lee) - */ -class ConstructorInjector { - - private final ImmutableSet injectableMembers; - private final SingleParameterInjector[] parameterInjectors; - private final ConstructionProxy constructionProxy; - private final MembersInjectorImpl membersInjector; - - ConstructorInjector(ImmutableSet injectableMembers, - ConstructionProxy constructionProxy, - SingleParameterInjector[] parameterInjectors, - MembersInjectorImpl membersInjector) - throws ErrorsException { - this.injectableMembers = injectableMembers; - this.constructionProxy = constructionProxy; - this.parameterInjectors = parameterInjectors; - this.membersInjector = membersInjector; - } - - public ImmutableSet getInjectableMembers() { - return injectableMembers; - } - - ConstructionProxy getConstructionProxy() { - return constructionProxy; - } - - /** - * Construct an instance. Returns {@code Object} instead of {@code T} because - * it may return a proxy. - */ - Object construct(Errors errors, InternalContext context, Class expectedType) - throws ErrorsException { - ConstructionContext constructionContext = context.getConstructionContext(this); - - // We have a circular reference between constructors. Return a proxy. - if (constructionContext.isConstructing()) { - // TODO (crazybob): if we can't proxy this object, can we proxy the other object? - return constructionContext.createProxy(errors, expectedType); - } - - // If we're re-entering this factory while injecting fields or methods, - // return the same instance. This prevents infinite loops. - T t = constructionContext.getCurrentReference(); - if (t != null) { - return t; - } - - try { - // First time through... - constructionContext.startConstruction(); - try { - Object[] parameters = SingleParameterInjector.getAll(errors, context, parameterInjectors); - t = constructionProxy.newInstance(parameters); - constructionContext.setProxyDelegates(t); - } finally { - constructionContext.finishConstruction(); - } - - // Store reference. If an injector re-enters this factory, they'll get the same reference. - constructionContext.setCurrentReference(t); - - membersInjector.injectMembers(t, errors, context); - membersInjector.notifyListeners(t, errors); - - return t; - } catch (InvocationTargetException userException) { - Throwable cause = userException.getCause() != null - ? userException.getCause() - : userException; - throw errors.withSource(constructionProxy.getInjectionPoint()) - .errorInjectingConstructor(cause).toException(); - } finally { - constructionContext.removeCurrentReference(); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorInjectorStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorInjectorStore.java deleted file mode 100644 index c7d28f63205..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ConstructorInjectorStore.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.FailableCache; -import org.elasticsearch.util.inject.spi.InjectionPoint; - -/** - * Constructor injectors by type. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -class ConstructorInjectorStore { - private final InjectorImpl injector; - - private final FailableCache, ConstructorInjector> cache - = new FailableCache, ConstructorInjector> () { - @SuppressWarnings("unchecked") - protected ConstructorInjector create(TypeLiteral type, Errors errors) - throws ErrorsException { - return createConstructor(type, errors); - } - }; - - ConstructorInjectorStore(InjectorImpl injector) { - this.injector = injector; - } - - /** - * Returns a new complete constructor injector with injection listeners registered. - */ - @SuppressWarnings("unchecked") // the ConstructorInjector type always agrees with the passed type - public ConstructorInjector get(TypeLiteral key, Errors errors) throws ErrorsException { - return (ConstructorInjector) cache.get(key, errors); - } - - private ConstructorInjector createConstructor(TypeLiteral type, Errors errors) - throws ErrorsException { - int numErrorsBefore = errors.size(); - - InjectionPoint injectionPoint; - try { - injectionPoint = InjectionPoint.forConstructorOf(type); - } catch (ConfigurationException e) { - errors.merge(e.getErrorMessages()); - throw errors.toException(); - } - - SingleParameterInjector[] constructorParameterInjectors - = injector.getParametersInjectors(injectionPoint.getDependencies(), errors); - MembersInjectorImpl membersInjector = injector.membersInjectorStore.get(type, errors); - - ConstructionProxyFactory factory = new DefaultConstructionProxyFactory(injectionPoint); - - errors.throwIfNewErrors(numErrorsBefore); - - return new ConstructorInjector(membersInjector.getInjectionPoints(), factory.create(), - constructorParameterInjectors, membersInjector); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ContextualCallable.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ContextualCallable.java deleted file mode 100644 index 67d3c45372a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ContextualCallable.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; - -/** - * @author crazybob@google.com (Bob Lee) -*/ -interface ContextualCallable { - T call(InternalContext context) throws ErrorsException; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/CreationException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/CreationException.java deleted file mode 100644 index 490698ba771..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/CreationException.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.Message; - -import java.util.Collection; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Thrown when errors occur while creating a {@link Injector}. Includes a list of encountered - * errors. Clients should catch this exception, log it, and stop execution. - * - * @author crazybob@google.com (Bob Lee) - */ -public class CreationException extends RuntimeException { - - private final ImmutableSet messages; - - /** Creates a CreationException containing {@code messages}. */ - public CreationException(Collection messages) { - this.messages = ImmutableSet.copyOf(messages); - checkArgument(!this.messages.isEmpty()); - initCause(Errors.getOnlyCause(this.messages)); - } - - /** Returns messages for the errors that caused this exception. */ - public Collection getErrorMessages() { - return messages; - } - - @Override public String getMessage() { - return Errors.format("Guice creation errors", messages); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/DefaultConstructionProxyFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/DefaultConstructionProxyFactory.java deleted file mode 100644 index e9d43aac956..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/DefaultConstructionProxyFactory.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.spi.InjectionPoint; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; - -/** - * Produces construction proxies that invoke the class constructor. - * - * @author crazybob@google.com (Bob Lee) - */ -class DefaultConstructionProxyFactory implements ConstructionProxyFactory { - - private final InjectionPoint injectionPoint; - - /** - * @param injectionPoint an injection point whose member is a constructor of {@code T}. - */ - DefaultConstructionProxyFactory(InjectionPoint injectionPoint) { - this.injectionPoint = injectionPoint; - } - - public ConstructionProxy create() { - @SuppressWarnings("unchecked") // the injection point is for a constructor of T - final Constructor constructor = (Constructor) injectionPoint.getMember(); - - // Use FastConstructor if the constructor is public. - if (Modifier.isPublic(constructor.getModifiers())) { - } else { - constructor.setAccessible(true); - } - - return new ConstructionProxy() { - public T newInstance(Object... arguments) throws InvocationTargetException { - try { - return constructor.newInstance(arguments); - } catch (InstantiationException e) { - throw new AssertionError(e); // shouldn't happen, we know this is a concrete type - } catch (IllegalAccessException e) { - throw new AssertionError(e); // a security manager is blocking us, we're hosed - } - } - public InjectionPoint getInjectionPoint() { - return injectionPoint; - } - public Constructor getConstructor() { - return constructor; - } - }; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/DeferredLookups.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/DeferredLookups.java deleted file mode 100644 index 1af59f2fcbc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/DeferredLookups.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.Element; -import org.elasticsearch.util.inject.spi.MembersInjectorLookup; -import org.elasticsearch.util.inject.spi.ProviderLookup; - -import java.util.List; - -/** - * Returns providers and members injectors that haven't yet been initialized. As a part of injector - * creation it's necessary to {@link #initialize initialize} these lookups. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -class DeferredLookups implements Lookups { - private final InjectorImpl injector; - private final List lookups = Lists.newArrayList(); - - public DeferredLookups(InjectorImpl injector) { - this.injector = injector; - } - - /** - * Initialize the specified lookups, either immediately or when the injector is created. - */ - public void initialize(Errors errors) { - injector.lookups = injector; - new LookupProcessor(errors).process(injector, lookups); - } - - public Provider getProvider(Key key) { - ProviderLookup lookup = new ProviderLookup(key, key); - lookups.add(lookup); - return lookup.getProvider(); - } - - public MembersInjector getMembersInjector(TypeLiteral type) { - MembersInjectorLookup lookup = new MembersInjectorLookup(type, type); - lookups.add(lookup); - return lookup.getMembersInjector(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/EncounterImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/EncounterImpl.java deleted file mode 100644 index 67fe447398c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/EncounterImpl.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.InjectionListener; -import org.elasticsearch.util.inject.spi.Message; -import org.elasticsearch.util.inject.spi.TypeEncounter; - -import java.util.List; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * @author jessewilson@google.com (Jesse Wilson) - */ -final class EncounterImpl implements TypeEncounter { - - private final Errors errors; - private final Lookups lookups; - private List> membersInjectors; // lazy - private List> injectionListeners; // lazy - private boolean valid = true; - - public EncounterImpl(Errors errors, Lookups lookups) { - this.errors = errors; - this.lookups = lookups; - } - - public void invalidate() { - valid = false; - } - - public ImmutableList> getMembersInjectors() { - return membersInjectors == null - ? ImmutableList.>of() - : ImmutableList.copyOf(membersInjectors); - } - - public ImmutableList> getInjectionListeners() { - return injectionListeners == null - ? ImmutableList.>of() - : ImmutableList.copyOf(injectionListeners); - } - - public void register(MembersInjector membersInjector) { - checkState(valid, "Encounters may not be used after hear() returns."); - - if (membersInjectors == null) { - membersInjectors = Lists.newArrayList(); - } - - membersInjectors.add(membersInjector); - } - - public void register(InjectionListener injectionListener) { - checkState(valid, "Encounters may not be used after hear() returns."); - - if (injectionListeners == null) { - injectionListeners = Lists.newArrayList(); - } - - injectionListeners.add(injectionListener); - } - - public void addError(String message, Object... arguments) { - checkState(valid, "Encounters may not be used after hear() returns."); - errors.addMessage(message, arguments); - } - - public void addError(Throwable t) { - checkState(valid, "Encounters may not be used after hear() returns."); - errors.errorInUserCode(t, "An exception was caught and reported. Message: %s", t.getMessage()); - } - - public void addError(Message message) { - checkState(valid, "Encounters may not be used after hear() returns."); - errors.addMessage(message); - } - - public Provider getProvider(Key key) { - checkState(valid, "Encounters may not be used after hear() returns."); - return lookups.getProvider(key); - } - - public Provider getProvider(Class type) { - return getProvider(Key.get(type)); - } - - public MembersInjector getMembersInjector(TypeLiteral typeLiteral) { - checkState(valid, "Encounters may not be used after hear() returns."); - return lookups.getMembersInjector(typeLiteral); - } - - public MembersInjector getMembersInjector(Class type) { - return getMembersInjector(TypeLiteral.get(type)); - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Exposed.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Exposed.java deleted file mode 100644 index 5615f45fbbe..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Exposed.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * Acccompanies a {@literal @}{@link org.elasticsearch.util.inject.Provides Provides} method annotation in a - * private module to indicate that the provided binding is exposed. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -@Target(ElementType.METHOD) @Retention(RUNTIME) @Documented -public @interface Exposed {} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ExposedKeyFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ExposedKeyFactory.java deleted file mode 100644 index 4193241c7a4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ExposedKeyFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.BindingImpl; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.internal.InternalFactory; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.PrivateElements; - -/** - * This factory exists in a parent injector. When invoked, it retrieves its value from a child - * injector. - */ -class ExposedKeyFactory implements InternalFactory, BindingProcessor.CreationListener { - private final Key key; - private final PrivateElements privateElements; - private BindingImpl delegate; - - public ExposedKeyFactory(Key key, PrivateElements privateElements) { - this.key = key; - this.privateElements = privateElements; - } - - public void notify(Errors errors) { - InjectorImpl privateInjector = (InjectorImpl) privateElements.getInjector(); - BindingImpl explicitBinding = privateInjector.state.getExplicitBinding(key); - - // validate that the child injector has its own factory. If the getInternalFactory() returns - // this, then that child injector doesn't have a factory (and getExplicitBinding has returned - // its parent's binding instead - if (explicitBinding.getInternalFactory() == this) { - errors.withSource(explicitBinding.getSource()).exposedButNotBound(key); - return; - } - - this.delegate = explicitBinding; - } - - public T get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException { - return delegate.getInternalFactory().get(errors, context, dependency); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/FactoryProxy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/FactoryProxy.java deleted file mode 100644 index 38ca8a626db..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/FactoryProxy.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.internal.InternalFactory; -import org.elasticsearch.util.inject.internal.ToStringBuilder; -import org.elasticsearch.util.inject.spi.Dependency; - -/** - * A placeholder which enables us to swap in the real factory once the injector is created. - */ -class FactoryProxy implements InternalFactory, BindingProcessor.CreationListener { - - private final InjectorImpl injector; - private final Key key; - private final Key targetKey; - private final Object source; - - private InternalFactory targetFactory; - - FactoryProxy(InjectorImpl injector, Key key, Key targetKey, Object source) { - this.injector = injector; - this.key = key; - this.targetKey = targetKey; - this.source = source; - } - - public void notify(final Errors errors) { - try { - targetFactory = injector.getInternalFactory(targetKey, errors.withSource(source)); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - } - - public T get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException { - return targetFactory.get(errors.withSource(targetKey), context, dependency); - } - - @Override public String toString() { - return new ToStringBuilder(FactoryProxy.class) - .add("key", key) - .add("provider", targetFactory) - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Guice.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Guice.java deleted file mode 100644 index 57919a4b096..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Guice.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import java.util.Arrays; - -/** - * The entry point to the Guice framework. Creates {@link Injector}s from - * {@link Module}s. - * - *

Guice supports a model of development that draws clear boundaries between - * APIs, Implementations of these APIs, Modules which configure these - * implementations, and finally Applications which consist of a collection of - * Modules. It is the Application, which typically defines your {@code main()} - * method, that bootstraps the Guice Injector using the {@code Guice} class, as - * in this example: - *

- *     public class FooApplication {
- *       public static void main(String[] args) {
- *         Injector injector = Guice.createInjector(
- *             new ModuleA(),
- *             new ModuleB(),
- *             . . .
- *             new FooApplicationFlagsModule(args)
- *         );
- *
- *         // Now just bootstrap the application and you're done
- *         FooStarter starter = injector.getInstance(FooStarter.class);
- *         starter.runApplication();
- *       }
- *     }
- * 
- */ -public final class Guice { - - private Guice() {} - - /** - * Creates an injector for the given set of modules. - * - * @throws CreationException if one or more errors occur during Injector - * construction - */ - public static Injector createInjector(Module... modules) { - return createInjector(Arrays.asList(modules)); - } - - /** - * Creates an injector for the given set of modules. - * - * @throws CreationException if one or more errors occur during Injector - * creation - */ - public static Injector createInjector(Iterable modules) { - return createInjector(Stage.DEVELOPMENT, modules); - } - - /** - * Creates an injector for the given set of modules, in a given development - * stage. - * - * @throws CreationException if one or more errors occur during Injector - * creation - */ - public static Injector createInjector(Stage stage, Module... modules) { - return createInjector(stage, Arrays.asList(modules)); - } - - /** - * Creates an injector for the given set of modules, in a given development - * stage. - * - * @throws CreationException if one or more errors occur during Injector - * construction - */ - public static Injector createInjector(Stage stage, - Iterable modules) { - return new InjectorBuilder() - .stage(stage) - .addModules(modules) - .build(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ImplementedBy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ImplementedBy.java deleted file mode 100644 index b5a9f3c07cd..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ImplementedBy.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import static java.lang.annotation.ElementType.TYPE; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * A pointer to the default implementation of a type. - * - * @author crazybob@google.com (Bob Lee) - */ -@Retention(RUNTIME) -@Target(TYPE) -public @interface ImplementedBy { - - /** - * The implementation type. - */ - Class value(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InheritingState.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InheritingState.java deleted file mode 100644 index d680414919e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InheritingState.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.inject.internal.BindingImpl; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.MatcherAndConverter; -import org.elasticsearch.util.inject.spi.TypeListenerBinding; - -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * @author jessewilson@google.com (Jesse Wilson) - */ -class InheritingState implements State { - - private final State parent; - - // Must be a linked hashmap in order to preserve order of bindings in Modules. - private final Map, Binding> explicitBindingsMutable = Maps.newLinkedHashMap(); - private final Map, Binding> explicitBindings - = Collections.unmodifiableMap(explicitBindingsMutable); - private final Map, Scope> scopes = Maps.newHashMap(); - private final List converters = Lists.newArrayList(); - private final List listenerBindings = Lists.newArrayList(); - private final WeakKeySet blacklistedKeys = new WeakKeySet(); - private final Object lock; - - InheritingState(State parent) { - this.parent = checkNotNull(parent, "parent"); - this.lock = (parent == State.NONE) ? this : parent.lock(); - } - - public State parent() { - return parent; - } - - @SuppressWarnings("unchecked") // we only put in BindingImpls that match their key types - public BindingImpl getExplicitBinding(Key key) { - Binding binding = explicitBindings.get(key); - return binding != null ? (BindingImpl) binding : parent.getExplicitBinding(key); - } - - public Map, Binding> getExplicitBindingsThisLevel() { - return explicitBindings; - } - - public void putBinding(Key key, BindingImpl binding) { - explicitBindingsMutable.put(key, binding); - } - - public Scope getScope(Class annotationType) { - Scope scope = scopes.get(annotationType); - return scope != null ? scope : parent.getScope(annotationType); - } - - public void putAnnotation(Class annotationType, Scope scope) { - scopes.put(annotationType, scope); - } - - public Iterable getConvertersThisLevel() { - return converters; - } - - public void addConverter(MatcherAndConverter matcherAndConverter) { - converters.add(matcherAndConverter); - } - - public MatcherAndConverter getConverter( - String stringValue, TypeLiteral type, Errors errors, Object source) { - MatcherAndConverter matchingConverter = null; - for (State s = this; s != State.NONE; s = s.parent()) { - for (MatcherAndConverter converter : s.getConvertersThisLevel()) { - if (converter.getTypeMatcher().matches(type)) { - if (matchingConverter != null) { - errors.ambiguousTypeConversion(stringValue, source, type, matchingConverter, converter); - } - matchingConverter = converter; - } - } - } - return matchingConverter; - } - - public void addTypeListener(TypeListenerBinding listenerBinding) { - listenerBindings.add(listenerBinding); - } - - public List getTypeListenerBindings() { - List parentBindings = parent.getTypeListenerBindings(); - List result - = new ArrayList(parentBindings.size() + 1); - result.addAll(parentBindings); - result.addAll(listenerBindings); - return result; - } - - public void blacklist(Key key) { - parent.blacklist(key); - blacklistedKeys.add(key); - } - - public boolean isBlacklisted(Key key) { - return blacklistedKeys.contains(key); - } - - public Object lock() { - return lock; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializable.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializable.java deleted file mode 100644 index 39ecbd046e2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializable.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; - -/** - * Holds a reference that requires initialization to be performed before it can be used. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -interface Initializable { - - /** - * Ensures the reference is initialized, then returns it. - */ - T get(Errors errors) throws ErrorsException; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializables.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializables.java deleted file mode 100644 index 872149e5a2d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializables.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; - -/** - * @author jessewilson@google.com (Jesse Wilson) - */ -class Initializables { - - /** - * Returns an initializable for an instance that requires no initialization. - */ - static Initializable of(final T instance) { - return new Initializable() { - public T get(Errors errors) throws ErrorsException { - return instance; - } - - @Override public String toString() { - return String.valueOf(instance); - } - }; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializer.java deleted file mode 100644 index c464a329ce2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Initializer.java +++ /dev/null @@ -1,157 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.spi.InjectionPoint; - -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CountDownLatch; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Manages and injects instances at injector-creation time. This is made more complicated by - * instances that request other instances while they're being injected. We overcome this by using - * {@link Initializable}, which attempts to perform injection before use. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -class Initializer { - /** the only thread that we'll use to inject members. */ - private final Thread creatingThread = Thread.currentThread(); - - /** zero means everything is injected. */ - private final CountDownLatch ready = new CountDownLatch(1); - - /** Maps instances that need injection to a source that registered them */ - private final Map> pendingInjection = Maps.newIdentityHashMap(); - - /** - * Registers an instance for member injection when that step is performed. - * - * @param instance an instance that optionally has members to be injected (each annotated with - * @Inject). - * @param source the source location that this injection was requested - */ - public Initializable requestInjection(InjectorImpl injector, T instance, Object source, - Set injectionPoints) { - checkNotNull(source); - - // short circuit if the object has no injections - if (instance == null - || (injectionPoints.isEmpty() && !injector.membersInjectorStore.hasTypeListeners())) { - return Initializables.of(instance); - } - - InjectableReference initializable = new InjectableReference(injector, instance, source); - pendingInjection.put(instance, initializable); - return initializable; - } - - /** - * Prepares member injectors for all injected instances. This prompts Guice to do static analysis - * on the injected instances. - */ - void validateOustandingInjections(Errors errors) { - for (InjectableReference reference : pendingInjection.values()) { - try { - reference.validate(errors); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - } - } - - /** - * Performs creation-time injections on all objects that require it. Whenever fulfilling an - * injection depends on another object that requires injection, we inject it first. If the two - * instances are codependent (directly or transitively), ordering of injection is arbitrary. - */ - void injectAll(final Errors errors) { - // loop over a defensive copy since ensureInjected() mutates the set. Unfortunately, that copy - // is made complicated by a bug in IBM's JDK, wherein entrySet().toArray(Object[]) doesn't work - for (InjectableReference reference : Lists.newArrayList(pendingInjection.values())) { - try { - reference.get(errors); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - } - - if (!pendingInjection.isEmpty()) { - throw new AssertionError("Failed to satisfy " + pendingInjection); - } - - ready.countDown(); - } - - private class InjectableReference implements Initializable { - private final InjectorImpl injector; - private final T instance; - private final Object source; - private MembersInjectorImpl membersInjector; - - public InjectableReference(InjectorImpl injector, T instance, Object source) { - this.injector = injector; - this.instance = checkNotNull(instance, "instance"); - this.source = checkNotNull(source, "source"); - } - - public void validate(Errors errors) throws ErrorsException { - @SuppressWarnings("unchecked") // the type of 'T' is a TypeLiteral - TypeLiteral type = TypeLiteral.get((Class) instance.getClass()); - membersInjector = injector.membersInjectorStore.get(type, errors.withSource(source)); - } - - /** - * Reentrant. If {@code instance} was registered for injection at injector-creation time, this - * method will ensure that all its members have been injected before returning. - */ - public T get(Errors errors) throws ErrorsException { - if (ready.getCount() == 0) { - return instance; - } - - // just wait for everything to be injected by another thread - if (Thread.currentThread() != creatingThread) { - try { - ready.await(); - return instance; - } catch (InterruptedException e) { - // Give up, since we don't know if our injection is ready - throw new RuntimeException(e); - } - } - - // toInject needs injection, do it right away. we only do this once, even if it fails - if (pendingInjection.remove(instance) != null) { - membersInjector.injectAndNotify(instance, errors.withSource(source)); - } - - return instance; - } - - @Override public String toString() { - return instance.toString(); - } - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Inject.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Inject.java deleted file mode 100644 index 776307b9d7a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Inject.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import java.lang.annotation.Documented; -import static java.lang.annotation.ElementType.CONSTRUCTOR; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * Annotates members of your implementation class (constructors, methods - * and fields) into which the {@link Injector} should inject values. - * The Injector fulfills injection requests for: - * - *
    - *
  • Every instance it constructs. The class being constructed must have - * exactly one of its constructors marked with {@code @Inject} or must have a - * constructor taking no parameters. The Injector then proceeds to perform - * method and field injections. - * - *
  • Pre-constructed instances passed to {@link Injector#injectMembers}, - * {@link org.elasticsearch.util.inject.binder.LinkedBindingBuilder#toInstance(Object)} and - * {@link org.elasticsearch.util.inject.binder.LinkedBindingBuilder#toProvider(Provider)}. - * In this case all constructors are, of course, ignored. - * - *
  • Static fields and methods of classes which any {@link Module} has - * specifically requested static injection for, using - * {@link Binder#requestStaticInjection}. - *
- * - * In all cases, a member can be injected regardless of its Java access - * specifier (private, default, protected, public). - * - * @author crazybob@google.com (Bob Lee) - */ -@Target({ METHOD, CONSTRUCTOR, FIELD }) -@Retention(RUNTIME) -@Documented -public @interface Inject { - - /** - * If true, and the appropriate binding is not found, - * the Injector will skip injection of this method or field rather than - * produce an error. When applied to a field, any default value already - * assigned to the field will remain (guice will not actively null out the - * field). When applied to a method, the method will only be invoked if - * bindings for all parameters are found. When applied to a - * constructor, an error will result upon Injector creation. - */ - boolean optional() default false; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectionRequestProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectionRequestProcessor.java deleted file mode 100644 index 5380f9bd604..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectionRequestProcessor.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.spi.InjectionPoint; -import org.elasticsearch.util.inject.spi.InjectionRequest; -import org.elasticsearch.util.inject.spi.StaticInjectionRequest; - -import java.util.List; -import java.util.Set; - -/** - * Handles {@link Binder#requestInjection} and {@link Binder#requestStaticInjection} commands. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - * @author mikeward@google.com (Mike Ward) - */ -class InjectionRequestProcessor extends AbstractProcessor { - - private final List staticInjections = Lists.newArrayList(); - private final Initializer initializer; - - InjectionRequestProcessor(Errors errors, Initializer initializer) { - super(errors); - this.initializer = initializer; - } - - @Override public Boolean visit(StaticInjectionRequest request) { - staticInjections.add(new StaticInjection(injector, request)); - return true; - } - - @Override public Boolean visit(InjectionRequest request) { - Set injectionPoints; - try { - injectionPoints = request.getInjectionPoints(); - } catch (ConfigurationException e) { - errors.merge(e.getErrorMessages()); - injectionPoints = e.getPartialValue(); - } - - initializer.requestInjection( - injector, request.getInstance(), request.getSource(), injectionPoints); - return true; - } - - public void validate() { - for (StaticInjection staticInjection : staticInjections) { - staticInjection.validate(); - } - } - - public void injectMembers() { - for (StaticInjection staticInjection : staticInjections) { - staticInjection.injectMembers(); - } - } - - /** A requested static injection. */ - private class StaticInjection { - final InjectorImpl injector; - final Object source; - final StaticInjectionRequest request; - ImmutableList memberInjectors; - - public StaticInjection(InjectorImpl injector, StaticInjectionRequest request) { - this.injector = injector; - this.source = request.getSource(); - this.request = request; - } - - void validate() { - Errors errorsForMember = errors.withSource(source); - Set injectionPoints; - try { - injectionPoints = request.getInjectionPoints(); - } catch (ConfigurationException e) { - errors.merge(e.getErrorMessages()); - injectionPoints = e.getPartialValue(); - } - memberInjectors = injector.membersInjectorStore.getInjectors( - injectionPoints, errorsForMember); - } - - void injectMembers() { - try { - injector.callInContext(new ContextualCallable() { - public Void call(InternalContext context) { - for (SingleMemberInjector injector : memberInjectors) { - injector.inject(errors, context, null); - } - return null; - } - }); - } catch (ErrorsException e) { - throw new AssertionError(); - } - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Injector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Injector.java deleted file mode 100644 index 9f1c54ecfbe..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Injector.java +++ /dev/null @@ -1,212 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import java.util.List; -import java.util.Map; - -/** - * Builds the graphs of objects that make up your application. The injector tracks the dependencies - * for each type and uses bindings to inject them. This is the core of Guice, although you rarely - * interact with it directly. This "behind-the-scenes" operation is what distinguishes dependency - * injection from its cousin, the service locator pattern. - * - *

Contains several default bindings: - * - *

    - *
  • This {@link Injector} instance itself - *
  • A {@code Provider} for each binding of type {@code T} - *
  • The {@link java.util.logging.Logger} for the class being injected - *
  • The {@link Stage} in which the Injector was created - *
- * - * Injectors are created using the facade class {@link Guice}. - * - *

An injector can also {@link #injectMembers(Object) inject the dependencies} of - * already-constructed instances. This can be used to interoperate with objects created by other - * frameworks or services. - * - *

Injectors can be {@link #createChildInjector(Iterable) hierarchical}. Child injectors inherit - * the configuration of their parent injectors, but the converse does not hold. - * - *

The injector's {@link #getBindings() internal bindings} are available for introspection. This - * enables tools and extensions to operate on an injector reflectively. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -public interface Injector { - - /** - * Injects dependencies into the fields and methods of {@code instance}. Ignores the presence or - * absence of an injectable constructor. - * - *

Whenever Guice creates an instance, it performs this injection automatically (after first - * performing constructor injection), so if you're able to let Guice create all your objects for - * you, you'll never need to use this method. - * - * @param instance to inject members on - * - * @see Binder#getMembersInjector(Class) for a preferred alternative that supports checks before - * run time - */ - void injectMembers(Object instance); - - /** - * Returns the members injector used to inject dependencies into methods and fields on instances - * of the given type {@code T}. - * - * @param typeLiteral type to get members injector for - * @see Binder#getMembersInjector(TypeLiteral) for an alternative that offers up front error - * detection - * @since 2.0 - */ - MembersInjector getMembersInjector(TypeLiteral typeLiteral); - - /** - * Returns the members injector used to inject dependencies into methods and fields on instances - * of the given type {@code T}. When feasible, use {@link Binder#getMembersInjector(TypeLiteral)} - * instead to get increased up front error detection. - * - * @param type type to get members injector for - * @see Binder#getMembersInjector(Class) for an alternative that offers up front error - * detection - * @since 2.0 - */ - MembersInjector getMembersInjector(Class type); - - /** - * Returns all explicit bindings. - * - *

The returned map does not include bindings inherited from a {@link #getParent() parent - * injector}, should one exist. The returned map is guaranteed to iterate (for example, with - * its {@link java.util.Map#entrySet()} iterator) in the order of insertion. In other words, - * the order in which bindings appear in user Modules. - * - *

This method is part of the Guice SPI and is intended for use by tools and extensions. - */ - Map, Binding> getBindings(); - - /** - * Returns the binding for the given injection key. This will be an explicit bindings if the key - * was bound explicitly by a module, or an implicit binding otherwise. The implicit binding will - * be created if necessary. - * - *

This method is part of the Guice SPI and is intended for use by tools and extensions. - * - * @throws ConfigurationException if this injector cannot find or create the binding. - */ - Binding getBinding(Key key); - - /** - * Returns the binding for the given type. This will be an explicit bindings if the injection key - * was bound explicitly by a module, or an implicit binding otherwise. The implicit binding will - * be created if necessary. - * - *

This method is part of the Guice SPI and is intended for use by tools and extensions. - * - * @throws ConfigurationException if this injector cannot find or create the binding. - * @since 2.0 - */ - Binding getBinding(Class type); - - /** - * Returns all explicit bindings for {@code type}. - * - *

This method is part of the Guice SPI and is intended for use by tools and extensions. - */ - List> findBindingsByType(TypeLiteral type); - - /** - * Returns the provider used to obtain instances for the given injection key. When feasible, avoid - * using this method, in favor of having Guice inject your dependencies ahead of time. - * - * @throws ConfigurationException if this injector cannot find or create the provider. - * @see Binder#getProvider(Key) for an alternative that offers up front error detection - */ - Provider getProvider(Key key); - - /** - * Returns the provider used to obtain instances for the given type. When feasible, avoid - * using this method, in favor of having Guice inject your dependencies ahead of time. - * - * @throws ConfigurationException if this injector cannot find or create the provider. - * @see Binder#getProvider(Class) for an alternative that offers up front error detection - */ - Provider getProvider(Class type); - - /** - * Returns the appropriate instance for the given injection key; equivalent to {@code - * getProvider(key).get()}. When feasible, avoid using this method, in favor of having Guice - * inject your dependencies ahead of time. - * - * @throws ConfigurationException if this injector cannot find or create the provider. - * @throws ProvisionException if there was a runtime failure while providing an instance. - */ - T getInstance(Key key); - - /** - * Returns the appropriate instance for the given injection type; equivalent to {@code - * getProvider(type).get()}. When feasible, avoid using this method, in favor of having Guice - * inject your dependencies ahead of time. - * - * @throws ConfigurationException if this injector cannot find or create the provider. - * @throws ProvisionException if there was a runtime failure while providing an instance. - */ - T getInstance(Class type); - - /** - * Returns this injector's parent, or {@code null} if this is a top-level injector. - * - * @since 2.0 - */ - Injector getParent(); - - /** - * Returns a new injector that inherits all state from this injector. All bindings, scopes, - * interceptors and type converters are inherited -- they are visible to the child injector. - * Elements of the child injector are not visible to its parent. - * - *

Just-in-time bindings created for child injectors will be created in an ancestor injector - * whenever possible. This allows for scoped instances to be shared between injectors. Use - * explicit bindings to prevent bindings from being shared with the parent injector. - * - *

No key may be bound by both an injector and one of its ancestors. This includes just-in-time - * bindings. The lone exception is the key for {@code Injector.class}, which is bound by each - * injector to itself. - * - * @since 2.0 - */ - Injector createChildInjector(Iterable modules); - - /** - * Returns a new injector that inherits all state from this injector. All bindings, scopes, - * interceptors and type converters are inherited -- they are visible to the child injector. - * Elements of the child injector are not visible to its parent. - * - *

Just-in-time bindings created for child injectors will be created in an ancestor injector - * whenever possible. This allows for scoped instances to be shared between injectors. Use - * explicit bindings to prevent bindings from being shared with the parent injector. - * - *

No key may be bound by both an injector and one of its ancestors. This includes just-in-time - * bindings. The lone exception is the key for {@code Injector.class}, which is bound by each - * injector to itself. - * - * @since 2.0 - */ - Injector createChildInjector(Module... modules); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorBuilder.java deleted file mode 100644 index c2883605849..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorBuilder.java +++ /dev/null @@ -1,271 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Iterables; -import org.elasticsearch.util.inject.internal.*; -import org.elasticsearch.util.inject.spi.Dependency; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Builds a tree of injectors. This is a primary injector, plus child injectors needed for each - * {@link Binder#newPrivateBinder() private environment}. The primary injector is not necessarily a - * top-level injector. - * - *

Injector construction happens in two phases. - *

    - *
  1. Static building. In this phase, we interpret commands, create bindings, and inspect - * dependencies. During this phase, we hold a lock to ensure consistency with parent injectors. - * No user code is executed in this phase.
  2. - *
  3. Dynamic injection. In this phase, we call user code. We inject members that requested - * injection. This may require user's objects be created and their providers be called. And we - * create eager singletons. In this phase, user code may have started other threads. This phase - * is not executed for injectors created using {@link Stage#TOOL the tool stage}
  4. - *
- * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -class InjectorBuilder { - - private final Stopwatch stopwatch = new Stopwatch(); - private final Errors errors = new Errors(); - - private Stage stage; - - private final Initializer initializer = new Initializer(); - private final BindingProcessor bindingProcesor; - private final InjectionRequestProcessor injectionRequestProcessor; - - private final InjectorShell.Builder shellBuilder = new InjectorShell.Builder(); - private List shells; - - InjectorBuilder() { - injectionRequestProcessor = new InjectionRequestProcessor(errors, initializer); - bindingProcesor = new BindingProcessor(errors, initializer); - } - - /** - * Sets the stage for the created injector. If the stage is {@link Stage#PRODUCTION}, this class - * will eagerly load singletons. - */ - InjectorBuilder stage(Stage stage) { - shellBuilder.stage(stage); - this.stage = stage; - return this; - } - - /** - * Sets the parent of the injector to-be-constructed. As a side effect, this sets this injector's - * stage to the stage of {@code parent}. - */ - InjectorBuilder parentInjector(InjectorImpl parent) { - shellBuilder.parent(parent); - return stage(parent.getInstance(Stage.class)); - } - - InjectorBuilder addModules(Iterable modules) { - shellBuilder.addModules(modules); - return this; - } - - Injector build() { - if (shellBuilder == null) { - throw new AssertionError("Already built, builders are not reusable."); - } - - // Synchronize while we're building up the bindings and other injector state. This ensures that - // the JIT bindings in the parent injector don't change while we're being built - synchronized (shellBuilder.lock()) { - shells = shellBuilder.build(initializer, bindingProcesor, stopwatch, errors); - stopwatch.resetAndLog("Injector construction"); - - initializeStatically(); - } - - // If we're in the tool stage, stop here. Don't eagerly inject or load anything. - if (stage == Stage.TOOL) { - return new ToolStageInjector(primaryInjector()); - } - - injectDynamically(); - - return primaryInjector(); - } - - /** Initialize and validate everything. */ - private void initializeStatically() { - bindingProcesor.initializeBindings(); - stopwatch.resetAndLog("Binding initialization"); - - for (InjectorShell shell : shells) { - shell.getInjector().index(); - } - stopwatch.resetAndLog("Binding indexing"); - - injectionRequestProcessor.process(shells); - stopwatch.resetAndLog("Collecting injection requests"); - - bindingProcesor.runCreationListeners(); - stopwatch.resetAndLog("Binding validation"); - - injectionRequestProcessor.validate(); - stopwatch.resetAndLog("Static validation"); - - initializer.validateOustandingInjections(errors); - stopwatch.resetAndLog("Instance member validation"); - - new LookupProcessor(errors).process(shells); - for (InjectorShell shell : shells) { - ((DeferredLookups) shell.getInjector().lookups).initialize(errors); - } - stopwatch.resetAndLog("Provider verification"); - - for (InjectorShell shell : shells) { - if (!shell.getElements().isEmpty()) { - throw new AssertionError("Failed to execute " + shell.getElements()); - } - } - - errors.throwCreationExceptionIfErrorsExist(); - } - - /** - * Returns the injector being constructed. This is not necessarily the root injector. - */ - private Injector primaryInjector() { - return shells.get(0).getInjector(); - } - - /** - * Inject everything that can be injected. This method is intentionally not synchronized. If we - * locked while injecting members (ie. running user code), things would deadlock should the user - * code build a just-in-time binding from another thread. - */ - private void injectDynamically() { - injectionRequestProcessor.injectMembers(); - stopwatch.resetAndLog("Static member injection"); - - initializer.injectAll(errors); - stopwatch.resetAndLog("Instance injection"); - errors.throwCreationExceptionIfErrorsExist(); - - for (InjectorShell shell : shells) { - loadEagerSingletons(shell.getInjector(), stage, errors); - } - stopwatch.resetAndLog("Preloading singletons"); - errors.throwCreationExceptionIfErrorsExist(); - } - - /** - * Loads eager singletons, or all singletons if we're in Stage.PRODUCTION. Bindings discovered - * while we're binding these singletons are not be eager. - */ - public void loadEagerSingletons(InjectorImpl injector, Stage stage, final Errors errors) { - @SuppressWarnings("unchecked") // casting Collection to Collection is safe - Set> candidateBindings = ImmutableSet.copyOf(Iterables.concat( - (Collection) injector.state.getExplicitBindingsThisLevel().values(), - injector.jitBindings.values())); - for (final BindingImpl binding : candidateBindings) { - if (binding.getScoping().isEagerSingleton(stage)) { - try { - injector.callInContext(new ContextualCallable() { - Dependency dependency = Dependency.get(binding.getKey()); - public Void call(InternalContext context) { - context.setDependency(dependency); - Errors errorsForBinding = errors.withSource(dependency); - try { - binding.getInternalFactory().get(errorsForBinding, context, dependency); - } catch (ErrorsException e) { - errorsForBinding.merge(e.getErrors()); - } finally { - context.setDependency(null); - } - - return null; - } - }); - } catch (ErrorsException e) { - throw new AssertionError(); - } - } - } - } - - /** {@link Injector} exposed to users in {@link Stage#TOOL}. */ - static class ToolStageInjector implements Injector { - private final Injector delegateInjector; - - ToolStageInjector(Injector delegateInjector) { - this.delegateInjector = delegateInjector; - } - public void injectMembers(Object o) { - throw new UnsupportedOperationException( - "Injector.injectMembers(Object) is not supported in Stage.TOOL"); - } - public Map, Binding> getBindings() { - return this.delegateInjector.getBindings(); - } - public Binding getBinding(Key key) { - return this.delegateInjector.getBinding(key); - } - public Binding getBinding(Class type) { - return this.delegateInjector.getBinding(type); - } - public List> findBindingsByType(TypeLiteral type) { - return this.delegateInjector.findBindingsByType(type); - } - public Injector getParent() { - return delegateInjector.getParent(); - } - public Injector createChildInjector(Iterable modules) { - return delegateInjector.createChildInjector(modules); - } - public Injector createChildInjector(Module... modules) { - return delegateInjector.createChildInjector(modules); - } - public Provider getProvider(Key key) { - throw new UnsupportedOperationException( - "Injector.getProvider(Key) is not supported in Stage.TOOL"); - } - public Provider getProvider(Class type) { - throw new UnsupportedOperationException( - "Injector.getProvider(Class) is not supported in Stage.TOOL"); - } - public MembersInjector getMembersInjector(TypeLiteral typeLiteral) { - throw new UnsupportedOperationException( - "Injector.getMembersInjector(TypeLiteral) is not supported in Stage.TOOL"); - } - public MembersInjector getMembersInjector(Class type) { - throw new UnsupportedOperationException( - "Injector.getMembersInjector(Class) is not supported in Stage.TOOL"); - } - public T getInstance(Key key) { - throw new UnsupportedOperationException( - "Injector.getInstance(Key) is not supported in Stage.TOOL"); - } - public T getInstance(Class type) { - throw new UnsupportedOperationException( - "Injector.getInstance(Class) is not supported in Stage.TOOL"); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorImpl.java deleted file mode 100644 index c6092b6e0aa..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorImpl.java +++ /dev/null @@ -1,801 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.Classes; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.inject.internal.*; -import org.elasticsearch.util.inject.spi.*; -import org.elasticsearch.util.inject.util.Providers; - -import java.lang.annotation.Annotation; -import java.lang.reflect.*; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.elasticsearch.util.inject.internal.Annotations.*; - -/** - * Default {@link Injector} implementation. - * - * @author crazybob@google.com (Bob Lee) - * @see InjectorBuilder - */ -class InjectorImpl implements Injector, Lookups { - final State state; - final InjectorImpl parent; - final BindingsMultimap bindingsMultimap = new BindingsMultimap(); - final Initializer initializer; - - /** Just-in-time binding cache. Guarded by state.lock() */ - final Map, BindingImpl> jitBindings = Maps.newHashMap(); - - Lookups lookups = new DeferredLookups(this); - - InjectorImpl(@Nullable InjectorImpl parent, State state, Initializer initializer) { - this.parent = parent; - this.state = state; - this.initializer = initializer; - - if (parent != null) { - localContext = parent.localContext; - } else { - localContext = new ThreadLocal() { - protected Object[] initialValue() { - return new Object[1]; - } - }; - } - } - - /** Indexes bindings by type. */ - void index() { - for (Binding binding : state.getExplicitBindingsThisLevel().values()) { - index(binding); - } - } - - void index(Binding binding) { - bindingsMultimap.put(binding.getKey().getTypeLiteral(), binding); - } - - public List> findBindingsByType(TypeLiteral type) { - return bindingsMultimap.getAll(type); - } - - /** Returns the binding for {@code key} */ - public BindingImpl getBinding(Key key) { - Errors errors = new Errors(key); - try { - BindingImpl result = getBindingOrThrow(key, errors); - errors.throwConfigurationExceptionIfErrorsExist(); - return result; - } catch (ErrorsException e) { - throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); - } - } - - /** - * Gets a binding implementation. First, it check to see if the parent has a binding. If the - * parent has a binding and the binding is scoped, it will use that binding. Otherwise, this - * checks for an explicit binding. If no explicit binding is found, it looks for a just-in-time - * binding. - */ - public BindingImpl getBindingOrThrow(Key key, Errors errors) - throws ErrorsException { - // Check explicit bindings, i.e. bindings created by modules. - BindingImpl binding = state.getExplicitBinding(key); - if (binding != null) { - return binding; - } - - // Look for an on-demand binding. - return getJustInTimeBinding(key, errors); - } - - public Binding getBinding(Class type) { - return getBinding(Key.get(type)); - } - - public Injector getParent() { - return parent; - } - - public Injector createChildInjector(Iterable modules) { - return new InjectorBuilder() - .parentInjector(this) - .addModules(modules) - .build(); - } - - public Injector createChildInjector(Module... modules) { - return createChildInjector(ImmutableList.of(modules)); - } - - /** - * Returns a just-in-time binding for {@code key}, creating it if necessary. - * - * @throws ErrorsException if the binding could not be created. - */ - private BindingImpl getJustInTimeBinding(Key key, Errors errors) - throws ErrorsException { - synchronized (state.lock()) { - // first try to find a JIT binding that we've already created - for (InjectorImpl injector = this; injector != null; injector = injector.parent) { - @SuppressWarnings("unchecked") // we only store bindings that match their key - BindingImpl binding = (BindingImpl) injector.jitBindings.get(key); - - if (binding != null) { - return binding; - } - } - - return createJustInTimeBindingRecursive(key, errors); - } - } - - /** Returns true if the key type is Provider (but not a subclass of Provider). */ - static boolean isProvider(Key key) { - return key.getTypeLiteral().getRawType().equals(Provider.class); - } - - /** Returns true if the key type is MembersInjector (but not a subclass of MembersInjector). */ - static boolean isMembersInjector(Key key) { - return key.getTypeLiteral().getRawType().equals(MembersInjector.class) - && !key.hasAnnotationType(); - } - - private BindingImpl> createMembersInjectorBinding( - Key> key, Errors errors) throws ErrorsException { - Type membersInjectorType = key.getTypeLiteral().getType(); - if (!(membersInjectorType instanceof ParameterizedType)) { - throw errors.cannotInjectRawMembersInjector().toException(); - } - - @SuppressWarnings("unchecked") // safe because T came from Key> - TypeLiteral instanceType = (TypeLiteral) TypeLiteral.get( - ((ParameterizedType) membersInjectorType).getActualTypeArguments()[0]); - MembersInjector membersInjector = membersInjectorStore.get(instanceType, errors); - - InternalFactory> factory = new ConstantFactory>( - Initializables.of(membersInjector)); - - - return new InstanceBindingImpl>(this, key, SourceProvider.UNKNOWN_SOURCE, - factory, ImmutableSet.of(), membersInjector); - } - - /** - * Creates a synthetic binding to {@code Provider}, i.e. a binding to the provider from - * {@code Binding}. - */ - private BindingImpl> createProviderBinding(Key> key, Errors errors) - throws ErrorsException { - Type providerType = key.getTypeLiteral().getType(); - - // If the Provider has no type parameter (raw Provider)... - if (!(providerType instanceof ParameterizedType)) { - throw errors.cannotInjectRawProvider().toException(); - } - - Type entryType = ((ParameterizedType) providerType).getActualTypeArguments()[0]; - - @SuppressWarnings("unchecked") // safe because T came from Key> - Key providedKey = (Key) key.ofType(entryType); - - BindingImpl delegate = getBindingOrThrow(providedKey, errors); - return new ProviderBindingImpl(this, key, delegate); - } - - static class ProviderBindingImpl extends BindingImpl> - implements ProviderBinding> { - final BindingImpl providedBinding; - - ProviderBindingImpl(InjectorImpl injector, Key> key, Binding providedBinding) { - super(injector, key, providedBinding.getSource(), createInternalFactory(providedBinding), - Scoping.UNSCOPED); - this.providedBinding = (BindingImpl) providedBinding; - } - - static InternalFactory> createInternalFactory(Binding providedBinding) { - final Provider provider = providedBinding.getProvider(); - return new InternalFactory>() { - public Provider get(Errors errors, InternalContext context, Dependency dependency) { - return provider; - } - }; - } - - public Key getProvidedKey() { - return providedBinding.getKey(); - } - - public V acceptTargetVisitor(BindingTargetVisitor, V> visitor) { - return visitor.visit(this); - } - - public void applyTo(Binder binder) { - throw new UnsupportedOperationException("This element represents a synthetic binding."); - } - - @Override public String toString() { - return new ToStringBuilder(ProviderKeyBinding.class) - .add("key", getKey()) - .add("providedKey", getProvidedKey()) - .toString(); - } - } - - /** - * Converts a constant string binding to the required type. - * - * @return the binding if it could be resolved, or null if the binding doesn't exist - * @throws org.elasticsearch.util.inject.internal.ErrorsException if there was an error resolving the binding - */ - private BindingImpl convertConstantStringBinding(Key key, Errors errors) - throws ErrorsException { - // Find a constant string binding. - Key stringKey = key.ofType(String.class); - BindingImpl stringBinding = state.getExplicitBinding(stringKey); - if (stringBinding == null || !stringBinding.isConstant()) { - return null; - } - - String stringValue = stringBinding.getProvider().get(); - Object source = stringBinding.getSource(); - - // Find a matching type converter. - TypeLiteral type = key.getTypeLiteral(); - MatcherAndConverter matchingConverter = state.getConverter(stringValue, type, errors, source); - - if (matchingConverter == null) { - // No converter can handle the given type. - return null; - } - - // Try to convert the string. A failed conversion results in an error. - try { - @SuppressWarnings("unchecked") // This cast is safe because we double check below. - T converted = (T) matchingConverter.getTypeConverter().convert(stringValue, type); - - if (converted == null) { - throw errors.converterReturnedNull(stringValue, source, type, matchingConverter) - .toException(); - } - - if (!type.getRawType().isInstance(converted)) { - throw errors.conversionTypeError(stringValue, source, type, matchingConverter, converted) - .toException(); - } - - return new ConvertedConstantBindingImpl(this, key, converted, stringBinding); - } catch (ErrorsException e) { - throw e; - } catch (RuntimeException e) { - throw errors.conversionError(stringValue, source, type, matchingConverter, e) - .toException(); - } - } - - private static class ConvertedConstantBindingImpl - extends BindingImpl implements ConvertedConstantBinding { - final T value; - final Provider provider; - final Binding originalBinding; - - ConvertedConstantBindingImpl( - Injector injector, Key key, T value, Binding originalBinding) { - super(injector, key, originalBinding.getSource(), - new ConstantFactory(Initializables.of(value)), Scoping.UNSCOPED); - this.value = value; - provider = Providers.of(value); - this.originalBinding = originalBinding; - } - - @Override public Provider getProvider() { - return provider; - } - - public V acceptTargetVisitor(BindingTargetVisitor visitor) { - return visitor.visit(this); - } - - public T getValue() { - return value; - } - - public Key getSourceKey() { - return originalBinding.getKey(); - } - - public Set> getDependencies() { - return ImmutableSet.>of(Dependency.get(getSourceKey())); - } - - public void applyTo(Binder binder) { - throw new UnsupportedOperationException("This element represents a synthetic binding."); - } - - @Override public String toString() { - return new ToStringBuilder(ConvertedConstantBinding.class) - .add("key", getKey()) - .add("sourceKey", getSourceKey()) - .add("value", value) - .toString(); - } - } - - void initializeBinding(BindingImpl binding, Errors errors) throws ErrorsException { - // Put the partially constructed binding in the map a little early. This enables us to handle - // circular dependencies. Example: FooImpl -> BarImpl -> FooImpl. - // Note: We don't need to synchronize on state.lock() during injector creation. - // TODO: for the above example, remove the binding for BarImpl if the binding for FooImpl fails - if (binding instanceof ConstructorBindingImpl) { - Key key = binding.getKey(); - jitBindings.put(key, binding); - boolean successful = false; - try { - ((ConstructorBindingImpl) binding).initialize(this, errors); - successful = true; - } finally { - if (!successful) { - jitBindings.remove(key); - } - } - } - } - - /** - * Creates a binding for an injectable type with the given scope. Looks for a scope on the type if - * none is specified. - */ - BindingImpl createUnitializedBinding(Key key, Scoping scoping, Object source, - Errors errors) throws ErrorsException { - Class rawType = key.getTypeLiteral().getRawType(); - - // Don't try to inject arrays, or enums. - if (rawType.isArray() || rawType.isEnum()) { - throw errors.missingImplementation(key).toException(); - } - - // Handle TypeLiteral by binding the inner type - if (rawType == TypeLiteral.class) { - @SuppressWarnings("unchecked") // we have to fudge the inner type as Object - BindingImpl binding = (BindingImpl) createTypeLiteralBinding( - (Key>) key, errors); - return binding; - } - - // Handle @ImplementedBy - ImplementedBy implementedBy = rawType.getAnnotation(ImplementedBy.class); - if (implementedBy != null) { - Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors); - return createImplementedByBinding(key, scoping, implementedBy, errors); - } - - // Handle @ProvidedBy. - ProvidedBy providedBy = rawType.getAnnotation(ProvidedBy.class); - if (providedBy != null) { - Annotations.checkForMisplacedScopeAnnotations(rawType, source, errors); - return createProvidedByBinding(key, scoping, providedBy, errors); - } - - // We can't inject abstract classes. - // TODO: Method interceptors could actually enable us to implement - // abstract types. Should we remove this restriction? - if (Modifier.isAbstract(rawType.getModifiers())) { - throw errors.missingImplementation(key).toException(); - } - - // Error: Inner class. - if (Classes.isInnerClass(rawType)) { - throw errors.cannotInjectInnerClass(rawType).toException(); - } - - if (!scoping.isExplicitlyScoped()) { - Class scopeAnnotation = findScopeAnnotation(errors, rawType); - if (scopeAnnotation != null) { - scoping = Scopes.makeInjectable(Scoping.forAnnotation(scopeAnnotation), - this, errors.withSource(rawType)); - } - } - - return ConstructorBindingImpl.create(this, key, source, scoping); - } - - /** - * Converts a binding for a {@code Key>} to the value {@code TypeLiteral}. It's - * a bit awkward because we have to pull out the inner type in the type literal. - */ - private BindingImpl> createTypeLiteralBinding( - Key> key, Errors errors) throws ErrorsException { - Type typeLiteralType = key.getTypeLiteral().getType(); - if (!(typeLiteralType instanceof ParameterizedType)) { - throw errors.cannotInjectRawTypeLiteral().toException(); - } - - ParameterizedType parameterizedType = (ParameterizedType) typeLiteralType; - Type innerType = parameterizedType.getActualTypeArguments()[0]; - - // this is unforunate. We don't support building TypeLiterals for type variable like 'T'. If - // this proves problematic, we can probably fix TypeLiteral to support type variables - if (!(innerType instanceof Class) - && !(innerType instanceof GenericArrayType) - && !(innerType instanceof ParameterizedType)) { - throw errors.cannotInjectTypeLiteralOf(innerType).toException(); - } - - @SuppressWarnings("unchecked") // by definition, innerType == T, so this is safe - TypeLiteral value = (TypeLiteral) TypeLiteral.get(innerType); - InternalFactory> factory = new ConstantFactory>( - Initializables.of(value)); - return new InstanceBindingImpl>(this, key, SourceProvider.UNKNOWN_SOURCE, - factory, ImmutableSet.of(), value); - } - - /** Creates a binding for a type annotated with @ProvidedBy. */ - BindingImpl createProvidedByBinding(Key key, Scoping scoping, - ProvidedBy providedBy, Errors errors) throws ErrorsException { - final Class rawType = key.getTypeLiteral().getRawType(); - final Class> providerType = providedBy.value(); - - // Make sure it's not the same type. TODO: Can we check for deeper loops? - if (providerType == rawType) { - throw errors.recursiveProviderType().toException(); - } - - // Assume the provider provides an appropriate type. We double check at runtime. - @SuppressWarnings("unchecked") - final Key> providerKey - = (Key>) Key.get(providerType); - final BindingImpl> providerBinding - = getBindingOrThrow(providerKey, errors); - - InternalFactory internalFactory = new InternalFactory() { - public T get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException { - errors = errors.withSource(providerKey); - Provider provider = providerBinding.getInternalFactory().get( - errors, context, dependency); - try { - Object o = provider.get(); - if (o != null && !rawType.isInstance(o)) { - throw errors.subtypeNotProvided(providerType, rawType).toException(); - } - @SuppressWarnings("unchecked") // protected by isInstance() check above - T t = (T) o; - return t; - } catch (RuntimeException e) { - throw errors.errorInProvider(e).toException(); - } - } - }; - - return new LinkedProviderBindingImpl( - this, - key, - rawType /* source */, - Scopes.scope(key, this, internalFactory, scoping), - scoping, - providerKey); - } - - /** Creates a binding for a type annotated with @ImplementedBy. */ - BindingImpl createImplementedByBinding(Key key, Scoping scoping, - ImplementedBy implementedBy, Errors errors) - throws ErrorsException { - Class rawType = key.getTypeLiteral().getRawType(); - Class implementationType = implementedBy.value(); - - // Make sure it's not the same type. TODO: Can we check for deeper cycles? - if (implementationType == rawType) { - throw errors.recursiveImplementationType().toException(); - } - - // Make sure implementationType extends type. - if (!rawType.isAssignableFrom(implementationType)) { - throw errors.notASubtype(implementationType, rawType).toException(); - } - - @SuppressWarnings("unchecked") // After the preceding check, this cast is safe. - Class subclass = (Class) implementationType; - - // Look up the target binding. - final Key targetKey = Key.get(subclass); - final BindingImpl targetBinding = getBindingOrThrow(targetKey, errors); - - InternalFactory internalFactory = new InternalFactory() { - public T get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException { - return targetBinding.getInternalFactory().get( - errors.withSource(targetKey), context, dependency); - } - }; - - return new LinkedBindingImpl( - this, - key, - rawType /* source */, - Scopes.scope(key, this, internalFactory, scoping), - scoping, - targetKey); - } - - /** - * Attempts to create a just-in-time binding for {@code key} in the root injector, falling back to - * other ancestor injectors until this injector is tried. - */ - private BindingImpl createJustInTimeBindingRecursive(Key key, Errors errors) - throws ErrorsException { - // ask the parent to create the JIT binding - if (parent != null) { - try { - return parent.createJustInTimeBindingRecursive(key, new Errors()); - } catch (ErrorsException ignored) { - } - } - - if (state.isBlacklisted(key)) { - throw errors.childBindingAlreadySet(key).toException(); - } - - BindingImpl binding = createJustInTimeBinding(key, errors); - state.parent().blacklist(key); - jitBindings.put(key, binding); - return binding; - } - - /** - * Returns a new just-in-time binding created by resolving {@code key}. The strategies used to - * create just-in-time bindings are: - *
    - *
  1. Internalizing Providers. If the requested binding is for {@code Provider}, we delegate - * to the binding for {@code T}. - *
  2. Converting constants. - *
  3. ImplementedBy and ProvidedBy annotations. Only for unannotated keys. - *
  4. The constructor of the raw type. Only for unannotated keys. - *
- * - * @throws org.elasticsearch.util.inject.internal.ErrorsException if the binding cannot be created. - */ - BindingImpl createJustInTimeBinding(Key key, Errors errors) throws ErrorsException { - if (state.isBlacklisted(key)) { - throw errors.childBindingAlreadySet(key).toException(); - } - - // Handle cases where T is a Provider. - if (isProvider(key)) { - // These casts are safe. We know T extends Provider and that given Key>, - // createProviderBinding() will return BindingImpl>. - @SuppressWarnings("unchecked") - BindingImpl binding = createProviderBinding((Key) key, errors); - return binding; - } - - // Handle cases where T is a MembersInjector - if (isMembersInjector(key)) { - // These casts are safe. T extends MembersInjector and that given Key>, - // createMembersInjectorBinding() will return BindingImpl>. - @SuppressWarnings("unchecked") - BindingImpl binding = createMembersInjectorBinding((Key) key, errors); - return binding; - } - - // Try to convert a constant string binding to the requested type. - BindingImpl convertedBinding = convertConstantStringBinding(key, errors); - if (convertedBinding != null) { - return convertedBinding; - } - - // If the key has an annotation... - if (key.hasAnnotationType()) { - // Look for a binding without annotation attributes or return null. - if (key.hasAttributes()) { - try { - Errors ignored = new Errors(); - return getBindingOrThrow(key.withoutAttributes(), ignored); - } catch (ErrorsException ignored) { - // throw with a more appropriate message below - } - } - throw errors.missingImplementation(key).toException(); - } - - Object source = key.getTypeLiteral().getRawType(); - BindingImpl binding = createUnitializedBinding(key, Scoping.UNSCOPED, source, errors); - initializeBinding(binding, errors); - return binding; - } - - InternalFactory getInternalFactory(Key key, Errors errors) - throws ErrorsException { - return getBindingOrThrow(key, errors).getInternalFactory(); - } - - // not test-covered - public Map, Binding> getBindings() { - return state.getExplicitBindingsThisLevel(); - } - - private static class BindingsMultimap { - final Map, List>> multimap = Maps.newHashMap(); - - void put(TypeLiteral type, Binding binding) { - List> bindingsForType = multimap.get(type); - if (bindingsForType == null) { - bindingsForType = Lists.newArrayList(); - multimap.put(type, bindingsForType); - } - bindingsForType.add(binding); - } - - - @SuppressWarnings("unchecked") // safe because we only put matching entries into the map - List> getAll(TypeLiteral type) { - List> bindings = multimap.get(type); - return bindings != null - ? Collections.>unmodifiableList((List) multimap.get(type)) - : ImmutableList.>of(); - } - } - - /** - * Returns parameter injectors, or {@code null} if there are no parameters. - */ - SingleParameterInjector[] getParametersInjectors( - List> parameters, Errors errors) throws ErrorsException { - if (parameters.isEmpty()) { - return null; - } - - int numErrorsBefore = errors.size(); - SingleParameterInjector[] result = new SingleParameterInjector[parameters.size()]; - int i = 0; - for (Dependency parameter : parameters) { - try { - result[i++] = createParameterInjector(parameter, errors.withSource(parameter)); - } catch (ErrorsException rethrownBelow) { - // rethrown below - } - } - - errors.throwIfNewErrors(numErrorsBefore); - return result; - } - - SingleParameterInjector createParameterInjector(final Dependency dependency, - final Errors errors) throws ErrorsException { - InternalFactory factory = getInternalFactory(dependency.getKey(), errors); - return new SingleParameterInjector(dependency, factory); - } - - /** Invokes a method. */ - interface MethodInvoker { - Object invoke(Object target, Object... parameters) - throws IllegalAccessException, InvocationTargetException; - } - - /** Cached constructor injectors for each type */ - final ConstructorInjectorStore constructors = new ConstructorInjectorStore(this); - - /** Cached field and method injectors for each type. */ - MembersInjectorStore membersInjectorStore; - - @SuppressWarnings("unchecked") // the members injector type is consistent with instance's type - public void injectMembers(Object instance) { - MembersInjector membersInjector = getMembersInjector(instance.getClass()); - membersInjector.injectMembers(instance); - } - - public MembersInjector getMembersInjector(TypeLiteral typeLiteral) { - Errors errors = new Errors(typeLiteral); - try { - return membersInjectorStore.get(typeLiteral, errors); - } catch (ErrorsException e) { - throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); - } - } - - public MembersInjector getMembersInjector(Class type) { - return getMembersInjector(TypeLiteral.get(type)); - } - - public Provider getProvider(Class type) { - return getProvider(Key.get(type)); - } - - Provider getProviderOrThrow(final Key key, Errors errors) throws ErrorsException { - final InternalFactory factory = getInternalFactory(key, errors); - final Dependency dependency = Dependency.get(key); - - return new Provider() { - public T get() { - final Errors errors = new Errors(dependency); - try { - T t = callInContext(new ContextualCallable() { - public T call(InternalContext context) throws ErrorsException { - context.setDependency(dependency); - try { - return factory.get(errors, context, dependency); - } finally { - context.setDependency(null); - } - } - }); - errors.throwIfNewErrors(0); - return t; - } catch (ErrorsException e) { - throw new ProvisionException(errors.merge(e.getErrors()).getMessages()); - } - } - - @Override public String toString() { - return factory.toString(); - } - }; - } - - public Provider getProvider(final Key key) { - Errors errors = new Errors(key); - try { - Provider result = getProviderOrThrow(key, errors); - errors.throwIfNewErrors(0); - return result; - } catch (ErrorsException e) { - throw new ConfigurationException(errors.merge(e.getErrors()).getMessages()); - } - } - - public T getInstance(Key key) { - return getProvider(key).get(); - } - - public T getInstance(Class type) { - return getProvider(type).get(); - } - - final ThreadLocal localContext; - - /** Looks up thread local context. Creates (and removes) a new context if necessary. */ - T callInContext(ContextualCallable callable) throws ErrorsException { - Object[] reference = localContext.get(); - if (reference[0] == null) { - reference[0] = new InternalContext(); - try { - return callable.call((InternalContext)reference[0]); - } finally { - // Only clear the context if this call created it. - reference[0] = null; - } - } else { - // Someone else will clean up this context. - return callable.call((InternalContext)reference[0]); - } - } - - public String toString() { - return new ToStringBuilder(Injector.class) - .add("bindings", state.getExplicitBindingsThisLevel().values()) - .toString(); - } - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorShell.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorShell.java deleted file mode 100644 index 177a45cf603..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InjectorShell.java +++ /dev/null @@ -1,243 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.internal.*; -import org.elasticsearch.util.inject.spi.*; - -import java.util.List; -import java.util.logging.Logger; - -import static org.elasticsearch.util.inject.Scopes.*; -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * A partially-initialized injector. See {@link InjectorBuilder}, which uses this to build a tree - * of injectors in batch. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -class InjectorShell { - - private final List elements; - private final InjectorImpl injector; - private final PrivateElements privateElements; - - private InjectorShell(Builder builder, List elements, InjectorImpl injector) { - this.privateElements = builder.privateElements; - this.elements = elements; - this.injector = injector; - } - - PrivateElements getPrivateElements() { - return privateElements; - } - - InjectorImpl getInjector() { - return injector; - } - - List getElements() { - return elements; - } - - static class Builder { - private final List elements = Lists.newArrayList(); - private final List modules = Lists.newArrayList(); - - /** lazily constructed */ - private State state; - - private InjectorImpl parent; - private Stage stage; - - /** null unless this exists in a {@link Binder#newPrivateBinder private environment} */ - private PrivateElementsImpl privateElements; - - Builder parent(InjectorImpl parent) { - this.parent = parent; - this.state = new InheritingState(parent.state); - return this; - } - - Builder stage(Stage stage) { - this.stage = stage; - return this; - } - - Builder privateElements(PrivateElements privateElements) { - this.privateElements = (PrivateElementsImpl) privateElements; - this.elements.addAll(privateElements.getElements()); - return this; - } - - void addModules(Iterable modules) { - for (Module module : modules) { - this.modules.add(module); - } - } - - /** Synchronize on this before calling {@link #build}. */ - Object lock() { - return getState().lock(); - } - - /** - * Creates and returns the injector shells for the current modules. Multiple shells will be - * returned if any modules contain {@link Binder#newPrivateBinder private environments}. The - * primary injector will be first in the returned list. - */ - List build(Initializer initializer, BindingProcessor bindingProcessor, - Stopwatch stopwatch, Errors errors) { - checkState(stage != null, "Stage not initialized"); - checkState(privateElements == null || parent != null, "PrivateElements with no parent"); - checkState(state != null, "no state. Did you remember to lock() ?"); - - InjectorImpl injector = new InjectorImpl(parent, state, initializer); - if (privateElements != null) { - privateElements.initInjector(injector); - } - - // bind Stage and Singleton if this is a top-level injector - if (parent == null) { - modules.add(0, new RootModule(stage)); - new TypeConverterBindingProcessor(errors).prepareBuiltInConverters(injector); - } - - elements.addAll(Elements.getElements(stage, modules)); - stopwatch.resetAndLog("Module execution"); - - new MessageProcessor(errors).process(injector, elements); - - new TypeListenerBindingProcessor(errors).process(injector, elements); - List listenerBindings = injector.state.getTypeListenerBindings(); - injector.membersInjectorStore = new MembersInjectorStore(injector, listenerBindings); - stopwatch.resetAndLog("TypeListeners creation"); - - new ScopeBindingProcessor(errors).process(injector, elements); - stopwatch.resetAndLog("Scopes creation"); - - new TypeConverterBindingProcessor(errors).process(injector, elements); - stopwatch.resetAndLog("Converters creation"); - - bindInjector(injector); - bindLogger(injector); - bindingProcessor.process(injector, elements); - stopwatch.resetAndLog("Binding creation"); - - List injectorShells = Lists.newArrayList(); - injectorShells.add(new InjectorShell(this, elements, injector)); - - // recursively build child shells - PrivateElementProcessor processor = new PrivateElementProcessor(errors, stage); - processor.process(injector, elements); - for (Builder builder : processor.getInjectorShellBuilders()) { - injectorShells.addAll(builder.build(initializer, bindingProcessor, stopwatch, errors)); - } - stopwatch.resetAndLog("Private environment creation"); - - return injectorShells; - } - - private State getState() { - if (state == null) { - state = new InheritingState(State.NONE); - } - return state; - } - } - - /** - * The Injector is a special case because we allow both parent and child injectors to both have - * a binding for that key. - */ - private static void bindInjector(InjectorImpl injector) { - Key key = Key.get(Injector.class); - InjectorFactory injectorFactory = new InjectorFactory(injector); - injector.state.putBinding(key, - new ProviderInstanceBindingImpl(injector, key, SourceProvider.UNKNOWN_SOURCE, - injectorFactory, Scoping.UNSCOPED, injectorFactory, - ImmutableSet.of())); - } - - private static class InjectorFactory implements InternalFactory, Provider { - private final Injector injector; - - private InjectorFactory(Injector injector) { - this.injector = injector; - } - - public Injector get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException { - return injector; - } - - public Injector get() { - return injector; - } - - public String toString() { - return "Provider"; - } - } - - /** - * The Logger is a special case because it knows the injection point of the injected member. It's - * the only binding that does this. - */ - private static void bindLogger(InjectorImpl injector) { - Key key = Key.get(Logger.class); - LoggerFactory loggerFactory = new LoggerFactory(); - injector.state.putBinding(key, - new ProviderInstanceBindingImpl(injector, key, - SourceProvider.UNKNOWN_SOURCE, loggerFactory, Scoping.UNSCOPED, - loggerFactory, ImmutableSet.of())); - } - - private static class LoggerFactory implements InternalFactory, Provider { - public Logger get(Errors errors, InternalContext context, Dependency dependency) { - InjectionPoint injectionPoint = dependency.getInjectionPoint(); - return injectionPoint == null - ? Logger.getAnonymousLogger() - : Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName()); - } - - public Logger get() { - return Logger.getAnonymousLogger(); - } - - public String toString() { - return "Provider"; - } - } - - private static class RootModule implements Module { - final Stage stage; - - private RootModule(Stage stage) { - this.stage = checkNotNull(stage, "stage"); - } - - public void configure(Binder binder) { - binder = binder.withSource(SourceProvider.UNKNOWN_SOURCE); - binder.bind(Stage.class).toInstance(stage); - binder.bindScope(Singleton.class, SINGLETON); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InternalFactoryToProviderAdapter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InternalFactoryToProviderAdapter.java deleted file mode 100644 index 5c6fef6b685..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/InternalFactoryToProviderAdapter.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.internal.InternalFactory; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import org.elasticsearch.util.inject.internal.SourceProvider; -import org.elasticsearch.util.inject.spi.Dependency; - -/** - * @author crazybob@google.com (Bob Lee) -*/ -class InternalFactoryToProviderAdapter implements InternalFactory { - - private final Initializable> initializable; - private final Object source; - - public InternalFactoryToProviderAdapter(Initializable> initializable) { - this(initializable, SourceProvider.UNKNOWN_SOURCE); - } - - public InternalFactoryToProviderAdapter( - Initializable> initializable, Object source) { - this.initializable = checkNotNull(initializable, "provider"); - this.source = checkNotNull(source, "source"); - } - - public T get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException { - try { - return errors.checkForNull(initializable.get(errors).get(), source, dependency); - } catch (RuntimeException userException) { - throw errors.withSource(source).errorInProvider(userException).toException(); - } - } - - @Override public String toString() { - return initializable.toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Key.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Key.java deleted file mode 100644 index d9e8f9a5abb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Key.java +++ /dev/null @@ -1,494 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Annotations; -import org.elasticsearch.util.inject.internal.MoreTypes; -import static org.elasticsearch.util.inject.internal.Preconditions.checkArgument; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import org.elasticsearch.util.inject.internal.ToStringBuilder; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -/** - * Binding key consisting of an injection type and an optional annotation. - * Matches the type and annotation at a point of injection. - * - *

For example, {@code Key.get(Service.class, Transactional.class)} will - * match: - * - *

- *   {@literal @}Inject
- *   public void setService({@literal @}Transactional Service service) {
- *     ...
- *   }
- * 
- * - *

{@code Key} supports generic types via subclassing just like {@link - * TypeLiteral}. - * - *

Keys do not differentiate between primitive types (int, char, etc.) and - * their correpsonding wrapper types (Integer, Character, etc.). Primitive - * types will be replaced with their wrapper types when keys are created. - * - * @author crazybob@google.com (Bob Lee) - */ -public class Key { - - private final AnnotationStrategy annotationStrategy; - - private final TypeLiteral typeLiteral; - private final int hashCode; - - /** - * Constructs a new key. Derives the type from this class's type parameter. - * - *

Clients create an empty anonymous subclass. Doing so embeds the type - * parameter in the anonymous class's type hierarchy so we can reconstitute it - * at runtime despite erasure. - * - *

Example usage for a binding of type {@code Foo} annotated with - * {@code @Bar}: - * - *

{@code new Key(Bar.class) {}}. - */ - @SuppressWarnings("unchecked") - protected Key(Class annotationType) { - this.annotationStrategy = strategyFor(annotationType); - this.typeLiteral = (TypeLiteral) TypeLiteral.fromSuperclassTypeParameter(getClass()); - this.hashCode = computeHashCode(); - } - - /** - * Constructs a new key. Derives the type from this class's type parameter. - * - *

Clients create an empty anonymous subclass. Doing so embeds the type - * parameter in the anonymous class's type hierarchy so we can reconstitute it - * at runtime despite erasure. - * - *

Example usage for a binding of type {@code Foo} annotated with - * {@code @Bar}: - * - *

{@code new Key(new Bar()) {}}. - */ - @SuppressWarnings("unchecked") - protected Key(Annotation annotation) { - // no usages, not test-covered - this.annotationStrategy = strategyFor(annotation); - this.typeLiteral = (TypeLiteral) TypeLiteral.fromSuperclassTypeParameter(getClass()); - this.hashCode = computeHashCode(); - } - - /** - * Constructs a new key. Derives the type from this class's type parameter. - * - *

Clients create an empty anonymous subclass. Doing so embeds the type - * parameter in the anonymous class's type hierarchy so we can reconstitute it - * at runtime despite erasure. - * - *

Example usage for a binding of type {@code Foo}: - * - *

{@code new Key() {}}. - */ - @SuppressWarnings("unchecked") - protected Key() { - this.annotationStrategy = NullAnnotationStrategy.INSTANCE; - this.typeLiteral = (TypeLiteral) TypeLiteral.fromSuperclassTypeParameter(getClass()); - this.hashCode = computeHashCode(); - } - - /** - * Unsafe. Constructs a key from a manually specified type. - */ - @SuppressWarnings("unchecked") - private Key(Type type, AnnotationStrategy annotationStrategy) { - this.annotationStrategy = annotationStrategy; - this.typeLiteral = MoreTypes.makeKeySafe((TypeLiteral) TypeLiteral.get(type)); - this.hashCode = computeHashCode(); - } - - /** Constructs a key from a manually specified type. */ - private Key(TypeLiteral typeLiteral, AnnotationStrategy annotationStrategy) { - this.annotationStrategy = annotationStrategy; - this.typeLiteral = MoreTypes.makeKeySafe(typeLiteral); - this.hashCode = computeHashCode(); - } - - private int computeHashCode() { - return typeLiteral.hashCode() * 31 + annotationStrategy.hashCode(); - } - - /** - * Gets the key type. - */ - public final TypeLiteral getTypeLiteral() { - return typeLiteral; - } - - /** - * Gets the annotation type. - */ - public final Class getAnnotationType() { - return annotationStrategy.getAnnotationType(); - } - - /** - * Gets the annotation. - */ - public final Annotation getAnnotation() { - return annotationStrategy.getAnnotation(); - } - - boolean hasAnnotationType() { - return annotationStrategy.getAnnotationType() != null; - } - - String getAnnotationName() { - Annotation annotation = annotationStrategy.getAnnotation(); - if (annotation != null) { - return annotation.toString(); - } - - // not test-covered - return annotationStrategy.getAnnotationType().toString(); - } - - Class getRawType() { - return typeLiteral.getRawType(); - } - - /** - * Gets the key of this key's provider. - */ - Key> providerKey() { - return ofType(typeLiteral.providerType()); - } - - @Override public final boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof Key)) { - return false; - } - Key other = (Key) o; - return annotationStrategy.equals(other.annotationStrategy) - && typeLiteral.equals(other.typeLiteral); - } - - @Override public final int hashCode() { - return this.hashCode; - } - - @Override public final String toString() { - return new ToStringBuilder(Key.class) - .add("type", typeLiteral) - .add("annotation", annotationStrategy) - .toString(); - } - - /** - * Gets a key for an injection type and an annotation strategy. - */ - static Key get(Class type, - AnnotationStrategy annotationStrategy) { - return new Key(type, annotationStrategy); - } - - /** - * Gets a key for an injection type. - */ - public static Key get(Class type) { - return new Key(type, NullAnnotationStrategy.INSTANCE); - } - - /** - * Gets a key for an injection type and an annotation type. - */ - public static Key get(Class type, - Class annotationType) { - return new Key(type, strategyFor(annotationType)); - } - - /** - * Gets a key for an injection type and an annotation. - */ - public static Key get(Class type, Annotation annotation) { - return new Key(type, strategyFor(annotation)); - } - - /** - * Gets a key for an injection type. - */ - public static Key get(Type type) { - return new Key(type, NullAnnotationStrategy.INSTANCE); - } - - /** - * Gets a key for an injection type and an annotation type. - */ - public static Key get(Type type, - Class annotationType) { - return new Key(type, strategyFor(annotationType)); - } - - /** - * Gets a key for an injection type and an annotation. - */ - public static Key get(Type type, Annotation annotation) { - return new Key(type, strategyFor(annotation)); - } - - /** - * Gets a key for an injection type. - */ - public static Key get(TypeLiteral typeLiteral) { - return new Key(typeLiteral, NullAnnotationStrategy.INSTANCE); - } - - /** - * Gets a key for an injection type and an annotation type. - */ - public static Key get(TypeLiteral typeLiteral, - Class annotationType) { - return new Key(typeLiteral, strategyFor(annotationType)); - } - - /** - * Gets a key for an injection type and an annotation. - */ - public static Key get(TypeLiteral typeLiteral, - Annotation annotation) { - return new Key(typeLiteral, strategyFor(annotation)); - } - - /** - * Returns a new key of the specified type with the same annotation as this - * key. - */ - Key ofType(Class type) { - return new Key(type, annotationStrategy); - } - - /** - * Returns a new key of the specified type with the same annotation as this - * key. - */ - Key ofType(Type type) { - return new Key(type, annotationStrategy); - } - - /** - * Returns a new key of the specified type with the same annotation as this - * key. - */ - Key ofType(TypeLiteral type) { - return new Key(type, annotationStrategy); - } - - /** - * Returns true if this key has annotation attributes. - */ - boolean hasAttributes() { - return annotationStrategy.hasAttributes(); - } - - /** - * Returns this key without annotation attributes, i.e. with only the - * annotation type. - */ - Key withoutAttributes() { - return new Key(typeLiteral, annotationStrategy.withoutAttributes()); - } - - interface AnnotationStrategy { - Annotation getAnnotation(); - Class getAnnotationType(); - boolean hasAttributes(); - AnnotationStrategy withoutAttributes(); - } - - /** - * Returns {@code true} if the given annotation type has no attributes. - */ - static boolean isMarker(Class annotationType) { - return annotationType.getDeclaredMethods().length == 0; - } - - /** - * Gets the strategy for an annotation. - */ - static AnnotationStrategy strategyFor(Annotation annotation) { - checkNotNull(annotation, "annotation"); - Class annotationType = annotation.annotationType(); - ensureRetainedAtRuntime(annotationType); - ensureIsBindingAnnotation(annotationType); - - if (annotationType.getDeclaredMethods().length == 0) { - return new AnnotationTypeStrategy(annotationType, annotation); - } - - return new AnnotationInstanceStrategy(annotation); - } - - /** - * Gets the strategy for an annotation type. - */ - static AnnotationStrategy strategyFor(Class annotationType) { - checkNotNull(annotationType, "annotation type"); - ensureRetainedAtRuntime(annotationType); - ensureIsBindingAnnotation(annotationType); - return new AnnotationTypeStrategy(annotationType, null); - } - - private static void ensureRetainedAtRuntime( - Class annotationType) { - checkArgument(Annotations.isRetainedAtRuntime(annotationType), - "%s is not retained at runtime. Please annotate it with @Retention(RUNTIME).", - annotationType.getName()); - } - - private static void ensureIsBindingAnnotation( - Class annotationType) { - checkArgument(isBindingAnnotation(annotationType), - "%s is not a binding annotation. Please annotate it with @BindingAnnotation.", - annotationType.getName()); - } - - static enum NullAnnotationStrategy implements AnnotationStrategy { - INSTANCE; - - public boolean hasAttributes() { - return false; - } - - public AnnotationStrategy withoutAttributes() { - throw new UnsupportedOperationException("Key already has no attributes."); - } - - public Annotation getAnnotation() { - return null; - } - - public Class getAnnotationType() { - return null; - } - - @Override public String toString() { - return "[none]"; - } - } - - // this class not test-covered - static class AnnotationInstanceStrategy implements AnnotationStrategy { - - final Annotation annotation; - - AnnotationInstanceStrategy(Annotation annotation) { - this.annotation = checkNotNull(annotation, "annotation"); - } - - public boolean hasAttributes() { - return true; - } - - public AnnotationStrategy withoutAttributes() { - return new AnnotationTypeStrategy(getAnnotationType(), annotation); - } - - public Annotation getAnnotation() { - return annotation; - } - - public Class getAnnotationType() { - return annotation.annotationType(); - } - - @Override public boolean equals(Object o) { - if (!(o instanceof AnnotationInstanceStrategy)) { - return false; - } - - AnnotationInstanceStrategy other = (AnnotationInstanceStrategy) o; - return annotation.equals(other.annotation); - } - - @Override public int hashCode() { - return annotation.hashCode(); - } - - @Override public String toString() { - return annotation.toString(); - } - } - - static class AnnotationTypeStrategy implements AnnotationStrategy { - - final Class annotationType; - - // Keep the instance around if we have it so the client can request it. - final Annotation annotation; - - AnnotationTypeStrategy(Class annotationType, - Annotation annotation) { - this.annotationType = checkNotNull(annotationType, "annotation type"); - this.annotation = annotation; - } - - public boolean hasAttributes() { - return false; - } - - public AnnotationStrategy withoutAttributes() { - throw new UnsupportedOperationException("Key already has no attributes."); - } - - public Annotation getAnnotation() { - return annotation; - } - - public Class getAnnotationType() { - return annotationType; - } - - @Override public boolean equals(Object o) { - if (!(o instanceof AnnotationTypeStrategy)) { - return false; - } - - AnnotationTypeStrategy other = (AnnotationTypeStrategy) o; - return annotationType.equals(other.annotationType); - } - - @Override public int hashCode() { - return annotationType.hashCode(); - } - - @Override public String toString() { - return "@" + annotationType.getName(); - } - } - - static boolean isBindingAnnotation(Annotation annotation) { - return isBindingAnnotation(annotation.annotationType()); - } - - static boolean isBindingAnnotation( - Class annotationType) { - return annotationType.isAnnotationPresent(BindingAnnotation.class); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/LookupProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/LookupProcessor.java deleted file mode 100644 index cf3ba337353..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/LookupProcessor.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.spi.MembersInjectorLookup; -import org.elasticsearch.util.inject.spi.ProviderLookup; - -/** - * Handles {@link Binder#getProvider} and {@link Binder#getMembersInjector(TypeLiteral)} commands. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -class LookupProcessor extends AbstractProcessor { - - LookupProcessor(Errors errors) { - super(errors); - } - - @Override public Boolean visit(MembersInjectorLookup lookup) { - try { - MembersInjector membersInjector - = injector.membersInjectorStore.get(lookup.getType(), errors); - lookup.initializeDelegate(membersInjector); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); // TODO: source - } - - return true; - } - - @Override public Boolean visit(ProviderLookup lookup) { - // ensure the provider can be created - try { - Provider provider = injector.getProviderOrThrow(lookup.getKey(), errors); - lookup.initializeDelegate(provider); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); // TODO: source - } - - return true; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Lookups.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Lookups.java deleted file mode 100644 index b60bcbd7a25..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Lookups.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -/** - * Accessors for providers and members injectors. The returned values will not be functional until - * the injector has been created. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -interface Lookups { - - Provider getProvider(Key key); - - MembersInjector getMembersInjector(TypeLiteral type); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjector.java deleted file mode 100644 index ea55b9029dd..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjector.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -/** - * Injects dependencies into the fields and methods on instances of type {@code T}. Ignores the - * presence or absence of an injectable constructor. - * - * @param type to inject members of - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface MembersInjector { - - /** - * Injects dependencies into the fields and methods of {@code instance}. Ignores the presence or - * absence of an injectable constructor. - * - *

Whenever Guice creates an instance, it performs this injection automatically (after first - * performing constructor injection), so if you're able to let Guice create all your objects for - * you, you'll never need to use this method. - * - * @param instance to inject members on. May be {@code null}. - */ - void injectMembers(T instance); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjectorImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjectorImpl.java deleted file mode 100644 index 5eb43a689dc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjectorImpl.java +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.spi.InjectionListener; -import org.elasticsearch.util.inject.spi.InjectionPoint; - -/** - * Injects members of instances of a given type. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -class MembersInjectorImpl implements MembersInjector { - private final TypeLiteral typeLiteral; - private final InjectorImpl injector; - private final ImmutableList memberInjectors; - private final ImmutableList> userMembersInjectors; - private final ImmutableList> injectionListeners; - - MembersInjectorImpl(InjectorImpl injector, TypeLiteral typeLiteral, - EncounterImpl encounter, ImmutableList memberInjectors) { - this.injector = injector; - this.typeLiteral = typeLiteral; - this.memberInjectors = memberInjectors; - this.userMembersInjectors = encounter.getMembersInjectors(); - this.injectionListeners = encounter.getInjectionListeners(); - } - - public ImmutableList getMemberInjectors() { - return memberInjectors; - } - - public void injectMembers(T instance) { - Errors errors = new Errors(typeLiteral); - try { - injectAndNotify(instance, errors); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - - errors.throwProvisionExceptionIfErrorsExist(); - } - - void injectAndNotify(final T instance, final Errors errors) throws ErrorsException { - if (instance == null) { - return; - } - - injector.callInContext(new ContextualCallable() { - public Void call(InternalContext context) throws ErrorsException { - injectMembers(instance, errors, context); - return null; - } - }); - - notifyListeners(instance, errors); - } - - void notifyListeners(T instance, Errors errors) throws ErrorsException { - int numErrorsBefore = errors.size(); - for (InjectionListener injectionListener : injectionListeners) { - try { - injectionListener.afterInjection(instance); - } catch (RuntimeException e) { - errors.errorNotifyingInjectionListener(injectionListener, typeLiteral, e); - } - } - errors.throwIfNewErrors(numErrorsBefore); - } - - void injectMembers(T t, Errors errors, InternalContext context) { - // optimization: use manual for/each to save allocating an iterator here - for (int i = 0, size = memberInjectors.size(); i < size; i++) { - memberInjectors.get(i).inject(errors, context, t); - } - - // optimization: use manual for/each to save allocating an iterator here - for (int i = 0, size = userMembersInjectors.size(); i < size; i++) { - MembersInjector userMembersInjector = userMembersInjectors.get(i); - try { - userMembersInjector.injectMembers(t); - } catch (RuntimeException e) { - errors.errorInUserInjector(userMembersInjector, typeLiteral, e); - } - } - } - - @Override public String toString() { - return "MembersInjector<" + typeLiteral + ">"; - } - - public ImmutableSet getInjectionPoints() { - ImmutableSet.Builder builder = ImmutableSet.builder(); - for (SingleMemberInjector memberInjector : memberInjectors) { - builder.add(memberInjector.getInjectionPoint()); - } - return builder.build(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjectorStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjectorStore.java deleted file mode 100644 index a2bebfa8bb9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MembersInjectorStore.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.FailableCache; -import org.elasticsearch.util.inject.spi.InjectionPoint; -import org.elasticsearch.util.inject.spi.TypeListenerBinding; - -import java.lang.reflect.Field; -import java.util.List; -import java.util.Set; - -/** - * Members injectors by type. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -class MembersInjectorStore { - private final InjectorImpl injector; - private final ImmutableList typeListenerBindings; - - private final FailableCache, MembersInjectorImpl> cache - = new FailableCache, MembersInjectorImpl>() { - @Override protected MembersInjectorImpl create(TypeLiteral type, Errors errors) - throws ErrorsException { - return createWithListeners(type, errors); - } - }; - - MembersInjectorStore(InjectorImpl injector, - List typeListenerBindings) { - this.injector = injector; - this.typeListenerBindings = ImmutableList.copyOf(typeListenerBindings); - } - - /** - * Returns true if any type listeners are installed. Other code may take shortcuts when there - * aren't any type listeners. - */ - public boolean hasTypeListeners() { - return !typeListenerBindings.isEmpty(); - } - - /** - * Returns a new complete members injector with injection listeners registered. - */ - @SuppressWarnings("unchecked") // the MembersInjector type always agrees with the passed type - public MembersInjectorImpl get(TypeLiteral key, Errors errors) throws ErrorsException { - return (MembersInjectorImpl) cache.get(key, errors); - } - - /** - * Creates a new members injector and attaches both injection listeners and method aspects. - */ - private MembersInjectorImpl createWithListeners(TypeLiteral type, Errors errors) - throws ErrorsException { - int numErrorsBefore = errors.size(); - - Set injectionPoints; - try { - injectionPoints = InjectionPoint.forInstanceMethodsAndFields(type); - } catch (ConfigurationException e) { - errors.merge(e.getErrorMessages()); - injectionPoints = e.getPartialValue(); - } - ImmutableList injectors = getInjectors(injectionPoints, errors); - errors.throwIfNewErrors(numErrorsBefore); - - EncounterImpl encounter = new EncounterImpl(errors, injector.lookups); - for (TypeListenerBinding typeListener : typeListenerBindings) { - if (typeListener.getTypeMatcher().matches(type)) { - try { - typeListener.getListener().hear(type, encounter); - } catch (RuntimeException e) { - errors.errorNotifyingTypeListener(typeListener, type, e); - } - } - } - encounter.invalidate(); - errors.throwIfNewErrors(numErrorsBefore); - - return new MembersInjectorImpl(injector, type, encounter, injectors); - } - - /** - * Returns the injectors for the specified injection points. - */ - ImmutableList getInjectors( - Set injectionPoints, Errors errors) { - List injectors = Lists.newArrayList(); - for (InjectionPoint injectionPoint : injectionPoints) { - try { - Errors errorsForMember = injectionPoint.isOptional() - ? new Errors(injectionPoint) - : errors.withSource(injectionPoint); - SingleMemberInjector injector = injectionPoint.getMember() instanceof Field - ? new SingleFieldInjector(this.injector, injectionPoint, errorsForMember) - : new SingleMethodInjector(this.injector, injectionPoint, errorsForMember); - injectors.add(injector); - } catch (ErrorsException ignoredForNow) { - // ignored for now - } - } - return ImmutableList.copyOf(injectors); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MessageProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MessageProcessor.java deleted file mode 100644 index 6dce552ea89..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/MessageProcessor.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.Message; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Handles {@link Binder#addError} commands. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -class MessageProcessor extends AbstractProcessor { - - private static final Logger logger = Logger.getLogger(Guice.class.getName()); - - MessageProcessor(Errors errors) { - super(errors); - } - - @Override public Boolean visit(Message message) { - if (message.getCause() != null) { - String rootMessage = getRootMessage(message.getCause()); - logger.log(Level.INFO, - "An exception was caught and reported. Message: " + rootMessage, - message.getCause()); - } - - errors.addMessage(message); - return true; - } - - public static String getRootMessage(Throwable t) { - Throwable cause = t.getCause(); - return cause == null ? t.toString() : getRootMessage(cause); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Module.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Module.java deleted file mode 100644 index a1a092ace6a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Module.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -/** - * A module contributes configuration information, typically interface - * bindings, which will be used to create an {@link Injector}. A Guice-based - * application is ultimately composed of little more than a set of - * {@code Module}s and some bootstrapping code. - * - *

Your Module classes can use a more streamlined syntax by extending - * {@link AbstractModule} rather than implementing this interface directly. - * - *

In addition to the bindings configured via {@link #configure}, bindings - * will be created for all methods annotated with {@literal @}{@link Provides}. - * Use scope and binding annotations on these methods to configure the - * bindings. - */ -public interface Module { - - /** - * Contributes bindings and other configurations for this module to {@code binder}. - * - *

Do not invoke this method directly to install submodules. Instead use - * {@link Binder#install(Module)}, which ensures that {@link Provides provider methods} are - * discovered. - */ - void configure(Binder binder); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/OutOfScopeException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/OutOfScopeException.java deleted file mode 100644 index 9d85e130053..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/OutOfScopeException.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -/** - * Thrown from {@link Provider#get} when an attempt is made to access a scoped - * object while the scope in question is not currently active. - * - * @author kevinb@google.com (Kevin Bourrillion) - * @since 2.0 - */ -public final class OutOfScopeException extends RuntimeException { - - public OutOfScopeException(String message) { - super(message); - } - - public OutOfScopeException(String message, Throwable cause) { - super(message, cause); - } - - public OutOfScopeException(Throwable cause) { - super(cause); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateBinder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateBinder.java deleted file mode 100644 index c6f46da0758..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateBinder.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.binder.AnnotatedElementBuilder; - -/** - * Returns a binder whose configuration information is hidden from its environment by default. See - * {@link org.elasticsearch.util.inject.PrivateModule PrivateModule} for details. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface PrivateBinder extends Binder { - - /** Makes the binding for {@code key} available to the enclosing environment */ - void expose(Key key); - - /** - * Makes a binding for {@code type} available to the enclosing environment. Use {@link - * org.elasticsearch.util.inject.binder.AnnotatedElementBuilder#annotatedWith(Class) annotatedWith()} to expose {@code type} with a - * binding annotation. - */ - AnnotatedElementBuilder expose(Class type); - - /** - * Makes a binding for {@code type} available to the enclosing environment. Use {@link - * AnnotatedElementBuilder#annotatedWith(Class) annotatedWith()} to expose {@code type} with a - * binding annotation. - */ - AnnotatedElementBuilder expose(TypeLiteral type); - - PrivateBinder withSource(Object source); - - PrivateBinder skipSources(Class... classesToSkip); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateElementProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateElementProcessor.java deleted file mode 100644 index 911f8410248..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateElementProcessor.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.PrivateElements; - -import java.util.List; - -/** - * Handles {@link Binder#newPrivateBinder()} elements. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -class PrivateElementProcessor extends AbstractProcessor { - - private final Stage stage; - private final List injectorShellBuilders = Lists.newArrayList(); - - PrivateElementProcessor(Errors errors, Stage stage) { - super(errors); - this.stage = stage; - } - - @Override public Boolean visit(PrivateElements privateElements) { - InjectorShell.Builder builder = new InjectorShell.Builder() - .parent(injector) - .stage(stage) - .privateElements(privateElements); - injectorShellBuilders.add(builder); - return true; - } - - public List getInjectorShellBuilders() { - return injectorShellBuilders; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateModule.java deleted file mode 100644 index 3a0f3f57bc7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/PrivateModule.java +++ /dev/null @@ -1,281 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.binder.AnnotatedBindingBuilder; -import org.elasticsearch.util.inject.binder.AnnotatedConstantBindingBuilder; -import org.elasticsearch.util.inject.binder.AnnotatedElementBuilder; -import org.elasticsearch.util.inject.binder.LinkedBindingBuilder; -import static org.elasticsearch.util.inject.internal.Preconditions.checkState; -import org.elasticsearch.util.inject.matcher.Matcher; -import org.elasticsearch.util.inject.spi.Message; -import org.elasticsearch.util.inject.spi.TypeConverter; -import org.elasticsearch.util.inject.spi.TypeListener; -import java.lang.annotation.Annotation; - -/** - * A module whose configuration information is hidden from its environment by default. Only bindings - * that are explicitly exposed will be available to other modules and to the users of the injector. - * This module may expose the bindings it creates and the bindings of the modules it installs. - * - *

A private module can be nested within a regular module or within another private module using - * {@link Binder#install install()}. Its bindings live in a new environment that inherits bindings, - * type converters, scopes, and interceptors from the surrounding ("parent") environment. When you - * nest multiple private modules, the result is a tree of environments where the injector's - * environment is the root. - * - *

Guice EDSL bindings can be exposed with {@link #expose(Class) expose()}. {@literal @}{@link - * org.elasticsearch.util.inject.Provides Provides} bindings can be exposed with the {@literal @}{@link - * Exposed} annotation: - * - *

- * public class FooBarBazModule extends PrivateModule {
- *   protected void configure() {
- *     bind(Foo.class).to(RealFoo.class);
- *     expose(Foo.class);
- *
- *     install(new TransactionalBarModule());
- *     expose(Bar.class).annotatedWith(Transactional.class);
- *
- *     bind(SomeImplementationDetail.class);
- *     install(new MoreImplementationDetailsModule());
- *   }
- *
- *   {@literal @}Provides {@literal @}Exposed
- *   public Baz provideBaz() {
- *     return new SuperBaz();
- *   }
- * }
- * 
- * - *

Private modules are implemented using {@link Injector#createChildInjector(Module[]) parent - * injectors}. When it can satisfy their dependencies, just-in-time bindings will be created in the - * root environment. Such bindings are shared among all environments in the tree. - * - *

The scope of a binding is constrained to its environment. A singleton bound in a private - * module will be unique to its environment. But a binding for the same type in a different private - * module will yield a different instance. - * - *

A shared binding that injects the {@code Injector} gets the root injector, which only has - * access to bindings in the root environment. An explicit binding that injects the {@code Injector} - * gets access to all bindings in the child environment. - * - *

To promote a just-in-time binding to an explicit binding, bind it: - *

- *   bind(FooImpl.class);
- * 
- * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public abstract class PrivateModule implements Module { - - /** Like abstract module, the binder of the current private module */ - private PrivateBinder binder; - - public final synchronized void configure(Binder binder) { - checkState(this.binder == null, "Re-entry is not allowed."); - - // Guice treats PrivateModules specially and passes in a PrivateBinder automatically. - this.binder = (PrivateBinder) binder.skipSources(PrivateModule.class); - try { - configure(); - } finally { - this.binder = null; - } - } - - /** - * Creates bindings and other configurations private to this module. Use {@link #expose(Class) - * expose()} to make the bindings in this module available externally. - */ - protected abstract void configure(); - - /** Makes the binding for {@code key} available to other modules and the injector. */ - protected final void expose(Key key) { - binder.expose(key); - } - - /** - * Makes a binding for {@code type} available to other modules and the injector. Use {@link - * AnnotatedElementBuilder#annotatedWith(Class) annotatedWith()} to expose {@code type} with a - * binding annotation. - */ - protected final AnnotatedElementBuilder expose(Class type) { - return binder.expose(type); - } - - /** - * Makes a binding for {@code type} available to other modules and the injector. Use {@link - * AnnotatedElementBuilder#annotatedWith(Class) annotatedWith()} to expose {@code type} with a - * binding annotation. - */ - protected final AnnotatedElementBuilder expose(TypeLiteral type) { - return binder.expose(type); - } - - // everything below is copied from AbstractModule - - /** - * Returns the current binder. - */ - protected final PrivateBinder binder() { - return binder; - } - - /** - * @see Binder#bindScope(Class, Scope) - */ - protected final void bindScope(Class scopeAnnotation, Scope scope) { - binder.bindScope(scopeAnnotation, scope); - } - - /** - * @see Binder#bind(Key) - */ - protected final LinkedBindingBuilder bind(Key key) { - return binder.bind(key); - } - - /** - * @see Binder#bind(TypeLiteral) - */ - protected final AnnotatedBindingBuilder bind(TypeLiteral typeLiteral) { - return binder.bind(typeLiteral); - } - - /** - * @see Binder#bind(Class) - */ - protected final AnnotatedBindingBuilder bind(Class clazz) { - return binder.bind(clazz); - } - - /** - * @see Binder#bindConstant() - */ - protected final AnnotatedConstantBindingBuilder bindConstant() { - return binder.bindConstant(); - } - - /** - * @see Binder#install(Module) - */ - protected final void install(Module module) { - binder.install(module); - } - - /** - * @see Binder#addError(String, Object[]) - */ - protected final void addError(String message, Object... arguments) { - binder.addError(message, arguments); - } - - /** - * @see Binder#addError(Throwable) - */ - protected final void addError(Throwable t) { - binder.addError(t); - } - - /** - * @see Binder#addError(Message) - */ - protected final void addError(Message message) { - binder.addError(message); - } - - /** - * @see Binder#requestInjection(Object) - */ - protected final void requestInjection(Object instance) { - binder.requestInjection(instance); - } - - /** - * @see Binder#requestStaticInjection(Class[]) - */ - protected final void requestStaticInjection(Class... types) { - binder.requestStaticInjection(types); - } - - /** - * Instructs Guice to require a binding to the given key. - */ - protected final void requireBinding(Key key) { - binder.getProvider(key); - } - - /** - * Instructs Guice to require a binding to the given type. - */ - protected final void requireBinding(Class type) { - binder.getProvider(type); - } - - /** - * @see Binder#getProvider(Key) - */ - protected final Provider getProvider(Key key) { - return binder.getProvider(key); - } - - /** - * @see Binder#getProvider(Class) - */ - protected final Provider getProvider(Class type) { - return binder.getProvider(type); - } - - /** - * @see Binder#convertToTypes(org.elasticsearch.util.inject.matcher.Matcher, org.elasticsearch.util.inject.spi.TypeConverter) - */ - protected final void convertToTypes(Matcher> typeMatcher, - TypeConverter converter) { - binder.convertToTypes(typeMatcher, converter); - } - - /** - * @see Binder#currentStage() - */ - protected final Stage currentStage() { - return binder.currentStage(); - } - - /** - * @see Binder#getMembersInjector(Class) - */ - protected MembersInjector getMembersInjector(Class type) { - return binder.getMembersInjector(type); - } - - /** - * @see Binder#getMembersInjector(TypeLiteral) - */ - protected MembersInjector getMembersInjector(TypeLiteral type) { - return binder.getMembersInjector(type); - } - - /** - * @see Binder#bindListener(org.elasticsearch.util.inject.matcher.Matcher, org.elasticsearch.util.inject.spi.TypeListener) - */ - protected void bindListener(Matcher> typeMatcher, - TypeListener listener) { - binder.bindListener(typeMatcher, listener); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProvidedBy.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProvidedBy.java deleted file mode 100644 index 06c7151d933..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProvidedBy.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import static java.lang.annotation.ElementType.TYPE; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * A pointer to the default provider type for a type. - * - * @author crazybob@google.com (Bob Lee) - */ -@Retention(RUNTIME) -@Target(TYPE) -public @interface ProvidedBy { - - /** - * The implementation type. - */ - Class> value(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Provider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Provider.java deleted file mode 100644 index 82bc456783f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Provider.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -/** - * An object capable of providing instances of type {@code T}. Providers are used in numerous ways - * by Guice: - * - *
    - *
  • When the default means for obtaining instances (an injectable or parameterless constructor) - * is insufficient for a particular binding, the module can specify a custom {@code Provider} - * instead, to control exactly how Guice creates or obtains instances for the binding. - * - *
  • An implementation class may always choose to have a {@code Provider} instance injected, - * rather than having a {@code T} injected directly. This may give you access to multiple - * instances, instances you wish to safely mutate and discard, instances which are out of scope - * (e.g. using a {@code @RequestScoped} object from within a {@code @SessionScoped} object), or - * instances that will be initialized lazily. - * - *
  • A custom {@link Scope} is implemented as a decorator of {@code Provider}, which decides - * when to delegate to the backing provider and when to provide the instance some other way. - * - *
  • The {@link Injector} offers access to the {@code Provider} it uses to fulfill requests - * for a given key, via the {@link Injector#getProvider} methods. - *
- * - * @param the type of object this provides - * - * @author crazybob@google.com (Bob Lee) - */ -public interface Provider { - - /** - * Provides an instance of {@code T}. Must never return {@code null}. - * - * @throws OutOfScopeException when an attempt is made to access a scoped object while the scope - * in question is not currently active - * @throws ProvisionException if an instance cannot be provided. Such exceptions include messages - * and throwables to describe why provision failed. - */ - T get(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProviderToInternalFactoryAdapter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProviderToInternalFactoryAdapter.java deleted file mode 100644 index 3df9d5755ff..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProviderToInternalFactoryAdapter.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.internal.InternalFactory; -import org.elasticsearch.util.inject.spi.Dependency; - -/** - * @author crazybob@google.com (Bob Lee) - */ -class ProviderToInternalFactoryAdapter implements Provider { - - private final InjectorImpl injector; - private final InternalFactory internalFactory; - - public ProviderToInternalFactoryAdapter(InjectorImpl injector, - InternalFactory internalFactory) { - this.injector = injector; - this.internalFactory = internalFactory; - } - - public T get() { - final Errors errors = new Errors(); - try { - T t = injector.callInContext(new ContextualCallable() { - public T call(InternalContext context) throws ErrorsException { - Dependency dependency = context.getDependency(); - return internalFactory.get(errors, context, dependency); - } - }); - errors.throwIfNewErrors(0); - return t; - } catch (ErrorsException e) { - throw new ProvisionException(errors.merge(e.getErrors()).getMessages()); - } - } - - @Override public String toString() { - return internalFactory.toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Provides.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Provides.java deleted file mode 100644 index 34adecb9f64..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Provides.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import java.lang.annotation.Documented; -import static java.lang.annotation.ElementType.METHOD; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * Annotates methods of a {@link Module} to create a provider method binding. The method's return - * type is bound to it's returned value. Guice will pass dependencies to the method as parameters. - * - * @author crazybob@google.com (Bob Lee) - * @since 2.0 - */ -@Documented @Target(METHOD) @Retention(RUNTIME) -public @interface Provides {} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProvisionException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProvisionException.java deleted file mode 100644 index f98003ab07d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ProvisionException.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.Message; - -import java.util.Collection; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Indicates that there was a runtime failure while providing an instance. - * - * @author kevinb@google.com (Kevin Bourrillion) - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class ProvisionException extends RuntimeException { - - private final ImmutableSet messages; - - /** Creates a ConfigurationException containing {@code messages}. */ - public ProvisionException(Iterable messages) { - this.messages = ImmutableSet.copyOf(messages); - checkArgument(!this.messages.isEmpty()); - initCause(Errors.getOnlyCause(this.messages)); - } - - public ProvisionException(String message, Throwable cause) { - super(cause); - this.messages = ImmutableSet.of(new Message(ImmutableList.of(), message, cause)); - } - - public ProvisionException(String message) { - this.messages = ImmutableSet.of(new Message(message)); - } - - /** Returns messages for the errors that caused this exception. */ - public Collection getErrorMessages() { - return messages; - } - - @Override public String getMessage() { - return Errors.format("Guice provision errors", messages); - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Reflection.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Reflection.java deleted file mode 100644 index 2fcf995d651..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Reflection.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.elasticsearch.util.inject; - -import java.lang.reflect.Constructor; - -/** - * Abstraction for Java's reflection APIs. This interface exists to provide a single place where - * runtime reflection can be substituted for another mechanism such as CGLib or compile-time code - * generation. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -class Reflection { - - /** - * A placeholder. This enables us to continue processing and gather more - * errors but blows up if you actually try to use it. - */ - static class InvalidConstructor { - InvalidConstructor() { - throw new AssertionError(); - } - } - - @SuppressWarnings("unchecked") - static Constructor invalidConstructor() { - try { - return (Constructor) InvalidConstructor.class.getDeclaredConstructor(); - } - catch (NoSuchMethodException e) { - throw new AssertionError(e); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Scope.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Scope.java deleted file mode 100644 index abbe5cc34e4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Scope.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -/** - * A scope is a level of visibility that instances provided by Guice may have. - * By default, an instance created by the {@link Injector} has no scope, - * meaning it has no state from the framework's perspective -- the - * {@code Injector} creates it, injects it once into the class that required it, - * and then immediately forgets it. Associating a scope with a particular - * binding allows the created instance to be "remembered" and possibly used - * again for other injections. - * - *

An example of a scope is {@link Scopes#SINGLETON}. - * - * @author crazybob@google.com (Bob Lee) - */ -public interface Scope { - - /** - * Scopes a provider. The returned provider returns objects from this scope. - * If an object does not exist in this scope, the provider can use the given - * unscoped provider to retrieve one. - * - *

Scope implementations are strongly encouraged to override - * {@link Object#toString} in the returned provider and include the backing - * provider's {@code toString()} output. - * - * @param key binding key - * @param unscoped locates an instance when one doesn't already exist in this - * scope. - * @return a new provider which only delegates to the given unscoped provider - * when an instance of the requested object doesn't already exist in this - * scope - */ - public Provider scope(Key key, Provider unscoped); - - /** - * A short but useful description of this scope. For comparison, the standard - * scopes that ship with guice use the descriptions - * {@code "Scopes.SINGLETON"}, {@code "ServletScopes.SESSION"} and - * {@code "ServletScopes.REQUEST"}. - */ - String toString(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ScopeAnnotation.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ScopeAnnotation.java deleted file mode 100644 index 8cba1ca1e5b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ScopeAnnotation.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * Annotates annotations which are used for scoping. Only one such annotation - * may apply to a single implementation class. You must also annotate scope - * annotations with {@code @Retention(RUNTIME)}. For example: - * - *

- *   {@code @}Retention(RUNTIME)
- *   {@code @}Target(TYPE)
- *   {@code @}ScopeAnnotation
- *   public {@code @}interface SessionScoped {}
- * 
- * - * @author crazybob@google.com (Bob Lee) - */ -@Target(ANNOTATION_TYPE) -@Retention(RUNTIME) -public @interface ScopeAnnotation {} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ScopeBindingProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ScopeBindingProcessor.java deleted file mode 100644 index 33668ebb789..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/ScopeBindingProcessor.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Annotations; -import org.elasticsearch.util.inject.internal.Errors; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import org.elasticsearch.util.inject.spi.ScopeBinding; -import java.lang.annotation.Annotation; - -/** - * Handles {@link Binder#bindScope} commands. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -class ScopeBindingProcessor extends AbstractProcessor { - - ScopeBindingProcessor(Errors errors) { - super(errors); - } - - @Override public Boolean visit(ScopeBinding command) { - Scope scope = command.getScope(); - Class annotationType = command.getAnnotationType(); - - if (!Annotations.isScopeAnnotation(annotationType)) { - errors.withSource(annotationType).missingScopeAnnotation(); - // Go ahead and bind anyway so we don't get collateral errors. - } - - if (!Annotations.isRetainedAtRuntime(annotationType)) { - errors.withSource(annotationType) - .missingRuntimeRetention(command.getSource()); - // Go ahead and bind anyway so we don't get collateral errors. - } - - Scope existing = injector.state.getScope(checkNotNull(annotationType, "annotation type")); - if (existing != null) { - errors.duplicateScopes(existing, annotationType, scope); - } else { - injector.state.putAnnotation(annotationType, checkNotNull(scope, "scope")); - } - - return true; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Scopes.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Scopes.java deleted file mode 100644 index 7357c7546ae..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Scopes.java +++ /dev/null @@ -1,128 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.InternalFactory; -import org.elasticsearch.util.inject.internal.Scoping; -import java.lang.annotation.Annotation; - -/** - * Built-in scope implementations. - * - * @author crazybob@google.com (Bob Lee) - */ -public class Scopes { - - private Scopes() {} - - /** - * One instance per {@link Injector}. Also see {@code @}{@link Singleton}. - */ - public static final Scope SINGLETON = new Scope() { - public Provider scope(Key key, final Provider creator) { - return new Provider() { - - private volatile T instance; - - // DCL on a volatile is safe as of Java 5, which we obviously require. - @SuppressWarnings("DoubleCheckedLocking") - public T get() { - if (instance == null) { - /* - * Use a pretty coarse lock. We don't want to run into deadlocks - * when two threads try to load circularly-dependent objects. - * Maybe one of these days we will identify independent graphs of - * objects and offer to load them in parallel. - */ - synchronized (InjectorImpl.class) { - if (instance == null) { - instance = creator.get(); - } - } - } - return instance; - } - - public String toString() { - return String.format("%s[%s]", creator, SINGLETON); - } - }; - } - - @Override public String toString() { - return "Scopes.SINGLETON"; - } - }; - - /** - * No scope; the same as not applying any scope at all. Each time the - * Injector obtains an instance of an object with "no scope", it injects this - * instance then immediately forgets it. When the next request for the same - * binding arrives it will need to obtain the instance over again. - * - *

This exists only in case a class has been annotated with a scope - * annotation such as {@link Singleton @Singleton}, and you need to override - * this to "no scope" in your binding. - * - * @since 2.0 - */ - public static final Scope NO_SCOPE = new Scope() { - public Provider scope(Key key, Provider unscoped) { - return unscoped; - } - @Override public String toString() { - return "Scopes.NO_SCOPE"; - } - }; - - /** Scopes an internal factory. */ - static InternalFactory scope(Key key, InjectorImpl injector, - InternalFactory creator, Scoping scoping) { - - if (scoping.isNoScope()) { - return creator; - } - - Scope scope = scoping.getScopeInstance(); - - Provider scoped - = scope.scope(key, new ProviderToInternalFactoryAdapter(injector, creator)); - return new InternalFactoryToProviderAdapter( - Initializables.>of(scoped)); - } - - /** - * Replaces annotation scopes with instance scopes using the Injector's annotation-to-instance - * map. If the scope annotation has no corresponding instance, an error will be added and unscoped - * will be retuned. - */ - static Scoping makeInjectable(Scoping scoping, InjectorImpl injector, Errors errors) { - Class scopeAnnotation = scoping.getScopeAnnotation(); - if (scopeAnnotation == null) { - return scoping; - } - - Scope scope = injector.state.getScope(scopeAnnotation); - if (scope != null) { - return Scoping.forInstance(scope); - } - - errors.scopeNotFound(scopeAnnotation); - return Scoping.UNSCOPED; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleFieldInjector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleFieldInjector.java deleted file mode 100644 index 3135f44fbc8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleFieldInjector.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.internal.InternalFactory; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.InjectionPoint; -import java.lang.reflect.Field; - -/** - * Sets an injectable field. - */ -class SingleFieldInjector implements SingleMemberInjector { - final Field field; - final InjectionPoint injectionPoint; - final Dependency dependency; - final InternalFactory factory; - - public SingleFieldInjector(InjectorImpl injector, InjectionPoint injectionPoint, Errors errors) - throws ErrorsException { - this.injectionPoint = injectionPoint; - this.field = (Field) injectionPoint.getMember(); - this.dependency = injectionPoint.getDependencies().get(0); - - // Ewwwww... - field.setAccessible(true); - factory = injector.getInternalFactory(dependency.getKey(), errors); - } - - public InjectionPoint getInjectionPoint() { - return injectionPoint; - } - - public void inject(Errors errors, InternalContext context, Object o) { - errors = errors.withSource(dependency); - - context.setDependency(dependency); - try { - Object value = factory.get(errors, context, dependency); - field.set(o, value); - } catch (ErrorsException e) { - errors.withSource(injectionPoint).merge(e.getErrors()); - } catch (IllegalAccessException e) { - throw new AssertionError(e); // a security manager is blocking us, we're hosed - } finally { - context.setDependency(null); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleMemberInjector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleMemberInjector.java deleted file mode 100644 index ea4325d6e35..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleMemberInjector.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.spi.InjectionPoint; - -/** - * Injects a field or method of a given object. - */ -interface SingleMemberInjector { - void inject(Errors errors, InternalContext context, Object o); - InjectionPoint getInjectionPoint(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleMethodInjector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleMethodInjector.java deleted file mode 100644 index 016698c43c0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleMethodInjector.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.InjectorImpl.MethodInvoker; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.spi.InjectionPoint; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -/** - * Invokes an injectable method. - */ -class SingleMethodInjector implements SingleMemberInjector { - final MethodInvoker methodInvoker; - final SingleParameterInjector[] parameterInjectors; - final InjectionPoint injectionPoint; - - public SingleMethodInjector(InjectorImpl injector, InjectionPoint injectionPoint, Errors errors) - throws ErrorsException { - this.injectionPoint = injectionPoint; - final Method method = (Method) injectionPoint.getMember(); - methodInvoker = createMethodInvoker(method); - parameterInjectors = injector.getParametersInjectors(injectionPoint.getDependencies(), errors); - } - - private MethodInvoker createMethodInvoker(final Method method) { - - // We can't use FastMethod if the method is private. - int modifiers = method.getModifiers(); - if (!Modifier.isPrivate(modifiers) && !Modifier.isProtected(modifiers)) { - } - - if (!Modifier.isPublic(modifiers)) { - method.setAccessible(true); - } - - return new MethodInvoker() { - public Object invoke(Object target, Object... parameters) - throws IllegalAccessException, InvocationTargetException { - return method.invoke(target, parameters); - } - }; - } - - public InjectionPoint getInjectionPoint() { - return injectionPoint; - } - - public void inject(Errors errors, InternalContext context, Object o) { - Object[] parameters; - try { - parameters = SingleParameterInjector.getAll(errors, context, parameterInjectors); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - return; - } - - try { - methodInvoker.invoke(o, parameters); - } catch (IllegalAccessException e) { - throw new AssertionError(e); // a security manager is blocking us, we're hosed - } catch (InvocationTargetException userException) { - Throwable cause = userException.getCause() != null - ? userException.getCause() - : userException; - errors.withSource(injectionPoint).errorInjectingMethod(cause); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleParameterInjector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleParameterInjector.java deleted file mode 100644 index a78854faaaa..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/SingleParameterInjector.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.internal.InternalContext; -import org.elasticsearch.util.inject.internal.InternalFactory; -import org.elasticsearch.util.inject.spi.Dependency; - -/** - * Resolves a single parameter, to be used in a constructor or method invocation. - */ -class SingleParameterInjector { - private static final Object[] NO_ARGUMENTS = {}; - - private final Dependency dependency; - private final InternalFactory factory; - - SingleParameterInjector(Dependency dependency, InternalFactory factory) { - this.dependency = dependency; - this.factory = factory; - } - - private T inject(Errors errors, InternalContext context) throws ErrorsException { - context.setDependency(dependency); - try { - return factory.get(errors.withSource(dependency), context, dependency); - } finally { - context.setDependency(null); - } - } - - /** - * Returns an array of parameter values. - */ - static Object[] getAll(Errors errors, InternalContext context, - SingleParameterInjector[] parameterInjectors) throws ErrorsException { - if (parameterInjectors == null) { - return NO_ARGUMENTS; - } - - int numErrorsBefore = errors.size(); - - int size = parameterInjectors.length; - Object[] parameters = new Object[size]; - - // optimization: use manual for/each to save allocating an iterator here - for (int i = 0; i < size; i++) { - SingleParameterInjector parameterInjector = parameterInjectors[i]; - try { - parameters[i] = parameterInjector.inject(errors, context); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - } - - errors.throwIfNewErrors(numErrorsBefore); - return parameters; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Singleton.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Singleton.java deleted file mode 100644 index a877faad105..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Singleton.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * Apply this to implementation classes when you want only one instance - * (per {@link Injector}) to be reused for all injections for that binding. - * - * @author crazybob@google.com (Bob Lee) - */ -@Target({ ElementType.TYPE, ElementType.METHOD }) -@Retention(RUNTIME) -@ScopeAnnotation -public @interface Singleton {} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Stage.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Stage.java deleted file mode 100644 index d6638b9761e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/Stage.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -/** - * The stage we're running in. - * - * @author crazybob@google.com (Bob Lee) - */ -public enum Stage { - - /** - * We're running in a tool (an IDE plugin for example). We need binding meta data but not a - * functioning Injector. Do not inject members of instances. Do not load eager singletons. Do as - * little as possible so our tools run nice and snappy. Injectors created in this stage cannot - * be used to satisfy injections. - */ - TOOL, - - /** - * We want fast startup times at the expense of runtime performance and some up front error - * checking. - */ - DEVELOPMENT, - - /** - * We want to catch errors as early as possible and take performance hits up front. - */ - PRODUCTION -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/State.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/State.java deleted file mode 100644 index 2c0b6d5b36d..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/State.java +++ /dev/null @@ -1,142 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.internal.BindingImpl; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.MatcherAndConverter; -import org.elasticsearch.util.inject.spi.TypeListenerBinding; - -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Map; - -/** - * The inheritable data within an injector. This class is intended to allow parent and local - * injector data to be accessed as a unit. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -interface State { - - static final State NONE = new State() { - public State parent() { - throw new UnsupportedOperationException(); - } - - public BindingImpl getExplicitBinding(Key key) { - return null; - } - - public Map, Binding> getExplicitBindingsThisLevel() { - throw new UnsupportedOperationException(); - } - - public void putBinding(Key key, BindingImpl binding) { - throw new UnsupportedOperationException(); - } - - public Scope getScope(Class scopingAnnotation) { - return null; - } - - public void putAnnotation(Class annotationType, Scope scope) { - throw new UnsupportedOperationException(); - } - - public void addConverter(MatcherAndConverter matcherAndConverter) { - throw new UnsupportedOperationException(); - } - - public MatcherAndConverter getConverter(String stringValue, TypeLiteral type, Errors errors, - Object source) { - throw new UnsupportedOperationException(); - } - - public Iterable getConvertersThisLevel() { - return ImmutableSet.of(); - } - - public void addTypeListener(TypeListenerBinding typeListenerBinding) { - throw new UnsupportedOperationException(); - } - - public List getTypeListenerBindings() { - return ImmutableList.of(); - } - - public void blacklist(Key key) { - } - - public boolean isBlacklisted(Key key) { - return true; - } - - public Object lock() { - throw new UnsupportedOperationException(); - } - }; - - State parent(); - - /** Gets a binding which was specified explicitly in a module, or null. */ - BindingImpl getExplicitBinding(Key key); - - /** Returns the explicit bindings at this level only. */ - Map, Binding> getExplicitBindingsThisLevel(); - - void putBinding(Key key, BindingImpl binding); - - /** Returns the matching scope, or null. */ - Scope getScope(Class scopingAnnotation); - - void putAnnotation(Class annotationType, Scope scope); - - void addConverter(MatcherAndConverter matcherAndConverter); - - /** Returns the matching converter for {@code type}, or null if none match. */ - MatcherAndConverter getConverter( - String stringValue, TypeLiteral type, Errors errors, Object source); - - /** Returns all converters at this level only. */ - Iterable getConvertersThisLevel(); - - void addTypeListener(TypeListenerBinding typeListenerBinding); - - List getTypeListenerBindings(); - - /** - * Forbids the corresponding injector from creating a binding to {@code key}. Child injectors - * blacklist their bound keys on their parent injectors to prevent just-in-time bindings on the - * parent injector that would conflict. - */ - void blacklist(Key key); - - /** - * Returns true if {@code key} is forbidden from being bound in this injector. This indicates that - * one of this injector's descendent's has bound the key. - */ - boolean isBlacklisted(Key key); - - /** - * Returns the shared lock for all injector data. This is a low-granularity, high-contention lock - * to be used when reading mutable data (ie. just-in-time bindings, and binding blacklists). - */ - Object lock(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeConverterBindingProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeConverterBindingProcessor.java deleted file mode 100644 index 75bfa5f2b92..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeConverterBindingProcessor.java +++ /dev/null @@ -1,174 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.MatcherAndConverter; -import org.elasticsearch.util.inject.internal.SourceProvider; -import org.elasticsearch.util.inject.internal.Strings; -import org.elasticsearch.util.inject.matcher.AbstractMatcher; -import org.elasticsearch.util.inject.matcher.Matcher; -import org.elasticsearch.util.inject.matcher.Matchers; -import org.elasticsearch.util.inject.spi.TypeConverter; -import org.elasticsearch.util.inject.spi.TypeConverterBinding; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Type; - -/** - * Handles {@link Binder#convertToTypes} commands. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -class TypeConverterBindingProcessor extends AbstractProcessor { - - TypeConverterBindingProcessor(Errors errors) { - super(errors); - } - - /** Installs default converters for primitives, enums, and class literals. */ - public void prepareBuiltInConverters(InjectorImpl injector) { - this.injector = injector; - try { - // Configure type converters. - convertToPrimitiveType(int.class, Integer.class); - convertToPrimitiveType(long.class, Long.class); - convertToPrimitiveType(boolean.class, Boolean.class); - convertToPrimitiveType(byte.class, Byte.class); - convertToPrimitiveType(short.class, Short.class); - convertToPrimitiveType(float.class, Float.class); - convertToPrimitiveType(double.class, Double.class); - - convertToClass(Character.class, new TypeConverter() { - public Object convert(String value, TypeLiteral toType) { - value = value.trim(); - if (value.length() != 1) { - throw new RuntimeException("Length != 1."); - } - return value.charAt(0); - } - - @Override public String toString() { - return "TypeConverter"; - } - }); - - convertToClasses(Matchers.subclassesOf(Enum.class), new TypeConverter() { - @SuppressWarnings("unchecked") - public Object convert(String value, TypeLiteral toType) { - return Enum.valueOf((Class) toType.getRawType(), value); - } - - @Override public String toString() { - return "TypeConverter>"; - } - }); - - internalConvertToTypes( - new AbstractMatcher>() { - public boolean matches(TypeLiteral typeLiteral) { - return typeLiteral.getRawType() == Class.class; - } - - @Override public String toString() { - return "Class"; - } - }, - new TypeConverter() { - @SuppressWarnings("unchecked") - public Object convert(String value, TypeLiteral toType) { - try { - return Class.forName(value); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e.getMessage()); - } - } - - @Override public String toString() { - return "TypeConverter>"; - } - } - ); - } finally { - this.injector = null; - } - } - - private void convertToPrimitiveType(Class primitiveType, final Class wrapperType) { - try { - final Method parser = wrapperType.getMethod( - "parse" + Strings.capitalize(primitiveType.getName()), String.class); - - TypeConverter typeConverter = new TypeConverter() { - @SuppressWarnings("unchecked") - public Object convert(String value, TypeLiteral toType) { - try { - return parser.invoke(null, value); - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e.getTargetException().getMessage()); - } - } - - @Override public String toString() { - return "TypeConverter<" + wrapperType.getSimpleName() + ">"; - } - }; - - convertToClass(wrapperType, typeConverter); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } - } - - private void convertToClass(Class type, TypeConverter converter) { - convertToClasses(Matchers.identicalTo(type), converter); - } - - private void convertToClasses(final Matcher> typeMatcher, - TypeConverter converter) { - internalConvertToTypes(new AbstractMatcher>() { - public boolean matches(TypeLiteral typeLiteral) { - Type type = typeLiteral.getType(); - if (!(type instanceof Class)) { - return false; - } - Class clazz = (Class) type; - return typeMatcher.matches(clazz); - } - - @Override public String toString() { - return typeMatcher.toString(); - } - }, converter); - } - - private void internalConvertToTypes(Matcher> typeMatcher, - TypeConverter converter) { - injector.state.addConverter( - new MatcherAndConverter(typeMatcher, converter, SourceProvider.UNKNOWN_SOURCE)); - } - - @Override public Boolean visit(TypeConverterBinding command) { - injector.state.addConverter(new MatcherAndConverter( - command.getTypeMatcher(), command.getTypeConverter(), command.getSource())); - return true; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeListenerBindingProcessor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeListenerBindingProcessor.java deleted file mode 100644 index c57c15fbc13..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeListenerBindingProcessor.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.TypeListenerBinding; - -/** - * Handles {@link Binder#bindListener} commands. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -class TypeListenerBindingProcessor extends AbstractProcessor { - - TypeListenerBindingProcessor(Errors errors) { - super(errors); - } - - @Override public Boolean visit(TypeListenerBinding binding) { - injector.state.addTypeListener(binding); - return true; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeLiteral.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeLiteral.java deleted file mode 100644 index 318e511b1c3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/TypeLiteral.java +++ /dev/null @@ -1,338 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.inject.internal.MoreTypes; -import org.elasticsearch.util.inject.util.Types; - -import java.lang.reflect.*; -import java.util.List; - -import static org.elasticsearch.util.inject.internal.MoreTypes.*; -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Represents a generic type {@code T}. Java doesn't yet provide a way to - * represent generic types, so this class does. Forces clients to create a - * subclass of this class which enables retrieval the type information even at - * runtime. - * - *

For example, to create a type literal for {@code List}, you can - * create an empty anonymous inner class: - * - *

- * {@code TypeLiteral> list = new TypeLiteral>() {};} - * - *

This syntax cannot be used to create type literals that have wildcard - * parameters, such as {@code Class} or {@code List}. - * Such type literals must be constructed programatically, either by {@link - * Method#getGenericReturnType extracting types from members} or by using the - * {@link Types} factory class. - * - *

Along with modeling generic types, this class can resolve type parameters. - * For example, to figure out what type {@code keySet()} returns on a {@code - * Map}, use this code:

   {@code
- *
- *   TypeLiteral> mapType
- *       = new TypeLiteral>() {};
- *   TypeLiteral keySetType
- *       = mapType.getReturnType(Map.class.getMethod("keySet"));
- *   System.out.println(keySetType); // prints "Set"}
- * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -public class TypeLiteral { - - final Class rawType; - final Type type; - final int hashCode; - - /** - * Constructs a new type literal. Derives represented class from type - * parameter. - * - *

Clients create an empty anonymous subclass. Doing so embeds the type - * parameter in the anonymous class's type hierarchy so we can reconstitute it - * at runtime despite erasure. - */ - @SuppressWarnings("unchecked") - protected TypeLiteral() { - this.type = getSuperclassTypeParameter(getClass()); - this.rawType = (Class) MoreTypes.getRawType(type); - this.hashCode = MoreTypes.hashCode(type); - } - - /** - * Unsafe. Constructs a type literal manually. - */ - @SuppressWarnings("unchecked") - TypeLiteral(Type type) { - this.type = canonicalize(checkNotNull(type, "type")); - this.rawType = (Class) MoreTypes.getRawType(this.type); - this.hashCode = MoreTypes.hashCode(this.type); - } - - /** - * Returns the type from super class's type parameter in {@link MoreTypes#canonicalize(Type) - * canonical form}. - */ - static Type getSuperclassTypeParameter(Class subclass) { - Type superclass = subclass.getGenericSuperclass(); - if (superclass instanceof Class) { - throw new RuntimeException("Missing type parameter."); - } - ParameterizedType parameterized = (ParameterizedType) superclass; - return canonicalize(parameterized.getActualTypeArguments()[0]); - } - - /** - * Gets type literal from super class's type parameter. - */ - static TypeLiteral fromSuperclassTypeParameter(Class subclass) { - return new TypeLiteral(getSuperclassTypeParameter(subclass)); - } - - /** - * Returns the raw (non-generic) type for this type. - * - * @since 2.0 - */ - public final Class getRawType() { - return rawType; - } - - /** - * Gets underlying {@code Type} instance. - */ - public final Type getType() { - return type; - } - - /** - * Gets the type of this type's provider. - */ - @SuppressWarnings("unchecked") - final TypeLiteral> providerType() { - // This cast is safe and wouldn't generate a warning if Type had a type - // parameter. - return (TypeLiteral>) get(Types.providerOf(getType())); - } - - @Override public final int hashCode() { - return this.hashCode; - } - - @Override public final boolean equals(Object o) { - return o instanceof TypeLiteral - && MoreTypes.equals(type, ((TypeLiteral) o).type); - } - - @Override public final String toString() { - return MoreTypes.toString(type); - } - - /** - * Gets type literal for the given {@code Type} instance. - */ - public static TypeLiteral get(Type type) { - return new TypeLiteral(type); - } - - /** - * Gets type literal for the given {@code Class} instance. - */ - public static TypeLiteral get(Class type) { - return new TypeLiteral(type); - } - - - /** Returns an immutable list of the resolved types. */ - private List> resolveAll(Type[] types) { - TypeLiteral[] result = new TypeLiteral[types.length]; - for (int t = 0; t < types.length; t++) { - result[t] = resolve(types[t]); - } - return ImmutableList.of(result); - } - - /** - * Resolves known type parameters in {@code toResolve} and returns the result. - */ - TypeLiteral resolve(Type toResolve) { - return TypeLiteral.get(resolveType(toResolve)); - } - - Type resolveType(Type toResolve) { - // this implementation is made a little more complicated in an attempt to avoid object-creation - while (true) { - if (toResolve instanceof TypeVariable) { - TypeVariable original = (TypeVariable) toResolve; - toResolve = MoreTypes.resolveTypeVariable(type, rawType, original); - if (toResolve == original) { - return toResolve; - } - - } else if (toResolve instanceof GenericArrayType) { - GenericArrayType original = (GenericArrayType) toResolve; - Type componentType = original.getGenericComponentType(); - Type newComponentType = resolveType(componentType); - return componentType == newComponentType - ? original - : Types.arrayOf(newComponentType); - - } else if (toResolve instanceof ParameterizedType) { - ParameterizedType original = (ParameterizedType) toResolve; - Type ownerType = original.getOwnerType(); - Type newOwnerType = resolveType(ownerType); - boolean changed = newOwnerType != ownerType; - - Type[] args = original.getActualTypeArguments(); - for (int t = 0, length = args.length; t < length; t++) { - Type resolvedTypeArgument = resolveType(args[t]); - if (resolvedTypeArgument != args[t]) { - if (!changed) { - args = args.clone(); - changed = true; - } - args[t] = resolvedTypeArgument; - } - } - - return changed - ? Types.newParameterizedTypeWithOwner(newOwnerType, original.getRawType(), args) - : original; - - } else if (toResolve instanceof WildcardType) { - WildcardType original = (WildcardType) toResolve; - Type[] originalLowerBound = original.getLowerBounds(); - Type[] originalUpperBound = original.getUpperBounds(); - - if (originalLowerBound.length == 1) { - Type lowerBound = resolveType(originalLowerBound[0]); - if (lowerBound != originalLowerBound[0]) { - return Types.supertypeOf(lowerBound); - } - } else if (originalUpperBound.length == 1) { - Type upperBound = resolveType(originalUpperBound[0]); - if (upperBound != originalUpperBound[0]) { - return Types.subtypeOf(upperBound); - } - } - return original; - - } else { - return toResolve; - } - } - } - - /** - * Returns the generic form of {@code supertype}. For example, if this is {@code - * ArrayList}, this returns {@code Iterable} given the input {@code - * Iterable.class}. - * - * @param supertype a superclass of, or interface implemented by, this. - * @since 2.0 - */ - public TypeLiteral getSupertype(Class supertype) { - checkArgument(supertype.isAssignableFrom(rawType), - "%s is not a supertype of %s", supertype, this.type); - return resolve(MoreTypes.getGenericSupertype(type, rawType, supertype)); - } - - /** - * Returns the resolved generic type of {@code field}. - * - * @param field a field defined by this or any superclass. - * @since 2.0 - */ - public TypeLiteral getFieldType(Field field) { - checkArgument(field.getDeclaringClass().isAssignableFrom(rawType), - "%s is not defined by a supertype of %s", field, type); - return resolve(field.getGenericType()); - } - - /** - * Returns the resolved generic parameter types of {@code methodOrConstructor}. - * - * @param methodOrConstructor a method or constructor defined by this or any supertype. - * @since 2.0 - */ - public List> getParameterTypes(Member methodOrConstructor) { - Type[] genericParameterTypes; - - if (methodOrConstructor instanceof Method) { - Method method = (Method) methodOrConstructor; - checkArgument(method.getDeclaringClass().isAssignableFrom(rawType), - "%s is not defined by a supertype of %s", method, type); - genericParameterTypes = method.getGenericParameterTypes(); - - } else if (methodOrConstructor instanceof Constructor) { - Constructor constructor = (Constructor) methodOrConstructor; - checkArgument(constructor.getDeclaringClass().isAssignableFrom(rawType), - "%s does not construct a supertype of %s", constructor, type); - genericParameterTypes = constructor.getGenericParameterTypes(); - - } else { - throw new IllegalArgumentException("Not a method or a constructor: " + methodOrConstructor); - } - - return resolveAll(genericParameterTypes); - } - - /** - * Returns the resolved generic exception types thrown by {@code constructor}. - * - * @param methodOrConstructor a method or constructor defined by this or any supertype. - * @since 2.0 - */ - public List> getExceptionTypes(Member methodOrConstructor) { - Type[] genericExceptionTypes; - - if (methodOrConstructor instanceof Method) { - Method method = (Method) methodOrConstructor; - checkArgument(method.getDeclaringClass().isAssignableFrom(rawType), - "%s is not defined by a supertype of %s", method, type); - genericExceptionTypes = method.getGenericExceptionTypes(); - - } else if (methodOrConstructor instanceof Constructor) { - Constructor constructor = (Constructor) methodOrConstructor; - checkArgument(constructor.getDeclaringClass().isAssignableFrom(rawType), - "%s does not construct a supertype of %s", constructor, type); - genericExceptionTypes = constructor.getGenericExceptionTypes(); - - } else { - throw new IllegalArgumentException("Not a method or a constructor: " + methodOrConstructor); - } - - return resolveAll(genericExceptionTypes); - } - - /** - * Returns the resolved generic return type of {@code method}. - * - * @param method a method defined by this or any supertype. - * @since 2.0 - */ - public TypeLiteral getReturnType(Method method) { - checkArgument(method.getDeclaringClass().isAssignableFrom(rawType), - "%s is not defined by a supertype of %s", method, type); - return resolve(method.getGenericReturnType()); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/WeakKeySet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/WeakKeySet.java deleted file mode 100644 index cfcfa4f4a28..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/WeakKeySet.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject; - -import org.elasticsearch.util.collect.Sets; - -import java.util.Set; - -/** - * Minimal set that doesn't hold strong references to the contained keys. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -final class WeakKeySet { - - /** - * We store strings rather than keys so we don't hold strong references. - * - *

One potential problem with this approach is that parent and child injectors cannot define - * keys whose class names are equal but class loaders are different. This shouldn't be an issue - * in practice. - */ - private Set backingSet = Sets.newHashSet(); - - public boolean add(Key key) { - return backingSet.add(key.toString()); - } - - public boolean contains(Object o) { - return o instanceof Key && backingSet.contains(o.toString()); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/Assisted.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/Assisted.java deleted file mode 100644 index d3e981bdf24..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/Assisted.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.assistedinject; - -import org.elasticsearch.util.inject.BindingAnnotation; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * Annotates an injected parameter or field whose value comes from an argument to a factory method. - * - * @author jmourits@google.com (Jerome Mourits) - * @author jessewilson@google.com (Jesse Wilson) - */ -@BindingAnnotation @Target({ FIELD, PARAMETER, METHOD }) @Retention(RUNTIME) -public @interface Assisted { - - /** - * The unique name for this parameter. This is matched to the {@literal @Assisted} constructor - * parameter with the same value. Names are not necessary when the parameter types are distinct. - */ - String value() default ""; -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/AssistedConstructor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/AssistedConstructor.java deleted file mode 100644 index 0bbd011286f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/AssistedConstructor.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.assistedinject; - -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.TypeLiteral; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Type; -import java.util.*; - -/** - * Internal respresentation of a constructor annotated with - * {@link AssistedInject} - * - * @author jmourits@google.com (Jerome Mourits) - * @author jessewilson@google.com (Jesse Wilson) - */ -class AssistedConstructor { - - private final Constructor constructor; - private final ParameterListKey assistedParameters; - private final List allParameters; - - @SuppressWarnings("unchecked") - public AssistedConstructor(Constructor constructor, List> parameterTypes) { - this.constructor = constructor; - - Annotation[][] annotations = constructor.getParameterAnnotations(); - - List typeList = Lists.newArrayList(); - allParameters = new ArrayList(); - - // categorize params as @Assisted or @Injected - for (int i = 0; i < parameterTypes.size(); i++) { - Parameter parameter = new Parameter(parameterTypes.get(i).getType(), annotations[i]); - allParameters.add(parameter); - if (parameter.isProvidedByFactory()) { - typeList.add(parameter.getType()); - } - } - this.assistedParameters = new ParameterListKey(typeList); - } - - /** - * Returns the {@link ParameterListKey} for this constructor. The - * {@link ParameterListKey} is created from the ordered list of {@link Assisted} - * constructor parameters. - */ - public ParameterListKey getAssistedParameters() { - return assistedParameters; - } - - /** - * Returns an ordered list of all constructor parameters (both - * {@link Assisted} and {@link Inject}ed). - */ - public List getAllParameters() { - return allParameters; - } - - public Set> getDeclaredExceptions() { - return new HashSet>(Arrays.asList(constructor.getExceptionTypes())); - } - - /** - * Returns an instance of T, constructed using this constructor, with the - * supplied arguments. - */ - public T newInstance(Object[] args) throws Throwable { - constructor.setAccessible(true); - try { - return constructor.newInstance(args); - } catch (InvocationTargetException e) { - throw e.getCause(); - } - } - - @Override - public String toString() { - return constructor.toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/AssistedInject.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/AssistedInject.java deleted file mode 100644 index f48b1395858..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/AssistedInject.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.assistedinject; - -import static java.lang.annotation.ElementType.CONSTRUCTOR; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - *

Constructors annotated with {@code @AssistedInject} indicate that they can be instantiated by - * the {@link FactoryProvider}. Each constructor must exactly match one corresponding factory method - * within the factory interface. - * - *

Constructor parameters must be either supplied by the factory interface and marked with - * @Assisted, or they must be injectable. - * - * @deprecated {@link FactoryProvider} now works better with the standard {@literal @Inject} - * annotation. When using that annotation, parameters are matched by name and type rather than - * by position. In addition, values that use the standard {@literal @Inject} constructor - * annotation are eligible for method interception. - * - * @author jmourits@google.com (Jerome Mourits) - * @author jessewilson@google.com (Jesse Wilson) - */ -@Target({CONSTRUCTOR}) -@Retention(RUNTIME) -@Deprecated -public @interface AssistedInject {} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/FactoryProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/FactoryProvider.java deleted file mode 100644 index 2d6de8f8370..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/FactoryProvider.java +++ /dev/null @@ -1,339 +0,0 @@ -/** - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.assistedinject; - -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.HasDependencies; -import org.elasticsearch.util.inject.spi.Message; - -import java.lang.annotation.Annotation; -import java.lang.reflect.*; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Provides a factory that combines the caller's arguments with injector-supplied values to - * construct objects. - * - *

Defining a factory

- * Create an interface whose methods return the constructed type, or any of its supertypes. The - * method's parameters are the arguments required to build the constructed type. - *
public interface PaymentFactory {
- *   Payment create(Date startDate, Money amount);
- * }
- * You can name your factory methods whatever you like, such as create, createPayment - * or newPayment. - * - *

Creating a type that accepts factory parameters

- * {@code constructedType} is a concrete class with an {@literal @}{@link Inject}-annotated - * constructor. In addition to injector-supplied parameters, the constructor should have - * parameters that match each of the factory method's parameters. Each factory-supplied parameter - * requires an {@literal @}{@link Assisted} annotation. This serves to document that the parameter - * is not bound by your application's modules. - *
public class RealPayment implements Payment {
- *   {@literal @}Inject
- *   public RealPayment(
- *      CreditService creditService,
- *      AuthService authService,
- *      {@literal @}Assisted Date startDate,
- *      {@literal @}Assisted Money amount) {
- *     ...
- *   }
- * }
- * Any parameter that permits a null value should also be annotated {@code @Nullable}. - * - *

Configuring factories

- * In your {@link org.elasticsearch.util.inject.Module module}, bind the factory interface to the returned - * factory: - *
bind(PaymentFactory.class).toProvider(
- *     FactoryProvider.newFactory(PaymentFactory.class, RealPayment.class));
- * As a side-effect of this binding, Guice will inject the factory to initialize it for use. The - * factory cannot be used until the injector has been initialized. - * - *

Using the factory

- * Inject your factory into your application classes. When you use the factory, your arguments - * will be combined with values from the injector to construct an instance. - *
public class PaymentAction {
- *   {@literal @}Inject private PaymentFactory paymentFactory;
- *
- *   public void doPayment(Money amount) {
- *     Payment payment = paymentFactory.create(new Date(), amount);
- *     payment.apply();
- *   }
- * }
- * - *

Making parameter types distinct

- * The types of the factory method's parameters must be distinct. To use multiple parameters of - * the same type, use a named {@literal @}{@link Assisted} annotation to disambiguate the - * parameters. The names must be applied to the factory method's parameters: - * - *
public interface PaymentFactory {
- *   Payment create(
- *       {@literal @}Assisted("startDate") Date startDate,
- *       {@literal @}Assisted("dueDate") Date dueDate,
- *       Money amount);
- * } 
- * ...and to the concrete type's constructor parameters: - *
public class RealPayment implements Payment {
- *   {@literal @}Inject
- *   public RealPayment(
- *      CreditService creditService,
- *      AuthService authService,
- *      {@literal @}Assisted("startDate") Date startDate,
- *      {@literal @}Assisted("dueDate") Date dueDate,
- *      {@literal @}Assisted Money amount) {
- *     ...
- *   }
- * }
- * - *

Values are created by Guice

- * Returned factories use child injectors to create values. The values are eligible for method - * interception. In addition, {@literal @}{@literal Inject} members will be injected before they are - * returned. - * - *

Backwards compatibility using {@literal @}AssistedInject

- * Instead of the {@literal @}Inject annotation, you may annotate the constructed classes with - * {@literal @}{@link AssistedInject}. This triggers a limited backwards-compatability mode. - * - *

Instead of matching factory method arguments to constructor parameters using their names, the - * parameters are matched by their order. The first factory method argument is - * used for the first {@literal @}Assisted constructor parameter, etc.. Annotation names have no - * effect. - * - *

Returned values are not created by Guice. These types are not eligible for - * method interception. They do receive post-construction member injection. - * - * @param The factory interface - * - * @author jmourits@google.com (Jerome Mourits) - * @author jessewilson@google.com (Jesse Wilson) - * @author dtm@google.com (Daniel Martin) - */ -public class FactoryProvider implements Provider, HasDependencies { - - /* - * This class implements the old @AssistedInject implementation that manually matches constructors - * to factory methods. The new child injector implementation lives in FactoryProvider2. - */ - - private Injector injector; - - private final TypeLiteral factoryType; - private final Map> factoryMethodToConstructor; - - public static Provider newFactory( - Class factoryType, Class implementationType){ - return newFactory(TypeLiteral.get(factoryType), TypeLiteral.get(implementationType)); - } - - public static Provider newFactory( - TypeLiteral factoryType, TypeLiteral implementationType) { - Map> factoryMethodToConstructor - = createMethodMapping(factoryType, implementationType); - - if (!factoryMethodToConstructor.isEmpty()) { - return new FactoryProvider(factoryType, factoryMethodToConstructor); - } else { - return new FactoryProvider2(factoryType, Key.get(implementationType)); - } - } - - private FactoryProvider(TypeLiteral factoryType, - Map> factoryMethodToConstructor) { - this.factoryType = factoryType; - this.factoryMethodToConstructor = factoryMethodToConstructor; - checkDeclaredExceptionsMatch(); - } - - @Inject - void setInjectorAndCheckUnboundParametersAreInjectable(Injector injector) { - this.injector = injector; - for (AssistedConstructor c : factoryMethodToConstructor.values()) { - for (Parameter p : c.getAllParameters()) { - if(!p.isProvidedByFactory() && !paramCanBeInjected(p, injector)) { - // this is lame - we're not using the proper mechanism to add an - // error to the injector. Throughout this class we throw exceptions - // to add errors, which isn't really the best way in Guice - throw newConfigurationException("Parameter of type '%s' is not injectable or annotated " - + "with @Assisted for Constructor '%s'", p, c); - } - } - } - } - - private void checkDeclaredExceptionsMatch() { - for (Map.Entry> entry : factoryMethodToConstructor.entrySet()) { - for (Class constructorException : entry.getValue().getDeclaredExceptions()) { - if (!isConstructorExceptionCompatibleWithFactoryExeception( - constructorException, entry.getKey().getExceptionTypes())) { - throw newConfigurationException("Constructor %s declares an exception, but no compatible " - + "exception is thrown by the factory method %s", entry.getValue(), entry.getKey()); - } - } - } - } - - private boolean isConstructorExceptionCompatibleWithFactoryExeception( - Class constructorException, Class[] factoryExceptions) { - for (Class factoryException : factoryExceptions) { - if (factoryException.isAssignableFrom(constructorException)) { - return true; - } - } - return false; - } - - private boolean paramCanBeInjected(Parameter parameter, Injector injector) { - return parameter.isBound(injector); - } - - private static Map> createMethodMapping( - TypeLiteral factoryType, TypeLiteral implementationType) { - List> constructors = Lists.newArrayList(); - - for (Constructor constructor : implementationType.getRawType().getDeclaredConstructors()) { - if (constructor.getAnnotation(AssistedInject.class) != null) { - @SuppressWarnings("unchecked") // the constructor type and implementation type agree - AssistedConstructor assistedConstructor = new AssistedConstructor( - constructor, implementationType.getParameterTypes(constructor)); - constructors.add(assistedConstructor); - } - } - - if (constructors.isEmpty()) { - return ImmutableMap.of(); - } - - Method[] factoryMethods = factoryType.getRawType().getMethods(); - - if (constructors.size() != factoryMethods.length) { - throw newConfigurationException("Constructor mismatch: %s has %s @AssistedInject " - + "constructors, factory %s has %s creation methods", implementationType, - constructors.size(), factoryType, factoryMethods.length); - } - - Map paramsToConstructor = Maps.newHashMap(); - - for (AssistedConstructor c : constructors) { - if (paramsToConstructor.containsKey(c.getAssistedParameters())) { - throw new RuntimeException("Duplicate constructor, " + c); - } - paramsToConstructor.put(c.getAssistedParameters(), c); - } - - Map> result = Maps.newHashMap(); - for (Method method : factoryMethods) { - if (!method.getReturnType().isAssignableFrom(implementationType.getRawType())) { - throw newConfigurationException("Return type of method %s is not assignable from %s", - method, implementationType); - } - - List parameterTypes = Lists.newArrayList(); - for (TypeLiteral parameterType : factoryType.getParameterTypes(method)) { - parameterTypes.add(parameterType.getType()); - } - ParameterListKey methodParams = new ParameterListKey(parameterTypes); - - if (!paramsToConstructor.containsKey(methodParams)) { - throw newConfigurationException("%s has no @AssistInject constructor that takes the " - + "@Assisted parameters %s in that order. @AssistInject constructors are %s", - implementationType, methodParams, paramsToConstructor.values()); - } - - method.getParameterAnnotations(); - for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) { - for (Annotation parameterAnnotation : parameterAnnotations) { - if (parameterAnnotation.annotationType() == Assisted.class) { - throw newConfigurationException("Factory method %s has an @Assisted parameter, which " - + "is incompatible with the deprecated @AssistedInject annotation. Please replace " - + "@AssistedInject with @Inject on the %s constructor.", - method, implementationType); - } - } - } - - AssistedConstructor matchingConstructor = paramsToConstructor.remove(methodParams); - - result.put(method, matchingConstructor); - } - return result; - } - - public Set> getDependencies() { - List> dependencies = Lists.newArrayList(); - for (AssistedConstructor constructor : factoryMethodToConstructor.values()) { - for (Parameter parameter : constructor.getAllParameters()) { - if (!parameter.isProvidedByFactory()) { - dependencies.add(Dependency.get(parameter.getPrimaryBindingKey())); - } - } - } - return ImmutableSet.copyOf(dependencies); - } - - public F get() { - InvocationHandler invocationHandler = new InvocationHandler() { - public Object invoke(Object proxy, Method method, Object[] creationArgs) throws Throwable { - // pass methods from Object.class to the proxy - if (method.getDeclaringClass().equals(Object.class)) { - return method.invoke(this, creationArgs); - } - - AssistedConstructor constructor = factoryMethodToConstructor.get(method); - Object[] constructorArgs = gatherArgsForConstructor(constructor, creationArgs); - Object objectToReturn = constructor.newInstance(constructorArgs); - injector.injectMembers(objectToReturn); - return objectToReturn; - } - - public Object[] gatherArgsForConstructor( - AssistedConstructor constructor, - Object[] factoryArgs) { - int numParams = constructor.getAllParameters().size(); - int argPosition = 0; - Object[] result = new Object[numParams]; - - for (int i = 0; i < numParams; i++) { - Parameter parameter = constructor.getAllParameters().get(i); - if (parameter.isProvidedByFactory()) { - result[i] = factoryArgs[argPosition]; - argPosition++; - } else { - result[i] = parameter.getValue(injector); - } - } - return result; - } - }; - - @SuppressWarnings("unchecked") // we imprecisely treat the class literal of T as a Class - Class factoryRawType = (Class) factoryType.getRawType(); - return factoryRawType.cast(Proxy.newProxyInstance(factoryRawType.getClassLoader(), - new Class[] { factoryRawType }, invocationHandler)); - } - - private static ConfigurationException newConfigurationException(String format, Object... args) { - return new ConfigurationException(ImmutableSet.of(new Message(Errors.format(format, args)))); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/FactoryProvider2.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/FactoryProvider2.java deleted file mode 100644 index 66e1b27e0d0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/FactoryProvider2.java +++ /dev/null @@ -1,247 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.assistedinject; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.ErrorsException; -import org.elasticsearch.util.inject.spi.Message; -import org.elasticsearch.util.inject.util.Providers; - -import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.Arrays; -import java.util.List; - -import static org.elasticsearch.util.collect.Iterables.*; -import static org.elasticsearch.util.inject.internal.Annotations.*; -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * The newer implementation of factory provider. This implementation uses a child injector to - * create values. - * - * @author jessewilson@google.com (Jesse Wilson) - * @author dtm@google.com (Daniel Martin) - */ -final class FactoryProvider2 implements InvocationHandler, Provider { - - /** if a factory method parameter isn't annotated, it gets this annotation. */ - static final Assisted DEFAULT_ANNOTATION = new Assisted() { - public String value() { - return ""; - } - - public Class annotationType() { - return Assisted.class; - } - - @Override public boolean equals(Object o) { - return o instanceof Assisted - && ((Assisted) o).value().equals(""); - } - - @Override public int hashCode() { - return 127 * "value".hashCode() ^ "".hashCode(); - } - - @Override public String toString() { - return "@" + Assisted.class.getName() + "(value=)"; - } - }; - - /** the produced type, or null if all methods return concrete types */ - private final Key producedType; - private final ImmutableMap> returnTypesByMethod; - private final ImmutableMap>> paramTypes; - - /** the hosting injector, or null if we haven't been initialized yet */ - private Injector injector; - - /** the factory interface, implemented and provided */ - private final F factory; - - /** - * @param factoryType a Java interface that defines one or more create methods. - * @param producedType a concrete type that is assignable to the return types of all factory - * methods. - */ - FactoryProvider2(TypeLiteral factoryType, Key producedType) { - this.producedType = producedType; - - Errors errors = new Errors(); - - @SuppressWarnings("unchecked") // we imprecisely treat the class literal of T as a Class - Class factoryRawType = (Class) factoryType.getRawType(); - - try { - ImmutableMap.Builder> returnTypesBuilder = ImmutableMap.builder(); - ImmutableMap.Builder>> paramTypesBuilder - = ImmutableMap.builder(); - // TODO: also grab methods from superinterfaces - for (Method method : factoryRawType.getMethods()) { - Key returnType = getKey( - factoryType.getReturnType(method), method, method.getAnnotations(), errors); - returnTypesBuilder.put(method, returnType); - List> params = factoryType.getParameterTypes(method); - Annotation[][] paramAnnotations = method.getParameterAnnotations(); - int p = 0; - List> keys = Lists.newArrayList(); - for (TypeLiteral param : params) { - Key paramKey = getKey(param, method, paramAnnotations[p++], errors); - keys.add(assistKey(method, paramKey, errors)); - } - paramTypesBuilder.put(method, ImmutableList.copyOf(keys)); - } - returnTypesByMethod = returnTypesBuilder.build(); - paramTypes = paramTypesBuilder.build(); - } catch (ErrorsException e) { - throw new ConfigurationException(e.getErrors().getMessages()); - } - - factory = factoryRawType.cast(Proxy.newProxyInstance(factoryRawType.getClassLoader(), - new Class[] { factoryRawType }, this)); - } - - public F get() { - return factory; - } - - /** - * Returns a key similar to {@code key}, but with an {@literal @}Assisted binding annotation. - * This fails if another binding annotation is clobbered in the process. If the key already has - * the {@literal @}Assisted annotation, it is returned as-is to preserve any String value. - */ - private Key assistKey(Method method, Key key, Errors errors) throws ErrorsException { - if (key.getAnnotationType() == null) { - return Key.get(key.getTypeLiteral(), DEFAULT_ANNOTATION); - } else if (key.getAnnotationType() == Assisted.class) { - return key; - } else { - errors.withSource(method).addMessage( - "Only @Assisted is allowed for factory parameters, but found @%s", - key.getAnnotationType()); - throw errors.toException(); - } - } - - /** - * At injector-creation time, we initialize the invocation handler. At this time we make sure - * all factory methods will be able to build the target types. - */ - @Inject - void initialize(Injector injector) { - if (this.injector != null) { - throw new ConfigurationException(ImmutableList.of(new Message(FactoryProvider2.class, - "Factories.create() factories may only be used in one Injector!"))); - } - - this.injector = injector; - - for (Method method : returnTypesByMethod.keySet()) { - Object[] args = new Object[method.getParameterTypes().length]; - Arrays.fill(args, "dummy object for validating Factories"); - getBindingFromNewInjector(method, args); // throws if the binding isn't properly configured - } - } - - /** - * Creates a child injector that binds the args, and returns the binding for the method's result. - */ - public Binding getBindingFromNewInjector(final Method method, final Object[] args) { - checkState(injector != null, - "Factories.create() factories cannot be used until they're initialized by Guice."); - - final Key returnType = returnTypesByMethod.get(method); - - Module assistedModule = new AbstractModule() { - @SuppressWarnings("unchecked") // raw keys are necessary for the args array and return value - protected void configure() { - Binder binder = binder().withSource(method); - - int p = 0; - for (Key paramKey : paramTypes.get(method)) { - // Wrap in a Provider to cover null, and to prevent Guice from injecting the parameter - binder.bind((Key) paramKey).toProvider(Providers.of(args[p++])); - } - - if (producedType != null && !returnType.equals(producedType)) { - binder.bind(returnType).to((Key) producedType); - } else { - binder.bind(returnType); - } - } - }; - - Injector forCreate = injector.createChildInjector(assistedModule); - return forCreate.getBinding(returnType); - } - - /** - * When a factory method is invoked, we create a child injector that binds all parameters, then - * use that to get an instance of the return type. - */ - public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable { - if (method.getDeclaringClass() == Object.class) { - return method.invoke(this, args); - } - - Provider provider = getBindingFromNewInjector(method, args).getProvider(); - try { - return provider.get(); - } catch (ProvisionException e) { - // if this is an exception declared by the factory method, throw it as-is - if (e.getErrorMessages().size() == 1) { - Message onlyError = getOnlyElement(e.getErrorMessages()); - Throwable cause = onlyError.getCause(); - if (cause != null && canRethrow(method, cause)) { - throw cause; - } - } - throw e; - } - } - - @Override public String toString() { - return factory.getClass().getInterfaces()[0].getName() - + " for " + producedType.getTypeLiteral(); - } - - @Override public boolean equals(Object o) { - return o == this || o == factory; - } - - /** Returns true if {@code thrown} can be thrown by {@code invoked} without wrapping. */ - static boolean canRethrow(Method invoked, Throwable thrown) { - if (thrown instanceof Error || thrown instanceof RuntimeException) { - return true; - } - - for (Class declared : invoked.getExceptionTypes()) { - if (declared.isInstance(thrown)) { - return true; - } - } - - return false; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/Parameter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/Parameter.java deleted file mode 100644 index d7afa731266..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/Parameter.java +++ /dev/null @@ -1,156 +0,0 @@ -/** - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.assistedinject; - -import org.elasticsearch.util.inject.BindingAnnotation; -import org.elasticsearch.util.inject.ConfigurationException; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Provider; -import static org.elasticsearch.util.inject.internal.Preconditions.checkArgument; -import java.lang.annotation.Annotation; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - -/** - * Models a method or constructor parameter. - * - * @author jmourits@google.com (Jerome Mourits) - * @author jessewilson@google.com (Jesse Wilson) - */ -class Parameter { - - private final Type type; - private final boolean isAssisted; - private final Annotation bindingAnnotation; - private final boolean isProvider; - - public Parameter(Type type, Annotation[] annotations) { - this.type = type; - this.bindingAnnotation = getBindingAnnotation(annotations); - this.isAssisted = hasAssistedAnnotation(annotations); - this.isProvider = isProvider(type); - } - - public boolean isProvidedByFactory() { - return isAssisted; - } - - public Type getType() { - return type; - } - - @Override - public String toString() { - StringBuilder result = new StringBuilder(); - if (isAssisted) { - result.append("@Assisted"); - result.append(" "); - } - if (bindingAnnotation != null) { - result.append(bindingAnnotation.toString()); - result.append(" "); - } - result.append(type.toString()); - return result.toString(); - } - - private boolean hasAssistedAnnotation(Annotation[] annotations) { - for (Annotation annotation : annotations) { - if (annotation.annotationType().equals(Assisted.class)) { - return true; - } - } - return false; - } - - /** - * Returns the Guice {@link Key} for this parameter. - */ - public Object getValue(Injector injector) { - return isProvider - ? injector.getProvider(getBindingForType(getProvidedType(type))) - : injector.getInstance(getPrimaryBindingKey()); - } - - public boolean isBound(Injector injector) { - return isBound(injector, getPrimaryBindingKey()) - || isBound(injector, fixAnnotations(getPrimaryBindingKey())); - } - - private boolean isBound(Injector injector, Key key) { - // This method is particularly lame - we really need an API that can test - // for any binding, implicit or explicit - try { - return injector.getBinding(key) != null; - } catch (ConfigurationException e) { - return false; - } - } - - /** - * Replace annotation instances with annotation types, this is only - * appropriate for testing if a key is bound and not for injecting. - * - * See Guice bug 125, - * http://code.google.com/p/google-guice/issues/detail?id=125 - */ - public Key fixAnnotations(Key key) { - return key.getAnnotation() == null - ? key - : Key.get(key.getTypeLiteral(), key.getAnnotation().annotationType()); - } - - Key getPrimaryBindingKey() { - return isProvider - ? getBindingForType(getProvidedType(type)) - : getBindingForType(type); - } - - private Type getProvidedType(Type type) { - return ((ParameterizedType) type).getActualTypeArguments()[0]; - } - - private boolean isProvider(Type type) { - return type instanceof ParameterizedType - && ((ParameterizedType) type).getRawType() == Provider.class; - } - - private Key getBindingForType(Type type) { - return bindingAnnotation != null - ? Key.get(type, bindingAnnotation) - : Key.get(type); - } - - /** - * Returns the unique binding annotation from the specified list, or - * {@code null} if there are none. - * - * @throws IllegalStateException if multiple binding annotations exist. - */ - private Annotation getBindingAnnotation(Annotation[] annotations) { - Annotation bindingAnnotation = null; - for (Annotation a : annotations) { - if (a.annotationType().getAnnotation(BindingAnnotation.class) != null) { - checkArgument(bindingAnnotation == null, - "Parameter has multiple binding annotations: %s and %s", bindingAnnotation, a); - bindingAnnotation = a; - } - } - return bindingAnnotation; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/ParameterListKey.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/ParameterListKey.java deleted file mode 100644 index 5c7e3ee2f0a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/ParameterListKey.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.assistedinject; - -import org.elasticsearch.util.inject.TypeLiteral; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * A list of {@link TypeLiteral}s to match an injectable Constructor's assited - * parameter types to the corresponding factory method. - * - * @author jmourits@google.com (Jerome Mourits) - * @author jessewilson@google.com (Jesse Wilson) - */ -class ParameterListKey { - - private final List paramList; - - public ParameterListKey(List paramList) { - this.paramList = new ArrayList(paramList); - } - - public ParameterListKey(Type[] types) { - this(Arrays.asList(types)); - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof ParameterListKey)) { - return false; - } - ParameterListKey other = (ParameterListKey) o; - return paramList.equals(other.paramList); - } - - @Override - public int hashCode() { - return paramList.hashCode(); - } - - @Override - public String toString() { - return paramList.toString(); - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/package-info.java deleted file mode 100644 index dbd4481d400..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/assistedinject/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Extension for combining factory interfaces with injection; this extension requires {@code - * guice-jndi-2.0.jar}. - */ -package org.elasticsearch.util.inject.assistedinject; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedBindingBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedBindingBuilder.java deleted file mode 100644 index 462df0dc9ba..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedBindingBuilder.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.binder; - -import java.lang.annotation.Annotation; - -/** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - * - * @author crazybob@google.com (Bob Lee) - */ -public interface AnnotatedBindingBuilder extends LinkedBindingBuilder { - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - LinkedBindingBuilder annotatedWith( - Class annotationType); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - LinkedBindingBuilder annotatedWith(Annotation annotation); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedConstantBindingBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedConstantBindingBuilder.java deleted file mode 100644 index ef0ab827a25..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedConstantBindingBuilder.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.binder; - -import java.lang.annotation.Annotation; - -/** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - * - * @author crazybob@google.com (Bob Lee) - */ -public interface AnnotatedConstantBindingBuilder { - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - ConstantBindingBuilder annotatedWith( - Class annotationType); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - ConstantBindingBuilder annotatedWith(Annotation annotation); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedElementBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedElementBuilder.java deleted file mode 100644 index 0a3b5e35acc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/AnnotatedElementBuilder.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.binder; - -import java.lang.annotation.Annotation; - -/** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface AnnotatedElementBuilder { - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - void annotatedWith(Class annotationType); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - void annotatedWith(Annotation annotation); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/ConstantBindingBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/ConstantBindingBuilder.java deleted file mode 100644 index 25a7735bebb..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/ConstantBindingBuilder.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.binder; - -/** - * Binds to a constant value. - */ -public interface ConstantBindingBuilder { - - /** - * Binds constant to the given value. - */ - void to(String value); - - /** - * Binds constant to the given value. - */ - void to(int value); - - /** - * Binds constant to the given value. - */ - void to(long value); - - /** - * Binds constant to the given value. - */ - void to(boolean value); - - /** - * Binds constant to the given value. - */ - void to(double value); - - /** - * Binds constant to the given value. - */ - void to(float value); - - /** - * Binds constant to the given value. - */ - void to(short value); - - /** - * Binds constant to the given value. - */ - void to(char value); - - /** - * Binds constant to the given value. - */ - void to(Class value); - - /** - * Binds constant to the given value. - */ - > void to(E value); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/LinkedBindingBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/LinkedBindingBuilder.java deleted file mode 100644 index 504ac26c558..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/LinkedBindingBuilder.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.binder; - -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Provider; -import org.elasticsearch.util.inject.TypeLiteral; - -/** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - * - * @author crazybob@google.com (Bob Lee) - */ -public interface LinkedBindingBuilder extends ScopedBindingBuilder { - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - ScopedBindingBuilder to(Class implementation); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - ScopedBindingBuilder to(TypeLiteral implementation); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - ScopedBindingBuilder to(Key targetKey); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - * - * @see org.elasticsearch.util.inject.Injector#injectMembers - */ - void toInstance(T instance); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - * - * @see org.elasticsearch.util.inject.Injector#injectMembers - */ - ScopedBindingBuilder toProvider(Provider provider); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - ScopedBindingBuilder toProvider( - Class> providerType); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - ScopedBindingBuilder toProvider( - Key> providerKey); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/ScopedBindingBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/ScopedBindingBuilder.java deleted file mode 100644 index f4e738481f3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/ScopedBindingBuilder.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.binder; - -import org.elasticsearch.util.inject.Scope; -import java.lang.annotation.Annotation; - -/** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - * - * @author crazybob@google.com (Bob Lee) - */ -public interface ScopedBindingBuilder { - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - void in(Class scopeAnnotation); - - /** - * See the EDSL examples at {@link org.elasticsearch.util.inject.Binder}. - */ - void in(Scope scope); - - /** - * Instructs the {@link org.elasticsearch.util.inject.Injector} to eagerly initialize this - * singleton-scoped binding upon creation. Useful for application - * initialization logic. See the EDSL examples at - * {@link org.elasticsearch.util.inject.Binder}. - */ - void asEagerSingleton(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/package-info.java deleted file mode 100644 index 539c86e3cec..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/binder/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Interfaces which make up {@link org.elasticsearch.util.inject.Binder}'s - * expression language. - */ -package org.elasticsearch.util.inject.binder; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/AbstractBindingBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/AbstractBindingBuilder.java deleted file mode 100644 index f975fc8629c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/AbstractBindingBuilder.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Scope; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import org.elasticsearch.util.inject.spi.Element; -import org.elasticsearch.util.inject.spi.InstanceBinding; -import java.lang.annotation.Annotation; -import java.util.List; - -/** - * Bind a value or constant. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public abstract class AbstractBindingBuilder { - - public static final String IMPLEMENTATION_ALREADY_SET = "Implementation is set more than once."; - public static final String SINGLE_INSTANCE_AND_SCOPE - = "Setting the scope is not permitted when binding to a single instance."; - public static final String SCOPE_ALREADY_SET = "Scope is set more than once."; - public static final String BINDING_TO_NULL = "Binding to null instances is not allowed. " - + "Use toProvider(Providers.of(null)) if this is your intended behaviour."; - public static final String CONSTANT_VALUE_ALREADY_SET = "Constant value is set more than once."; - public static final String ANNOTATION_ALREADY_SPECIFIED - = "More than one annotation is specified for this binding."; - - protected static final Key NULL_KEY = Key.get(Void.class); - - protected List elements; - protected int position; - protected final Binder binder; - private BindingImpl binding; - - public AbstractBindingBuilder(Binder binder, List elements, Object source, Key key) { - this.binder = binder; - this.elements = elements; - this.position = elements.size(); - this.binding = new UntargettedBindingImpl(source, key, Scoping.UNSCOPED); - elements.add(position, this.binding); - } - - protected BindingImpl getBinding() { - return binding; - } - - protected BindingImpl setBinding(BindingImpl binding) { - this.binding = binding; - elements.set(position, binding); - return binding; - } - - /** Sets the binding to a copy with the specified annotation on the bound key */ - protected BindingImpl annotatedWithInternal(Class annotationType) { - checkNotNull(annotationType, "annotationType"); - checkNotAnnotated(); - return setBinding(binding.withKey( - Key.get(this.binding.getKey().getTypeLiteral(), annotationType))); - } - - /** Sets the binding to a copy with the specified annotation on the bound key */ - protected BindingImpl annotatedWithInternal(Annotation annotation) { - checkNotNull(annotation, "annotation"); - checkNotAnnotated(); - return setBinding(binding.withKey( - Key.get(this.binding.getKey().getTypeLiteral(), annotation))); - } - - public void in(final Class scopeAnnotation) { - checkNotNull(scopeAnnotation, "scopeAnnotation"); - checkNotScoped(); - setBinding(getBinding().withScoping(Scoping.forAnnotation(scopeAnnotation))); - } - - public void in(final Scope scope) { - checkNotNull(scope, "scope"); - checkNotScoped(); - setBinding(getBinding().withScoping(Scoping.forInstance(scope))); - } - - public void asEagerSingleton() { - checkNotScoped(); - setBinding(getBinding().withScoping(Scoping.EAGER_SINGLETON)); - } - - protected boolean keyTypeIsSet() { - return !Void.class.equals(binding.getKey().getTypeLiteral().getType()); - } - - protected void checkNotTargetted() { - if (!(binding instanceof UntargettedBindingImpl)) { - binder.addError(IMPLEMENTATION_ALREADY_SET); - } - } - - protected void checkNotAnnotated() { - if (binding.getKey().getAnnotationType() != null) { - binder.addError(ANNOTATION_ALREADY_SPECIFIED); - } - } - - protected void checkNotScoped() { - // Scoping isn't allowed when we have only one instance. - if (binding instanceof InstanceBinding) { - binder.addError(SINGLE_INSTANCE_AND_SCOPE); - return; - } - - if (binding.getScoping().isExplicitlyScoped()) { - binder.addError(SCOPE_ALREADY_SET); - } - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Annotations.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Annotations.java deleted file mode 100644 index 985a65fc8d7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Annotations.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.BindingAnnotation; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.ScopeAnnotation; -import org.elasticsearch.util.inject.TypeLiteral; -import org.elasticsearch.util.Classes; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Member; - -/** - * Annotation utilities. - * - * @author crazybob@google.com (Bob Lee) - */ -public class Annotations { - - /** - * Returns true if the given annotation is retained at runtime. - */ - public static boolean isRetainedAtRuntime(Class annotationType) { - Retention retention = annotationType.getAnnotation(Retention.class); - return retention != null && retention.value() == RetentionPolicy.RUNTIME; - } - - /** Returns the scope annotation on {@code type}, or null if none is specified. */ - public static Class findScopeAnnotation( - Errors errors, Class implementation) { - return findScopeAnnotation(errors, implementation.getAnnotations()); - } - - /** Returns the scoping annotation, or null if there isn't one. */ - public static Class findScopeAnnotation(Errors errors, Annotation[] annotations) { - Class found = null; - - for (Annotation annotation : annotations) { - if (annotation.annotationType().isAnnotationPresent(ScopeAnnotation.class)) { - if (found != null) { - errors.duplicateScopeAnnotations(found, annotation.annotationType()); - } else { - found = annotation.annotationType(); - } - } - } - - return found; - } - - public static boolean isScopeAnnotation(Class annotationType) { - return annotationType.isAnnotationPresent(ScopeAnnotation.class); - } - - /** - * Adds an error if there is a misplaced annotations on {@code type}. Scoping - * annotations are not allowed on abstract classes or interfaces. - */ - public static void checkForMisplacedScopeAnnotations( - Class type, Object source, Errors errors) { - if (Classes.isConcrete(type)) { - return; - } - - Class scopeAnnotation = findScopeAnnotation(errors, type); - if (scopeAnnotation != null) { - errors.withSource(type).scopeAnnotationOnAbstractType(scopeAnnotation, type, source); - } - } - - /** Gets a key for the given type, member and annotations. */ - public static Key getKey(TypeLiteral type, Member member, Annotation[] annotations, - Errors errors) throws ErrorsException { - int numErrorsBefore = errors.size(); - Annotation found = findBindingAnnotation(errors, member, annotations); - errors.throwIfNewErrors(numErrorsBefore); - return found == null ? Key.get(type) : Key.get(type, found); - } - - /** - * Returns the binding annotation on {@code member}, or null if there isn't one. - */ - public static Annotation findBindingAnnotation( - Errors errors, Member member, Annotation[] annotations) { - Annotation found = null; - - for (Annotation annotation : annotations) { - if (annotation.annotationType().isAnnotationPresent(BindingAnnotation.class)) { - if (found != null) { - errors.duplicateBindingAnnotations(member, - found.annotationType(), annotation.annotationType()); - } else { - found = annotation; - } - } - } - - return found; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/AsynchronousComputationException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/AsynchronousComputationException.java deleted file mode 100644 index 9e8576bbe9e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/AsynchronousComputationException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -/** - * Wraps an exception that occured during a computation in a different thread. - * - * @author Bob Lee - */ -public class AsynchronousComputationException extends ComputationException { - - public AsynchronousComputationException(Throwable cause) { - super(cause); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BindingBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BindingBuilder.java deleted file mode 100644 index e1ca5fca1db..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BindingBuilder.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.binder.AnnotatedBindingBuilder; -import org.elasticsearch.util.inject.spi.Element; -import org.elasticsearch.util.inject.spi.InjectionPoint; -import org.elasticsearch.util.inject.spi.Message; - -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Set; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Bind a non-constant key. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public class BindingBuilder extends AbstractBindingBuilder - implements AnnotatedBindingBuilder { - - public BindingBuilder(Binder binder, List elements, Object source, Key key) { - super(binder, elements, source, key); - } - - public BindingBuilder annotatedWith(Class annotationType) { - annotatedWithInternal(annotationType); - return this; - } - - public BindingBuilder annotatedWith(Annotation annotation) { - annotatedWithInternal(annotation); - return this; - } - - public BindingBuilder to(Class implementation) { - return to(Key.get(implementation)); - } - - public BindingBuilder to(TypeLiteral implementation) { - return to(Key.get(implementation)); - } - - public BindingBuilder to(Key linkedKey) { - checkNotNull(linkedKey, "linkedKey"); - checkNotTargetted(); - BindingImpl base = getBinding(); - setBinding(new LinkedBindingImpl( - base.getSource(), base.getKey(), base.getScoping(), linkedKey)); - return this; - } - - public void toInstance(T instance) { - checkNotTargetted(); - - // lookup the injection points, adding any errors to the binder's errors list - Set injectionPoints; - if (instance != null) { - try { - injectionPoints = InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); - } catch (ConfigurationException e) { - for (Message message : e.getErrorMessages()) { - binder.addError(message); - } - injectionPoints = e.getPartialValue(); - } - } else { - binder.addError(BINDING_TO_NULL); - injectionPoints = ImmutableSet.of(); - } - - BindingImpl base = getBinding(); - setBinding(new InstanceBindingImpl( - base.getSource(), base.getKey(), base.getScoping(), injectionPoints, instance)); - } - - public BindingBuilder toProvider(Provider provider) { - checkNotNull(provider, "provider"); - checkNotTargetted(); - - // lookup the injection points, adding any errors to the binder's errors list - Set injectionPoints; - try { - injectionPoints = InjectionPoint.forInstanceMethodsAndFields(provider.getClass()); - } catch (ConfigurationException e) { - for (Message message : e.getErrorMessages()) { - binder.addError(message); - } - injectionPoints = e.getPartialValue(); - } - - BindingImpl base = getBinding(); - setBinding(new ProviderInstanceBindingImpl( - base.getSource(), base.getKey(), base.getScoping(), injectionPoints, provider)); - return this; - } - - public BindingBuilder toProvider(Class> providerType) { - return toProvider(Key.get(providerType)); - } - - public BindingBuilder toProvider(Key> providerKey) { - checkNotNull(providerKey, "providerKey"); - checkNotTargetted(); - - BindingImpl base = getBinding(); - setBinding(new LinkedProviderBindingImpl( - base.getSource(), base.getKey(), base.getScoping(), providerKey)); - return this; - } - - @Override public String toString() { - return "BindingBuilder<" + getBinding().getKey().getTypeLiteral() + ">"; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BindingImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BindingImpl.java deleted file mode 100644 index 9e09a5630f5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BindingImpl.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.Binding; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Provider; -import org.elasticsearch.util.inject.spi.BindingScopingVisitor; -import org.elasticsearch.util.inject.spi.ElementVisitor; -import org.elasticsearch.util.inject.spi.InstanceBinding; - -/** - * @author crazybob@google.com (Bob Lee) - */ -public abstract class BindingImpl implements Binding { - - private final Injector injector; - private final Key key; - private final Object source; - private final Scoping scoping; - private final InternalFactory internalFactory; - - public BindingImpl(Injector injector, Key key, Object source, - InternalFactory internalFactory, Scoping scoping) { - this.injector = injector; - this.key = key; - this.source = source; - this.internalFactory = internalFactory; - this.scoping = scoping; - } - - protected BindingImpl(Object source, Key key, Scoping scoping) { - this.internalFactory = null; - this.injector = null; - this.source = source; - this.key = key; - this.scoping = scoping; - } - - public Key getKey() { - return key; - } - - public Object getSource() { - return source; - } - - private volatile Provider provider; - - public Provider getProvider() { - if (provider == null) { - if (injector == null) { - throw new UnsupportedOperationException("getProvider() not supported for module bindings"); - } - - provider = injector.getProvider(key); - } - return provider; - } - - public InternalFactory getInternalFactory() { - return internalFactory; - } - - public Scoping getScoping() { - return scoping; - } - - /** - * Is this a constant binding? This returns true for constant bindings as - * well as toInstance() bindings. - */ - public boolean isConstant() { - return this instanceof InstanceBinding; - } - - public V acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } - - public V acceptScopingVisitor(BindingScopingVisitor visitor) { - return scoping.acceptVisitor(visitor); - } - - protected BindingImpl withScoping(Scoping scoping) { - throw new AssertionError(); - } - - protected BindingImpl withKey(Key key) { - throw new AssertionError(); - } - - @Override public String toString() { - return new ToStringBuilder(Binding.class) - .add("key", key) - .add("scope", scoping) - .add("source", source) - .toString(); - } - - public Injector getInjector() { - return injector; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BytecodeGen.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BytecodeGen.java deleted file mode 100644 index 233325f8ee0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/BytecodeGen.java +++ /dev/null @@ -1,231 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.base.Function; -import org.elasticsearch.util.collect.MapMaker; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Map; -import java.util.logging.Logger; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Utility methods for runtime code generation and class loading. We use this stuff for {@link - * net.sf.cglib.reflect.FastClass faster reflection}, {@link net.sf.cglib.proxy.Enhancer method - * interceptors} and to proxy circular dependencies. - * - *

When loading classes, we need to be careful of: - *

    - *
  • Memory leaks. Generated classes need to be garbage collected in long-lived - * applications. Once an injector and any instances it created can be garbage collected, the - * corresponding generated classes should be collectable. - *
  • Visibility. Containers like OSGi use class loader boundaries - * to enforce modularity at runtime. - *
- * - *

For each generated class, there's multiple class loaders involved: - *

    - *
  • The related class's class loader. Every generated class services exactly - * one user-supplied class. This class loader must be used to access members with private and - * package visibility. - *
  • Guice's class loader. - *
  • Our bridge class loader. This is a child of the user's class loader. It - * selectively delegates to either the user's class loader (for user classes) or the Guice - * class loader (for internal classes that are used by the generated classes). This class - * loader that owns the classes generated by Guice. - *
- * - * @author mcculls@gmail.com (Stuart McCulloch) - * @author jessewilson@google.com (Jesse Wilson) - */ -public final class BytecodeGen { - - private static final Logger logger = Logger.getLogger(BytecodeGen.class.getName()); - - static final ClassLoader GUICE_CLASS_LOADER = BytecodeGen.class.getClassLoader(); - - /** ie. "com.google.inject.internal" */ - private static final String GUICE_INTERNAL_PACKAGE - = BytecodeGen.class.getName().replaceFirst("\\.internal\\..*$", ".internal"); - - private static final String CGLIB_PACKAGE = " "; // any string that's illegal in a package name - - /** Use "-Dguice.custom.loader=false" to disable custom classloading. */ - static final boolean HOOK_ENABLED - = "true".equals(System.getProperty("guice.custom.loader", "true")); - - /** - * Weak cache of bridge class loaders that make the Guice implementation - * classes visible to various code-generated proxies of client classes. - */ - private static final Map CLASS_LOADER_CACHE - = new MapMaker().weakKeys().weakValues().makeComputingMap( - new Function() { - public ClassLoader apply(final @Nullable ClassLoader typeClassLoader) { - logger.fine("Creating a bridge ClassLoader for " + typeClassLoader); - return AccessController.doPrivileged(new PrivilegedAction() { - public ClassLoader run() { - return new BridgeClassLoader(typeClassLoader); - } - }); - } - }); - - /** - * For class loaders, {@code null}, is always an alias to the - * {@link ClassLoader#getSystemClassLoader() system class loader}. This method - * will not return null. - */ - private static ClassLoader canonicalize(ClassLoader classLoader) { - return classLoader != null - ? classLoader - : checkNotNull(getSystemClassLoaderOrNull(), "Couldn't get a ClassLoader"); - } - - /** - * Returns the system classloader, or {@code null} if we don't have - * permission. - */ - private static ClassLoader getSystemClassLoaderOrNull() { - try { - return ClassLoader.getSystemClassLoader(); - } catch (SecurityException e) { - return null; - } - } - - /** - * Returns the class loader to host generated classes for {@code type}. - */ - public static ClassLoader getClassLoader(Class type) { - return getClassLoader(type, type.getClassLoader()); - } - - private static ClassLoader getClassLoader(Class type, ClassLoader delegate) { - delegate = canonicalize(delegate); - - // if the application is running in the System classloader, assume we can run there too - if (delegate == getSystemClassLoaderOrNull()) { - return delegate; - } - - // Don't bother bridging existing bridge classloaders - if (delegate instanceof BridgeClassLoader) { - return delegate; - } - - if (HOOK_ENABLED && Visibility.forType(type) == Visibility.PUBLIC) { - return CLASS_LOADER_CACHE.get(delegate); - } - - return delegate; - } - - /** - * The required visibility of a user's class from a Guice-generated class. Visibility of - * package-private members depends on the loading classloader: only if two classes were loaded by - * the same classloader can they see each other's package-private members. We need to be careful - * when choosing which classloader to use for generated classes. We prefer our bridge classloader, - * since it's OSGi-safe and doesn't leak permgen space. But often we cannot due to visibility. - */ - public enum Visibility { - - /** - * Indicates that Guice-generated classes only need to call and override public members of the - * target class. These generated classes may be loaded by our bridge classloader. - */ - PUBLIC { - public Visibility and(Visibility that) { - return that; - } - }, - - /** - * Indicates that Guice-generated classes need to call or override package-private members. - * These generated classes must be loaded in the same classloader as the target class. They - * won't work with OSGi, and won't get garbage collected until the target class' classloader is - * garbage collected. - */ - SAME_PACKAGE { - public Visibility and(Visibility that) { - return this; - } - }; - - public static Visibility forMember(Member member) { - if ((member.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC)) == 0) { - return SAME_PACKAGE; - } - - Class[] parameterTypes = member instanceof Constructor - ? ((Constructor) member).getParameterTypes() - : ((Method) member).getParameterTypes(); - for (Class type : parameterTypes) { - if (forType(type) == SAME_PACKAGE) { - return SAME_PACKAGE; - } - } - - return PUBLIC; - } - - public static Visibility forType(Class type) { - return (type.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC)) != 0 - ? PUBLIC - : SAME_PACKAGE; - } - - public abstract Visibility and(Visibility that); - } - - /** - * Loader for Guice-generated classes. For referenced classes, this delegates to either either the - * user's classloader (which is the parent of this classloader) or Guice's class loader. - */ - private static class BridgeClassLoader extends ClassLoader { - - public BridgeClassLoader(ClassLoader usersClassLoader) { - super(usersClassLoader); - } - - @Override protected Class loadClass(String name, boolean resolve) - throws ClassNotFoundException { - - // delegate internal requests to Guice class space - if (name.startsWith(GUICE_INTERNAL_PACKAGE) || name.startsWith(CGLIB_PACKAGE)) { - try { - Class clazz = GUICE_CLASS_LOADER.loadClass(name); - if (resolve) { - resolveClass(clazz); - } - return clazz; - } catch (Exception e) { - // fall back to classic delegation - } - } - - return super.loadClass(name, resolve); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Collections2.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Collections2.java deleted file mode 100644 index e734ed65467..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Collections2.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.Lists; - -import java.util.Collection; -import java.util.Set; - -/** - * Provides static methods for working with {@code Collection} instances. - * - * @author Chris Povirk - * @author Mike Bostock - * @author Jared Levy - */ -public final class Collections2 { - private Collections2() {} - - /** - * Converts an iterable into a collection. If the iterable is already a - * collection, it is returned. Otherwise, an {@link java.util.ArrayList} is - * created with the contents of the iterable in same iteration order. - */ - static Collection toCollection(Iterable iterable) { - return (iterable instanceof Collection) - ? (Collection) iterable : Lists.newArrayList(iterable); - } - - static boolean setEquals(Set thisSet, @Nullable Object object) { - if (object == thisSet) { - return true; - } - if (object instanceof Set) { - Set thatSet = (Set) object; - return thisSet.size() == thatSet.size() - && thisSet.containsAll(thatSet); - } - return false; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ComputationException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ComputationException.java deleted file mode 100644 index dbf2f72f84a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ComputationException.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -/** - * Wraps an exception that occured during a computation. - */ -public class ComputationException extends RuntimeException { - - public ComputationException(Throwable cause) { - super(cause); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ConstantBindingBuilderImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ConstantBindingBuilderImpl.java deleted file mode 100644 index b21c3a81665..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ConstantBindingBuilderImpl.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.binder.AnnotatedConstantBindingBuilder; -import org.elasticsearch.util.inject.binder.ConstantBindingBuilder; -import org.elasticsearch.util.inject.spi.Element; -import org.elasticsearch.util.inject.spi.InjectionPoint; - -import java.lang.annotation.Annotation; -import java.util.List; - -/** - * Bind a constant. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public final class ConstantBindingBuilderImpl - extends AbstractBindingBuilder - implements AnnotatedConstantBindingBuilder, ConstantBindingBuilder { - - @SuppressWarnings("unchecked") // constant bindings start out with T unknown - public ConstantBindingBuilderImpl(Binder binder, List elements, Object source) { - super(binder, elements, source, (Key) NULL_KEY); - } - - public ConstantBindingBuilder annotatedWith(Class annotationType) { - annotatedWithInternal(annotationType); - return this; - } - - public ConstantBindingBuilder annotatedWith(Annotation annotation) { - annotatedWithInternal(annotation); - return this; - } - - public void to(final String value) { - toConstant(String.class, value); - } - - public void to(final int value) { - toConstant(Integer.class, value); - } - - public void to(final long value) { - toConstant(Long.class, value); - } - - public void to(final boolean value) { - toConstant(Boolean.class, value); - } - - public void to(final double value) { - toConstant(Double.class, value); - } - - public void to(final float value) { - toConstant(Float.class, value); - } - - public void to(final short value) { - toConstant(Short.class, value); - } - - public void to(final char value) { - toConstant(Character.class, value); - } - - public void to(final Class value) { - toConstant(Class.class, value); - } - - public > void to(final E value) { - toConstant(value.getDeclaringClass(), value); - } - - private void toConstant(Class type, Object instance) { - // this type will define T, so these assignments are safe - @SuppressWarnings("unchecked") - Class typeAsClassT = (Class) type; - @SuppressWarnings("unchecked") - T instanceAsT = (T) instance; - - if (keyTypeIsSet()) { - binder.addError(CONSTANT_VALUE_ALREADY_SET); - return; - } - - BindingImpl base = getBinding(); - Key key; - if (base.getKey().getAnnotation() != null) { - key = Key.get(typeAsClassT, base.getKey().getAnnotation()); - } else if (base.getKey().getAnnotationType() != null) { - key = Key.get(typeAsClassT, base.getKey().getAnnotationType()); - } else { - key = Key.get(typeAsClassT); - } - - if (instanceAsT == null) { - binder.addError(BINDING_TO_NULL); - } - - setBinding(new InstanceBindingImpl( - base.getSource(), key, base.getScoping(), ImmutableSet.of(), instanceAsT)); - } - - @Override public String toString() { - return "ConstantBindingBuilder"; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ConstructionContext.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ConstructionContext.java deleted file mode 100644 index df0d0f3351c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ConstructionContext.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.List; - -/** - * Context of a dependency construction. Used to manage circular references. - * - * @author crazybob@google.com (Bob Lee) - */ -public class ConstructionContext { - - T currentReference; - boolean constructing; - - List> invocationHandlers; - - public T getCurrentReference() { - return currentReference; - } - - public void removeCurrentReference() { - this.currentReference = null; - } - - public void setCurrentReference(T currentReference) { - this.currentReference = currentReference; - } - - public boolean isConstructing() { - return constructing; - } - - public void startConstruction() { - this.constructing = true; - } - - public void finishConstruction() { - this.constructing = false; - invocationHandlers = null; - } - - public Object createProxy(Errors errors, Class expectedType) throws ErrorsException { - // TODO: if I create a proxy which implements all the interfaces of - // the implementation type, I'll be able to get away with one proxy - // instance (as opposed to one per caller). - - if (!expectedType.isInterface()) { - throw errors.cannotSatisfyCircularDependency(expectedType).toException(); - } - - if (invocationHandlers == null) { - invocationHandlers = new ArrayList>(); - } - - DelegatingInvocationHandler invocationHandler - = new DelegatingInvocationHandler(); - invocationHandlers.add(invocationHandler); - - ClassLoader classLoader = BytecodeGen.getClassLoader(expectedType); - return expectedType.cast(Proxy.newProxyInstance(classLoader, - new Class[] { expectedType }, invocationHandler)); - } - - public void setProxyDelegates(T delegate) { - if (invocationHandlers != null) { - for (DelegatingInvocationHandler handler : invocationHandlers) { - handler.setDelegate(delegate); - } - } - } - - static class DelegatingInvocationHandler implements InvocationHandler { - - T delegate; - - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - if (delegate == null) { - throw new IllegalStateException("This is a proxy used to support" - + " circular references involving constructors. The object we're" - + " proxying is not constructed yet. Please wait until after" - + " injection has completed to use this object."); - } - - try { - // This appears to be not test-covered - return method.invoke(delegate, args); - } - catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - catch (IllegalArgumentException e) { - throw new RuntimeException(e); - } - catch (InvocationTargetException e) { - throw e.getTargetException(); - } - } - - void setDelegate(T delegate) { - this.delegate = delegate; - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ErrorHandler.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ErrorHandler.java deleted file mode 100644 index 7601e8de7b0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ErrorHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.spi.Message; - -/** - * Handles errors in the Injector. - * - * @author crazybob@google.com (Bob Lee) - */ -public interface ErrorHandler { - - /** - * Handles an error. - */ - void handle(Object source, Errors errors); - - /** - * Handles a user-reported error. - */ - void handle(Message message); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Errors.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Errors.java deleted file mode 100644 index 26db0368c76..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Errors.java +++ /dev/null @@ -1,631 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.spi.*; - -import java.io.PrintWriter; -import java.io.Serializable; -import java.io.StringWriter; -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Type; -import java.util.*; - -/** - * A collection of error messages. If this type is passed as a method parameter, the method is - * considered to have executed succesfully only if new errors were not added to this collection. - * - *

Errors can be chained to provide additional context. To add context, call {@link #withSource} - * to create a new Errors instance that contains additional context. All messages added to the - * returned instance will contain full context. - * - *

To avoid messages with redundant context, {@link #withSource} should be added sparingly. A - * good rule of thumb is to assume a ethod's caller has already specified enough context to - * identify that method. When calling a method that's defined in a different context, call that - * method with an errors object that includes its context. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public final class Errors implements Serializable { - - /** - * The root errors object. Used to access the list of error messages. - */ - private final Errors root; - - /** - * The parent errors object. Used to obtain the chain of source objects. - */ - private final Errors parent; - - /** - * The leaf source for errors added here. - */ - private final Object source; - - /** - * null unless (root == this) and error messages exist. Never an empty list. - */ - private List errors; // lazy, use getErrorsForAdd() - - public Errors() { - this.root = this; - this.parent = null; - this.source = SourceProvider.UNKNOWN_SOURCE; - } - - public Errors(Object source) { - this.root = this; - this.parent = null; - this.source = source; - } - - private Errors(Errors parent, Object source) { - this.root = parent.root; - this.parent = parent; - this.source = source; - } - - /** - * Returns an instance that uses {@code source} as a reference point for newly added errors. - */ - public Errors withSource(Object source) { - return source == SourceProvider.UNKNOWN_SOURCE - ? this - : new Errors(this, source); - } - - /** - * We use a fairly generic error message here. The motivation is to share the - * same message for both bind time errors: - *

Guice.createInjector(new AbstractModule() {
-   *   public void configure() {
-   *     bind(Runnable.class);
-   *   }
-   * }
- * ...and at provide-time errors: - *
Guice.createInjector().getInstance(Runnable.class);
- * Otherwise we need to know who's calling when resolving a just-in-time - * binding, which makes things unnecessarily complex. - */ - public Errors missingImplementation(Key key) { - return addMessage("No implementation for %s was bound.", key); - } - - public Errors converterReturnedNull(String stringValue, Object source, - TypeLiteral type, MatcherAndConverter matchingConverter) { - return addMessage("Received null converting '%s' (bound at %s) to %s%n" - + " using %s.", - stringValue, convert(source), type, matchingConverter); - } - - public Errors conversionTypeError(String stringValue, Object source, TypeLiteral type, - MatcherAndConverter matchingConverter, Object converted) { - return addMessage("Type mismatch converting '%s' (bound at %s) to %s%n" - + " using %s.%n" - + " Converter returned %s.", - stringValue, convert(source), type, matchingConverter, converted); - } - - public Errors conversionError(String stringValue, Object source, - TypeLiteral type, MatcherAndConverter matchingConverter, RuntimeException cause) { - return errorInUserCode(cause, "Error converting '%s' (bound at %s) to %s%n" - + " using %s.%n" - + " Reason: %s", - stringValue, convert(source), type, matchingConverter, cause); - } - - public Errors ambiguousTypeConversion(String stringValue, Object source, TypeLiteral type, - MatcherAndConverter a, MatcherAndConverter b) { - return addMessage("Multiple converters can convert '%s' (bound at %s) to %s:%n" - + " %s and%n" - + " %s.%n" - + " Please adjust your type converter configuration to avoid overlapping matches.", - stringValue, convert(source), type, a, b); - } - - public Errors bindingToProvider() { - return addMessage("Binding to Provider is not allowed."); - } - - public Errors subtypeNotProvided(Class> providerType, - Class type) { - return addMessage("%s doesn't provide instances of %s.", providerType, type); - } - - public Errors notASubtype(Class implementationType, Class type) { - return addMessage("%s doesn't extend %s.", implementationType, type); - } - - public Errors recursiveImplementationType() { - return addMessage("@ImplementedBy points to the same class it annotates."); - } - - public Errors recursiveProviderType() { - return addMessage("@ProvidedBy points to the same class it annotates."); - } - - public Errors missingRuntimeRetention(Object source) { - return addMessage("Please annotate with @Retention(RUNTIME).%n" - + " Bound at %s.", convert(source)); - } - - public Errors missingScopeAnnotation() { - return addMessage("Please annotate with @ScopeAnnotation."); - } - - public Errors optionalConstructor(Constructor constructor) { - return addMessage("%s is annotated @Inject(optional=true), " - + "but constructors cannot be optional.", constructor); - } - - public Errors cannotBindToGuiceType(String simpleName) { - return addMessage("Binding to core guice framework type is not allowed: %s.", simpleName); - } - - public Errors scopeNotFound(Class scopeAnnotation) { - return addMessage("No scope is bound to %s.", scopeAnnotation); - } - - public Errors scopeAnnotationOnAbstractType( - Class scopeAnnotation, Class type, Object source) { - return addMessage("%s is annotated with %s, but scope annotations are not supported " - + "for abstract types.%n Bound at %s.", type, scopeAnnotation, convert(source)); - } - - public Errors misplacedBindingAnnotation(Member member, Annotation bindingAnnotation) { - return addMessage("%s is annotated with %s, but binding annotations should be applied " - + "to its parameters instead.", member, bindingAnnotation); - } - - private static final String CONSTRUCTOR_RULES = - "Classes must have either one (and only one) constructor " - + "annotated with @Inject or a zero-argument constructor that is not private."; - - public Errors missingConstructor(Class implementation) { - return addMessage("Could not find a suitable constructor in %s. " + CONSTRUCTOR_RULES, - implementation); - } - - public Errors tooManyConstructors(Class implementation) { - return addMessage("%s has more than one constructor annotated with @Inject. " - + CONSTRUCTOR_RULES, implementation); - } - - public Errors duplicateScopes(Scope existing, - Class annotationType, Scope scope) { - return addMessage("Scope %s is already bound to %s. Cannot bind %s.", existing, - annotationType, scope); - } - - public Errors voidProviderMethod() { - return addMessage("Provider methods must return a value. Do not return void."); - } - - public Errors missingConstantValues() { - return addMessage("Missing constant value. Please call to(...)."); - } - - public Errors cannotInjectInnerClass(Class type) { - return addMessage("Injecting into inner classes is not supported. " - + "Please use a 'static' class (top-level or nested) instead of %s.", type); - } - - public Errors duplicateBindingAnnotations(Member member, - Class a, Class b) { - return addMessage("%s has more than one annotation annotated with @BindingAnnotation: " - + "%s and %s", member, a, b); - } - - public Errors duplicateScopeAnnotations( - Class a, Class b) { - return addMessage("More than one scope annotation was found: %s and %s.", a, b); - } - - public Errors recursiveBinding() { - return addMessage("Binding points to itself."); - } - - public Errors bindingAlreadySet(Key key, Object source) { - return addMessage("A binding to %s was already configured at %s.", key, convert(source)); - } - - public Errors childBindingAlreadySet(Key key) { - return addMessage("A binding to %s already exists on a child injector.", key); - } - - public Errors errorInjectingMethod(Throwable cause) { - return errorInUserCode(cause, "Error injecting method, %s", cause); - } - - public Errors errorNotifyingTypeListener(TypeListenerBinding listener, - TypeLiteral type, Throwable cause) { - return errorInUserCode(cause, - "Error notifying TypeListener %s (bound at %s) of %s.%n" - + " Reason: %s", - listener.getListener(), convert(listener.getSource()), type, cause); - } - - public Errors errorInjectingConstructor(Throwable cause) { - return errorInUserCode(cause, "Error injecting constructor, %s", cause); - } - - public Errors errorInProvider(RuntimeException runtimeException) { - return errorInUserCode(runtimeException, "Error in custom provider, %s", runtimeException); - } - - public Errors errorInUserInjector( - MembersInjector listener, TypeLiteral type, RuntimeException cause) { - return errorInUserCode(cause, "Error injecting %s using %s.%n" - + " Reason: %s", type, listener, cause); - } - - public Errors errorNotifyingInjectionListener( - InjectionListener listener, TypeLiteral type, RuntimeException cause) { - return errorInUserCode(cause, "Error notifying InjectionListener %s of %s.%n" - + " Reason: %s", listener, type, cause); - } - - public void exposedButNotBound(Key key) { - addMessage("Could not expose() %s, it must be explicitly bound.", key); - } - - public static Collection getMessagesFromThrowable(Throwable throwable) { - if (throwable instanceof ProvisionException) { - return ((ProvisionException) throwable).getErrorMessages(); - } else if (throwable instanceof ConfigurationException) { - return ((ConfigurationException) throwable).getErrorMessages(); - } else if (throwable instanceof CreationException) { - return ((CreationException) throwable).getErrorMessages(); - } else { - return ImmutableSet.of(); - } - } - - public Errors errorInUserCode(Throwable cause, String messageFormat, Object... arguments) { - Collection messages = getMessagesFromThrowable(cause); - - if (!messages.isEmpty()) { - return merge(messages); - } else { - return addMessage(cause, messageFormat, arguments); - } - } - - public Errors cannotInjectRawProvider() { - return addMessage("Cannot inject a Provider that has no type parameter"); - } - - public Errors cannotInjectRawMembersInjector() { - return addMessage("Cannot inject a MembersInjector that has no type parameter"); - } - - public Errors cannotInjectTypeLiteralOf(Type unsupportedType) { - return addMessage("Cannot inject a TypeLiteral of %s", unsupportedType); - } - - public Errors cannotInjectRawTypeLiteral() { - return addMessage("Cannot inject a TypeLiteral that has no type parameter"); - } - - public Errors cannotSatisfyCircularDependency(Class expectedType) { - return addMessage( - "Tried proxying %s to support a circular dependency, but it is not an interface.", - expectedType); - } - - public void throwCreationExceptionIfErrorsExist() { - if (!hasErrors()) { - return; - } - - throw new CreationException(getMessages()); - } - - public void throwConfigurationExceptionIfErrorsExist() { - if (!hasErrors()) { - return; - } - - throw new ConfigurationException(getMessages()); - } - - public void throwProvisionExceptionIfErrorsExist() { - if (!hasErrors()) { - return; - } - - throw new ProvisionException(getMessages()); - } - - private Message merge(Message message) { - List sources = Lists.newArrayList(); - sources.addAll(getSources()); - sources.addAll(message.getSources()); - return new Message(sources, message.getMessage(), message.getCause()); - } - - public Errors merge(Collection messages) { - for (Message message : messages) { - addMessage(merge(message)); - } - return this; - } - - public Errors merge(Errors moreErrors) { - if (moreErrors.root == root || moreErrors.root.errors == null) { - return this; - } - - merge(moreErrors.root.errors); - return this; - } - - public List getSources() { - List sources = Lists.newArrayList(); - for (Errors e = this; e != null; e = e.parent) { - if (e.source != SourceProvider.UNKNOWN_SOURCE) { - sources.add(0, e.source); - } - } - return sources; - } - - public void throwIfNewErrors(int expectedSize) throws ErrorsException { - if (size() == expectedSize) { - return; - } - - throw toException(); - } - - public ErrorsException toException() { - return new ErrorsException(this); - } - - public boolean hasErrors() { - return root.errors != null; - } - - public Errors addMessage(String messageFormat, Object... arguments) { - return addMessage(null, messageFormat, arguments); - } - - private Errors addMessage(Throwable cause, String messageFormat, Object... arguments) { - String message = format(messageFormat, arguments); - addMessage(new Message(getSources(), message, cause)); - return this; - } - - public Errors addMessage(Message message) { - if (root.errors == null) { - root.errors = Lists.newArrayList(); - } - root.errors.add(message); - return this; - } - - public static String format(String messageFormat, Object... arguments) { - for (int i = 0; i < arguments.length; i++) { - arguments[i] = Errors.convert(arguments[i]); - } - return String.format(messageFormat, arguments); - } - - public List getMessages() { - if (root.errors == null) { - return ImmutableList.of(); - } - - List result = Lists.newArrayList(root.errors); - Collections.sort(result, new Comparator() { - public int compare(Message a, Message b) { - return a.getSource().compareTo(b.getSource()); - } - }); - - return result; - } - - /** Returns the formatted message for an exception with the specified messages. */ - public static String format(String heading, Collection errorMessages) { - Formatter fmt = new Formatter().format(heading).format(":%n%n"); - int index = 1; - boolean displayCauses = getOnlyCause(errorMessages) == null; - - for (Message errorMessage : errorMessages) { - fmt.format("%s) %s%n", index++, errorMessage.getMessage()); - - List dependencies = errorMessage.getSources(); - for (int i = dependencies.size() - 1; i >= 0; i--) { - Object source = dependencies.get(i); - formatSource(fmt, source); - } - - Throwable cause = errorMessage.getCause(); - if (displayCauses && cause != null) { - StringWriter writer = new StringWriter(); - cause.printStackTrace(new PrintWriter(writer)); - fmt.format("Caused by: %s", writer.getBuffer()); - } - - fmt.format("%n"); - } - - if (errorMessages.size() == 1) { - fmt.format("1 error"); - } else { - fmt.format("%s errors", errorMessages.size()); - } - - return fmt.toString(); - } - - /** - * Returns {@code value} if it is non-null allowed to be null. Otherwise a message is added and - * an {@code ErrorsException} is thrown. - */ - public T checkForNull(T value, Object source, Dependency dependency) - throws ErrorsException { - if (value != null || dependency.isNullable()) { - return value; - } - - int parameterIndex = dependency.getParameterIndex(); - String parameterName = (parameterIndex != -1) - ? "parameter " + parameterIndex + " of " - : ""; - addMessage("null returned by binding at %s%n but %s%s is not @Nullable", - source, parameterName, dependency.getInjectionPoint().getMember()); - - throw toException(); - } - - /** - * Returns the cause throwable if there is exactly one cause in {@code messages}. If there are - * zero or multiple messages with causes, null is returned. - */ - public static Throwable getOnlyCause(Collection messages) { - Throwable onlyCause = null; - for (Message message : messages) { - Throwable messageCause = message.getCause(); - if (messageCause == null) { - continue; - } - - if (onlyCause != null) { - return null; - } - - onlyCause = messageCause; - } - - return onlyCause; - } - - public int size() { - return root.errors == null ? 0 : root.errors.size(); - } - - private static abstract class Converter { - - final Class type; - - Converter(Class type) { - this.type = type; - } - - boolean appliesTo(Object o) { - return type.isAssignableFrom(o.getClass()); - } - - String convert(Object o) { - return toString(type.cast(o)); - } - - abstract String toString(T t); - } - - private static final Collection> converters = ImmutableList.of( - new Converter(Class.class) { - public String toString(Class c) { - return c.getName(); - } - }, - new Converter(Member.class) { - public String toString(Member member) { - return MoreTypes.toString(member); - } - }, - new Converter(Key.class) { - public String toString(Key key) { - if (key.getAnnotationType() != null) { - return key.getTypeLiteral() + " annotated with " - + (key.getAnnotation() != null ? key.getAnnotation() : key.getAnnotationType()); - } else { - return key.getTypeLiteral().toString(); - } - } - }); - - public static Object convert(Object o) { - for (Converter converter : converters) { - if (converter.appliesTo(o)) { - return converter.convert(o); - } - } - return o; - } - - public static void formatSource(Formatter formatter, Object source) { - if (source instanceof Dependency) { - Dependency dependency = (Dependency) source; - InjectionPoint injectionPoint = dependency.getInjectionPoint(); - if (injectionPoint != null) { - formatInjectionPoint(formatter, dependency, injectionPoint); - } else { - formatSource(formatter, dependency.getKey()); - } - - } else if (source instanceof InjectionPoint) { - formatInjectionPoint(formatter, null, (InjectionPoint) source); - - } else if (source instanceof Class) { - formatter.format(" at %s%n", StackTraceElements.forType((Class) source)); - - } else if (source instanceof Member) { - formatter.format(" at %s%n", StackTraceElements.forMember((Member) source)); - - } else if (source instanceof TypeLiteral) { - formatter.format(" while locating %s%n", source); - - } else if (source instanceof Key) { - Key key = (Key) source; - formatter.format(" while locating %s%n", convert(key)); - - } else { - formatter.format(" at %s%n", source); - } - } - - public static void formatInjectionPoint(Formatter formatter, Dependency dependency, - InjectionPoint injectionPoint) { - Member member = injectionPoint.getMember(); - Class memberType = MoreTypes.memberType(member); - - if (memberType == Field.class) { - dependency = injectionPoint.getDependencies().get(0); - formatter.format(" while locating %s%n", convert(dependency.getKey())); - formatter.format(" for field at %s%n", StackTraceElements.forMember(member)); - - } else if (dependency != null) { - formatter.format(" while locating %s%n", convert(dependency.getKey())); - formatter.format(" for parameter %s at %s%n", - dependency.getParameterIndex(), StackTraceElements.forMember(member)); - - } else { - formatSource(formatter, injectionPoint.getMember()); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ErrorsException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ErrorsException.java deleted file mode 100644 index 3efe8e0e378..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ErrorsException.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.elasticsearch.util.inject.internal; - -/** - * Indicates that a result could not be returned while preparing or resolving a binding. The caller - * should {@link Errors#merge(Errors) merge} the errors from this exception with their existing - * errors. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public class ErrorsException extends Exception { - - private final Errors errors; - - public ErrorsException(Errors errors) { - this.errors = errors; - } - - public Errors getErrors() { - return errors; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExpirationTimer.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExpirationTimer.java deleted file mode 100644 index 437bcca56f8..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExpirationTimer.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import java.util.Timer; - -/** - * Timer used for entry expiration in MapMaker. - */ -class ExpirationTimer { - static Timer instance = new Timer(true); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExposedBindingImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExposedBindingImpl.java deleted file mode 100644 index 2c74bfba03e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExposedBindingImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.spi.BindingTargetVisitor; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.ExposedBinding; -import org.elasticsearch.util.inject.spi.PrivateElements; - -import java.util.Set; - -public class ExposedBindingImpl extends BindingImpl implements ExposedBinding { - - private final PrivateElements privateElements; - - public ExposedBindingImpl(Injector injector, Object source, Key key, - InternalFactory factory, PrivateElements privateElements) { - super(injector, key, source, factory, Scoping.UNSCOPED); - this.privateElements = privateElements; - } - - public ExposedBindingImpl(Object source, Key key, Scoping scoping, - PrivateElements privateElements) { - super(source, key, scoping); - this.privateElements = privateElements; - } - - public V acceptTargetVisitor(BindingTargetVisitor visitor) { - return visitor.visit(this); - } - - public Set> getDependencies() { - return ImmutableSet.>of(Dependency.get(Key.get(Injector.class))); - } - - public PrivateElements getPrivateElements() { - return privateElements; - } - - public BindingImpl withScoping(Scoping scoping) { - return new ExposedBindingImpl(getSource(), getKey(), scoping, privateElements); - } - - public ExposedBindingImpl withKey(Key key) { - return new ExposedBindingImpl(getSource(), key, getScoping(), privateElements); - } - - @Override public String toString() { - return new ToStringBuilder(ExposedBinding.class) - .add("key", getKey()) - .add("source", getSource()) - .add("privateElements", privateElements) - .toString(); - } - - public void applyTo(Binder binder) { - throw new UnsupportedOperationException("This element represents a synthetic binding."); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExposureBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExposureBuilder.java deleted file mode 100644 index 4090a3c377b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ExposureBuilder.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.binder.AnnotatedElementBuilder; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.Key; -import java.lang.annotation.Annotation; - -/** - * For private binder's expose() method. - */ -public class ExposureBuilder implements AnnotatedElementBuilder { - private final Binder binder; - private final Object source; - private Key key; - - public ExposureBuilder(Binder binder, Object source, Key key) { - this.binder = binder; - this.source = source; - this.key = key; - } - - protected void checkNotAnnotated() { - if (key.getAnnotationType() != null) { - binder.addError(AbstractBindingBuilder.ANNOTATION_ALREADY_SPECIFIED); - } - } - - public void annotatedWith(Class annotationType) { - org.elasticsearch.util.inject.internal.Preconditions.checkNotNull(annotationType, "annotationType"); - checkNotAnnotated(); - key = Key.get(key.getTypeLiteral(), annotationType); - } - - public void annotatedWith(Annotation annotation) { - org.elasticsearch.util.inject.internal.Preconditions.checkNotNull(annotation, "annotation"); - checkNotAnnotated(); - key = Key.get(key.getTypeLiteral(), annotation); - } - - public Key getKey() { - return key; - } - - public Object getSource() { - return source; - } - - @Override public String toString() { - return "AnnotatedElementBuilder"; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/FailableCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/FailableCache.java deleted file mode 100644 index 691213c635c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/FailableCache.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.base.Function; -import org.elasticsearch.util.collect.MapMaker; - -import java.util.Map; - -/** - * Lazily creates (and caches) values for keys. If creating the value fails (with errors), an - * exception is thrown on retrieval. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public abstract class FailableCache { - - private final Map delegate = new MapMaker().makeComputingMap( - new Function() { - public Object apply(@Nullable K key) { - Errors errors = new Errors(); - V result = null; - try { - result = FailableCache.this.create(key, errors); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - return errors.hasErrors() ? errors : result; - } - }); - - protected abstract V create(K key, Errors errors) throws ErrorsException; - - public V get(K key, Errors errors) throws ErrorsException { - Object resultOrError = delegate.get(key); - if (resultOrError instanceof Errors) { - errors.merge((Errors) resultOrError); - throw errors.toException(); - } else { - @SuppressWarnings("unchecked") // create returned a non-error result, so this is safe - V result = (V) resultOrError; - return result; - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InstanceBindingImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InstanceBindingImpl.java deleted file mode 100644 index d05b76f8ab5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InstanceBindingImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Provider; -import org.elasticsearch.util.inject.spi.*; -import org.elasticsearch.util.inject.util.Providers; - -import java.util.Set; - -public class InstanceBindingImpl extends BindingImpl implements InstanceBinding { - - final T instance; - final Provider provider; - final ImmutableSet injectionPoints; - - public InstanceBindingImpl(Injector injector, Key key, Object source, - InternalFactory internalFactory, Set injectionPoints, - T instance) { - super(injector, key, source, internalFactory, Scoping.UNSCOPED); - this.injectionPoints = ImmutableSet.copyOf(injectionPoints); - this.instance = instance; - this.provider = Providers.of(instance); - } - - public InstanceBindingImpl(Object source, Key key, Scoping scoping, - Set injectionPoints, T instance) { - super(source, key, scoping); - this.injectionPoints = ImmutableSet.copyOf(injectionPoints); - this.instance = instance; - this.provider = Providers.of(instance); - } - - @Override public Provider getProvider() { - return this.provider; - } - - public V acceptTargetVisitor(BindingTargetVisitor visitor) { - return visitor.visit(this); - } - - public T getInstance() { - return instance; - } - - public Set getInjectionPoints() { - return injectionPoints; - } - - public Set> getDependencies() { - return instance instanceof HasDependencies - ? ImmutableSet.copyOf(((HasDependencies) instance).getDependencies()) - : Dependency.forInjectionPoints(injectionPoints); - } - - public BindingImpl withScoping(Scoping scoping) { - return new InstanceBindingImpl(getSource(), getKey(), scoping, injectionPoints, instance); - } - - public BindingImpl withKey(Key key) { - return new InstanceBindingImpl(getSource(), key, getScoping(), injectionPoints, instance); - } - - public void applyTo(Binder binder) { - // instance bindings aren't scoped - binder.withSource(getSource()).bind(getKey()).toInstance(instance); - } - - @Override public String toString() { - return new ToStringBuilder(InstanceBinding.class) - .add("key", getKey()) - .add("source", getSource()) - .add("instance", instance) - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InternalContext.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InternalContext.java deleted file mode 100644 index f8356804870..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InternalContext.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.inject.spi.Dependency; - -import java.util.Map; - -/** - * Internal context. Used to coordinate injections and support circular - * dependencies. - * - * @author crazybob@google.com (Bob Lee) - */ -public final class InternalContext { - - private Map> constructionContexts = Maps.newHashMap(); - private Dependency dependency; - - @SuppressWarnings("unchecked") - public ConstructionContext getConstructionContext(Object key) { - ConstructionContext constructionContext - = (ConstructionContext) constructionContexts.get(key); - if (constructionContext == null) { - constructionContext = new ConstructionContext(); - constructionContexts.put(key, constructionContext); - } - return constructionContext; - } - - public Dependency getDependency() { - return dependency; - } - - public void setDependency(Dependency dependency) { - this.dependency = dependency; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InternalFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InternalFactory.java deleted file mode 100644 index 261d6d11e78..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/InternalFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.spi.Dependency; - -/** - * Creates objects which will be injected. - * - * @author crazybob@google.com (Bob Lee) - */ -public interface InternalFactory { - - /** - * Creates an object to be injected. - * - * @param context of this injection - * @throws org.elasticsearch.util.inject.internal.ErrorsException if a value cannot be provided - * @return instance to be injected - */ - T get(Errors errors, InternalContext context, Dependency dependency) - throws ErrorsException; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Join.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Join.java deleted file mode 100644 index b77c7761e56..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Join.java +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.Lists; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Utility for joining pieces of text separated by a delimiter. It can handle - * iterators, collections, arrays, and varargs, and can append to any - * {@link Appendable} or just return a {@link String}. For example, - * {@code join(":", "a", "b", "c")} returns {@code "a:b:c"}. - * - *

All methods of this class throw {@link NullPointerException} when a value - * of {@code null} is supplied for any parameter. The elements within the - * collection, iterator, array, or varargs parameter list may be null -- - * these will be represented in the output by the string {@code "null"}. - * - * @author Kevin Bourrillion - */ -public final class Join { - private Join() {} - - /** - * Returns a string containing the {@code tokens}, converted to strings if - * necessary, separated by {@code delimiter}. If {@code tokens} is empty, it - * returns an empty string. - * - *

Each token will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param delimiter a string to append between every element, but not at the - * beginning or end - * @param tokens objects to append - * @return a string consisting of the joined elements - */ - public static String join(String delimiter, Iterable tokens) { - return join(delimiter, tokens.iterator()); - } - - /** - * Returns a string containing the {@code tokens}, converted to strings if - * necessary, separated by {@code delimiter}. If {@code tokens} is empty, it - * returns an empty string. - * - *

Each token will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param delimiter a string to append between every element, but not at the - * beginning or end - * @param tokens objects to append - * @return a string consisting of the joined elements - */ - public static String join(String delimiter, Object[] tokens) { - return join(delimiter, Arrays.asList(tokens)); - } - - /** - * Returns a string containing the {@code tokens}, converted to strings if - * necessary, separated by {@code delimiter}. - * - *

Each token will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param delimiter a string to append between every element, but not at the - * beginning or end - * @param firstToken the first object to append - * @param otherTokens subsequent objects to append - * @return a string consisting of the joined elements - */ - public static String join( - String delimiter, @Nullable Object firstToken, Object... otherTokens) { - checkNotNull(otherTokens); - return join(delimiter, Lists.newArrayList(firstToken, otherTokens)); - } - - /** - * Returns a string containing the {@code tokens}, converted to strings if - * necessary, separated by {@code delimiter}. If {@code tokens} is empty, it - * returns an empty string. - * - *

Each token will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param delimiter a string to append between every element, but not at the - * beginning or end - * @param tokens objects to append - * @return a string consisting of the joined elements - */ - public static String join(String delimiter, Iterator tokens) { - StringBuilder sb = new StringBuilder(); - join(sb, delimiter, tokens); - return sb.toString(); - } - - /** - * Returns a string containing the contents of {@code map}, with entries - * separated by {@code entryDelimiter}, and keys and values separated with - * {@code keyValueSeparator}. - * - *

Each key and value will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param keyValueSeparator a string to append between every key and its - * associated value - * @param entryDelimiter a string to append between every entry, but not at - * the beginning or end - * @param map the map containing the data to join - * @return a string consisting of the joined entries of the map; empty if the - * map is empty - */ - public static String join( - String keyValueSeparator, String entryDelimiter, Map map) { - return join(new StringBuilder(), keyValueSeparator, entryDelimiter, map) - .toString(); - } - - /** - * Appends each of the {@code tokens} to {@code appendable}, separated by - * {@code delimiter}. - * - *

Each token will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param appendable the object to append the results to - * @param delimiter a string to append between every element, but not at the - * beginning or end - * @param tokens objects to append - * @return the same {@code Appendable} instance that was passed in - * @throws JoinException if an {@link IOException} occurs - */ - public static T join( - T appendable, String delimiter, Iterable tokens) { - return join(appendable, delimiter, tokens.iterator()); - } - - /** - * Appends each of the {@code tokens} to {@code appendable}, separated by - * {@code delimiter}. - * - *

Each token will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param appendable the object to append the results to - * @param delimiter a string to append between every element, but not at the - * beginning or end - * @param tokens objects to append - * @return the same {@code Appendable} instance that was passed in - * @throws JoinException if an {@link IOException} occurs - */ - public static T join( - T appendable, String delimiter, Object[] tokens) { - return join(appendable, delimiter, Arrays.asList(tokens)); - } - - /** - * Appends each of the {@code tokens} to {@code appendable}, separated by - * {@code delimiter}. - * - *

Each token will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param appendable the object to append the results to - * @param delimiter a string to append between every element, but not at the - * beginning or end - * @param firstToken the first object to append - * @param otherTokens subsequent objects to append - * @return the same {@code Appendable} instance that was passed in - * @throws JoinException if an {@link IOException} occurs - */ - public static T join(T appendable, String delimiter, - @Nullable Object firstToken, Object... otherTokens) { - checkNotNull(otherTokens); - return join(appendable, delimiter, Lists.newArrayList(firstToken, otherTokens)); - } - - /** - * Appends each of the {@code tokens} to {@code appendable}, separated by - * {@code delimiter}. - * - *

Each token will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param appendable the object to append the results to - * @param delimiter a string to append between every element, but not at the - * beginning or end - * @param tokens objects to append - * @return the same {@code Appendable} instance that was passed in - * @throws JoinException if an {@link IOException} occurs - */ - public static T join( - T appendable, String delimiter, Iterator tokens) { - - /* This method is the workhorse of the class */ - - checkNotNull(appendable); - checkNotNull(delimiter); - if (tokens.hasNext()) { - try { - appendOneToken(appendable, tokens.next()); - while (tokens.hasNext()) { - appendable.append(delimiter); - appendOneToken(appendable, tokens.next()); - } - } catch (IOException e) { - throw new JoinException(e); - } - } - return appendable; - } - - /** - * Appends the contents of {@code map} to {@code appendable}, with entries - * separated by {@code entryDelimiter}, and keys and values separated with - * {@code keyValueSeparator}. - * - *

Each key and value will be converted to a {@link CharSequence} using - * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. - * Note that this implies that null tokens will be appended as the - * four-character string {@code "null"}. - * - * @param appendable the object to append the results to - * @param keyValueSeparator a string to append between every key and its - * associated value - * @param entryDelimiter a string to append between every entry, but not at - * the beginning or end - * @param map the map containing the data to join - * @return the same {@code Appendable} instance that was passed in - */ - public static T join(T appendable, - String keyValueSeparator, String entryDelimiter, Map map) { - checkNotNull(appendable); - checkNotNull(keyValueSeparator); - checkNotNull(entryDelimiter); - Iterator> entries = map.entrySet().iterator(); - if (entries.hasNext()) { - try { - appendOneEntry(appendable, keyValueSeparator, entries.next()); - while (entries.hasNext()) { - appendable.append(entryDelimiter); - appendOneEntry(appendable, keyValueSeparator, entries.next()); - } - } catch (IOException e) { - throw new JoinException(e); - } - } - return appendable; - } - - private static void appendOneEntry( - Appendable appendable, String keyValueSeparator, Map.Entry entry) - throws IOException { - appendOneToken(appendable, entry.getKey()); - appendable.append(keyValueSeparator); - appendOneToken(appendable, entry.getValue()); - } - - private static void appendOneToken(Appendable appendable, Object token) - throws IOException { - appendable.append(toCharSequence(token)); - } - - private static CharSequence toCharSequence(Object token) { - return (token instanceof CharSequence) - ? (CharSequence) token - : String.valueOf(token); - } - - /** - * Exception thrown in response to an {@link IOException} from the supplied - * {@link Appendable}. This is used because most callers won't want to - * worry about catching an IOException. - */ - public static class JoinException extends RuntimeException { - private JoinException(IOException cause) { - super(cause); - } - - private static final long serialVersionUID = 1L; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/LinkedBindingImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/LinkedBindingImpl.java deleted file mode 100644 index eb1da56e5aa..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/LinkedBindingImpl.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.spi.BindingTargetVisitor; -import org.elasticsearch.util.inject.spi.LinkedKeyBinding; - -public final class LinkedBindingImpl extends BindingImpl implements LinkedKeyBinding { - - final Key targetKey; - - public LinkedBindingImpl(Injector injector, Key key, Object source, - InternalFactory internalFactory, Scoping scoping, - Key targetKey) { - super(injector, key, source, internalFactory, scoping); - this.targetKey = targetKey; - } - - public LinkedBindingImpl(Object source, Key key, Scoping scoping, Key targetKey) { - super(source, key, scoping); - this.targetKey = targetKey; - } - - public V acceptTargetVisitor(BindingTargetVisitor visitor) { - return visitor.visit(this); - } - - public Key getLinkedKey() { - return targetKey; - } - - public BindingImpl withScoping(Scoping scoping) { - return new LinkedBindingImpl(getSource(), getKey(), scoping, targetKey); - } - - public BindingImpl withKey(Key key) { - return new LinkedBindingImpl(getSource(), key, getScoping(), targetKey); - } - - public void applyTo(Binder binder) { - getScoping().applyTo(binder.withSource(getSource()).bind(getKey()).to(getLinkedKey())); - } - - @Override public String toString() { - return new ToStringBuilder(LinkedKeyBinding.class) - .add("key", getKey()) - .add("source", getSource()) - .add("scope", getScoping()) - .add("target", targetKey) - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/LinkedProviderBindingImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/LinkedProviderBindingImpl.java deleted file mode 100644 index ac6849f7010..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/LinkedProviderBindingImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Provider; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.spi.BindingTargetVisitor; -import org.elasticsearch.util.inject.spi.ProviderKeyBinding; - -public final class LinkedProviderBindingImpl - extends BindingImpl implements ProviderKeyBinding { - - final Key> providerKey; - - public LinkedProviderBindingImpl(Injector injector, Key key, Object source, - InternalFactory internalFactory, Scoping scoping, - Key> providerKey) { - super(injector, key, source, internalFactory, scoping); - this.providerKey = providerKey; - } - - LinkedProviderBindingImpl(Object source, Key key, Scoping scoping, - Key> providerKey) { - super(source, key, scoping); - this.providerKey = providerKey; - } - - public V acceptTargetVisitor(BindingTargetVisitor visitor) { - return visitor.visit(this); - } - - public Key> getProviderKey() { - return providerKey; - } - - public BindingImpl withScoping(Scoping scoping) { - return new LinkedProviderBindingImpl(getSource(), getKey(), scoping, providerKey); - } - - public BindingImpl withKey(Key key) { - return new LinkedProviderBindingImpl(getSource(), key, getScoping(), providerKey); - } - - public void applyTo(Binder binder) { - getScoping().applyTo(binder.withSource(getSource()) - .bind(getKey()).toProvider(getProviderKey())); - } - - @Override public String toString() { - return new ToStringBuilder(ProviderKeyBinding.class) - .add("key", getKey()) - .add("source", getSource()) - .add("scope", getScoping()) - .add("provider", providerKey) - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/MatcherAndConverter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/MatcherAndConverter.java deleted file mode 100644 index 58600cefb2a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/MatcherAndConverter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.TypeLiteral; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import org.elasticsearch.util.inject.matcher.Matcher; -import org.elasticsearch.util.inject.spi.TypeConverter; - -/** - * @author crazybob@google.com (Bob Lee) - */ -public final class MatcherAndConverter { - - private final Matcher> typeMatcher; - private final TypeConverter typeConverter; - private final Object source; - - public MatcherAndConverter(Matcher> typeMatcher, - TypeConverter typeConverter, Object source) { - this.typeMatcher = checkNotNull(typeMatcher, "type matcher"); - this.typeConverter = checkNotNull(typeConverter, "converter"); - this.source = source; - } - - public TypeConverter getTypeConverter() { - return typeConverter; - } - - public Matcher> getTypeMatcher() { - return typeMatcher; - } - - public Object getSource() { - return source; - } - - @Override public String toString() { - return typeConverter + " which matches " + typeMatcher - + " (bound at " + source + ")"; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/MoreTypes.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/MoreTypes.java deleted file mode 100644 index f4bedaac544..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/MoreTypes.java +++ /dev/null @@ -1,651 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.base.Objects; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.ConfigurationException; -import org.elasticsearch.util.inject.TypeLiteral; -import org.elasticsearch.util.inject.spi.Message; - -import java.io.Serializable; -import java.lang.reflect.*; -import java.util.Arrays; -import java.util.Map; -import java.util.NoSuchElementException; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Static methods for working with types that we aren't publishing in the - * public {@code Types} API. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public class MoreTypes { - - public static final Type[] EMPTY_TYPE_ARRAY = new Type[] {}; - - private MoreTypes() {} - - private static final Map, TypeLiteral> PRIMITIVE_TO_WRAPPER - = new ImmutableMap.Builder, TypeLiteral>() - .put(TypeLiteral.get(boolean.class), TypeLiteral.get(Boolean.class)) - .put(TypeLiteral.get(byte.class), TypeLiteral.get(Byte.class)) - .put(TypeLiteral.get(short.class), TypeLiteral.get(Short.class)) - .put(TypeLiteral.get(int.class), TypeLiteral.get(Integer.class)) - .put(TypeLiteral.get(long.class), TypeLiteral.get(Long.class)) - .put(TypeLiteral.get(float.class), TypeLiteral.get(Float.class)) - .put(TypeLiteral.get(double.class), TypeLiteral.get(Double.class)) - .put(TypeLiteral.get(char.class), TypeLiteral.get(Character.class)) - .put(TypeLiteral.get(void.class), TypeLiteral.get(Void.class)) - .build(); - - /** - * Returns an equivalent type that's safe for use in a key. The returned type will be free of - * primitive types. Type literals of primitives will return the corresponding wrapper types. - * - * @throws ConfigurationException if {@code type} contains a type variable - */ - public static TypeLiteral makeKeySafe(TypeLiteral type) { - if (!isFullySpecified(type.getType())) { - String message = type + " cannot be used as a key; It is not fully specified."; - throw new ConfigurationException(ImmutableSet.of(new Message(message))); - } - - @SuppressWarnings("unchecked") - TypeLiteral wrappedPrimitives = (TypeLiteral) PRIMITIVE_TO_WRAPPER.get(type); - return wrappedPrimitives != null - ? wrappedPrimitives - : type; - } - - /** - * Returns true if {@code type} is free from type variables. - */ - private static boolean isFullySpecified(Type type) { - if (type instanceof Class) { - return true; - - } else if (type instanceof CompositeType) { - return ((CompositeType) type).isFullySpecified(); - - } else if (type instanceof TypeVariable){ - return false; - - } else { - return ((CompositeType) canonicalize(type)).isFullySpecified(); - } - } - - /** - * Returns a type that is functionally equal but not necessarily equal - * according to {@link Object#equals(Object) Object.equals()}. The returned - * type is {@link Serializable}. - */ - public static Type canonicalize(Type type) { - if (type instanceof ParameterizedTypeImpl - || type instanceof GenericArrayTypeImpl - || type instanceof WildcardTypeImpl) { - return type; - - } else if (type instanceof ParameterizedType) { - ParameterizedType p = (ParameterizedType) type; - return new ParameterizedTypeImpl(p.getOwnerType(), - p.getRawType(), p.getActualTypeArguments()); - - } else if (type instanceof GenericArrayType) { - GenericArrayType g = (GenericArrayType) type; - return new GenericArrayTypeImpl(g.getGenericComponentType()); - - } else if (type instanceof Class && ((Class) type).isArray()) { - Class c = (Class) type; - return new GenericArrayTypeImpl(c.getComponentType()); - - } else if (type instanceof WildcardType) { - WildcardType w = (WildcardType) type; - return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds()); - - } else { - // type is either serializable as-is or unsupported - return type; - } - } - - /** - * Returns a type that's functionally equal but not necessarily equal - * according to {@link Object#equals(Object) Object.equals}. The returned - * member is {@link Serializable}. - */ - public static Member serializableCopy(Member member) { - return member instanceof MemberImpl - ? member - : new MemberImpl(member); - } - - public static Class getRawType(Type type) { - if (type instanceof Class) { - // type is a normal class. - return (Class) type; - - } else if (type instanceof ParameterizedType) { - ParameterizedType parameterizedType = (ParameterizedType) type; - - // I'm not exactly sure why getRawType() returns Type instead of Class. - // Neal isn't either but suspects some pathological case related - // to nested classes exists. - Type rawType = parameterizedType.getRawType(); - checkArgument(rawType instanceof Class, - "Expected a Class, but <%s> is of type %s", type, type.getClass().getName()); - return (Class) rawType; - - } else if (type instanceof GenericArrayType) { - // TODO: Is this sufficient? - return Object[].class; - - } else if (type instanceof TypeVariable) { - // we could use the variable's bounds, but that'll won't work if there are multiple. - // having a raw type that's more general than necessary is okay - return Object.class; - - } else { - throw new IllegalArgumentException("Expected a Class, ParameterizedType, or " - + "GenericArrayType, but <" + type + "> is of type " + type.getClass().getName()); - } - } - - /** - * Returns true if {@code a} and {@code b} are equal. - */ - public static boolean equals(Type a, Type b) { - if (a == b) { - // also handles (a == null && b == null) - return true; - - } else if (a instanceof Class) { - // Class already specifies equals(). - return a.equals(b); - - } else if (a instanceof ParameterizedType) { - if (!(b instanceof ParameterizedType)) { - return false; - } - - // TODO: save a .clone() call - ParameterizedType pa = (ParameterizedType) a; - ParameterizedType pb = (ParameterizedType) b; - return Objects.equal(pa.getOwnerType(), pb.getOwnerType()) - && pa.getRawType().equals(pb.getRawType()) - && Arrays.equals(pa.getActualTypeArguments(), pb.getActualTypeArguments()); - - } else if (a instanceof GenericArrayType) { - if (!(b instanceof GenericArrayType)) { - return false; - } - - GenericArrayType ga = (GenericArrayType) a; - GenericArrayType gb = (GenericArrayType) b; - return equals(ga.getGenericComponentType(), gb.getGenericComponentType()); - - } else if (a instanceof WildcardType) { - if (!(b instanceof WildcardType)) { - return false; - } - - WildcardType wa = (WildcardType) a; - WildcardType wb = (WildcardType) b; - return Arrays.equals(wa.getUpperBounds(), wb.getUpperBounds()) - && Arrays.equals(wa.getLowerBounds(), wb.getLowerBounds()); - - } else if (a instanceof TypeVariable) { - if (!(b instanceof TypeVariable)) { - return false; - } - TypeVariable va = (TypeVariable) a; - TypeVariable vb = (TypeVariable) b; - return va.getGenericDeclaration() == vb.getGenericDeclaration() - && va.getName().equals(vb.getName()); - - } else { - // This isn't a type we support. Could be a generic array type, wildcard type, etc. - return false; - } - } - - /** - * Returns the hashCode of {@code type}. - */ - public static int hashCode(Type type) { - if (type instanceof Class) { - // Class specifies hashCode(). - return type.hashCode(); - - } else if (type instanceof ParameterizedType) { - ParameterizedType p = (ParameterizedType) type; - return Arrays.hashCode(p.getActualTypeArguments()) - ^ p.getRawType().hashCode() - ^ hashCodeOrZero(p.getOwnerType()); - - } else if (type instanceof GenericArrayType) { - return hashCode(((GenericArrayType) type).getGenericComponentType()); - - } else if (type instanceof WildcardType) { - WildcardType w = (WildcardType) type; - return Arrays.hashCode(w.getLowerBounds()) ^ Arrays.hashCode(w.getUpperBounds()); - - } else { - // This isn't a type we support. Probably a type variable - return hashCodeOrZero(type); - } - } - - private static int hashCodeOrZero(Object o) { - return o != null ? o.hashCode() : 0; - } - - public static String toString(Type type) { - if (type instanceof Class) { - return ((Class) type).getName(); - - } else if (type instanceof ParameterizedType) { - ParameterizedType parameterizedType = (ParameterizedType) type; - Type[] arguments = parameterizedType.getActualTypeArguments(); - Type ownerType = parameterizedType.getOwnerType(); - StringBuilder stringBuilder = new StringBuilder(); - if (ownerType != null) { - stringBuilder.append(toString(ownerType)).append("."); - } - stringBuilder.append(toString(parameterizedType.getRawType())); - if (arguments.length > 0) { - stringBuilder - .append("<") - .append(toString(arguments[0])); - for (int i = 1; i < arguments.length; i++) { - stringBuilder.append(", ").append(toString(arguments[i])); - } - } - return stringBuilder.append(">").toString(); - - } else if (type instanceof GenericArrayType) { - return toString(((GenericArrayType) type).getGenericComponentType()) + "[]"; - - } else if (type instanceof WildcardType) { - WildcardType wildcardType = (WildcardType) type; - Type[] lowerBounds = wildcardType.getLowerBounds(); - Type[] upperBounds = wildcardType.getUpperBounds(); - - if (upperBounds.length != 1 || lowerBounds.length > 1) { - throw new UnsupportedOperationException("Unsupported wildcard type " + type); - } - - if (lowerBounds.length == 1) { - if (upperBounds[0] != Object.class) { - throw new UnsupportedOperationException("Unsupported wildcard type " + type); - } - return "? super " + toString(lowerBounds[0]); - } else if (upperBounds[0] == Object.class) { - return "?"; - } else { - return "? extends " + toString(upperBounds[0]); - } - - } else { - return type.toString(); - } - } - - /** - * Returns {@code Field.class}, {@code Method.class} or {@code Constructor.class}. - */ - public static Class memberType(Member member) { - checkNotNull(member, "member"); - - if (member instanceof MemberImpl) { - return ((MemberImpl) member).memberType; - - } else if (member instanceof Field) { - return Field.class; - - } else if (member instanceof Method) { - return Method.class; - - } else if (member instanceof Constructor) { - return Constructor.class; - - } else { - throw new IllegalArgumentException( - "Unsupported implementation class for Member, " + member.getClass()); - } - } - - /** - * Formats a member as concise string, such as {@code java.util.ArrayList.size}, - * {@code java.util.ArrayList()} or {@code java.util.List.remove()}. - */ - public static String toString(Member member) { - Class memberType = memberType(member); - - if (memberType == Method.class) { - return member.getDeclaringClass().getName() + "." + member.getName() + "()"; - } else if (memberType == Field.class) { - return member.getDeclaringClass().getName() + "." + member.getName(); - } else if (memberType == Constructor.class) { - return member.getDeclaringClass().getName() + ".()"; - } else { - throw new AssertionError(); - } - } - - public static String memberKey(Member member) { - checkNotNull(member, "member"); - - return ""; - } - - /** - * Returns the generic supertype for {@code supertype}. For example, given a class {@code - * IntegerSet}, the result for when supertype is {@code Set.class} is {@code Set} and the - * result when the supertype is {@code Collection.class} is {@code Collection}. - */ - public static Type getGenericSupertype(Type type, Class rawType, Class toResolve) { - if (toResolve == rawType) { - return type; - } - - // we skip searching through interfaces if unknown is an interface - if (toResolve.isInterface()) { - Class[] interfaces = rawType.getInterfaces(); - for (int i = 0, length = interfaces.length; i < length; i++) { - if (interfaces[i] == toResolve) { - return rawType.getGenericInterfaces()[i]; - } else if (toResolve.isAssignableFrom(interfaces[i])) { - return getGenericSupertype(rawType.getGenericInterfaces()[i], interfaces[i], toResolve); - } - } - } - - // check our supertypes - if (!rawType.isInterface()) { - while (rawType != Object.class) { - Class rawSupertype = rawType.getSuperclass(); - if (rawSupertype == toResolve) { - return rawType.getGenericSuperclass(); - } else if (toResolve.isAssignableFrom(rawSupertype)) { - return getGenericSupertype(rawType.getGenericSuperclass(), rawSupertype, toResolve); - } - rawType = rawSupertype; - } - } - - // we can't resolve this further - return toResolve; - } - - public static Type resolveTypeVariable(Type type, Class rawType, TypeVariable unknown) { - Class declaredByRaw = declaringClassOf(unknown); - - // we can't reduce this further - if (declaredByRaw == null) { - return unknown; - } - - Type declaredBy = getGenericSupertype(type, rawType, declaredByRaw); - if (declaredBy instanceof ParameterizedType) { - int index = indexOf(declaredByRaw.getTypeParameters(), unknown); - return ((ParameterizedType) declaredBy).getActualTypeArguments()[index]; - } - - return unknown; - } - - private static int indexOf(Object[] array, Object toFind) { - for (int i = 0; i < array.length; i++) { - if (toFind.equals(array[i])) { - return i; - } - } - throw new NoSuchElementException(); - } - - /** - * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by - * a class. - */ - private static Class declaringClassOf(TypeVariable typeVariable) { - GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); - return genericDeclaration instanceof Class - ? (Class) genericDeclaration - : null; - } - - public static class ParameterizedTypeImpl - implements ParameterizedType, Serializable, CompositeType { - private final Type ownerType; - private final Type rawType; - private final Type[] typeArguments; - - public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments) { - // require an owner type if the raw type needs it - if (rawType instanceof Class) { - Class rawTypeAsClass = (Class) rawType; - checkArgument(ownerType != null || rawTypeAsClass.getEnclosingClass() == null, - "No owner type for enclosed %s", rawType); - checkArgument(ownerType == null || rawTypeAsClass.getEnclosingClass() != null, - "Owner type for unenclosed %s", rawType); - } - - this.ownerType = ownerType == null ? null : canonicalize(ownerType); - this.rawType = canonicalize(rawType); - this.typeArguments = typeArguments.clone(); - for (int t = 0; t < this.typeArguments.length; t++) { - checkNotNull(this.typeArguments[t], "type parameter"); - checkNotPrimitive(this.typeArguments[t], "type parameters"); - this.typeArguments[t] = canonicalize(this.typeArguments[t]); - } - } - - public Type[] getActualTypeArguments() { - return typeArguments.clone(); - } - - public Type getRawType() { - return rawType; - } - - public Type getOwnerType() { - return ownerType; - } - - public boolean isFullySpecified() { - if (ownerType != null && !MoreTypes.isFullySpecified(ownerType)) { - return false; - } - - if (!MoreTypes.isFullySpecified(rawType)) { - return false; - } - - for (Type type : typeArguments) { - if (!MoreTypes.isFullySpecified(type)) { - return false; - } - } - - return true; - } - - @Override public boolean equals(Object other) { - return other instanceof ParameterizedType - && MoreTypes.equals(this, (ParameterizedType) other); - } - - @Override public int hashCode() { - return MoreTypes.hashCode(this); - } - - @Override public String toString() { - return MoreTypes.toString(this); - } - - private static final long serialVersionUID = 0; - } - - public static class GenericArrayTypeImpl - implements GenericArrayType, Serializable, CompositeType { - private final Type componentType; - - public GenericArrayTypeImpl(Type componentType) { - this.componentType = canonicalize(componentType); - } - - public Type getGenericComponentType() { - return componentType; - } - - public boolean isFullySpecified() { - return MoreTypes.isFullySpecified(componentType); - } - - @Override public boolean equals(Object o) { - return o instanceof GenericArrayType - && MoreTypes.equals(this, (GenericArrayType) o); - } - - @Override public int hashCode() { - return MoreTypes.hashCode(this); - } - - @Override public String toString() { - return MoreTypes.toString(this); - } - - private static final long serialVersionUID = 0; - } - - /** - * The WildcardType interface supports multiple upper bounds and multiple - * lower bounds. We only support what the Java 6 language needs - at most one - * bound. If a lower bound is set, the upper bound must be Object.class. - */ - public static class WildcardTypeImpl implements WildcardType, Serializable, CompositeType { - private final Type upperBound; - private final Type lowerBound; - - public WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) { - checkArgument(lowerBounds.length <= 1, "Must have at most one lower bound."); - checkArgument(upperBounds.length == 1, "Must have exactly one upper bound."); - - if (lowerBounds.length == 1) { - checkNotNull(lowerBounds[0], "lowerBound"); - checkNotPrimitive(lowerBounds[0], "wildcard bounds"); - checkArgument(upperBounds[0] == Object.class, "bounded both ways"); - this.lowerBound = canonicalize(lowerBounds[0]); - this.upperBound = Object.class; - - } else { - checkNotNull(upperBounds[0], "upperBound"); - checkNotPrimitive(upperBounds[0], "wildcard bounds"); - this.lowerBound = null; - this.upperBound = canonicalize(upperBounds[0]); - } - } - - public Type[] getUpperBounds() { - return new Type[] { upperBound }; - } - - public Type[] getLowerBounds() { - return lowerBound != null ? new Type[] { lowerBound } : EMPTY_TYPE_ARRAY; - } - - public boolean isFullySpecified() { - return MoreTypes.isFullySpecified(upperBound) - && (lowerBound == null || MoreTypes.isFullySpecified(lowerBound)); - } - - @Override public boolean equals(Object other) { - return other instanceof WildcardType - && MoreTypes.equals(this, (WildcardType) other); - } - - @Override public int hashCode() { - return MoreTypes.hashCode(this); - } - - @Override public String toString() { - return MoreTypes.toString(this); - } - - private static final long serialVersionUID = 0; - } - - private static void checkNotPrimitive(Type type, String use) { - checkArgument(!(type instanceof Class) || !((Class) type).isPrimitive(), - "Primitive types are not allowed in %s: %s", use, type); - } - - /** - * We cannot serialize the built-in Java member classes, which prevents us from using Members in - * our exception types. We workaround this with this serializable implementation. It includes all - * of the API methods, plus everything we use for line numbers and messaging. - */ - public static class MemberImpl implements Member, Serializable { - private final Class declaringClass; - private final String name; - private final int modifiers; - private final boolean synthetic; - private final Class memberType; - private final String memberKey; - - private MemberImpl(Member member) { - this.declaringClass = member.getDeclaringClass(); - this.name = member.getName(); - this.modifiers = member.getModifiers(); - this.synthetic = member.isSynthetic(); - this.memberType = memberType(member); - this.memberKey = memberKey(member); - } - - public Class getDeclaringClass() { - return declaringClass; - } - - public String getName() { - return name; - } - - public int getModifiers() { - return modifiers; - } - - public boolean isSynthetic() { - return synthetic; - } - - @Override public String toString() { - return MoreTypes.toString(this); - } - } - - /** A type formed from other types, such as arrays, parameterized types or wildcard types */ - private interface CompositeType { - /** Returns true if there are no type variables in this type. */ - boolean isFullySpecified(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/NullOutputException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/NullOutputException.java deleted file mode 100644 index 5ef9ea50ef7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/NullOutputException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -/** - * Thrown when a computer function returns null. This subclass exists so - * that our ReferenceCache adapter can differentiate null output from null - * keys, but we don't want to make this public otherwise. - * - * @author Bob Lee - */ -class NullOutputException extends NullPointerException { - public NullOutputException(String s) { - super(s); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Nullability.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Nullability.java deleted file mode 100644 index 2115d5eb7c2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Nullability.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.elasticsearch.util.inject.internal; - -import java.lang.annotation.Annotation; - -/** - * Whether a member supports null values injected. - * - *

Support for {@code Nullable} annotations in Guice is loose. - * Any annotation type whose simplename is "Nullable" is sufficient to indicate - * support for null values injected. - * - *

This allows support for JSR-305's - * - * javax.annotation.meta.Nullable annotation and IntelliJ IDEA's - * - * org.jetbrains.annotations.Nullable. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public class Nullability { - private Nullability() {} - - public static boolean allowsNull(Annotation[] annotations) { - for(Annotation a : annotations) { - if ("Nullable".equals(a.annotationType().getSimpleName())) { - return true; - } - } - return false; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Nullable.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Nullable.java deleted file mode 100644 index 71c5a6e630c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Nullable.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * The presence of this annotation on a method parameter indicates that - * {@code null} is an acceptable value for that parameter. It should not be - * used for parameters of primitive types. - * - *

This annotation may be used with the Google Web Toolkit (GWT). - * - * @author Kevin Bourrillion - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.PARAMETER, ElementType.FIELD}) -public @interface Nullable { } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Preconditions.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Preconditions.java deleted file mode 100644 index 214676d1d09..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Preconditions.java +++ /dev/null @@ -1,465 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import java.util.Collection; -import java.util.NoSuchElementException; - -/** - * Simple static methods to be called at the start of your own methods to verify - * correct arguments and state. This allows constructs such as - *

- *     if (count <= 0) {
- *       throw new IllegalArgumentException("must be positive: " + count);
- *     }
- * - * to be replaced with the more compact - *
- *     checkArgument(count > 0, "must be positive: %s", count);
- * - * Note that the sense of the expression is inverted; with {@code Preconditions} - * you declare what you expect to be true, just as you do with an - * - * {@code assert} or a JUnit {@code assertTrue()} call. - * - *

Take care not to confuse precondition checking with other similar types - * of checks! Precondition exceptions -- including those provided here, but also - * {@link IndexOutOfBoundsException}, {@link NoSuchElementException}, {@link - * UnsupportedOperationException} and others -- are used to signal that the - * calling method has made an error. This tells the caller that it should - * not have invoked the method when it did, with the arguments it did, or - * perhaps ever. Postcondition or other invariant failures should not - * throw these types of exceptions. - * - *

Note: The methods of the {@code Preconditions} class are highly - * unusual in one way: they are supposed to throw exceptions, and promise - * in their specifications to do so even when given perfectly valid input. That - * is, {@code null} is a valid parameter to the method {@link - * #checkNotNull(Object)} -- and technically this parameter could be even marked - * as {@link Nullable} -- yet the method will still throw an exception anyway, - * because that's what its contract says to do. - * - *

This class may be used with the Google Web Toolkit (GWT). - * - * @author Kevin Bourrillion - */ -public final class Preconditions { - private Preconditions() {} - - /** - * Ensures the truth of an expression involving one or more parameters to the - * calling method. - * - * @param expression a boolean expression - * @throws IllegalArgumentException if {@code expression} is false - */ - public static void checkArgument(boolean expression) { - if (!expression) { - throw new IllegalArgumentException(); - } - } - - /** - * Ensures the truth of an expression involving one or more parameters to the - * calling method. - * - * @param expression a boolean expression - * @param errorMessage the exception message to use if the check fails; will - * be converted to a string using {@link String#valueOf(Object)} - * @throws IllegalArgumentException if {@code expression} is false - */ - public static void checkArgument(boolean expression, Object errorMessage) { - if (!expression) { - throw new IllegalArgumentException(String.valueOf(errorMessage)); - } - } - - /** - * Ensures the truth of an expression involving one or more parameters to the - * calling method. - * - * @param expression a boolean expression - * @param errorMessageTemplate a template for the exception message should the - * check fail. The message is formed by replacing each {@code %s} - * placeholder in the template with an argument. These are matched by - * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. - * Unmatched arguments will be appended to the formatted message in square - * braces. Unmatched placeholders will be left as-is. - * @param errorMessageArgs the arguments to be substituted into the message - * template. Arguments are converted to strings using - * {@link String#valueOf(Object)}. - * @throws IllegalArgumentException if {@code expression} is false - * @throws NullPointerException if the check fails and either {@code - * errorMessageTemplate} or {@code errorMessageArgs} is null (don't let - * this happen) - */ - public static void checkArgument(boolean expression, - String errorMessageTemplate, Object... errorMessageArgs) { - if (!expression) { - throw new IllegalArgumentException( - format(errorMessageTemplate, errorMessageArgs)); - } - } - - /** - * Ensures the truth of an expression involving the state of the calling - * instance, but not involving any parameters to the calling method. - * - * @param expression a boolean expression - * @throws IllegalStateException if {@code expression} is false - */ - public static void checkState(boolean expression) { - if (!expression) { - throw new IllegalStateException(); - } - } - - /** - * Ensures the truth of an expression involving the state of the calling - * instance, but not involving any parameters to the calling method. - * - * @param expression a boolean expression - * @param errorMessage the exception message to use if the check fails; will - * be converted to a string using {@link String#valueOf(Object)} - * @throws IllegalStateException if {@code expression} is false - */ - public static void checkState(boolean expression, Object errorMessage) { - if (!expression) { - throw new IllegalStateException(String.valueOf(errorMessage)); - } - } - - /** - * Ensures the truth of an expression involving the state of the calling - * instance, but not involving any parameters to the calling method. - * - * @param expression a boolean expression - * @param errorMessageTemplate a template for the exception message should the - * check fail. The message is formed by replacing each {@code %s} - * placeholder in the template with an argument. These are matched by - * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. - * Unmatched arguments will be appended to the formatted message in square - * braces. Unmatched placeholders will be left as-is. - * @param errorMessageArgs the arguments to be substituted into the message - * template. Arguments are converted to strings using - * {@link String#valueOf(Object)}. - * @throws IllegalStateException if {@code expression} is false - * @throws NullPointerException if the check fails and either {@code - * errorMessageTemplate} or {@code errorMessageArgs} is null (don't let - * this happen) - */ - public static void checkState(boolean expression, - String errorMessageTemplate, Object... errorMessageArgs) { - if (!expression) { - throw new IllegalStateException( - format(errorMessageTemplate, errorMessageArgs)); - } - } - - /** - * Ensures that an object reference passed as a parameter to the calling - * method is not null. - * - * @param reference an object reference - * @return the non-null reference that was validated - * @throws NullPointerException if {@code reference} is null - */ - public static T checkNotNull(T reference) { - if (reference == null) { - throw new NullPointerException(); - } - return reference; - } - - /** - * Ensures that an object reference passed as a parameter to the calling - * method is not null. - * - * @param reference an object reference - * @param errorMessage the exception message to use if the check fails; will - * be converted to a string using {@link String#valueOf(Object)} - * @return the non-null reference that was validated - * @throws NullPointerException if {@code reference} is null - */ - public static T checkNotNull(T reference, Object errorMessage) { - if (reference == null) { - throw new NullPointerException(String.valueOf(errorMessage)); - } - return reference; - } - - /** - * Ensures that an object reference passed as a parameter to the calling - * method is not null. - * - * @param reference an object reference - * @param errorMessageTemplate a template for the exception message should the - * check fail. The message is formed by replacing each {@code %s} - * placeholder in the template with an argument. These are matched by - * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. - * Unmatched arguments will be appended to the formatted message in square - * braces. Unmatched placeholders will be left as-is. - * @param errorMessageArgs the arguments to be substituted into the message - * template. Arguments are converted to strings using - * {@link String#valueOf(Object)}. - * @return the non-null reference that was validated - * @throws NullPointerException if {@code reference} is null - */ - public static T checkNotNull(T reference, String errorMessageTemplate, - Object... errorMessageArgs) { - if (reference == null) { - // If either of these parameters is null, the right thing happens anyway - throw new NullPointerException( - format(errorMessageTemplate, errorMessageArgs)); - } - return reference; - } - - /** - * Ensures that an {@code Iterable} object passed as a parameter to the - * calling method is not null and contains no null elements. - * - * @param iterable the iterable to check the contents of - * @return the non-null {@code iterable} reference just validated - * @throws NullPointerException if {@code iterable} is null or contains at - * least one null element - */ - public static > T checkContentsNotNull(T iterable) { - if (containsOrIsNull(iterable)) { - throw new NullPointerException(); - } - return iterable; - } - - /** - * Ensures that an {@code Iterable} object passed as a parameter to the - * calling method is not null and contains no null elements. - * - * @param iterable the iterable to check the contents of - * @param errorMessage the exception message to use if the check fails; will - * be converted to a string using {@link String#valueOf(Object)} - * @return the non-null {@code iterable} reference just validated - * @throws NullPointerException if {@code iterable} is null or contains at - * least one null element - */ - public static > T checkContentsNotNull( - T iterable, Object errorMessage) { - if (containsOrIsNull(iterable)) { - throw new NullPointerException(String.valueOf(errorMessage)); - } - return iterable; - } - - /** - * Ensures that an {@code Iterable} object passed as a parameter to the - * calling method is not null and contains no null elements. - * - * @param iterable the iterable to check the contents of - * @param errorMessageTemplate a template for the exception message should the - * check fail. The message is formed by replacing each {@code %s} - * placeholder in the template with an argument. These are matched by - * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. - * Unmatched arguments will be appended to the formatted message in square - * braces. Unmatched placeholders will be left as-is. - * @param errorMessageArgs the arguments to be substituted into the message - * template. Arguments are converted to strings using - * {@link String#valueOf(Object)}. - * @return the non-null {@code iterable} reference just validated - * @throws NullPointerException if {@code iterable} is null or contains at - * least one null element - */ - public static > T checkContentsNotNull(T iterable, - String errorMessageTemplate, Object... errorMessageArgs) { - if (containsOrIsNull(iterable)) { - throw new NullPointerException( - format(errorMessageTemplate, errorMessageArgs)); - } - return iterable; - } - - private static boolean containsOrIsNull(Iterable iterable) { - if (iterable == null) { - return true; - } - - if (iterable instanceof Collection) { - Collection collection = (Collection) iterable; - try { - return collection.contains(null); - } catch (NullPointerException e) { - // A NPE implies that the collection doesn't contain null. - return false; - } - } else { - for (Object element : iterable) { - if (element == null) { - return true; - } - } - return false; - } - } - - /** - * Ensures that {@code index} specifies a valid element in an array, - * list or string of size {@code size}. An element index may range from zero, - * inclusive, to {@code size}, exclusive. - * - * @param index a user-supplied index identifying an element of an array, list - * or string - * @param size the size of that array, list or string - * @throws IndexOutOfBoundsException if {@code index} is negative or is not - * less than {@code size} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static void checkElementIndex(int index, int size) { - checkElementIndex(index, size, "index"); - } - - /** - * Ensures that {@code index} specifies a valid element in an array, - * list or string of size {@code size}. An element index may range from zero, - * inclusive, to {@code size}, exclusive. - * - * @param index a user-supplied index identifying an element of an array, list - * or string - * @param size the size of that array, list or string - * @param desc the text to use to describe this index in an error message - * @throws IndexOutOfBoundsException if {@code index} is negative or is not - * less than {@code size} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static void checkElementIndex(int index, int size, String desc) { - checkArgument(size >= 0, "negative size: %s", size); - if (index < 0) { - throw new IndexOutOfBoundsException( - format("%s (%s) must not be negative", desc, index)); - } - if (index >= size) { - throw new IndexOutOfBoundsException( - format("%s (%s) must be less than size (%s)", desc, index, size)); - } - } - - /** - * Ensures that {@code index} specifies a valid position in an array, - * list or string of size {@code size}. A position index may range from zero - * to {@code size}, inclusive. - * - * @param index a user-supplied index identifying a position in an array, list - * or string - * @param size the size of that array, list or string - * @throws IndexOutOfBoundsException if {@code index} is negative or is - * greater than {@code size} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static void checkPositionIndex(int index, int size) { - checkPositionIndex(index, size, "index"); - } - - /** - * Ensures that {@code index} specifies a valid position in an array, - * list or string of size {@code size}. A position index may range from zero - * to {@code size}, inclusive. - * - * @param index a user-supplied index identifying a position in an array, list - * or string - * @param size the size of that array, list or string - * @param desc the text to use to describe this index in an error message - * @throws IndexOutOfBoundsException if {@code index} is negative or is - * greater than {@code size} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static void checkPositionIndex(int index, int size, String desc) { - checkArgument(size >= 0, "negative size: %s", size); - if (index < 0) { - throw new IndexOutOfBoundsException(format( - "%s (%s) must not be negative", desc, index)); - } - if (index > size) { - throw new IndexOutOfBoundsException(format( - "%s (%s) must not be greater than size (%s)", desc, index, size)); - } - } - - /** - * Ensures that {@code start} and {@code end} specify a valid positions - * in an array, list or string of size {@code size}, and are in order. A - * position index may range from zero to {@code size}, inclusive. - * - * @param start a user-supplied index identifying a starting position in an - * array, list or string - * @param end a user-supplied index identifying a ending position in an array, - * list or string - * @param size the size of that array, list or string - * @throws IndexOutOfBoundsException if either index is negative or is - * greater than {@code size}, or if {@code end} is less than {@code start} - * @throws IllegalArgumentException if {@code size} is negative - */ - public static void checkPositionIndexes(int start, int end, int size) { - checkPositionIndex(start, size, "start index"); - checkPositionIndex(end, size, "end index"); - if (end < start) { - throw new IndexOutOfBoundsException(format( - "end index (%s) must not be less than start index (%s)", end, start)); - } - } - - /** - * Substitutes each {@code %s} in {@code template} with an argument. These - * are matched by position - the first {@code %s} gets {@code args[0]}, etc. - * If there are more arguments than placeholders, the unmatched arguments will - * be appended to the end of the formatted message in square braces. - * - * @param template a non-null string containing 0 or more {@code %s} - * placeholders. - * @param args the arguments to be substituted into the message - * template. Arguments are converted to strings using - * {@link String#valueOf(Object)}. Arguments can be null. - */ - // VisibleForTesting - static String format(String template, Object... args) { - // start substituting the arguments into the '%s' placeholders - StringBuilder builder = new StringBuilder( - template.length() + 16 * args.length); - int templateStart = 0; - int i = 0; - while (i < args.length) { - int placeholderStart = template.indexOf("%s", templateStart); - if (placeholderStart == -1) { - break; - } - builder.append(template.substring(templateStart, placeholderStart)); - builder.append(args[i++]); - templateStart = placeholderStart + 2; - } - builder.append(template.substring(templateStart)); - - // if we run out of placeholders, append the extra args in square braces - if (i < args.length) { - builder.append(" ["); - builder.append(args[i++]); - while (i < args.length) { - builder.append(", "); - builder.append(args[i++]); - } - builder.append("]"); - } - - return builder.toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/PrivateElementsImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/PrivateElementsImpl.java deleted file mode 100644 index bf2a40ea7fe..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/PrivateElementsImpl.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.PrivateBinder; -import org.elasticsearch.util.inject.spi.Element; -import org.elasticsearch.util.inject.spi.ElementVisitor; -import org.elasticsearch.util.inject.spi.PrivateElements; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * @author jessewilson@google.com (Jesse Wilson) - */ -public final class PrivateElementsImpl implements PrivateElements { - - /* - * This class acts as both a value object and as a builder. When getElements() is called, an - * immutable collection of elements is constructed and the original mutable list is nulled out. - * Similarly, the exposed keys are made immutable on access. - */ - - private final Object source; - - private List elementsMutable = Lists.newArrayList(); - private List> exposureBuilders = Lists.newArrayList(); - - /** lazily instantiated */ - private ImmutableList elements; - - /** lazily instantiated */ - private ImmutableMap, Object> exposedKeysToSources; - private Injector injector; - - public PrivateElementsImpl(Object source) { - this.source = checkNotNull(source, "source"); - } - - public Object getSource() { - return source; - } - - public List getElements() { - if (elements == null) { - elements = ImmutableList.copyOf(elementsMutable); - elementsMutable = null; - } - - return elements; - } - - public Injector getInjector() { - return injector; - } - - public void initInjector(Injector injector) { - checkState(this.injector == null, "injector already initialized"); - this.injector = checkNotNull(injector, "injector"); - } - - public Set> getExposedKeys() { - if (exposedKeysToSources == null) { - Map, Object> exposedKeysToSourcesMutable = Maps.newLinkedHashMap(); - for (ExposureBuilder exposureBuilder : exposureBuilders) { - exposedKeysToSourcesMutable.put(exposureBuilder.getKey(), exposureBuilder.getSource()); - } - exposedKeysToSources = ImmutableMap.copyOf(exposedKeysToSourcesMutable); - exposureBuilders = null; - } - - return exposedKeysToSources.keySet(); - } - - public T acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } - - public List getElementsMutable() { - return elementsMutable; - } - - public void addExposureBuilder(ExposureBuilder exposureBuilder) { - exposureBuilders.add(exposureBuilder); - } - - public void applyTo(Binder binder) { - PrivateBinder privateBinder = binder.withSource(source).newPrivateBinder(); - - for (Element element : getElements()) { - element.applyTo(privateBinder); - } - - getExposedKeys(); // ensure exposedKeysToSources is populated - for (Map.Entry, Object> entry : exposedKeysToSources.entrySet()) { - privateBinder.withSource(entry.getValue()).expose(entry.getKey()); - } - } - - public Object getExposedSource(Key key) { - getExposedKeys(); // ensure exposedKeysToSources is populated - Object source = exposedKeysToSources.get(key); - checkArgument(source != null, "%s not exposed by %s.", key, this); - return source; - } - - @Override public String toString() { - return new ToStringBuilder(PrivateElements.class) - .add("exposedKeys", getExposedKeys()) - .add("source", getSource()) - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderInstanceBindingImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderInstanceBindingImpl.java deleted file mode 100644 index 8f8732baee5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderInstanceBindingImpl.java +++ /dev/null @@ -1,92 +0,0 @@ -/* -Copyright (C) 2007 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Provider; -import org.elasticsearch.util.inject.spi.*; - -import java.util.Set; - -public final class ProviderInstanceBindingImpl extends BindingImpl - implements ProviderInstanceBinding { - - final Provider providerInstance; - final ImmutableSet injectionPoints; - - public ProviderInstanceBindingImpl(Injector injector, Key key, - Object source, InternalFactory internalFactory, Scoping scoping, - Provider providerInstance, - Set injectionPoints) { - super(injector, key, source, internalFactory, scoping); - this.providerInstance = providerInstance; - this.injectionPoints = ImmutableSet.copyOf(injectionPoints); - } - - public ProviderInstanceBindingImpl(Object source, Key key, Scoping scoping, - Set injectionPoints, Provider providerInstance) { - super(source, key, scoping); - this.injectionPoints = ImmutableSet.copyOf(injectionPoints); - this.providerInstance = providerInstance; - } - - public V acceptTargetVisitor(BindingTargetVisitor visitor) { - return visitor.visit(this); - } - - public Provider getProviderInstance() { - return providerInstance; - } - - public Set getInjectionPoints() { - return injectionPoints; - } - - public Set> getDependencies() { - return providerInstance instanceof HasDependencies - ? ImmutableSet.copyOf(((HasDependencies) providerInstance).getDependencies()) - : Dependency.forInjectionPoints(injectionPoints); - } - - public BindingImpl withScoping(Scoping scoping) { - return new ProviderInstanceBindingImpl( - getSource(), getKey(), scoping, injectionPoints, providerInstance); - } - - public BindingImpl withKey(Key key) { - return new ProviderInstanceBindingImpl( - getSource(), key, getScoping(), injectionPoints, providerInstance); - } - - public void applyTo(Binder binder) { - getScoping().applyTo( - binder.withSource(getSource()).bind(getKey()).toProvider(getProviderInstance())); - } - - @Override - public String toString() { - return new ToStringBuilder(ProviderInstanceBinding.class) - .add("key", getKey()) - .add("source", getSource()) - .add("scope", getScoping()) - .add("provider", providerInstance) - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderMethod.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderMethod.java deleted file mode 100644 index 7e7df86aec1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderMethod.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.ProviderWithDependencies; - -import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.List; -import java.util.Set; - -/** - * A provider that invokes a method and returns its result. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public class ProviderMethod implements ProviderWithDependencies { - private final Key key; - private final Class scopeAnnotation; - private final Object instance; - private final Method method; - private final ImmutableSet> dependencies; - private final List> parameterProviders; - private final boolean exposed; - - /** - * @param method the method to invoke. It's return type must be the same type as {@code key}. - */ - ProviderMethod(Key key, Method method, Object instance, - ImmutableSet> dependencies, List> parameterProviders, - Class scopeAnnotation) { - this.key = key; - this.scopeAnnotation = scopeAnnotation; - this.instance = instance; - this.dependencies = dependencies; - this.method = method; - this.parameterProviders = parameterProviders; - this.exposed = method.isAnnotationPresent(Exposed.class); - - method.setAccessible(true); - } - - public Key getKey() { - return key; - } - - public Method getMethod() { - return method; - } - - // exposed for GIN - public Object getInstance() { - return instance; - } - - public void configure(Binder binder) { - binder = binder.withSource(method); - - if (scopeAnnotation != null) { - binder.bind(key).toProvider(this).in(scopeAnnotation); - } else { - binder.bind(key).toProvider(this); - } - - if (exposed) { - // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a - // misplaced @Exposed, calling this will add an error to the binder's error queue - ((PrivateBinder) binder).expose(key); - } - } - - public T get() { - Object[] parameters = new Object[parameterProviders.size()]; - for (int i = 0; i < parameters.length; i++) { - parameters[i] = parameterProviders.get(i).get(); - } - - try { - // We know this cast is safe becase T is the method's return type. - @SuppressWarnings({ "unchecked", "UnnecessaryLocalVariable" }) - T result = (T) method.invoke(instance, parameters); - return result; - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - public Set> getDependencies() { - return dependencies; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderMethodsModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderMethodsModule.java deleted file mode 100644 index 1ea75dc1a88..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ProviderMethodsModule.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.Message; -import org.elasticsearch.util.inject.util.Modules; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.util.List; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Creates bindings to methods annotated with {@literal @}{@link Provides}. Use the scope and - * binding annotations on the provider method to configure the binding. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - */ -public final class ProviderMethodsModule implements Module { - private final Object delegate; - private final TypeLiteral typeLiteral; - - private ProviderMethodsModule(Object delegate) { - this.delegate = checkNotNull(delegate, "delegate"); - this.typeLiteral = TypeLiteral.get(this.delegate.getClass()); - } - - /** - * Returns a module which creates bindings for provider methods from the given module. - */ - public static Module forModule(Module module) { - return forObject(module); - } - - /** - * Returns a module which creates bindings for provider methods from the given object. - * This is useful notably for GIN - */ - public static Module forObject(Object object) { - // avoid infinite recursion, since installing a module always installs itself - if (object instanceof ProviderMethodsModule) { - return Modules.EMPTY_MODULE; - } - - return new ProviderMethodsModule(object); - } - public synchronized void configure(Binder binder) { - for (ProviderMethod providerMethod : getProviderMethods(binder)) { - providerMethod.configure(binder); - } - } - - public List> getProviderMethods(Binder binder) { - List> result = Lists.newArrayList(); - for (Class c = delegate.getClass(); c != Object.class; c = c.getSuperclass()) { - for (Method method : c.getDeclaredMethods()) { - if (method.isAnnotationPresent(Provides.class)) { - result.add(createProviderMethod(binder, method)); - } - } - } - return result; - } - - ProviderMethod createProviderMethod(Binder binder, final Method method) { - binder = binder.withSource(method); - Errors errors = new Errors(method); - - // prepare the parameter providers - List> dependencies = Lists.newArrayList(); - List> parameterProviders = Lists.newArrayList(); - List> parameterTypes = typeLiteral.getParameterTypes(method); - Annotation[][] parameterAnnotations = method.getParameterAnnotations(); - for (int i = 0; i < parameterTypes.size(); i++) { - Key key = getKey(errors, parameterTypes.get(i), method, parameterAnnotations[i]); - dependencies.add(Dependency.get(key)); - parameterProviders.add(binder.getProvider(key)); - } - - @SuppressWarnings("unchecked") // Define T as the method's return type. - TypeLiteral returnType = (TypeLiteral) typeLiteral.getReturnType(method); - - Key key = getKey(errors, returnType, method, method.getAnnotations()); - Class scopeAnnotation - = Annotations.findScopeAnnotation(errors, method.getAnnotations()); - - for (Message message : errors.getMessages()) { - binder.addError(message); - } - - return new ProviderMethod(key, method, delegate, ImmutableSet.copyOf(dependencies), - parameterProviders, scopeAnnotation); - } - - Key getKey(Errors errors, TypeLiteral type, Member member, Annotation[] annotations) { - Annotation bindingAnnotation = Annotations.findBindingAnnotation(errors, member, annotations); - return bindingAnnotation == null ? Key.get(type) : Key.get(type, bindingAnnotation); - } - - @Override public boolean equals(Object o) { - return o instanceof ProviderMethodsModule - && ((ProviderMethodsModule) o).delegate == delegate; - } - - @Override public int hashCode() { - return delegate.hashCode(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Scoping.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Scoping.java deleted file mode 100644 index 3c5b11c2bc4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Scoping.java +++ /dev/null @@ -1,209 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.Scope; -import org.elasticsearch.util.inject.Scopes; -import org.elasticsearch.util.inject.Singleton; -import org.elasticsearch.util.inject.Stage; -import org.elasticsearch.util.inject.binder.ScopedBindingBuilder; -import org.elasticsearch.util.inject.spi.BindingScopingVisitor; -import java.lang.annotation.Annotation; - -/** - * References a scope, either directly (as a scope instance), or indirectly (as a scope annotation). - * The scope's eager or laziness is also exposed. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public abstract class Scoping { - - /** - * No scoping annotation has been applied. Note that this is different from {@code - * in(Scopes.NO_SCOPE)}, where the 'NO_SCOPE' has been explicitly applied. - */ - public static final Scoping UNSCOPED = new Scoping() { - public V acceptVisitor(BindingScopingVisitor visitor) { - return visitor.visitNoScoping(); - } - - @Override public Scope getScopeInstance() { - return Scopes.NO_SCOPE; - } - - @Override public String toString() { - return Scopes.NO_SCOPE.toString(); - } - - public void applyTo(ScopedBindingBuilder scopedBindingBuilder) { - // do nothing - } - }; - - public static final Scoping SINGLETON_ANNOTATION = new Scoping() { - public V acceptVisitor(BindingScopingVisitor visitor) { - return visitor.visitScopeAnnotation(Singleton.class); - } - - @Override public Class getScopeAnnotation() { - return Singleton.class; - } - - @Override public String toString() { - return Singleton.class.getName(); - } - - public void applyTo(ScopedBindingBuilder scopedBindingBuilder) { - scopedBindingBuilder.in(Singleton.class); - } - }; - - public static final Scoping SINGLETON_INSTANCE = new Scoping() { - public V acceptVisitor(BindingScopingVisitor visitor) { - return visitor.visitScope(Scopes.SINGLETON); - } - - @Override public Scope getScopeInstance() { - return Scopes.SINGLETON; - } - - @Override public String toString() { - return Scopes.SINGLETON.toString(); - } - - public void applyTo(ScopedBindingBuilder scopedBindingBuilder) { - scopedBindingBuilder.in(Scopes.SINGLETON); - } - }; - - public static final Scoping EAGER_SINGLETON = new Scoping() { - public V acceptVisitor(BindingScopingVisitor visitor) { - return visitor.visitEagerSingleton(); - } - - @Override public Scope getScopeInstance() { - return Scopes.SINGLETON; - } - - @Override public String toString() { - return "eager singleton"; - } - - public void applyTo(ScopedBindingBuilder scopedBindingBuilder) { - scopedBindingBuilder.asEagerSingleton(); - } - }; - - public static Scoping forAnnotation(final Class scopingAnnotation) { - if (scopingAnnotation == Singleton.class) { - return SINGLETON_ANNOTATION; - } - - return new Scoping() { - public V acceptVisitor(BindingScopingVisitor visitor) { - return visitor.visitScopeAnnotation(scopingAnnotation); - } - - @Override public Class getScopeAnnotation() { - return scopingAnnotation; - } - - @Override public String toString() { - return scopingAnnotation.getName(); - } - - public void applyTo(ScopedBindingBuilder scopedBindingBuilder) { - scopedBindingBuilder.in(scopingAnnotation); - } - }; - } - - public static Scoping forInstance(final Scope scope) { - if (scope == Scopes.SINGLETON) { - return SINGLETON_INSTANCE; - } - - return new Scoping() { - public V acceptVisitor(BindingScopingVisitor visitor) { - return visitor.visitScope(scope); - } - - @Override public Scope getScopeInstance() { - return scope; - } - - @Override public String toString() { - return scope.toString(); - } - - public void applyTo(ScopedBindingBuilder scopedBindingBuilder) { - scopedBindingBuilder.in(scope); - } - }; - } - - /** - * Returns true if this scope was explicitly applied. If no scope was explicitly applied then the - * scoping annotation will be used. - */ - public boolean isExplicitlyScoped() { - return this != UNSCOPED; - } - - /** - * Returns true if this is the default scope. In this case a new instance will be provided for - * each injection. - */ - public boolean isNoScope() { - return getScopeInstance() == Scopes.NO_SCOPE; - } - - /** - * Returns true if this scope is a singleton that should be loaded eagerly in {@code stage}. - */ - public boolean isEagerSingleton(Stage stage) { - if (this == EAGER_SINGLETON) { - return true; - } - - if (stage == Stage.PRODUCTION) { - return this == SINGLETON_ANNOTATION || this == SINGLETON_INSTANCE; - } - - return false; - } - - /** - * Returns the scope instance, or {@code null} if that isn't known for this instance. - */ - public Scope getScopeInstance() { - return null; - } - - /** - * Returns the scope annotation, or {@code null} if that isn't known for this instance. - */ - public Class getScopeAnnotation() { - return null; - } - - public abstract V acceptVisitor(BindingScopingVisitor visitor); - - public abstract void applyTo(ScopedBindingBuilder scopedBindingBuilder); - - private Scoping() {} -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/SourceProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/SourceProvider.java deleted file mode 100644 index b5275e38578..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/SourceProvider.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; - -import java.util.List; - -import static org.elasticsearch.util.collect.Iterables.*; - -/** - * Provides access to the calling line of code. - * - * @author crazybob@google.com (Bob Lee) - */ -public class SourceProvider { - - /** Indicates that the source is unknown. */ - public static final Object UNKNOWN_SOURCE = "[unknown source]"; - - private final ImmutableSet classNamesToSkip; - - public SourceProvider() { - this.classNamesToSkip = ImmutableSet.of(SourceProvider.class.getName()); - } - - public static final SourceProvider DEFAULT_INSTANCE - = new SourceProvider(ImmutableSet.of(SourceProvider.class.getName())); - - private SourceProvider(Iterable classesToSkip) { - this.classNamesToSkip = ImmutableSet.copyOf(classesToSkip); - } - - /** Returns a new instance that also skips {@code moreClassesToSkip}. */ - public SourceProvider plusSkippedClasses(Class... moreClassesToSkip) { - return new SourceProvider(concat(classNamesToSkip, asStrings(moreClassesToSkip))); - } - - /** Returns the class names as Strings */ - private static List asStrings(Class... classes) { - List strings = Lists.newArrayList(); - for (Class c : classes) { - strings.add(c.getName()); - } - return strings; - } - - /** - * Returns the calling line of code. The selected line is the nearest to the top of the stack that - * is not skipped. - */ - public StackTraceElement get() { - for (final StackTraceElement element : new Throwable().getStackTrace()) { - String className = element.getClassName(); - if (!classNamesToSkip.contains(className)) { - return element; - } - } - throw new AssertionError(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/StackTraceElements.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/StackTraceElements.java deleted file mode 100644 index 3096d17b6d7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/StackTraceElements.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Member; - -/** - * Creates stack trace elements for members. - * - * @author crazybob@google.com (Bob Lee) - */ -public class StackTraceElements { - - public static Object forMember(Member member) { - if (member == null) { - return SourceProvider.UNKNOWN_SOURCE; - } - - Class declaringClass = member.getDeclaringClass(); - - String fileName = null; - int lineNumber = -1; - - Class memberType = MoreTypes.memberType(member); - String memberName = memberType == Constructor.class ? "" : member.getName(); - return new StackTraceElement(declaringClass.getName(), memberName, fileName, lineNumber); - } - - public static Object forType(Class implementation) { - String fileName = null; - int lineNumber = -1; - - return new StackTraceElement(implementation.getName(), "class", fileName, lineNumber); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Stopwatch.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Stopwatch.java deleted file mode 100644 index 71d63cf76c7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Stopwatch.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import java.util.logging.Logger; - -/** - * Enables simple performance monitoring. - * - * @author crazybob@google.com (Bob Lee) - */ -public class Stopwatch { - private static final Logger logger = Logger.getLogger(Stopwatch.class.getName()); - - private long start = System.currentTimeMillis(); - - /** - * Resets and returns elapsed time in milliseconds. - */ - public long reset() { - long now = System.currentTimeMillis(); - try { - return now - start; - } finally { - start = now; - } - } - - /** - * Resets and logs elapsed time in milliseconds. - */ - public void resetAndLog(String label) { - logger.fine(label + ": " + reset() + "ms"); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Strings.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Strings.java deleted file mode 100644 index 92fff198c0b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/Strings.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -/** - * String utilities. - * - * @author crazybob@google.com (Bob Lee) - */ -public class Strings { - private Strings() {} - - /** - * Returns a string that is equivalent to the specified string with its - * first character converted to uppercase as by {@link String#toUpperCase}. - * The returned string will have the same value as the specified string if - * its first character is non-alphabetic, if its first character is already - * uppercase, or if the specified string is of length 0. - * - *

For example: - *

-   *    capitalize("foo bar").equals("Foo bar");
-   *    capitalize("2b or not 2b").equals("2b or not 2b")
-   *    capitalize("Foo bar").equals("Foo bar");
-   *    capitalize("").equals("");
-   * 
- * - * @param s the string whose first character is to be uppercased - * @return a string equivalent to s with its first character - * converted to uppercase - * @throws NullPointerException if s is null - */ - public static String capitalize(String s) { - if (s.length() == 0) { - return s; - } - char first = s.charAt(0); - char capitalized = Character.toUpperCase(first); - return (first == capitalized) - ? s - : capitalized + s.substring(1); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ToStringBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ToStringBuilder.java deleted file mode 100644 index ab701c28c85..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/ToStringBuilder.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Helps with {@code toString()} methods. - * - * @author crazybob@google.com (Bob Lee) - */ -public class ToStringBuilder { - - // Linked hash map ensures ordering. - final Map map = new LinkedHashMap(); - - final String name; - - public ToStringBuilder(String name) { - this.name = name; - } - - public ToStringBuilder(Class type) { - this.name = type.getSimpleName(); - } - - public ToStringBuilder add(String name, Object value) { - if (map.put(name, value) != null) { - throw new RuntimeException("Duplicate names: " + name); - } - return this; - } - - @Override public String toString() { - return name + map.toString().replace('{', '[').replace('}', ']'); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UniqueAnnotations.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UniqueAnnotations.java deleted file mode 100644 index 1943402039c..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UniqueAnnotations.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.BindingAnnotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author jessewilson@google.com (Jesse Wilson) - */ -public class UniqueAnnotations { - private UniqueAnnotations() {} - private static final AtomicInteger nextUniqueValue = new AtomicInteger(1); - - /** - * Returns an annotation instance that is not equal to any other annotation - * instances, for use in creating distinct {@link org.elasticsearch.util.inject.Key}s. - */ - public static Annotation create() { - return create(nextUniqueValue.getAndIncrement()); - } - - static Annotation create(final int value) { - return new Internal() { - public int value() { - return value; - } - - public Class annotationType() { - return Internal.class; - } - - @Override public String toString() { - return "@" + Internal.class.getName() + "(value=" + value + ")"; - } - - @Override public boolean equals(Object o) { - return o instanceof Internal - && ((Internal) o).value() == value(); - } - - @Override public int hashCode() { - return (127 * "value".hashCode()) ^ value; - } - }; - } - - @Retention(RUNTIME) @BindingAnnotation - @interface Internal { - int value(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UnmodifiableIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UnmodifiableIterator.java deleted file mode 100644 index d79013232fd..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UnmodifiableIterator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import java.util.Iterator; - -/** - * An iterator that does not support {@link #remove}. - * - * @author Jared Levy - */ -public abstract class UnmodifiableIterator implements Iterator { - - /** - * Guaranteed to throw an exception and leave the underlying data unmodified. - * - * @throws UnsupportedOperationException always - */ - public final void remove() { - throw new UnsupportedOperationException(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UntargettedBindingImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UntargettedBindingImpl.java deleted file mode 100644 index 73ba352f22e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/UntargettedBindingImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.internal; - -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.spi.BindingTargetVisitor; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.UntargettedBinding; - -public class UntargettedBindingImpl extends BindingImpl implements UntargettedBinding { - - public UntargettedBindingImpl(Injector injector, Key key, Object source) { - super(injector, key, source, new InternalFactory() { - public T get(Errors errors, InternalContext context, Dependency dependency) { - throw new AssertionError(); - } - }, Scoping.UNSCOPED); - } - - public UntargettedBindingImpl(Object source, Key key, Scoping scoping) { - super(source, key, scoping); - } - - public V acceptTargetVisitor(BindingTargetVisitor visitor) { - return visitor.visit(this); - } - - public BindingImpl withScoping(Scoping scoping) { - return new UntargettedBindingImpl(getSource(), getKey(), scoping); - } - - public BindingImpl withKey(Key key) { - return new UntargettedBindingImpl(getSource(), key, getScoping()); - } - - public void applyTo(Binder binder) { - getScoping().applyTo(binder.withSource(getSource()).bind(getKey())); - } - - @Override public String toString() { - return new ToStringBuilder(UntargettedBinding.class) - .add("key", getKey()) - .add("source", getSource()) - .toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/package-info.java deleted file mode 100644 index 0a8aba72307..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/internal/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Guice (sounds like like "juice") - */ - -package org.elasticsearch.util.inject.internal; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/AbstractMatcher.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/AbstractMatcher.java deleted file mode 100644 index 7f3ec4bf595..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/AbstractMatcher.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.matcher; - -import java.io.Serializable; - -/** - * Implements {@code and()} and {@code or()}. - * - * @author crazybob@google.com (Bob Lee) - */ -public abstract class AbstractMatcher implements Matcher { - - public Matcher and(final Matcher other) { - return new AndMatcher(this, other); - } - - public Matcher or(Matcher other) { - return new OrMatcher(this, other); - } - - private static class AndMatcher extends AbstractMatcher implements Serializable { - private final Matcher a, b; - - public AndMatcher(Matcher a, Matcher b) { - this.a = a; - this.b = b; - } - - public boolean matches(T t) { - return a.matches(t) && b.matches(t); - } - - @Override public boolean equals(Object other) { - return other instanceof AndMatcher - && ((AndMatcher) other).a.equals(a) - && ((AndMatcher) other).b.equals(b); - } - - @Override public int hashCode() { - return 41 * (a.hashCode() ^ b.hashCode()); - } - - @Override public String toString() { - return "and(" + a + ", " + b + ")"; - } - - private static final long serialVersionUID = 0; - } - - private static class OrMatcher extends AbstractMatcher implements Serializable { - private final Matcher a, b; - - public OrMatcher(Matcher a, Matcher b) { - this.a = a; - this.b = b; - } - - public boolean matches(T t) { - return a.matches(t) || b.matches(t); - } - - @Override public boolean equals(Object other) { - return other instanceof OrMatcher - && ((OrMatcher) other).a.equals(a) - && ((OrMatcher) other).b.equals(b); - } - - @Override public int hashCode() { - return 37 * (a.hashCode() ^ b.hashCode()); - } - - @Override public String toString() { - return "or(" + a + ", " + b + ")"; - } - - private static final long serialVersionUID = 0; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/Matcher.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/Matcher.java deleted file mode 100644 index 3d00653dbb9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/Matcher.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.matcher; - -/** - * Returns {@code true} or {@code false} for a given input. - * - * @author crazybob@google.com (Bob Lee) - */ -public interface Matcher { - - /** - * Returns {@code true} if this matches {@code t}, {@code false} otherwise. - */ - boolean matches(T t); - - /** - * Returns a new matcher which returns {@code true} if both this and the - * given matcher return {@code true}. - */ - Matcher and(Matcher other); - - /** - * Returns a new matcher which returns {@code true} if either this or the - * given matcher return {@code true}. - */ - Matcher or(Matcher other); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/Matchers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/Matchers.java deleted file mode 100644 index 6aac5f13d93..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/Matchers.java +++ /dev/null @@ -1,399 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.matcher; - -import static org.elasticsearch.util.inject.internal.Preconditions.checkArgument; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import java.io.Serializable; -import java.lang.annotation.Annotation; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Method; - -/** - * Matcher implementations. Supports matching classes and methods. - * - * @author crazybob@google.com (Bob Lee) - */ -public class Matchers { - private Matchers() {} - - /** - * Returns a matcher which matches any input. - */ - public static Matcher any() { - return ANY; - } - - private static final Matcher ANY = new Any(); - - private static class Any extends AbstractMatcher implements Serializable { - public boolean matches(Object o) { - return true; - } - - @Override public String toString() { - return "any()"; - } - - public Object readResolve() { - return any(); - } - - private static final long serialVersionUID = 0; - } - - /** - * Inverts the given matcher. - */ - public static Matcher not(final Matcher p) { - return new Not(p); - } - - private static class Not extends AbstractMatcher implements Serializable { - final Matcher delegate; - - private Not(Matcher delegate) { - this.delegate = checkNotNull(delegate, "delegate"); - } - - public boolean matches(T t) { - return !delegate.matches(t); - } - - @Override public boolean equals(Object other) { - return other instanceof Not - && ((Not) other).delegate.equals(delegate); - } - - @Override public int hashCode() { - return -delegate.hashCode(); - } - - @Override public String toString() { - return "not(" + delegate + ")"; - } - - private static final long serialVersionUID = 0; - } - - private static void checkForRuntimeRetention( - Class annotationType) { - Retention retention = annotationType.getAnnotation(Retention.class); - checkArgument(retention != null && retention.value() == RetentionPolicy.RUNTIME, - "Annotation " + annotationType.getSimpleName() + " is missing RUNTIME retention"); - } - - /** - * Returns a matcher which matches elements (methods, classes, etc.) - * with a given annotation. - */ - public static Matcher annotatedWith( - final Class annotationType) { - return new AnnotatedWithType(annotationType); - } - - private static class AnnotatedWithType extends AbstractMatcher - implements Serializable { - private final Class annotationType; - - public AnnotatedWithType(Class annotationType) { - this.annotationType = checkNotNull(annotationType, "annotation type"); - checkForRuntimeRetention(annotationType); - } - - public boolean matches(AnnotatedElement element) { - return element.getAnnotation(annotationType) != null; - } - - @Override public boolean equals(Object other) { - return other instanceof AnnotatedWithType - && ((AnnotatedWithType) other).annotationType.equals(annotationType); - } - - @Override public int hashCode() { - return 37 * annotationType.hashCode(); - } - - @Override public String toString() { - return "annotatedWith(" + annotationType.getSimpleName() + ".class)"; - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a matcher which matches elements (methods, classes, etc.) - * with a given annotation. - */ - public static Matcher annotatedWith( - final Annotation annotation) { - return new AnnotatedWith(annotation); - } - - private static class AnnotatedWith extends AbstractMatcher - implements Serializable { - private final Annotation annotation; - - public AnnotatedWith(Annotation annotation) { - this.annotation = checkNotNull(annotation, "annotation"); - checkForRuntimeRetention(annotation.annotationType()); - } - - public boolean matches(AnnotatedElement element) { - Annotation fromElement = element.getAnnotation(annotation.annotationType()); - return fromElement != null && annotation.equals(fromElement); - } - - @Override public boolean equals(Object other) { - return other instanceof AnnotatedWith - && ((AnnotatedWith) other).annotation.equals(annotation); - } - - @Override public int hashCode() { - return 37 * annotation.hashCode(); - } - - @Override public String toString() { - return "annotatedWith(" + annotation + ")"; - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a matcher which matches subclasses of the given type (as well as - * the given type). - */ - public static Matcher subclassesOf(final Class superclass) { - return new SubclassesOf(superclass); - } - - private static class SubclassesOf extends AbstractMatcher - implements Serializable { - private final Class superclass; - - public SubclassesOf(Class superclass) { - this.superclass = checkNotNull(superclass, "superclass"); - } - - public boolean matches(Class subclass) { - return superclass.isAssignableFrom(subclass); - } - - @Override public boolean equals(Object other) { - return other instanceof SubclassesOf - && ((SubclassesOf) other).superclass.equals(superclass); - } - - @Override public int hashCode() { - return 37 * superclass.hashCode(); - } - - @Override public String toString() { - return "subclassesOf(" + superclass.getSimpleName() + ".class)"; - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a matcher which matches objects equal to the given object. - */ - public static Matcher only(Object value) { - return new Only(value); - } - - private static class Only extends AbstractMatcher - implements Serializable { - private final Object value; - - public Only(Object value) { - this.value = checkNotNull(value, "value"); - } - - public boolean matches(Object other) { - return value.equals(other); - } - - @Override public boolean equals(Object other) { - return other instanceof Only - && ((Only) other).value.equals(value); - } - - @Override public int hashCode() { - return 37 * value.hashCode(); - } - - @Override public String toString() { - return "only(" + value + ")"; - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a matcher which matches only the given object. - */ - public static Matcher identicalTo(final Object value) { - return new IdenticalTo(value); - } - - private static class IdenticalTo extends AbstractMatcher - implements Serializable { - private final Object value; - - public IdenticalTo(Object value) { - this.value = checkNotNull(value, "value"); - } - - public boolean matches(Object other) { - return value == other; - } - - @Override public boolean equals(Object other) { - return other instanceof IdenticalTo - && ((IdenticalTo) other).value == value; - } - - @Override public int hashCode() { - return 37 * System.identityHashCode(value); - } - - @Override public String toString() { - return "identicalTo(" + value + ")"; - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a matcher which matches classes in the given package. Packages are specific to their - * classloader, so classes with the same package name may not have the same package at runtime. - */ - public static Matcher inPackage(final Package targetPackage) { - return new InPackage(targetPackage); - } - - private static class InPackage extends AbstractMatcher implements Serializable { - private final transient Package targetPackage; - private final String packageName; - - public InPackage(Package targetPackage) { - this.targetPackage = checkNotNull(targetPackage, "package"); - this.packageName = targetPackage.getName(); - } - - public boolean matches(Class c) { - return c.getPackage().equals(targetPackage); - } - - @Override public boolean equals(Object other) { - return other instanceof InPackage - && ((InPackage) other).targetPackage.equals(targetPackage); - } - - @Override public int hashCode() { - return 37 * targetPackage.hashCode(); - } - - @Override public String toString() { - return "inPackage(" + targetPackage.getName() + ")"; - } - - public Object readResolve() { - return inPackage(Package.getPackage(packageName)); - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a matcher which matches classes in the given package and its subpackages. Unlike - * {@link #inPackage(Package) inPackage()}, this matches classes from any classloader. - * - * @since 2.0 - */ - public static Matcher inSubpackage(final String targetPackageName) { - return new InSubpackage(targetPackageName); - } - - private static class InSubpackage extends AbstractMatcher implements Serializable { - private final String targetPackageName; - - public InSubpackage(String targetPackageName) { - this.targetPackageName = targetPackageName; - } - - public boolean matches(Class c) { - String classPackageName = c.getPackage().getName(); - return classPackageName.equals(targetPackageName) - || classPackageName.startsWith(targetPackageName + "."); - } - - @Override public boolean equals(Object other) { - return other instanceof InSubpackage - && ((InSubpackage) other).targetPackageName.equals(targetPackageName); - } - - @Override public int hashCode() { - return 37 * targetPackageName.hashCode(); - } - - @Override public String toString() { - return "inSubpackage(" + targetPackageName + ")"; - } - - private static final long serialVersionUID = 0; - } - - /** - * Returns a matcher which matches methods with matching return types. - */ - public static Matcher returns( - final Matcher> returnType) { - return new Returns(returnType); - } - - private static class Returns extends AbstractMatcher implements Serializable { - private final Matcher> returnType; - - public Returns(Matcher> returnType) { - this.returnType = checkNotNull(returnType, "return type matcher"); - } - - public boolean matches(Method m) { - return returnType.matches(m.getReturnType()); - } - - @Override public boolean equals(Object other) { - return other instanceof Returns - && ((Returns) other).returnType.equals(returnType); - } - - @Override public int hashCode() { - return 37 * returnType.hashCode(); - } - - @Override public String toString() { - return "returns(" + returnType + ")"; - } - - private static final long serialVersionUID = 0; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/package-info.java deleted file mode 100644 index 677807d92d4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/matcher/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Used for matching things. Primarily used to pick out methods to which to - * apply interceptors. - */ -package org.elasticsearch.util.inject.matcher; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/Element.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/Element.java deleted file mode 100644 index a315bf2fcce..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/Element.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.elasticsearch.util.inject.multibindings; - -import org.elasticsearch.util.inject.BindingAnnotation; - -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * An internal binding annotation applied to each element in a multibinding. - * All elements are assigned a globally-unique id to allow different modules - * to contribute multibindings independently. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -@Retention(RUNTIME) @BindingAnnotation -@interface Element { - String setName(); - int uniqueId(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/MapBinder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/MapBinder.java deleted file mode 100644 index 738bcc74b63..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/MapBinder.java +++ /dev/null @@ -1,365 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.multibindings; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.binder.LinkedBindingBuilder; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.ProviderWithDependencies; -import org.elasticsearch.util.inject.util.Types; - -import java.lang.annotation.Annotation; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import static org.elasticsearch.util.inject.multibindings.Multibinder.*; -import static org.elasticsearch.util.inject.util.Types.*; - -/** - * An API to bind multiple map entries separately, only to later inject them as - * a complete map. MapBinder is intended for use in your application's module: - *

- * public class SnacksModule extends AbstractModule {
- *   protected void configure() {
- *     MapBinder<String, Snack> mapbinder
- *         = MapBinder.newMapBinder(binder(), String.class, Snack.class);
- *     mapbinder.addBinding("twix").toInstance(new Twix());
- *     mapbinder.addBinding("snickers").toProvider(SnickersProvider.class);
- *     mapbinder.addBinding("skittles").to(Skittles.class);
- *   }
- * }
- * - *

With this binding, a {@link Map}{@code } can now be - * injected: - *


- * class SnackMachine {
- *   {@literal @}Inject
- *   public SnackMachine(Map<String, Snack> snacks) { ... }
- * }
- * - *

In addition to binding {@code Map}, a mapbinder will also bind - * {@code Map>} for lazy value provision: - *


- * class SnackMachine {
- *   {@literal @}Inject
- *   public SnackMachine(Map<String, Provider<Snack>> snackProviders) { ... }
- * }
- * - *

Creating mapbindings from different modules is supported. For example, it - * is okay to have both {@code CandyModule} and {@code ChipsModule} both - * create their own {@code MapBinder}, and to each contribute - * bindings to the snacks map. When that map is injected, it will contain - * entries from both modules. - * - *

Values are resolved at map injection time. If a value is bound to a - * provider, that provider's get method will be called each time the map is - * injected (unless the binding is also scoped, or a map of providers is injected). - * - *

Annotations are used to create different maps of the same key/value - * type. Each distinct annotation gets its own independent map. - * - *

Keys must be distinct. If the same key is bound more than - * once, map injection will fail. - * - *

Keys must be non-null. {@code addBinding(null)} will - * throw an unchecked exception. - * - *

Values must be non-null to use map injection. If any - * value is null, map injection will fail (although injecting a map of providers - * will not). - * - * @author dpb@google.com (David P. Baker) - */ -public abstract class MapBinder { - private MapBinder() {} - - /** - * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a - * {@link Map} that is itself bound with no binding annotation. - */ - public static MapBinder newMapBinder(Binder binder, - TypeLiteral keyType, TypeLiteral valueType) { - binder = binder.skipSources(MapBinder.class, RealMapBinder.class); - return newMapBinder(binder, valueType, - Key.get(mapOf(keyType, valueType)), - Key.get(mapOfProviderOf(keyType, valueType)), - Multibinder.newSetBinder(binder, entryOfProviderOf(keyType, valueType))); - } - - /** - * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a - * {@link Map} that is itself bound with no binding annotation. - */ - public static MapBinder newMapBinder(Binder binder, - Class keyType, Class valueType) { - return newMapBinder(binder, TypeLiteral.get(keyType), TypeLiteral.get(valueType)); - } - - /** - * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a - * {@link Map} that is itself bound with {@code annotation}. - */ - public static MapBinder newMapBinder(Binder binder, - TypeLiteral keyType, TypeLiteral valueType, Annotation annotation) { - binder = binder.skipSources(MapBinder.class, RealMapBinder.class); - return newMapBinder(binder, valueType, - Key.get(mapOf(keyType, valueType), annotation), - Key.get(mapOfProviderOf(keyType, valueType), annotation), - Multibinder.newSetBinder(binder, entryOfProviderOf(keyType, valueType), annotation)); - } - - /** - * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a - * {@link Map} that is itself bound with {@code annotation}. - */ - public static MapBinder newMapBinder(Binder binder, - Class keyType, Class valueType, Annotation annotation) { - return newMapBinder(binder, TypeLiteral.get(keyType), TypeLiteral.get(valueType), annotation); - } - - /** - * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a - * {@link Map} that is itself bound with {@code annotationType}. - */ - public static MapBinder newMapBinder(Binder binder, TypeLiteral keyType, - TypeLiteral valueType, Class annotationType) { - binder = binder.skipSources(MapBinder.class, RealMapBinder.class); - return newMapBinder(binder, valueType, - Key.get(mapOf(keyType, valueType), annotationType), - Key.get(mapOfProviderOf(keyType, valueType), annotationType), - Multibinder.newSetBinder(binder, entryOfProviderOf(keyType, valueType), annotationType)); - } - - /** - * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a - * {@link Map} that is itself bound with {@code annotationType}. - */ - public static MapBinder newMapBinder(Binder binder, Class keyType, - Class valueType, Class annotationType) { - return newMapBinder( - binder, TypeLiteral.get(keyType), TypeLiteral.get(valueType), annotationType); - } - - @SuppressWarnings("unchecked") // a map of is safely a Map - private static TypeLiteral> mapOf( - TypeLiteral keyType, TypeLiteral valueType) { - return (TypeLiteral>) TypeLiteral.get( - Types.mapOf(keyType.getType(), valueType.getType())); - } - - @SuppressWarnings("unchecked") // a provider map is safely a Map> - private static TypeLiteral>> mapOfProviderOf( - TypeLiteral keyType, TypeLiteral valueType) { - return (TypeLiteral>>) TypeLiteral.get( - Types.mapOf(keyType.getType(), newParameterizedType(Provider.class, valueType.getType()))); - } - - @SuppressWarnings("unchecked") // a provider entry is safely a Map.Entry> - private static TypeLiteral>> entryOfProviderOf( - TypeLiteral keyType, TypeLiteral valueType) { - return (TypeLiteral>>) TypeLiteral.get(newParameterizedTypeWithOwner( - Map.class, Entry.class, keyType.getType(), Types.providerOf(valueType.getType()))); - } - - private static MapBinder newMapBinder(Binder binder, TypeLiteral valueType, - Key> mapKey, Key>> providerMapKey, - Multibinder>> entrySetBinder) { - RealMapBinder mapBinder = new RealMapBinder( - binder, valueType, mapKey, providerMapKey, entrySetBinder); - binder.install(mapBinder); - return mapBinder; - } - - /** - * Returns a binding builder used to add a new entry in the map. Each - * key must be distinct (and non-null). Bound providers will be evaluated each - * time the map is injected. - * - *

It is an error to call this method without also calling one of the - * {@code to} methods on the returned binding builder. - * - *

Scoping elements independently is supported. Use the {@code in} method - * to specify a binding scope. - */ - public abstract LinkedBindingBuilder addBinding(K key); - - /** - * The actual mapbinder plays several roles: - * - *

As a MapBinder, it acts as a factory for LinkedBindingBuilders for - * each of the map's values. It delegates to a {@link Multibinder} of - * entries (keys to value providers). - * - *

As a Module, it installs the binding to the map itself, as well as to - * a corresponding map whose values are providers. It uses the entry set - * multibinder to construct the map and the provider map. - * - *

As a module, this implements equals() and hashcode() in order to trick - * Guice into executing its configure() method only once. That makes it so - * that multiple mapbinders can be created for the same target map, but - * only one is bound. Since the list of bindings is retrieved from the - * injector itself (and not the mapbinder), each mapbinder has access to - * all contributions from all equivalent mapbinders. - * - *

Rather than binding a single Map.Entry<K, V>, the map binder - * binds keys and values independently. This allows the values to be properly - * scoped. - * - *

We use a subclass to hide 'implements Module' from the public API. - */ - private static final class RealMapBinder extends MapBinder implements Module { - private final TypeLiteral valueType; - private final Key> mapKey; - private final Key>> providerMapKey; - private final RealMultibinder>> entrySetBinder; - - /* the target injector's binder. non-null until initialization, null afterwards */ - private Binder binder; - - private RealMapBinder(Binder binder, TypeLiteral valueType, - Key> mapKey, Key>> providerMapKey, - Multibinder>> entrySetBinder) { - this.valueType = valueType; - this.mapKey = mapKey; - this.providerMapKey = providerMapKey; - this.entrySetBinder = (RealMultibinder>>) entrySetBinder; - this.binder = binder; - } - - /** - * This creates two bindings. One for the {@code Map.Entry>} - * and another for {@code V}. - */ - @Override public LinkedBindingBuilder addBinding(K key) { - checkNotNull(key, "key"); - checkConfiguration(!isInitialized(), "MapBinder was already initialized"); - - Key valueKey = Key.get(valueType, new RealElement(entrySetBinder.getSetName())); - entrySetBinder.addBinding().toInstance(new MapEntry>(key, - binder.getProvider(valueKey))); - return binder.bind(valueKey); - } - - public void configure(Binder binder) { - checkConfiguration(!isInitialized(), "MapBinder was already initialized"); - - final ImmutableSet> dependencies - = ImmutableSet.>of(Dependency.get(entrySetBinder.getSetKey())); - - // binds a Map> from a collection of Map> - final Provider>>> entrySetProvider = binder - .getProvider(entrySetBinder.getSetKey()); - binder.bind(providerMapKey).toProvider(new ProviderWithDependencies>>() { - private Map> providerMap; - - @SuppressWarnings("unused") - @Inject void initialize() { - RealMapBinder.this.binder = null; - - Map> providerMapMutable = new LinkedHashMap>(); - for (Entry> entry : entrySetProvider.get()) { - checkConfiguration(providerMapMutable.put(entry.getKey(), entry.getValue()) == null, - "Map injection failed due to duplicated key \"%s\"", entry.getKey()); - } - - providerMap = Collections.unmodifiableMap(providerMapMutable); - } - - public Map> get() { - return providerMap; - } - - public Set> getDependencies() { - return dependencies; - } - }); - - final Provider>> mapProvider = binder.getProvider(providerMapKey); - binder.bind(mapKey).toProvider(new ProviderWithDependencies>() { - public Map get() { - Map map = new LinkedHashMap(); - for (Entry> entry : mapProvider.get().entrySet()) { - V value = entry.getValue().get(); - K key = entry.getKey(); - checkConfiguration(value != null, - "Map injection failed due to null value for key \"%s\"", key); - map.put(key, value); - } - return Collections.unmodifiableMap(map); - } - - public Set> getDependencies() { - return dependencies; - } - }); - } - - private boolean isInitialized() { - return binder == null; - } - - @Override public boolean equals(Object o) { - return o instanceof RealMapBinder - && ((RealMapBinder) o).mapKey.equals(mapKey); - } - - @Override public int hashCode() { - return mapKey.hashCode(); - } - - private static final class MapEntry implements Map.Entry { - private final K key; - private final V value; - - private MapEntry(K key, V value) { - this.key = key; - this.value = value; - } - - public K getKey() { - return key; - } - - public V getValue() { - return value; - } - - public V setValue(V value) { - throw new UnsupportedOperationException(); - } - - @Override public boolean equals(Object obj) { - return obj instanceof Map.Entry - && key.equals(((Map.Entry) obj).getKey()) - && value.equals(((Map.Entry) obj).getValue()); - } - - @Override public int hashCode() { - return 127 * ("key".hashCode() ^ key.hashCode()) - + 127 * ("value".hashCode() ^ value.hashCode()); - } - - @Override public String toString() { - return "MapEntry(" + key + ", " + value + ")"; - } - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/Multibinder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/Multibinder.java deleted file mode 100644 index 06e0ddcbed4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/Multibinder.java +++ /dev/null @@ -1,316 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.multibindings; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.binder.LinkedBindingBuilder; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.spi.Dependency; -import org.elasticsearch.util.inject.spi.HasDependencies; -import org.elasticsearch.util.inject.spi.Message; -import org.elasticsearch.util.inject.util.Types; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -/** - * An API to bind multiple values separately, only to later inject them as a - * complete collection. Multibinder is intended for use in your application's - * module: - *


- * public class SnacksModule extends AbstractModule {
- *   protected void configure() {
- *     Multibinder<Snack> multibinder
- *         = Multibinder.newSetBinder(binder(), Snack.class);
- *     multibinder.addBinding().toInstance(new Twix());
- *     multibinder.addBinding().toProvider(SnickersProvider.class);
- *     multibinder.addBinding().to(Skittles.class);
- *   }
- * }
- * - *

With this binding, a {@link Set}{@code } can now be injected: - *


- * class SnackMachine {
- *   {@literal @}Inject
- *   public SnackMachine(Set<Snack> snacks) { ... }
- * }
- * - *

Create multibindings from different modules is supported. For example, it - * is okay to have both {@code CandyModule} and {@code ChipsModule} to both - * create their own {@code Multibinder}, and to each contribute bindings - * to the set of snacks. When that set is injected, it will contain elements - * from both modules. - * - *

Elements are resolved at set injection time. If an element is bound to a - * provider, that provider's get method will be called each time the set is - * injected (unless the binding is also scoped). - * - *

Annotations are be used to create different sets of the same element - * type. Each distinct annotation gets its own independent collection of - * elements. - * - *

Elements must be distinct. If multiple bound elements - * have the same value, set injection will fail. - * - *

Elements must be non-null. If any set element is null, - * set injection will fail. - * - * @author jessewilson@google.com (Jesse Wilson) - */ -public abstract class Multibinder { - private Multibinder() {} - - /** - * Returns a new multibinder that collects instances of {@code type} in a {@link Set} that is - * itself bound with no binding annotation. - */ - public static Multibinder newSetBinder(Binder binder, TypeLiteral type) { - binder = binder.skipSources(RealMultibinder.class, Multibinder.class); - RealMultibinder result = new RealMultibinder(binder, type, "", - Key.get(Multibinder.setOf(type))); - binder.install(result); - return result; - } - - /** - * Returns a new multibinder that collects instances of {@code type} in a {@link Set} that is - * itself bound with no binding annotation. - */ - public static Multibinder newSetBinder(Binder binder, Class type) { - return newSetBinder(binder, TypeLiteral.get(type)); - } - - /** - * Returns a new multibinder that collects instances of {@code type} in a {@link Set} that is - * itself bound with {@code annotation}. - */ - public static Multibinder newSetBinder( - Binder binder, TypeLiteral type, Annotation annotation) { - binder = binder.skipSources(RealMultibinder.class, Multibinder.class); - RealMultibinder result = new RealMultibinder(binder, type, annotation.toString(), - Key.get(Multibinder.setOf(type), annotation)); - binder.install(result); - return result; - } - - /** - * Returns a new multibinder that collects instances of {@code type} in a {@link Set} that is - * itself bound with {@code annotation}. - */ - public static Multibinder newSetBinder( - Binder binder, Class type, Annotation annotation) { - return newSetBinder(binder, TypeLiteral.get(type), annotation); - } - - /** - * Returns a new multibinder that collects instances of {@code type} in a {@link Set} that is - * itself bound with {@code annotationType}. - */ - public static Multibinder newSetBinder(Binder binder, TypeLiteral type, - Class annotationType) { - binder = binder.skipSources(RealMultibinder.class, Multibinder.class); - RealMultibinder result = new RealMultibinder(binder, type, "@" + annotationType.getName(), - Key.get(Multibinder.setOf(type), annotationType)); - binder.install(result); - return result; - } - - /** - * Returns a new multibinder that collects instances of {@code type} in a {@link Set} that is - * itself bound with {@code annotationType}. - */ - public static Multibinder newSetBinder(Binder binder, Class type, - Class annotationType) { - return newSetBinder(binder, TypeLiteral.get(type), annotationType); - } - - @SuppressWarnings("unchecked") // wrapping a T in a Set safely returns a Set - private static TypeLiteral> setOf(TypeLiteral elementType) { - Type type = Types.setOf(elementType.getType()); - return (TypeLiteral>) TypeLiteral.get(type); - } - - /** - * Returns a binding builder used to add a new element in the set. Each - * bound element must have a distinct value. Bound providers will be - * evaluated each time the set is injected. - * - *

It is an error to call this method without also calling one of the - * {@code to} methods on the returned binding builder. - * - *

Scoping elements independently is supported. Use the {@code in} method - * to specify a binding scope. - */ - public abstract LinkedBindingBuilder addBinding(); - - /** - * The actual multibinder plays several roles: - * - *

As a Multibinder, it acts as a factory for LinkedBindingBuilders for - * each of the set's elements. Each binding is given an annotation that - * identifies it as a part of this set. - * - *

As a Module, it installs the binding to the set itself. As a module, - * this implements equals() and hashcode() in order to trick Guice into - * executing its configure() method only once. That makes it so that - * multiple multibinders can be created for the same target collection, but - * only one is bound. Since the list of bindings is retrieved from the - * injector itself (and not the multibinder), each multibinder has access to - * all contributions from all multibinders. - * - *

As a Provider, this constructs the set instances. - * - *

We use a subclass to hide 'implements Module, Provider' from the public - * API. - */ - static final class RealMultibinder extends Multibinder - implements Module, Provider>, HasDependencies { - - private final TypeLiteral elementType; - private final String setName; - private final Key> setKey; - - /* the target injector's binder. non-null until initialization, null afterwards */ - private Binder binder; - - /* a provider for each element in the set. null until initialization, non-null afterwards */ - private List> providers; - private Set> dependencies; - - private RealMultibinder(Binder binder, TypeLiteral elementType, - String setName, Key> setKey) { - this.binder = checkNotNull(binder, "binder"); - this.elementType = checkNotNull(elementType, "elementType"); - this.setName = checkNotNull(setName, "setName"); - this.setKey = checkNotNull(setKey, "setKey"); - } - - @SuppressWarnings("unchecked") - public void configure(Binder binder) { - checkConfiguration(!isInitialized(), "Multibinder was already initialized"); - - binder.bind(setKey).toProvider(this); - } - - @Override public LinkedBindingBuilder addBinding() { - checkConfiguration(!isInitialized(), "Multibinder was already initialized"); - - return binder.bind(Key.get(elementType, new RealElement(setName))); - } - - /** - * Invoked by Guice at Injector-creation time to prepare providers for each - * element in this set. At this time the set's size is known, but its - * contents are only evaluated when get() is invoked. - */ - @Inject void initialize(Injector injector) { - providers = Lists.newArrayList(); - List> dependencies = Lists.newArrayList(); - for (Binding entry : injector.findBindingsByType(elementType)) { - - if (keyMatches(entry.getKey())) { - @SuppressWarnings("unchecked") // protected by findBindingsByType() - Binding binding = (Binding) entry; - providers.add(binding.getProvider()); - dependencies.add(Dependency.get(binding.getKey())); - } - } - - this.dependencies = ImmutableSet.copyOf(dependencies); - this.binder = null; - } - - private boolean keyMatches(Key key) { - return key.getTypeLiteral().equals(elementType) - && key.getAnnotation() instanceof Element - && ((Element) key.getAnnotation()).setName().equals(setName); - } - - private boolean isInitialized() { - return binder == null; - } - - public Set get() { - checkConfiguration(isInitialized(), "Multibinder is not initialized"); - - Set result = new LinkedHashSet(); - for (Provider provider : providers) { - final T newValue = provider.get(); - checkConfiguration(newValue != null, "Set injection failed due to null element"); - checkConfiguration(result.add(newValue), - "Set injection failed due to duplicated element \"%s\"", newValue); - } - return Collections.unmodifiableSet(result); - } - - String getSetName() { - return setName; - } - - Key> getSetKey() { - return setKey; - } - - public Set> getDependencies() { - return dependencies; - } - - @Override public boolean equals(Object o) { - return o instanceof RealMultibinder - && ((RealMultibinder) o).setKey.equals(setKey); - } - - @Override public int hashCode() { - return setKey.hashCode(); - } - - @Override public String toString() { - return new StringBuilder() - .append(setName) - .append(setName.length() > 0 ? " " : "") - .append("Multibinder<") - .append(elementType) - .append(">") - .toString(); - } - } - - static void checkConfiguration(boolean condition, String format, Object... args) { - if (condition) { - return; - } - - throw new ConfigurationException(ImmutableSet.of(new Message(Errors.format(format, args)))); - } - - static T checkNotNull(T reference, String name) { - if (reference != null) { - return reference; - } - - NullPointerException npe = new NullPointerException(name); - throw new ConfigurationException(ImmutableSet.of( - new Message(ImmutableList.of(), npe.toString(), npe))); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/RealElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/RealElement.java deleted file mode 100644 index b07242802f5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/RealElement.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.multibindings; - -import java.lang.annotation.Annotation; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author jessewilson@google.com (Jesse Wilson) - */ -class RealElement implements Element { - private static final AtomicInteger nextUniqueId = new AtomicInteger(1); - - private final int uniqueId; - private final String setName; - - RealElement(String setName) { - uniqueId = nextUniqueId.getAndIncrement(); - this.setName = setName; - } - - public String setName() { - return setName; - } - - public int uniqueId() { - return uniqueId; - } - - public Class annotationType() { - return Element.class; - } - - @Override public String toString() { - return "@" + Element.class.getName() + "(setName=" + setName - + ",uniqueId=" + uniqueId + ")"; - } - - @Override public boolean equals(Object o) { - return o instanceof Element - && ((Element) o).setName().equals(setName()) - && ((Element) o).uniqueId() == uniqueId(); - } - - @Override public int hashCode() { - return 127 * ("setName".hashCode() ^ setName.hashCode()) - + 127 * ("uniqueId".hashCode() ^ uniqueId); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/package-info.java deleted file mode 100644 index cab04e7e4e7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/multibindings/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Extension for binding multiple instances in a collection; this extension requires {@code - * guice-multibindings-2.0.jar}. - */ -package org.elasticsearch.util.inject.multibindings; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/Named.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/Named.java deleted file mode 100644 index 8eb11f1701b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/Named.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.name; - -import org.elasticsearch.util.inject.BindingAnnotation; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import java.lang.annotation.Target; - -/** - * Annotates named things. - * - * @author crazybob@google.com (Bob Lee) - */ -@Retention(RUNTIME) -@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) -@BindingAnnotation -public @interface Named { - String value(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/NamedImpl.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/NamedImpl.java deleted file mode 100644 index 1c7db2ae671..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/NamedImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.name; - -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import java.io.Serializable; -import java.lang.annotation.Annotation; - -class NamedImpl implements Named, Serializable { - - private final String value; - - public NamedImpl(String value) { - this.value = checkNotNull(value, "name"); - } - - public String value() { - return this.value; - } - - public int hashCode() { - // This is specified in java.lang.Annotation. - return (127 * "value".hashCode()) ^ value.hashCode(); - } - - public boolean equals(Object o) { - if (!(o instanceof Named)) { - return false; - } - - Named other = (Named) o; - return value.equals(other.value()); - } - - public String toString() { - return "@" + Named.class.getName() + "(value=" + value + ")"; - } - - public Class annotationType() { - return Named.class; - } - - private static final long serialVersionUID = 0; -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/Names.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/Names.java deleted file mode 100644 index 339dfff5ffa..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/Names.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.name; - -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.Key; -import java.util.Enumeration; -import java.util.Map; -import java.util.Properties; - -/** - * Utility methods for use with {@code @}{@link Named}. - * - * @author crazybob@google.com (Bob Lee) - */ -public class Names { - - private Names() {} - - /** - * Creates a {@link Named} annotation with {@code name} as the value. - */ - public static Named named(String name) { - return new NamedImpl(name); - } - - /** - * Creates a constant binding to {@code @Named(key)} for each entry in - * {@code properties}. - */ - public static void bindProperties(Binder binder, Map properties) { - binder = binder.skipSources(Names.class); - for (Map.Entry entry : properties.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - binder.bind(Key.get(String.class, new NamedImpl(key))).toInstance(value); - } - } - - /** - * Creates a constant binding to {@code @Named(key)} for each property. This - * method binds all properties including those inherited from - * {@link Properties#defaults defaults}. - */ - public static void bindProperties(Binder binder, Properties properties) { - binder = binder.skipSources(Names.class); - - // use enumeration to include the default properties - for (Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) { - String propertyName = (String) e.nextElement(); - String value = properties.getProperty(propertyName); - binder.bind(Key.get(String.class, new NamedImpl(propertyName))).toInstance(value); - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/package-info.java deleted file mode 100644 index 79bdf18c4f3..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/name/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Support for binding to string-based names. - */ -package org.elasticsearch.util.inject.name; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/package-info.java deleted file mode 100644 index edd0cf8d503..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/package-info.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Google Guice (pronounced "juice") is an ultra-lightweight dependency - * injection framework. Please refer to the Guice - * User's Guide - * for a gentle introduction. - * - *

The principal public APIs in this package are: - * - *

- *
{@link org.elasticsearch.util.inject.Inject} - *
The annotation you will use in your implementation classes to tell Guice - * where and how it should send in ("inject") the objects you depend on - * (your "dependencies"). - * - *
{@link org.elasticsearch.util.inject.Module} - *
The interface you will implement in order to specify "bindings" -- - * instructions for how Guice should handle injection -- for a particular - * set of interfaces. - * - *
{@link org.elasticsearch.util.inject.Binder} - *
The object that Guice passes into your {@link org.elasticsearch.util.inject.Module} - * to collect these bindings. - * - *
{@link org.elasticsearch.util.inject.Provider} - *
The interface you will implement when you need to customize exactly how - * Guice creates instances for a particular binding. - * - *
- * - */ -package org.elasticsearch.util.inject; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/BindingScopingVisitor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/BindingScopingVisitor.java deleted file mode 100644 index f3d5a7f6b78..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/BindingScopingVisitor.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Scope; -import java.lang.annotation.Annotation; - -/** - * Visits each of the strategies used to scope an injection. - * - * @param any type to be returned by the visit method. Use {@link Void} with - * {@code return null} if no return type is needed. - * @since 2.0 - */ -public interface BindingScopingVisitor { - - /** - * Visit an eager singleton or single instance. This scope strategy is found on both module and - * injector bindings. - */ - V visitEagerSingleton(); - - /** - * Visit a scope instance. This scope strategy is found on both module and injector bindings. - */ - V visitScope(Scope scope); - - /** - * Visit a scope annotation. This scope strategy is found only on module bindings. The instance - * that implements this scope is registered by {@link org.elasticsearch.util.inject.Binder#bindScope(Class, - * Scope) Binder.bindScope()}. - */ - V visitScopeAnnotation(Class scopeAnnotation); - - /** - * Visit an unspecified or unscoped strategy. On a module, this strategy indicates that the - * injector should use scoping annotations to find a scope. On an injector, it indicates that - * no scope is applied to the binding. An unscoped binding will behave like a scoped one when it - * is linked to a scoped binding. - */ - V visitNoScoping(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/BindingTargetVisitor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/BindingTargetVisitor.java deleted file mode 100644 index 284d8ca41ce..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/BindingTargetVisitor.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -/** - * Visits each of the strategies used to find an instance to satisfy an injection. - * - * @param any type to be returned by the visit method. Use {@link Void} with - * {@code return null} if no return type is needed. - * @since 2.0 - */ -public interface BindingTargetVisitor { - - /** - * Visit a instance binding. The same instance is returned for every injection. This target is - * found in both module and injector bindings. - */ - V visit(InstanceBinding binding); - - /** - * Visit a provider instance binding. The provider's {@code get} method is invoked to resolve - * injections. This target is found in both module and injector bindings. - */ - V visit(ProviderInstanceBinding binding); - - /** - * Visit a provider key binding. To resolve injections, the provider key is first resolved, then - * that provider's {@code get} method is invoked. This target is found in both module and injector - * bindings. - */ - V visit(ProviderKeyBinding binding); - - /** - * Visit a linked key binding. The other key's binding is used to resolve injections. This - * target is found in both module and injector bindings. - */ - V visit(LinkedKeyBinding binding); - - /** - * Visit a binding to a key exposed from an enclosed private environment. This target is only - * found in injector bindings. - */ - V visit(ExposedBinding binding); - - /** - * Visit an untargetted binding. This target is found only on module bindings. It indicates - * that the injector should use its implicit binding strategies to resolve injections. - */ - V visit(UntargettedBinding binding); - - /** - * Visit a constructor binding. To resolve injections, an instance is instantiated by invoking - * {@code constructor}. This target is found only on injector bindings. - */ - V visit(ConstructorBinding binding); - - /** - * Visit a binding created from converting a bound instance to a new type. The source binding - * has the same binding annotation but a different type. This target is found only on injector - * bindings. - */ - V visit(ConvertedConstantBinding binding); - - /** - * Visit a binding to a {@link org.elasticsearch.util.inject.Provider} that delegates to the binding for the - * provided type. This target is found only on injector bindings. - */ - V visit(ProviderBinding binding); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ConstructorBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ConstructorBinding.java deleted file mode 100644 index a38f90a3cf1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ConstructorBinding.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; - -import java.util.Set; - -/** - * A binding to the constructor of a concrete clss. To resolve injections, an instance is - * instantiated by invoking the constructor. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface ConstructorBinding extends Binding, HasDependencies { - - /** - * Gets the constructor this binding injects. - */ - InjectionPoint getConstructor(); - - /** - * Returns all instance method and field injection points on {@code type}. - * - * @return a possibly empty set of injection points. The set has a specified iteration order. All - * fields are returned and then all methods. Within the fields, supertype fields are returned - * before subtype fields. Similarly, supertype methods are returned before subtype methods. - */ - Set getInjectableMembers(); -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ConvertedConstantBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ConvertedConstantBinding.java deleted file mode 100644 index 9d0534e35cc..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ConvertedConstantBinding.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; -import org.elasticsearch.util.inject.Key; -import java.util.Set; - -/** - * A binding created from converting a bound instance to a new type. The source binding has the same - * binding annotation but a different type. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface ConvertedConstantBinding extends Binding, HasDependencies { - - /** - * Returns the converted value. - */ - T getValue(); - - /** - * Returns the key for the source binding. That binding can e retrieved from an injector using - * {@link org.elasticsearch.util.inject.Injector#getBinding(Key) Injector.getBinding(key)}. - */ - Key getSourceKey(); - - /** - * Returns a singleton set containing only the converted key. - */ - Set> getDependencies(); -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultBindingScopingVisitor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultBindingScopingVisitor.java deleted file mode 100644 index 1c25252d592..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultBindingScopingVisitor.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Scope; -import java.lang.annotation.Annotation; - -/** - * No-op visitor for subclassing. All interface methods simply delegate to - * {@link #visitOther()}, returning its result. - * - * @param any type to be returned by the visit method. Use {@link Void} with - * {@code return null} if no return type is needed. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public class DefaultBindingScopingVisitor implements BindingScopingVisitor { - - /** - * Default visit implementation. Returns {@code null}. - */ - protected V visitOther() { - return null; - } - - public V visitEagerSingleton() { - return visitOther(); - } - - public V visitScope(Scope scope) { - return visitOther(); - } - - public V visitScopeAnnotation(Class scopeAnnotation) { - return visitOther(); - } - - public V visitNoScoping() { - return visitOther(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultBindingTargetVisitor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultBindingTargetVisitor.java deleted file mode 100644 index 2bced9c808b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultBindingTargetVisitor.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; - -/** - * No-op visitor for subclassing. All interface methods simply delegate to {@link - * #visitOther(Binding)}, returning its result. - * - * @param any type to be returned by the visit method. Use {@link Void} with - * {@code return null} if no return type is needed. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public abstract class DefaultBindingTargetVisitor implements BindingTargetVisitor { - - /** - * Default visit implementation. Returns {@code null}. - */ - protected V visitOther(Binding binding) { - return null; - } - - public V visit(InstanceBinding instanceBinding) { - return visitOther(instanceBinding); - } - - public V visit(ProviderInstanceBinding providerInstanceBinding) { - return visitOther(providerInstanceBinding); - } - - public V visit(ProviderKeyBinding providerKeyBinding) { - return visitOther(providerKeyBinding); - } - - public V visit(LinkedKeyBinding linkedKeyBinding) { - return visitOther(linkedKeyBinding); - } - - public V visit(ExposedBinding exposedBinding) { - return visitOther(exposedBinding); - } - - public V visit(UntargettedBinding untargettedBinding) { - return visitOther(untargettedBinding); - } - - public V visit(ConstructorBinding constructorBinding) { - return visitOther(constructorBinding); - } - - public V visit(ConvertedConstantBinding convertedConstantBinding) { - return visitOther(convertedConstantBinding); - } - - // javac says it's an error to cast ProviderBinding to Binding - @SuppressWarnings("unchecked") - public V visit(ProviderBinding providerBinding) { - return visitOther((Binding) providerBinding); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultElementVisitor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultElementVisitor.java deleted file mode 100644 index 86d4500237b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/DefaultElementVisitor.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; - -/** - * No-op visitor for subclassing. All interface methods simply delegate to - * {@link #visitOther(Element)}, returning its result. - * - * @param any type to be returned by the visit method. Use {@link Void} with - * {@code return null} if no return type is needed. - * - * @author sberlin@gmail.com (Sam Berlin) - * @since 2.0 - */ -public abstract class DefaultElementVisitor implements ElementVisitor { - - /** - * Default visit implementation. Returns {@code null}. - */ - protected V visitOther(Element element) { - return null; - } - - public V visit(Message message) { - return visitOther(message); - } - - public V visit(Binding binding) { - return visitOther(binding); - } - - public V visit(ScopeBinding scopeBinding) { - return visitOther(scopeBinding); - } - - public V visit(TypeConverterBinding typeConverterBinding) { - return visitOther(typeConverterBinding); - } - - public V visit(ProviderLookup providerLookup) { - return visitOther(providerLookup); - } - - public V visit(InjectionRequest injectionRequest) { - return visitOther(injectionRequest); - } - - public V visit(StaticInjectionRequest staticInjectionRequest) { - return visitOther(staticInjectionRequest); - } - - public V visit(PrivateElements privateElements) { - return visitOther(privateElements); - } - - public V visit(MembersInjectorLookup lookup) { - return visitOther(lookup); - } - - public V visit(TypeListenerBinding binding) { - return visitOther(binding); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Dependency.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Dependency.java deleted file mode 100644 index 0e9e7fe9616..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Dependency.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.base.Objects; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.Key; - -import java.util.List; -import java.util.Set; - -/** - * A variable that can be resolved by an injector. - * - *

Use {@link #get} to build a freestanding dependency, or {@link InjectionPoint} to build one - * that's attached to a constructor, method or field. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class Dependency { - private final InjectionPoint injectionPoint; - private final Key key; - private final boolean nullable; - private final int parameterIndex; - - Dependency(InjectionPoint injectionPoint, Key key, - boolean nullable, int parameterIndex) { - this.injectionPoint = injectionPoint; - this.key = key; - this.nullable = nullable; - this.parameterIndex = parameterIndex; - } - - /** - * Returns a new dependency that is not attached to an injection point. The returned dependency is - * nullable. - */ - public static Dependency get(Key key) { - return new Dependency(null, key, true, -1); - } - - /** - * Returns the dependencies from the given injection points. - */ - public static Set> forInjectionPoints(Set injectionPoints) { - List> dependencies = Lists.newArrayList(); - for (InjectionPoint injectionPoint : injectionPoints) { - dependencies.addAll(injectionPoint.getDependencies()); - } - return ImmutableSet.copyOf(dependencies); - } - - /** - * Returns the key to the binding that satisfies this dependency. - */ - public Key getKey() { - return this.key; - } - - /** - * Returns true if null is a legal value for this dependency. - */ - public boolean isNullable() { - return nullable; - } - - /** - * Returns the injection point to which this dependency belongs, or null if this dependency isn't - * attached to a particular injection point. - */ - public InjectionPoint getInjectionPoint() { - return injectionPoint; - } - - /** - * Returns the index of this dependency in the injection point's parameter list, or {@code -1} if - * this dependency does not belong to a parameter list. Only method and constuctor dependencies - * are elements in a parameter list. - */ - public int getParameterIndex() { - return parameterIndex; - } - - @Override public int hashCode() { - return Objects.hashCode(injectionPoint, parameterIndex, key); - } - - @Override public boolean equals(Object o) { - if (o instanceof Dependency) { - Dependency dependency = (Dependency) o; - return Objects.equal(injectionPoint, dependency.injectionPoint) - && Objects.equal(parameterIndex, dependency.parameterIndex) - && Objects.equal(key, dependency.key); - } else { - return false; - } - } - - @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(key); - if (injectionPoint != null) { - builder.append("@").append(injectionPoint); - if (parameterIndex != -1) { - builder.append("[").append(parameterIndex).append("]"); - } - } - return builder.toString(); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Element.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Element.java deleted file mode 100644 index 9c972aff019..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Element.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binder; - -/** - * A core component of a module or injector. - * - *

The elements of a module can be inspected, validated and rewritten. Use {@link - * Elements#getElements(org.elasticsearch.util.inject.Module[]) Elements.getElements()} to read the elements - * from a module, and {@link Elements#getModule(Iterable) Elements.getModule()} to rewrite them. - * This can be used for static analysis and generation of Guice modules. - * - *

The elements of an injector can be inspected and exercised. Use {@link - * org.elasticsearch.util.inject.Injector#getBindings Injector.getBindings()} to reflect on Guice injectors. - * - * @author jessewilson@google.com (Jesse Wilson) - * @author crazybob@google.com (Bob Lee) - * @since 2.0 - */ -public interface Element { - - /** - * Returns an arbitrary object containing information about the "place" where this element was - * configured. Used by Guice in the production of descriptive error messages. - * - *

Tools might specially handle types they know about; {@code StackTraceElement} is a good - * example. Tools should simply call {@code toString()} on the source object if the type is - * unfamiliar. - */ - Object getSource(); - - /** - * Accepts an element visitor. Invokes the visitor method specific to this element's type. - * - * @param visitor to call back on - */ - T acceptVisitor(ElementVisitor visitor); - - /** - * Writes this module element to the given binder (optional operation). - * - * @param binder to apply configuration element to - * @throws UnsupportedOperationException if the {@code applyTo} method is not supported by this - * element. - */ - void applyTo(Binder binder); - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ElementVisitor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ElementVisitor.java deleted file mode 100644 index 92c07cc3e49..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ElementVisitor.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; - -/** - * Visit elements. - * - * @param any type to be returned by the visit method. Use {@link Void} with - * {@code return null} if no return type is needed. - * - * @since 2.0 - */ -public interface ElementVisitor { - - /** - * Visit a mapping from a key (type and optional annotation) to the strategy for getting - * instances of the type. - */ - V visit(Binding binding); - - /** - * Visit a registration of a scope annotation with the scope that implements it. - */ - V visit(ScopeBinding binding); - - /** - * Visit a registration of type converters for matching target types. - */ - V visit(TypeConverterBinding binding); - - /** - * Visit a request to inject the instance fields and methods of an instance. - */ - V visit(InjectionRequest request); - - /** - * Visit a request to inject the static fields and methods of type. - */ - V visit(StaticInjectionRequest request); - - /** - * Visit a lookup of the provider for a type. - */ - V visit(ProviderLookup lookup); - - /** - * Visit a lookup of the members injector. - */ - V visit(MembersInjectorLookup lookup); - - /** - * Visit an error message and the context in which it occured. - */ - V visit(Message message); - - /** - * Visit a collection of configuration elements for a {@linkplain org.elasticsearch.util.inject.PrivateBinder - * private binder}. - */ - V visit(PrivateElements elements); - - /** - * Visit an injectable type listener binding. - */ - V visit(TypeListenerBinding binding); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Elements.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Elements.java deleted file mode 100644 index a887cc66506..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Elements.java +++ /dev/null @@ -1,311 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Sets; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.binder.AnnotatedBindingBuilder; -import org.elasticsearch.util.inject.binder.AnnotatedConstantBindingBuilder; -import org.elasticsearch.util.inject.binder.AnnotatedElementBuilder; -import org.elasticsearch.util.inject.internal.*; -import org.elasticsearch.util.inject.matcher.Matcher; - -import java.lang.annotation.Annotation; -import java.util.*; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * Exposes elements of a module so they can be inspected, validated or {@link - * Element#applyTo(Binder) rewritten}. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class Elements { - private static final BindingTargetVisitor GET_INSTANCE_VISITOR - = new DefaultBindingTargetVisitor() { - @Override public Object visit(InstanceBinding binding) { - return binding.getInstance(); - } - - @Override protected Object visitOther(Binding binding) { - throw new IllegalArgumentException(); - } - }; - - /** - * Records the elements executed by {@code modules}. - */ - public static List getElements(Module... modules) { - return getElements(Stage.DEVELOPMENT, Arrays.asList(modules)); - } - - /** - * Records the elements executed by {@code modules}. - */ - public static List getElements(Stage stage, Module... modules) { - return getElements(stage, Arrays.asList(modules)); - } - - /** - * Records the elements executed by {@code modules}. - */ - public static List getElements(Iterable modules) { - return getElements(Stage.DEVELOPMENT, modules); - } - - /** - * Records the elements executed by {@code modules}. - */ - public static List getElements(Stage stage, Iterable modules) { - RecordingBinder binder = new RecordingBinder(stage); - for (Module module : modules) { - binder.install(module); - } - return Collections.unmodifiableList(binder.elements); - } - - /** - * Returns the module composed of {@code elements}. - */ - public static Module getModule(final Iterable elements) { - return new Module() { - public void configure(Binder binder) { - for (Element element : elements) { - element.applyTo(binder); - } - } - }; - } - - @SuppressWarnings("unchecked") - static BindingTargetVisitor getInstanceVisitor() { - return (BindingTargetVisitor) GET_INSTANCE_VISITOR; - } - - private static class RecordingBinder implements Binder, PrivateBinder { - private final Stage stage; - private final Set modules; - private final List elements; - private final Object source; - private final SourceProvider sourceProvider; - - /** The binder where exposed bindings will be created */ - private final RecordingBinder parent; - private final PrivateElementsImpl privateElements; - - private RecordingBinder(Stage stage) { - this.stage = stage; - this.modules = Sets.newHashSet(); - this.elements = Lists.newArrayList(); - this.source = null; - this.sourceProvider = new SourceProvider().plusSkippedClasses( - Elements.class, RecordingBinder.class, AbstractModule.class, - ConstantBindingBuilderImpl.class, AbstractBindingBuilder.class, BindingBuilder.class); - this.parent = null; - this.privateElements = null; - } - - /** Creates a recording binder that's backed by {@code prototype}. */ - private RecordingBinder( - RecordingBinder prototype, Object source, SourceProvider sourceProvider) { - checkArgument(source == null ^ sourceProvider == null); - - this.stage = prototype.stage; - this.modules = prototype.modules; - this.elements = prototype.elements; - this.source = source; - this.sourceProvider = sourceProvider; - this.parent = prototype.parent; - this.privateElements = prototype.privateElements; - } - - /** Creates a private recording binder. */ - private RecordingBinder(RecordingBinder parent, PrivateElementsImpl privateElements) { - this.stage = parent.stage; - this.modules = Sets.newHashSet(); - this.elements = privateElements.getElementsMutable(); - this.source = parent.source; - this.sourceProvider = parent.sourceProvider; - this.parent = parent; - this.privateElements = privateElements; - } - - public void bindScope(Class annotationType, Scope scope) { - elements.add(new ScopeBinding(getSource(), annotationType, scope)); - } - - @SuppressWarnings("unchecked") // it is safe to use the type literal for the raw type - public void requestInjection(Object instance) { - requestInjection((TypeLiteral) TypeLiteral.get(instance.getClass()), instance); - } - - public void requestInjection(TypeLiteral type, T instance) { - elements.add(new InjectionRequest(getSource(), type, instance)); - } - - public MembersInjector getMembersInjector(final TypeLiteral typeLiteral) { - final MembersInjectorLookup element - = new MembersInjectorLookup(getSource(), typeLiteral); - elements.add(element); - return element.getMembersInjector(); - } - - public MembersInjector getMembersInjector(Class type) { - return getMembersInjector(TypeLiteral.get(type)); - } - - public void bindListener(Matcher> typeMatcher, TypeListener listener) { - elements.add(new TypeListenerBinding(getSource(), listener, typeMatcher)); - } - - public void requestStaticInjection(Class... types) { - for (Class type : types) { - elements.add(new StaticInjectionRequest(getSource(), type)); - } - } - - public void install(Module module) { - if (modules.add(module)) { - Binder binder = this; - if (module instanceof PrivateModule) { - binder = binder.newPrivateBinder(); - } - - try { - module.configure(binder); - } catch (RuntimeException e) { - Collection messages = Errors.getMessagesFromThrowable(e); - if (!messages.isEmpty()) { - elements.addAll(messages); - } else { - addError(e); - } - } - binder.install(ProviderMethodsModule.forModule(module)); - } - } - - public Stage currentStage() { - return stage; - } - - public void addError(String message, Object... arguments) { - elements.add(new Message(getSource(), Errors.format(message, arguments))); - } - - public void addError(Throwable t) { - String message = "An exception was caught and reported. Message: " + t.getMessage(); - elements.add(new Message(ImmutableList.of(getSource()), message, t)); - } - - public void addError(Message message) { - elements.add(message); - } - - public AnnotatedBindingBuilder bind(Key key) { - return new BindingBuilder(this, elements, getSource(), key); - } - - public AnnotatedBindingBuilder bind(TypeLiteral typeLiteral) { - return bind(Key.get(typeLiteral)); - } - - public AnnotatedBindingBuilder bind(Class type) { - return bind(Key.get(type)); - } - - public AnnotatedConstantBindingBuilder bindConstant() { - return new ConstantBindingBuilderImpl(this, elements, getSource()); - } - - public Provider getProvider(final Key key) { - final ProviderLookup element = new ProviderLookup(getSource(), key); - elements.add(element); - return element.getProvider(); - } - - public Provider getProvider(Class type) { - return getProvider(Key.get(type)); - } - - public void convertToTypes(Matcher> typeMatcher, - TypeConverter converter) { - elements.add(new TypeConverterBinding(getSource(), typeMatcher, converter)); - } - - public RecordingBinder withSource(final Object source) { - return new RecordingBinder(this, source, null); - } - - public RecordingBinder skipSources(Class... classesToSkip) { - // if a source is specified explicitly, we don't need to skip sources - if (source != null) { - return this; - } - - SourceProvider newSourceProvider = sourceProvider.plusSkippedClasses(classesToSkip); - return new RecordingBinder(this, null, newSourceProvider); - } - - public PrivateBinder newPrivateBinder() { - PrivateElementsImpl privateElements = new PrivateElementsImpl(getSource()); - elements.add(privateElements); - return new RecordingBinder(this, privateElements); - } - - public void expose(Key key) { - exposeInternal(key); - } - - public AnnotatedElementBuilder expose(Class type) { - return exposeInternal(Key.get(type)); - } - - public AnnotatedElementBuilder expose(TypeLiteral type) { - return exposeInternal(Key.get(type)); - } - - private AnnotatedElementBuilder exposeInternal(Key key) { - if (privateElements == null) { - addError("Cannot expose %s on a standard binder. " - + "Exposed bindings are only applicable to private binders.", key); - return new AnnotatedElementBuilder() { - public void annotatedWith(Class annotationType) {} - public void annotatedWith(Annotation annotation) {} - }; - } - - ExposureBuilder builder = new ExposureBuilder(this, getSource(), key); - privateElements.addExposureBuilder(builder); - return builder; - } - - protected Object getSource() { - return sourceProvider != null - ? sourceProvider.get() - : source; - } - - @Override public String toString() { - return "Binder"; - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ExposedBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ExposedBinding.java deleted file mode 100644 index c06cfbe4439..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ExposedBinding.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; -import org.elasticsearch.util.inject.Binder; - -/** - * A binding to a key exposed from an enclosed private environment. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface ExposedBinding extends Binding, HasDependencies { - - /** - * Returns the enclosed environment that holds the original binding. - */ - PrivateElements getPrivateElements(); - - /** - * Unsupported. Always throws {@link UnsupportedOperationException}. - */ - void applyTo(Binder binder); -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/HasDependencies.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/HasDependencies.java deleted file mode 100644 index 61bfe0e6f6e..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/HasDependencies.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import java.util.Set; - -/** - * Implemented by {@link org.elasticsearch.util.inject.Binding bindings}, {@link org.elasticsearch.util.inject.Provider - * providers} and instances that expose their dependencies explicitly. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface HasDependencies { - - /** - * Returns the known dependencies for this type. If this has dependencies whose values are not - * known statically, a dependency for the {@link org.elasticsearch.util.inject.Injector Injector} will be - * included in the returned set. - * - * @return a possibly empty set - */ - Set> getDependencies(); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionListener.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionListener.java deleted file mode 100644 index d79f74b76d4..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionListener.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -/** - * Listens for injections into instances of type {@code I}. Useful for performing further - * injections, post-injection initialization, and more. - * - * @author crazybob@google.com (Bob Lee) - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface InjectionListener { - - /** - * Invoked by Guice after it injects the fields and methods of instance. - * - * @param injectee instance that Guice injected dependencies into - */ - void afterInjection(I injectee); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionPoint.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionPoint.java deleted file mode 100644 index 3e918f65fa5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionPoint.java +++ /dev/null @@ -1,395 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.ConfigurationException; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.TypeLiteral; -import org.elasticsearch.util.inject.internal.*; - -import java.lang.annotation.Annotation; -import java.lang.reflect.*; -import java.util.*; - -import static org.elasticsearch.util.inject.internal.MoreTypes.*; - -/** - * A constructor, field or method that can receive injections. Typically this is a member with the - * {@literal @}{@link Inject} annotation. For non-private, no argument constructors, the member may - * omit the annotation. - * - * @author crazybob@google.com (Bob Lee) - * @since 2.0 - */ -public final class InjectionPoint { - - private final boolean optional; - private final Member member; - private final ImmutableList> dependencies; - - private InjectionPoint(Member member, - ImmutableList> dependencies, boolean optional) { - this.member = member; - this.dependencies = dependencies; - this.optional = optional; - } - - InjectionPoint(TypeLiteral type, Method method) { - this.member = method; - - Inject inject = method.getAnnotation(Inject.class); - this.optional = inject.optional(); - - this.dependencies = forMember(method, type, method.getParameterAnnotations()); - } - - InjectionPoint(TypeLiteral type, Constructor constructor) { - this.member = constructor; - this.optional = false; - this.dependencies = forMember(constructor, type, constructor.getParameterAnnotations()); - } - - InjectionPoint(TypeLiteral type, Field field) { - this.member = field; - - Inject inject = field.getAnnotation(Inject.class); - this.optional = inject.optional(); - - Annotation[] annotations = field.getAnnotations(); - - Errors errors = new Errors(field); - Key key = null; - try { - key = Annotations.getKey(type.getFieldType(field), field, annotations, errors); - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - errors.throwConfigurationExceptionIfErrorsExist(); - - this.dependencies = ImmutableList.>of( - newDependency(key, Nullability.allowsNull(annotations), -1)); - } - - private ImmutableList> forMember(Member member, TypeLiteral type, - Annotation[][] paramterAnnotations) { - Errors errors = new Errors(member); - Iterator annotationsIterator = Arrays.asList(paramterAnnotations).iterator(); - - List> dependencies = Lists.newArrayList(); - int index = 0; - - for (TypeLiteral parameterType : type.getParameterTypes(member)) { - try { - Annotation[] parameterAnnotations = annotationsIterator.next(); - Key key = Annotations.getKey(parameterType, member, parameterAnnotations, errors); - dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index)); - index++; - } catch (ErrorsException e) { - errors.merge(e.getErrors()); - } - } - - errors.throwConfigurationExceptionIfErrorsExist(); - return ImmutableList.copyOf(dependencies); - } - - // This metohd is necessary to create a Dependency with proper generic type information - private Dependency newDependency(Key key, boolean allowsNull, int parameterIndex) { - return new Dependency(this, key, allowsNull, parameterIndex); - } - - /** - * Returns the injected constructor, field, or method. - */ - public Member getMember() { - return member; - } - - /** - * Returns the dependencies for this injection point. If the injection point is for a method or - * constructor, the dependencies will correspond to that member's parameters. Field injection - * points always have a single dependency for the field itself. - * - * @return a possibly-empty list - */ - public List> getDependencies() { - return dependencies; - } - - /** - * Returns true if this injection point shall be skipped if the injector cannot resolve bindings - * for all required dependencies. Both explicit bindings (as specified in a module), and implicit - * bindings ({@literal @}{@link org.elasticsearch.util.inject.ImplementedBy ImplementedBy}, default - * constructors etc.) may be used to satisfy optional injection points. - */ - public boolean isOptional() { - return optional; - } - - @Override public boolean equals(Object o) { - return o instanceof InjectionPoint - && member.equals(((InjectionPoint) o).member); - } - - @Override public int hashCode() { - return member.hashCode(); - } - - @Override public String toString() { - return MoreTypes.toString(member); - } - - /** - * Returns a new injection point for the injectable constructor of {@code type}. - * - * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, - * or a no-arguments constructor that is not private. - * @throws ConfigurationException if there is no injectable constructor, more than one injectable - * constructor, or if parameters of the injectable constructor are malformed, such as a - * parameter with multiple binding annotations. - */ - public static InjectionPoint forConstructorOf(TypeLiteral type) { - Class rawType = getRawType(type.getType()); - Errors errors = new Errors(rawType); - - Constructor injectableConstructor = null; - for (Constructor constructor : rawType.getDeclaredConstructors()) { - Inject inject = constructor.getAnnotation(Inject.class); - if (inject != null) { - if (inject.optional()) { - errors.optionalConstructor(constructor); - } - - if (injectableConstructor != null) { - errors.tooManyConstructors(rawType); - } - - injectableConstructor = constructor; - checkForMisplacedBindingAnnotations(injectableConstructor, errors); - } - } - - errors.throwConfigurationExceptionIfErrorsExist(); - - if (injectableConstructor != null) { - return new InjectionPoint(type, injectableConstructor); - } - - // If no annotated constructor is found, look for a no-arg constructor instead. - try { - Constructor noArgConstructor = rawType.getDeclaredConstructor(); - - // Disallow private constructors on non-private classes (unless they have @Inject) - if (Modifier.isPrivate(noArgConstructor.getModifiers()) - && !Modifier.isPrivate(rawType.getModifiers())) { - errors.missingConstructor(rawType); - throw new ConfigurationException(errors.getMessages()); - } - - checkForMisplacedBindingAnnotations(noArgConstructor, errors); - return new InjectionPoint(type, noArgConstructor); - } catch (NoSuchMethodException e) { - errors.missingConstructor(rawType); - throw new ConfigurationException(errors.getMessages()); - } - } - - /** - * Returns a new injection point for the injectable constructor of {@code type}. - * - * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, - * or a no-arguments constructor that is not private. - * @throws ConfigurationException if there is no injectable constructor, more than one injectable - * constructor, or if parameters of the injectable constructor are malformed, such as a - * parameter with multiple binding annotations. - */ - public static InjectionPoint forConstructorOf(Class type) { - return forConstructorOf(TypeLiteral.get(type)); - } - - /** - * Returns all static method and field injection points on {@code type}. - * - * @return a possibly empty set of injection points. The set has a specified iteration order. All - * fields are returned and then all methods. Within the fields, supertype fields are returned - * before subtype fields. Similarly, supertype methods are returned before subtype methods. - * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as - * a field with multiple binding annotations. The exception's {@link - * ConfigurationException#getPartialValue() partial value} is a {@code Set} - * of the valid injection points. - */ - public static Set forStaticMethodsAndFields(TypeLiteral type) { - List sink = Lists.newArrayList(); - Errors errors = new Errors(); - - addInjectionPoints(type, Factory.FIELDS, true, sink, errors); - addInjectionPoints(type, Factory.METHODS, true, sink, errors); - - ImmutableSet result = ImmutableSet.copyOf(sink); - if (errors.hasErrors()) { - throw new ConfigurationException(errors.getMessages()).withPartialValue(result); - } - return result; - } - - /** - * Returns all static method and field injection points on {@code type}. - * - * @return a possibly empty set of injection points. The set has a specified iteration order. All - * fields are returned and then all methods. Within the fields, supertype fields are returned - * before subtype fields. Similarly, supertype methods are returned before subtype methods. - * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as - * a field with multiple binding annotations. The exception's {@link - * ConfigurationException#getPartialValue() partial value} is a {@code Set} - * of the valid injection points. - */ - public static Set forStaticMethodsAndFields(Class type) { - return forStaticMethodsAndFields(TypeLiteral.get(type)); - } - - /** - * Returns all instance method and field injection points on {@code type}. - * - * @return a possibly empty set of injection points. The set has a specified iteration order. All - * fields are returned and then all methods. Within the fields, supertype fields are returned - * before subtype fields. Similarly, supertype methods are returned before subtype methods. - * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as - * a field with multiple binding annotations. The exception's {@link - * ConfigurationException#getPartialValue() partial value} is a {@code Set} - * of the valid injection points. - */ - public static Set forInstanceMethodsAndFields(TypeLiteral type) { - List sink = Lists.newArrayList(); - Errors errors = new Errors(); - - // TODO (crazybob): Filter out overridden members. - addInjectionPoints(type, Factory.FIELDS, false, sink, errors); - addInjectionPoints(type, Factory.METHODS, false, sink, errors); - - ImmutableSet result = ImmutableSet.copyOf(sink); - if (errors.hasErrors()) { - throw new ConfigurationException(errors.getMessages()).withPartialValue(result); - } - return result; - } - - /** - * Returns all instance method and field injection points on {@code type}. - * - * @return a possibly empty set of injection points. The set has a specified iteration order. All - * fields are returned and then all methods. Within the fields, supertype fields are returned - * before subtype fields. Similarly, supertype methods are returned before subtype methods. - * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as - * a field with multiple binding annotations. The exception's {@link - * ConfigurationException#getPartialValue() partial value} is a {@code Set} - * of the valid injection points. - */ - public static Set forInstanceMethodsAndFields(Class type) { - return forInstanceMethodsAndFields(TypeLiteral.get(type)); - } - - private static void checkForMisplacedBindingAnnotations(Member member, Errors errors) { - Annotation misplacedBindingAnnotation = Annotations.findBindingAnnotation( - errors, member, ((AnnotatedElement) member).getAnnotations()); - if (misplacedBindingAnnotation == null) { - return; - } - - // don't warn about misplaced binding annotations on methods when there's a field with the same - // name. In Scala, fields always get accessor methods (that we need to ignore). See bug 242. - if (member instanceof Method) { - try { - if (member.getDeclaringClass().getDeclaredField(member.getName()) != null) { - return; - } - } catch (NoSuchFieldException ignore) { - } - } - - errors.misplacedBindingAnnotation(member, misplacedBindingAnnotation); - } - - private static void addInjectionPoints(TypeLiteral type, - Factory factory, boolean statics, Collection injectionPoints, - Errors errors) { - if (type.getType() == Object.class) { - return; - } - - // Add injectors for superclass first. - TypeLiteral superType = type.getSupertype(type.getRawType().getSuperclass()); - addInjectionPoints(superType, factory, statics, injectionPoints, errors); - - // Add injectors for all members next - addInjectorsForMembers(type, factory, statics, injectionPoints, errors); - } - - private static void addInjectorsForMembers( - TypeLiteral typeLiteral, Factory factory, boolean statics, - Collection injectionPoints, Errors errors) { - for (M member : factory.getMembers(getRawType(typeLiteral.getType()))) { - if (isStatic(member) != statics) { - continue; - } - - Inject inject = member.getAnnotation(Inject.class); - if (inject == null) { - continue; - } - - try { - injectionPoints.add(factory.create(typeLiteral, member, errors)); - } catch (ConfigurationException ignorable) { - if (!inject.optional()) { - errors.merge(ignorable.getErrorMessages()); - } - } - } - } - - private static boolean isStatic(Member member) { - return Modifier.isStatic(member.getModifiers()); - } - - private interface Factory { - Factory FIELDS = new Factory() { - public Field[] getMembers(Class type) { - return type.getDeclaredFields(); - } - public InjectionPoint create(TypeLiteral typeLiteral, Field member, Errors errors) { - return new InjectionPoint(typeLiteral, member); - } - }; - - Factory METHODS = new Factory() { - public Method[] getMembers(Class type) { - return type.getDeclaredMethods(); - } - public InjectionPoint create(TypeLiteral typeLiteral, Method member, Errors errors) { - checkForMisplacedBindingAnnotations(member, errors); - return new InjectionPoint(typeLiteral, member); - } - }; - - M[] getMembers(Class type); - InjectionPoint create(TypeLiteral typeLiteral, M member, Errors errors); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionRequest.java deleted file mode 100644 index f0b743b797f..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InjectionRequest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.ConfigurationException; -import org.elasticsearch.util.inject.TypeLiteral; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import java.util.Set; - -/** - * A request to inject the instance fields and methods of an instance. Requests are created - * explicitly in a module using {@link org.elasticsearch.util.inject.Binder#requestInjection(Object) - * requestInjection()} statements: - *

- *     requestInjection(serviceInstance);
- * - * @author mikeward@google.com (Mike Ward) - * @since 2.0 - */ -public final class InjectionRequest implements Element { - - private final Object source; - private final TypeLiteral type; - private final T instance; - - public InjectionRequest(Object source, TypeLiteral type, T instance) { - this.source = checkNotNull(source, "source"); - this.type = checkNotNull(type, "type"); - this.instance = checkNotNull(instance, "instance"); - } - - public Object getSource() { - return source; - } - - public T getInstance() { - return instance; - } - - public TypeLiteral getType() { - return type; - } - - /** - * Returns the instance methods and fields of {@code instance} that will be injected to fulfill - * this request. - * - * @return a possibly empty set of injection points. The set has a specified iteration order. All - * fields are returned and then all methods. Within the fields, supertype fields are returned - * before subtype fields. Similarly, supertype methods are returned before subtype methods. - * @throws ConfigurationException if there is a malformed injection point on the class of {@code - * instance}, such as a field with multiple binding annotations. The exception's {@link - * ConfigurationException#getPartialValue() partial value} is a {@code Set} - * of the valid injection points. - */ - public Set getInjectionPoints() throws ConfigurationException { - return InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); - } - - public R acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } - - public void applyTo(Binder binder) { - binder.withSource(getSource()).requestInjection(type, instance); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InstanceBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InstanceBinding.java deleted file mode 100644 index 2ad458317d5..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/InstanceBinding.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; -import java.util.Set; - -/** - * A binding to a single instance. The same instance is returned for every injection. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface InstanceBinding extends Binding, HasDependencies { - - /** - * Returns the user-supplied instance. - */ - T getInstance(); - - /** - * Returns the field and method injection points of the instance, injected at injector-creation - * time only. - * - * @return a possibly empty set - */ - Set getInjectionPoints(); - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/LinkedKeyBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/LinkedKeyBinding.java deleted file mode 100644 index 89e15e37a91..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/LinkedKeyBinding.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; -import org.elasticsearch.util.inject.Key; - -/** - * A binding to a linked key. The other key's binding is used to resolve injections. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface LinkedKeyBinding extends Binding { - - /** - * Returns the linked key used to resolve injections. That binding can be retrieved from an - * injector using {@link org.elasticsearch.util.inject.Injector#getBinding(Key) Injector.getBinding(key)}. - */ - Key getLinkedKey(); - -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/MembersInjectorLookup.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/MembersInjectorLookup.java deleted file mode 100644 index 5bde3644799..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/MembersInjectorLookup.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.MembersInjector; -import org.elasticsearch.util.inject.TypeLiteral; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import static org.elasticsearch.util.inject.internal.Preconditions.checkState; - -/** - * A lookup of the members injector for a type. Lookups are created explicitly in a module using - * {@link org.elasticsearch.util.inject.Binder#getMembersInjector(Class) getMembersInjector()} statements: - *
- *     MembersInjector<PaymentService> membersInjector
- *         = getMembersInjector(PaymentService.class);
- * - * @author crazybob@google.com (Bob Lee) - * @since 2.0 - */ -public final class MembersInjectorLookup implements Element { - - private final Object source; - private final TypeLiteral type; - private MembersInjector delegate; - - public MembersInjectorLookup(Object source, TypeLiteral type) { - this.source = checkNotNull(source, "source"); - this.type = checkNotNull(type, "type"); - } - - public Object getSource() { - return source; - } - - /** - * Gets the type containing the members to be injected. - */ - public TypeLiteral getType() { - return type; - } - - public T acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } - - /** - * Sets the actual members injector. - * - * @throws IllegalStateException if the delegate is already set - */ - public void initializeDelegate(MembersInjector delegate) { - checkState(this.delegate == null, "delegate already initialized"); - this.delegate = checkNotNull(delegate, "delegate"); - } - - public void applyTo(Binder binder) { - initializeDelegate(binder.withSource(getSource()).getMembersInjector(type)); - } - - /** - * Returns the delegate members injector, or {@code null} if it has not yet been initialized. - * The delegate will be initialized when this element is processed, or otherwise used to create - * an injector. - */ - public MembersInjector getDelegate() { - return delegate; - } - - /** - * Returns the looked up members injector. The result is not valid until this lookup has been - * initialized, which usually happens when the injector is created. The members injector will - * throw an {@code IllegalStateException} if you try to use it beforehand. - */ - public MembersInjector getMembersInjector() { - return new MembersInjector() { - public void injectMembers(T instance) { - checkState(delegate != null, - "This MembersInjector cannot be used until the Injector has been created."); - delegate.injectMembers(instance); - } - - @Override public String toString() { - return "MembersInjector<" + type + ">"; - } - }; - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Message.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Message.java deleted file mode 100644 index eca56ed9b31..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/Message.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.base.Objects; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.internal.Errors; -import org.elasticsearch.util.inject.internal.SourceProvider; - -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.util.List; - -import static org.elasticsearch.util.inject.internal.Preconditions.*; - -/** - * An error message and the context in which it occured. Messages are usually created internally by - * Guice and its extensions. Messages can be created explicitly in a module using {@link - * org.elasticsearch.util.inject.Binder#addError(Throwable) addError()} statements: - *
- *     try {
- *       bindPropertiesFromFile();
- *     } catch (IOException e) {
- *       addError(e);
- *     }
- * - * @author crazybob@google.com (Bob Lee) - */ -public final class Message implements Serializable, Element { - private final String message; - private final Throwable cause; - private final List sources; - - /** - * @since 2.0 - */ - public Message(List sources, String message, Throwable cause) { - this.sources = ImmutableList.copyOf(sources); - this.message = checkNotNull(message, "message"); - this.cause = cause; - } - - public Message(Object source, String message) { - this(ImmutableList.of(source), message, null); - } - - public Message(String message) { - this(ImmutableList.of(), message, null); - } - - public String getSource() { - return sources.isEmpty() - ? SourceProvider.UNKNOWN_SOURCE.toString() - : Errors.convert(sources.get(sources.size() - 1)).toString(); - } - - /** @since 2.0 */ - public List getSources() { - return sources; - } - - /** - * Gets the error message text. - */ - public String getMessage() { - return message; - } - - /** @since 2.0 */ - public T acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } - - /** - * Returns the throwable that caused this message, or {@code null} if this - * message was not caused by a throwable. - * - * @since 2.0 - */ - public Throwable getCause() { - return cause; - } - - @Override public String toString() { - return message; - } - - @Override public int hashCode() { - return message.hashCode(); - } - - @Override public boolean equals(Object o) { - if (!(o instanceof Message)) { - return false; - } - Message e = (Message) o; - return message.equals(e.message) && Objects.equal(cause, e.cause) && sources.equals(e.sources); - } - - /** @since 2.0 */ - public void applyTo(Binder binder) { - binder.withSource(getSource()).addError(this); - } - - /** - * When serialized, we eagerly convert sources to strings. This hurts our formatting, but it - * guarantees that the receiving end will be able to read the message. - */ - private Object writeReplace() throws ObjectStreamException { - Object[] sourcesAsStrings = sources.toArray(); - for (int i = 0; i < sourcesAsStrings.length; i++) { - sourcesAsStrings[i] = Errors.convert(sourcesAsStrings[i]).toString(); - } - return new Message(ImmutableList.of(sourcesAsStrings), message, cause); - } - - private static final long serialVersionUID = 0; -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/PrivateElements.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/PrivateElements.java deleted file mode 100644 index 38eb6cd7d12..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/PrivateElements.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.Key; -import java.util.List; -import java.util.Set; - -/** - * A private collection of elements that are hidden from the enclosing injector or module by - * default. See {@link org.elasticsearch.util.inject.PrivateModule PrivateModule} for details. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface PrivateElements extends Element { - - /** - * Returns the configuration information in this private environment. - */ - List getElements(); - - /** - * Returns the child injector that hosts these private elements, or null if the elements haven't - * been used to create an injector. - */ - Injector getInjector(); - - /** - * Returns the unique exposed keys for these private elements. - */ - Set> getExposedKeys(); - - /** - * Returns an arbitrary object containing information about the "place" where this key was - * exposed. Used by Guice in the production of descriptive error messages. - * - *

Tools might specially handle types they know about; {@code StackTraceElement} is a good - * example. Tools should simply call {@code toString()} on the source object if the type is - * unfamiliar. - * - * @param key one of the keys exposed by this module. - */ - Object getExposedSource(Key key); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderBinding.java deleted file mode 100644 index d7c3d1c93d7..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderBinding.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Provider; - -/** - * A binding to a {@link Provider} that delegates to the binding for the provided type. This binding - * is used whenever a {@code Provider} is injected (as opposed to injecting {@code T} directly). - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface ProviderBinding> extends Binding { - - /** - * Returns the key whose binding is used to {@link Provider#get provide instances}. That binding - * can be retrieved from an injector using {@link org.elasticsearch.util.inject.Injector#getBinding(Key) - * Injector.getBinding(providedKey)} - */ - Key getProvidedKey(); -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderInstanceBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderInstanceBinding.java deleted file mode 100644 index 60c4d4f962a..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderInstanceBinding.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; -import org.elasticsearch.util.inject.Provider; -import java.util.Set; - -/** - * A binding to a provider instance. The provider's {@code get} method is invoked to resolve - * injections. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface ProviderInstanceBinding extends Binding, HasDependencies { - - /** - * Returns the user-supplied, unscoped provider. - */ - Provider getProviderInstance(); - - /** - * Returns the field and method injection points of the provider, injected at injector-creation - * time only. - * - * @return a possibly empty set - */ - Set getInjectionPoints(); - -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderKeyBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderKeyBinding.java deleted file mode 100644 index 8cc094c7fac..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderKeyBinding.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Provider; - -/** - * A binding to a provider key. To resolve injections, the provider key is first resolved, then that - * provider's {@code get} method is invoked. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface ProviderKeyBinding extends Binding { - - /** - * Returns the key used to resolve the provider's binding. That binding can be retrieved from an - * injector using {@link org.elasticsearch.util.inject.Injector#getBinding(Key) - * Injector.getBinding(providerKey)} - */ - Key> getProviderKey(); - -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderLookup.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderLookup.java deleted file mode 100644 index 17b168f1163..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderLookup.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.Provider; -import org.elasticsearch.util.inject.Binder; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import static org.elasticsearch.util.inject.internal.Preconditions.checkState; - -/** - * A lookup of the provider for a type. Lookups are created explicitly in a module using - * {@link org.elasticsearch.util.inject.Binder#getProvider(Class) getProvider()} statements: - *

- *     Provider<PaymentService> paymentServiceProvider
- *         = getProvider(PaymentService.class);
- * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class ProviderLookup implements Element { - private final Object source; - private final Key key; - private Provider delegate; - - public ProviderLookup(Object source, Key key) { - this.source = checkNotNull(source, "source"); - this.key = checkNotNull(key, "key"); - } - - public Object getSource() { - return source; - } - - public Key getKey() { - return key; - } - - public T acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } - - /** - * Sets the actual provider. - * - * @throws IllegalStateException if the delegate is already set - */ - public void initializeDelegate(Provider delegate) { - checkState(this.delegate == null, "delegate already initialized"); - this.delegate = checkNotNull(delegate, "delegate"); - } - - public void applyTo(Binder binder) { - initializeDelegate(binder.withSource(getSource()).getProvider(key)); - } - - /** - * Returns the delegate provider, or {@code null} if it has not yet been initialized. The delegate - * will be initialized when this element is processed, or otherwise used to create an injector. - */ - public Provider getDelegate() { - return delegate; - } - - /** - * Returns the looked up provider. The result is not valid until this lookup has been initialized, - * which usually happens when the injector is created. The provider will throw an {@code - * IllegalStateException} if you try to use it beforehand. - */ - public Provider getProvider() { - return new Provider() { - public T get() { - checkState(delegate != null, - "This Provider cannot be used until the Injector has been created."); - return delegate.get(); - } - - @Override public String toString() { - return "Provider<" + key.getTypeLiteral() + ">"; - } - }; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderWithDependencies.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderWithDependencies.java deleted file mode 100644 index a48ea26d1ca..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ProviderWithDependencies.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Provider; - -/** - * A provider with dependencies on other injected types. If a {@link Provider} has dependencies that - * aren't specified in injections, this interface should be used to expose all dependencies. - * - * @since 2.0 - */ -public interface ProviderWithDependencies extends Provider, HasDependencies {} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ScopeBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ScopeBinding.java deleted file mode 100644 index da2f8d4eaca..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/ScopeBinding.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Scope; -import org.elasticsearch.util.inject.Binder; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import java.lang.annotation.Annotation; - -/** - * Registration of a scope annotation with the scope that implements it. Instances are created - * explicitly in a module using {@link org.elasticsearch.util.inject.Binder#bindScope(Class, Scope) bindScope()} - * statements: - *
- *     Scope recordScope = new RecordScope();
- *     bindScope(RecordScoped.class, new RecordScope());
- * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class ScopeBinding implements Element { - private final Object source; - private final Class annotationType; - private final Scope scope; - - ScopeBinding(Object source, Class annotationType, Scope scope) { - this.source = checkNotNull(source, "source"); - this.annotationType = checkNotNull(annotationType, "annotationType"); - this.scope = checkNotNull(scope, "scope"); - } - - public Object getSource() { - return source; - } - - public Class getAnnotationType() { - return annotationType; - } - - public Scope getScope() { - return scope; - } - - public T acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } - - public void applyTo(Binder binder) { - binder.withSource(getSource()).bindScope(annotationType, scope); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/StaticInjectionRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/StaticInjectionRequest.java deleted file mode 100644 index 07f4dcab7f6..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/StaticInjectionRequest.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.ConfigurationException; -import org.elasticsearch.util.inject.Binder; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import java.util.Set; - -/** - * A request to inject the static fields and methods of a type. Requests are created - * explicitly in a module using {@link org.elasticsearch.util.inject.Binder#requestStaticInjection(Class[]) - * requestStaticInjection()} statements: - *
- *     requestStaticInjection(MyLegacyService.class);
- * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class StaticInjectionRequest implements Element { - private final Object source; - private final Class type; - - StaticInjectionRequest(Object source, Class type) { - this.source = checkNotNull(source, "source"); - this.type = checkNotNull(type, "type"); - } - - public Object getSource() { - return source; - } - - public Class getType() { - return type; - } - - /** - * Returns the static methods and fields of {@code type} that will be injected to fulfill this - * request. - * - * @return a possibly empty set of injection points. The set has a specified iteration order. All - * fields are returned and then all methods. Within the fields, supertype fields are returned - * before subtype fields. Similarly, supertype methods are returned before subtype methods. - * @throws ConfigurationException if there is a malformed injection point on {@code type}, such as - * a field with multiple binding annotations. The exception's {@link - * ConfigurationException#getPartialValue() partial value} is a {@code Set} - * of the valid injection points. - */ - public Set getInjectionPoints() throws ConfigurationException { - return InjectionPoint.forStaticMethodsAndFields(type); - } - - public void applyTo(Binder binder) { - binder.withSource(getSource()).requestStaticInjection(type); - } - - public T acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeConverter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeConverter.java deleted file mode 100644 index 864f0911eb1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeConverter.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.TypeLiteral; - -/** - * Converts constant string values to a different type. - * - * @author crazybob@google.com (Bob Lee) - * @since 2.0 - */ -public interface TypeConverter { - - /** - * Converts a string value. Throws an exception if a conversion error occurs. - */ - Object convert(String value, TypeLiteral toType); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeConverterBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeConverterBinding.java deleted file mode 100644 index 11772125734..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeConverterBinding.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.TypeLiteral; -import org.elasticsearch.util.inject.Binder; -import static org.elasticsearch.util.inject.internal.Preconditions.checkNotNull; -import org.elasticsearch.util.inject.matcher.Matcher; - -/** - * Registration of type converters for matching target types. Instances are created - * explicitly in a module using {@link org.elasticsearch.util.inject.Binder#convertToTypes(Matcher, - * TypeConverter) convertToTypes()} statements: - *
- *     convertToTypes(Matchers.only(DateTime.class), new DateTimeConverter());
- * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class TypeConverterBinding implements Element { - private final Object source; - private final Matcher> typeMatcher; - private final TypeConverter typeConverter; - - TypeConverterBinding(Object source, Matcher> typeMatcher, - TypeConverter typeConverter) { - this.source = checkNotNull(source, "source"); - this.typeMatcher = checkNotNull(typeMatcher, "typeMatcher"); - this.typeConverter = checkNotNull(typeConverter, "typeConverter"); - } - - public Object getSource() { - return source; - } - - public Matcher> getTypeMatcher() { - return typeMatcher; - } - - public TypeConverter getTypeConverter() { - return typeConverter; - } - - public T acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } - - public void applyTo(Binder binder) { - binder.withSource(getSource()).convertToTypes(typeMatcher, typeConverter); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeEncounter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeEncounter.java deleted file mode 100644 index 1c93a23ea04..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeEncounter.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Provider; -import org.elasticsearch.util.inject.Key; -import org.elasticsearch.util.inject.MembersInjector; -import org.elasticsearch.util.inject.TypeLiteral; - -/** - * Context of an injectable type encounter. Enables reporting errors, registering injection - * listeners and binding method interceptors for injectable type {@code I}. It is an error to use - * an encounter after the {@link TypeListener#hear(TypeLiteral, TypeEncounter) hear()} method has - * returned. - * - * @param the injectable type encountered - * @since 2.0 - */ -public interface TypeEncounter { - - /** - * Records an error message for type {@code I} which will be presented to the user at a later - * time. Unlike throwing an exception, this enable us to continue configuring the Injector and - * discover more errors. Uses {@link String#format(String, Object[])} to insert the arguments - * into the message. - */ - void addError(String message, Object... arguments); - - /** - * Records an exception for type {@code I}, the full details of which will be logged, and the - * message of which will be presented to the user at a later time. If your type listener calls - * something that you worry may fail, you should catch the exception and pass it to this method. - */ - void addError(Throwable t); - - /** - * Records an error message to be presented to the user at a later time. - */ - void addError(Message message); - - /** - * Returns the provider used to obtain instances for the given injection key. The returned - * provider will not be valid until the injector has been created. The provider will throw an - * {@code IllegalStateException} if you try to use it beforehand. - */ - Provider getProvider(Key key); - - /** - * Returns the provider used to obtain instances for the given injection type. The returned - * provider will not be valid until the injetor has been created. The provider will throw an - * {@code IllegalStateException} if you try to use it beforehand. - */ - Provider getProvider(Class type); - - /** - * Returns the members injector used to inject dependencies into methods and fields on instances - * of the given type {@code T}. The returned members injector will not be valid until the main - * injector has been created. The members injector will throw an {@code IllegalStateException} - * if you try to use it beforehand. - * - * @param typeLiteral type to get members injector for - */ - MembersInjector getMembersInjector(TypeLiteral typeLiteral); - - /** - * Returns the members injector used to inject dependencies into methods and fields on instances - * of the given type {@code T}. The returned members injector will not be valid until the main - * injector has been created. The members injector will throw an {@code IllegalStateException} - * if you try to use it beforehand. - * - * @param type type to get members injector for - */ - MembersInjector getMembersInjector(Class type); - - /** - * Registers a members injector for type {@code I}. Guice will use the members injector after its - * performed its own injections on an instance of {@code I}. - */ - void register(MembersInjector membersInjector); - - /** - * Registers an injection listener for type {@code I}. Guice will notify the listener after all - * injections have been performed on an instance of {@code I}. - */ - void register(InjectionListener listener); -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeListener.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeListener.java deleted file mode 100644 index 55a29433ea1..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.TypeLiteral; - -/** - * Listens for Guice to encounter injectable types. If a given type has its constructor injected in - * one situation but only its methods and fields injected in another, Guice will notify this - * listener once. - * - *

Useful for extra type checking, {@linkplain TypeEncounter#register(InjectionListener) - * registering injection listeners}, and {@linkplain TypeEncounter#bindInterceptor( - * org.elasticsearch.util.inject.matcher.Matcher, org.aopalliance.intercept.MethodInterceptor[]) - * binding method interceptors}. - * - * @since 2.0 - */ -public interface TypeListener { - - /** - * Invoked when Guice encounters a new type eligible for constructor or members injection. - * Called during injector creation (or afterwords if Guice encounters a type at run time and - * creates a JIT binding). - * - * @param type encountered by Guice - * @param encounter context of this encounter, enables reporting errors, registering injection - * listeners and binding method interceptors for {@code type}. - * - * @param the injectable type - */ - void hear(TypeLiteral type, TypeEncounter encounter); - -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeListenerBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeListenerBinding.java deleted file mode 100644 index 72a9a762cc9..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/TypeListenerBinding.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binder; -import org.elasticsearch.util.inject.TypeLiteral; -import org.elasticsearch.util.inject.matcher.Matcher; - -/** - * Binds types (picked using a Matcher) to an type listener. Registrations are created explicitly in - * a module using {@link org.elasticsearch.util.inject.Binder#bindListener(Matcher, TypeListener)} statements: - * - *

- *     register(only(new TypeLiteral<PaymentService<CreditCard>>() {}), listener);
- * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class TypeListenerBinding implements Element { - - private final Object source; - private final Matcher> typeMatcher; - private final TypeListener listener; - - TypeListenerBinding(Object source, TypeListener listener, - Matcher> typeMatcher) { - this.source = source; - this.listener = listener; - this.typeMatcher = typeMatcher; - } - - /** Returns the registered listener. */ - public TypeListener getListener() { - return listener; - } - - /** Returns the type matcher which chooses which types the listener should be notified of. */ - public Matcher> getTypeMatcher() { - return typeMatcher; - } - - public Object getSource() { - return source; - } - - public T acceptVisitor(ElementVisitor visitor) { - return visitor.visit(this); - } - - public void applyTo(Binder binder) { - binder.withSource(getSource()).bindListener(typeMatcher, listener); - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/UntargettedBinding.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/UntargettedBinding.java deleted file mode 100644 index d0c0f6787ac..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/UntargettedBinding.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.spi; - -import org.elasticsearch.util.inject.Binding; - -/** - * An untargetted binding. This binding indicates that the injector should use its implicit binding - * strategies to resolve injections. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public interface UntargettedBinding extends Binding {} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/package-info.java deleted file mode 100644 index 516d029952b..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/spi/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2006 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Guice service provider interface - */ - -package org.elasticsearch.util.inject.spi; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Modules.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Modules.java deleted file mode 100644 index d9c3ea0feac..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Modules.java +++ /dev/null @@ -1,259 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.util; - -import org.elasticsearch.util.collect.ImmutableSet; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.collect.Sets; -import org.elasticsearch.util.inject.*; -import org.elasticsearch.util.inject.spi.*; - -import java.lang.annotation.Annotation; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Static utility methods for creating and working with instances of {@link Module}. - * - * @author jessewilson@google.com (Jesse Wilson) - * @since 2.0 - */ -public final class Modules { - private Modules() {} - - public static final Module EMPTY_MODULE = new Module() { - public void configure(Binder binder) {} - }; - - /** - * Returns a builder that creates a module that overlays override modules over the given - * modules. If a key is bound in both sets of modules, only the binding from the override modules - * is kept. This can be used to replace the bindings of a production module with test bindings: - *
-   * Module functionalTestModule
-   *     = Modules.override(new ProductionModule()).with(new TestModule());
-   * 
- * - *

Prefer to write smaller modules that can be reused and tested without overrides. - * - * @param modules the modules whose bindings are open to be overridden - */ - public static OverriddenModuleBuilder override(Module... modules) { - return new RealOverriddenModuleBuilder(Arrays.asList(modules)); - } - - /** - * Returns a builder that creates a module that overlays override modules over the given - * modules. If a key is bound in both sets of modules, only the binding from the override modules - * is kept. This can be used to replace the bindings of a production module with test bindings: - *

-   * Module functionalTestModule
-   *     = Modules.override(getProductionModules()).with(getTestModules());
-   * 
- * - *

Prefer to write smaller modules that can be reused and tested without overrides. - * - * @param modules the modules whose bindings are open to be overridden - */ - public static OverriddenModuleBuilder override(Iterable modules) { - return new RealOverriddenModuleBuilder(modules); - } - - /** - * Returns a new module that installs all of {@code modules}. - */ - public static Module combine(Module... modules) { - return combine(ImmutableSet.of(modules)); - } - - /** - * Returns a new module that installs all of {@code modules}. - */ - public static Module combine(Iterable modules) { - final Set modulesSet = ImmutableSet.copyOf(modules); - return new Module() { - public void configure(Binder binder) { - binder = binder.skipSources(getClass()); - for (Module module : modulesSet) { - binder.install(module); - } - } - }; - } - - /** - * See the EDSL example at {@link Modules#override(Module[]) override()}. - */ - public interface OverriddenModuleBuilder { - - /** - * See the EDSL example at {@link Modules#override(Module[]) override()}. - */ - Module with(Module... overrides); - - /** - * See the EDSL example at {@link Modules#override(Module[]) override()}. - */ - Module with(Iterable overrides); - } - - private static final class RealOverriddenModuleBuilder implements OverriddenModuleBuilder { - private final ImmutableSet baseModules; - - private RealOverriddenModuleBuilder(Iterable baseModules) { - this.baseModules = ImmutableSet.copyOf(baseModules); - } - - public Module with(Module... overrides) { - return with(Arrays.asList(overrides)); - } - - public Module with(final Iterable overrides) { - return new AbstractModule() { - @Override - public void configure() { - final List elements = Elements.getElements(baseModules); - final List overrideElements = Elements.getElements(overrides); - - final Set overriddenKeys = Sets.newHashSet(); - final Set> overridesScopeAnnotations = Sets.newHashSet(); - - // execute the overrides module, keeping track of which keys and scopes are bound - new ModuleWriter(binder()) { - @Override public Void visit(Binding binding) { - overriddenKeys.add(binding.getKey()); - return super.visit(binding); - } - - @Override public Void visit(ScopeBinding scopeBinding) { - overridesScopeAnnotations.add(scopeBinding.getAnnotationType()); - return super.visit(scopeBinding); - } - - @Override public Void visit(PrivateElements privateElements) { - overriddenKeys.addAll(privateElements.getExposedKeys()); - return super.visit(privateElements); - } - }.writeAll(overrideElements); - - // execute the original module, skipping all scopes and overridden keys. We only skip each - // overridden binding once so things still blow up if the module binds the same thing - // multiple times. - final Map scopeInstancesInUse = Maps.newHashMap(); - final List scopeBindings = Lists.newArrayList(); - new ModuleWriter(binder()) { - @Override public Void visit(Binding binding) { - if (!overriddenKeys.remove(binding.getKey())) { - super.visit(binding); - - // Record when a scope instance is used in a binding - Scope scope = getScopeInstanceOrNull(binding); - if (scope != null) { - scopeInstancesInUse.put(scope, binding.getSource()); - } - } - - return null; - } - - @Override public Void visit(PrivateElements privateElements) { - PrivateBinder privateBinder = binder.withSource(privateElements.getSource()) - .newPrivateBinder(); - - Set> skippedExposes = Sets.newHashSet(); - - for (Key key : privateElements.getExposedKeys()) { - if (overriddenKeys.remove(key)) { - skippedExposes.add(key); - } else { - privateBinder.withSource(privateElements.getExposedSource(key)).expose(key); - } - } - - // we're not skipping deep exposes, but that should be okay. If we ever need to, we - // have to search through this set of elements for PrivateElements, recursively - for (Element element : privateElements.getElements()) { - if (element instanceof Binding - && skippedExposes.contains(((Binding) element).getKey())) { - continue; - } - element.applyTo(privateBinder); - } - - return null; - } - - @Override public Void visit(ScopeBinding scopeBinding) { - scopeBindings.add(scopeBinding); - return null; - } - }.writeAll(elements); - - // execute the scope bindings, skipping scopes that have been overridden. Any scope that - // is overridden and in active use will prompt an error - new ModuleWriter(binder()) { - @Override public Void visit(ScopeBinding scopeBinding) { - if (!overridesScopeAnnotations.remove(scopeBinding.getAnnotationType())) { - super.visit(scopeBinding); - } else { - Object source = scopeInstancesInUse.get(scopeBinding.getScope()); - if (source != null) { - binder().withSource(source).addError( - "The scope for @%s is bound directly and cannot be overridden.", - scopeBinding.getAnnotationType().getSimpleName()); - } - } - return null; - } - }.writeAll(scopeBindings); - - // TODO: bind the overridden keys using multibinder - } - - private Scope getScopeInstanceOrNull(Binding binding) { - return binding.acceptScopingVisitor(new DefaultBindingScopingVisitor() { - public Scope visitScope(Scope scope) { - return scope; - } - }); - } - }; - } - } - - private static class ModuleWriter extends DefaultElementVisitor { - protected final Binder binder; - - ModuleWriter(Binder binder) { - this.binder = binder; - } - - @Override protected Void visitOther(Element element) { - element.applyTo(binder); - return null; - } - - void writeAll(Iterable elements) { - for (Element element : elements) { - element.acceptVisitor(this); - } - } - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Providers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Providers.java deleted file mode 100644 index 37b87965de0..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Providers.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.elasticsearch.util.inject.util; - -import org.elasticsearch.util.inject.Provider; - -/** - * Static utility methods for creating and working with instances of - * {@link Provider}. - * - * @author Kevin Bourrillion (kevinb9n@gmail.com) - * @since 2.0 - */ -public final class Providers { - - private Providers() {} - - /** - * Returns a provider which always provides {@code instance}. This should not - * be necessary to use in your application, but is helpful for several types - * of unit tests. - * - * @param instance the instance that should always be provided. This is also - * permitted to be null, to enable aggressive testing, although in real - * life a Guice-supplied Provider will never return null. - */ - public static Provider of(final T instance) { - return new Provider() { - public T get() { - return instance; - } - - @Override public String toString() { - return "of(" + instance + ")"; - } - }; - } -} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Types.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Types.java deleted file mode 100644 index 9e86bf74174..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/Types.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.elasticsearch.util.inject.util; - -import org.elasticsearch.util.inject.Provider; -import org.elasticsearch.util.inject.internal.MoreTypes; -import org.elasticsearch.util.inject.internal.MoreTypes.GenericArrayTypeImpl; -import org.elasticsearch.util.inject.internal.MoreTypes.ParameterizedTypeImpl; -import org.elasticsearch.util.inject.internal.MoreTypes.WildcardTypeImpl; -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.WildcardType; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Static methods for working with types. - * - * @author crazybob@google.com (Bob Lee) - * @since 2.0 - */ -public final class Types { - private Types() {} - - /** - * Returns a new parameterized type, applying {@code typeArguments} to - * {@code rawType}. The returned type does not have an owner type. - * - * @return a {@link java.io.Serializable serializable} parameterized type. - */ - public static ParameterizedType newParameterizedType(Type rawType, Type... typeArguments) { - return newParameterizedTypeWithOwner(null, rawType, typeArguments); - } - - /** - * Returns a new parameterized type, applying {@code typeArguments} to - * {@code rawType} and enclosed by {@code ownerType}. - * - * @return a {@link java.io.Serializable serializable} parameterized type. - */ - public static ParameterizedType newParameterizedTypeWithOwner( - Type ownerType, Type rawType, Type... typeArguments) { - return new ParameterizedTypeImpl(ownerType, rawType, typeArguments); - } - - /** - * Returns an array type whose elements are all instances of - * {@code componentType}. - * - * @return a {@link java.io.Serializable serializable} generic array type. - */ - public static GenericArrayType arrayOf(Type componentType) { - return new GenericArrayTypeImpl(componentType); - } - - /** - * Returns a type that represents an unknown type that extends {@code bound}. - * For example, if {@code bound} is {@code CharSequence.class}, this returns - * {@code ? extends CharSequence}. If {@code bound} is {@code Object.class}, - * this returns {@code ?}, which is shorthand for {@code ? extends Object}. - */ - public static WildcardType subtypeOf(Type bound) { - return new WildcardTypeImpl(new Type[] { bound }, MoreTypes.EMPTY_TYPE_ARRAY); - } - - /** - * Returns a type that represents an unknown supertype of {@code bound}. For - * example, if {@code bound} is {@code String.class}, this returns {@code ? - * super String}. - */ - public static WildcardType supertypeOf(Type bound) { - return new WildcardTypeImpl(new Type[] { Object.class }, new Type[] { bound }); - } - - /** - * Returns a type modelling a {@link List} whose elements are of type - * {@code elementType}. - * - * @return a {@link java.io.Serializable serializable} parameterized type. - */ - public static ParameterizedType listOf(Type elementType) { - return newParameterizedType(List.class, elementType); - } - - /** - * Returns a type modelling a {@link Set} whose elements are of type - * {@code elementType}. - * - * @return a {@link java.io.Serializable serializable} parameterized type. - */ - public static ParameterizedType setOf(Type elementType) { - return newParameterizedType(Set.class, elementType); - } - - /** - * Returns a type modelling a {@link Map} whose keys are of type - * {@code keyType} and whose values are of type {@code valueType}. - * - * @return a {@link java.io.Serializable serializable} parameterized type. - */ - public static ParameterizedType mapOf(Type keyType, Type valueType) { - return newParameterizedType(Map.class, keyType, valueType); - } - - // for other custom collections types, use newParameterizedType() - - /** - * Returns a type modelling a {@link Provider} that provides elements of type - * {@code elementType}. - * - * @return a {@link java.io.Serializable serializable} parameterized type. - */ - public static ParameterizedType providerOf(Type providedType) { - return newParameterizedType(Provider.class, providedType); - } -} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/package-info.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/package-info.java deleted file mode 100644 index 5c680b4b5d2..00000000000 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/inject/util/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Helper methods for working with Guice. - */ -package org.elasticsearch.util.inject.util; \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/io/stream/HandlesStreamInput.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/io/stream/HandlesStreamInput.java index f5af82e68a9..2d57fde089b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/io/stream/HandlesStreamInput.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/io/stream/HandlesStreamInput.java @@ -19,8 +19,8 @@ package org.elasticsearch.util.io.stream; +import org.elasticsearch.common.trove.TIntObjectHashMap; import org.elasticsearch.util.ThreadLocals; -import org.elasticsearch.util.gnu.trove.TIntObjectHashMap; import java.io.IOException; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/io/stream/HandlesStreamOutput.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/io/stream/HandlesStreamOutput.java index dbdfc3a7d94..8c47dca47d9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/io/stream/HandlesStreamOutput.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/io/stream/HandlesStreamOutput.java @@ -19,8 +19,8 @@ package org.elasticsearch.util.io.stream; -import org.elasticsearch.util.gnu.trove.TObjectIntHashMap; -import org.elasticsearch.util.trove.ExtTObjectIntHasMap; +import org.elasticsearch.common.trove.ExtTObjectIntHasMap; +import org.elasticsearch.common.trove.TObjectIntHashMap; import java.io.IOException; import java.util.Arrays; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetaDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetaDataTests.java index fe31c6565c7..620120ced2a 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetaDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetaDataTests.java @@ -19,15 +19,15 @@ package org.elasticsearch.cluster.metadata; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.testng.annotations.Test; import java.io.IOException; import static org.elasticsearch.cluster.metadata.IndexMetaData.*; import static org.elasticsearch.cluster.metadata.MetaData.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/FailedShardsRoutingTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/FailedShardsRoutingTests.java index 9bf9e77b77e..43710440c49 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/FailedShardsRoutingTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/FailedShardsRoutingTests.java @@ -25,9 +25,9 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.MutableShardRouting; import org.elasticsearch.cluster.routing.RoutingNodes; import org.elasticsearch.cluster.routing.RoutingTable; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.transport.DummyTransportAddress; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.transport.DummyTransportAddress; import org.testng.annotations.Test; import java.util.List; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/SingleShardNoBackupsRoutingStrategyTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/SingleShardNoBackupsRoutingStrategyTests.java index 28c500996ae..9ea726ef2d1 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/SingleShardNoBackupsRoutingStrategyTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/SingleShardNoBackupsRoutingStrategyTests.java @@ -27,9 +27,9 @@ import org.elasticsearch.cluster.routing.MutableShardRouting; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.RoutingNodes; import org.elasticsearch.cluster.routing.RoutingTable; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.transport.DummyTransportAddress; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.transport.DummyTransportAddress; import org.testng.annotations.Test; import java.util.List; @@ -41,8 +41,8 @@ import static org.elasticsearch.cluster.metadata.MetaData.*; import static org.elasticsearch.cluster.node.DiscoveryNodes.*; import static org.elasticsearch.cluster.routing.RoutingBuilders.*; import static org.elasticsearch.cluster.routing.ShardRoutingState.*; -import static org.elasticsearch.util.collect.Lists.*; -import static org.elasticsearch.util.collect.Sets.*; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Sets.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/SingleShardOneBackupRoutingStrategyTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/SingleShardOneBackupRoutingStrategyTests.java index c126818df22..08b189331f9 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/SingleShardOneBackupRoutingStrategyTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/SingleShardOneBackupRoutingStrategyTests.java @@ -24,9 +24,9 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.RoutingNodes; import org.elasticsearch.cluster.routing.RoutingTable; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.transport.DummyTransportAddress; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.transport.DummyTransportAddress; import org.testng.annotations.Test; import static org.elasticsearch.cluster.ClusterState.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/TenShardsOneBackupRoutingTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/TenShardsOneBackupRoutingTests.java index 94b9d7d5df9..7f176fa5003 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/TenShardsOneBackupRoutingTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/routing/strategy/TenShardsOneBackupRoutingTests.java @@ -24,9 +24,9 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.RoutingNodes; import org.elasticsearch.cluster.routing.RoutingTable; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.transport.DummyTransportAddress; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.transport.DummyTransportAddress; import org.testng.annotations.Test; import static org.elasticsearch.cluster.ClusterState.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/serialization/ClusterSerializationTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/serialization/ClusterSerializationTests.java index b245dcb0b90..340988f4c58 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/serialization/ClusterSerializationTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/cluster/serialization/ClusterSerializationTests.java @@ -25,10 +25,10 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.strategy.DefaultShardsRoutingStrategy; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.util.io.stream.BytesStreamInput; import org.elasticsearch.util.io.stream.BytesStreamOutput; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.transport.DummyTransportAddress; import org.testng.annotations.Test; import static org.elasticsearch.cluster.ClusterState.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/IndexWritersTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/IndexWritersTests.java similarity index 92% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/IndexWritersTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/IndexWritersTests.java index bbc1e0e7726..957f1829c8f 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/IndexWritersTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/IndexWritersTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene; +package org.elasticsearch.common.lucene; import org.apache.lucene.document.Field; import org.apache.lucene.document.NumericField; @@ -27,8 +27,8 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.testng.annotations.Test; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; -import static org.elasticsearch.util.lucene.IndexWriters.*; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.lucene.IndexWriters.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/all/SimpleAllTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/all/SimpleAllTests.java similarity index 99% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/all/SimpleAllTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/all/SimpleAllTests.java index e54bff3a56c..fba4af7fd2c 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/all/SimpleAllTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/all/SimpleAllTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.all; +package org.elasticsearch.common.lucene.all; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -28,7 +28,7 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; -import org.elasticsearch.util.lucene.Lucene; +import org.elasticsearch.common.lucene.Lucene; import org.testng.annotations.Test; import static org.hamcrest.MatcherAssert.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/search/MoreLikeThisQueryTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/search/MoreLikeThisQueryTests.java similarity index 91% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/search/MoreLikeThisQueryTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/search/MoreLikeThisQueryTests.java index e3d1e81376f..74aaf580b70 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/search/MoreLikeThisQueryTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/search/MoreLikeThisQueryTests.java @@ -17,18 +17,18 @@ * under the License. */ -package org.elasticsearch.util.lucene.search; +package org.elasticsearch.common.lucene.search; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; -import org.elasticsearch.util.lucene.Lucene; +import org.elasticsearch.common.lucene.Lucene; import org.testng.annotations.Test; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; -import static org.elasticsearch.util.lucene.IndexWriters.*; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.lucene.IndexWriters.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/store/InputStreamIndexInputTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/store/InputStreamIndexInputTests.java similarity index 99% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/store/InputStreamIndexInputTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/store/InputStreamIndexInputTests.java index a9c82e82b57..c4131f743b2 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/store/InputStreamIndexInputTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/store/InputStreamIndexInputTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.store; +package org.elasticsearch.common.lucene.store; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexOutput; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/AbstractVersionedMapTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/AbstractVersionedMapTests.java similarity index 97% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/AbstractVersionedMapTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/AbstractVersionedMapTests.java index 996f684479f..99cf3e25664 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/AbstractVersionedMapTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/AbstractVersionedMapTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.versioned; +package org.elasticsearch.common.lucene.versioned; import org.testng.annotations.Test; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/NativeVersionedMapTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/NativeVersionedMapTests.java similarity index 95% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/NativeVersionedMapTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/NativeVersionedMapTests.java index 51ddf008455..61b2ffdcd3e 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/NativeVersionedMapTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/NativeVersionedMapTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.versioned; +package org.elasticsearch.common.lucene.versioned; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/NonBlockingVersionedMapTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/NonBlockingVersionedMapTests.java similarity index 95% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/NonBlockingVersionedMapTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/NonBlockingVersionedMapTests.java index 7a2ec58a722..d8713bb37ea 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/NonBlockingVersionedMapTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/NonBlockingVersionedMapTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.versioned; +package org.elasticsearch.common.lucene.versioned; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/VersionedIndexReaderTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReaderTests.java similarity index 96% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/VersionedIndexReaderTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReaderTests.java index e78f6f04a8e..c1ffc053ec6 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/lucene/versioned/VersionedIndexReaderTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReaderTests.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.util.lucene.versioned; +package org.elasticsearch.common.lucene.versioned; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; @@ -25,12 +25,12 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.index.TermDocs; import org.apache.lucene.store.RAMDirectory; -import org.elasticsearch.util.lucene.Lucene; +import org.elasticsearch.common.lucene.Lucene; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/path/PathTrieTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/path/PathTrieTests.java similarity index 96% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/path/PathTrieTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/path/PathTrieTests.java index e9bea16527d..d0a8c5b5e18 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/path/PathTrieTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/path/PathTrieTests.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.util.path; +package org.elasticsearch.common.path; import org.testng.annotations.Test; import java.util.Map; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Maps.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/JsonSettingsLoaderTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java similarity index 91% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/JsonSettingsLoaderTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java index 0d3d0469ca6..f3b8bfac685 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/JsonSettingsLoaderTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.util.settings.loader; +package org.elasticsearch.common.settings.loader; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.settings.Settings; import org.testng.annotations.Test; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/YamlSettingsLoaderTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java similarity index 91% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/YamlSettingsLoaderTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java index 830eb41355c..56bdde77dfc 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/YamlSettingsLoaderTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java @@ -17,12 +17,12 @@ * under the License. */ -package org.elasticsearch.util.settings.loader; +package org.elasticsearch.common.settings.loader; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.settings.Settings; import org.testng.annotations.Test; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/test-settings.json b/modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/test-settings.json similarity index 100% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/test-settings.json rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/test-settings.json diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/test-settings.yml b/modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/test-settings.yml similarity index 100% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/settings/loader/test-settings.yml rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/settings/loader/test-settings.yml diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/xcontent/builder/XContentBuilderTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java similarity index 92% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/xcontent/builder/XContentBuilderTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java index 6ab3438d9e0..79eece52c8b 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/xcontent/builder/XContentBuilderTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java @@ -17,16 +17,16 @@ * under the License. */ -package org.elasticsearch.util.xcontent.builder; +package org.elasticsearch.common.xcontent.builder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentGenerator; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.util.io.FastByteArrayOutputStream; import org.elasticsearch.util.io.FastCharArrayWriter; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentGenerator; -import org.elasticsearch.util.xcontent.XContentType; import org.testng.annotations.Test; -import static org.elasticsearch.util.xcontent.builder.XContentBuilder.FieldCaseConversion.*; +import static org.elasticsearch.common.xcontent.builder.XContentBuilder.FieldCaseConversion.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/xcontent/xson/JsonVsXsonTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/xcontent/xson/JsonVsXsonTests.java similarity index 92% rename from modules/elasticsearch/src/test/java/org/elasticsearch/util/xcontent/xson/JsonVsXsonTests.java rename to modules/elasticsearch/src/test/java/org/elasticsearch/common/xcontent/xson/JsonVsXsonTests.java index 81f518cb6d8..6d8268213c3 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/xcontent/xson/JsonVsXsonTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/xcontent/xson/JsonVsXsonTests.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.util.xcontent.xson; +package org.elasticsearch.common.xcontent.xson; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentGenerator; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.util.io.FastByteArrayOutputStream; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentGenerator; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.XContentType; import org.testng.annotations.Test; import java.io.IOException; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/jackson/JacksonLocationTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/jackson/JacksonLocationTests.java index 7dd1a9134c9..3c530bcf18f 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/jackson/JacksonLocationTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/jackson/JacksonLocationTests.java @@ -19,7 +19,7 @@ package org.elasticsearch.deps.jackson; -import org.codehaus.jackson.*; +import org.elasticsearch.common.jackson.*; import org.elasticsearch.util.io.FastByteArrayOutputStream; import org.testng.annotations.Test; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/joda/SimpleJodaTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/joda/SimpleJodaTests.java index 5bfc86bd55e..4f8327db115 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/joda/SimpleJodaTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/joda/SimpleJodaTests.java @@ -19,12 +19,12 @@ package org.elasticsearch.deps.joda; -import org.elasticsearch.util.joda.FormatDateTimeFormatter; -import org.elasticsearch.util.joda.Joda; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; +import org.elasticsearch.common.joda.FormatDateTimeFormatter; +import org.elasticsearch.common.joda.Joda; +import org.elasticsearch.common.joda.time.DateTimeZone; +import org.elasticsearch.common.joda.time.format.DateTimeFormat; +import org.elasticsearch.common.joda.time.format.DateTimeFormatter; +import org.elasticsearch.common.joda.time.format.ISODateTimeFormat; import org.testng.annotations.Test; import java.util.Date; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/IndexWriterNoBufferTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/IndexWriterNoBufferTests.java index e31f2256cee..e118fa68ce8 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/IndexWriterNoBufferTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/IndexWriterNoBufferTests.java @@ -22,11 +22,11 @@ package org.elasticsearch.deps.lucene; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; -import org.elasticsearch.util.lucene.IndexWriters; -import org.elasticsearch.util.lucene.Lucene; +import org.elasticsearch.common.lucene.IndexWriters; +import org.elasticsearch.common.lucene.Lucene; import org.testng.annotations.Test; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/LuceneFieldCacheTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/LuceneFieldCacheTests.java index 664c7dc8c1a..ca66da9148d 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/LuceneFieldCacheTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/LuceneFieldCacheTests.java @@ -26,7 +26,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.search.FieldCache; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; -import org.elasticsearch.util.lucene.Lucene; +import org.elasticsearch.common.lucene.Lucene; import org.testng.annotations.Test; import static org.hamcrest.MatcherAssert.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/SimpleLuceneTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/SimpleLuceneTests.java index 4ff115ff3ff..d3aa389423a 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/SimpleLuceneTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/SimpleLuceneTests.java @@ -27,8 +27,8 @@ import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.NumericUtils; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.lucene.Lucene; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.lucene.Lucene; import org.testng.annotations.Test; import java.io.IOException; @@ -36,7 +36,7 @@ import java.util.ArrayList; import java.util.IdentityHashMap; import java.util.List; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/VectorHighlighterTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/VectorHighlighterTests.java index 736c18fbcdf..53fc36e4adb 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/VectorHighlighterTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/deps/lucene/VectorHighlighterTests.java @@ -28,10 +28,10 @@ import org.apache.lucene.search.vectorhighlight.CustomFieldQuery; import org.apache.lucene.search.vectorhighlight.FastVectorHighlighter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; -import org.elasticsearch.util.lucene.Lucene; +import org.elasticsearch.common.lucene.Lucene; import org.testng.annotations.Test; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java index 9f90a7138a6..2f0b246847d 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java @@ -22,6 +22,9 @@ package org.elasticsearch.discovery.zen.ping.unicast; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.discovery.zen.DiscoveryNodesProvider; import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.threadpool.ThreadPool; @@ -30,9 +33,6 @@ import org.elasticsearch.timer.TimerService; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.netty.NettyTransport; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.transport.InetSocketTransportAddress; import org.testng.annotations.Test; import static org.hamcrest.MatcherAssert.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index 8bcb7e5a945..d4ed3756bb3 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -19,16 +19,16 @@ package org.elasticsearch.index.analysis; -import org.elasticsearch.util.inject.Guice; -import org.elasticsearch.util.inject.Injector; import org.apache.lucene.analysis.Analyzer; +import org.elasticsearch.common.inject.Guice; +import org.elasticsearch.common.inject.Injector; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.settings.IndexSettingsModule; -import org.elasticsearch.util.settings.Settings; import org.testng.annotations.Test; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/cache/filter/FilterCacheTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/cache/filter/FilterCacheTests.java index 5d8cd7106d5..f63b8342ba3 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/cache/filter/FilterCacheTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/cache/filter/FilterCacheTests.java @@ -25,18 +25,18 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.index.Index; import org.elasticsearch.index.cache.filter.none.NoneFilterCache; import org.elasticsearch.index.cache.filter.soft.SoftFilterCache; import org.elasticsearch.index.cache.filter.weak.WeakFilterCache; -import org.elasticsearch.util.lucene.Lucene; -import org.elasticsearch.util.lucene.search.TermFilter; import org.testng.annotations.Test; import java.io.IOException; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java index 55f7f26fc35..6c5bbef5219 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java @@ -21,16 +21,16 @@ package org.elasticsearch.index.deletionpolicy; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.util.lucene.Lucene; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import static org.elasticsearch.util.lucene.Directories.*; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.lucene.Directories.*; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/AbstractSimpleEngineTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/AbstractSimpleEngineTests.java index b97dfcde62c..0d77d02cf3b 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/AbstractSimpleEngineTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/AbstractSimpleEngineTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.engine; import org.apache.lucene.index.IndexDeletionPolicy; import org.apache.lucene.index.Term; import org.apache.lucene.search.TermQuery; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.Index; import org.elasticsearch.index.deletionpolicy.KeepOnlyLastDeletionPolicy; import org.elasticsearch.index.deletionpolicy.SnapshotDeletionPolicy; @@ -35,7 +36,6 @@ import org.elasticsearch.index.store.Store; import org.elasticsearch.index.store.ram.RamStore; import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.memory.MemoryTranslog; -import org.elasticsearch.util.lucene.Lucene; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -45,11 +45,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.elasticsearch.index.deletionpolicy.SnapshotIndexCommitExistsMatcher.*; import static org.elasticsearch.index.engine.EngineSearcherTotalHitsMatcher.*; import static org.elasticsearch.index.translog.TranslogSizeMatcher.*; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/EngineSearcherTotalHitsMatcher.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/EngineSearcherTotalHitsMatcher.java index 1ffcbaccf22..c62af1fb311 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/EngineSearcherTotalHitsMatcher.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/EngineSearcherTotalHitsMatcher.java @@ -21,7 +21,7 @@ package org.elasticsearch.index.engine; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; -import org.elasticsearch.util.lucene.Lucene; +import org.elasticsearch.common.lucene.Lucene; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/robin/SimpleRobinEngineTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/robin/SimpleRobinEngineTests.java index 87da2270dfd..1d3543708d7 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/robin/SimpleRobinEngineTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/engine/robin/SimpleRobinEngineTests.java @@ -25,7 +25,7 @@ import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.index.store.Store; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; /** * @author kimchy diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataTests.java index 583563ccafd..0073a54dcf8 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/doubles/DoubleFieldDataTests.java @@ -24,16 +24,16 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.lucene.Lucene; import org.testng.annotations.Test; import java.util.ArrayList; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.elasticsearch.index.field.data.FieldDataOptions.*; import static org.elasticsearch.util.Tuple.*; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/floats/FloatFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/floats/FloatFieldDataTests.java index 58af03beb87..7af1146054f 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/floats/FloatFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/floats/FloatFieldDataTests.java @@ -24,16 +24,16 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.lucene.Lucene; import org.testng.annotations.Test; import java.util.ArrayList; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.elasticsearch.index.field.data.FieldDataOptions.*; import static org.elasticsearch.util.Tuple.*; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/ints/IntFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/ints/IntFieldDataTests.java index b07d5b1b7c3..107a430af42 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/ints/IntFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/ints/IntFieldDataTests.java @@ -24,16 +24,16 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.lucene.Lucene; import org.testng.annotations.Test; import java.util.ArrayList; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.elasticsearch.index.field.data.FieldDataOptions.*; import static org.elasticsearch.util.Tuple.*; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/longs/LongFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/longs/LongFieldDataTests.java index d48e46f4b6b..694fee85bac 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/longs/LongFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/longs/LongFieldDataTests.java @@ -24,16 +24,16 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.lucene.Lucene; import org.testng.annotations.Test; import java.util.ArrayList; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.elasticsearch.index.field.data.FieldDataOptions.*; import static org.elasticsearch.util.Tuple.*; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataTests.java index d6038e5ce9d..6599ef8ef87 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/shorts/ShortFieldDataTests.java @@ -24,16 +24,16 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.lucene.Lucene; import org.testng.annotations.Test; import java.util.ArrayList; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.elasticsearch.index.field.data.FieldDataOptions.*; import static org.elasticsearch.util.Tuple.*; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/strings/StringFieldDataTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/strings/StringFieldDataTests.java index 275900132d2..6f9e6e47f56 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/strings/StringFieldDataTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/field/data/strings/StringFieldDataTests.java @@ -23,16 +23,16 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.field.data.FieldData; import org.elasticsearch.util.Tuple; -import org.elasticsearch.util.lucene.Lucene; import org.testng.annotations.Test; import java.util.ArrayList; +import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.elasticsearch.index.field.data.FieldDataOptions.*; import static org.elasticsearch.util.Tuple.*; -import static org.elasticsearch.util.lucene.DocumentBuilder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/all/SimpleAllMapperTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/all/SimpleAllMapperTests.java index 10479f52771..b9688eebd0d 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/all/SimpleAllMapperTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/all/SimpleAllMapperTests.java @@ -20,13 +20,13 @@ package org.elasticsearch.index.mapper.xcontent.all; import org.apache.lucene.document.Document; +import org.elasticsearch.common.lucene.all.AllEntries; +import org.elasticsearch.common.lucene.all.AllField; +import org.elasticsearch.common.lucene.all.AllTokenStream; import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapper; import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapperParser; -import org.elasticsearch.util.lucene.all.AllEntries; -import org.elasticsearch.util.lucene.all.AllField; -import org.elasticsearch.util.lucene.all.AllTokenStream; import org.testng.annotations.Test; import static org.elasticsearch.util.io.Streams.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java index 7c38d82f6c3..17f224105ba 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java @@ -23,6 +23,9 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.*; import org.apache.lucene.search.spans.*; import org.apache.lucene.util.NumericUtils; +import org.elasticsearch.common.lucene.search.*; +import org.elasticsearch.common.lucene.search.function.BoostScoreFunction; +import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.AnalysisService; @@ -31,9 +34,6 @@ import org.elasticsearch.index.engine.robin.RobinIndexEngine; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.IndexQueryParser; import org.elasticsearch.script.ScriptService; -import org.elasticsearch.util.lucene.search.*; -import org.elasticsearch.util.lucene.search.function.BoostScoreFunction; -import org.elasticsearch.util.lucene.search.function.FunctionScoreQuery; import org.testng.annotations.Test; import java.io.IOException; @@ -41,10 +41,10 @@ import java.lang.reflect.Field; import java.util.List; import java.util.Set; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.elasticsearch.index.query.xcontent.FilterBuilders.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.util.io.Streams.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/IndexQueryParserModuleTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/IndexQueryParserModuleTests.java index 5cebdd66323..80981b5d93b 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/IndexQueryParserModuleTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/IndexQueryParserModuleTests.java @@ -19,6 +19,10 @@ package org.elasticsearch.index.query.xcontent.guice; +import org.elasticsearch.common.inject.Guice; +import org.elasticsearch.common.inject.Injector; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.AnalysisModule; @@ -31,13 +35,9 @@ import org.elasticsearch.index.query.xcontent.XContentQueryParserRegistry; import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.index.similarity.SimilarityModule; import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.util.inject.Guice; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsModule; import org.testng.annotations.Test; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/MyJsonFilterParser.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/MyJsonFilterParser.java index 6faf8b7a708..774dfef45a6 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/MyJsonFilterParser.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/MyJsonFilterParser.java @@ -19,16 +19,16 @@ package org.elasticsearch.index.query.xcontent.guice; -import org.elasticsearch.index.query.xcontent.QueryParseContext; -import org.elasticsearch.index.query.xcontent.XContentFilterParser; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; import org.apache.lucene.search.Filter; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryParsingException; +import org.elasticsearch.index.query.xcontent.QueryParseContext; +import org.elasticsearch.index.query.xcontent.XContentFilterParser; import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/MyJsonQueryParser.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/MyJsonQueryParser.java index a0e8d244ff4..740d030178e 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/MyJsonQueryParser.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/guice/MyJsonQueryParser.java @@ -19,16 +19,16 @@ package org.elasticsearch.index.query.xcontent.guice; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; import org.apache.lucene.search.Query; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryParsingException; import org.elasticsearch.index.query.xcontent.QueryParseContext; import org.elasticsearch.index.query.xcontent.XContentQueryParser; import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/IndexQueryParserPluginTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/IndexQueryParserPluginTests.java index ef647d605b3..f3a251f173d 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/IndexQueryParserPluginTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/IndexQueryParserPluginTests.java @@ -19,6 +19,11 @@ package org.elasticsearch.index.query.xcontent.plugin; +import org.elasticsearch.common.inject.Guice; +import org.elasticsearch.common.inject.Injector; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.AnalysisModule; @@ -31,11 +36,6 @@ import org.elasticsearch.index.query.xcontent.XContentQueryParserRegistry; import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.index.similarity.SimilarityModule; import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.util.inject.Guice; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsModule; import org.testng.annotations.Test; import static org.hamcrest.MatcherAssert.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/PluginJsonFilterParser.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/PluginJsonFilterParser.java index e8b7b0634fc..0a9078a4ca5 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/PluginJsonFilterParser.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/PluginJsonFilterParser.java @@ -20,15 +20,15 @@ package org.elasticsearch.index.query.xcontent.plugin; import org.apache.lucene.search.Filter; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryParsingException; import org.elasticsearch.index.query.xcontent.QueryParseContext; import org.elasticsearch.index.query.xcontent.XContentFilterParser; import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/PluginJsonQueryParser.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/PluginJsonQueryParser.java index 38bf73785cb..4eaea5c0be7 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/PluginJsonQueryParser.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/plugin/PluginJsonQueryParser.java @@ -20,15 +20,15 @@ package org.elasticsearch.index.query.xcontent.plugin; import org.apache.lucene.search.Query; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryParsingException; import org.elasticsearch.index.query.xcontent.QueryParseContext; import org.elasticsearch.index.query.xcontent.XContentQueryParser; import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java index 2ac0b0fd5f8..02374f4de83 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.shard; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.cache.IndexCache; @@ -40,13 +41,12 @@ import org.elasticsearch.index.translog.memory.MemoryTranslog; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.scaling.ScalingThreadPool; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.settings.Settings; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/memory/MemorySimpleTranslogTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/memory/MemorySimpleTranslogTests.java index b5a13731a36..87187f83d96 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/memory/MemorySimpleTranslogTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/memory/MemorySimpleTranslogTests.java @@ -22,7 +22,7 @@ package org.elasticsearch.index.translog.memory; import org.elasticsearch.index.translog.AbstractSimpleTranslogTests; import org.elasticsearch.index.translog.Translog; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/monitor/jvm/DeadlockSimulator.java b/modules/elasticsearch/src/test/java/org/elasticsearch/monitor/jvm/DeadlockSimulator.java index 040a1b30406..fadcb7c6e49 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/monitor/jvm/DeadlockSimulator.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/monitor/jvm/DeadlockSimulator.java @@ -23,7 +23,7 @@ import org.elasticsearch.monitor.dump.DumpMonitorService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.scaling.ScalingThreadPool; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; /** * @author kimchy diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/rest/util/RestUtilsTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/rest/util/RestUtilsTests.java index 1c1c7a7df81..d02bc24c3d5 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/rest/util/RestUtilsTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/rest/util/RestUtilsTests.java @@ -24,7 +24,7 @@ import org.testng.annotations.Test; import java.util.Map; -import static org.elasticsearch.util.collect.Maps.*; +import static org.elasticsearch.common.collect.Maps.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java index abee21b2389..59136db1727 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java @@ -24,7 +24,7 @@ import org.elasticsearch.transport.AbstractSimpleTransportTests; import org.elasticsearch.transport.TransportService; import org.testng.annotations.Test; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; @Test public class SimpleNettyTransportTests extends AbstractSimpleTransportTests { diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyClient.java b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyClient.java index d55e0a7bb63..035d791d013 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyClient.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyClient.java @@ -20,6 +20,9 @@ package org.elasticsearch.transport.netty.benchmark; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.cached.CachedThreadPool; import org.elasticsearch.timer.TimerService; @@ -30,9 +33,6 @@ import org.elasticsearch.transport.netty.NettyTransport; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.StopWatch; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.transport.InetSocketTransportAddress; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicLong; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyServer.java b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyServer.java index 8faea99342c..4edc6675e6b 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyServer.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/transport/netty/benchmark/BenchmarkNettyServer.java @@ -19,6 +19,8 @@ package org.elasticsearch.transport.netty.benchmark; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.cached.CachedThreadPool; import org.elasticsearch.timer.TimerService; @@ -26,8 +28,6 @@ import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.netty.NettyTransport; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/TimeValueTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/util/TimeValueTests.java index cf2218e56bd..d490efe2ab5 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/TimeValueTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/util/TimeValueTests.java @@ -19,7 +19,7 @@ package org.elasticsearch.util; -import org.joda.time.PeriodType; +import org.elasticsearch.common.joda.time.PeriodType; import org.testng.annotations.Test; import java.util.concurrent.TimeUnit; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/util/guice/InjectorsTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/util/guice/InjectorsTests.java index 0dfde515e52..406df704a85 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/util/guice/InjectorsTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/util/guice/InjectorsTests.java @@ -19,11 +19,8 @@ package org.elasticsearch.util.guice; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.BindingAnnotation; -import org.elasticsearch.util.inject.Guice; -import org.elasticsearch.util.inject.Injector; -import org.elasticsearch.util.inject.matcher.Matchers; +import org.elasticsearch.common.inject.*; +import org.elasticsearch.common.inject.matcher.Matchers; import org.testng.annotations.Test; import java.lang.annotation.Documented; diff --git a/modules/jarjar/build.gradle b/modules/jarjar/build.gradle new file mode 100644 index 00000000000..11c71fa0f5b --- /dev/null +++ b/modules/jarjar/build.gradle @@ -0,0 +1,81 @@ +apply plugin: 'java' + +archivesBaseName = "$project.archivesBaseName" + +dependencies { + runtime 'aopalliance:aopalliance:1.0' + runtime 'com.google.inject:guice:2.0' + runtime 'com.google.inject.extensions:guice-assisted-inject:2.0' + runtime 'com.google.inject.extensions:guice-multibindings:2.0' + + runtime 'com.google.guava:guava:r05' + runtime 'org.elasticsearch:es-trove:2.1.0' + + runtime 'joda-time:joda-time:1.6' + runtime 'org.mvel:mvel2:2.0.17' + + runtime 'org.codehaus.jackson:jackson-core-asl:1.5.2' + runtime 'org.yaml:snakeyaml:1.6' + + runtime('org.jboss.netty:netty:3.2.0.CR1') { transitive = false } + runtime('com.ning:async-http-client:1.0.0-SNAPSHOT') { transitive = false } +} + +configurations { + tools +} + +dependencies { + tools "org.elasticsearch:es-jarjar:1.0.0" +} + +jar << { + jarjarArchivePath = new File(jar.archivePath.absolutePath + ".jarjar.jar") + project.ant { + taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask", classpath: configurations.tools.asPath + jarjar(jarfile: jarjarArchivePath) { + zipfileset(src: jar.archivePath) + configurations.runtime.files.findAll {file -> + ['mvel', 'jackson', 'joda', 'snakeyaml', 'netty', 'async-http-client', 'guice', 'aopalliance', 'guava', 'trove'].any { file.name.contains(it) } + }.each { jarjarFile -> + zipfileset(src: jarjarFile) { + exclude(name: "META-INF/**") + } + } + rule pattern: "com.google.common.**", result: "org.elasticsearch.common.@1" + rule pattern: "gnu.trove.**", result: "org.elasticsearch.common.trove.@1" + + rule pattern: "org.aopalliance.**", result: "org.elasticsearch.common.aopalliance.@1" + rule pattern: "com.google.inject.**", result: "org.elasticsearch.common.inject.@1" + + rule pattern: "org.mvel2.**", result: "org.elasticsearch.common.mvel2.@1" + + rule pattern: "org.codehaus.jackson.**", result: "org.elasticsearch.common.jackson.@1" + rule pattern: "org.yaml.**", result: "org.elasticsearch.common.yaml.@1" + + rule pattern: "org.joda.**", result: "org.elasticsearch.common.joda.@1" + + rule pattern: "org.jboss.netty.**", result: "org.elasticsearch.common.netty.@1" + rule pattern: "com.ning.http.**", result: "org.elasticsearch.common.http.@1" + } + delete(file: jar.archivePath) + copy(file: jarjarArchivePath, tofile: jar.archivePath) + delete(file: jarjarArchivePath) + + // seems like empty dirst still exists, unjar and clean them + unjar(src: jar.archivePath, dest: "build/tmp/extracted") + delete(dir: "build/tmp/extracted/gnu/trove") + delete(dir: "build/tmp/extracted/org/codehaus") + delete(dir: "build/tmp/extracted/org/aopalliance") + delete(dir: "build/tmp/extracted/com/google") + delete(dir: "build/tmp/extracted/org/mvel2") + delete(dir: "build/tmp/extracted/org/joda") + delete(dir: "build/tmp/extracted/org/yaml") + delete(dir: "build/tmp/extracted/org/jboss") + delete(dir: "build/tmp/extracted/com/ning") + + delete(file: jar.archivePath) + jar(destfile: jar.archivePath, basedir: "build/tmp/extracted") + delete(dir: "build/tmp/extracted") + } +} diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java index 3a9b58ebdfc..4e72fb2a7d5 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/AbstractNodesTests.java @@ -20,17 +20,17 @@ package org.elasticsearch.test.integration; import org.elasticsearch.client.Client; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.settings.Settings; import java.util.Map; +import static org.elasticsearch.common.collect.Maps.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.elasticsearch.node.NodeBuilder.*; -import static org.elasticsearch.util.collect.Maps.*; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; public abstract class AbstractNodesTests { diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/broadcast/BroadcastActionsTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/broadcast/BroadcastActionsTests.java index ba0ce3df38b..7f00b257d4d 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/broadcast/BroadcastActionsTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/broadcast/BroadcastActionsTests.java @@ -26,11 +26,11 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.test.integration.AbstractNodesTests; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/ClientTransportTwoServersSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/ClientTransportTwoServersSearchTests.java index 3bd798748c2..afffa03af62 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/ClientTransportTwoServersSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/ClientTransportTwoServersSearchTests.java @@ -21,10 +21,10 @@ package org.elasticsearch.test.integration.client.transport; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.test.integration.search.TransportTwoServersSearchTests; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.transport.TransportAddress; /** * @author kimchy (shay.banon) diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/DiscoveryTransportClientTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/DiscoveryTransportClientTests.java index 0aff9ecbe5f..fb2db2a8041 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/DiscoveryTransportClientTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/DiscoveryTransportClientTests.java @@ -20,8 +20,8 @@ package org.elasticsearch.test.integration.client.transport; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.test.integration.AbstractNodesTests; -import org.elasticsearch.util.settings.ImmutableSettings; import org.testng.annotations.AfterMethod; import static org.elasticsearch.client.Requests.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/TransportClientDocumentActionsTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/TransportClientDocumentActionsTests.java index a4e107f0cdf..1d8eaf72b20 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/TransportClientDocumentActionsTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/TransportClientDocumentActionsTests.java @@ -21,12 +21,12 @@ package org.elasticsearch.test.integration.client.transport; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.test.integration.document.DocumentActionsTests; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.transport.TransportAddress; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * @author kimchy (shay.banon) diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/TransportClientMoreLikeThisActionTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/TransportClientMoreLikeThisActionTests.java index 3dbc2fb0e19..10b5e30abd1 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/TransportClientMoreLikeThisActionTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/client/transport/TransportClientMoreLikeThisActionTests.java @@ -21,12 +21,12 @@ package org.elasticsearch.test.integration.client.transport; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.test.integration.document.MoreLikeThisActionTests; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.transport.TransportAddress; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * @author kimchy (shay.banon) diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/datanode/SimpleDataNodesTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/datanode/SimpleDataNodesTests.java index e04f5b4d934..a44b97af461 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/datanode/SimpleDataNodesTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/datanode/SimpleDataNodesTests.java @@ -27,8 +27,8 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/AliasedIndexDocumentActionsTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/AliasedIndexDocumentActionsTests.java index 10fb908bc73..2b3eef49c8b 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/AliasedIndexDocumentActionsTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/AliasedIndexDocumentActionsTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.test.integration.document; import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * @author kimchy (shay.banon) diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/MoreLikeThisActionTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/MoreLikeThisActionTests.java index d74f7ef4775..cb2c74d0f05 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/MoreLikeThisActionTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/MoreLikeThisActionTests.java @@ -29,7 +29,7 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/indexlifecycle/IndexLifecycleActionTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/indexlifecycle/IndexLifecycleActionTests.java index 7b8a75b8673..5cc344d2d79 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/indexlifecycle/IndexLifecycleActionTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/indexlifecycle/IndexLifecycleActionTests.java @@ -26,18 +26,18 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.RoutingNode; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.test.integration.AbstractNodesTests; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.settings.Settings; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import static org.elasticsearch.client.Requests.*; import static org.elasticsearch.cluster.metadata.IndexMetaData.*; import static org.elasticsearch.cluster.routing.ShardRoutingState.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/ping/PingActionTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/ping/PingActionTests.java index 70fea295a34..ad05e7f70f8 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/ping/PingActionTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/ping/PingActionTests.java @@ -22,9 +22,9 @@ package org.elasticsearch.test.integration.ping; import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingResponse; import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingResponse; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.test.integration.AbstractNodesTests; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/rest/http/RestHttpDocumentActions.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/rest/http/RestHttpDocumentActions.java index 70336df1a32..7956d70a323 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/rest/http/RestHttpDocumentActions.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/rest/http/RestHttpDocumentActions.java @@ -22,12 +22,12 @@ package org.elasticsearch.test.integration.rest.http; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.client.Client; +import org.elasticsearch.common.http.client.AsyncHttpClient; +import org.elasticsearch.common.http.client.HttpClientService; +import org.elasticsearch.common.http.client.Response; +import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.test.integration.AbstractNodesTests; -import org.elasticsearch.util.http.HttpClientService; -import org.elasticsearch.util.http.client.AsyncHttpClient; -import org.elasticsearch.util.http.client.Response; -import org.elasticsearch.util.xcontent.XContentFactory; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/SingleInstanceEmbeddedSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/SingleInstanceEmbeddedSearchTests.java index daaa5f325a5..6b9a09d1a08 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/SingleInstanceEmbeddedSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/SingleInstanceEmbeddedSearchTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.test.integration.search; import org.elasticsearch.client.Client; +import org.elasticsearch.common.trove.ExtTIntArrayList; import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchContextMissingException; @@ -39,7 +40,6 @@ import org.elasticsearch.search.query.QuerySearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.test.integration.AbstractNodesTests; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.trove.ExtTIntArrayList; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -47,9 +47,9 @@ import org.testng.annotations.Test; import java.util.Map; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.collect.Lists.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; -import static org.elasticsearch.util.collect.Lists.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TransportSearchFailuresTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TransportSearchFailuresTests.java index dfce57fbb9d..1b2666709a4 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TransportSearchFailuresTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TransportSearchFailuresTests.java @@ -27,16 +27,16 @@ import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.test.integration.AbstractNodesTests; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import java.io.IOException; import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TransportTwoServersSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TransportTwoServersSearchTests.java index 6316fe4f6bb..148e88a49c0 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TransportTwoServersSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TransportTwoServersSearchTests.java @@ -24,14 +24,14 @@ import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; +import org.elasticsearch.common.collect.Sets; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.facets.query.QueryFacet; import org.elasticsearch.test.integration.AbstractNodesTests; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.collect.Sets; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -42,10 +42,10 @@ import java.util.Set; import static org.elasticsearch.action.search.SearchType.*; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TwoInstanceEmbeddedSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TwoInstanceEmbeddedSearchTests.java index 99ca00d870a..aa46717eafe 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TwoInstanceEmbeddedSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TwoInstanceEmbeddedSearchTests.java @@ -24,6 +24,9 @@ import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.collect.Sets; +import org.elasticsearch.common.trove.ExtTIntArrayList; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.search.*; @@ -44,9 +47,6 @@ import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.test.integration.AbstractNodesTests; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.collect.Sets; -import org.elasticsearch.util.trove.ExtTIntArrayList; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -57,11 +57,11 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Maps.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.collect.Lists.*; -import static org.elasticsearch.util.collect.Maps.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TwoInstanceUnbalancedShardsEmbeddedSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TwoInstanceUnbalancedShardsEmbeddedSearchTests.java index 8eade1e4b8d..a309d5b3858 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TwoInstanceUnbalancedShardsEmbeddedSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/TwoInstanceUnbalancedShardsEmbeddedSearchTests.java @@ -24,6 +24,11 @@ import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardsIterator; +import org.elasticsearch.common.collect.ImmutableMap; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.trove.ExtTIntArrayList; import org.elasticsearch.index.Index; import org.elasticsearch.index.routing.OperationRouting; import org.elasticsearch.index.routing.plain.PlainOperationRouting; @@ -48,11 +53,6 @@ import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.test.integration.AbstractNodesTests; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.collect.ImmutableMap; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.trove.ExtTIntArrayList; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -62,11 +62,11 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.collect.Lists.*; +import static org.elasticsearch.common.collect.Maps.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.collect.Lists.*; -import static org.elasticsearch.util.collect.Maps.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/customscore/CustomScoreSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/customscore/CustomScoreSearchTests.java index 1d4a57e61f3..f15a8e85c80 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/customscore/CustomScoreSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/customscore/CustomScoreSearchTests.java @@ -28,9 +28,9 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/facets/SimpleFacetsTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/facets/SimpleFacetsTests.java index a2bba8b9504..5e549c0fd2b 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/facets/SimpleFacetsTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/facets/SimpleFacetsTests.java @@ -30,9 +30,9 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.index.query.xcontent.FilterBuilders.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/highlight/HighlightSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/highlight/HighlightSearchTests.java index 1f708fbe902..328e48a76f5 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/highlight/HighlightSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/highlight/HighlightSearchTests.java @@ -22,11 +22,11 @@ package org.elasticsearch.test.integration.search.highlight; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.test.integration.AbstractNodesTests; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -36,10 +36,10 @@ import java.util.Arrays; import static org.elasticsearch.action.search.SearchType.*; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; import static org.elasticsearch.util.TimeValue.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/indicesboost/SimpleIndicesBoostSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/indicesboost/SimpleIndicesBoostSearchTests.java index afa51e5f9ea..c6715d7386c 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/indicesboost/SimpleIndicesBoostSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/indicesboost/SimpleIndicesBoostSearchTests.java @@ -28,9 +28,9 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/scriptfield/ScriptFieldSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/scriptfield/ScriptFieldSearchTests.java index 7a273d113df..e7ce8ffc41e 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/scriptfield/ScriptFieldSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/scriptfield/ScriptFieldSearchTests.java @@ -30,9 +30,9 @@ import org.testng.annotations.Test; import java.util.Map; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.search.builder.SearchSourceBuilder.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/terms/ClientTransportTermsActionTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/terms/ClientTransportTermsActionTests.java index 8763a899dbe..36159cb4c6a 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/terms/ClientTransportTermsActionTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/terms/ClientTransportTermsActionTests.java @@ -21,9 +21,9 @@ package org.elasticsearch.test.integration.terms; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.node.internal.InternalNode; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.transport.TransportAddress; import org.testng.annotations.Test; /** diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/terms/TermsActionTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/terms/TermsActionTests.java index ffe05e66824..65034887b43 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/terms/TermsActionTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/terms/TermsActionTests.java @@ -33,8 +33,8 @@ import org.testng.annotations.Test; import static org.elasticsearch.action.terms.TermsRequest.SortType.*; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.util.MapBuilder.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/ICUNormalizer2Filter.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/ICUNormalizer2Filter.java index 29a8afd4517..f097a46aa8f 100644 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/ICUNormalizer2Filter.java +++ b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/ICUNormalizer2Filter.java @@ -24,7 +24,7 @@ import com.ibm.icu.text.Normalizer2; import org.apache.lucene.analysis.TokenFilter; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.TermAttribute; -import org.elasticsearch.util.lucene.analysis.CharSequenceTermAttribute; +import org.elasticsearch.common.lucene.analysis.CharSequenceTermAttribute; import java.io.IOException; diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java index 7e240690317..203ffdd5cc2 100644 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java +++ b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java @@ -24,13 +24,13 @@ import com.ibm.icu.text.RuleBasedCollator; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.collation.ICUCollationKeyFilter; import org.elasticsearch.ElasticSearchIllegalArgumentException; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.env.FailedToResolveConfigException; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; import java.util.Locale; diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java index c248aa153b6..658dabca5b4 100644 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java +++ b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuFoldingTokenFilterFactory.java @@ -20,11 +20,11 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.analysis.TokenStream; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; -import org.elasticsearch.util.settings.Settings; /** diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java index edef41876aa..fba1e1dac07 100644 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java +++ b/plugins/analysis/icu/src/main/java/org/elasticsearch/index/analysis/IcuNormalizerTokenFilterFactory.java @@ -21,17 +21,17 @@ package org.elasticsearch.index.analysis; import com.ibm.icu.text.Normalizer2; import org.apache.lucene.analysis.TokenStream; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.assistedinject.Assisted; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.assistedinject.Assisted; -import org.elasticsearch.util.settings.Settings; /** * Uses the {@link org.elasticsearch.index.analysis.ICUNormalizer2Filter} to normalize tokens. * - *

The name can be used to provide the type of normalization to perofrm. + *

The name can be used to provide the type of normalization to perofrm. * * @author kimchy (shay.banon) * @see org.elasticsearch.index.analysis.ICUNormalizer2Filter diff --git a/plugins/analysis/icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java b/plugins/analysis/icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java index 41172f51326..589f60dc985 100644 --- a/plugins/analysis/icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java +++ b/plugins/analysis/icu/src/main/java/org/elasticsearch/plugin/analysis/icu/AnalysisICUPlugin.java @@ -19,10 +19,10 @@ package org.elasticsearch.plugin.analysis.icu; +import org.elasticsearch.common.inject.Module; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.IcuAnalysisBinderProcessor; import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.util.inject.Module; /** * @author kimchy (shay.banon) diff --git a/plugins/analysis/icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuAnalysisTests.java b/plugins/analysis/icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuAnalysisTests.java index eb3d638bfe4..e5833f34160 100644 --- a/plugins/analysis/icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuAnalysisTests.java +++ b/plugins/analysis/icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuAnalysisTests.java @@ -19,15 +19,15 @@ package org.elasticsearch.index.analysis; +import org.elasticsearch.common.inject.Guice; +import org.elasticsearch.common.inject.Injector; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.settings.IndexSettingsModule; -import org.elasticsearch.util.inject.Guice; -import org.elasticsearch.util.inject.Injector; import org.hamcrest.MatcherAssert; import org.testng.annotations.Test; -import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; +import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.hamcrest.Matchers.*; /** diff --git a/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClient.groovy b/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClient.groovy index 95114cd7c96..8fd86741a70 100644 --- a/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClient.groovy +++ b/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/client/GClient.groovy @@ -37,9 +37,9 @@ import org.elasticsearch.action.terms.TermsRequest import org.elasticsearch.action.terms.TermsResponse import org.elasticsearch.client.Client import org.elasticsearch.client.internal.InternalClient +import org.elasticsearch.common.xcontent.XContentType import org.elasticsearch.groovy.client.action.GActionFuture import org.elasticsearch.groovy.util.xcontent.GXContentBuilder -import org.elasticsearch.util.xcontent.XContentType /** * @author kimchy (shay.banon) diff --git a/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNodeBuilder.groovy b/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNodeBuilder.groovy index d6aa8e92015..b5f6f8fbd36 100644 --- a/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNodeBuilder.groovy +++ b/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/node/GNodeBuilder.groovy @@ -19,15 +19,15 @@ package org.elasticsearch.groovy.node +import org.elasticsearch.common.settings.ImmutableSettings +import org.elasticsearch.common.settings.Settings +import org.elasticsearch.common.settings.loader.JsonSettingsLoader import org.elasticsearch.groovy.util.xcontent.GXContentBuilder import org.elasticsearch.node.Node import org.elasticsearch.node.internal.InternalNode -import org.elasticsearch.util.settings.ImmutableSettings -import org.elasticsearch.util.settings.Settings -import org.elasticsearch.util.settings.loader.JsonSettingsLoader /** - * The node builder allow to build a {@link GNode} instance. + * The node builder allow to build a {@link GNode} instance. * * @author kimchy (shay.banon) */ diff --git a/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/util/xcontent/GXContentBuilder.groovy b/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/util/xcontent/GXContentBuilder.groovy index e9ee4d6eecc..70ebe83a301 100644 --- a/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/util/xcontent/GXContentBuilder.groovy +++ b/plugins/client/groovy/src/main/groovy/org/elasticsearch/groovy/util/xcontent/GXContentBuilder.groovy @@ -19,10 +19,10 @@ package org.elasticsearch.groovy.util.xcontent -import org.elasticsearch.util.xcontent.XContentFactory -import org.elasticsearch.util.xcontent.XContentType -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder -import org.elasticsearch.util.xcontent.builder.TextXContentBuilder +import org.elasticsearch.common.xcontent.XContentFactory +import org.elasticsearch.common.xcontent.XContentType +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder +import org.elasticsearch.common.xcontent.builder.TextXContentBuilder /** * Used to build JSON data. diff --git a/plugins/cloud/src/main/java/org/elasticsearch/cloud/CloudModule.java b/plugins/cloud/src/main/java/org/elasticsearch/cloud/CloudModule.java index f830b85a28a..80c6f7bd137 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/cloud/CloudModule.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/cloud/CloudModule.java @@ -21,7 +21,7 @@ package org.elasticsearch.cloud; import org.elasticsearch.cloud.blobstore.CloudBlobStoreService; import org.elasticsearch.cloud.compute.CloudComputeService; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/plugins/cloud/src/main/java/org/elasticsearch/cloud/blobstore/CloudBlobStoreService.java b/plugins/cloud/src/main/java/org/elasticsearch/cloud/blobstore/CloudBlobStoreService.java index 6f09fd85b9e..5d812e6996b 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/cloud/blobstore/CloudBlobStoreService.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/cloud/blobstore/CloudBlobStoreService.java @@ -22,11 +22,11 @@ package org.elasticsearch.cloud.blobstore; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cloud.jclouds.JCloudsUtils; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsFilter; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContextFactory; diff --git a/plugins/cloud/src/main/java/org/elasticsearch/cloud/compute/CloudComputeService.java b/plugins/cloud/src/main/java/org/elasticsearch/cloud/compute/CloudComputeService.java index d45ee5e82ec..9fe002dfc4e 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/cloud/compute/CloudComputeService.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/cloud/compute/CloudComputeService.java @@ -22,11 +22,11 @@ package org.elasticsearch.cloud.compute; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cloud.jclouds.JCloudsUtils; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.ImmutableSettings; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.settings.SettingsFilter; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; diff --git a/plugins/cloud/src/main/java/org/elasticsearch/cloud/jclouds/JCloudsUtils.java b/plugins/cloud/src/main/java/org/elasticsearch/cloud/jclouds/JCloudsUtils.java index acecd57138b..e6abe3b0b40 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/cloud/jclouds/JCloudsUtils.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/cloud/jclouds/JCloudsUtils.java @@ -21,9 +21,9 @@ package org.elasticsearch.cloud.jclouds; import com.google.inject.Module; import org.elasticsearch.cloud.jclouds.logging.JCloudsLoggingModule; -import org.elasticsearch.util.collect.ImmutableList; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.concurrent.DynamicExecutors; -import org.elasticsearch.util.settings.Settings; import org.jclouds.concurrent.config.ExecutorServiceModule; import java.util.concurrent.Executors; diff --git a/plugins/cloud/src/main/java/org/elasticsearch/cloud/jclouds/logging/JCloudsLoggingModule.java b/plugins/cloud/src/main/java/org/elasticsearch/cloud/jclouds/logging/JCloudsLoggingModule.java index d1e9c80fb93..f4e0760fe0c 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/cloud/jclouds/logging/JCloudsLoggingModule.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/cloud/jclouds/logging/JCloudsLoggingModule.java @@ -19,9 +19,9 @@ package org.elasticsearch.cloud.jclouds.logging; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.settings.Settings; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; import org.jclouds.logging.BaseLogger; import org.jclouds.logging.Logger; import org.jclouds.logging.config.LoggingModule; diff --git a/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudDiscovery.java b/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudDiscovery.java index 1c988007e08..fcddbd7c666 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudDiscovery.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudDiscovery.java @@ -22,15 +22,15 @@ package org.elasticsearch.discovery.cloud; import org.elasticsearch.cloud.compute.CloudComputeService; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.zen.ZenDiscovery; import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.discovery.zen.ping.ZenPingService; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudDiscoveryModule.java b/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudDiscoveryModule.java index eba01289d9f..954e27cf933 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudDiscoveryModule.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudDiscoveryModule.java @@ -19,9 +19,9 @@ package org.elasticsearch.discovery.cloud; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.zen.ping.ZenPingService; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudUnicastHostsProvider.java b/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudUnicastHostsProvider.java index f4c78af0fc4..4443225ccd7 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudUnicastHostsProvider.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/discovery/cloud/CloudUnicastHostsProvider.java @@ -21,11 +21,11 @@ package org.elasticsearch.discovery.cloud; import org.elasticsearch.cloud.compute.CloudComputeService; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.common.transport.PortsRange; import org.elasticsearch.discovery.zen.ping.unicast.UnicastHostsProvider; -import org.elasticsearch.util.component.AbstractComponent; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.transport.InetSocketTransportAddress; -import org.elasticsearch.util.transport.PortsRange; import org.jclouds.compute.ComputeService; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.NodeMetadata; @@ -35,7 +35,7 @@ import org.jclouds.domain.Location; import java.util.List; import java.util.Set; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/plugins/cloud/src/main/java/org/elasticsearch/gateway/cloud/CloudGateway.java b/plugins/cloud/src/main/java/org/elasticsearch/gateway/cloud/CloudGateway.java index c7a3fc30d73..6c8b02cd458 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/gateway/cloud/CloudGateway.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/gateway/cloud/CloudGateway.java @@ -24,20 +24,20 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.cloud.blobstore.CloudBlobStoreService; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.gateway.GatewayException; import org.elasticsearch.index.gateway.cloud.CloudIndexGatewayModule; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.Module; import org.elasticsearch.util.io.FastByteArrayInputStream; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.PageSet; diff --git a/plugins/cloud/src/main/java/org/elasticsearch/gateway/cloud/CloudGatewayModule.java b/plugins/cloud/src/main/java/org/elasticsearch/gateway/cloud/CloudGatewayModule.java index a9c3827e3a1..211d9049b70 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/gateway/cloud/CloudGatewayModule.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/gateway/cloud/CloudGatewayModule.java @@ -19,8 +19,8 @@ package org.elasticsearch.gateway.cloud; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.gateway.Gateway; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexGateway.java b/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexGateway.java index 049dd36439e..a912b656787 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexGateway.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexGateway.java @@ -23,6 +23,8 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.cloud.blobstore.CloudBlobStoreService; import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.gateway.cloud.CloudGateway; import org.elasticsearch.index.AbstractIndexComponent; @@ -32,8 +34,6 @@ import org.elasticsearch.index.gateway.IndexShardGateway; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.domain.Location; diff --git a/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexGatewayModule.java b/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexGatewayModule.java index 429cb26b51c..f4232d457ce 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexGatewayModule.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexGatewayModule.java @@ -19,8 +19,8 @@ package org.elasticsearch.index.gateway.cloud; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.index.gateway.IndexGateway; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexShardGateway.java b/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexShardGateway.java index 8cdc576b2a3..3b6d11034cc 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexShardGateway.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/index/gateway/cloud/CloudIndexShardGateway.java @@ -25,6 +25,13 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexOutput; import org.elasticsearch.cloud.blobstore.CloudBlobStoreService; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.collect.Maps; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lucene.Directories; +import org.elasticsearch.common.lucene.store.InputStreamIndexInput; +import org.elasticsearch.common.lucene.store.ThreadSafeInputStreamIndexInput; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit; import org.elasticsearch.index.gateway.IndexGateway; import org.elasticsearch.index.gateway.IndexShardGateway; @@ -42,16 +49,9 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.collect.Maps; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.FastByteArrayInputStream; import org.elasticsearch.util.io.stream.BytesStreamOutput; import org.elasticsearch.util.io.stream.InputStreamStreamInput; -import org.elasticsearch.util.lucene.Directories; -import org.elasticsearch.util.lucene.store.InputStreamIndexInput; -import org.elasticsearch.util.lucene.store.ThreadSafeInputStreamIndexInput; -import org.elasticsearch.util.settings.Settings; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.PageSet; diff --git a/plugins/cloud/src/main/java/org/elasticsearch/plugin/cloud/CloudPlugin.java b/plugins/cloud/src/main/java/org/elasticsearch/plugin/cloud/CloudPlugin.java index 042d069768b..f3c2cc78e03 100644 --- a/plugins/cloud/src/main/java/org/elasticsearch/plugin/cloud/CloudPlugin.java +++ b/plugins/cloud/src/main/java/org/elasticsearch/plugin/cloud/CloudPlugin.java @@ -22,14 +22,14 @@ package org.elasticsearch.plugin.cloud; import org.elasticsearch.cloud.CloudModule; import org.elasticsearch.cloud.blobstore.CloudBlobStoreService; import org.elasticsearch.cloud.compute.CloudComputeService; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.util.component.LifecycleComponent; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.settings.Settings; import java.util.Collection; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsCustomLogFactory.java b/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsCustomLogFactory.java index 98fb0383039..2a1809a2fce 100644 --- a/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsCustomLogFactory.java +++ b/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsCustomLogFactory.java @@ -19,8 +19,8 @@ package org.elasticsearch.discovery.jgroups; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.ESLoggerFactory; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.ESLoggerFactory; import org.jgroups.logging.CustomLogFactory; import org.jgroups.logging.Log; diff --git a/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsDiscovery.java b/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsDiscovery.java index 87e845cec97..d3cc824303a 100644 --- a/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsDiscovery.java +++ b/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsDiscovery.java @@ -24,18 +24,18 @@ import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.*; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.network.NetworkService; +import org.elasticsearch.common.network.NetworkUtils; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.DiscoveryException; import org.elasticsearch.discovery.InitialStateDiscoveryListener; import org.elasticsearch.env.Environment; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.BytesStreamInput; import org.elasticsearch.util.io.stream.BytesStreamOutput; -import org.elasticsearch.util.network.NetworkService; -import org.elasticsearch.util.network.NetworkUtils; -import org.elasticsearch.util.settings.Settings; import org.jgroups.*; import java.io.IOException; @@ -50,8 +50,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.elasticsearch.cluster.ClusterState.*; import static org.elasticsearch.cluster.node.DiscoveryNode.*; -import static org.elasticsearch.util.collect.Maps.*; -import static org.elasticsearch.util.collect.Sets.*; +import static org.elasticsearch.common.collect.Maps.*; +import static org.elasticsearch.common.collect.Sets.*; /** * @author kimchy (Shay Banon) diff --git a/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsDiscoveryModule.java b/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsDiscoveryModule.java index cbb983712bb..aaf8a061339 100644 --- a/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsDiscoveryModule.java +++ b/plugins/discovery/jgroups/src/main/java/org/elasticsearch/discovery/jgroups/JgroupsDiscoveryModule.java @@ -19,9 +19,9 @@ package org.elasticsearch.discovery.jgroups; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.Discovery; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (Shay Banon) diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGateway.java b/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGateway.java index 223d30e7912..1125f50c3fe 100644 --- a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGateway.java +++ b/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGateway.java @@ -25,17 +25,17 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.builder.BinaryXContentBuilder; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.gateway.GatewayException; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.xcontent.ToXContent; -import org.elasticsearch.util.xcontent.XContentFactory; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.XContentType; -import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder; import java.io.IOException; import java.net.URI; diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGatewayModule.java b/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGatewayModule.java index 33ba3b749f8..969aae95dff 100644 --- a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGatewayModule.java +++ b/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsGatewayModule.java @@ -19,8 +19,8 @@ package org.elasticsearch.gateway.hdfs; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.gateway.Gateway; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsIndexGatewayModule.java b/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsIndexGatewayModule.java index 4b4d4ccb595..68c5c9ee8a4 100644 --- a/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsIndexGatewayModule.java +++ b/plugins/hadoop/src/main/java/org/elasticsearch/gateway/hdfs/HdfsIndexGatewayModule.java @@ -19,9 +19,9 @@ package org.elasticsearch.gateway.hdfs; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.index.gateway.IndexGateway; import org.elasticsearch.index.gateway.hdfs.HdfsIndexGateway; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (Shay Banon) diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexGateway.java b/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexGateway.java index e2e9f5d3acd..3d647e7f47e 100644 --- a/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexGateway.java +++ b/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexGateway.java @@ -23,6 +23,8 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalArgumentException; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.gateway.hdfs.HdfsGateway; import org.elasticsearch.index.AbstractIndexComponent; @@ -30,8 +32,6 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.gateway.IndexGateway; import org.elasticsearch.index.gateway.IndexShardGateway; import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; import java.io.IOException; diff --git a/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexShardGateway.java b/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexShardGateway.java index 193fa8fcb19..c6d30a166d9 100644 --- a/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexShardGateway.java +++ b/plugins/hadoop/src/main/java/org/elasticsearch/index/gateway/hdfs/HdfsIndexShardGateway.java @@ -23,6 +23,10 @@ import org.apache.hadoop.fs.*; import org.apache.lucene.index.IndexReader; import org.apache.lucene.store.IndexInput; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lucene.Directories; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit; import org.elasticsearch.index.gateway.IndexGateway; import org.elasticsearch.index.gateway.IndexShardGateway; @@ -40,13 +44,9 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.util.SizeUnit; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; -import org.elasticsearch.util.collect.Lists; -import org.elasticsearch.util.inject.Inject; import org.elasticsearch.util.io.stream.DataInputStreamInput; import org.elasticsearch.util.io.stream.DataOutputStreamOutput; import org.elasticsearch.util.io.stream.StreamOutput; -import org.elasticsearch.util.lucene.Directories; -import org.elasticsearch.util.settings.Settings; import java.io.EOFException; import java.io.FileNotFoundException; @@ -56,8 +56,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.common.lucene.Directories.*; import static org.elasticsearch.index.translog.TranslogStreams.*; -import static org.elasticsearch.util.lucene.Directories.*; /** * @author kimchy (shay.banon) diff --git a/plugins/hadoop/src/test/java/org/elasticsearch/hadoop/gateway/HdfsGatewayTests.java b/plugins/hadoop/src/test/java/org/elasticsearch/hadoop/gateway/HdfsGatewayTests.java index 9f7c47ae9aa..01f84a56272 100644 --- a/plugins/hadoop/src/test/java/org/elasticsearch/hadoop/gateway/HdfsGatewayTests.java +++ b/plugins/hadoop/src/test/java/org/elasticsearch/hadoop/gateway/HdfsGatewayTests.java @@ -25,20 +25,20 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.client.Requests; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.node.Node; import org.elasticsearch.node.internal.InternalNode; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; -import org.elasticsearch.util.settings.Settings; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; import static org.elasticsearch.node.NodeBuilder.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentAttachmentMapper.java b/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentAttachmentMapper.java index 11fa219760d..73c6605f8dd 100644 --- a/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentAttachmentMapper.java +++ b/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentAttachmentMapper.java @@ -21,12 +21,12 @@ package org.elasticsearch.index.mapper.xcontent; import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.builder.XContentBuilder; import org.elasticsearch.index.mapper.FieldMapperListener; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.util.io.FastByteArrayInputStream; -import org.elasticsearch.util.xcontent.XContentParser; -import org.elasticsearch.util.xcontent.builder.XContentBuilder; import java.io.IOException; import java.util.Map; diff --git a/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentAttachmentMapperService.java b/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentAttachmentMapperService.java index d76d794b45e..53f1544c3ab 100644 --- a/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentAttachmentMapperService.java +++ b/plugins/mapper/attachments/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentAttachmentMapperService.java @@ -19,12 +19,12 @@ package org.elasticsearch.index.mapper.xcontent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.settings.IndexSettings; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsIndexModule.java b/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsIndexModule.java index 40a5b2f637d..60a15c2b60c 100644 --- a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsIndexModule.java +++ b/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsIndexModule.java @@ -19,8 +19,8 @@ package org.elasticsearch.plugin.mapper.attachments; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.index.mapper.xcontent.XContentAttachmentMapperService; -import org.elasticsearch.util.inject.AbstractModule; /** * @author kimchy (shay.banon) diff --git a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsPlugin.java b/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsPlugin.java index 7a87a1945c1..0c4f8285024 100644 --- a/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsPlugin.java +++ b/plugins/mapper/attachments/src/main/java/org/elasticsearch/plugin/mapper/attachments/MapperAttachmentsPlugin.java @@ -19,12 +19,12 @@ package org.elasticsearch.plugin.mapper.attachments; +import org.elasticsearch.common.inject.Module; import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.util.inject.Module; import java.util.Collection; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java b/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java index f13dc3ea9a1..104f9b3baf4 100644 --- a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java +++ b/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java @@ -25,8 +25,8 @@ import org.elasticsearch.index.analysis.AnalysisService; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.util.io.Streams.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/plugins/mapper/attachments/src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java b/plugins/mapper/attachments/src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java index a3468af1dfd..cbe0aa75479 100644 --- a/plugins/mapper/attachments/src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java +++ b/plugins/mapper/attachments/src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java @@ -22,17 +22,17 @@ package org.elasticsearch.plugin.mapper.attachments.test; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.count.CountResponse; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.node.Node; -import org.elasticsearch.util.logging.ESLogger; -import org.elasticsearch.util.logging.Loggers; import org.testng.annotations.*; import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.common.settings.ImmutableSettings.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.node.NodeBuilder.*; import static org.elasticsearch.util.io.Streams.*; -import static org.elasticsearch.util.settings.ImmutableSettings.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/plugins/transport/memcached/build.gradle b/plugins/transport/memcached/build.gradle index d7dea98784e..992a9985832 100644 --- a/plugins/transport/memcached/build.gradle +++ b/plugins/transport/memcached/build.gradle @@ -107,36 +107,6 @@ artifacts { archives javadocJar } -jar << { - jarjarArchivePath = new File(jar.archivePath.absolutePath + ".jarjar.jar") - project.ant { - taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask", classpath: configurations.tools.asPath - jarjar(jarfile: jarjarArchivePath) { - zipfileset(src: jar.archivePath) - configurations.compile.files.findAll {file -> - ['netty'].any { file.name.contains(it) } - }.each { jarjarFile -> - zipfileset(src: jarjarFile) { - exclude(name: "META-INF/**") - } - } - rule pattern: "org.jboss.netty.**", result: "org.elasticsearch.util.netty.@1" - } - delete(file: jar.archivePath) - copy(file: jarjarArchivePath, tofile: jar.archivePath) - delete(file: jarjarArchivePath) - - // hack, we want to reuse the jarjar of elasticsearch into util.netty, but don't want it to be in memcached jar - unjar(src: jar.archivePath, dest: "build/tmp/extracted") - delete(dir: "build/tmp/extracted/org/elasticsearch/util/netty") - delete(dir: "build/tmp/extracted/org/jboss") - - delete(file: jar.archivePath) - jar(destfile: jar.archivePath, basedir: "build/tmp/extracted", manifest: "build/tmp/extracted/META-INF/MANIFEST.MF") - delete(dir: "build/tmp/extracted") - } -} - uploadArchives { repositories.mavenDeployer { configuration = configurations.deployerJars diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java index a965452b47f..c54e46744ea 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedRestRequest.java @@ -19,12 +19,12 @@ package org.elasticsearch.memcached; +import org.elasticsearch.common.collect.ImmutableList; +import org.elasticsearch.common.collect.ImmutableSet; import org.elasticsearch.rest.support.AbstractRestRequest; import org.elasticsearch.rest.support.RestUtils; import org.elasticsearch.util.Booleans; import org.elasticsearch.util.Unicode; -import org.elasticsearch.util.collect.ImmutableList; -import org.elasticsearch.util.collect.ImmutableSet; import java.util.HashMap; import java.util.List; diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServer.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServer.java index 1b7e912c713..f342877b8a0 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServer.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServer.java @@ -21,10 +21,10 @@ package org.elasticsearch.memcached; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfoAction; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.settings.Settings; /** * @author kimchy (shay.banon) diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerModule.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerModule.java index 093f0769ff1..b3e642dcb83 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerModule.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerModule.java @@ -19,12 +19,12 @@ package org.elasticsearch.memcached; -import org.elasticsearch.util.inject.AbstractModule; -import org.elasticsearch.util.inject.Module; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.util.Classes; -import org.elasticsearch.util.settings.Settings; -import static org.elasticsearch.util.guice.ModulesFactory.*; +import static org.elasticsearch.common.inject.ModulesFactory.*; /** * @author kimchy (shay.banon) diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerTransport.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerTransport.java index 063c0a2677c..950b7775327 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerTransport.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/MemcachedServerTransport.java @@ -19,8 +19,8 @@ package org.elasticsearch.memcached; -import org.elasticsearch.util.component.LifecycleComponent; -import org.elasticsearch.util.transport.BoundTransportAddress; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.transport.BoundTransportAddress; /** * @author kimchy (shay.banon) diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDecoder.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDecoder.java index 4e67c2cf632..07f94d088d3 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDecoder.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDecoder.java @@ -19,14 +19,14 @@ package org.elasticsearch.memcached.netty; +import org.elasticsearch.common.netty.buffer.ChannelBuffer; +import org.elasticsearch.common.netty.channel.Channel; +import org.elasticsearch.common.netty.channel.ChannelHandlerContext; +import org.elasticsearch.common.netty.channel.ExceptionEvent; +import org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder; import org.elasticsearch.memcached.MemcachedRestRequest; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.util.Unicode; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ExceptionEvent; -import org.jboss.netty.handler.codec.frame.FrameDecoder; import java.io.StreamCorruptedException; import java.util.regex.Pattern; diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDispatcher.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDispatcher.java index c46fd6ffa06..927f4544304 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDispatcher.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedDispatcher.java @@ -19,11 +19,11 @@ package org.elasticsearch.memcached.netty; +import org.elasticsearch.common.netty.channel.ChannelHandlerContext; +import org.elasticsearch.common.netty.channel.MessageEvent; +import org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler; import org.elasticsearch.memcached.MemcachedRestRequest; import org.elasticsearch.rest.RestController; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.channel.SimpleChannelUpstreamHandler; /** * @author kimchy (shay.banon) diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedRestChannel.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedRestChannel.java index 74015db2a83..e5772a8dbf3 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedRestChannel.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/MemcachedRestChannel.java @@ -19,6 +19,9 @@ package org.elasticsearch.memcached.netty; +import org.elasticsearch.common.netty.buffer.ChannelBuffer; +import org.elasticsearch.common.netty.buffer.ChannelBuffers; +import org.elasticsearch.common.netty.channel.Channel; import org.elasticsearch.memcached.MemcachedRestRequest; import org.elasticsearch.memcached.MemcachedTransportException; import org.elasticsearch.rest.RestChannel; @@ -26,9 +29,6 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.util.Bytes; import org.elasticsearch.util.Unicode; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; import java.nio.charset.Charset; diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransport.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransport.java index b46eb974970..fe8359b703c 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransport.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransport.java @@ -20,25 +20,25 @@ package org.elasticsearch.memcached.netty; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.common.component.AbstractLifecycleComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.netty.bootstrap.ServerBootstrap; +import org.elasticsearch.common.netty.channel.Channel; +import org.elasticsearch.common.netty.channel.ChannelPipeline; +import org.elasticsearch.common.netty.channel.ChannelPipelineFactory; +import org.elasticsearch.common.netty.channel.Channels; +import org.elasticsearch.common.netty.channel.socket.nio.NioServerSocketChannelFactory; +import org.elasticsearch.common.network.NetworkService; +import org.elasticsearch.common.network.NetworkUtils; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.BoundTransportAddress; +import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.common.transport.PortsRange; import org.elasticsearch.http.BindHttpException; import org.elasticsearch.memcached.MemcachedServerTransport; import org.elasticsearch.rest.RestController; import org.elasticsearch.transport.BindTransportException; import org.elasticsearch.util.SizeValue; -import org.elasticsearch.util.component.AbstractLifecycleComponent; -import org.elasticsearch.util.inject.Inject; -import org.elasticsearch.util.network.NetworkService; -import org.elasticsearch.util.network.NetworkUtils; -import org.elasticsearch.util.settings.Settings; -import org.elasticsearch.util.transport.BoundTransportAddress; -import org.elasticsearch.util.transport.InetSocketTransportAddress; -import org.elasticsearch.util.transport.PortsRange; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.Channels; -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; import java.io.IOException; import java.net.InetAddress; @@ -46,8 +46,8 @@ import java.net.InetSocketAddress; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.common.network.NetworkService.TcpSettings.*; import static org.elasticsearch.util.concurrent.DynamicExecutors.*; -import static org.elasticsearch.util.network.NetworkService.TcpSettings.*; /** * @author kimchy (shay.banon) diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransportModule.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransportModule.java index 1fde05cca72..ecc7966c48c 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransportModule.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/NettyMemcachedServerTransportModule.java @@ -19,7 +19,7 @@ package org.elasticsearch.memcached.netty; -import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.memcached.MemcachedServerTransport; /** diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/OpenChannelsHandler.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/OpenChannelsHandler.java index 9c1e04a610f..ba00e243c49 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/OpenChannelsHandler.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/memcached/netty/OpenChannelsHandler.java @@ -19,8 +19,8 @@ package org.elasticsearch.memcached.netty; +import org.elasticsearch.common.netty.channel.*; import org.elasticsearch.util.concurrent.ConcurrentCollections; -import org.jboss.netty.channel.*; import java.util.Set; diff --git a/plugins/transport/memcached/src/main/java/org/elasticsearch/plugin/transport/memcached/MemcachedTransportPlugin.java b/plugins/transport/memcached/src/main/java/org/elasticsearch/plugin/transport/memcached/MemcachedTransportPlugin.java index eacda68985a..5ca1d4f38dd 100644 --- a/plugins/transport/memcached/src/main/java/org/elasticsearch/plugin/transport/memcached/MemcachedTransportPlugin.java +++ b/plugins/transport/memcached/src/main/java/org/elasticsearch/plugin/transport/memcached/MemcachedTransportPlugin.java @@ -19,16 +19,16 @@ package org.elasticsearch.plugin.transport.memcached; +import org.elasticsearch.common.component.LifecycleComponent; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.memcached.MemcachedServer; import org.elasticsearch.memcached.MemcachedServerModule; import org.elasticsearch.plugins.AbstractPlugin; -import org.elasticsearch.util.component.LifecycleComponent; -import org.elasticsearch.util.inject.Module; -import org.elasticsearch.util.settings.Settings; import java.util.Collection; -import static org.elasticsearch.util.collect.Lists.*; +import static org.elasticsearch.common.collect.Lists.*; /** * @author kimchy (shay.banon) diff --git a/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/AbstractMemcachedActionsTests.java b/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/AbstractMemcachedActionsTests.java index 04e2544e015..71c01e745a0 100644 --- a/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/AbstractMemcachedActionsTests.java +++ b/plugins/transport/memcached/src/test/java/org/elasticsearch/memcached/test/AbstractMemcachedActionsTests.java @@ -29,8 +29,8 @@ import java.io.IOException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.node.NodeBuilder.*; -import static org.elasticsearch.util.xcontent.XContentFactory.*; /** * @author kimchy (shay.banon) diff --git a/settings.gradle b/settings.gradle index 38d685c91e3..810d903305e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,7 @@ include 'test-testng' +include 'jarjar' + include 'elasticsearch' include 'test-integration'