/** * 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))); } } }
@Override public int hashCode() { final int prime = 821; int hashCode = super.hashCode(); if (isSetQualifier()) { hashCode += prime * getQualifier().hashCode(); } for (String uri : getResources()) { hashCode += prime * uri.hashCode(); } return hashCode; }
/** * Creates a new {@link CVTerm} element and adds it to the * {@link #listOfNestedCVTerms} list. * * @return the newly created {@link CVTerm} element, which is the last * element in the {@link #listOfNestedCVTerms}. */ public CVTerm createNestedCVTerm() { CVTerm cvTerm = new CVTerm(); addNestedCVTerm(cvTerm); return cvTerm; }
/** * Unsets the qualifier type if it is set. * */ public void unsetQualifierType() { if (isSetQualifierType()) { firePropertyChange(TreeNodeChangeEvent.qualifier, type, null); type = null; } }
@Override public int getChildCount() { // TODO - include NestedCVTerms in the tree so that we get them when doing recursive filters on SBase. int childCount = getResources().size(); if (getNestedCVTermCount() > 0) { childCount++; } return childCount; }
/** * Creates a new {@link CVTerm} with the given {@link Type} and * {@link Qualifier} pointing to all given resources. * * @param type * @param qualifier * @param resources * @throws IllegalArgumentException * if the combination of the given type and qualifier is not * possible or if the given resources are invalid. */ public CVTerm(Type type, Qualifier qualifier, String... resources) { this(); setQualifierType(type); if (isBiologicalQualifier()) { setBiologicalQualifierType(qualifier); } else if (isModelQualifier()) { setModelQualifierType(qualifier); } else { throw new IllegalArgumentException(MessageFormat.format( resourceBundle.getString("CVTerm.INVALID_TYPE_AND_QUALIFIER_COMBINATION_MSG"), type, qualifier)); } for (String resource : resources) { addResource(resource); } }
CVTerm cvt = (CVTerm) o; if (qualifier != null) { if (cvt.isBiologicalQualifier() && (cvt.getBiologicalQualifierType() == qualifier)) { return pattern != null ? cvt.filterResources(pattern) .size() > 0 : true; } else if (cvt.isModelQualifier() && cvt.getModelQualifierType() == qualifier) { return pattern != null ? cvt.filterResources(pattern) .size() > 0 : true; return cvt.filterResources(pattern).size() > 0;
String cvtermPrefix = "bqbiol"; if (cvterm.isModelQualifier()) String qualifierXMLName = cvterm.getQualifier().getElementNameEquivalent(); if (cvterm.getQualifier().equals(Qualifier.BQB_UNKNOWN) || cvterm.getQualifier().equals(Qualifier.BQM_UNKNOWN)) qualifierXMLName = cvterm.getUnknownQualifierName(); cvtermURI, cvtermPrefix, cvterm.getUserObject(CUSTOM_RDF)); for (String uri : cvterm.getResources())
private Map<Qualifier, Set<String>> extractRDFAnnotation(SBase element) { EnumMap<Qualifier, Set<String>> rdfMap = new EnumMap<Qualifier, Set<String>>(Qualifier.class); if (element.isSetAnnotation()) { Annotation ann = element.getAnnotation(); for (CVTerm cvterm : ann.getListOfCVTerms()) { rdfMap.put(cvterm.getBiologicalQualifierType(), new HashSet<String>(cvterm.getResources())); } } return rdfMap; }
@Override public boolean equals(Object object) { boolean equals = super.equals(object); if (equals) { CVTerm t = (CVTerm) object; equals &= t.getQualifierType() == getQualifierType(); equals &= (t.getBiologicalQualifierType() == qualifier) || (t.getModelQualifierType() == qualifier); } return equals; }
/** * Guesses the {@link Type} argument and sets the {@link Qualifier} * attribute appropriately. Then it adds all the given resources. * * @param qualifier * @param resources */ public CVTerm(Qualifier qualifier, String... resources) { this(); if (qualifier.isBiologicalQualifier()) { setQualifierType(Type.BIOLOGICAL_QUALIFIER); setBiologicalQualifierType(qualifier); } else { setQualifierType(Type.MODEL_QUALIFIER); setModelQualifierType(qualifier); } addResources(resources); }
CVTerm cvTerm = new CVTerm(CVTerm.Type.MODEL_QUALIFIER, qualifier, resources.toArray(new String[resources.size()])); cvTerm.putUserObject(JSBML.READING_IN_PROGRESS, Boolean.TRUE); cvTerm.setUnknownQualifierName(bqmodelNode.getName()); ((SBase) contextSBase).addCVTerm(cvTerm); } else if (contextSBase instanceof CVTerm) { ((CVTerm) contextSBase).addNestedCVTerm(cvTerm); cvTerm.putUserObject(CUSTOM_RDF, bqmodelNode); bqmodelNode.removeFromParent(); CVTerm cvTerm = new CVTerm(CVTerm.Type.BIOLOGICAL_QUALIFIER, qualifier, resources.toArray(new String[resources.size()])); cvTerm.putUserObject(JSBML.READING_IN_PROGRESS, Boolean.TRUE); cvTerm.setUnknownQualifierName(bqbiolNode.getName()); ((SBase) contextSBase).addCVTerm(cvTerm); } else if (contextSBase instanceof CVTerm) { ((CVTerm) contextSBase).addNestedCVTerm(cvTerm); cvTerm.putUserObject(CUSTOM_RDF, bqbiolNode); bqbiolNode.removeFromParent();
/** * Returns true if the {@link Qualifier} is set and is of type {@link Type#BIOLOGICAL_QUALIFIER} * * @return true if the {@link Qualifier} is set and is of type {@link Type#BIOLOGICAL_QUALIFIER}, false otherwise. */ public boolean isSetBiologicalQualifierType() { return getBiologicalQualifierType() != null; }
/** * 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; } }
/** * Unsets the biological qualifier if it is set and of the type {@link Type#BIOLOGICAL_QUALIFIER} * * @see #unsetQualifier() */ public void unsetBiologicalQualifierType() { if (type == Type.BIOLOGICAL_QUALIFIER) { firePropertyChange(TreeNodeChangeEvent.qualifier, qualifier, null); qualifier = null; } }
setQualifier(Qualifier.getBiologicalQualifierFor(miriam.getName())); } else { setQualifier(Qualifier.getModelQualifierFor(miriam.getName())); XMLAttributes attributes = child.getAttributes(); for (int i = 0; i < attributes.size(); i++) { addResource(attributes.getValue(i));
/** * Returns a list of resource URIs that contain the given pattern(s). This is * useful to obtain, e.g., all KEGG resources this term points to. * * @param patterns * an arbitrary number of patterns, e.g., * {@code http://idenifiers.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 {@link CVTerm}. * @see Pattern * @see Matcher#find() * */ public List<String> filterResources(String... patterns) { Pattern pattern; Pattern[] patternList = new Pattern[patterns.length]; for (int i = 0; i < patternList.length; i++) { pattern = Pattern.compile(patterns[i]); patternList[i] = pattern; } return filterResources(patternList); }
/** * Adds list of resources to the {@link CVTerm}. * * @param resources a list of strings representing the resources; e.g., * 'http://identifiers.org/kegg.reaction/R00351' * @return {@code true} if all the resources have been added properly. */ public boolean addResources(String... resources) { boolean success = true; for (String resource : resources) { success &= addResource(resource); } return success; }
@Override public CVTerm clone() { return new CVTerm(this); }
/** * * @param elementName * @param attributeName * @param prefix * @param value * @return */ public boolean readAttribute(String elementName, String attributeName, String prefix, String value) { // TODO - remove this method if not used if (elementName.equals("li")) { if (attributeName.equals("resource")) { addResourceURI(value); return true; } } return false; }