/**@class java.util.stream.StreamOpFlag @extends java.lang.Enum Flags corresponding to characteristics of streams and operations. Flags are utilized by the stream framework to control, specialize or optimize computation. <p> Stream flags may be used to describe characteristics of several different entities associated with streams: stream sources, intermediate operations, and terminal operations. Not all stream flags are meaningful for all entities; the following table summarizes which flags are meaningful in what contexts: <div> <table> <caption>Type Characteristics</caption> <thead class="tableSubHeadingColor"> <tr> <th colspan="2"> </th> <th>{@code DISTINCT}</th> <th>{@code SORTED}</th> <th>{@code ORDERED}</th> <th>{@code SIZED}</th> <th>{@code SHORT_CIRCUIT}</th> </tr> </thead> <tbody> <tr> <th colspan="2" class="tableSubHeadingColor">Stream source</th> <td>Y</td> <td>Y</td> <td>Y</td> <td>Y</td> <td>N</td> </tr> <tr> <th colspan="2" class="tableSubHeadingColor">Intermediate operation</th> <td>PCI</td> <td>PCI</td> <td>PCI</td> <td>PC</td> <td>PI</td> </tr> <tr> <th colspan="2" class="tableSubHeadingColor">Terminal operation</th> <td>N</td> <td>N</td> <td>PC</td> <td>N</td> <td>PI</td> </tr> </tbody> <tfoot> <tr> <th class="tableSubHeadingColor" colspan="2">Legend</th> <th colspan="6" rowspan="7"> </th> </tr> <tr> <th class="tableSubHeadingColor">Flag</th> <th class="tableSubHeadingColor">Meaning</th> <th colspan="6"></th> </tr> <tr><td>Y</td><td>Allowed</td></tr> <tr><td>N</td><td>Invalid</td></tr> <tr><td>P</td><td>Preserves</td></tr> <tr><td>C</td><td>Clears</td></tr> <tr><td>I</td><td>Injects</td></tr> </tfoot> </table> </div> <p>In the above table, "PCI" means "may preserve, clear, or inject"; "PC" means "may preserve or clear", "PI" means "may preserve or inject", and "N" means "not valid". <p>Stream flags are represented by unioned bit sets, so that a single word may describe all the characteristics of a given stream entity, and that, for example, the flags for a stream source can be efficiently combined with the flags for later operations on that stream. <p>The bit masks {@link #STREAM_MASK}, {@link #OP_MASK}, and {@link #TERMINAL_OP_MASK} can be ANDed with a bit set of stream flags to produce a mask containing only the valid flags for that entity type. <p>When describing a stream source, one only need describe what characteristics that stream has; when describing a stream operation, one need describe whether the operation preserves, injects, or clears that characteristic. Accordingly, two bits are used for each flag, so as to allow representing not only the presence of of a characteristic, but how an operation modifies that characteristic. There are two common forms in which flag bits are combined into an {@code int} bit set. <em>Stream flags</em> are a unioned bit set constructed by ORing the enum characteristic values of {@link #set}() (or, more commonly, ORing the corresponding static named constants prefixed with {@code IS_}). <em>Operation flags</em> are a unioned bit set constructed by ORing the enum characteristic values of {@link #set}() or {@link #clear}() (to inject, or clear, respectively, the corresponding flag), or more commonly ORing the corresponding named constants prefixed with {@code IS_} or {@code NOT_}. Flags that are not marked with {@code IS_} or {@code NOT_} are implicitly treated as preserved. Care must be taken when combining bitsets that the correct combining operations are applied in the correct order. <p> With the exception of {@link #SHORT_CIRCUIT}, stream characteristics can be derived from the equivalent {@link java.util.Spliterator} characteristics: {@link java.util.Spliterator#DISTINCT}, {@link java.util.Spliterator#SORTED}, {@link java.util.Spliterator#ORDERED}, and {@link java.util.Spliterator#SIZED}. A spliterator characteristics bit set can be converted to stream flags using the method {@link #fromCharacteristics(java.util.Spliterator)} and converted back using {@link #toCharacteristics}(int). (The bit set {@link #SPLITERATOR_CHARACTERISTICS_MASK} is used to AND with a bit set to produce a valid spliterator characteristics bit set that can be converted to stream flags.) <p> The source of a stream encapsulates a spliterator. The characteristics of that source spliterator when transformed to stream flags will be a proper subset of stream flags of that stream. For example: <pre> {@code Spliterator s = ...; Stream stream = Streams.stream(s); flagsFromSplitr = fromCharacteristics(s.characteristics()); assert(flagsFromSplitr & stream.getStreamFlags() == flagsFromSplitr); }</pre> <p> An intermediate operation, performed on an input stream to create a new output stream, may preserve, clear or inject stream or operation characteristics. Similarly, a terminal operation, performed on an input stream to produce an output result may preserve, clear or inject stream or operation characteristics. Preservation means that if that characteristic is present on the input, then it is also present on the output. Clearing means that the characteristic is not present on the output regardless of the input. Injection means that the characteristic is present on the output regardless of the input. If a characteristic is not cleared or injected then it is implicitly preserved. <p> A pipeline consists of a stream source encapsulating a spliterator, one or more intermediate operations, and finally a terminal operation that produces a result. At each stage of the pipeline, a combined stream and operation flags can be calculated, using {@link #combineOpFlags(int, int)}. Such flags ensure that preservation, clearing and injecting information is retained at each stage. The combined stream and operation flags for the source stage of the pipeline is calculated as follows: <pre> {@code int flagsForSourceStage = combineOpFlags(sourceFlags, INITIAL_OPS_VALUE); }</pre> The combined stream and operation flags of each subsequent intermediate operation stage in the pipeline is calculated as follows: <pre> {@code int flagsForThisStage = combineOpFlags(flagsForPreviousStage, thisOpFlags); }</pre> Finally the flags output from the last intermediate operation of the pipeline are combined with the operation flags of the terminal operation to produce the flags output from the pipeline. <p>Those flags can then be used to apply optimizations. For example, if {@code SIZED.isKnown(flags)} returns true then the stream size remains constant throughout the pipeline, this information can be utilized to pre-allocate data structures and combined with {@link java.util.Spliterator#SUBSIZED} that information can be utilized to perform concurrent in-place updates into a shared array. For specific details see the {@link java.util.stream.AbstractPipeline} constructors. @since 1.8 @hide Visible for CTS testing only (OpenJDK8 tests). */ var StreamOpFlag = { /** Characteristic value signifying that, for each pair of encountered elements in a stream {@code x, y}, {@code !x.equals(y)}. <p> A stream may have this value or an intermediate operation can preserve, clear or inject this value. */ DISTINCT : "null", /** Characteristic value signifying that encounter order follows a natural sort order of comparable elements. <p> A stream can have this value or an intermediate operation can preserve, clear or inject this value. <p> Note: The {@link java.util.Spliterator#SORTED} characteristic can define a sort order with an associated non-null comparator. Augmenting flag state with addition properties such that those properties can be passed to operations requires some disruptive changes for a singular use-case. Furthermore, comparing comparators for equality beyond that of identity is likely to be unreliable. Therefore the {@code SORTED} characteristic for a defined non-natural sort order is not mapped internally to the {@code SORTED} flag. */ SORTED : "null", /** Characteristic value signifying that an encounter order is defined for stream elements. <p> A stream can have this value, an intermediate operation can preserve, clear or inject this value, or a terminal operation can preserve or clear this value. */ ORDERED : "null", /** Characteristic value signifying that size of the stream is of a known finite size that is equal to the known finite size of the source spliterator input to the first stream in the pipeline. <p> A stream can have this value or an intermediate operation can preserve or clear this value. */ SIZED : "null", /** Characteristic value signifying that an operation may short-circuit the stream. <p> An intermediate operation can preserve or inject this value, or a terminal operation can preserve or inject this value. */ SHORT_CIRCUIT : "null", /** The bit mask for spliterator characteristics */ SPLITERATOR_CHARACTERISTICS_MASK : "null", /** The bit mask for source stream flags. */ STREAM_MASK : "null", /** The bit mask for intermediate operation flags. */ OP_MASK : "null", /** The bit mask for terminal operation flags. */ TERMINAL_OP_MASK : "null", /** The bit mask for upstream terminal operation flags. */ UPSTREAM_TERMINAL_OP_MASK : "null", /** The initial value to be combined with the stream flags of the first stream in the pipeline. */ INITIAL_OPS_VALUE : "null", /** The bit value to set or inject {@link #DISTINCT}. */ IS_DISTINCT : "null", /** The bit value to clear {@link #DISTINCT}. */ NOT_DISTINCT : "null", /** The bit value to set or inject {@link #SORTED}. */ IS_SORTED : "null", /** The bit value to clear {@link #SORTED}. */ NOT_SORTED : "null", /** The bit value to set or inject {@link #ORDERED}. */ IS_ORDERED : "null", /** The bit value to clear {@link #ORDERED}. */ NOT_ORDERED : "null", /** The bit value to set {@link #SIZED}. */ IS_SIZED : "null", /** The bit value to clear {@link #SIZED}. */ NOT_SIZED : "null", /** The bit value to inject {@link #SHORT_CIRCUIT}. */ IS_SHORT_CIRCUIT : "null", /** */ values : function( ) {}, /** */ valueOf : function( ) {}, /**Gets the bitmap associated with setting this characteristic. @return {Number} the bitmap for setting this characteristic */ set : function( ) {}, /**Gets the bitmap associated with clearing this characteristic. @return {Number} the bitmap for clearing this characteristic */ clear : function( ) {}, /**Determines if this flag is a stream-based flag. @return {Boolean} true if a stream-based flag, otherwise false. */ isStreamFlag : function( ) {}, /**Checks if this flag is set on stream flags, injected on operation flags, and injected on combined stream and operation flags. @param {Number} flags the stream flags, operation flags, or combined stream and operation flags @return {Boolean} true if this flag is known, otherwise false. */ isKnown : function( ) {}, /**Checks if this flag is cleared on operation flags or combined stream and operation flags. @param {Number} flags the operation flags or combined stream and operations flags. @return {Boolean} true if this flag is preserved, otherwise false. */ isCleared : function( ) {}, /**Checks if this flag is preserved on combined stream and operation flags. @param {Number} flags the combined stream and operations flags. @return {Boolean} true if this flag is preserved, otherwise false. */ isPreserved : function( ) {}, /**Determines if this flag can be set for a flag type. @param {Object {StreamOpFlag.Type}} t the flag type. @return {Boolean} true if this flag can be set for the flag type, otherwise false. */ canSet : function( ) {}, /**Combines stream or operation flags with previously combined stream and operation flags to produce updated combined stream and operation flags. <p> A flag set on stream flags or injected on operation flags, and injected combined stream and operation flags, will be injected on the updated combined stream and operation flags. <p> A flag set on stream flags or injected on operation flags, and cleared on the combined stream and operation flags, will be cleared on the updated combined stream and operation flags. <p> A flag set on the stream flags or injected on operation flags, and preserved on the combined stream and operation flags, will be injected on the updated combined stream and operation flags. <p> A flag not set on the stream flags or cleared/preserved on operation flags, and injected on the combined stream and operation flags, will be injected on the updated combined stream and operation flags. <p> A flag not set on the stream flags or cleared/preserved on operation flags, and cleared on the combined stream and operation flags, will be cleared on the updated combined stream and operation flags. <p> A flag not set on the stream flags, and preserved on the combined stream and operation flags will be preserved on the updated combined stream and operation flags. <p> A flag cleared on operation flags, and preserved on the combined stream and operation flags will be cleared on the updated combined stream and operation flags. <p> A flag preserved on operation flags, and preserved on the combined stream and operation flags will be preserved on the updated combined stream and operation flags. @param {Number} newStreamOrOpFlags the stream or operation flags. @param {Number} prevCombOpFlags previously combined stream and operation flags. The value {#link INITIAL_OPS_VALUE} must be used as the seed value. @return {Number} the updated combined stream and operation flags. */ combineOpFlags : function( ) {}, /**Converts combined stream and operation flags to stream flags. <p>Each flag injected on the combined stream and operation flags will be set on the stream flags. @param {Number} combOpFlags the combined stream and operation flags. @return {Number} the stream flags. */ toStreamFlags : function( ) {}, /**Converts stream flags to a spliterator characteristic bit set. @param {Number} streamFlags the stream flags. @return {Number} the spliterator characteristic bit set. */ toCharacteristics : function( ) {}, /**Converts a spliterator characteristic bit set to stream flags. @param {Object {java.util.Spliterator}} spliterator the spliterator from which to obtain characteristic bit set. @param spliterator the spliterator from which to obtain characteristic bit set. @return {Number} the stream flags. */ fromCharacteristics : function( ) {}, /**Converts a spliterator characteristic bit set to stream flags. @param {Number} characteristics the spliterator characteristic bit set. @return {Number} the stream flags. */ fromCharacteristics : function( ) {}, };