com.connectifex.polymer.mdl.shared.generated.types.DmcTypePlasticPatternREFMAP Maven / Gradle / Ivy
// Copyright 2020 connectifex
//
// 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.connectifex.polymer.mdl.shared.generated.types;
import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.Iterator;
import org.dmd.dmc.DmcAttribute;
import org.dmd.dmc.DmcAttributeInfo;
import org.dmd.dmc.DmcValueException;
import org.dmd.dmc.DmcMappedAttributeIF;
import org.dmd.dms.generated.enums.ValueTypeEnum;
import org.dmd.dmc.types.DefinitionName; // key type import
/**
* The DmcTypePlasticPatternREFMAP provides storage for a map of PlasticPatternREF
*
* This code was auto-generated and shouldn't be altered manually!
* Generated from: org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3044)
* Called from: org.dmd.dms.util.DmoTypeFormatter.dumpNamedREF(DmoTypeFormatter.java:544)
*/
@SuppressWarnings("serial")
// public class DmcTypePlasticPatternREFMAP extends DmcTypePlasticPatternREF {
public class DmcTypePlasticPatternREFMAP extends DmcTypePlasticPatternREF implements Serializable {
private final static Iterator emptyList = (new HashMap()).values().iterator();
protected Map value;
public DmcTypePlasticPatternREFMAP(){
value = null;
}
public DmcTypePlasticPatternREFMAP(DmcAttributeInfo ai){
super(ai);
initValue();
}
void initValue(){
if (getAttributeInfo().valueType == ValueTypeEnum.HASHMAPPED)
value = new HashMap();
else
value = new TreeMap();
}
public DefinitionName firstKey(){
if (getAttributeInfo().valueType == ValueTypeEnum.TREEMAPPED){
if (value == null)
return(null);
TreeMap map = (TreeMap)value;
return(map.firstKey());
}
throw(new IllegalStateException("Attribute " + getAttributeInfo().name + " is HASHMAPPED and doesn't support firstKey()"));
}
@Override
public DmcTypePlasticPatternREFMAP getNew(){
return(new DmcTypePlasticPatternREFMAP(getAttributeInfo()));
}
@Override
// org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3101)
public DmcAttribute cloneIt(){
synchronized(this){
DmcTypePlasticPatternREFMAP rc = getNew();
if (value == null)
return(rc);
for(PlasticPatternREF val: value.values())
try {
rc.add(val);
} catch (DmcValueException e) {
throw(new IllegalStateException("typeCheck() should never fail here!",e));
}
return(rc);
}
}
@Override
// org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3121)
public PlasticPatternREF add(Object v) throws DmcValueException {
synchronized(this){
PlasticPatternREF newval = typeCheck(v);
if (value == null)
initValue();
DefinitionName key = (DefinitionName)((DmcMappedAttributeIF)newval).getKey();
PlasticPatternREF oldval = value.put(key,newval);
if (oldval != null){
// We had a value with this key, ensure that the value actually changed
if (oldval.valuesAreEqual(newval))
newval = null;
}
return(newval);
}
}
@Override
// org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3142)
public PlasticPatternREF del(Object key){
synchronized(this){
if (value == null)
return(null);
if (key instanceof DefinitionName)
return(value.remove(key));
else
throw(new IllegalStateException("Incompatible key type: " + key.getClass().getName() + " passed to del():" + getName()));
}
}
@Override
// org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3158)
public Iterator getMV(){
synchronized(this){
if (value == null)
return(emptyList);
Map clone = null;
if (getAttributeInfo().valueType == ValueTypeEnum.HASHMAPPED)
clone = new HashMap(value);
else
clone = new TreeMap(value);
return(clone.values().iterator());
}
}
// org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3175)
public Map getMVCopy(){
synchronized(this){
Map clone = null;
if (getAttributeInfo().valueType == ValueTypeEnum.HASHMAPPED){
if (value == null)
clone = new HashMap();
else
clone = new HashMap(value);
}
else{
if (value == null)
clone = new TreeMap();
else
clone = new TreeMap(value);
}
return(clone);
}
}
// org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3196)
@Override
public int getMVSize(){
synchronized(this){
if (value == null)
return(0);
return(value.size());
}
}
@Override
// org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3208)
public PlasticPatternREF getByKey(Object key){
synchronized(this){
if (value == null)
return(null);
if (key instanceof DefinitionName)
return(value.get((DefinitionName) key));
else
throw(new IllegalStateException("Incompatible type: " + key.getClass().getName() + " passed to del():" + getName()));
}
}
@Override
// org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3223)
public boolean contains(Object v){
synchronized(this){
if (value == null)
return(false);
try {
PlasticPatternREF val = typeCheck(v);
return(value.containsValue(val));
} catch (DmcValueException e) {
return(false);
}
}
}
@Override
// org.dmd.dms.util.GenUtility.dumpMAPType(GenUtility.java:3240)
public boolean containsKey(Object key){
synchronized(this){
if (value == null)
return(false);
if (key instanceof DefinitionName)
return(value.containsKey(key));
return(false);
}
}
}