com.att.research.xacmlatt.pdp.policy.VariableMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xacml-pdp Show documentation
Show all versions of xacml-pdp Show documentation
ATT reference implementation of XACML PDP engine
/*
*
* Copyright (c) 2013,2019 AT&T Knowledge Ventures
* SPDX-License-Identifier: MIT
*/
package com.att.research.xacmlatt.pdp.policy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.att.research.xacml.util.StringUtils;
/**
* VariableMap is a collection of {@link com.att.research.xacmlatt.pdp.policy.VariableDefinition}s that are accessible by
* the variable identifier.
*
* @author car
* @version $Revision: 1.1 $
*/
public class VariableMap {
private List variableDefinitions;
private Map mapVariableDefinitions;
private void ensureVariableDefinitions() {
if (this.variableDefinitions == null) {
this.variableDefinitions = new ArrayList<>();
}
}
private void ensureMap() {
if (this.mapVariableDefinitions == null) {
this.mapVariableDefinitions = new HashMap<>();
}
}
public VariableMap() {
super();
}
/**
* Gets the VariableDefinition
with the given String
id.
*
* @param variableId the String
identifier of the VariableDefinition
to retrieve
* @return the VariableDefinition
with the given String
id or null if not found.
*/
public VariableDefinition getVariableDefinition(String variableId) {
return (this.mapVariableDefinitions == null ? null : this.mapVariableDefinitions.get(variableId));
}
/**
* Gets an Iterator
over the VariableDefinition
s in this VariableMap
* in the order they were added.
*
* @return an Iterator
over the VariableDefinition
s in this VariableMap
*/
public Iterator getVariableDefinitions() {
return (this.variableDefinitions == null ? null : this.variableDefinitions.iterator());
}
/**
* Adds the given VariableDefinition
to this VariableMap
.
*
* @param variableDefinition the VariableDefinition
to add
*/
public void add(VariableDefinition variableDefinition) {
this.ensureMap();
this.ensureVariableDefinitions();
this.variableDefinitions.add(variableDefinition);
this.mapVariableDefinitions.put(variableDefinition.getId(), variableDefinition);
}
/**
* Adds the contents of the given Collection
of VariableDefinition
s to the set of
* VariableDefinition
s in this VariableMap
>
*
* @param listVariableDefinitions the Collection
of VariableDefinition
s to add
*/
public void addVariableDefinitions(Collection listVariableDefinitions) {
for (VariableDefinition variableDefinition: listVariableDefinitions) {
this.add(variableDefinition);
}
}
/**
* Sets the VariableDefinition
s in this VariableMap
to the contents of the given
* Collection
.
*
* @param listVariableDefinitions the Collection
of VariableDefinition
to set
*/
public void setVariableDefinitions(Collection listVariableDefinitions) {
this.variableDefinitions = null;
this.mapVariableDefinitions = null;
if (listVariableDefinitions != null) {
this.addVariableDefinitions(variableDefinitions);
}
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder("{");
if (this.mapVariableDefinitions.size() > 0) {
stringBuilder.append("variableDefinitions=");
stringBuilder.append(StringUtils.toString(this.mapVariableDefinitions.values().iterator()));
}
stringBuilder.append('}');
return stringBuilder.toString();
}
}