/** * Returns the number of resources for this {@link CVTerm}. * * @return the number of resources for this {@link CVTerm}. * @libsbml.deprecated use {@link #getResourceCount()} */ public int getNumResources() { return getResourceCount(); }
/** * Adds a resource to the {@link CVTerm}. * * <p>Same method a {@link #addResourceURI(String)} * * @param urn * string representing the resource; e.g., * 'http://identifiers.org/kegg.reaction/R00351' * @return {@code true} as specified in {@link Collection#add(Object)} */ public boolean addResource(String urn) { try { return addResource(getResourceCount(), urn); } catch (Throwable t) { return false; } }
@Override public TreeNode getChildAt(int childIndex) { if (childIndex < getResourceCount()) { return new TreeNodeAdapter(getResourceURI(childIndex), this); } else if (childIndex == getResourceCount()) { return new TreeNodeAdapter(listOfNestedCVTerms, this); } else { throw new IndexOutOfBoundsException(Integer.toString(childIndex)); } }
/** * Returns a list of resource URIs that contain the given {@link Pattern}(s). This is * useful to obtain, e.g., all KEGG resources this term points to. * * @param patterns * an arbitrary number of {@link Pattern}(s), e.g., * {@code http://identifiers.org/kegg.reaction/R.*}, {@code .*kegg.*} or just {@code kegg} that * are matched to all resources using an OR-operation, i.e., * if just one of the patterns matches a resource, this resource will * appear in the returned list. * @return A list of all resources that contain the given pattern. This list * can be empty, but never {@code null}. The order of the resources * in that list will be identical to the order in this term. * @see Pattern * @see Matcher#find() */ public List<String> filterResources(Pattern... patterns) { List<String> selectedResources = new ArrayList<String>(); for (int i = 0; i < getResourceCount(); i++) { String resource = getResourceURI(i); for (Pattern pattern : patterns) { Matcher matcher = pattern.matcher(resource); if (matcher.find()) { selectedResources.add(resource); break; } } } return selectedResources; }
/** * Creates a {@link CVTerm} instance from a given {@link CVTerm}. * * @param term the {@link CVTerm} to clone */ public CVTerm(CVTerm term) { super(term); type = term.getQualifierType(); switch (type) { case MODEL_QUALIFIER: qualifier = term.getModelQualifierType(); break; case BIOLOGICAL_QUALIFIER: qualifier = term.getBiologicalQualifierType(); break; default: // UNKNOWN qualifier = null; break; } resourceURIs = new ArrayList<String>(); for (int i = 0; i < term.getResourceCount(); i++) { String resource = term.getResourceURI(i); if (resource != null) { resourceURIs.add(new String(term.getResourceURI(i))); } } }
/** * Checks if the {@link Annotation} is initialized. * * <p>An {@link Annotation} is initialized if * at least one of the following is true: * <ul> * <li> there is some non RDF annotation * <li> one or more {@link CVTerm} are defined * <li> there is an history defined. * </ul> * * @return {@code true} if the Annotation is initialized */ public boolean isSetAnnotation() { if ((getNonRDFannotation() == null) && getListOfCVTerms().isEmpty() && !isSetHistory()) { return false; } else if ((getNonRDFannotation() == null) && !isSetHistory() && !getListOfCVTerms().isEmpty()) { for (int i = 0; i < getListOfCVTerms().size(); i++) { if ((getCVTerm(i) != null) && getCVTerm(i).getResourceCount() > 0) { return true; } } } return true; }
/** * Writes all the MIRIAM annotations of the {@link CVTerm} in 'buffer' * * @param indent * @param buffer */ public void toXML(String indent, StringBuffer buffer) { StringTools.append(buffer, "<", type.getElementNameEquivalent(), ":", getQualifier().getElementNameEquivalent(), ">\n", indent, "<rdf:Bag>\n"); if (resourceURIs != null) { for (int i = 0; i < getResourceCount(); i++) { StringTools.append(buffer, indent, indent, "<rdf:li rdf:resource=\"", getResourceURI(i), "\"/>\n"); } } StringTools.append(buffer, indent, "</rdf:Bag>\n", "</", type.getElementNameEquivalent(), ":", getQualifier().getElementNameEquivalent(), ">\n"); }