From 82e5612b7473f902682093010a29671e11c75522 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Mon, 8 Dec 2025 11:58:15 -0500 Subject: [PATCH] Replace Apache Commons Collection with built-in Java types --- .../java/com/azure/cosmos/BatchTestBase.java | 7 +- ...titionEndpointManagerForPPAFUnitTests.java | 8 +- ...titionEndpointManagerForPPCBUnitTests.java | 35 +- .../ProactiveConnectionManagementTest.java | 10 +- .../implementation/ConsistencyTestsBase.java | 9 +- ...ScopedSessionContainerConcurrencyTest.java | 5 +- .../RegionScopedSessionContainerTest.java | 213 ++- .../GlobalAddressResolverTest.java | 11 +- .../routing/LocationCacheTest.java | 20 +- .../com/azure/cosmos/CosmosClientBuilder.java | 4 +- .../implementation/ClientRetryPolicy.java | 8 +- .../CosmosBulkExecutionOptionsImpl.java | 4 +- .../CosmosChangeFeedRequestOptionsImpl.java | 4 +- .../CosmosQueryRequestOptionsBase.java | 3 +- .../implementation/GlobalEndpointManager.java | 14 +- .../PartitionScopedRegionLevelProgress.java | 5 +- .../implementation/SessionTokenHelper.java | 4 +- .../implementation/VectorSessionToken.java | 47 +- .../AbstractCollectionDecorator.java | 146 -- .../collections/CollectionUtils.java | 64 - .../collections/ComparatorUtils.java | 47 - .../apachecommons/collections/Get.java | 90 -- .../collections/IterableGet.java | 43 - .../collections/IterableMap.java | 28 - .../apachecommons/collections/KeyValue.java | 39 - .../collections/MapIterator.java | 87 -- .../apachecommons/collections/Put.java | 54 - .../collections/ResettableIterator.java | 32 - .../collections/UnmodifiableCollection.java | 100 -- .../comparators/ComparableComparator.java | 106 -- .../iterators/AbstractEmptyIterator.java | 74 - .../iterators/AbstractEmptyMapIterator.java | 43 - .../iterators/AbstractIteratorDecorator.java | 42 - .../AbstractUntypedIteratorDecorator.java | 62 - .../collections/iterators/EmptyIterator.java | 67 - .../iterators/EmptyMapIterator.java | 53 - .../iterators/EntrySetMapIterator.java | 160 -- .../iterators/UnmodifiableMapIterator.java | 92 -- .../keyvalue/AbstractMapEntryDecorator.java | 86 -- .../list/AbstractListDecorator.java | 121 -- .../AbstractSerializableListDecorator.java | 68 - .../collections/list/Unmodifiable.java | 22 - .../collections/list/UnmodifiableList.java | 136 -- .../list/iterators/UnmodifiableIterator.java | 78 - .../iterators/UnmodifiableListIterator.java | 106 -- .../collections/map/AbstractHashedMap.java | 1370 ----------------- .../collections/map/AbstractIterableMap.java | 35 - .../collections/map/AbstractMapDecorator.java | 138 -- .../collections/map/CaseInsensitiveMap.java | 131 -- .../map/EntrySetToMapIteratorAdapter.java | 118 -- .../collections/map/UnmodifiableEntrySet.java | 172 --- .../collections/map/UnmodifiableMap.java | 146 -- .../set/AbstractSerializableSetDecorator.java | 68 - .../collections/set/AbstractSetDecorator.java | 69 - .../collections/set/UnmodifiableSet.java | 99 -- .../batch/ServerBatchRequest.java | 4 +- .../caches/RxPartitionKeyRangeCache.java | 7 +- .../directconnectivity/ConsistencyWriter.java | 3 +- .../feedranges/FeedRangeEpkImpl.java | 4 +- .../feedranges/FeedRangePartitionKeyImpl.java | 4 +- .../FeedRangePartitionKeyRangeImpl.java | 5 +- ...tManagerForPerPartitionCircuitBreaker.java | 9 +- .../routing/InMemoryCollectionRoutingMap.java | 13 +- .../implementation/routing/LocationCache.java | 155 +- .../com/azure/cosmos/models/CosmosBatch.java | 4 +- .../models/CosmosBatchRequestOptions.java | 3 +- .../models/CosmosItemRequestOptions.java | 3 +- .../cosmos/models/CosmosRequestOptions.java | 3 +- sdk/cosmos/cgmanifest.json | 10 - 69 files changed, 288 insertions(+), 4742 deletions(-) delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/AbstractCollectionDecorator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/CollectionUtils.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/ComparatorUtils.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/Get.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/IterableGet.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/IterableMap.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/KeyValue.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/MapIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/Put.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/ResettableIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/UnmodifiableCollection.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/comparators/ComparableComparator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractEmptyIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractEmptyMapIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractIteratorDecorator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractUntypedIteratorDecorator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EmptyIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EmptyMapIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EntrySetMapIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/UnmodifiableMapIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/keyvalue/AbstractMapEntryDecorator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/AbstractListDecorator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/AbstractSerializableListDecorator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/Unmodifiable.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/UnmodifiableList.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/iterators/UnmodifiableIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/iterators/UnmodifiableListIterator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractHashedMap.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractIterableMap.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractMapDecorator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/CaseInsensitiveMap.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/EntrySetToMapIteratorAdapter.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/UnmodifiableEntrySet.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/UnmodifiableMap.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/AbstractSerializableSetDecorator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/AbstractSetDecorator.java delete mode 100644 sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/UnmodifiableSet.java diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/BatchTestBase.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/BatchTestBase.java index ea32cf948eff..64326032eeff 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/BatchTestBase.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/BatchTestBase.java @@ -6,11 +6,9 @@ import com.azure.cosmos.implementation.ISessionToken; import com.azure.cosmos.implementation.SessionTokenHelper; import com.azure.cosmos.implementation.VectorSessionToken; -import com.azure.cosmos.implementation.apachecommons.collections.map.UnmodifiableMap; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.azure.cosmos.models.CosmosBatchOperationResult; import com.azure.cosmos.models.CosmosBatchResponse; -import com.azure.cosmos.models.CosmosItemRequestOptions; import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.PartitionKey; import com.azure.cosmos.rx.TestSuiteBase; @@ -21,6 +19,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.util.Map; import java.util.Objects; import java.util.Random; import java.util.UUID; @@ -175,9 +174,9 @@ private static ISessionToken createSessionToken(ISessionToken from, long globalL Field fieldLocalLsnByRegion = VectorSessionToken.class.getDeclaredField("localLsnByRegion"); fieldLocalLsnByRegion.setAccessible(true); - UnmodifiableMap localLsnByRegion = (UnmodifiableMap) fieldLocalLsnByRegion.get(fromSessionToken); + Map localLsnByRegion = (Map) fieldLocalLsnByRegion.get(fromSessionToken); - Constructor constructor = VectorSessionToken.class.getDeclaredConstructor(long.class, long.class, UnmodifiableMap.class); + Constructor constructor = VectorSessionToken.class.getDeclaredConstructor(long.class, long.class, Map.class); constructor.setAccessible(true); VectorSessionToken vectorSessionToken = constructor.newInstance(version, globalLSN, localLsnByRegion); return vectorSessionToken; diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/GlobalPartitionEndpointManagerForPPAFUnitTests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/GlobalPartitionEndpointManagerForPPAFUnitTests.java index 15da7043bd87..f519b5b41ef4 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/GlobalPartitionEndpointManagerForPPAFUnitTests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/GlobalPartitionEndpointManagerForPPAFUnitTests.java @@ -4,7 +4,6 @@ package com.azure.cosmos; import com.azure.cosmos.implementation.AvailabilityStrategyContext; -import com.azure.cosmos.implementation.Configs; import com.azure.cosmos.implementation.ConnectionPolicy; import com.azure.cosmos.implementation.CrossRegionAvailabilityContextForRxDocumentServiceRequest; import com.azure.cosmos.implementation.GlobalEndpointManager; @@ -15,7 +14,6 @@ import com.azure.cosmos.implementation.ResourceType; import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.SerializationDiagnosticsContext; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.guava25.collect.ImmutableList; import com.azure.cosmos.implementation.perPartitionAutomaticFailover.GlobalPartitionEndpointManagerForPerPartitionAutomaticFailover; import com.azure.cosmos.implementation.perPartitionAutomaticFailover.PartitionLevelFailoverInfo; @@ -31,13 +29,11 @@ import org.testng.annotations.Test; import java.lang.reflect.Field; - import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; @@ -87,12 +83,12 @@ public void beforeClass() { .collect(Collectors.toList()); Mockito.when(this.singleWriteAccountGlobalEndpointManagerMock.getAvailableReadRoutingContexts()).thenReturn(availableReadRegionalRoutingContexts); - Mockito.when(this.singleWriteAccountGlobalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(new UnmodifiableList<>(availableReadRegionalRoutingContexts)); + Mockito.when(this.singleWriteAccountGlobalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(availableReadRegionalRoutingContexts)); Mockito.when(this.singleWriteAccountGlobalEndpointManagerMock.canUseMultipleWriteLocations()).thenReturn(false); Mockito.when(this.singleWriteAccountGlobalEndpointManagerMock.canUseMultipleWriteLocations(Mockito.any())).thenReturn(false); Mockito.when(this.multiWriteAccountGlobalEndpointManagerMock.getAvailableReadRoutingContexts()).thenReturn(availableReadRegionalRoutingContexts); - Mockito.when(this.multiWriteAccountGlobalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(new UnmodifiableList<>(availableReadRegionalRoutingContexts)); + Mockito.when(this.multiWriteAccountGlobalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(availableReadRegionalRoutingContexts)); Mockito.when(this.multiWriteAccountGlobalEndpointManagerMock.canUseMultipleWriteLocations()).thenReturn(true); Mockito.when(this.multiWriteAccountGlobalEndpointManagerMock.canUseMultipleWriteLocations(Mockito.any())).thenReturn(true); } diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/GlobalPartitionEndpointManagerForPPCBUnitTests.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/GlobalPartitionEndpointManagerForPPCBUnitTests.java index 11d14758f352..ef446dc9bdf0 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/GlobalPartitionEndpointManagerForPPCBUnitTests.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/GlobalPartitionEndpointManagerForPPCBUnitTests.java @@ -14,11 +14,10 @@ import com.azure.cosmos.implementation.ResourceType; import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.SerializationDiagnosticsContext; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; +import com.azure.cosmos.implementation.guava25.collect.ImmutableList; import com.azure.cosmos.implementation.perPartitionCircuitBreaker.GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker; import com.azure.cosmos.implementation.perPartitionCircuitBreaker.LocationHealthStatus; import com.azure.cosmos.implementation.perPartitionCircuitBreaker.LocationSpecificHealthContext; -import com.azure.cosmos.implementation.guava25.collect.ImmutableList; import com.azure.cosmos.implementation.routing.RegionalRoutingContext; import org.apache.commons.lang3.tuple.Pair; import org.mockito.Mockito; @@ -212,8 +211,8 @@ public void recordHealthyToHealthyWithFailuresStatusTransition(String partitionL maxExclusive, LocationEastUs2EndpointToLocationPair.getKey()); - Mockito.when(this.globalEndpointManagerMock.getReadEndpoints()).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); - Mockito.when(this.globalEndpointManagerMock.getWriteEndpoints()).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getReadEndpoints()).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getWriteEndpoints()).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); globalPartitionEndpointManagerForCircuitBreaker .handleLocationExceptionForPartitionKeyRange(request, new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getKey()), false); @@ -282,8 +281,8 @@ public void recordHealthyWithFailuresToUnavailableStatusTransition(String partit maxExclusive, LocationEastUs2EndpointToLocationPair.getKey()); - Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); - Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); int exceptionCountToHandle = globalPartitionEndpointManagerForCircuitBreaker.getConsecutiveExceptionBasedCircuitBreaker().getAllowedExceptionCountToMaintainStatus(LocationHealthStatus.HealthyWithFailures, readOperationTrue); @@ -359,8 +358,8 @@ public void recordUnavailableToHealthyTentativeStatusTransition(String partition maxExclusive, LocationEastUs2EndpointToLocationPair.getKey()); - Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); - Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn((Collections.unmodifiableList(applicableReadWriteEndpoints)); int exceptionCountToHandle = globalPartitionEndpointManagerForCircuitBreaker.getConsecutiveExceptionBasedCircuitBreaker().getAllowedExceptionCountToMaintainStatus(LocationHealthStatus.HealthyWithFailures, readOperationTrue); @@ -447,8 +446,8 @@ public void recordHealthyTentativeToHealthyStatusTransition(String partitionLeve maxExclusive, LocationEastUs2EndpointToLocationPair.getKey()); - Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); - Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); int exceptionCountToHandle = globalPartitionEndpointManagerForCircuitBreaker.getConsecutiveExceptionBasedCircuitBreaker().getAllowedExceptionCountToMaintainStatus(LocationHealthStatus.HealthyWithFailures, readOperationTrue); @@ -543,8 +542,8 @@ public void recordHealthyTentativeToUnavailableTransition(String partitionLevelC maxExclusive, LocationEastUs2EndpointToLocationPair.getKey()); - Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); - Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); int exceptionCountToHandle = globalPartitionEndpointManagerForCircuitBreaker.getConsecutiveExceptionBasedCircuitBreaker().getAllowedExceptionCountToMaintainStatus(LocationHealthStatus.HealthyWithFailures, readOperationTrue); @@ -637,8 +636,8 @@ public void allRegionsUnavailableHandling(String partitionLevelCircuitBreakerCon maxExclusive, LocationEastUs2EndpointToLocationPair.getKey()); - Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); - Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); int exceptionCountToHandle = globalPartitionEndpointManagerForCircuitBreaker @@ -722,8 +721,8 @@ public void multiContainerBothWithSinglePartitionHealthyToUnavailableHandling(St maxExclusive, LocationEastUs2EndpointToLocationPair.getKey()); - Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); - Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); int exceptionCountToHandle = globalPartitionEndpointManagerForCircuitBreaker.getConsecutiveExceptionBasedCircuitBreaker().getAllowedExceptionCountToMaintainStatus(LocationHealthStatus.HealthyWithFailures, readOperationTrue); @@ -819,8 +818,8 @@ public void allRegionsUnavailableHandlingWithMultiThreading(String partitionLeve .map(uriStringPair -> new RegionalRoutingContext(uriStringPair.getLeft())) .collect(Collectors.toList()); - Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); - Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn((UnmodifiableList) UnmodifiableList.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); + Mockito.when(this.globalEndpointManagerMock.getApplicableReadRegionalRoutingContexts(Mockito.anyList())).thenReturn(Collections.unmodifiableList(applicableReadWriteEndpoints)); RxDocumentServiceRequest requestCentralUs = constructRxDocumentServiceRequestInstance( readOperationTrue ? OperationType.Read : OperationType.Create, diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/ProactiveConnectionManagementTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/ProactiveConnectionManagementTest.java index 2c17b8733bf2..18c781ed9704 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/ProactiveConnectionManagementTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/ProactiveConnectionManagementTest.java @@ -15,7 +15,6 @@ import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.TestConfigurations; import com.azure.cosmos.implementation.Utils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.apachecommons.lang.tuple.ImmutablePair; import com.azure.cosmos.implementation.caches.AsyncCache; import com.azure.cosmos.implementation.caches.AsyncCacheNonBlocking; @@ -181,8 +180,7 @@ public void openConnectionsAndInitCachesWithContainer(ProactiveConnectionManagem cosmosAsyncContainer.openConnectionsAndInitCaches(proactiveConnectionRegionCount).block(); - UnmodifiableList readEndpoints = - globalEndpointManager.getReadEndpoints(); + List readEndpoints = globalEndpointManager.getReadEndpoints(); List proactiveConnectionEndpoints = readEndpoints.subList( 0, @@ -345,7 +343,7 @@ public void openConnectionsAndInitCachesWithCosmosClient_And_PerContainerConnect ConcurrentHashMap routingMap = getRoutingMap(rxDocumentClient); ConcurrentHashMap collectionInfoByNameMap = getCollectionInfoByNameMap(rxDocumentClient); Set endpoints = ConcurrentHashMap.newKeySet(); - UnmodifiableList readEndpoints = globalEndpointManager.getReadEndpoints(); + List readEndpoints = globalEndpointManager.getReadEndpoints(); List proactiveConnectionEndpoints = readEndpoints.subList( 0, @@ -495,7 +493,7 @@ public void openConnectionsAndInitCachesWithCosmosClient_And_PerContainerConnect ConcurrentHashMap routingMap = getRoutingMap(rxDocumentClient); ConcurrentHashMap collectionInfoByNameMap = getCollectionInfoByNameMap(rxDocumentClient); Set endpoints = ConcurrentHashMap.newKeySet(); - UnmodifiableList readEndpoints = globalEndpointManager.getReadEndpoints(); + List readEndpoints = globalEndpointManager.getReadEndpoints(); List proactiveConnectionEndpoints = readEndpoints.subList( 0, Math.min(readEndpoints.size(), proactiveContainerInitConfig.getProactiveConnectionRegionsCount())) @@ -666,7 +664,7 @@ public void openConnectionsAndInitCachesWithCosmosClient_And_PerContainerConnect ConcurrentHashMap routingMap = getRoutingMap(rxDocumentClient); ConcurrentHashMap collectionInfoByNameMap = getCollectionInfoByNameMap(rxDocumentClient); Set endpoints = ConcurrentHashMap.newKeySet(); - UnmodifiableList readEndpoints = globalEndpointManager.getReadEndpoints(); + List readEndpoints = globalEndpointManager.getReadEndpoints(); List proactiveConnectionEndpoints = readEndpoints.subList( 0, Math.min(readEndpoints.size(), proactiveContainerInitConfig.getProactiveConnectionRegionsCount())) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java index 75b5c04bf6ea..5665bf141b2b 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java @@ -8,7 +8,6 @@ import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.GatewayConnectionConfig; -import com.azure.cosmos.implementation.apachecommons.collections.map.UnmodifiableMap; import com.azure.cosmos.implementation.clienttelemetry.ClientTelemetry; import com.azure.cosmos.implementation.directconnectivity.WFConstants; import com.azure.cosmos.implementation.routing.PartitionKeyInternalHelper; @@ -28,6 +27,7 @@ import java.lang.reflect.Field; import java.time.Instant; import java.util.Arrays; +import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -907,12 +907,11 @@ public static ISessionToken createSessionToken(ISessionToken from, long globalLS Field fieldLocalLsnByRegion = VectorSessionToken.class.getDeclaredField("localLsnByRegion"); fieldLocalLsnByRegion.setAccessible(true); - UnmodifiableMap localLsnByRegion = (UnmodifiableMap) fieldLocalLsnByRegion.get(fromSessionToken); + Map localLsnByRegion = (Map) fieldLocalLsnByRegion.get(fromSessionToken); - Constructor constructor = VectorSessionToken.class.getDeclaredConstructor(long.class, long.class, UnmodifiableMap.class); + Constructor constructor = VectorSessionToken.class.getDeclaredConstructor(long.class, long.class, Map.class); constructor.setAccessible(true); - VectorSessionToken vectorSessionToken = constructor.newInstance(version, globalLSN, localLsnByRegion); - return vectorSessionToken; + return constructor.newInstance(version, globalLSN, localLsnByRegion); } else { throw new IllegalArgumentException(); } diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RegionScopedSessionContainerConcurrencyTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RegionScopedSessionContainerConcurrencyTest.java index 2512f9bd3508..8fdb0a81e750 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RegionScopedSessionContainerConcurrencyTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RegionScopedSessionContainerConcurrencyTest.java @@ -4,7 +4,6 @@ package com.azure.cosmos.implementation; import com.azure.cosmos.GatewayTestUtils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.guava25.collect.ImmutableList; import com.azure.cosmos.implementation.routing.RegionalRoutingContext; import com.azure.cosmos.models.ModelBridgeInternal; @@ -20,6 +19,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -253,8 +253,7 @@ public void concurrentSetAndResolveTokens(String profileName, for (URI u : orderedReadEndpoints) { endpointBuilder.add(new RegionalRoutingContext(u)); } - UnmodifiableList endpoints = - new UnmodifiableList<>(endpointBuilder.build()); + List endpoints = Collections.unmodifiableList(endpointBuilder.build()); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(EAST_US), Mockito.any())) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RegionScopedSessionContainerTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RegionScopedSessionContainerTest.java index d1fb33e71dae..f86a8caaef0b 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RegionScopedSessionContainerTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/RegionScopedSessionContainerTest.java @@ -5,7 +5,6 @@ import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.GatewayTestUtils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.guava25.collect.ImmutableList; import com.azure.cosmos.implementation.guava25.collect.ImmutableMap; import com.azure.cosmos.implementation.routing.RegionalRoutingContext; @@ -25,6 +24,7 @@ import java.net.URI; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -377,11 +377,10 @@ public void sessionContainer() throws Exception { int numPartitionKeyRangeIds = 5; String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(LocationEastUsEndpointToLocationPair.getLeft()), Mockito.any())).thenReturn(regionContacted); @@ -441,11 +440,10 @@ public void setSessionToken_NoSessionTokenForPartitionKeyRangeId() throws Except GlobalEndpointManager globalEndpointManagerMock = Mockito.mock(GlobalEndpointManager.class); ISessionContainer sessionContainer = new RegionScopedSessionContainer("127.0.0.1", false, globalEndpointManagerMock); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(endpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -508,11 +506,10 @@ public void setSessionToken_MergeOldWithNew() throws Exception { GlobalEndpointManager globalEndpointManagerMock = Mockito.mock(GlobalEndpointManager.class); RegionScopedSessionContainer sessionContainer = new RegionScopedSessionContainer("127.0.0.1", false, globalEndpointManagerMock); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -569,11 +566,10 @@ public void resolveGlobalSessionTokenReturnsEmptyStringOnCacheMiss() { GlobalEndpointManager globalEndpointManagerMock = Mockito.mock(GlobalEndpointManager.class); RegionScopedSessionContainer sessionContainer = new RegionScopedSessionContainer("127.0.0.1", false, globalEndpointManagerMock); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -601,11 +597,10 @@ public void resolveGlobalSessionTokenReturnsTokenMapUsingName() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -647,11 +642,10 @@ public void resolveGlobalSessionTokenReturnsTokenMapUsingResourceId() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -695,11 +689,10 @@ public void resolveLocalSessionTokenReturnsTokenMapUsingName() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -739,11 +732,10 @@ public void resolveLocalSessionTokenReturnsTokenMapUsingResourceId() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -788,11 +780,10 @@ public void resolveLocalSessionTokenReturnsNullOnPartitionMiss() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -833,11 +824,10 @@ public void resolveLocalSessionTokenReturnsNullOnCollectionMiss() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -876,11 +866,10 @@ public void resolvePartitionLocalSessionTokenReturnsTokenOnParentMatch() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -922,11 +911,10 @@ public void clearTokenByCollectionFullNameRemovesToken() { URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); String unparsedSessionToken = "range_0:1#100#1=20#2=5#3=30"; - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -985,11 +973,10 @@ public void clearTokenByResourceIdRemovesToken() { String unparsedSessionToken = "range_0:1#100#1=20#2=5#3=30"; - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1049,11 +1036,10 @@ public void clearTokenKeepsUnmatchedCollection() { URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); String unparsedSessionToken = "range_0:1#100#1=20#2=5#3=30"; - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1108,11 +1094,10 @@ public void setSessionTokenSetsTokenWhenRequestIsntNameBased() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1150,11 +1135,10 @@ public void setSessionTokenGivesPriorityToOwnerFullNameOverResourceAddress() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1197,11 +1181,10 @@ public void setSessionTokenIgnoresOwnerIdWhenRequestIsntNameBased() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1251,11 +1234,10 @@ public void setSessionTokenGivesPriorityToOwnerIdOverResourceIdWhenRequestIsName String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(LocationEastUsEndpointToLocationPair.getLeft()), Mockito.any())).thenReturn(regionContacted); @@ -1319,11 +1301,10 @@ public void setSessionTokenDoesntOverwriteHigherLSN() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1367,11 +1348,10 @@ public void setSessionTokenOverwriteLowerLSN() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1414,11 +1394,10 @@ public void setSessionTokenDoesNothingOnEmptySessionTokenHeader() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1510,11 +1489,10 @@ public void useParentSessionTokenAfterSplit() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1562,11 +1540,10 @@ public void useParentSessionTokenAfterMerge() { String regionContacted = LocationEastUsEndpointToLocationPair.getRight(); URI locationEndpointContacted = LocationEastUsEndpointToLocationPair.getLeft(); - UnmodifiableList endpoints = new UnmodifiableList<>( - ImmutableList.of( - new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), - new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft()))); + List endpoints = ImmutableList.of( + new RegionalRoutingContext(LocationEastUsEndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationEastUs2EndpointToLocationPair.getLeft()), + new RegionalRoutingContext(LocationCentralUsEndpointToLocationPair.getLeft())); Mockito.when(globalEndpointManagerMock.getReadEndpoints()).thenReturn(endpoints); Mockito.when(globalEndpointManagerMock.getRegionName(Mockito.eq(locationEndpointContacted), Mockito.any())).thenReturn(regionContacted); @@ -1683,7 +1660,7 @@ public void resolvePartitionLocalSessionToken( .when(globalEndpointManagerMock.getLatestDatabaseAccount()) .thenReturn(databaseAccount); - UnmodifiableList readEndpointsInUnmodifiableList = new UnmodifiableList<>(consolidatedReadRegionalEndpointRoutingContexts); + List readEndpointsInUnmodifiableList = Collections.unmodifiableList(consolidatedReadRegionalEndpointRoutingContexts); Mockito .when(globalEndpointManagerMock.getReadEndpoints()) @@ -1691,7 +1668,7 @@ public void resolvePartitionLocalSessionToken( Mockito .when(globalEndpointManagerMock.getApplicableWriteRegionalRoutingContexts(Mockito.anyList())) - .thenReturn(new UnmodifiableList<>(consolidatedWriteRegionalEndpointRoutingContexts)); + .thenReturn(Collections.unmodifiableList(consolidatedWriteRegionalEndpointRoutingContexts)); Mockito .when(globalEndpointManagerMock.canUseMultipleWriteLocations(Mockito.any())) diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/directconnectivity/GlobalAddressResolverTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/directconnectivity/GlobalAddressResolverTest.java index 331be53cc7af..2493b7a967c3 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/directconnectivity/GlobalAddressResolverTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/directconnectivity/GlobalAddressResolverTest.java @@ -3,10 +3,9 @@ package com.azure.cosmos.implementation.directconnectivity; - -import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.CosmosContainerProactiveInitConfig; import com.azure.cosmos.CosmosContainerProactiveInitConfigBuilder; +import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.implementation.Configs; import com.azure.cosmos.implementation.ConnectionPolicy; import com.azure.cosmos.implementation.DocumentCollection; @@ -19,7 +18,6 @@ import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.UserAgentContainer; import com.azure.cosmos.implementation.Utils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.apachecommons.lang.tuple.ImmutablePair; import com.azure.cosmos.implementation.caches.RxCollectionCache; import com.azure.cosmos.implementation.caches.RxPartitionKeyRangeCache; @@ -39,6 +37,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.UUID; @@ -82,13 +81,13 @@ public void before_GlobalAddressResolverTest() throws Exception { readEndPointList.add(new RegionalRoutingContext(urlforRead1)); readEndPointList.add(new RegionalRoutingContext(urlforRead2)); readEndPointList.add(new RegionalRoutingContext(urlforRead3)); - UnmodifiableList readList = new UnmodifiableList<>(readEndPointList); + List readList = Collections.unmodifiableList(readEndPointList); List writeEndPointList = new ArrayList<>(); writeEndPointList.add(new RegionalRoutingContext(urlforWrite1)); writeEndPointList.add(new RegionalRoutingContext(urlforWrite2)); writeEndPointList.add(new RegionalRoutingContext(urlforWrite3)); - UnmodifiableList writeList = new UnmodifiableList<>(writeEndPointList); + List writeList = Collections.unmodifiableList(writeEndPointList); Mockito.when(endpointManager.getReadEndpoints()).thenReturn(readList); Mockito.when(endpointManager.getWriteEndpoints()).thenReturn(writeList); @@ -157,7 +156,7 @@ public void submitOpenConnectionTasksAndInitCaches() { Mockito .when(endpointManager.getReadEndpoints()) - .thenReturn(new UnmodifiableList<>( + .thenReturn(Collections.unmodifiableList( Arrays.asList(new RegionalRoutingContext(urlforRead1), new RegionalRoutingContext(urlforRead2)))); DocumentCollection documentCollection = new DocumentCollection(); diff --git a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/routing/LocationCacheTest.java b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/routing/LocationCacheTest.java index 4d0680e60318..abe9c2dafbdd 100644 --- a/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/routing/LocationCacheTest.java +++ b/sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/routing/LocationCacheTest.java @@ -5,22 +5,21 @@ import com.azure.cosmos.CosmosExcludedRegions; import com.azure.cosmos.DirectConnectionConfig; +import com.azure.cosmos.implementation.Configs; import com.azure.cosmos.implementation.ConnectionPolicy; -import com.azure.cosmos.implementation.LifeCycleUtils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.DatabaseAccount; import com.azure.cosmos.implementation.DatabaseAccountLocation; -import com.azure.cosmos.implementation.Configs; import com.azure.cosmos.implementation.DatabaseAccountManagerInternal; import com.azure.cosmos.implementation.GlobalEndpointManager; +import com.azure.cosmos.implementation.LifeCycleUtils; import com.azure.cosmos.implementation.OperationType; import com.azure.cosmos.implementation.ResourceType; import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.Utils; import com.azure.cosmos.implementation.directconnectivity.ReflectionUtils; -import com.azure.cosmos.models.ModelBridgeUtils; import com.azure.cosmos.implementation.guava25.collect.ImmutableList; import com.azure.cosmos.implementation.guava25.collect.Iterables; +import com.azure.cosmos.models.ModelBridgeUtils; import org.testng.annotations.AfterClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -45,6 +44,7 @@ import java.util.stream.IntStream; import java.util.stream.Stream; import java.util.stream.StreamSupport; + import static com.azure.cosmos.implementation.TestUtils.mockDiagnosticsClientContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -76,7 +76,7 @@ public int getUnavailableLocationsExpirationTimeInSeconds() { } }; - private UnmodifiableList preferredLocations; + private List preferredLocations; private DatabaseAccount databaseAccount; private LocationCache cache; private GlobalEndpointManager endpointManager; @@ -589,8 +589,8 @@ private void initialize(boolean useMultipleWriteLocations, this.databaseAccount = LocationCacheTest.createDatabaseAccount(useMultipleWriteLocations); this.preferredLocations = isPreferredLocationsListEmpty ? - new UnmodifiableList<>(Collections.emptyList()) : - new UnmodifiableList<>(ImmutableList.of("location1", "location2", "location3")); + Collections.emptyList() : + ImmutableList.of("location1", "location2", "location3"); connectionPolicy.setPreferredRegions(this.preferredLocations); @@ -666,8 +666,8 @@ private void validateLocationCacheAsync( endpointDiscoveryEnabled, isPreferredListEmpty); - UnmodifiableList currentWriteEndpoints = this.cache.getWriteEndpoints(); - UnmodifiableList currentReadEndpoints = this.cache.getReadEndpoints(); + List currentWriteEndpoints = this.cache.getWriteEndpoints(); + List currentReadEndpoints = this.cache.getReadEndpoints(); for (int i = 0; i < readLocationIndex; i++) { this.cache.markEndpointUnavailableForRead(createUrl(Iterables.get(this.databaseAccount.getReadableLocations(), i).getEndpoint())); this.endpointManager.markEndpointUnavailableForRead(createUrl(Iterables.get(this.databaseAccount.getReadableLocations(), i).getEndpoint()));; @@ -897,7 +897,7 @@ private void validateRequestEndpointResolution( // If current write endpoint is unavailable, write endpoints order doesn't change // ALL write requests flip-flop between current write and alternate write endpoint - UnmodifiableList writeEndpoints = this.cache.getWriteEndpoints(); + List writeEndpoints = this.cache.getWriteEndpoints(); assertThat(new RegionalRoutingContext(firstAvailableWriteEndpoint)).isEqualTo(writeEndpoints.get(0)); assertThat(new RegionalRoutingContext(secondAvailableWriteEndpoint)).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Document, true)); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java index 12d022e69ee7..262415757bc6 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosClientBuilder.java @@ -15,11 +15,9 @@ import com.azure.cosmos.implementation.DiagnosticsProvider; import com.azure.cosmos.implementation.Strings; import com.azure.cosmos.implementation.WriteRetryPolicy; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.azure.cosmos.implementation.apachecommons.lang.time.StopWatch; import com.azure.cosmos.implementation.guava25.base.Preconditions; -import com.azure.cosmos.implementation.perPartitionCircuitBreaker.PartitionLevelCircuitBreakerConfig; import com.azure.cosmos.implementation.routing.LocationHelper; import com.azure.cosmos.models.CosmosAuthorizationTokenResolver; import com.azure.cosmos.models.CosmosClientTelemetryConfig; @@ -300,7 +298,7 @@ public CosmosClientBuilder addOperationPolicy(CosmosOperationPolicy policy) { } List getOperationPolicies() { - return UnmodifiableList.unmodifiableList(this.requestPolicies); + return Collections.unmodifiableList(this.requestPolicies); } /** diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientRetryPolicy.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientRetryPolicy.java index ca9731f86e50..dc95a9260486 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientRetryPolicy.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ClientRetryPolicy.java @@ -6,19 +6,19 @@ import com.azure.cosmos.CosmosDiagnostics; import com.azure.cosmos.CosmosException; import com.azure.cosmos.ThrottlingRetryOptions; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.caches.RxCollectionCache; -import com.azure.cosmos.implementation.perPartitionCircuitBreaker.GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker; import com.azure.cosmos.implementation.directconnectivity.WebExceptionUtility; import com.azure.cosmos.implementation.faultinjection.FaultInjectionRequestContext; -import com.azure.cosmos.implementation.routing.RegionalRoutingContext; import com.azure.cosmos.implementation.perPartitionAutomaticFailover.GlobalPartitionEndpointManagerForPerPartitionAutomaticFailover; +import com.azure.cosmos.implementation.perPartitionCircuitBreaker.GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker; +import com.azure.cosmos.implementation.routing.RegionalRoutingContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; import java.net.URI; import java.time.Duration; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull; @@ -235,7 +235,7 @@ private ShouldRetryResult shouldRetryOnSessionNotAvailable(RxDocumentServiceRequ return ShouldRetryResult.noRetry(); } else { if (this.canUseMultipleWriteLocations) { - UnmodifiableList endpoints = + List endpoints = this.isReadRequest ? this.globalEndpointManager.getApplicableReadRegionalRoutingContexts(request) : this.globalEndpointManager.getApplicableWriteRegionalRoutingContexts(request); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosBulkExecutionOptionsImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosBulkExecutionOptionsImpl.java index ad2be21bfe92..90cee02dd59b 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosBulkExecutionOptionsImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosBulkExecutionOptionsImpl.java @@ -8,7 +8,6 @@ import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.CosmosItemSerializer; import com.azure.cosmos.ReadConsistencyStrategy; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.batch.BatchRequestResponseConstants; import com.azure.cosmos.implementation.batch.BulkExecutorDiagnosticsTracker; import com.azure.cosmos.implementation.spark.OperationContextAndListenerTuple; @@ -19,6 +18,7 @@ import java.time.Duration; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -327,7 +327,7 @@ public List getExcludedRegions() { if (this.excludeRegions == null) { return null; } - return UnmodifiableList.unmodifiableList(this.excludeRegions); + return Collections.unmodifiableList(this.excludeRegions); } public void setDiagnosticsTracker(BulkExecutorDiagnosticsTracker tracker) { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosChangeFeedRequestOptionsImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosChangeFeedRequestOptionsImpl.java index 2ef17d397b5f..1fa3434f9e32 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosChangeFeedRequestOptionsImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosChangeFeedRequestOptionsImpl.java @@ -8,7 +8,6 @@ import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.CosmosItemSerializer; import com.azure.cosmos.ReadConsistencyStrategy; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.changefeed.common.ChangeFeedMode; import com.azure.cosmos.implementation.changefeed.common.ChangeFeedStartFromInternal; import com.azure.cosmos.implementation.changefeed.common.ChangeFeedState; @@ -21,6 +20,7 @@ import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.util.Beta; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -337,7 +337,7 @@ public List getExcludedRegions() { if (this.excludeRegions == null) { return null; } - return UnmodifiableList.unmodifiableList(this.excludeRegions); + return Collections.unmodifiableList(this.excludeRegions); } public CosmosChangeFeedRequestOptionsImpl setHeader(String name, String value) { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosQueryRequestOptionsBase.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosQueryRequestOptionsBase.java index b27fbba4acea..2864fd07a87a 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosQueryRequestOptionsBase.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosQueryRequestOptionsBase.java @@ -8,7 +8,6 @@ import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.CosmosItemSerializer; import com.azure.cosmos.ReadConsistencyStrategy; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.spark.OperationContextAndListenerTuple; import com.azure.cosmos.models.CosmosQueryRequestOptions; import com.azure.cosmos.models.CosmosRequestOptions; @@ -271,7 +270,7 @@ public List getExcludedRegions() { if (this.excludeRegions == null) { return null; } - return UnmodifiableList.unmodifiableList(this.excludeRegions); + return Collections.unmodifiableList(this.excludeRegions); } /** diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/GlobalEndpointManager.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/GlobalEndpointManager.java index ec0ceb536615..66367e522028 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/GlobalEndpointManager.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/GlobalEndpointManager.java @@ -3,7 +3,6 @@ package com.azure.cosmos.implementation; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.routing.LocationCache; import com.azure.cosmos.implementation.routing.LocationHelper; import com.azure.cosmos.implementation.routing.RegionalRoutingContext; @@ -21,7 +20,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Consumer; @@ -95,32 +93,32 @@ public void init() { startRefreshLocationTimerAsync(true).block(maxInitializationTime); } - public UnmodifiableList getReadEndpoints() { + public List getReadEndpoints() { // readonly return this.locationCache.getReadEndpoints(); } - public UnmodifiableList getWriteEndpoints() { + public List getWriteEndpoints() { //readonly return this.locationCache.getWriteEndpoints(); } - public UnmodifiableList getApplicableReadRegionalRoutingContexts(RxDocumentServiceRequest request) { + public List getApplicableReadRegionalRoutingContexts(RxDocumentServiceRequest request) { // readonly return this.locationCache.getApplicableReadRegionRoutingContexts(request); } - public UnmodifiableList getApplicableWriteRegionalRoutingContexts(RxDocumentServiceRequest request) { + public List getApplicableWriteRegionalRoutingContexts(RxDocumentServiceRequest request) { //readonly return this.locationCache.getApplicableWriteRegionRoutingContexts(request); } - public UnmodifiableList getApplicableReadRegionalRoutingContexts(List excludedRegions) { + public List getApplicableReadRegionalRoutingContexts(List excludedRegions) { // readonly return this.locationCache.getApplicableReadRegionRoutingContexts(excludedRegions, Collections.emptyList()); } - public UnmodifiableList getApplicableWriteRegionalRoutingContexts(List excludedRegions) { + public List getApplicableWriteRegionalRoutingContexts(List excludedRegions) { //readonly return this.locationCache.getApplicableWriteRegionRoutingContexts(excludedRegions, Collections.emptyList()); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/PartitionScopedRegionLevelProgress.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/PartitionScopedRegionLevelProgress.java index c88955c78ea4..f97db1cd9627 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/PartitionScopedRegionLevelProgress.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/PartitionScopedRegionLevelProgress.java @@ -5,7 +5,6 @@ import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.CosmosException; -import com.azure.cosmos.implementation.apachecommons.collections.map.UnmodifiableMap; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.azure.cosmos.implementation.routing.PartitionKeyInternal; import com.azure.cosmos.implementation.routing.RegionNameToRegionIdMap; @@ -100,7 +99,7 @@ public void tryRecordSessionToken( checkNotNull(globalLevelProgress, "globalLevelProgress cannot be null!"); // identify whether regionRoutedTo has a regionId mapping in session token - Utils.ValueHolder> localLsnByRegion = new Utils.ValueHolder<>(); + Utils.ValueHolder> localLsnByRegion = new Utils.ValueHolder<>(); // if regionId to localLsn mappings cannot be extracted, the only mapping would be "global" to whatever is the session token corresponding to the globalLsn seen across all regions if (!SessionTokenHelper.tryEvaluateLocalLsnByRegionMappingWithNullSafety(parsedSessionToken, localLsnByRegion)) { @@ -331,7 +330,7 @@ public ISessionToken tryResolveSessionToken( long globalLsn = -1; - Utils.ValueHolder> localLsnByRegion = new Utils.ValueHolder<>(); + Utils.ValueHolder> localLsnByRegion = new Utils.ValueHolder<>(); // return global merged progress of the session token for a given physical partition since regionId to localLsn mappings cannot be resolved if (!SessionTokenHelper.tryEvaluateLocalLsnByRegionMappingWithNullSafety(globalSessionTokenAsVal, localLsnByRegion)) { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/SessionTokenHelper.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/SessionTokenHelper.java index 8667e40aa879..a26b9d1e8596 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/SessionTokenHelper.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/SessionTokenHelper.java @@ -3,7 +3,6 @@ package com.azure.cosmos.implementation; -import com.azure.cosmos.implementation.apachecommons.collections.map.UnmodifiableMap; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.azure.cosmos.implementation.routing.PartitionKeyInternal; import com.azure.cosmos.models.PartitionKeyDefinition; @@ -14,6 +13,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -258,7 +258,7 @@ public static String concatPartitionKeyRangeIdWithSessionToken(String partition return partitionKeyRangeRid + ":" + sessionToken; } - public static boolean tryEvaluateLocalLsnByRegionMappingWithNullSafety(ISessionToken sessionToken, Utils.ValueHolder> localLsnByRegion) { + public static boolean tryEvaluateLocalLsnByRegionMappingWithNullSafety(ISessionToken sessionToken, Utils.ValueHolder> localLsnByRegion) { if (sessionToken instanceof VectorSessionToken) { VectorSessionToken castVectorSessionToken = Utils.as(sessionToken, VectorSessionToken.class); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/VectorSessionToken.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/VectorSessionToken.java index 897f3b18742e..531c7bc50a34 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/VectorSessionToken.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/VectorSessionToken.java @@ -3,13 +3,12 @@ package com.azure.cosmos.implementation; - -import com.azure.cosmos.implementation.apachecommons.collections.map.UnmodifiableMap; import com.azure.cosmos.implementation.apachecommons.lang.ObjectUtils; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -35,42 +34,30 @@ public class VectorSessionToken implements ISessionToken { private final long version; private final long globalLsn; - private final UnmodifiableMap localLsnByRegion; + private final Map localLsnByRegion; private final String sessionToken; private final boolean isSessionTokenFalseProgressMergeEnabled = Configs.isSessionTokenFalseProgressMergeEnabled(); - private VectorSessionToken(long version, long globalLsn, UnmodifiableMap localLsnByRegion) { + private VectorSessionToken(long version, long globalLsn, Map localLsnByRegion) { this(version, globalLsn, localLsnByRegion, null); } - private VectorSessionToken(long version, long globalLsn, UnmodifiableMap localLsnByRegion, String sessionToken) { + private VectorSessionToken(long version, long globalLsn, Map localLsnByRegion, String sessionToken) { this.version = version; this.globalLsn = globalLsn; this.localLsnByRegion = localLsnByRegion; if (sessionToken == null) { - String regionProgress = String.join( - Character.toString(VectorSessionToken.SegmentSeparator), - localLsnByRegion. - entrySet() - .stream() - .map(kvp -> new StringBuilder().append(kvp.getKey()).append(VectorSessionToken.RegionProgressSeparator).append(kvp.getValue())) - .collect(Collectors.toList())); + String regionProgress = localLsnByRegion.entrySet() + .stream() + .map(kvp -> "" + kvp.getKey() + VectorSessionToken.RegionProgressSeparator + kvp.getValue()) + .collect(Collectors.joining(Character.toString(VectorSessionToken.SegmentSeparator))); if (Strings.isNullOrEmpty(regionProgress)) { - StringBuilder sb = new StringBuilder(); - sb.append(this.version) - .append(VectorSessionToken.SegmentSeparator) - .append(this.globalLsn); - this.sessionToken = sb.toString(); + this.sessionToken = String.valueOf(this.version) + VectorSessionToken.SegmentSeparator + this.globalLsn; } else { - StringBuilder sb = new StringBuilder(); - sb.append(this.version) - .append(VectorSessionToken.SegmentSeparator) - .append(this.globalLsn) - .append(VectorSessionToken.SegmentSeparator) - .append(regionProgress); - this.sessionToken = sb.toString(); + this.sessionToken = String.valueOf(this.version) + VectorSessionToken.SegmentSeparator + this.globalLsn + + VectorSessionToken.SegmentSeparator + regionProgress; } } else { this.sessionToken = sessionToken; @@ -81,7 +68,7 @@ public static boolean tryCreate(String sessionToken, ValueHolder ValueHolder versionHolder = ValueHolder.initialize(-1l); ValueHolder globalLsnHolder = ValueHolder.initialize(-1l); - ValueHolder> localLsnByRegion = ValueHolder.initialize(null); + ValueHolder> localLsnByRegion = ValueHolder.initialize(null); if (VectorSessionToken.tryParseSessionToken( sessionToken, @@ -233,7 +220,7 @@ public ISessionToken merge(ISessionToken obj) { return new VectorSessionToken( Math.max(this.version, other.version), (!isSessionTokenFalseProgressMergeEnabled || this.version == other.version) ? Math.max(this.globalLsn, other.globalLsn) : sessionTokenWithHigherVersion.globalLsn, - (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(highestLocalLsnByRegion)); + Collections.unmodifiableMap(highestLocalLsnByRegion)); } public String convertToString() { @@ -244,11 +231,11 @@ public long getVersion() { return version; } - public UnmodifiableMap getLocalLsnByRegion() { + public Map getLocalLsnByRegion() { return localLsnByRegion; } - private boolean areRegionProgressEqual(UnmodifiableMap other) { + private boolean areRegionProgressEqual(Map other) { if (this.localLsnByRegion.size() != other.size()) { return false; } @@ -272,7 +259,7 @@ private static boolean tryParseSessionToken( String sessionToken, ValueHolder version, ValueHolder globalLsn, - ValueHolder> localLsnByRegion) { + ValueHolder> localLsnByRegion) { version.v = 0L; localLsnByRegion.v = null; globalLsn.v = -1L; @@ -318,7 +305,7 @@ private static boolean tryParseSessionToken( lsnByRegion.put(regionId.v, localLsn.v); } - localLsnByRegion.v = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(lsnByRegion); + localLsnByRegion.v = Collections.unmodifiableMap(lsnByRegion); return true; } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/AbstractCollectionDecorator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/AbstractCollectionDecorator.java deleted file mode 100644 index 366227513ffb..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/AbstractCollectionDecorator.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Iterator; - -public abstract class AbstractCollectionDecorator - implements Collection, Serializable { - /** Serialization version */ - private static final long serialVersionUID = 4124674254999113719L; - - /** The collection being decorated */ - private Collection collection; - - /** - * Constructor only used in deserialization, do not use otherwise. - */ - protected AbstractCollectionDecorator() { - super(); - } - - /** - * Constructor that wraps (not copies). - * - * @param coll the collection to decorate, must not be null - * @throws NullPointerException if the collection is null - */ - protected AbstractCollectionDecorator(final Collection coll) { - if (coll == null) { - throw new NullPointerException("Collection must not be null."); - } - this.collection = coll; - } - - /** - * Gets the collection being decorated. - * All access to the decorated collection goes via this method. - * - * @return the decorated collection - */ - protected Collection decorated() { - return collection; - } - - /** - * Sets the collection being decorated. - *

- * NOTE: this method should only be used during deserialization - * - * @param coll the decorated collection - */ - protected void setCollection(final Collection coll) { - this.collection = coll; - } - - @Override - public boolean add(final E object) { - return decorated().add(object); - } - - @Override - public boolean addAll(final Collection coll) { - return decorated().addAll(coll); - } - - @Override - public void clear() { - decorated().clear(); - } - - @Override - public boolean contains(final Object object) { - return decorated().contains(object); - } - - @Override - public boolean isEmpty() { - return decorated().isEmpty(); - } - - @Override - public Iterator iterator() { - return decorated().iterator(); - } - - @Override - public boolean remove(final Object object) { - return decorated().remove(object); - } - - @Override - public int size() { - return decorated().size(); - } - - @Override - public Object[] toArray() { - return decorated().toArray(); - } - - @Override - public T[] toArray(final T[] object) { - return decorated().toArray(object); - } - - @Override - public boolean containsAll(final Collection coll) { - return decorated().containsAll(coll); - } - - @Override - public boolean removeAll(final Collection coll) { - return decorated().removeAll(coll); - } - - @Override - public boolean retainAll(final Collection coll) { - return decorated().retainAll(coll); - } - - @Override - public String toString() { - return decorated().toString(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/CollectionUtils.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/CollectionUtils.java deleted file mode 100644 index 61ef3d715076..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/CollectionUtils.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -import java.util.Collection; -import java.util.Collections; - -public class CollectionUtils { - /** - * An empty unmodifiable collection. - * The JDK provides empty Set and List implementations which could be used for - * this purpose. However they could be cast to Set or List which might be - * undesirable. This implementation only implements Collection. - */ - @SuppressWarnings("rawtypes") // we deliberately use the raw type here - public static final Collection EMPTY_COLLECTION = Collections.emptyList(); - - - private CollectionUtils() {} - - /** - * Returns the immutable EMPTY_COLLECTION with generic type safety. - * - * @see #EMPTY_COLLECTION - * @param the element type - * @return immutable empty collection - */ - @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type - public static Collection emptyCollection() { - return EMPTY_COLLECTION; - } - - - /** - * Returns an immutable empty collection if the argument is null, - * or the argument itself otherwise. - * - * @param the element type - * @param collection the collection, possibly null - * @return an empty collection if the argument is null - */ - public static Collection emptyIfNull(final Collection collection) { - return collection == null ? CollectionUtils.emptyCollection() : collection; - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/ComparatorUtils.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/ComparatorUtils.java deleted file mode 100644 index 1c081661caf1..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/ComparatorUtils.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -import com.azure.cosmos.implementation.apachecommons.collections.comparators.ComparableComparator; - -import java.util.Comparator; - -public class ComparatorUtils { - /** - * Comparator for natural sort order. - * - * @see ComparableComparator#comparableComparator() - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) // explicit type needed for Java 1.5 compilation - public static final Comparator NATURAL_COMPARATOR = ComparableComparator.comparableComparator(); - - /** - * Gets a comparator that uses the natural order of the objects. - * - * @param the object type to compare - * @return a comparator which uses natural order - */ - @SuppressWarnings("unchecked") - public static > Comparator naturalComparator() { - return NATURAL_COMPARATOR; - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/Get.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/Get.java deleted file mode 100644 index 07e6d355f6c8..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/Get.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -import java.util.Collection; -import java.util.Set; - -public interface Get { - - /** - * @param key key whose presence in this map is to be tested - * @return true if this map contains a mapping for the specified - * key - * @see java.util.Map#containsKey(Object) - */ - boolean containsKey(Object key); - - /** - * @param value value whose presence in this map is to be tested - * @return true if this map maps one or more keys to the - * specified value - * @see java.util.Map#containsValue(Object) - */ - boolean containsValue(Object value); - - /** - * @return a set view of the mappings contained in this map - * @see java.util.Map#entrySet() - */ - Set> entrySet(); - - /** - * @param key the key whose associated value is to be returned - * @return the value to which the specified key is mapped, or - * {@code null} if this map contains no mapping for the key - * @see java.util.Map#get(Object) - */ - V get(Object key); - - /** - * @param key key whose mapping is to be removed from the map - * @return the previous value associated with key, or - * null if there was no mapping for key. - * @see java.util.Map#remove(Object) - */ - V remove(Object key); - - /** - * @return true if this map contains no key-value mappings - * @see java.util.Map#isEmpty() - */ - boolean isEmpty(); - - /** - * @return a set view of the keys contained in this map - * @see java.util.Map#keySet() - */ - Set keySet(); - - /** - * @return the number of key-value mappings in this map - * @see java.util.Map#size() - */ - int size(); - - /** - * @return a collection view of the values contained in this map - * @see java.util.Map#values() - */ - Collection values(); -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/IterableGet.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/IterableGet.java deleted file mode 100644 index e8e9df596a27..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/IterableGet.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -public interface IterableGet extends Get { - /** - * Obtains a MapIterator over the map. - *

- * A map iterator is an efficient way of iterating over maps. - * There is no need to access the entry set or use Map Entry objects. - *

-     * IterableMap<String,Integer> map = new HashedMap<String,Integer>();
-     * MapIterator<String,Integer> it = map.mapIterator();
-     * while (it.hasNext()) {
-     *   String key = it.next();
-     *   Integer value = it.getValue();
-     *   it.setValue(value + 1);
-     * }
-     * 
- * - * @return a map iterator - */ - MapIterator mapIterator(); -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/IterableMap.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/IterableMap.java deleted file mode 100644 index 31c216e40433..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/IterableMap.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -import java.util.Map; - -public interface IterableMap extends Map, Put, IterableGet { - // empty -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/KeyValue.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/KeyValue.java deleted file mode 100644 index c03912f0099c..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/KeyValue.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -public interface KeyValue { - /** - * Gets the key from the pair. - * - * @return the key - */ - K getKey(); - - /** - * Gets the value from the pair. - * - * @return the value - */ - V getValue(); -} - diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/MapIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/MapIterator.java deleted file mode 100644 index d450e4c9ea52..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/MapIterator.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -import java.util.Iterator; - -public interface MapIterator extends Iterator { - /** - * Checks to see if there are more entries still to be iterated. - * - * @return true if the iterator has more elements - */ - @Override - boolean hasNext(); - - /** - * Gets the next key from the Map. - * - * @return the next key in the iteration - * @throws java.util.NoSuchElementException if the iteration is finished - */ - @Override - K next(); - - /** - * Gets the current key, which is the key returned by the last call - * to next(). - * - * @return the current key - * @throws IllegalStateException if next() has not yet been called - */ - K getKey(); - - /** - * Gets the current value, which is the value associated with the last key - * returned by next(). - * - * @return the current value - * @throws IllegalStateException if next() has not yet been called - */ - V getValue(); - - /** - * Removes the last returned key from the underlying Map (optional operation). - *

- * This method can be called once per call to next(). - * - * @throws UnsupportedOperationException if remove is not supported by the map - * @throws IllegalStateException if next() has not yet been called - * @throws IllegalStateException if remove() has already been called - * since the last call to next() - */ - @Override - void remove(); - - /** - * Sets the value associated with the current key (optional operation). - * - * @param value the new value - * @return the previous value - * @throws UnsupportedOperationException if setValue is not supported by the map - * @throws IllegalStateException if next() has not yet been called - * @throws IllegalStateException if remove() has been called since the - * last call to next() - */ - V setValue(V value); -} - diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/Put.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/Put.java deleted file mode 100644 index 0785972c0c93..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/Put.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - - -import java.util.Map; - -public interface Put { - /** - * @see Map#clear() - */ - void clear(); - - /** - * Note that the return type is Object, rather than V as in the Map interface. - * See the class Javadoc for further info. - * - * @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 key, or - * null if there was no mapping for key. - * (A null return can also indicate that the map - * previously associated null with key, - * if the implementation supports null values.) - * @see Map#put(Object, Object) - */ - Object put(K key, V value); - - /** - * @param t mappings to be stored in this map - * @see Map#putAll(Map) - */ - void putAll(Map t); -} - diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/ResettableIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/ResettableIterator.java deleted file mode 100644 index 086a78bfb2c5..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/ResettableIterator.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -import java.util.Iterator; - -public interface ResettableIterator extends Iterator { - /** - * Resets the iterator back to the position at which the iterator - * was created. - */ - void reset(); -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/UnmodifiableCollection.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/UnmodifiableCollection.java deleted file mode 100644 index 59c8ba666c5a..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/UnmodifiableCollection.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections; - -import java.util.Collection; -import java.util.Iterator; - -import com.azure.cosmos.implementation.apachecommons.collections.list.Unmodifiable; -import com.azure.cosmos.implementation.apachecommons.collections.list.iterators.UnmodifiableIterator; - -public final class UnmodifiableCollection - extends AbstractCollectionDecorator - implements Unmodifiable { - /** Serialization version */ - private static final long serialVersionUID = -1742294389933370464L; - - /** - * Factory method to create an unmodifiable collection. - *

- * If the collection passed in is already unmodifiable, it is returned. - * - * @param the type of the elements in the collection - * @param coll the collection to decorate, must not be null - * @return an unmodifiable collection - * @throws NullPointerException if collection is null - */ - public static Collection unmodifiableCollection(final Collection coll) { - if (coll instanceof Unmodifiable) { - @SuppressWarnings("unchecked") // safe to upcast - final Collection tmpColl = (Collection) coll; - return tmpColl; - } - return new UnmodifiableCollection<>(coll); - } - - /** - * Constructor that wraps (not copies). - * - * @param coll the collection to decorate, must not be null - * @throws NullPointerException if collection is null - */ - @SuppressWarnings("unchecked") // safe to upcast - private UnmodifiableCollection(final Collection coll) { - super((Collection) coll); - } - - @Override - public Iterator iterator() { - return UnmodifiableIterator.unmodifiableIterator(decorated().iterator()); - } - - @Override - public boolean add(final E object) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean addAll(final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean remove(final Object object) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean removeAll(final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean retainAll(final Collection coll) { - throw new UnsupportedOperationException(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/comparators/ComparableComparator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/comparators/ComparableComparator.java deleted file mode 100644 index 40a608dc6964..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/comparators/ComparableComparator.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.comparators; - -import java.io.Serializable; -import java.util.Comparator; - -public class ComparableComparator> implements Comparator, Serializable { - /** Serialization version. */ - private static final long serialVersionUID = 7476918961260943496L; - - /** The singleton instance. */ - @SuppressWarnings("rawtypes") - public static final ComparableComparator INSTANCE = new ComparableComparator(); - - /** - * Gets the singleton instance of a ComparableComparator. - *

- * Developers are encouraged to use the comparator returned from this method - * instead of constructing a new instance to reduce allocation and GC overhead - * when multiple comparable comparators may be used in the same VM. - * - * @param the element type - * @return the singleton ComparableComparator - */ - @SuppressWarnings("unchecked") - public static > ComparableComparator comparableComparator() { - return INSTANCE; - } - - /** - * Constructor whose use should be avoided. - *

- * Please use the {@link #comparableComparator()} method whenever possible. - */ - public ComparableComparator() { - super(); - } - - /** - * Compare the two {@link Comparable Comparable} arguments. - * This method is equivalent to: - *

((Comparable)obj1).compareTo(obj2)
- * - * @param obj1 the first object to compare - * @param obj2 the second object to compare - * @return negative if obj1 is less, positive if greater, zero if equal - * @throws NullPointerException if obj1 is null, - * or when ((Comparable)obj1).compareTo(obj2) does - * @throws ClassCastException if obj1 is not a Comparable, - * or when ((Comparable)obj1).compareTo(obj2) does - */ - @Override - public int compare(final E obj1, final E obj2) { - return obj1.compareTo(obj2); - } - - /** - * Implement a hash code for this comparator that is consistent with - * {@link #equals(Object) equals}. - * - * @return a hash code for this comparator. - */ - @Override - public int hashCode() { - return "ComparableComparator".hashCode(); - } - - /** - * Returns {@code true} iff that Object is is a {@link Comparator Comparator} - * whose ordering is known to be equivalent to mine. - *

- * This implementation returns {@code true} iff - * object.{@link Object#getClass() getClass()} equals - * this.getClass(). Subclasses may want to override this behavior to remain - * consistent with the {@link Comparator#equals(Object)} contract. - * - * @param object the object to compare with - * @return {@code true} if equal - */ - @Override - public boolean equals(final Object object) { - return this == object || - null != object && object.getClass().equals(this.getClass()); - } -} - diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractEmptyIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractEmptyIterator.java deleted file mode 100644 index 5aebcbf24e3e..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractEmptyIterator.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.iterators; - -import java.util.NoSuchElementException; - -abstract class AbstractEmptyIterator { - /** - * Constructor. - */ - protected AbstractEmptyIterator() { - super(); - } - - public boolean hasNext() { - return false; - } - - public E next() { - throw new NoSuchElementException("Iterator contains no elements"); - } - - public boolean hasPrevious() { - return false; - } - - public E previous() { - throw new NoSuchElementException("Iterator contains no elements"); - } - - public int nextIndex() { - return 0; - } - - public int previousIndex() { - return -1; - } - - public void add(final E obj) { - throw new UnsupportedOperationException("add() not supported for empty Iterator"); - } - - public void set(final E obj) { - throw new IllegalStateException("Iterator contains no elements"); - } - - public void remove() { - throw new IllegalStateException("Iterator contains no elements"); - } - - public void reset() { - // do nothing - } -} - diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractEmptyMapIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractEmptyMapIterator.java deleted file mode 100644 index 03a622bf183b..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractEmptyMapIterator.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.iterators; - -public abstract class AbstractEmptyMapIterator extends AbstractEmptyIterator { - /** - * Create a new AbstractEmptyMapIterator. - */ - public AbstractEmptyMapIterator() { - super(); - } - - public K getKey() { - throw new IllegalStateException("Iterator contains no elements"); - } - - public V getValue() { - throw new IllegalStateException("Iterator contains no elements"); - } - - public V setValue(final V value) { - throw new IllegalStateException("Iterator contains no elements"); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractIteratorDecorator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractIteratorDecorator.java deleted file mode 100644 index 201ed1950fe8..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractIteratorDecorator.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.iterators; - -import java.util.Iterator; - -public abstract class AbstractIteratorDecorator extends AbstractUntypedIteratorDecorator { - /** - * Constructor that decorates the specified iterator. - * - * @param iterator the iterator to decorate, must not be null - * @throws NullPointerException if the iterator is null - */ - protected AbstractIteratorDecorator(final Iterator iterator) { - super(iterator); - } - - /** {@inheritDoc} */ - @Override - public E next() { - return getIterator().next(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractUntypedIteratorDecorator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractUntypedIteratorDecorator.java deleted file mode 100644 index 68c260cc15eb..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/AbstractUntypedIteratorDecorator.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.iterators; - -import java.util.Iterator; - -public abstract class AbstractUntypedIteratorDecorator implements Iterator { - /** The iterator being decorated */ - private final Iterator iterator; - - /** - * Create a new AbstractUntypedIteratorDecorator. - * - * @param iterator the iterator to decorate - * @throws NullPointerException if the iterator is null - */ - protected AbstractUntypedIteratorDecorator(final Iterator iterator) { - super(); - if (iterator == null) { - throw new NullPointerException("Iterator must not be null"); - } - this.iterator = iterator; - } - - /** - * Gets the iterator being decorated. - * - * @return the decorated iterator - */ - protected Iterator getIterator() { - return iterator; - } - - @Override - public boolean hasNext() { - return iterator.hasNext(); - } - - @Override - public void remove() { - iterator.remove(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EmptyIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EmptyIterator.java deleted file mode 100644 index 3daebdf59b6b..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EmptyIterator.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.iterators; - -import com.azure.cosmos.implementation.apachecommons.collections.ResettableIterator; - -import java.util.Iterator; - -public class EmptyIterator extends AbstractEmptyIterator implements ResettableIterator { - /** - * Singleton instance of the iterator. - */ - @SuppressWarnings("rawtypes") - public static final ResettableIterator RESETTABLE_INSTANCE = new EmptyIterator<>(); - - /** - * Singleton instance of the iterator. - */ - @SuppressWarnings("rawtypes") - public static final Iterator INSTANCE = RESETTABLE_INSTANCE; - - /** - * Get a typed resettable empty iterator instance. - * @param the element type - * @return ResettableIterator<E> - */ - @SuppressWarnings("unchecked") - public static ResettableIterator resettableEmptyIterator() { - return RESETTABLE_INSTANCE; - } - - /** - * Get a typed empty iterator instance. - * @param the element type - * @return Iterator<E> - */ - @SuppressWarnings("unchecked") - public static Iterator emptyIterator() { - return INSTANCE; - } - - /** - * Constructor. - */ - protected EmptyIterator() { - super(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EmptyMapIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EmptyMapIterator.java deleted file mode 100644 index 7f0aff134e14..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EmptyMapIterator.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.iterators; - -import com.azure.cosmos.implementation.apachecommons.collections.MapIterator; -import com.azure.cosmos.implementation.apachecommons.collections.ResettableIterator; - -public class EmptyMapIterator extends AbstractEmptyMapIterator implements - MapIterator, ResettableIterator { - - /** - * Singleton instance of the iterator. - */ - @SuppressWarnings("rawtypes") - public static final MapIterator INSTANCE = new EmptyMapIterator<>(); - - /** - * Get a typed instance of the iterator. - * @param the key type - * @param the value type - * @return {@link MapIterator}<K, V> - */ - @SuppressWarnings("unchecked") - public static MapIterator emptyMapIterator() { - return INSTANCE; - } - - /** - * Constructor. - */ - protected EmptyMapIterator() { - super(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EntrySetMapIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EntrySetMapIterator.java deleted file mode 100644 index 559778fb929d..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/EntrySetMapIterator.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.iterators; - -import com.azure.cosmos.implementation.apachecommons.collections.MapIterator; -import com.azure.cosmos.implementation.apachecommons.collections.ResettableIterator; - -import java.util.Iterator; -import java.util.Map; - -public class EntrySetMapIterator implements MapIterator, ResettableIterator { - private final Map map; - private Iterator> iterator; - private Map.Entry last; - private boolean canRemove = false; - - /** - * Constructor. - * - * @param map the map to iterate over - */ - public EntrySetMapIterator(final Map map) { - super(); - this.map = map; - this.iterator = map.entrySet().iterator(); - } - - /** - * Checks to see if there are more entries still to be iterated. - * - * @return true if the iterator has more elements - */ - @Override - public boolean hasNext() { - return iterator.hasNext(); - } - - /** - * Gets the next key from the Map. - * - * @return the next key in the iteration - * @throws java.util.NoSuchElementException if the iteration is finished - */ - @Override - public K next() { - last = iterator.next(); - canRemove = true; - return last.getKey(); - } - - /** - * Removes the last returned key from the underlying Map. - *

- * This method can be called once per call to next(). - * - * @throws UnsupportedOperationException if remove is not supported by the map - * @throws IllegalStateException if next() has not yet been called - * @throws IllegalStateException if remove() has already been called - * since the last call to next() - */ - @Override - public void remove() { - if (canRemove == false) { - throw new IllegalStateException("Iterator remove() can only be called once after next()"); - } - iterator.remove(); - last = null; - canRemove = false; - } - - /** - * Gets the current key, which is the key returned by the last call - * to next(). - * - * @return the current key - * @throws IllegalStateException if next() has not yet been called - */ - @Override - public K getKey() { - if (last == null) { - throw new IllegalStateException("Iterator getKey() can only be called after next() and before remove()"); - } - return last.getKey(); - } - - /** - * Gets the current value, which is the value associated with the last key - * returned by next(). - * - * @return the current value - * @throws IllegalStateException if next() has not yet been called - */ - @Override - public V getValue() { - if (last == null) { - throw new IllegalStateException("Iterator getValue() can only be called after next() and before remove()"); - } - return last.getValue(); - } - - /** - * Sets the value associated with the current key. - * - * @param value the new value - * @return the previous value - * @throws UnsupportedOperationException if setValue is not supported by the map - * @throws IllegalStateException if next() has not yet been called - * @throws IllegalStateException if remove() has been called since the - * last call to next() - */ - @Override - public V setValue(final V value) { - if (last == null) { - throw new IllegalStateException("Iterator setValue() can only be called after next() and before remove()"); - } - return last.setValue(value); - } - - /** - * Resets the state of the iterator. - */ - @Override - public void reset() { - iterator = map.entrySet().iterator(); - last = null; - canRemove = false; - } - - /** - * Gets the iterator as a String. - * - * @return a string version of the iterator - */ - @Override - public String toString() { - if (last != null) { - return "MapIterator[" + getKey() + "=" + getValue() + "]"; - } - return "MapIterator[]"; - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/UnmodifiableMapIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/UnmodifiableMapIterator.java deleted file mode 100644 index f489d9c2eda1..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/iterators/UnmodifiableMapIterator.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.iterators; - -import com.azure.cosmos.implementation.apachecommons.collections.MapIterator; -import com.azure.cosmos.implementation.apachecommons.collections.list.Unmodifiable; - -public final class UnmodifiableMapIterator implements MapIterator, Unmodifiable { - /** The iterator being decorated */ - private final MapIterator iterator; - - /** - * Decorates the specified iterator such that it cannot be modified. - * - * @param the key type - * @param the value type - * @param iterator the iterator to decorate - * @return a new unmodifiable map iterator - * @throws NullPointerException if the iterator is null - */ - public static MapIterator unmodifiableMapIterator( - final MapIterator iterator) { - if (iterator == null) { - throw new NullPointerException("MapIterator must not be null"); - } - if (iterator instanceof Unmodifiable) { - @SuppressWarnings("unchecked") // safe to upcast - final MapIterator tmpIterator = (MapIterator) iterator; - return tmpIterator; - } - return new UnmodifiableMapIterator<>(iterator); - } - - /** - * Constructor. - * - * @param iterator the iterator to decorate - */ - private UnmodifiableMapIterator(final MapIterator iterator) { - super(); - this.iterator = iterator; - } - - @Override - public boolean hasNext() { - return iterator.hasNext(); - } - - @Override - public K next() { - return iterator.next(); - } - - @Override - public K getKey() { - return iterator.getKey(); - } - - @Override - public V getValue() { - return iterator.getValue(); - } - - @Override - public V setValue(final V value) { - throw new UnsupportedOperationException("setValue() is not supported"); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("remove() is not supported"); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/keyvalue/AbstractMapEntryDecorator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/keyvalue/AbstractMapEntryDecorator.java deleted file mode 100644 index 6db6abf3e0a1..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/keyvalue/AbstractMapEntryDecorator.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.keyvalue; - -import com.azure.cosmos.implementation.apachecommons.collections.KeyValue; - -import java.util.Map; - -public abstract class AbstractMapEntryDecorator implements Map.Entry, KeyValue { - /** The Map.Entry to decorate */ - private final Map.Entry entry; - - /** - * Constructor that wraps (not copies). - * - * @param entry the Map.Entry to decorate, must not be null - * @throws NullPointerException if the collection is null - */ - public AbstractMapEntryDecorator(final Map.Entry entry) { - if (entry == null) { - throw new NullPointerException("Map Entry must not be null."); - } - this.entry = entry; - } - - /** - * Gets the map being decorated. - * - * @return the decorated map - */ - protected Map.Entry getMapEntry() { - return entry; - } - - @Override - public K getKey() { - return entry.getKey(); - } - - @Override - public V getValue() { - return entry.getValue(); - } - - @Override - public V setValue(final V object) { - return entry.setValue(object); - } - - @Override - public boolean equals(final Object object) { - if (object == this) { - return true; - } - return entry.equals(object); - } - - @Override - public int hashCode() { - return entry.hashCode(); - } - - @Override - public String toString() { - return entry.toString(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/AbstractListDecorator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/AbstractListDecorator.java deleted file mode 100644 index e8fd73fdc5f9..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/AbstractListDecorator.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.list; - -import com.azure.cosmos.implementation.apachecommons.collections.AbstractCollectionDecorator; - -import java.util.Collection; -import java.util.List; -import java.util.ListIterator; - -public abstract class AbstractListDecorator extends AbstractCollectionDecorator - implements List { - /** Serialization version--necessary in an abstract class? */ - private static final long serialVersionUID = -2582852948666413654L; - - /** - * Constructor only used in deserialization, do not use otherwise. - */ - protected AbstractListDecorator() { - super(); - } - - /** - * Constructor that wraps (not copies). - * - * @param list the list to decorate, must not be null - * @throws NullPointerException if list is null - */ - protected AbstractListDecorator(final List list) { - super(list); - } - - /** - * Gets the list being decorated. - * - * @return the decorated list - */ - @Override - protected List decorated() { - return (List) super.decorated(); - } - - @Override - public boolean equals(final Object object) { - return object == this || decorated().equals(object); - } - - @Override - public int hashCode() { - return decorated().hashCode(); - } - - @Override - public void add(final int index, final E object) { - decorated().add(index, object); - } - - @Override - public boolean addAll(final int index, final Collection coll) { - return decorated().addAll(index, coll); - } - - @Override - public E get(final int index) { - return decorated().get(index); - } - - @Override - public int indexOf(final Object object) { - return decorated().indexOf(object); - } - - @Override - public int lastIndexOf(final Object object) { - return decorated().lastIndexOf(object); - } - - @Override - public ListIterator listIterator() { - return decorated().listIterator(); - } - - @Override - public ListIterator listIterator(final int index) { - return decorated().listIterator(index); - } - - @Override - public E remove(final int index) { - return decorated().remove(index); - } - - @Override - public E set(final int index, final E object) { - return decorated().set(index, object); - } - - @Override - public List subList(final int fromIndex, final int toIndex) { - return decorated().subList(fromIndex, toIndex); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/AbstractSerializableListDecorator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/AbstractSerializableListDecorator.java deleted file mode 100644 index e28cf010842b..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/AbstractSerializableListDecorator.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.list; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Collection; -import java.util.List; - -public abstract class AbstractSerializableListDecorator - extends AbstractListDecorator { - /** Serialization version */ - private static final long serialVersionUID = -1278833155561656880L; - - /** - * Constructor that wraps (not copies). - * - * @param list the list to decorate, must not be null - * @throws NullPointerException if list is null - */ - protected AbstractSerializableListDecorator(final List list) { - super(list); - } - - /** - * Write the list out using a custom routine. - * - * @param out the output stream - * @throws IOException if an error occurs while writing to the stream - */ - private void writeObject(final ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - out.writeObject(decorated()); - } - - /** - * Read the list in using a custom routine. - * - * @param in the input stream - * @throws IOException if an error occurs while reading from the stream - * @throws ClassNotFoundException if an object read from the stream can not be loaded - */ - @SuppressWarnings("unchecked") - private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); - setCollection((Collection) in.readObject()); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/Unmodifiable.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/Unmodifiable.java deleted file mode 100644 index 1f3ef70f32ee..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/Unmodifiable.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.azure.cosmos.implementation.apachecommons.collections.list; - -public interface Unmodifiable { - // marker interface - no methods to implement -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/UnmodifiableList.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/UnmodifiableList.java deleted file mode 100644 index 8486ccec2ff3..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/UnmodifiableList.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.list; - -import com.azure.cosmos.implementation.apachecommons.collections.list.iterators.UnmodifiableIterator; -import com.azure.cosmos.implementation.apachecommons.collections.list.iterators.UnmodifiableListIterator; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -public final class UnmodifiableList - extends AbstractSerializableListDecorator - implements Unmodifiable { - /** Serialization version */ - private static final long serialVersionUID = -5965906429914500171L; - - /** - * Factory method to create an unmodifiable list. - * - * @param the type of the elements in the list - * @param list the list to decorate, must not be null - * @return a new unmodifiable list - * @throws NullPointerException if list is null - */ - public static List unmodifiableList(final List list) { - if (list instanceof Unmodifiable) { - @SuppressWarnings("unchecked") // safe to upcast - final List tmpList = (List) list; - return tmpList; - } - return new UnmodifiableList<>(list); - } - - /** - * Constructor that wraps (not copies). - * - * @param list the list to decorate, must not be null - * @throws NullPointerException if list is null - */ - @SuppressWarnings("unchecked") // safe to upcast - public UnmodifiableList(final List list) { - super((List) list); - } - - @Override - public Iterator iterator() { - return UnmodifiableIterator.unmodifiableIterator(decorated().iterator()); - } - - @Override - public boolean add(final Object object) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean addAll(final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean remove(final Object object) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean removeAll(final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean retainAll(final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public ListIterator listIterator() { - return UnmodifiableListIterator.umodifiableListIterator(decorated().listIterator()); - } - - @Override - public ListIterator listIterator(final int index) { - return UnmodifiableListIterator.umodifiableListIterator(decorated().listIterator(index)); - } - - @Override - public void add(final int index, final E object) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean addAll(final int index, final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public E remove(final int index) { - throw new UnsupportedOperationException(); - } - - @Override - public E set(final int index, final E object) { - throw new UnsupportedOperationException(); - } - - @Override - public List subList(final int fromIndex, final int toIndex) { - final List sub = decorated().subList(fromIndex, toIndex); - return new UnmodifiableList<>(sub); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/iterators/UnmodifiableIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/iterators/UnmodifiableIterator.java deleted file mode 100644 index 8da31d326b74..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/iterators/UnmodifiableIterator.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.list.iterators; - -import com.azure.cosmos.implementation.apachecommons.collections.list.Unmodifiable; - -import java.util.Iterator; - -public final class UnmodifiableIterator implements Iterator, Unmodifiable { - /** The iterator being decorated */ - private final Iterator iterator; - - /** - * Decorates the specified iterator such that it cannot be modified. - *

- * If the iterator is already unmodifiable it is returned directly. - * - * @param the element type - * @param iterator the iterator to decorate - * @return a new unmodifiable iterator - * @throws NullPointerException if the iterator is null - */ - public static Iterator unmodifiableIterator(final Iterator iterator) { - if (iterator == null) { - throw new NullPointerException("Iterator must not be null"); - } - if (iterator instanceof Unmodifiable) { - @SuppressWarnings("unchecked") // safe to upcast - final Iterator tmpIterator = (Iterator) iterator; - return tmpIterator; - } - return new UnmodifiableIterator<>(iterator); - } - - /** - * Constructor. - * - * @param iterator the iterator to decorate - */ - private UnmodifiableIterator(final Iterator iterator) { - super(); - this.iterator = iterator; - } - - @Override - public boolean hasNext() { - return iterator.hasNext(); - } - - @Override - public E next() { - return iterator.next(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("remove() is not supported"); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/iterators/UnmodifiableListIterator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/iterators/UnmodifiableListIterator.java deleted file mode 100644 index 72862659cb27..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/list/iterators/UnmodifiableListIterator.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.list.iterators; - -import com.azure.cosmos.implementation.apachecommons.collections.list.Unmodifiable; - -import java.util.ListIterator; - -public final class UnmodifiableListIterator implements ListIterator, Unmodifiable { - /** The iterator being decorated */ - private final ListIterator iterator; - - /** - * Decorates the specified iterator such that it cannot be modified. - * - * @param the element type - * @param iterator the iterator to decorate - * @return a new unmodifiable list iterator - * @throws NullPointerException if the iterator is null - */ - public static ListIterator umodifiableListIterator(final ListIterator iterator) { - if (iterator == null) { - throw new NullPointerException("ListIterator must not be null"); - } - if (iterator instanceof Unmodifiable) { - @SuppressWarnings("unchecked") // safe to upcast - final ListIterator tmpIterator = (ListIterator) iterator; - return tmpIterator; - } - return new UnmodifiableListIterator<>(iterator); - } - - /** - * Constructor. - * - * @param iterator the iterator to decorate - */ - private UnmodifiableListIterator(final ListIterator iterator) { - super(); - this.iterator = iterator; - } - - @Override - public boolean hasNext() { - return iterator.hasNext(); - } - - @Override - public E next() { - return iterator.next(); - } - - @Override - public int nextIndex() { - return iterator.nextIndex(); - } - - @Override - public boolean hasPrevious() { - return iterator.hasPrevious(); - } - - @Override - public E previous() { - return iterator.previous(); - } - - @Override - public int previousIndex() { - return iterator.previousIndex(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("remove() is not supported"); - } - - @Override - public void set(final E obj) { - throw new UnsupportedOperationException("set() is not supported"); - } - - @Override - public void add(final E obj) { - throw new UnsupportedOperationException("add() is not supported"); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractHashedMap.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractHashedMap.java deleted file mode 100644 index 788e792553d4..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractHashedMap.java +++ /dev/null @@ -1,1370 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.map; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.AbstractCollection; -import java.util.AbstractMap; -import java.util.AbstractSet; -import java.util.Collection; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; - -import com.azure.cosmos.implementation.apachecommons.collections.IterableMap; -import com.azure.cosmos.implementation.apachecommons.collections.KeyValue; -import com.azure.cosmos.implementation.apachecommons.collections.MapIterator; -import com.azure.cosmos.implementation.apachecommons.collections.iterators.EmptyIterator; -import com.azure.cosmos.implementation.apachecommons.collections.iterators.EmptyMapIterator; - -public class AbstractHashedMap extends AbstractMap implements IterableMap { - protected static final String NO_NEXT_ENTRY = "No next() entry in the iteration"; - protected static final String NO_PREVIOUS_ENTRY = "No previous() entry in the iteration"; - protected static final String REMOVE_INVALID = "remove() can only be called once after next()"; - protected static final String GETKEY_INVALID = "getKey() can only be called after next() and before remove()"; - protected static final String GETVALUE_INVALID = "getValue() can only be called after next() and before remove()"; - protected static final String SETVALUE_INVALID = "setValue() can only be called after next() and before remove()"; - - /** The default capacity to use */ - protected static final int DEFAULT_CAPACITY = 16; - /** The default threshold to use */ - protected static final int DEFAULT_THRESHOLD = 12; - /** The default load factor to use */ - protected static final float DEFAULT_LOAD_FACTOR = 0.75f; - /** The maximum capacity allowed */ - protected static final int MAXIMUM_CAPACITY = 1 << 30; - /** An object for masking null */ - protected static final Object NULL = new Object(); - - /** Load factor, normally 0.75 */ - transient float loadFactor; - /** The size of the map */ - transient int size; - /** Map entries */ - transient HashEntry[] data; - /** Size at which to rehash */ - transient int threshold; - /** Modification count for iterators */ - transient int modCount; - /** Entry set */ - transient EntrySet entrySet; - /** Key set */ - transient KeySet keySet; - /** Values */ - transient Values values; - - /** - * Constructor only used in deserialization, do not use otherwise. - */ - protected AbstractHashedMap() { - super(); - } - - /** - * Constructor which performs no validation on the passed in parameters. - * - * @param initialCapacity the initial capacity, must be a power of two - * @param loadFactor the load factor, must be > 0.0f and generally < 1.0f - * @param threshold the threshold, must be sensible - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - protected AbstractHashedMap(final int initialCapacity, final float loadFactor, final int threshold) { - super(); - this.loadFactor = loadFactor; - this.data = new HashEntry[initialCapacity]; - this.threshold = threshold; - init(); - } - - /** - * Constructs a new, empty map with the specified initial capacity and - * default load factor. - * - * @param initialCapacity the initial capacity - * @throws IllegalArgumentException if the initial capacity is negative - */ - protected AbstractHashedMap(final int initialCapacity) { - this(initialCapacity, DEFAULT_LOAD_FACTOR); - } - - /** - * Constructs a new, empty map with the specified initial capacity and - * load factor. - * - * @param initialCapacity the initial capacity - * @param loadFactor the load factor - * @throws IllegalArgumentException if the initial capacity is negative - * @throws IllegalArgumentException if the load factor is less than or equal to zero - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - protected AbstractHashedMap(int initialCapacity, final float loadFactor) { - super(); - if (initialCapacity < 0) { - throw new IllegalArgumentException("Initial capacity must be a non negative number"); - } - if (loadFactor <= 0.0f || Float.isNaN(loadFactor)) { - throw new IllegalArgumentException("Load factor must be greater than 0"); - } - this.loadFactor = loadFactor; - initialCapacity = calculateNewCapacity(initialCapacity); - this.threshold = calculateThreshold(initialCapacity, loadFactor); - this.data = new HashEntry[initialCapacity]; - init(); - } - - /** - * Constructor copying elements from another map. - * - * @param map the map to copy - * @throws NullPointerException if the map is null - */ - protected AbstractHashedMap(final Map map) { - this(Math.max(2 * map.size(), DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR); - _putAll(map); - } - - /** - * Initialise subclasses during construction, cloning or deserialization. - */ - protected void init() { - } - - /** - * Gets the value mapped to the key specified. - * - * @param key the key - * @return the mapped value, null if no match - */ - @Override - public V get(Object key) { - key = convertKey(key); - final int hashCode = hash(key); - HashEntry entry = data[hashIndex(hashCode, data.length)]; // no local for hash index - while (entry != null) { - if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) { - return entry.getValue(); - } - entry = entry.next; - } - return null; - } - - /** - * Gets the size of the map. - * - * @return the size - */ - @Override - public int size() { - return size; - } - - /** - * Checks whether the map is currently empty. - * - * @return true if the map is currently size zero - */ - @Override - public boolean isEmpty() { - return size == 0; - } - - //----------------------------------------------------------------------- - /** - * Checks whether the map contains the specified key. - * - * @param key the key to search for - * @return true if the map contains the key - */ - @Override - public boolean containsKey(Object key) { - key = convertKey(key); - final int hashCode = hash(key); - HashEntry entry = data[hashIndex(hashCode, data.length)]; // no local for hash index - while (entry != null) { - if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) { - return true; - } - entry = entry.next; - } - return false; - } - - /** - * Checks whether the map contains the specified value. - * - * @param value the value to search for - * @return true if the map contains the value - */ - @Override - public boolean containsValue(final Object value) { - if (value == null) { - for (final HashEntry element : data) { - HashEntry entry = element; - while (entry != null) { - if (entry.getValue() == null) { - return true; - } - entry = entry.next; - } - } - } else { - for (final HashEntry element : data) { - HashEntry entry = element; - while (entry != null) { - if (isEqualValue(value, entry.getValue())) { - return true; - } - entry = entry.next; - } - } - } - return false; - } - - //----------------------------------------------------------------------- - /** - * Puts a key-value mapping into this map. - * - * @param key the key to add - * @param value the value to add - * @return the value previously mapped to this key, null if none - */ - @Override - public V put(final K key, final V value) { - final Object convertedKey = convertKey(key); - final int hashCode = hash(convertedKey); - final int index = hashIndex(hashCode, data.length); - HashEntry entry = data[index]; - while (entry != null) { - if (entry.hashCode == hashCode && isEqualKey(convertedKey, entry.key)) { - final V oldValue = entry.getValue(); - updateEntry(entry, value); - return oldValue; - } - entry = entry.next; - } - - addMapping(index, hashCode, key, value); - return null; - } - - /** - * Puts all the values from the specified map into this map. - *

- * This implementation iterates around the specified map and - * uses {@link #put(Object, Object)}. - * - * @param map the map to add - * @throws NullPointerException if the map is null - */ - @Override - public void putAll(final Map map) { - _putAll(map); - } - - /** - * Puts all the values from the specified map into this map. - *

- * This implementation iterates around the specified map and - * uses {@link #put(Object, Object)}. - *

- * It is private to allow the constructor to still call it - * even when putAll is overriden. - * - * @param map the map to add - * @throws NullPointerException if the map is null - */ - private void _putAll(final Map map) { - final int mapSize = map.size(); - if (mapSize == 0) { - return; - } - final int newSize = (int) ((size + mapSize) / loadFactor + 1); - ensureCapacity(calculateNewCapacity(newSize)); - for (final Map.Entry entry: map.entrySet()) { - put(entry.getKey(), entry.getValue()); - } - } - - /** - * Removes the specified mapping from this map. - * - * @param key the mapping to remove - * @return the value mapped to the removed key, null if key not in map - */ - @Override - public V remove(Object key) { - key = convertKey(key); - final int hashCode = hash(key); - final int index = hashIndex(hashCode, data.length); - HashEntry entry = data[index]; - HashEntry previous = null; - while (entry != null) { - if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) { - final V oldValue = entry.getValue(); - removeMapping(entry, index, previous); - return oldValue; - } - previous = entry; - entry = entry.next; - } - return null; - } - - /** - * Clears the map, resetting the size to zero and nullifying references - * to avoid garbage collection issues. - */ - @Override - public void clear() { - modCount++; - final HashEntry[] data = this.data; - for (int i = data.length - 1; i >= 0; i--) { - data[i] = null; - } - size = 0; - } - - /** - * Converts input keys to another object for storage in the map. - * This implementation masks nulls. - * Subclasses can override this to perform alternate key conversions. - *

- * The reverse conversion can be changed, if required, by overriding the - * getKey() method in the hash entry. - * - * @param key the key convert - * @return the converted key - */ - protected Object convertKey(final Object key) { - return key == null ? NULL : key; - } - - /** - * Gets the hash code for the key specified. - * This implementation uses the additional hashing routine from JDK1.4. - * Subclasses can override this to return alternate hash codes. - * - * @param key the key to get a hash code for - * @return the hash code - */ - protected int hash(final Object key) { - // same as JDK 1.4 - int h = key.hashCode(); - h += ~(h << 9); - h ^= h >>> 14; - h += h << 4; - h ^= h >>> 10; - return h; - } - - /** - * Compares two keys, in internal converted form, to see if they are equal. - * This implementation uses the equals method and assumes neither key is null. - * Subclasses can override this to match differently. - * - * @param key1 the first key to compare passed in from outside - * @param key2 the second key extracted from the entry via entry.key - * @return true if equal - */ - protected boolean isEqualKey(final Object key1, final Object key2) { - return key1 == key2 || key1.equals(key2); - } - - /** - * Compares two values, in external form, to see if they are equal. - * This implementation uses the equals method and assumes neither value is null. - * Subclasses can override this to match differently. - * - * @param value1 the first value to compare passed in from outside - * @param value2 the second value extracted from the entry via getValue() - * @return true if equal - */ - protected boolean isEqualValue(final Object value1, final Object value2) { - return value1 == value2 || value1.equals(value2); - } - - /** - * Gets the index into the data storage for the hashCode specified. - * This implementation uses the least significant bits of the hashCode. - * Subclasses can override this to return alternate bucketing. - * - * @param hashCode the hash code to use - * @param dataSize the size of the data to pick a bucket from - * @return the bucket index - */ - protected int hashIndex(final int hashCode, final int dataSize) { - return hashCode & dataSize - 1; - } - - //----------------------------------------------------------------------- - /** - * Gets the entry mapped to the key specified. - *

- * This method exists for subclasses that may need to perform a multi-step - * process accessing the entry. The public methods in this class don't use this - * method to gain a small performance boost. - * - * @param key the key - * @return the entry, null if no match - */ - protected HashEntry getEntry(Object key) { - key = convertKey(key); - final int hashCode = hash(key); - HashEntry entry = data[hashIndex(hashCode, data.length)]; // no local for hash index - while (entry != null) { - if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) { - return entry; - } - entry = entry.next; - } - return null; - } - - //----------------------------------------------------------------------- - /** - * Updates an existing key-value mapping to change the value. - *

- * This implementation calls setValue() on the entry. - * Subclasses could override to handle changes to the map. - * - * @param entry the entry to update - * @param newValue the new value to store - */ - protected void updateEntry(final HashEntry entry, final V newValue) { - entry.setValue(newValue); - } - - /** - * Reuses an existing key-value mapping, storing completely new data. - *

- * This implementation sets all the data fields on the entry. - * Subclasses could populate additional entry fields. - * - * @param entry the entry to update, not null - * @param hashIndex the index in the data array - * @param hashCode the hash code of the key to add - * @param key the key to add - * @param value the value to add - */ - protected void reuseEntry(final HashEntry entry, final int hashIndex, final int hashCode, - final K key, final V value) { - entry.next = data[hashIndex]; - entry.hashCode = hashCode; - entry.key = key; - entry.value = value; - } - - //----------------------------------------------------------------------- - /** - * Adds a new key-value mapping into this map. - *

- * This implementation calls createEntry(), addEntry() - * and checkCapacity(). - * It also handles changes to modCount and size. - * Subclasses could override to fully control adds to the map. - * - * @param hashIndex the index into the data array to store at - * @param hashCode the hash code of the key to add - * @param key the key to add - * @param value the value to add - */ - protected void addMapping(final int hashIndex, final int hashCode, final K key, final V value) { - modCount++; - final HashEntry entry = createEntry(data[hashIndex], hashCode, key, value); - addEntry(entry, hashIndex); - size++; - checkCapacity(); - } - - /** - * Creates an entry to store the key-value data. - *

- * This implementation creates a new HashEntry instance. - * Subclasses can override this to return a different storage class, - * or implement caching. - * - * @param next the next entry in sequence - * @param hashCode the hash code to use - * @param key the key to store - * @param value the value to store - * @return the newly created entry - */ - protected HashEntry createEntry(final HashEntry next, final int hashCode, final K key, final V value) { - return new HashEntry<>(next, hashCode, convertKey(key), value); - } - - /** - * Adds an entry into this map. - *

- * This implementation adds the entry to the data storage table. - * Subclasses could override to handle changes to the map. - * - * @param entry the entry to add - * @param hashIndex the index into the data array to store at - */ - protected void addEntry(final HashEntry entry, final int hashIndex) { - data[hashIndex] = entry; - } - - /** - * Removes a mapping from the map. - *

- * This implementation calls removeEntry() and destroyEntry(). - * It also handles changes to modCount and size. - * Subclasses could override to fully control removals from the map. - * - * @param entry the entry to remove - * @param hashIndex the index into the data structure - * @param previous the previous entry in the chain - */ - protected void removeMapping(final HashEntry entry, final int hashIndex, final HashEntry previous) { - modCount++; - removeEntry(entry, hashIndex, previous); - size--; - destroyEntry(entry); - } - - /** - * Removes an entry from the chain stored in a particular index. - *

- * This implementation removes the entry from the data storage table. - * The size is not updated. - * Subclasses could override to handle changes to the map. - * - * @param entry the entry to remove - * @param hashIndex the index into the data structure - * @param previous the previous entry in the chain - */ - protected void removeEntry(final HashEntry entry, final int hashIndex, final HashEntry previous) { - if (previous == null) { - data[hashIndex] = entry.next; - } else { - previous.next = entry.next; - } - } - - /** - * Kills an entry ready for the garbage collector. - *

- * This implementation prepares the HashEntry for garbage collection. - * Subclasses can override this to implement caching (override clear as well). - * - * @param entry the entry to destroy - */ - protected void destroyEntry(final HashEntry entry) { - entry.next = null; - entry.key = null; - entry.value = null; - } - - //----------------------------------------------------------------------- - /** - * Checks the capacity of the map and enlarges it if necessary. - *

- * This implementation uses the threshold to check if the map needs enlarging - */ - protected void checkCapacity() { - if (size >= threshold) { - final int newCapacity = data.length * 2; - if (newCapacity <= MAXIMUM_CAPACITY) { - ensureCapacity(newCapacity); - } - } - } - - /** - * Changes the size of the data structure to the capacity proposed. - * - * @param newCapacity the new capacity of the array (a power of two, less or equal to max) - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - protected void ensureCapacity(final int newCapacity) { - final int oldCapacity = data.length; - if (newCapacity <= oldCapacity) { - return; - } - if (size == 0) { - threshold = calculateThreshold(newCapacity, loadFactor); - data = new HashEntry[newCapacity]; - } else { - final HashEntry oldEntries[] = data; - final HashEntry newEntries[] = new HashEntry[newCapacity]; - - modCount++; - for (int i = oldCapacity - 1; i >= 0; i--) { - HashEntry entry = oldEntries[i]; - if (entry != null) { - oldEntries[i] = null; // gc - do { - final HashEntry next = entry.next; - final int index = hashIndex(entry.hashCode, newCapacity); - entry.next = newEntries[index]; - newEntries[index] = entry; - entry = next; - } while (entry != null); - } - } - threshold = calculateThreshold(newCapacity, loadFactor); - data = newEntries; - } - } - - /** - * Calculates the new capacity of the map. - * This implementation normalizes the capacity to a power of two. - * - * @param proposedCapacity the proposed capacity - * @return the normalized new capacity - */ - protected int calculateNewCapacity(final int proposedCapacity) { - int newCapacity = 1; - if (proposedCapacity > MAXIMUM_CAPACITY) { - newCapacity = MAXIMUM_CAPACITY; - } else { - while (newCapacity < proposedCapacity) { - newCapacity <<= 1; // multiply by two - } - if (newCapacity > MAXIMUM_CAPACITY) { - newCapacity = MAXIMUM_CAPACITY; - } - } - return newCapacity; - } - - /** - * Calculates the new threshold of the map, where it will be resized. - * This implementation uses the load factor. - * - * @param newCapacity the new capacity - * @param factor the load factor - * @return the new resize threshold - */ - protected int calculateThreshold(final int newCapacity, final float factor) { - return (int) (newCapacity * factor); - } - - /** - * Gets the next field from a HashEntry. - * Used in subclasses that have no visibility of the field. - * - * @param entry the entry to query, must not be null - * @return the next field of the entry - * @throws NullPointerException if the entry is null - */ - protected HashEntry entryNext(final HashEntry entry) { - return entry.next; - } - - /** - * Gets the hashCode field from a HashEntry. - * Used in subclasses that have no visibility of the field. - * - * @param entry the entry to query, must not be null - * @return the hashCode field of the entry - * @throws NullPointerException if the entry is null - */ - protected int entryHashCode(final HashEntry entry) { - return entry.hashCode; - } - - /** - * Gets the key field from a HashEntry. - * Used in subclasses that have no visibility of the field. - * - * @param entry the entry to query, must not be null - * @return the key field of the entry - * @throws NullPointerException if the entry is null - */ - protected K entryKey(final HashEntry entry) { - return entry.getKey(); - } - - /** - * Gets the value field from a HashEntry. - * Used in subclasses that have no visibility of the field. - * - * @param entry the entry to query, must not be null - * @return the value field of the entry - * @throws NullPointerException if the entry is null - */ - protected V entryValue(final HashEntry entry) { - return entry.getValue(); - } - - /** - * Gets an iterator over the map. - * Changes made to the iterator affect this map. - *

- * A MapIterator returns the keys in the map. It also provides convenient - * methods to get the key and value, and set the value. - * It avoids the need to create an entrySet/keySet/values object. - * It also avoids creating the Map.Entry object. - * - * @return the map iterator - */ - @Override - public MapIterator mapIterator() { - if (size == 0) { - return EmptyMapIterator.emptyMapIterator(); - } - return new HashMapIterator<>(this); - } - - /** - * MapIterator implementation. - */ - protected static class HashMapIterator extends HashIterator implements MapIterator { - - protected HashMapIterator(final AbstractHashedMap parent) { - super(parent); - } - - @Override - public K next() { - return super.nextEntry().getKey(); - } - - @Override - public K getKey() { - final HashEntry current = currentEntry(); - if (current == null) { - throw new IllegalStateException(AbstractHashedMap.GETKEY_INVALID); - } - return current.getKey(); - } - - @Override - public V getValue() { - final HashEntry current = currentEntry(); - if (current == null) { - throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID); - } - return current.getValue(); - } - - @Override - public V setValue(final V value) { - final HashEntry current = currentEntry(); - if (current == null) { - throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID); - } - return current.setValue(value); - } - } - - /** - * Gets the entrySet view of the map. - * Changes made to the view affect this map. - * To simply iterate through the entries, use {@link #mapIterator()}. - * - * @return the entrySet view - */ - @Override - public Set> entrySet() { - if (entrySet == null) { - entrySet = new EntrySet<>(this); - } - return entrySet; - } - - /** - * Creates an entry set iterator. - * Subclasses can override this to return iterators with different properties. - * - * @return the entrySet iterator - */ - protected Iterator> createEntrySetIterator() { - if (size() == 0) { - return EmptyIterator.>emptyIterator(); - } - return new EntrySetIterator<>(this); - } - - /** - * EntrySet implementation. - */ - protected static class EntrySet extends AbstractSet> { - /** The parent map */ - private final AbstractHashedMap parent; - - protected EntrySet(final AbstractHashedMap parent) { - super(); - this.parent = parent; - } - - @Override - public int size() { - return parent.size(); - } - - @Override - public void clear() { - parent.clear(); - } - - @Override - public boolean contains(final Object entry) { - if (entry instanceof Map.Entry) { - final Map.Entry e = (Map.Entry) entry; - final Entry match = parent.getEntry(e.getKey()); - return match != null && match.equals(e); - } - return false; - } - - @Override - public boolean remove(final Object obj) { - if (obj instanceof Map.Entry == false) { - return false; - } - if (contains(obj) == false) { - return false; - } - final Map.Entry entry = (Map.Entry) obj; - parent.remove(entry.getKey()); - return true; - } - - @Override - public Iterator> iterator() { - return parent.createEntrySetIterator(); - } - } - - /** - * EntrySet iterator. - */ - protected static class EntrySetIterator extends HashIterator implements Iterator> { - - protected EntrySetIterator(final AbstractHashedMap parent) { - super(parent); - } - - @Override - public Map.Entry next() { - return super.nextEntry(); - } - } - - /** - * Gets the keySet view of the map. - * Changes made to the view affect this map. - * To simply iterate through the keys, use {@link #mapIterator()}. - * - * @return the keySet view - */ - @Override - public Set keySet() { - if (keySet == null) { - keySet = new KeySet<>(this); - } - return keySet; - } - - /** - * Creates a key set iterator. - * Subclasses can override this to return iterators with different properties. - * - * @return the keySet iterator - */ - protected Iterator createKeySetIterator() { - if (size() == 0) { - return EmptyIterator.emptyIterator(); - } - return new KeySetIterator<>(this); - } - - /** - * KeySet implementation. - */ - protected static class KeySet extends AbstractSet { - /** The parent map */ - private final AbstractHashedMap parent; - - protected KeySet(final AbstractHashedMap parent) { - super(); - this.parent = parent; - } - - @Override - public int size() { - return parent.size(); - } - - @Override - public void clear() { - parent.clear(); - } - - @Override - public boolean contains(final Object key) { - return parent.containsKey(key); - } - - @Override - public boolean remove(final Object key) { - final boolean result = parent.containsKey(key); - parent.remove(key); - return result; - } - - @Override - public Iterator iterator() { - return parent.createKeySetIterator(); - } - } - - /** - * KeySet iterator. - */ - protected static class KeySetIterator extends HashIterator implements Iterator { - - @SuppressWarnings("unchecked") - protected KeySetIterator(final AbstractHashedMap parent) { - super((AbstractHashedMap) parent); - } - - @Override - public K next() { - return super.nextEntry().getKey(); - } - } - - /** - * Gets the values view of the map. - * Changes made to the view affect this map. - * To simply iterate through the values, use {@link #mapIterator()}. - * - * @return the values view - */ - @Override - public Collection values() { - if (values == null) { - values = new Values<>(this); - } - return values; - } - - /** - * Creates a values iterator. - * Subclasses can override this to return iterators with different properties. - * - * @return the values iterator - */ - protected Iterator createValuesIterator() { - if (size() == 0) { - return EmptyIterator.emptyIterator(); - } - return new ValuesIterator<>(this); - } - - /** - * Values implementation. - */ - protected static class Values extends AbstractCollection { - /** The parent map */ - private final AbstractHashedMap parent; - - protected Values(final AbstractHashedMap parent) { - super(); - this.parent = parent; - } - - @Override - public int size() { - return parent.size(); - } - - @Override - public void clear() { - parent.clear(); - } - - @Override - public boolean contains(final Object value) { - return parent.containsValue(value); - } - - @Override - public Iterator iterator() { - return parent.createValuesIterator(); - } - } - - /** - * Values iterator. - */ - protected static class ValuesIterator extends HashIterator implements Iterator { - - @SuppressWarnings("unchecked") - protected ValuesIterator(final AbstractHashedMap parent) { - super((AbstractHashedMap) parent); - } - - @Override - public V next() { - return super.nextEntry().getValue(); - } - } - - /** - * HashEntry used to store the data. - *

- * If you subclass AbstractHashedMap but not HashEntry - * then you will not be able to access the protected fields. - * The entryXxx() methods on AbstractHashedMap exist - * to provide the necessary access. - */ - protected static class HashEntry implements Map.Entry, KeyValue { - /** The next entry in the hash chain */ - protected HashEntry next; - /** The hash code of the key */ - protected int hashCode; - /** The key */ - protected Object key; - /** The value */ - protected Object value; - - protected HashEntry(final HashEntry next, final int hashCode, final Object key, final V value) { - super(); - this.next = next; - this.hashCode = hashCode; - this.key = key; - this.value = value; - } - - @Override - @SuppressWarnings("unchecked") - public K getKey() { - if (key == NULL) { - return null; - } - return (K) key; - } - - @Override - @SuppressWarnings("unchecked") - public V getValue() { - return (V) value; - } - - @Override - @SuppressWarnings("unchecked") - public V setValue(final V value) { - final Object old = this.value; - this.value = value; - return (V) old; - } - - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof Map.Entry == false) { - return false; - } - final Map.Entry other = (Map.Entry) obj; - return - (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && - (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); - } - - @Override - public int hashCode() { - return (getKey() == null ? 0 : getKey().hashCode()) ^ - (getValue() == null ? 0 : getValue().hashCode()); - } - - @Override - public String toString() { - return new StringBuilder().append(getKey()).append('=').append(getValue()).toString(); - } - } - - /** - * Base Iterator - */ - protected static abstract class HashIterator { - - /** The parent map */ - private final AbstractHashedMap parent; - /** The current index into the array of buckets */ - private int hashIndex; - /** The last returned entry */ - private HashEntry last; - /** The next entry */ - private HashEntry next; - /** The modification count expected */ - private int expectedModCount; - - protected HashIterator(final AbstractHashedMap parent) { - super(); - this.parent = parent; - final HashEntry[] data = parent.data; - int i = data.length; - HashEntry next = null; - while (i > 0 && next == null) { - next = data[--i]; - } - this.next = next; - this.hashIndex = i; - this.expectedModCount = parent.modCount; - } - - public boolean hasNext() { - return next != null; - } - - protected HashEntry nextEntry() { - if (parent.modCount != expectedModCount) { - throw new ConcurrentModificationException(); - } - final HashEntry newCurrent = next; - if (newCurrent == null) { - throw new NoSuchElementException(AbstractHashedMap.NO_NEXT_ENTRY); - } - final HashEntry[] data = parent.data; - int i = hashIndex; - HashEntry n = newCurrent.next; - while (n == null && i > 0) { - n = data[--i]; - } - next = n; - hashIndex = i; - last = newCurrent; - return newCurrent; - } - - protected HashEntry currentEntry() { - return last; - } - - public void remove() { - if (last == null) { - throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID); - } - if (parent.modCount != expectedModCount) { - throw new ConcurrentModificationException(); - } - parent.remove(last.getKey()); - last = null; - expectedModCount = parent.modCount; - } - - @Override - public String toString() { - if (last != null) { - return "Iterator[" + last.getKey() + "=" + last.getValue() + "]"; - } - return "Iterator[]"; - } - } - - //----------------------------------------------------------------------- - /** - * Writes the map data to the stream. This method must be overridden if a - * subclass must be setup before put() is used. - *

- * Serialization is not one of the JDK's nicest topics. Normal serialization will - * initialise the superclass before the subclass. Sometimes however, this isn't - * what you want, as in this case the put() method on read can be - * affected by subclass state. - *

- * The solution adopted here is to serialize the state data of this class in - * this protected method. This method must be called by the - * writeObject() of the first serializable subclass. - *

- * Subclasses may override if they have a specific field that must be present - * on read before this implementation will work. Generally, the read determines - * what must be serialized here, if anything. - * - * @param out the output stream - * @throws IOException if an error occurs while writing tothe stream - */ - protected void doWriteObject(final ObjectOutputStream out) throws IOException { - out.writeFloat(loadFactor); - out.writeInt(data.length); - out.writeInt(size); - for (final MapIterator it = mapIterator(); it.hasNext();) { - out.writeObject(it.next()); - out.writeObject(it.getValue()); - } - } - - /** - * Reads the map data from the stream. This method must be overridden if a - * subclass must be setup before put() is used. - *

- * Serialization is not one of the JDK's nicest topics. Normal serialization will - * initialise the superclass before the subclass. Sometimes however, this isn't - * what you want, as in this case the put() method on read can be - * affected by subclass state. - *

- * The solution adopted here is to deserialize the state data of this class in - * this protected method. This method must be called by the - * readObject() of the first serializable subclass. - *

- * Subclasses may override if the subclass has a specific field that must be present - * before put() or calculateThreshold() will work correctly. - * - * @param in the input stream - * @throws IOException if an error occurs while reading from the stream - * @throws ClassNotFoundException if an object read from the stream can not be loaded - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - protected void doReadObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { - loadFactor = in.readFloat(); - final int capacity = in.readInt(); - final int size = in.readInt(); - init(); - threshold = calculateThreshold(capacity, loadFactor); - data = new HashEntry[capacity]; - for (int i = 0; i < size; i++) { - final K key = (K) in.readObject(); - final V value = (V) in.readObject(); - put(key, value); - } - } - - /** - * Clones the map without cloning the keys or values. - *

- * To implement clone(), a subclass must implement the - * Cloneable interface and make this method public. - * - * @return a shallow clone - * @throws InternalError if {@link AbstractMap#clone()} failed - */ - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - protected AbstractHashedMap clone() { - try { - final AbstractHashedMap cloned = (AbstractHashedMap) super.clone(); - cloned.data = new HashEntry[data.length]; - cloned.entrySet = null; - cloned.keySet = null; - cloned.values = null; - cloned.modCount = 0; - cloned.size = 0; - cloned.init(); - cloned.putAll(this); - return cloned; - } catch (final CloneNotSupportedException ex) { - throw new InternalError(); - } - } - - /** - * Compares this map with another. - * - * @param obj the object to compare to - * @return true if equal - */ - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof Map == false) { - return false; - } - final Map map = (Map) obj; - if (map.size() != size()) { - return false; - } - final MapIterator it = mapIterator(); - try { - while (it.hasNext()) { - final Object key = it.next(); - final Object value = it.getValue(); - if (value == null) { - if (map.get(key) != null || map.containsKey(key) == false) { - return false; - } - } else { - if (value.equals(map.get(key)) == false) { - return false; - } - } - } - } catch (final ClassCastException ignored) { - return false; - } catch (final NullPointerException ignored) { - return false; - } - return true; - } - - /** - * Gets the standard Map hashCode. - * - * @return the hash code defined in the Map interface - */ - @Override - public int hashCode() { - int total = 0; - final Iterator> it = createEntrySetIterator(); - while (it.hasNext()) { - total += it.next().hashCode(); - } - return total; - } - - /** - * Gets the map as a String. - * - * @return a string version of the map - */ - @Override - public String toString() { - if (size() == 0) { - return "{}"; - } - final StringBuilder buf = new StringBuilder(32 * size()); - buf.append('{'); - - final MapIterator it = mapIterator(); - boolean hasNext = it.hasNext(); - while (hasNext) { - final K key = it.next(); - final V value = it.getValue(); - buf.append(key == this ? "(this Map)" : key) - .append('=') - .append(value == this ? "(this Map)" : value); - - hasNext = it.hasNext(); - if (hasNext) { - buf.append(',').append(' '); - } - } - - buf.append('}'); - return buf.toString(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractIterableMap.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractIterableMap.java deleted file mode 100644 index f249fecdfbfa..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractIterableMap.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.map; - -import com.azure.cosmos.implementation.apachecommons.collections.IterableMap; -import com.azure.cosmos.implementation.apachecommons.collections.MapIterator; - -public abstract class AbstractIterableMap implements IterableMap { - /** - * {@inheritDoc} - */ - @Override - public MapIterator mapIterator() { - return new EntrySetToMapIteratorAdapter<>(entrySet()); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractMapDecorator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractMapDecorator.java deleted file mode 100644 index 3d06cdec256c..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/AbstractMapDecorator.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.map; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -public abstract class AbstractMapDecorator extends AbstractIterableMap { - /** The map to decorate */ - transient Map map; - - /** - * Constructor only used in deserialization, do not use otherwise. - */ - protected AbstractMapDecorator() { - super(); - } - - /** - * Constructor that wraps (not copies). - * - * @param map the map to decorate, must not be null - * @throws NullPointerException if the map is null - */ - protected AbstractMapDecorator(final Map map) { - if (map == null) { - throw new NullPointerException("Map must not be null."); - } - this.map = map; - } - - /** - * Gets the map being decorated. - * - * @return the decorated map - */ - protected Map decorated() { - return map; - } - - @Override - public void clear() { - decorated().clear(); - } - - @Override - public boolean containsKey(final Object key) { - return decorated().containsKey(key); - } - - @Override - public boolean containsValue(final Object value) { - return decorated().containsValue(value); - } - - @Override - public Set> entrySet() { - return decorated().entrySet(); - } - - @Override - public V get(final Object key) { - return decorated().get(key); - } - - @Override - public boolean isEmpty() { - return decorated().isEmpty(); - } - - @Override - public Set keySet() { - return decorated().keySet(); - } - - @Override - public V put(final K key, final V value) { - return decorated().put(key, value); - } - - @Override - public void putAll(final Map mapToCopy) { - decorated().putAll(mapToCopy); - } - - @Override - public V remove(final Object key) { - return decorated().remove(key); - } - - @Override - public int size() { - return decorated().size(); - } - - @Override - public Collection values() { - return decorated().values(); - } - - @Override - public boolean equals(final Object object) { - if (object == this) { - return true; - } - return decorated().equals(object); - } - - @Override - public int hashCode() { - return decorated().hashCode(); - } - - @Override - public String toString() { - return decorated().toString(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/CaseInsensitiveMap.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/CaseInsensitiveMap.java deleted file mode 100644 index 31e2a1ca165d..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/CaseInsensitiveMap.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.map; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.Map; - -public class CaseInsensitiveMap extends AbstractHashedMap implements Serializable, Cloneable { - /** Serialisation version */ - private static final long serialVersionUID = 4769170840551472270L; - - /** - * Constructs a new empty map with default size and load factor. - */ - public CaseInsensitiveMap() { - super(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD); - } - - /** - * Constructs a new, empty map with the specified initial capacity. - * - * @param initialCapacity the initial capacity - * @throws IllegalArgumentException if the initial capacity is negative - */ - public CaseInsensitiveMap(final int initialCapacity) { - super(initialCapacity); - } - - /** - * Constructs a new, empty map with the specified initial capacity and - * load factor. - * - * @param initialCapacity the initial capacity - * @param loadFactor the load factor - * @throws IllegalArgumentException if the initial capacity is negative - * @throws IllegalArgumentException if the load factor is less than zero - */ - public CaseInsensitiveMap(final int initialCapacity, final float loadFactor) { - super(initialCapacity, loadFactor); - } - - /** - * Constructor copying elements from another map. - *

- * Keys will be converted to lower case strings, which may cause - * some entries to be removed (if string representation of keys differ - * only by character case). - * - * @param map the map to copy - * @throws NullPointerException if the map is null - */ - public CaseInsensitiveMap(final Map map) { - super(map); - } - - /** - * Overrides convertKey() from {@link AbstractHashedMap} to convert keys to - * lower case. - *

- * Returns {@link AbstractHashedMap#NULL} if key is null. - * - * @param key the key convert - * @return the converted key - */ - @Override - protected Object convertKey(final Object key) { - if (key != null) { - final char[] chars = key.toString().toCharArray(); - for (int i = chars.length - 1; i >= 0; i--) { - chars[i] = Character.toLowerCase(Character.toUpperCase(chars[i])); - } - return new String(chars); - } - return AbstractHashedMap.NULL; - } - - /** - * Clones the map without cloning the keys or values. - * - * @return a shallow clone - */ - @Override - public CaseInsensitiveMap clone() { - return (CaseInsensitiveMap) super.clone(); - } - - /** - * Write the map out using a custom routine. - * - * @param out the output stream - * @throws IOException if an error occurs while writing to the stream - */ - private void writeObject(final ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - doWriteObject(out); - } - - /** - * Read the map in using a custom routine. - * - * @param in the input stream - * @throws IOException if an error occurs while reading from the stream - * @throws ClassNotFoundException if an object read from the stream can not be loaded - */ - private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); - doReadObject(in); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/EntrySetToMapIteratorAdapter.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/EntrySetToMapIteratorAdapter.java deleted file mode 100644 index 2e81f78c9b43..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/EntrySetToMapIteratorAdapter.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.map; - -import com.azure.cosmos.implementation.apachecommons.collections.MapIterator; -import com.azure.cosmos.implementation.apachecommons.collections.ResettableIterator; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -public class EntrySetToMapIteratorAdapter implements MapIterator, ResettableIterator { - /** The adapted Map entry Set. */ - Set> entrySet; - - /** The resettable iterator in use. */ - transient Iterator> iterator; - - /** The currently positioned Map entry. */ - transient Map.Entry entry; - - /** - * Create a new EntrySetToMapIteratorAdapter. - * @param entrySet the entrySet to adapt - */ - public EntrySetToMapIteratorAdapter(final Set> entrySet) { - this.entrySet = entrySet; - reset(); - } - - /** - * {@inheritDoc} - */ - @Override - public K getKey() { - return current().getKey(); - } - - /** - * {@inheritDoc} - */ - @Override - public V getValue() { - return current().getValue(); - } - - /** - * {@inheritDoc} - */ - @Override - public V setValue(final V value) { - return current().setValue(value); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean hasNext() { - return iterator.hasNext(); - } - - /** - * {@inheritDoc} - */ - @Override - public K next() { - entry = iterator.next(); - return getKey(); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void reset() { - iterator = entrySet.iterator(); - } - - /** - * {@inheritDoc} - */ - @Override - public void remove() { - iterator.remove(); - entry = null; - } - - /** - * Get the currently active entry. - * @return Map.Entry<K, V> - */ - protected synchronized Map.Entry current() { - if (entry == null) { - throw new IllegalStateException(); - } - return entry; - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/UnmodifiableEntrySet.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/UnmodifiableEntrySet.java deleted file mode 100644 index e1d2ef619305..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/UnmodifiableEntrySet.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.map; - -import java.lang.reflect.Array; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import com.azure.cosmos.implementation.apachecommons.collections.iterators.AbstractIteratorDecorator; -import com.azure.cosmos.implementation.apachecommons.collections.keyvalue.AbstractMapEntryDecorator; -import com.azure.cosmos.implementation.apachecommons.collections.list.Unmodifiable; -import com.azure.cosmos.implementation.apachecommons.collections.set.AbstractSetDecorator; - -public final class UnmodifiableEntrySet - extends AbstractSetDecorator> implements Unmodifiable { - /** Serialization version */ - private static final long serialVersionUID = -5620364180021911893L; - - /** - * Factory method to create an unmodifiable set of Map Entry objects. - * - * @param the key type - * @param the value type - * @param set the set to decorate, must not be null - * @return a new unmodifiable entry set - * @throws NullPointerException if set is null - */ - public static Set> unmodifiableEntrySet(final Set> set) { - if (set instanceof Unmodifiable) { - return set; - } - return new UnmodifiableEntrySet<>(set); - } - - /** - * Constructor that wraps (not copies). - * - * @param set the set to decorate, must not be null - * @throws NullPointerException if set is null - */ - private UnmodifiableEntrySet(final Set> set) { - super(set); - } - - @Override - public boolean add(final Map.Entry object) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean addAll(final Collection> coll) { - throw new UnsupportedOperationException(); - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean remove(final Object object) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean removeAll(final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean retainAll(final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public Iterator> iterator() { - return new UnmodifiableEntrySetIterator(decorated().iterator()); - } - - @Override - @SuppressWarnings("unchecked") - public Object[] toArray() { - final Object[] array = decorated().toArray(); - for (int i = 0; i < array.length; i++) { - array[i] = new UnmodifiableEntry((Map.Entry) array[i]); - } - return array; - } - - @Override - @SuppressWarnings("unchecked") - public T[] toArray(final T[] array) { - Object[] result = array; - if (array.length > 0) { - // we must create a new array to handle multi-threaded situations - // where another thread could access data before we decorate it - result = (Object[]) Array.newInstance(array.getClass().getComponentType(), 0); - } - result = decorated().toArray(result); - for (int i = 0; i < result.length; i++) { - result[i] = new UnmodifiableEntry((Map.Entry) result[i]); - } - - // check to see if result should be returned straight - if (result.length > array.length) { - return (T[]) result; - } - - // copy back into input array to fulfill the method contract - System.arraycopy(result, 0, array, 0, result.length); - if (array.length > result.length) { - array[result.length] = null; - } - return array; - } - - /** - * Implementation of an entry set iterator. - */ - private class UnmodifiableEntrySetIterator extends AbstractIteratorDecorator> { - - protected UnmodifiableEntrySetIterator(final Iterator> iterator) { - super(iterator); - } - - @Override - public Map.Entry next() { - return new UnmodifiableEntry(getIterator().next()); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - } - - /** - * Implementation of a map entry that is unmodifiable. - */ - private class UnmodifiableEntry extends AbstractMapEntryDecorator { - - protected UnmodifiableEntry(final Map.Entry entry) { - super(entry); - } - - @Override - public V setValue(final V obj) { - throw new UnsupportedOperationException(); - } - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/UnmodifiableMap.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/UnmodifiableMap.java deleted file mode 100644 index 6f9cbcbd70d3..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/map/UnmodifiableMap.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.map; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import com.azure.cosmos.implementation.apachecommons.collections.IterableMap; -import com.azure.cosmos.implementation.apachecommons.collections.MapIterator; -import com.azure.cosmos.implementation.apachecommons.collections.UnmodifiableCollection; -import com.azure.cosmos.implementation.apachecommons.collections.iterators.EntrySetMapIterator; -import com.azure.cosmos.implementation.apachecommons.collections.iterators.UnmodifiableMapIterator; -import com.azure.cosmos.implementation.apachecommons.collections.list.Unmodifiable; -import com.azure.cosmos.implementation.apachecommons.collections.set.UnmodifiableSet; - -public final class UnmodifiableMap - extends AbstractMapDecorator - implements Unmodifiable, Serializable { - /** Serialization version */ - private static final long serialVersionUID = -1132159183705203881L; - - /** - * Factory method to create an unmodifiable map. - * - * @param the key type - * @param the value type - * @param map the map to decorate, must not be null - * @return a new unmodifiable map - * @throws NullPointerException if map is null - */ - public static Map unmodifiableMap(final Map map) { - if (map instanceof Unmodifiable) { - @SuppressWarnings("unchecked") // safe to upcast - final Map tmpMap = (Map) map; - return tmpMap; - } - return new UnmodifiableMap<>(map); - } - - /** - * Constructor that wraps (not copies). - * - * @param map the map to decorate, must not be null - * @throws NullPointerException if map is null - */ - @SuppressWarnings("unchecked") // safe to upcast - private UnmodifiableMap(final Map map) { - super((Map) map); - } - - /** - * Write the map out using a custom routine. - * - * @param out the output stream - * @throws IOException if an error occurs while writing to the stream - */ - private void writeObject(final ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - out.writeObject(map); - } - - /** - * Read the map in using a custom routine. - * - * @param in the input stream - * @throws IOException if an error occurs while reading from the stream - * @throws ClassNotFoundException if an object read from the stream can not be loaded - */ - @SuppressWarnings("unchecked") - private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); - map = (Map) in.readObject(); - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public V put(final K key, final V value) { - throw new UnsupportedOperationException(); - } - - @Override - public void putAll(final Map mapToCopy) { - throw new UnsupportedOperationException(); - } - - @Override - public V remove(final Object key) { - throw new UnsupportedOperationException(); - } - - @Override - public MapIterator mapIterator() { - if (map instanceof IterableMap) { - final MapIterator it = ((IterableMap) map).mapIterator(); - return UnmodifiableMapIterator.unmodifiableMapIterator(it); - } - final MapIterator it = new EntrySetMapIterator<>(map); - return UnmodifiableMapIterator.unmodifiableMapIterator(it); - } - - @Override - public Set> entrySet() { - final Set> set = super.entrySet(); - return UnmodifiableEntrySet.unmodifiableEntrySet(set); - } - - @Override - public Set keySet() { - final Set set = super.keySet(); - return UnmodifiableSet.unmodifiableSet(set); - } - - @Override - public Collection values() { - final Collection coll = super.values(); - return UnmodifiableCollection.unmodifiableCollection(coll); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/AbstractSerializableSetDecorator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/AbstractSerializableSetDecorator.java deleted file mode 100644 index 9584bbb84c89..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/AbstractSerializableSetDecorator.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.set; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Collection; -import java.util.Set; - -public abstract class AbstractSerializableSetDecorator - extends AbstractSetDecorator { - /** Serialization version */ - private static final long serialVersionUID = -8998839529695814986L; - - /** - * Constructor. - * - * @param set the list to decorate, must not be null - * @throws NullPointerException if set is null - */ - protected AbstractSerializableSetDecorator(final Set set) { - super(set); - } - - /** - * Write the set out using a custom routine. - * - * @param out the output stream - * @throws IOException if an error occurs while writing to the stream - */ - private void writeObject(final ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - out.writeObject(decorated()); - } - - /** - * Read the set in using a custom routine. - * - * @param in the input stream - * @throws IOException if an error occurs while reading from the stream - * @throws ClassNotFoundException if an object read from the stream can not be loaded - */ - @SuppressWarnings("unchecked") - private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); - setCollection((Collection) in.readObject()); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/AbstractSetDecorator.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/AbstractSetDecorator.java deleted file mode 100644 index f2049747c27e..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/AbstractSetDecorator.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.set; - -import com.azure.cosmos.implementation.apachecommons.collections.AbstractCollectionDecorator; - -import java.util.Set; - -public abstract class AbstractSetDecorator extends AbstractCollectionDecorator implements - Set { - /** Serialization version */ - private static final long serialVersionUID = 7970325904666333066L; - - /** - * Constructor only used in deserialization, do not use otherwise. - */ - protected AbstractSetDecorator() { - super(); - } - - /** - * Constructor that wraps (not copies). - * - * @param set the set to decorate, must not be null - * @throws NullPointerException if set is null - */ - protected AbstractSetDecorator(final Set set) { - super(set); - } - - /** - * Gets the set being decorated. - * - * @return the decorated set - */ - @Override - protected Set decorated() { - return (Set) super.decorated(); - } - - @Override - public boolean equals(final Object object) { - return object == this || decorated().equals(object); - } - - @Override - public int hashCode() { - return decorated().hashCode(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/UnmodifiableSet.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/UnmodifiableSet.java deleted file mode 100644 index 6914e4063f87..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/apachecommons/collections/set/UnmodifiableSet.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Portions Copyright (c) Microsoft Corporation - */ - -package com.azure.cosmos.implementation.apachecommons.collections.set; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import com.azure.cosmos.implementation.apachecommons.collections.list.Unmodifiable; -import com.azure.cosmos.implementation.apachecommons.collections.list.iterators.UnmodifiableIterator; - -public final class UnmodifiableSet - extends AbstractSerializableSetDecorator - implements Unmodifiable { - /** Serialization version */ - private static final long serialVersionUID = 2106511754030535764L; - - /** - * Factory method to create an unmodifiable set. - * - * @param the element type - * @param set the set to decorate, must not be null - * @return a new unmodifiable set - * @throws NullPointerException if set is null - */ - public static Set unmodifiableSet(final Set set) { - if (set instanceof Unmodifiable) { - @SuppressWarnings("unchecked") // safe to upcast - final Set tmpSet = (Set) set; - return tmpSet; - } - return new UnmodifiableSet<>(set); - } - - /** - * Constructor that wraps (not copies). - * - * @param set the set to decorate, must not be null - * @throws NullPointerException if set is null - */ - @SuppressWarnings("unchecked") // safe to upcast - private UnmodifiableSet(final Set set) { - super((Set) set); - } - - @Override - public Iterator iterator() { - return UnmodifiableIterator.unmodifiableIterator(decorated().iterator()); - } - - @Override - public boolean add(final E object) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean addAll(final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean remove(final Object object) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean removeAll(final Collection coll) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean retainAll(final Collection coll) { - throw new UnsupportedOperationException(); - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/ServerBatchRequest.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/ServerBatchRequest.java index 6748be3cb080..49f4fc155e00 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/ServerBatchRequest.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/batch/ServerBatchRequest.java @@ -6,10 +6,10 @@ import com.azure.cosmos.CosmosItemSerializer; import com.azure.cosmos.implementation.JsonSerializable; import com.azure.cosmos.implementation.Utils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.models.CosmosItemOperation; import com.fasterxml.jackson.databind.node.ArrayNode; +import java.util.Collections; import java.util.List; import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull; @@ -106,7 +106,7 @@ public final String getRequestBody() { * @return the list of {@link CosmosItemOperation operations} in this {@link ServerBatchRequest batch request}. */ public final List getOperations() { - return UnmodifiableList.unmodifiableList(this.operations); + return Collections.unmodifiableList(this.operations); } public boolean isAtomicBatch() { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/caches/RxPartitionKeyRangeCache.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/caches/RxPartitionKeyRangeCache.java index b869489c7d75..1017ad1af0da 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/caches/RxPartitionKeyRangeCache.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/caches/RxPartitionKeyRangeCache.java @@ -17,7 +17,6 @@ import com.azure.cosmos.implementation.RxDocumentClientImpl; import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.Utils; -import com.azure.cosmos.implementation.apachecommons.collections.CollectionUtils; import com.azure.cosmos.implementation.apachecommons.lang.tuple.ImmutablePair; import com.azure.cosmos.implementation.routing.CollectionRoutingMap; import com.azure.cosmos.implementation.routing.IServerIdentity; @@ -33,12 +32,12 @@ import java.time.Instant; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * While this class is public, but it is not part of our published public APIs. @@ -308,7 +307,9 @@ private CollectionRoutingMap updateRoutingMap( if (previousRoutingMap == null) { // Splits could have happened during change feed query and we might have a mix of gone and new ranges. - Set goneRanges = new HashSet<>(ranges.stream().flatMap(range -> CollectionUtils.emptyIfNull(range.getParents()).stream()).collect(Collectors.toSet())); + Set goneRanges = ranges.stream() + .flatMap(range -> range.getParents() == null ? Stream.of() :range.getParents().stream()) + .collect(Collectors.toSet()); routingMap = InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap( rangesTuples.stream().filter(tuple -> !goneRanges.contains(tuple.left.getId())).collect(Collectors.toList()), diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/ConsistencyWriter.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/ConsistencyWriter.java index 86b3e6cd0346..f55a5b8d222f 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/ConsistencyWriter.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/ConsistencyWriter.java @@ -26,7 +26,6 @@ import com.azure.cosmos.implementation.SessionTokenMismatchRetryPolicy; import com.azure.cosmos.implementation.Strings; import com.azure.cosmos.implementation.Utils; -import com.azure.cosmos.implementation.apachecommons.collections.ComparatorUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.Exceptions; @@ -456,7 +455,7 @@ private Mono waitForWriteBarrierAsync( //get max global committed lsn from current batch of responses, then update if greater than max of all batches. long maxGlobalCommittedLsn = (responses != null) ? - responses.stream().map(s -> s.globalCommittedLSN).max(ComparatorUtils.naturalComparator()).orElse(0L) : + responses.stream().map(s -> s.globalCommittedLSN).max(Long::compareTo).orElse(0L) : 0L; maxGlobalCommittedLsnReceived.set(Math.max(maxGlobalCommittedLsnReceived.get(), maxGlobalCommittedLsn)); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangeEpkImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangeEpkImpl.java index 93ac1cc571f9..19e56dfb6d29 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangeEpkImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangeEpkImpl.java @@ -16,7 +16,6 @@ import com.azure.cosmos.implementation.ReadFeedKeyType; import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.Utils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.routing.PartitionKeyInternalHelper; import com.azure.cosmos.implementation.routing.PartitionKeyRangeIdentity; import com.azure.cosmos.implementation.routing.Range; @@ -24,6 +23,7 @@ import reactor.core.publisher.Mono; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -125,7 +125,7 @@ public Mono> getPartitionKeyRanges( } } - return Mono.just(UnmodifiableList.unmodifiableList(rangeList)); + return Mono.just(Collections.unmodifiableList(rangeList)); }); }); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangePartitionKeyImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangePartitionKeyImpl.java index dd7731eaa3f6..1e9257beb932 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangePartitionKeyImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangePartitionKeyImpl.java @@ -12,13 +12,13 @@ import com.azure.cosmos.implementation.MetadataDiagnosticsContext; import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.Utils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.routing.PartitionKeyInternal; import com.azure.cosmos.implementation.routing.Range; import com.azure.cosmos.models.PartitionKeyDefinition; import reactor.core.publisher.Mono; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -139,7 +139,7 @@ public Mono> getPartitionKeyRanges( rangeList.add(rangeId); } - return Mono.just((UnmodifiableList)UnmodifiableList.unmodifiableList(rangeList)); + return Mono.just(Collections.unmodifiableList(rangeList)); }); }); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangePartitionKeyRangeImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangePartitionKeyRangeImpl.java index fdd76fddf617..295786460269 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangePartitionKeyRangeImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/feedranges/FeedRangePartitionKeyRangeImpl.java @@ -12,12 +12,12 @@ import com.azure.cosmos.implementation.PartitionKeyRangeGoneException; import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.Utils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.routing.PartitionKeyRangeIdentity; import com.azure.cosmos.implementation.routing.Range; import reactor.core.publisher.Mono; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -125,8 +125,7 @@ public Mono> getPartitionKeyRanges( final ArrayList temp = new ArrayList<>(); temp.add(this.partitionKeyRangeId); - return Mono.just( - UnmodifiableList.unmodifiableList(temp)); + return Mono.just(Collections.unmodifiableList(temp)); } @Override diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/perPartitionCircuitBreaker/GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/perPartitionCircuitBreaker/GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker.java index 0213f2255144..7fa83a527f64 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/perPartitionCircuitBreaker/GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/perPartitionCircuitBreaker/GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker.java @@ -14,7 +14,6 @@ import com.azure.cosmos.implementation.PartitionKeyRangeWrapper; import com.azure.cosmos.implementation.ResourceType; import com.azure.cosmos.implementation.RxDocumentServiceRequest; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.azure.cosmos.implementation.apachecommons.lang.tuple.Pair; import com.azure.cosmos.implementation.directconnectivity.GatewayAddressCache; @@ -138,7 +137,7 @@ public void handleLocationExceptionForPartitionKeyRange( if (isFailureThresholdBreached.get()) { - UnmodifiableList applicableRegionalRoutingContexts = request.isReadOnlyRequest() ? + List applicableRegionalRoutingContexts = request.isReadOnlyRequest() ? this.globalEndpointManager.getApplicableReadRegionalRoutingContexts(request.requestContext.getExcludeRegions()) : this.globalEndpointManager.getApplicableWriteRegionalRoutingContexts(request.requestContext.getExcludeRegions()); @@ -270,7 +269,7 @@ public List getUnavailableRegionsForPartitionKeyRange( } } - return UnmodifiableList.unmodifiableList(unavailableRegions); + return Collections.unmodifiableList(unavailableRegions); } catch (Exception e) { throw wrapAsCosmosException(request, e); } @@ -432,12 +431,12 @@ public boolean isPerPartitionLevelCircuitBreakingApplicable(RxDocumentServiceReq return false; } - UnmodifiableList applicableReadEndpoints = globalEndpointManager.getApplicableReadRegionalRoutingContexts(Collections.emptyList()); + List applicableReadEndpoints = globalEndpointManager.getApplicableReadRegionalRoutingContexts(Collections.emptyList()); return applicableReadEndpoints != null && applicableReadEndpoints.size() > 1; } - UnmodifiableList applicableWriteEndpoints = globalEndpointManager.getApplicableWriteRegionalRoutingContexts(Collections.emptyList()); + List applicableWriteEndpoints = globalEndpointManager.getApplicableWriteRegionalRoutingContexts(Collections.emptyList()); return applicableWriteEndpoints != null && applicableWriteEndpoints.size() > 1; } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/routing/InMemoryCollectionRoutingMap.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/routing/InMemoryCollectionRoutingMap.java index fdbc9983c799..a8e6a8765829 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/routing/InMemoryCollectionRoutingMap.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/routing/InMemoryCollectionRoutingMap.java @@ -5,7 +5,6 @@ import com.azure.cosmos.implementation.InCompleteRoutingMapException; import com.azure.cosmos.implementation.PartitionKeyRange; -import com.azure.cosmos.implementation.apachecommons.collections.CollectionUtils; import com.azure.cosmos.implementation.apachecommons.lang.tuple.ImmutablePair; import com.azure.cosmos.implementation.apachecommons.lang.tuple.Pair; import org.slf4j.Logger; @@ -16,13 +15,13 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Used internally to cache partition key ranges of a collection in the Azure Cosmos DB database service. @@ -54,7 +53,9 @@ private InMemoryCollectionRoutingMap(Map(orderedPartitionKeyRanges.stream().flatMap(r -> CollectionUtils.emptyIfNull(r.getParents()).stream()).collect(Collectors.toSet())); + this.goneRanges = orderedPartitionKeyRanges.stream() + .flatMap(r -> r.getParents() == null ? Stream.of() : r.getParents().stream()) + .collect(Collectors.toSet()); this.changeFeedNextIfNoneMatch.set(changeFeedNextIfNoneMatch); } @@ -242,7 +243,9 @@ public CollectionRoutingMap tryCombine( List> ranges, String changeFeedNextIfNoneMatch, String collectionRid) { - Set newGoneRanges = new HashSet<>(ranges.stream().flatMap(tuple -> CollectionUtils.emptyIfNull(tuple.getLeft().getParents()).stream()).collect(Collectors.toSet())); + Set newGoneRanges = ranges.stream() + .flatMap(tuple -> tuple.getLeft().getParents() == null ? Stream.of() : tuple.getLeft().getParents().stream()) + .collect(Collectors.toSet()); newGoneRanges.addAll(this.goneRanges); Map> newRangeById = @@ -253,7 +256,7 @@ public CollectionRoutingMap tryCombine( newRangeById.put(tuple.getLeft().getId(), tuple); } - List> sortedRanges = newRangeById.values().stream().collect(Collectors.toList()); + List> sortedRanges = new ArrayList<>(newRangeById.values()); Collections.sort(sortedRanges, new MinPartitionKeyPairComparator()); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/routing/LocationCache.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/routing/LocationCache.java index 6d61cca536d1..a70382a05ed9 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/routing/LocationCache.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/routing/LocationCache.java @@ -15,9 +15,6 @@ import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.Strings; import com.azure.cosmos.implementation.Utils; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; -import com.azure.cosmos.implementation.apachecommons.collections.map.CaseInsensitiveMap; -import com.azure.cosmos.implementation.apachecommons.collections.map.UnmodifiableMap; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,10 +24,12 @@ import java.time.Instant; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiFunction; import java.util.function.Supplier; @@ -45,6 +44,14 @@ public class LocationCache { private final static Logger logger = LoggerFactory.getLogger(LocationCache.class); + // Case-insensitive map Comparator for when the key is RegionalRoutingContext. + // This effectively matches the behavior of Apache Commons's CaseInsensitiveMap which uses a sentinel value when the + // key (RegionalRoutingContext) is null. Since it used the toString() value for key comparison, use + // Objects.toString(), which returns "null" when the key is null, to match behavior. We don't need to worry about + // inadvertent matches on "null" as RegionalRoutingContext overrides toString() and will never return "null". + private static final Comparator REGIONAL_ROUTING_CONTEXT_COMPARATOR + = Comparator.comparing(Objects::toString, String.CASE_INSENSITIVE_ORDER); + private final boolean enableEndpointDiscovery; private final RegionalRoutingContext defaultRoutingContext; private final boolean useMultipleWriteLocations; @@ -89,7 +96,7 @@ public LocationCache( * 2. Endpoint availability * @return */ - public UnmodifiableList getReadEndpoints() { + public List getReadEndpoints() { if (!this.locationUnavailabilityInfoByEndpoint.isEmpty() && unavailableLocationsExpirationTimePassed()) { this.updateLocationCache(); @@ -104,7 +111,7 @@ && unavailableLocationsExpirationTimePassed()) { * 2. Endpoint availability * @return */ - public UnmodifiableList getWriteEndpoints() { + public List getWriteEndpoints() { if (!this.locationUnavailabilityInfoByEndpoint.isEmpty() && unavailableLocationsExpirationTimePassed()) { this.updateLocationCache(); @@ -197,19 +204,19 @@ public RegionalRoutingContext resolveServiceEndpoint(RxDocumentServiceRequest re return this.defaultRoutingContext; } } else { - UnmodifiableList endpoints = + List endpoints = request.getOperationType().isWriteOperation()? this.getApplicableWriteRegionRoutingContexts(request) : this.getApplicableReadRegionRoutingContexts(request); return endpoints.get(locationIndex % endpoints.size()); } } - public UnmodifiableList getApplicableWriteRegionRoutingContexts(RxDocumentServiceRequest request) { + public List getApplicableWriteRegionRoutingContexts(RxDocumentServiceRequest request) { return this.getApplicableWriteRegionRoutingContexts(request, request.requestContext.getExcludeRegions(), request.requestContext.getUnavailableRegionsForPartition()); } - public UnmodifiableList getApplicableWriteRegionRoutingContexts(List excludedRegionsOnRequest, List unavailableRegionsForPartition) { + public List getApplicableWriteRegionRoutingContexts(List excludedRegionsOnRequest, List unavailableRegionsForPartition) { - UnmodifiableList writeEndpoints = this.getWriteEndpoints(); + List writeEndpoints = this.getWriteEndpoints(); Supplier excludedRegionsSupplier = this.connectionPolicy.getExcludedRegionsSupplier(); List effectiveExcludedRegions = isExcludedRegionsSupplierConfigured(excludedRegionsSupplier) ? @@ -236,12 +243,12 @@ public UnmodifiableList getApplicableWriteRegionRoutingC unavailableRegionsForPartition); } - public UnmodifiableList getApplicableReadRegionRoutingContexts(RxDocumentServiceRequest request) { + public List getApplicableReadRegionRoutingContexts(RxDocumentServiceRequest request) { return this.getApplicableReadRegionRoutingContexts(request, request.requestContext.getExcludeRegions(), request.requestContext.getUnavailableRegionsForPartition()); } - public UnmodifiableList getApplicableReadRegionRoutingContexts(List excludedRegionsOnRequest, List unavailableRegionsForPartition) { - UnmodifiableList readEndpoints = this.getReadEndpoints(); + public List getApplicableReadRegionRoutingContexts(List excludedRegionsOnRequest, List unavailableRegionsForPartition) { + List readEndpoints = this.getReadEndpoints(); Supplier excludedRegionsSupplier = this.connectionPolicy.getExcludedRegionsSupplier(); List effectiveExcludedRegions = isExcludedRegionsSupplierConfigured(excludedRegionsSupplier) ? @@ -268,11 +275,11 @@ public UnmodifiableList getApplicableReadRegionRoutingCo unavailableRegionsForPartition); } - private UnmodifiableList getApplicableReadRegionRoutingContexts( + private List getApplicableReadRegionRoutingContexts( RxDocumentServiceRequest request, List excludedRegionsOnRequest, List unavailableRegionsForPartition) { - UnmodifiableList readEndpoints = this.getReadEndpoints(); + List readEndpoints = this.getReadEndpoints(); Supplier excludedRegionsSupplier = this.connectionPolicy.getExcludedRegionsSupplier(); List effectiveExcludedRegions = isExcludedRegionsSupplierConfigured(excludedRegionsSupplier) ? @@ -299,12 +306,12 @@ private UnmodifiableList getApplicableReadRegionRoutingC unavailableRegionsForPartition); } - private UnmodifiableList getApplicableWriteRegionRoutingContexts( + private List getApplicableWriteRegionRoutingContexts( RxDocumentServiceRequest request, List excludedRegionsOnRequest, List unavailableRegionsForPartition) { - UnmodifiableList writeEndpoints = this.getWriteEndpoints(); + List writeEndpoints = this.getWriteEndpoints(); Supplier excludedRegionsSupplier = this.connectionPolicy.getExcludedRegionsSupplier(); List effectiveExcludedRegions = isExcludedRegionsSupplierConfigured(excludedRegionsSupplier) ? @@ -331,13 +338,13 @@ private UnmodifiableList getApplicableWriteRegionRouting unavailableRegionsForPartition); } - private UnmodifiableList getApplicableRegionRoutingContexts( + private List getApplicableRegionRoutingContexts( RxDocumentServiceRequest request, List effectivePreferredLocations, - UnmodifiableList regionalRoutingContexts, + List regionalRoutingContexts, RegionalRoutingContext hubRoutingContext, - UnmodifiableMap regionNameByRegionalRoutingContext, - UnmodifiableMap regionalRoutingContextByRegionName, + Map regionNameByRegionalRoutingContext, + Map regionalRoutingContextByRegionName, RegionalRoutingContext fallbackRoutingContext, List userConfiguredExcludeRegions, List internalExcludeRegions) { @@ -389,7 +396,7 @@ private UnmodifiableList getApplicableRegionRoutingConte return this.reevaluate( request, effectivePreferredLocations, - new UnmodifiableList<>(applicableEndpoints), + Collections.unmodifiableList(applicableEndpoints), regionNameByRegionalRoutingContext, regionalRoutingContextByRegionName, userConfiguredExcludeRegions, @@ -400,13 +407,13 @@ private UnmodifiableList getApplicableRegionRoutingConte isFallbackEndpointUsed); } - private UnmodifiableList reevaluate( + private List reevaluate( RxDocumentServiceRequest request, // populated when global endpoint == default endpoint && preferred regions not populated by user List effectivePreferredLocations, - UnmodifiableList applicableRegionalRoutingContexts, - UnmodifiableMap regionNameByRegionalRoutingContexts, - UnmodifiableMap regionalRoutingContextsByRegionName, + List applicableRegionalRoutingContexts, + Map regionNameByRegionalRoutingContexts, + Map regionalRoutingContextsByRegionName, // exclude regions from request options or client List userConfiguredExcludeRegions, // exclude URIs from per-partition circuit breaker @@ -509,7 +516,7 @@ private UnmodifiableList reevaluate( } } - return new UnmodifiableList<>(modifiedRegionalRoutingContexts); + return Collections.unmodifiableList(modifiedRegionalRoutingContexts); } private boolean isExcludeRegionsConfigured(List excludedRegionsOnRequest, List excludedRegionsOnClient) { @@ -766,7 +773,7 @@ private void updateLocationCache( Iterable gatewayReadLocations, Iterable thinClientWriteLocations, Iterable thinClientReadLocations, - UnmodifiableList preferenceList, + List preferenceList, Boolean enableMultipleWriteLocations) { synchronized (this.lockObject) { DatabaseAccountLocationsInfo nextLocationInfo = new DatabaseAccountLocationsInfo(this.locationInfo); @@ -784,9 +791,9 @@ private void updateLocationCache( this.clearStaleEndpointUnavailabilityInfo(); if (gatewayReadLocations != null) { - Utils.ValueHolder> readLocationsValueHolderOut = Utils.ValueHolder.initialize(nextLocationInfo.availableReadLocations); - Utils.ValueHolder> availableReadEndpointsOut = Utils.ValueHolder.initialize(nextLocationInfo.availableReadRegionalRoutingContexts); - Utils.ValueHolder> readRegionMapValueHolderOut = Utils.ValueHolder.initialize(nextLocationInfo.regionNameByReadRegionalRoutingContexts); + Utils.ValueHolder> readLocationsValueHolderOut = Utils.ValueHolder.initialize(nextLocationInfo.availableReadLocations); + Utils.ValueHolder> availableReadEndpointsOut = Utils.ValueHolder.initialize(nextLocationInfo.availableReadRegionalRoutingContexts); + Utils.ValueHolder> readRegionMapValueHolderOut = Utils.ValueHolder.initialize(nextLocationInfo.regionNameByReadRegionalRoutingContexts); nextLocationInfo.availableReadRegionalRoutingContextsByRegionName = this.getEndpointsByLocation(gatewayReadLocations, thinClientReadLocations, readLocationsValueHolderOut, availableReadEndpointsOut, readRegionMapValueHolderOut); nextLocationInfo.availableReadLocations = readLocationsValueHolderOut.v; @@ -796,9 +803,9 @@ private void updateLocationCache( } if (gatewayWriteLocations != null) { - Utils.ValueHolder> writeLocationsValueHolderOut = Utils.ValueHolder.initialize(nextLocationInfo.availableWriteLocations); - Utils.ValueHolder> writeRegionMapOut = Utils.ValueHolder.initialize(nextLocationInfo.regionNameByWriteRegionalRoutingContexts); - Utils.ValueHolder> availableWriteEndpointsOut = Utils.ValueHolder.initialize(nextLocationInfo.availableWriteRegionalRoutingContexts); + Utils.ValueHolder> writeLocationsValueHolderOut = Utils.ValueHolder.initialize(nextLocationInfo.availableWriteLocations); + Utils.ValueHolder> writeRegionMapOut = Utils.ValueHolder.initialize(nextLocationInfo.regionNameByWriteRegionalRoutingContexts); + Utils.ValueHolder> availableWriteEndpointsOut = Utils.ValueHolder.initialize(nextLocationInfo.availableWriteRegionalRoutingContexts); nextLocationInfo.availableWriteRegionalRoutingContextsByRegionName = this.getEndpointsByLocation(gatewayWriteLocations, thinClientWriteLocations, writeLocationsValueHolderOut, availableWriteEndpointsOut, writeRegionMapOut); nextLocationInfo.availableWriteLocations = writeLocationsValueHolderOut.v; @@ -828,10 +835,10 @@ private void updateLocationCache( } } - private UnmodifiableList getPreferredAvailableRoutingContexts(UnmodifiableMap endpointsByLocation, - UnmodifiableList orderedLocations, - OperationType expectedAvailableOperation, - RegionalRoutingContext fallbackRegionalRoutingContext) { + private List getPreferredAvailableRoutingContexts(Map endpointsByLocation, + List orderedLocations, + OperationType expectedAvailableOperation, + RegionalRoutingContext fallbackRegionalRoutingContext) { List endpoints = new ArrayList<>(); DatabaseAccountLocationsInfo currentLocationInfo = this.locationInfo; // if enableEndpointDiscovery is false, we always use the defaultEndpoint that user passed in during documentClient init @@ -895,7 +902,7 @@ private UnmodifiableList getPreferredAvailableRoutingCon if (endpoints.isEmpty()) { endpoints.add(fallbackRegionalRoutingContext); } - return new UnmodifiableList<>(endpoints); + return Collections.unmodifiableList(endpoints); } private void addRoutingContexts( @@ -957,23 +964,23 @@ private void addRoutingContexts( } } - private UnmodifiableMap getEndpointsByLocation(Iterable gatewayLocations, + private Map getEndpointsByLocation(Iterable gatewayLocations, Iterable thinclientLocations, - Utils.ValueHolder> orderedLocations, - Utils.ValueHolder> orderedEndpointsHolder, - Utils.ValueHolder> regionMap) { - Map endpointsByLocation = new CaseInsensitiveMap<>(); - Map regionByEndpoint = new CaseInsensitiveMap<>(); + Utils.ValueHolder> orderedLocations, + Utils.ValueHolder> orderedEndpointsHolder, + Utils.ValueHolder> regionMap) { + Map endpointsByLocation = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + Map regionByEndpoint = new TreeMap<>(REGIONAL_ROUTING_CONTEXT_COMPARATOR); List parsedLocations = new ArrayList<>(); List orderedEndpoints = new ArrayList<>(); addRoutingContexts(gatewayLocations, thinclientLocations, endpointsByLocation, regionByEndpoint, parsedLocations, orderedEndpoints); - orderedLocations.v = new UnmodifiableList<>(parsedLocations); - orderedEndpointsHolder.v = new UnmodifiableList<>(orderedEndpoints); - regionMap.v = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(regionByEndpoint); + orderedLocations.v = Collections.unmodifiableList(parsedLocations); + orderedEndpointsHolder.v = Collections.unmodifiableList(orderedEndpoints); + regionMap.v = Collections.unmodifiableMap(regionByEndpoint); - return (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(endpointsByLocation); + return Collections.unmodifiableMap(endpointsByLocation); } public boolean canUseMultipleWriteLocations() { @@ -1049,40 +1056,36 @@ private static boolean isExcludedRegionsSupplierConfigured(Supplier writeRegionalRoutingContexts; - private UnmodifiableList readRegionalRoutingContexts; - private UnmodifiableList preferredLocations; - private UnmodifiableList effectivePreferredLocations; + private List writeRegionalRoutingContexts; + private List readRegionalRoutingContexts; + private List preferredLocations; + private List effectivePreferredLocations; // lower-case region - private UnmodifiableList availableWriteLocations; + private List availableWriteLocations; // lower-case region - private UnmodifiableList availableReadLocations; - private UnmodifiableMap availableWriteRegionalRoutingContextsByRegionName; - private UnmodifiableMap availableReadRegionalRoutingContextsByRegionName; - private UnmodifiableMap regionNameByWriteRegionalRoutingContexts; - private UnmodifiableMap regionNameByReadRegionalRoutingContexts; - private UnmodifiableList availableWriteRegionalRoutingContexts; - private UnmodifiableList availableReadRegionalRoutingContexts; + private List availableReadLocations; + private Map availableWriteRegionalRoutingContextsByRegionName; + private Map availableReadRegionalRoutingContextsByRegionName; + private Map regionNameByWriteRegionalRoutingContexts; + private Map regionNameByReadRegionalRoutingContexts; + private List availableWriteRegionalRoutingContexts; + private List availableReadRegionalRoutingContexts; private RegionalRoutingContext hubRoutingContext; public DatabaseAccountLocationsInfo(List preferredLocations, RegionalRoutingContext defaultRoutingContext) { - this.preferredLocations = new UnmodifiableList<>(preferredLocations.stream().map(loc -> loc.toLowerCase(Locale.ROOT)).collect(Collectors.toList())); - this.effectivePreferredLocations = new UnmodifiableList<>(Collections.emptyList()); - this.availableWriteRegionalRoutingContextsByRegionName - = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(new CaseInsensitiveMap<>()); - this.availableReadRegionalRoutingContextsByRegionName - = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(new CaseInsensitiveMap<>()); - this.regionNameByWriteRegionalRoutingContexts - = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(new CaseInsensitiveMap<>()); - this.regionNameByReadRegionalRoutingContexts - = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(new CaseInsensitiveMap<>()); - this.availableReadLocations = new UnmodifiableList<>(Collections.emptyList()); - this.availableWriteLocations = new UnmodifiableList<>(Collections.emptyList()); - this.readRegionalRoutingContexts = new UnmodifiableList<>(Collections.singletonList(defaultRoutingContext)); - this.writeRegionalRoutingContexts = new UnmodifiableList<>(Collections.singletonList(defaultRoutingContext)); - this.availableReadRegionalRoutingContexts = new UnmodifiableList<>(Collections.singletonList(defaultRoutingContext)); - this.availableWriteRegionalRoutingContexts = new UnmodifiableList<>(Collections.singletonList(defaultRoutingContext)); + this.preferredLocations = Collections.unmodifiableList(preferredLocations.stream().map(loc -> loc.toLowerCase(Locale.ROOT)).collect(Collectors.toList())); + this.effectivePreferredLocations = Collections.emptyList(); + this.availableWriteRegionalRoutingContextsByRegionName = Collections.unmodifiableMap(new TreeMap<>(String.CASE_INSENSITIVE_ORDER)); + this.availableReadRegionalRoutingContextsByRegionName = Collections.unmodifiableMap(new TreeMap<>(String.CASE_INSENSITIVE_ORDER)); + this.regionNameByWriteRegionalRoutingContexts = Collections.unmodifiableMap(new TreeMap<>(REGIONAL_ROUTING_CONTEXT_COMPARATOR)); + this.regionNameByReadRegionalRoutingContexts = Collections.unmodifiableMap(new TreeMap<>(REGIONAL_ROUTING_CONTEXT_COMPARATOR)); + this.availableReadLocations = Collections.emptyList(); + this.availableWriteLocations = Collections.emptyList(); + this.readRegionalRoutingContexts = Collections.singletonList(defaultRoutingContext); + this.writeRegionalRoutingContexts = Collections.singletonList(defaultRoutingContext); + this.availableReadRegionalRoutingContexts = Collections.singletonList(defaultRoutingContext); + this.availableWriteRegionalRoutingContexts = Collections.singletonList(defaultRoutingContext); } public DatabaseAccountLocationsInfo(DatabaseAccountLocationsInfo other) { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosBatch.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosBatch.java index fe9b5aab8c3b..78d6dac2ace0 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosBatch.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosBatch.java @@ -4,10 +4,10 @@ package com.azure.cosmos.models; import com.azure.cosmos.implementation.ImplementationBridgeHelpers; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.batch.ItemBatchOperation; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull; @@ -375,7 +375,7 @@ public CosmosItemOperation patchItemOperation( * @return The list of operations which are to be executed. */ public List getOperations() { - return UnmodifiableList.unmodifiableList(operations); + return Collections.unmodifiableList(operations); } /** diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosBatchRequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosBatchRequestOptions.java index 78ff20d76815..89daa46b5e8a 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosBatchRequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosBatchRequestOptions.java @@ -8,7 +8,6 @@ import com.azure.cosmos.CosmosItemSerializer; import com.azure.cosmos.implementation.ImplementationBridgeHelpers; import com.azure.cosmos.implementation.RequestOptions; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import java.util.ArrayList; import java.util.Collections; @@ -171,7 +170,7 @@ public List getExcludedRegions() { if (this.excludeRegions == null) { return null; } - return UnmodifiableList.unmodifiableList(this.excludeRegions); + return Collections.unmodifiableList(this.excludeRegions); } /** diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemRequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemRequestOptions.java index 72eb108a6428..52c592fcaf30 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemRequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemRequestOptions.java @@ -10,7 +10,6 @@ import com.azure.cosmos.ReadConsistencyStrategy; import com.azure.cosmos.implementation.ImplementationBridgeHelpers; import com.azure.cosmos.implementation.RequestOptions; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.implementation.spark.OperationContextAndListenerTuple; import com.azure.cosmos.util.Beta; @@ -457,7 +456,7 @@ public List getExcludedRegions() { if (this.excludeRegions == null) { return null; } - return UnmodifiableList.unmodifiableList(this.excludeRegions); + return Collections.unmodifiableList(this.excludeRegions); } /** diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosRequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosRequestOptions.java index 6a332c16299d..66ade524454c 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosRequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosRequestOptions.java @@ -6,7 +6,6 @@ import com.azure.cosmos.CosmosDiagnosticsThresholds; import com.azure.cosmos.CosmosEndToEndOperationLatencyPolicyConfig; import com.azure.cosmos.ReadConsistencyStrategy; -import com.azure.cosmos.implementation.apachecommons.collections.list.UnmodifiableList; import com.azure.cosmos.util.Beta; import java.util.Collections; @@ -338,7 +337,7 @@ public List getExcludedRegions() { if (this.excludeRegions == null) { return null; } - return UnmodifiableList.unmodifiableList(this.excludeRegions); + return Collections.unmodifiableList(this.excludeRegions); } /** diff --git a/sdk/cosmos/cgmanifest.json b/sdk/cosmos/cgmanifest.json index e7c03ac900f1..5b97332eb68b 100644 --- a/sdk/cosmos/cgmanifest.json +++ b/sdk/cosmos/cgmanifest.json @@ -12,16 +12,6 @@ } } }, - { - "component": { - "type": "maven", - "maven": { - "groupId": "org.apache.commons", - "artifactId": "commons-collections4", - "version": "4.2" - } - } - }, { "component": { "type": "maven",