Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Maintains state during a single conversion operation.
*
* @author John DeRegnaucourt ([email protected])
*
* Copyright (c) Cedar Software LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class CollectionHandling {
private CollectionHandling() { }
// Special collection type markers with their handlers
private static final Map, CollectionFactory> SPECIAL_HANDLERS = new LinkedHashMap<>();
// Base collection type mappings (most specific to most general)
private static final Map, Function>> BASE_FACTORIES = new LinkedHashMap<>();
private static final Map, Function>> FACTORY_CACHE = new ConcurrentHashMap<>();
static {
// Initialize special collection handlers (most specific to most general)
initializeSpecialHandlers();
// Initialize base collection factories (most specific to most general)
initializeBaseFactories();
validateMappings();
}
@SuppressWarnings({"unchecked"})
private static void initializeSpecialHandlers() {
// Empty collections
SPECIAL_HANDLERS.put(CollectionsWrappers.getEmptyNavigableSetClass(), (size, source) ->
Collections.emptyNavigableSet());
SPECIAL_HANDLERS.put(CollectionsWrappers.getEmptySortedSetClass(), (size, source) ->
Collections.emptySortedSet());
SPECIAL_HANDLERS.put(CollectionsWrappers.getEmptySetClass(), (size, source) ->
Collections.emptySet());
SPECIAL_HANDLERS.put(CollectionsWrappers.getEmptyListClass(), (size, source) ->
Collections.emptyList());
SPECIAL_HANDLERS.put(CollectionsWrappers.getEmptyCollectionClass(), (size, source) ->
Collections.emptyList());
// Unmodifiable collections
SPECIAL_HANDLERS.put(CollectionsWrappers.getUnmodifiableNavigableSetClass(), (size, source) ->
createOptimalNavigableSet(source, size));
SPECIAL_HANDLERS.put(CollectionsWrappers.getUnmodifiableSortedSetClass(), (size, source) ->
createOptimalSortedSet(source, size));
SPECIAL_HANDLERS.put(CollectionsWrappers.getUnmodifiableSetClass(), (size, source) ->
createOptimalSet(source, size));
SPECIAL_HANDLERS.put(CollectionsWrappers.getUnmodifiableListClass(), (size, source) ->
createOptimalList(source, size));
SPECIAL_HANDLERS.put(CollectionsWrappers.getUnmodifiableCollectionClass(), (size, source) ->
createOptimalCollection(source, size));
// Synchronized collections
SPECIAL_HANDLERS.put(CollectionsWrappers.getSynchronizedNavigableSetClass(), (size, source) ->
Collections.synchronizedNavigableSet(createOptimalNavigableSet(source, size)));
SPECIAL_HANDLERS.put(CollectionsWrappers.getSynchronizedSortedSetClass(), (size, source) ->
Collections.synchronizedSortedSet(createOptimalSortedSet(source, size)));
SPECIAL_HANDLERS.put(CollectionsWrappers.getSynchronizedSetClass(), (size, source) ->
Collections.synchronizedSet(createOptimalSet(source, size)));
SPECIAL_HANDLERS.put(CollectionsWrappers.getSynchronizedListClass(), (size, source) ->
Collections.synchronizedList(createOptimalList(source, size)));
SPECIAL_HANDLERS.put(CollectionsWrappers.getSynchronizedCollectionClass(), (size, source) ->
Collections.synchronizedCollection(createOptimalCollection(source, size)));
// Checked collections
SPECIAL_HANDLERS.put(CollectionsWrappers.getCheckedNavigableSetClass(), (size, source) -> {
NavigableSet> navigableSet = createOptimalNavigableSet(source, size);
Class