Class FlagSet<E extends Enum<E>>

java.lang.Object
org.apache.hadoop.fs.impl.FlagSet<E>
All Implemented Interfaces:
StreamCapabilities

public final class FlagSet<E extends Enum<E>> extends Object implements StreamCapabilities
A set of flags, constructed from a configuration option or from a string, with the semantics of ConfigurationHelper.parseEnumSet(String, String, Class, boolean) and implementing StreamCapabilities.

Thread safety: there is no synchronization on a mutable FlagSet. Once declared immutable, flags cannot be changed, so they becomes implicitly thread-safe.

  • Method Details

    • flags

      public EnumSet<E> flags()
      Get a copy of the flags.

      This is immutable.

      Returns:
      the flags.
    • isEmpty

      public boolean isEmpty()
      Probe for the FlagSet being empty.
      Returns:
      true if there are no flags set.
    • enabled

      public boolean enabled(E flag)
      Is a flag enabled?
      Parameters:
      flag - flag to check
      Returns:
      true if it is in the set of enabled flags.
    • enable

      public void enable(E flag)
      Enable a flag.
      Parameters:
      flag - flag to enable.
    • disable

      public void disable(E flag)
      Disable a flag.
      Parameters:
      flag - flag to disable
    • set

      public void set(E flag, boolean state)
      Set a flag to the chosen value.
      Parameters:
      flag - flag
      state - true to enable, false to disable.
    • hasCapability

      public boolean hasCapability(String capability)
      Is a flag enabled?
      Specified by:
      hasCapability in interface StreamCapabilities
      Parameters:
      capability - string to query the stream support for.
      Returns:
      true if the capability maps to an enum value and that value is set.
    • makeImmutable

      public void makeImmutable()
      Make immutable; no-op if already set.
    • isImmutable

      public boolean isImmutable()
      Is the FlagSet immutable?
      Returns:
      true iff the FlagSet is immutable.
    • getEnumClass

      public Class<E> getEnumClass()
      Get the enum class.
      Returns:
      the enum class.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • pathCapabilities

      public List<String> pathCapabilities()
      Generate the list of capabilities.
      Returns:
      a possibly empty list.
    • equals

      public boolean equals(Object o)
      Equality is based on the value of enumClass and prefix and the contents of the set, which must match.

      The immutability flag is not considered, nor is the namesToValues map, though as that is generated from the enumeration and prefix, it is implicitly equal if the prefix and enumClass fields are equal.

      Overrides:
      equals in class Object
      Parameters:
      o - other object
      Returns:
      true iff the equality condition is met.
    • hashCode

      public int hashCode()
      Hash code is based on the flags.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code.
    • copy

      public FlagSet<E> copy()
      Create a copy of the FlagSet.
      Returns:
      a new mutable instance with a separate copy of the flags
    • toConfigurationString

      public String toConfigurationString()
      Convert to a string which can be then set in a configuration. This is effectively a marshalled form of the flags.
      Returns:
      a comma separated list of flag names.
    • createFlagSet

      public static <E extends Enum<E>> FlagSet<E> createFlagSet(Class<E> enumClass, String prefix, EnumSet<E> flags)
      Create a FlagSet.
      Type Parameters:
      E - enum type
      Parameters:
      enumClass - class of enum
      prefix - prefix (with trailing ".") for path capabilities probe
      flags - flags
      Returns:
      a mutable FlagSet
    • createFlagSet

      @SafeVarargs public static <E extends Enum<E>> FlagSet<E> createFlagSet(Class<E> enumClass, String prefix, E... enabled)
      Create a FlagSet from a list of enum values.
      Type Parameters:
      E - enum type
      Parameters:
      enumClass - class of enum
      prefix - prefix (with trailing ".") for path capabilities probe
      enabled - varags list of flags to enable.
      Returns:
      a mutable FlagSet
    • buildFlagSet

      public static <E extends Enum<E>> FlagSet<E> buildFlagSet(Class<E> enumClass, Configuration conf, String key, boolean ignoreUnknown)
      Build a FlagSet from a comma separated list of values. Case independent. Special handling of "*" meaning: all values.
      Type Parameters:
      E - enumeration type
      Parameters:
      enumClass - class of enum
      conf - configuration
      key - key to look for
      ignoreUnknown - should unknown values raise an exception?
      Returns:
      a mutable FlagSet
      Throws:
      IllegalArgumentException - if one of the entries was unknown and ignoreUnknown is false, or there are two entries in the enum which differ only by case.