Class Semaphores

java.lang.Object
org.apache.sis.internal.system.Semaphores

public final class Semaphores extends Object
Thread-local booleans that need to be shared across different packages. Each thread has its own set of booleans. The clear(int) method must be invoked after the queryAndSet(int) method in a try ... finally block.
Since:
0.5
Version:
1.2
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    A lock for avoiding never-ending recursivity in the equals method of AbstractDerivedCRS and AbstractCoordinateOperation.
    static final int
    A flag to indicate that AbstractCoordinateOperation is querying parameters of a MathTransform enclosed in the operation.
    static final int
    A flag to indicate that a finer logging level should be used for reporting geodetic object creations.
    private int
    The bit flags.
    private static final ThreadLocal<Semaphores>
    The flags per running thread.
    static final int
    A flag to indicate that only metadata are desired and that there is no need to create costly objects.
    static final int
    A flag to indicate that empty collections should be returned as null.
    static final int
    A flag to indicate that a parameter value outside its domain of validity should not cause an exception to be thrown.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    For internal use only.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    clear(int flag)
    Clears the given flag.
    static void
    clear(int flag, boolean previous)
    Clears the given flag only if it was previously cleared.
    static boolean
    query(int flag)
    Returns true if the given flag is set.
    static boolean
    queryAndSet(int flag)
    Sets the given flag.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NULL_COLLECTION

      public static final int NULL_COLLECTION
      A flag to indicate that empty collections should be returned as null. Returning null collections is not a recommended practice, but is useful in some situations like marshalling a XML document with JAXB, when we want to omit empty XML blocks.
      See Also:
    • METADATA_ONLY

      public static final int METADATA_ONLY
      A flag to indicate that only metadata are desired and that there is no need to create costly objects. This flag is used during iteration over many coordinate operations before to select a single one by inspecting only their metadata.
      See Also:
    • CONVERSION_AND_CRS

      public static final int CONVERSION_AND_CRS
      A lock for avoiding never-ending recursivity in the equals method of AbstractDerivedCRS and AbstractCoordinateOperation. It is set to true when a comparison is in progress. This lock is necessary because AbstractDerivedCRS objects contain a conversionFromBase field, which contains a DefaultConversion.targetCRS field referencing back the AbstractDerivedCRS object.
      See Also:
    • ENCLOSED_IN_OPERATION

      public static final int ENCLOSED_IN_OPERATION
      A flag to indicate that AbstractCoordinateOperation is querying parameters of a MathTransform enclosed in the operation. This is often at the time of formatting the WKT of a "ProjectedCRS" element.
      See Also:
    • SUSPEND_PARAMETER_CHECK

      @Workaround(library="EPSG:3752", version="8.9") public static final int SUSPEND_PARAMETER_CHECK
      A flag to indicate that a parameter value outside its domain of validity should not cause an exception to be thrown. This flag is set only when creating a deprecated operation from the EPSG database. Typically the operation is deprecated precisely because it used invalid parameter values, but SIS should still be able to create those deprecated objects if a user request them.

      Example: EPSG:3752 was a Mercator (variant A) projection but set the latitude of origin to 41°S.

      See Also:
    • FINER_OBJECT_CREATION_LOGS

      public static final int FINER_OBJECT_CREATION_LOGS
      A flag to indicate that a finer logging level should be used for reporting geodetic object creations. This flag is used during operations that potentially create a large amount of CRS, for example when trying many CRS candidates in search for a CRS compliant with some criteria.
      See Also:
    • FLAGS

      private static final ThreadLocal<Semaphores> FLAGS
      The flags per running thread.
    • flags

      private int flags
      The bit flags.
  • Constructor Details

    • Semaphores

      private Semaphores()
      For internal use only.
  • Method Details

    • query

      public static boolean query(int flag)
      Returns true if the given flag is set.
      Parameters:
      flag - one of CONVERSION_AND_CRS, ENCLOSED_IN_OPERATION or other constants.
      Returns:
      true if the given flag is set.
    • queryAndSet

      public static boolean queryAndSet(int flag)
      Sets the given flag.
      Parameters:
      flag - one of CONVERSION_AND_CRS, ENCLOSED_IN_OPERATION or other constants.
      Returns:
      true if the given flag was already set.
    • clear

      public static void clear(int flag)
      Clears the given flag.
      Parameters:
      flag - one of CONVERSION_AND_CRS, ENCLOSED_IN_OPERATION or other constants.
    • clear

      public static void clear(int flag, boolean previous)
      Clears the given flag only if it was previously cleared. This is a convenience method for a common pattern with try … finally blocks.
      Parameters:
      flag - one of CONVERSION_AND_CRS, ENCLOSED_IN_OPERATION or other constants.
      previous - value returned by queryAndSet(int).