![JAR search and dependency download from the Maven repository](/logo.png)
org.protempa.proposition.value.OrdinalValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of protempa-framework Show documentation
Show all versions of protempa-framework Show documentation
Protempa Framework is the core of Protempa.
/*
* #%L
* Protempa Framework
* %%
* Copyright (C) 2012 - 2013 Emory University
* %%
* 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.
* #L%
*/
package org.protempa.proposition.value;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.text.Format;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.builder.ToStringBuilder;
/**
* Represents ordinal string values. This currently is non-functional.
*
* @author Andrew Post
*/
public final class OrdinalValue implements OrderedValue, Serializable {
private static final long serialVersionUID = -1605459658420554439L;
private String val;
private int index;
private transient volatile int hashCode;
/**
* Creates an ordinal value of a type with allowed values.
*
* @param value
* a {@link String}.
* @param sortedAllowedValues
* the allowed values {@link List 0) {
return ValueComparator.GREATER_THAN;
} else {
return ValueComparator.LESS_THAN;
}
case VALUELIST:
ValueList> vl = (ValueList>) o;
return equals(vl) ? ValueComparator.EQUAL_TO
: ValueComparator.NOT_EQUAL_TO;
default:
return ValueComparator.NOT_EQUAL_TO;
}
}
@Override
public int hashCode() {
int hash = 3;
hash = 67 * hash + Objects.hashCode(this.val);
hash = 67 * hash + this.index;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final OrdinalValue other = (OrdinalValue) obj;
if (!Objects.equals(this.val, other.val)) {
return false;
}
if (this.index != other.index) {
return false;
}
return true;
}
@Override
public void accept(ValueVisitor valueVisitor) {
if (valueVisitor == null) {
throw new IllegalArgumentException("valueVisitor cannot be null");
}
valueVisitor.visit(this);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
private void writeObject(ObjectOutputStream s) throws IOException {
s.writeObject(this.val);
s.writeInt(this.index);
}
private void readObject(ObjectInputStream s) throws IOException,
ClassNotFoundException {
this.val = (String) s.readObject();
this.index = s.readInt();
}
@Override
public OrdinalValueBuilder asBuilder() {
return new OrdinalValueBuilder(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy