/** * Adds a new {@link CVTerm} to the {@link #listOfNestedCVTerms}. * <p>The listOfNestedCVTerms is initialized if necessary. * * @param cvTerm the element to add to the list * @return {@code true} (as specified by {@link java.util.Collection#add}) * @see java.util.Collection#add(Object) */ public boolean addNestedCVTerm(CVTerm cvTerm) { return getListOfNestedCVTerms().add(cvTerm); // TODO - set the parent as this }
/** * Returns the number of {@link CVTerm}s in this * {@link CVTerm}. * * @return the number of {@link CVTerm}s in this * {@link CVTerm}. */ public int getNestedCVTermCount() { return isSetListOfNestedCVTerms() ? getListOfNestedCVTerms().size() : 0; }
/** * Removes an element from the {@link #listOfNestedCVTerms}. * * @param cvTerm the element to be removed from the list. * @return {@code true} if the list contained the specified element and it was * removed. * @see java.util.List#remove(Object) */ public boolean removeNestedCVTerm(CVTerm cvTerm) { if (isSetListOfNestedCVTerms()) { return getListOfNestedCVTerms().remove(cvTerm); } return false; }
/** * Gets an element from the {@link #listOfNestedCVTerms} at the given index. * * @param i the index of the {@link CVTerm} element to get. * @return an element from the listOfNestedCVTerms at the given index. * @throws IndexOutOfBoundsException if the listOf is not set or * if the index is out of bound (index < 0 || index > list.size). */ public CVTerm getNestedCVTerm(int i) { if (!isSetListOfNestedCVTerms()) { throw new IndexOutOfBoundsException(Integer.toString(i)); } return getListOfNestedCVTerms().get(i); }
/** * Removes an element from the {@link #listOfNestedCVTerms} at the given index. * * @param i the index where to remove the {@link CVTerm}. * @return the specified element if it was successfully found and removed. * @throws IndexOutOfBoundsException if the listOf is not set or if the index is * out of bound ({@code (i < 0) || (i > listOfNestedCVTerms)}). */ public CVTerm removeNestedCVTerm(int i) { if (!isSetListOfNestedCVTerms()) { throw new IndexOutOfBoundsException(Integer.toString(i)); } return getListOfNestedCVTerms().remove(i); }
/** * Returns a list of CVTerm having the given qualifier. * * @param qualifier the qualifier * @param terms the list of CVTerm to filter * @return a list of CVTerm having the given qualifier, an empty * list is returned if no CVTerm are found. */ private List<CVTerm> filterCVTerms(Qualifier qualifier, List<CVTerm> terms) { ArrayList<CVTerm> l = new ArrayList<CVTerm>(); CVTermFilter filter = new CVTermFilter(qualifier); for (CVTerm term : terms) { if (filter.accepts(term)) { l.add(term); } if (term.getNestedCVTermCount() > 0) { l.addAll(filterCVTerms(qualifier, term.getListOfNestedCVTerms())); } } return l; }
/** * * @param currentCVTerm * @param parentNode */ private void writeURIs(CVTerm currentCVTerm, XMLNode parentNode) { if (currentCVTerm.getNestedCVTermCount() > 0) { String precedingElementName = "li"; String precedingElementNamespaceURI = Annotation.URI_RDF_SYNTAX_NS; int i = currentCVTerm.getListOfNestedCVTerms().size() - 1; for (; i >= 0; i--) { CVTerm cvterm = currentCVTerm.getNestedCVTerm(i); writeCVTerm(cvterm, parentNode, precedingElementName, precedingElementNamespaceURI); } } }
/** * Returns a list of CVTerm having the given qualifier. * * @param qualifier the qualifier * @return a list of CVTerm having the given qualifier, an empty * list is returned if no CVTerm are found. */ public List<CVTerm> filterCVTerms(Qualifier qualifier) { ArrayList<CVTerm> l = new ArrayList<CVTerm>(); CVTermFilter filter = new CVTermFilter(qualifier); for (CVTerm term : getListOfCVTerms()) { if (filter.accepts(term)) { l.add(term); } if (term.getNestedCVTermCount() > 0) { l.addAll(filterCVTerms(qualifier, term.getListOfNestedCVTerms())); } } return l; }