github.com/searKing/golang/go@v1.2.74/util/spliterator/of_primitive.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package spliterator
     6  
     7  import (
     8  	"context"
     9  
    10  	"github.com/searKing/golang/go/util/function/consumer"
    11  	"github.com/searKing/golang/go/util/object"
    12  )
    13  
    14  type OfPrimitive struct {
    15  	TODO
    16  }
    17  
    18  func NewOfPrimitive() *OfPrimitive {
    19  	split := &OfPrimitive{}
    20  	split.SetDerived(split)
    21  	return split
    22  }
    23  
    24  func (split *OfPrimitive) TrySplit() Spliterator {
    25  	return nil
    26  }
    27  
    28  /**
    29   * If a remaining element exists, performs the given action on it,
    30   * returning {@code true}; else returns {@code false}.  If this
    31   * Spliterator is {@link #ORDERED} the action is performed on the
    32   * next element in encounter order.  Exceptions thrown by the
    33   * action are relayed to the caller.
    34   *
    35   * @param action The action
    36   * @return {@code false} if no remaining elements existed
    37   * upon entry to this method, else {@code true}.
    38   * @throws NullPointerException if the specified action is null
    39   */
    40  func (split *OfPrimitive) TryAdvance(ctx context.Context, action consumer.Consumer) bool {
    41  	object.RequireNonNil(action)
    42  	return false
    43  }
    44  
    45  /**
    46   * Performs the given action for each remaining element, sequentially in
    47   * the current thread, until all elements have been processed or the
    48   * action throws an exception.  If this Spliterator is {@link #ORDERED},
    49   * actions are performed in encounter order.  Exceptions thrown by the
    50   * action are relayed to the caller.
    51   *
    52   * @implSpec
    53   * The default implementation repeatedly invokes {@link #tryAdvance}
    54   * until it returns {@code false}.  It should be overridden whenever
    55   * possible.
    56   *
    57   * @param action The action
    58   * @throws NullPointerException if the specified action is null
    59   */
    60  func (split *OfPrimitive) ForEachRemaining(ctx context.Context, action consumer.Consumer) {
    61  	for {
    62  		if !split.GetDerivedElse(split).(Spliterator).TryAdvance(ctx, action) {
    63  			break
    64  		}
    65  	}
    66  }