Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.obolibrary.oboformat.model;
import static org.semanticweb.owlapi.util.OWLAPIPreconditions.verifyNotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.obolibrary.obo2owl.OboInOwlCardinalityTools;
import org.obolibrary.oboformat.parser.OBOFormatConstants.OboFormatTag;
/**
* The Class Frame.
*/
public class Frame {
/**
* The clauses.
*/
protected Collection clauses = new ArrayList<>();
/**
* The id.
*/
@Nullable
protected String id;
/**
* The type.
*/
@Nullable
protected FrameType type;
/**
* Instantiates a new frame.
*/
public Frame() {
this(null);
}
/**
* Instantiates a new frame.
*
* @param type the type
*/
public Frame(@Nullable FrameType type) {
this.type = type;
}
/**
* freezing a frame signals that a frame has become quiescent, and that data structures can be
* adjusted to increase performance or reduce memory consumption. If a frozen frame is
* subsequently modified it will be thawed as necessary.
*/
public void freeze() {
if (clauses.isEmpty()) {
clauses = Collections.emptyList();
return;
}
for (Clause clause : clauses) {
clause.freeze();
}
if (clauses.size() == 1) {
clauses = Collections.singletonList(clauses.iterator().next());
return;
}
if (clauses instanceof ArrayList>) {
ArrayList> arrayList = (ArrayList>) clauses;
arrayList.trimToSize();
}
}
/**
* @return the type
*/
@Nullable
public FrameType getType() {
return type;
}
/**
* @param type the new type
*/
public void setType(FrameType type) {
this.type = type;
}
/**
* @return the id
*/
@Nullable
public String getId() {
return id;
}
/**
* @param id the new id
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the clauses
*/
public Collection getClauses() {
return clauses;
}
/**
* @param clauses the new clauses
*/
public void setClauses(Collection clauses) {
this.clauses = clauses;
}
/**
* @param tag the tag
* @return the clauses for tag
*/
public List getClauses(@Nullable String tag) {
List cls = new ArrayList<>();
if (tag == null) {
return cls;
}
for (Clause cl : clauses) {
if (tag.equals(cl.getTag())) {
cls.add(cl);
}
}
return cls;
}
/**
* @param tag the tag
* @return the clauses for tag
*/
public List getClauses(OboFormatTag tag) {
return getClauses(tag.getTag());
}
/**
* @param tag the tag
* @return null if no value set, otherwise first value
*/
@Nullable
public Clause getClause(@Nullable String tag) {
if (tag == null) {
return null;
}
for (Clause cl : clauses) {
if (tag.equals(cl.getTag())) {
return cl;
}
// TODO - throw exception if more than one clause of this type?
}
return null;
}
/**
* @param tag the tag
* @return the clause for tag
*/
@Nullable
public Clause getClause(OboFormatTag tag) {
return getClause(tag.getTag());
}
/**
* @param cl the clause
*/
public void addClause(Clause cl) {
if (!(clauses instanceof ArrayList)) {
Collection tmp = new ArrayList<>(clauses.size() + 1);
tmp.addAll(clauses);
clauses = tmp;
}
clauses.add(cl);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("Frame(");
sb.append(id);
sb.append(' ');
clauses.forEach(cl -> sb.append(cl).append(' '));
sb.append(')');
return sb.toString();
}
/**
* @param tag the tag
* @return the tag value for tag
*/
@Nullable
public Object getTagValue(String tag) {
Clause clause = getClause(tag);
if (clause == null) {
return null;
}
return clause.getValue();
}
/**
* @param tag the tag
* @return the tag value for tag
*/
@Nullable
public Object getTagValue(OboFormatTag tag) {
return getTagValue(tag.getTag());
}
/**
* @param the generic type
* @param tag the tag
* @param cls the class
* @return the tag value for tag and class
*/
@Nullable
public T getTagValue(String tag, Class cls) {
Clause clause = getClause(tag);
if (clause == null) {
return null;
}
Object value = clause.getValue();
if (value.getClass().isAssignableFrom(cls)) {
return cls.cast(value);
}
return null;
}
/**
* @param the generic type
* @param tag the tag
* @param cls the class
* @return the tag value for tag and class
*/
@Nullable
public T getTagValue(OboFormatTag tag, Class cls) {
return getTagValue(tag.getTag(), cls);
}
/**
* @param tag the tag
* @return the tag values for tag
*/
public Collection