com.nutanix.dp1.dat.models.DatAbstractBoundedMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dataprotection-java-client Show documentation
Show all versions of dataprotection-java-client Show documentation
Business Continuity with full spectrum of Disaster Recovery and Backup solution. Spanning across Single PC, Cross AZ, MultiSite. Configuration of Recovery points, Protection policies, Recovery Plans. Execution and monitoring of back up and recovery orchestrations on OnPrem as well as Cloud.
The newest version!
package com.nutanix.dp1.dat.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@SuppressWarnings({"unused", "SameParameterValue"})
@Slf4j
@Data
public abstract class DatAbstractBoundedMap {
@Setter(AccessLevel.NONE)
@Getter(AccessLevel.NONE)
protected Map boundedMap;
@JsonIgnore
protected final Class valueClass;
@JsonIgnore
@Setter(AccessLevel.NONE)
@Getter(AccessLevel.NONE)
protected Map unknownKeysMap = new LinkedHashMap<>();
protected DatAbstractBoundedMap(Class valueClass) {
this.valueClass = valueClass;
}
public T get(String key) {
if(key == null || boundedMap == null || !boundedMap.containsKey(key)) {
log.debug("Null or invalid key {} ", key);
throw new IllegalArgumentException("key:" + key + " not recognized");
}
return boundedMap.get(key);
}
public void put(String key, T value) {
if(boundedMap == null) {
throw new IllegalStateException("BoundedMap is not initialized");
}
if(key == null) {
throw new IllegalArgumentException("Null key is not supported");
}
if(!boundedMap.containsKey(key)) {
log.debug("Putting unrecognized key {} into unknown map", key);
unknownKeysMap.put(key, value);
return;
}
boundedMap.replace(key, value);
}
@JsonIgnore
public Set getKeys() {
return boundedMap.keySet();
}
protected final void init(List allowedKeys, T defaultValue) {
if(boundedMap == null) {
boundedMap = new LinkedHashMap<>();
allowedKeys.forEach(k -> boundedMap.put(k, defaultValue));
}
}
}