Commit 39ea6ff1 authored by cdanger's avatar cdanger

- Improved javadoc of AttributeValue ("implementations must implement

equals and hashCode!")
- Implemented toString, equals and hashcode in PepAction,
PepActionAttributeAssignment
parent 39ec0c06
......@@ -49,7 +49,7 @@ public final class DecisionResults
{
if (toString == null)
{
toString = "Result( decision= NotApplicable, status=" + getStatus() + " )";
toString = "Result[ decision= NotApplicable, status=" + getStatus() + " ]";
}
return toString;
}
......
......@@ -20,6 +20,8 @@
*/
package org.ow2.authzforce.core.pdp.api;
import java.util.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
......@@ -34,6 +36,9 @@ public final class PepAction
private final boolean isMandatory;
private final ImmutableList<PepActionAttributeAssignment<?>> attAssignments;
private transient volatile int hashCode = 0;
private transient volatile String toString = null;
/**
* Constructor
*
......@@ -79,4 +84,43 @@ public final class PepAction
return attAssignments;
}
@Override
public int hashCode()
{
if (hashCode == 0)
{
hashCode = Objects.hash(isMandatory, actionId, attAssignments);
}
return hashCode;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (!(obj instanceof PepAction))
{
return false;
}
final PepAction other = (PepAction) obj;
return this.isMandatory == other.isMandatory && this.actionId.equals(other.actionId) && this.attAssignments.equals(other.attAssignments);
}
@Override
public String toString()
{
if (toString == null)
{
toString = "PepAction [actionId=" + actionId + ", isMandatory=" + isMandatory + ", attAssignments=" + attAssignments + "]";
}
return toString;
}
}
......@@ -17,6 +17,7 @@
*/
package org.ow2.authzforce.core.pdp.api;
import java.util.Objects;
import java.util.Optional;
import org.ow2.authzforce.core.pdp.api.value.AttributeValue;
......@@ -37,6 +38,9 @@ public final class PepActionAttributeAssignment<AV extends AttributeValue>
private final Datatype<AV> datatype;
private final AV value;
private transient volatile int hashCode = 0;
private transient volatile String toString = null;
/**
* Default constructor
*
......@@ -101,4 +105,43 @@ public final class PepActionAttributeAssignment<AV extends AttributeValue>
return value;
}
@Override
public int hashCode()
{
if (hashCode == 0)
{
hashCode = Objects.hash(this.attId, this.category, this.issuer, this.datatype, this.value);
}
return hashCode;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (!(obj instanceof PepActionAttributeAssignment))
{
return false;
}
final PepActionAttributeAssignment<?> other = (PepActionAttributeAssignment<?>) obj;
return this.attId.equals(other.attId) && this.category.equals(other.category) && this.issuer.equals(other.issuer) && this.datatype.equals(other.datatype) && this.value.equals(other.value);
}
@Override
public String toString()
{
if (toString == null)
{
toString = "PepActionAttributeAssignment [attId=" + attId + ", category=" + category.orElse(null) + ", issuer=" + issuer.orElse(null) + ", datatype=" + datatype + ", value=" + value + "]";
}
return toString;
}
}
......@@ -29,7 +29,7 @@ import javax.xml.namespace.QName;
* of all standard XACML primitive datatypes extend this. Contrary to {@link PrimitiveValue}, this does not represent Functions which are not attribute values. If you want to provide a new type of
* AttributeValue, i.e. new datatype, extend {@link AttributeValueFactory} to provide a factory for it.
*
* https://docs.oracle.com/javaee/7/api/javax/xml/bind/annotation/XmlMixed.html
* <b>All implementations must implement/override {@link #equals(Object)} and {@link #hashCode()} properly.</b>
*/
public interface AttributeValue extends PrimitiveValue
{
......
......@@ -37,7 +37,7 @@ import net.sf.saxon.s9api.XPathCompiler;
* Superclass of all "simple" Attribute Values, including values of any XACML standard datatype; "simple" as in "simple type" or "simple content" of XML schema. This means the value can be represented
* as character data only (String) with no sub-elements (no XML elements) - but with possibly extra XML attributes - as opposed to structured values that have sub-elements. In this definition, all
* XACML core standard primitive types are "simple" types, and their corresponding Java classes extend this class.
*
*
* @param <V>
* underlying Java value type
*
......@@ -122,14 +122,16 @@ public abstract class SimpleValue<V> implements AttributeValue
if (content == null)
{
content0 = "";
} else
}
else
{
final Iterator<Serializable> contentIterator = content.iterator();
if (!contentIterator.hasNext())
{
content0 = "";
} else
}
else
{
content0 = contentIterator.next();
if (contentIterator.hasNext())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment