
com.cognitect.transit.impl.WriteHandlerMap Maven / Gradle / Ivy
// Copyright 2014 Cognitect. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES 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.cognitect.transit.impl;
import com.cognitect.transit.WriteHandler;
import java.util.*;
public class WriteHandlerMap implements TagProvider, Map> {
private final Map> handlers;
private WriteHandlerMap verboseHandlerMap;
public WriteHandlerMap(Map> customHandlers) {
this.handlers = WriterFactory.defaultHandlers();
if (customHandlers != null) {
handlers.putAll(customHandlers);
}
setTagProvider(handlers);
}
public WriteHandlerMap verboseWriteHandlerMap() {
if (verboseHandlerMap == null) {
Map> verboseHandlers = new HashMap>(handlers.size());
for (Map.Entry> entry : handlers.entrySet()) {
WriteHandler, ?> verboseHandler = entry.getValue().getVerboseHandler();
verboseHandlers.put(
entry.getKey(),
(verboseHandler == null) ? entry.getValue() : verboseHandler);
}
this.verboseHandlerMap = new WriteHandlerMap(verboseHandlers);
}
return this.verboseHandlerMap;
}
private void setTagProvider(Map> handlers) {
Iterator> i = handlers.values().iterator();
while(i.hasNext()) {
WriteHandler h = i.next();
if(h instanceof TagProviderAware)
((TagProviderAware)h).setTagProvider(this);
}
}
private Map> getUnderlyingMap() {
return handlers;
}
@Override
public int size() {
return handlers.size();
}
@Override
public boolean isEmpty() {
return handlers.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return handlers.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return handlers.containsValue(value);
}
@Override
public WriteHandler, ?> get(Object key) {
return handlers.get(key);
}
@Override
public WriteHandler, ?> put(Class key, WriteHandler, ?> value) {
throw new UnsupportedOperationException("WriteHandlerMap is read-only");
}
@Override
public WriteHandler, ?> remove(Object key) {
throw new UnsupportedOperationException("WriteHandlerMap is read-only");
}
@Override
public void putAll(Map extends Class, ? extends WriteHandler, ?>> m) {
throw new UnsupportedOperationException("WriteHandlerMap is read-only");
}
@Override
public void clear() {
throw new UnsupportedOperationException("WriteHandlerMap is read-only");
}
@Override
public Set keySet() {
return handlers.keySet();
}
@Override
public Collection> values() {
return handlers.values();
}
@Override
public Set>> entrySet() {
return handlers.entrySet();
}
@Override
public int hashCode() {
return handlers.hashCode();
}
public boolean equals(Object other) {
return (other instanceof WriteHandlerMap) && getUnderlyingMap().equals(((WriteHandlerMap)other).getUnderlyingMap());
}
public WriteHandler
© 2015 - 2025 Weber Informatics LLC | Privacy Policy