Class Facets


  • public class Facets
    extends java.lang.Object
    Utility methods for working with facets.
    See Also:
    Faceted
    • Constructor Summary

      Constructors 
      Constructor Description
      Facets()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T asFacet​(java.lang.Class<T> facetType, Faceted subject)
      Returns a facet of the given subject if supported, returning null otherwise.
      static <T> T asFacet​(java.lang.Class<T> facetType, java.lang.Object subject)
      Returns a facet of the given subject if supported, returning null otherwise.
      static <T> T assumeFacet​(java.lang.Class<T> facetType, Faceted subject)
      Returns a facet of the given subject if supported, throwing an exception otherwise.
      static <T> T assumeFacet​(java.lang.Class<T> facetType, java.lang.Object subject)
      Returns a facet of the given subject if supported, throwing an exception otherwise.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Facets

        public Facets()
    • Method Detail

      • asFacet

        public static <T> T asFacet​(java.lang.Class<T> facetType,
                                    Faceted subject)
        Returns a facet of the given subject if supported, returning null otherwise.

        This does not attempt to cast the subject to the requested type, since the Faceted interface declares the intent to control the conversion.

        Returns:
        the requested facet, or null if subject is null or if subject doesn't support the requested facet type.
      • asFacet

        public static <T> T asFacet​(java.lang.Class<T> facetType,
                                    java.lang.Object subject)
        Returns a facet of the given subject if supported, returning null otherwise.

        If the subject implements Faceted, then this conversion is delegated to Faceted.asFacet(Class). Otherwise, a simple cast of the subject is attempted.

        Returns:
        the requested facet, or null if subject is null or if subject doesn't support the requested facet type.
      • assumeFacet

        public static <T> T assumeFacet​(java.lang.Class<T> facetType,
                                        Faceted subject)
        Returns a facet of the given subject if supported, throwing an exception otherwise.

        This does not attempt to cast the subject to the requested type, since the Faceted interface declares the intent to control the conversion.

        Returns:
        not null.
        Throws:
        UnsupportedFacetException - if subject is null or if the subject doesn't support the requested facet type.
      • assumeFacet

        public static <T> T assumeFacet​(java.lang.Class<T> facetType,
                                        java.lang.Object subject)
        Returns a facet of the given subject if supported, throwing an exception otherwise.

        If the subject implements Faceted, then this conversion is delegated to Faceted.asFacet(Class). Otherwise, a simple cast of the subject is attempted.

        Returns:
        not null.
        Throws:
        UnsupportedFacetException - if subject is null or if the subject doesn't support the requested facet type.