org.osgi.util.converter.MapDelegate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aem-sdk-api Show documentation
Show all versions of aem-sdk-api Show documentation
The Adobe Experience Manager SDK
The newest version!
/*******************************************************************************
* Copyright (c) Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
package org.osgi.util.converter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author $Id: 8ef010ebad1d31b8decce2b532a30d937942ec2a $
*/
class MapDelegate implements Map {
// not synchronized. Worst that can happen is that cloning is done more than
// once, which is harmless.
private volatile boolean cloned = false;
private final ConvertingImpl convertingImpl;
private final InternalConverter converter;
Map delegate;
private MapDelegate(ConvertingImpl converting, InternalConverter c,
Map del) {
convertingImpl = converting;
converter = c;
delegate = del;
}
static MapDelegate forBean(Object b, Class< ? > beanClass,
ConvertingImpl converting, InternalConverter c) {
return new MapDelegate<>(converting, c,
new DynamicBeanFacade(b, beanClass, converting));
}
static Map forMap(Map m, ConvertingImpl converting,
InternalConverter c) {
return new MapDelegate<>(converting, c,
new DynamicMapFacade<>(m, converting));
}
static MapDelegate forDictionary(Dictionary d,
ConvertingImpl converting, InternalConverter c) {
return new MapDelegate<>(converting, c,
new DynamicDictionaryFacade<>(d, converting));
}
static MapDelegate forDTO(Object obj, Class< ? > dtoClass,
ConvertingImpl converting, InternalConverter c) {
return new MapDelegate<>(converting, c,
new DynamicDTOFacade(obj, dtoClass, converting));
}
static MapDelegate forInterface(Object obj, Class< ? > intf,
ConvertingImpl converting, InternalConverter c) {
return new MapDelegate<>(converting, c,
new DynamicInterfaceFacade(obj, intf, converting));
}
@Override
public int size() {
// Need to convert the entire map to get the size
Set