Class PathClass
- All Implemented Interfaces:
- Serializable,- Comparable<PathClass>
The constructors in this class should never be called directly, because there should only ever be one instance of each classification - shared among all objects with that classification. This is important for checking if classifications are identical, and also assigning colors to them for display.
 To achieve this, be sure to use one of the getInstance() or fromXXX() methods each time
 you want to access or create a new PathClass instance.
 
This class has been with QuPath since the beginning, but was thoroughly revised for v0.4.0 to simplify the code, improve the validation, and make it easier to use.
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classEnum representing standard classifications.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringGet the delimiter to use between names of the PathClass when converting to a string.static final StringDefault name for a class representing "Negative" staining intensitystatic final StringDefault name for a class representing "1+" staining intensity (i.e.static final StringDefault name for a class representing "Positive" staining intensitystatic final StringDefault name for a class representing "3+" staining intensity (i.e.static final StringDefault name for a class representing "2+" staining intensity (i.e.static final PathClassDefault PathClass that represents no classification.
- 
Method SummaryModifier and TypeMethodDescriptionintThis is now equivalent tothis.toString().compareTo(o.toString()).static PathClassGet a PathClass from an array of individual names.static PathClassfromCollection(Collection<String> names) Get a PathClass using all the name elements specified in the collection, without providing a default color.static PathClassfromCollection(Collection<String> names, Integer color) Get a PathClass instance using all the name elements specified in the collection, with optional default color if a new instance is created.static PathClassfromString(String string) Get a PathClass instance from a string representation, without specifying a default color.static PathClassfromString(String string, Integer color) Get a PathClass instance from a string representation, optionally providing a default color if a new instance needs to be created.Get the 'base' class, i.e.getColor()Get the color that should be used to display objects with this classification.static PathClassgetInstance(String name) static PathClassgetInstance(String name, Integer color) Get a base PathClass instance, without any parent PathClass.static PathClassgetInstance(PathClass parent, String name, Integer color) Get a derived PathClass instance with the specified parent.getName()Get the name of this classification.static PathClassgetNegative(PathClass parentClass) Get a standalone or derived Negative classificationstatic PathClassGet the value ofNULL_CLASS, used to represent no classification.static PathClassgetOnePlus(PathClass parentClass) Get a standalone or derived 1+ classification, indicating weak positivityGet the parent classification, or null if this classification has no parent.static PathClassgetPositive(PathClass parentClass) Get a standalone or derived Positive classificationstatic PathClassgetSingleton(PathClass pathClass) Get the singleton PathClass that is equivalent to the PathClass provided.static PathClassgetThreePlus(PathClass parentClass) Get a standalone or derived 3+ classification, indicating strong positivitystatic PathClassgetTwoPlus(PathClass parentClass) Get a standalone or derived 2+ classification, indicating moderate positivitybooleanisAncestorOf(PathClass childClass) Returnstrueif this class is equal to the specified child class, or an ancestor of that class.booleanReturnstrueif#getParentClass() != null.booleanisDerivedFrom(PathClass parentClass) Returnstrueif this class, or any ancestor class, is equal to the specified parent class.booleanisValid()A PathClass is valid if its name is not null.protected ObjectCalled during deserialization to ensure that only a single instance of each PathClass exists.voidsetColor(int red, int green, int blue) Set the color as 8-bit RGB valuesvoidSet the color that should be used to display objects with this classification.toSet()Return a view of this path class as an unmodifiable set, with each element representing the name of a path class component names.toString()Create a string representation, using the specified delimiter between elements of derived PathClasses.
- 
Field Details- 
NAME_POSITIVEDefault name for a class representing "Positive" staining intensity- See Also:
 
- 
NAME_NEGATIVEDefault name for a class representing "Negative" staining intensity- See Also:
 
- 
NAME_ONE_PLUSDefault name for a class representing "1+" staining intensity (i.e. weakly positive)- See Also:
 
- 
NAME_TWO_PLUSDefault name for a class representing "2+" staining intensity (i.e. moderately positive)- See Also:
 
- 
NAME_THREE_PLUSDefault name for a class representing "3+" staining intensity (i.e. strongly positive)- See Also:
 
- 
DELIMITERGet the delimiter to use between names of the PathClass when converting to a string.
- 
NULL_CLASSDefault PathClass that represents no classification. Usually no classification is represented bynull, so this is not normally needed; however, sometimes it is required in contexts where a null is not permitted (e.g. some collections).
 
- 
- 
Method Details- 
getParentClassGet the parent classification, or null if this classification has no parent.- Returns:
 
- 
isDerivedClasspublic boolean isDerivedClass()Returnstrueif#getParentClass() != null.- Returns:
 
- 
isDerivedFromReturnstrueif this class, or any ancestor class, is equal to the specified parent class.- Parameters:
- parentClass-
- Returns:
 
- 
isAncestorOfReturnstrueif this class is equal to the specified child class, or an ancestor of that class.- Parameters:
- childClass-
- Returns:
 
- 
getBaseClassGet the 'base' class, i.e. trace back throughgetParentClass()until no parent is available.For a PathClass with no parent, this just returns itself. - Returns:
 
- 
setColorSet the color that should be used to display objects with this classification.- Parameters:
- colorRGB- color, as a packed (A)RGB value
 
- 
setColorpublic void setColor(int red, int green, int blue) Set the color as 8-bit RGB values- Parameters:
- red-
- green-
- blue-
- Since:
- v0.4.0
 
- 
getColorGet the color that should be used to display objects with this classification.- Returns:
- packed (A)RGB value representing the classification color.
 
- 
getNameGet the name of this classification. Note that this does not incorporate information from any parent classifications; to access this, usetoString()instead.- Returns:
 
- 
toString
- 
toStringCreate a string representation, using the specified delimiter between elements of derived PathClasses.- Parameters:
- delimiter-
- Returns:
 
- 
isValidpublic boolean isValid()A PathClass is valid if its name is not null.This should generally the case, but a single (invalid) PathClass with a null name can be used to indicate the absence of a classification; however, it should not be assigned to any object. Rather, objects should be assigned either a valid PathClass or null to indicate that they have no classification. - Returns:
 
- 
toSetReturn a view of this path class as an unmodifiable set, with each element representing the name of a path class component names.Important! If any path class component names are duplicates, these will (necessarily) be removed from the set. Therefore it is not guaranteed that calling fromCollection(Collection)on the output will return the samePathClassobject.var pathClass = ...; var pathClass2 = PathClass.getInstance(pathClass.toSet()); assert pathClass == pathClass2; // This may or may not be true!However the PathClassobjects should be the same if the name components are all valid and there are no duplicates (which should normally be the case).- Returns:
 
- 
compareToThis is now equivalent tothis.toString().compareTo(o.toString()).Note that in previous versions (< 0.1.2), the comparison was made based on the name only. This could result in unexpected behavior whenever comparing with equality and using derived PathClassobjects, because only the (final) name part was being compared and this could potentially result in classifications (wrongly) being considered equal (e.g. "Tumor: Positive" and "Stroma: Positive").This was most significant when working with Groovy, where ==is replaced bycompareTo.- Specified by:
- compareToin interface- Comparable<PathClass>
 
- 
getNullClassGet the value ofNULL_CLASS, used to represent no classification. In most cases,nullshould be used instead; this exists only as a representation in cases wherenullis not permitted (e.g. in some collection implementations).- Returns:
 
- 
fromStringGet a PathClass instance from a string representation, without specifying a default color.This calls fromString(String, Integer)with the second argument asnull.- Parameters:
- string-
- Returns:
 
- 
fromStringGet a PathClass instance from a string representation, optionally providing a default color if a new instance needs to be created.This ultimately calls getInstance(PathClass, String, Integer)but differs in that it accepts a string representation that may include theDELIMITER. If so, this is used to split the string into different name components that are passed tofromCollection(Collection, Integer).- Parameters:
- string- a string representation containing one or more name elements, separated by- DELIMITER
- color- a default color (optional, may be null)
- Returns:
 
- 
fromCollectionGet a PathClass using all the name elements specified in the collection, without providing a default color.- Parameters:
- names-
- Returns:
- See Also:
 
- 
fromCollectionGet a PathClass instance using all the name elements specified in the collection, with optional default color if a new instance is created. The rules are:- If the collection is empty, NULL_CLASSis returned
- If the collection has one element, this is equivalent to calling getInstance(String, Integer)
- If the collection has multiple element, this is equivalent to creating a base class from 
 the first element and deriving subclassifications by calling  getInstance(PathClass, String, Integer)for each element, in the order returned by the collection's iterator
 - Parameters:
- names-
- color-
- Returns:
- See Also:
 
- If the collection is empty, 
- 
getInstance
- 
getInstanceGet a base PathClass instance, without any parent PathClass.This is equivalent to calling getInstance(PathClass, String, Integer)with the first argument asnull.- Parameters:
- name-
- color-
- Returns:
- See Also:
 
- 
getInstanceGet a derived PathClass instance with the specified parent.This will be derived from the parent PathClass (if provided) and have the specified name, stripped to remove any leading or training whitespace. Note that the name should generally be an alphanumeric string, optionally including punctuation symbols but not including DELIMITER.The delimiter is currently a colon ":"but it is advised not to rely upon this and to avoid punctuation where possible, because the delimiter may possibly change in a future release - primarily because the choice of colon can be problematic in some cases, e.g. when using ontologies.- Parameters:
- parent- parent class (optional, may be null)
- name- name of the PathClass
- color- color to use if a new instance is created (may be null to use the default)
- Returns:
- a PathClass instance; the same instance will be returned given the same parent and name
- See Also:
- Implementation Requirements
- the color is only used if a new PathClass instance needs to be created. If a suitable instance has already been created, then that will be returned instead and the color will not be created.
 
- 
getOnePlusGet a standalone or derived 1+ classification, indicating weak positivity- Parameters:
- parentClass- parent classification (may be null)
- Returns:
 
- 
getTwoPlusGet a standalone or derived 2+ classification, indicating moderate positivity- Parameters:
- parentClass- parent classification (may be null)
- Returns:
 
- 
getThreePlusGet a standalone or derived 3+ classification, indicating strong positivity- Parameters:
- parentClass- parent classification (may be null)
- Returns:
 
- 
getNegativeGet a standalone or derived Negative classification- Parameters:
- parentClass- parent classification (may be null)
- Returns:
 
- 
getPositiveGet a standalone or derived Positive classification- Parameters:
- parentClass- parent classification (may be null)
- Returns:
 
- 
getSingletonGet the singleton PathClass that is equivalent to the PathClass provided.This is important because there should only ever be one PathClass instance for any classification - and accessing PathClasses only via the getInstance()methods here should ensure that.However, if receiving a PathClass from some other source then it is possible that the PathClass was created some other way and duplicates could emerge. Calling this method returns resolves that problem by returning the single instance that should be used. This is significant if the PathClass has been created via Java deserialization, which skips the required use of getInstance()by default.- Parameters:
- pathClass-
- Returns:
- either the input PathClass, or an equivalent that should be used
 
- 
fromArrayGet a PathClass from an array of individual names.- Parameters:
- names-
- Returns:
- See Also:
 
- 
readResolveCalled during deserialization to ensure that only a single instance of each PathClass exists. Partly addresses https://github.com/qupath/qupath/issues/1306 (during standard deserialation, but not from JSON)- Returns:
- Throws:
- ObjectStreamException
 
 
-