org.soulwing.cas.service.TransformingMap Maven / Gradle / Ivy
Show all versions of cas-subsystem Show documentation
/*
* File created on Feb 25, 2015
*
* Copyright (c) 2014 Virginia Polytechnic Institute and State University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.soulwing.cas.service;
import java.util.AbstractMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.jboss.as.controller.transform.Transformers;
import org.soulwing.cas.api.Transformer;
/**
* A {@link Map} that transforms mapped values in a delegate map using
* a map of corresponding {@link Transformers}.
*
* If the specified transformer map does not contain a value for a key defined
* in the delegate map, the value of the delegate map is not transformed
* (in other words, an identity transform is applied).
*
* @author Carl Harris
*/
class TransformingMap extends AbstractMap {
private final Lock lock = new ReentrantLock();
private final Map delegate;
private final Map> transformers;
private Set> entrySet;
/**
* Constructs a new instance.
* @param delegate
*/
public TransformingMap(Map delegate,
Map> transformers) {
this.delegate = delegate;
this.transformers = transformers;
}
@Override
public Set> entrySet() {
if (entrySet == null) {
lock.lock();
try {
if (entrySet == null) {
entrySet = new LinkedHashSet<>();
for (String key : delegate.keySet()) {
Transformer