Package org.apache.hadoop.fs.impl
Class FlagSet<E extends Enum<E>>
java.lang.Object
org.apache.hadoop.fs.impl.FlagSet<E>
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.hadoop.fs.StreamCapabilities
StreamCapabilities.StreamCapability -
Field Summary
Fields inherited from interface org.apache.hadoop.fs.StreamCapabilities
ABORTABLE_STREAM, DROPBEHIND, HFLUSH, HSYNC, IOSTATISTICS, IOSTATISTICS_CONTEXT, PREADBYTEBUFFER, READAHEAD, READBYTEBUFFER, UNBUFFER, VECTOREDIO, VECTOREDIO_BUFFERS_SLICED -
Method Summary
Modifier and TypeMethodDescriptionbuildFlagSet(Class<E> enumClass, Configuration conf, String key, boolean ignoreUnknown) Build a FlagSet from a comma separated list of values.copy()Create a copy of the FlagSet.createFlagSet(Class<E> enumClass, String prefix, E... enabled) Create a FlagSet from a list of enum values.createFlagSet(Class<E> enumClass, String prefix, EnumSet<E> flags) Create a FlagSet.voidDisable a flag.voidEnable a flag.booleanIs a flag enabled?booleanEquality is based on the value ofenumClassandprefixand the contents of the set, which must match.flags()Get a copy of the flags.Get the enum class.booleanhasCapability(String capability) Is a flag enabled?inthashCode()Hash code is based on the flags.booleanisEmpty()Probe for the FlagSet being empty.booleanIs the FlagSet immutable?voidMake immutable; no-op if already set.Generate the list of capabilities.voidSet a flag to the chosen value.Convert to a string which can be then set in a configuration.toString()
-
Method Details
-
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
Is a flag enabled?- Parameters:
flag- flag to check- Returns:
- true if it is in the set of enabled flags.
-
enable
Enable a flag.- Parameters:
flag- flag to enable.
-
disable
Disable a flag.- Parameters:
flag- flag to disable
-
set
Set a flag to the chosen value.- Parameters:
flag- flagstate- true to enable, false to disable.
-
hasCapability
Is a flag enabled?- Specified by:
hasCapabilityin interfaceStreamCapabilities- 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
Get the enum class.- Returns:
- the enum class.
-
toString
-
pathCapabilities
Generate the list of capabilities.- Returns:
- a possibly empty list.
-
equals
Equality is based on the value ofenumClassandprefixand the contents of the set, which must match.The immutability flag is not considered, nor is the
namesToValuesmap, though as that is generated from the enumeration and prefix, it is implicitly equal if the prefix and enumClass fields are equal. -
hashCode
public int hashCode()Hash code is based on the flags. -
copy
Create a copy of the FlagSet.- Returns:
- a new mutable instance with a separate copy of the flags
-
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 enumprefix- prefix (with trailing ".") for path capabilities probeflags- 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 enumprefix- prefix (with trailing ".") for path capabilities probeenabled- 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 enumconf- configurationkey- key to look forignoreUnknown- 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.
-