org.databene.commons.collection.OrderedNameMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of databene-commons Show documentation
Show all versions of databene-commons Show documentation
'databene commons' is an open source Java library by Volker Bergmann.
It provides extensions to the Java core library by utility classes, abstract concepts
and concrete implementations.
The newest version!
/*
* Copyright (C) 2004-2015 Volker Bergmann ([email protected]).
* 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 org.databene.commons.collection;
import java.util.List;
import java.util.Map;
import org.databene.commons.OrderedMap;
/**
* A map that assigns names to Objects and keeps entries
* in the order in which they were inserted.
* Created at 14.04.2008 09:49:34
* @param the type of the collection's elements
* @since 0.5.2
* @author Volker Bergmann
*/
public class OrderedNameMap extends MapProxy, String, E> {
/** caseSupport setting which respects capitalization */
private static final int CASE_SENSITIVE = 0;
/** caseSupport setting which preserves capitalization for stored entries but */
private static final int CASE_INSENSITIVE = 1;
private static final int CASE_IGNORANT = 2;
private int caseSupport;
// constructors + factory methods ----------------------------------------------------------------------------------
public OrderedNameMap() {
this(CASE_SENSITIVE);
}
public OrderedNameMap(int caseSupport) {
super(OrderedNameMap.createRealMap(caseSupport));
this.caseSupport = caseSupport;
}
public OrderedNameMap(OrderedNameMap that) {
super(OrderedNameMap.createRealMap(that.caseSupport));
this.caseSupport = that.caseSupport;
putAll(that);
}
private static OrderedMap createRealMap(int caseSupport) {
switch (caseSupport) {
case CASE_SENSITIVE: return new CaseSensitiveOrderedNameMap();
case CASE_INSENSITIVE: return new CaseInsensitiveOrderedNameMap();
case CASE_IGNORANT: return new CaseIgnorantOrderedNameMap();
default: throw new IllegalArgumentException("Illegal caseSupport setting: " + caseSupport);
}
}
public static OrderedNameMap createCaseSensitiveMap() {
return new OrderedNameMap(CASE_SENSITIVE);
}
public static OrderedNameMap createCaseInsensitiveMap() {
return new OrderedNameMap(CASE_INSENSITIVE);
}
public static OrderedNameMap createCaseIgnorantMap() {
return new OrderedNameMap(CASE_IGNORANT);
}
public E valueAt(int index) {
return realMap.valueAt(index);
}
public int indexOfValue(E value) {
return realMap.indexOfValue(value);
}
public Map.Entry getEntry(String key) {
return realMap.getEntry(key);
}
public boolean equalsIgnoreOrder(Map that) {
return realMap.equalsIgnoreOrder(that);
}
@Override
public List values() {
return realMap.values();
}
}