Adapt a {@code Spliterator<Long>} to a {@code Spliterator.OfLong}.

@implNote
The implementation attempts to cast to a Spliterator.OfLong, and throws
an exception if this cast is not possible.
481016
private static Spliterator.OfLong adapt(Spliterator<Long> s) {
        if (s instanceof Spliterator.OfLong) {
            return (Spliterator.OfLong) s;
        } else {
//            if (Tripwire.ENABLED)
//                Tripwire.trip(AbstractPipeline.class,
//                              "using LongStream.adapt(Spliterator<Long> s)");
            throw new UnsupportedOperationException("LongStream.adapt(Spliterator<Long> s)");
        }
    }
787627
public static LongIteratorEx oF(final Supplier<long[]> arraySupplier) {
        N.checkArgNotNull(arraySupplier, "arraySupplier");

        return new LongIteratorEx() {
            private LongIteratorEx iterEx = null;
            private boolean isInitialized = false;

            @Override
            public boolean hasNext() {
                if (isInitialized == false) {
                    init();
                }

                return iterEx.hasNext();
            }

            @Override
            public long nextLong() {
                if (isInitialized == false) {
                    init();
                }

                return iterEx.nextLong();
            }

            @Override
            public void skip(long n) {
                N.checkArgNotNegative(n, "n");

                if (isInitialized == false) {
                    init();
                }

                iterEx.skip(n);
            }

            @Override
            public long count() {
                if (isInitialized == false) {
                    init();
                }

                return iterEx.count();
            }

            private void init() {
                if (isInitialized == false) {
                    isInitialized = true;
                    long[] aar = arraySupplier.get();
                    iterEx = LongIteratorEx.of(aar);
                }
            }
        };
    }
666120
private Stream<ImmutableSubstitution<ImmutableTerm>> splitSubstitution(
            ImmutableSubstitution<ImmutableTerm> substitution, VariableGenerator variableGenerator) {

        ImmutableMultimap<Variable, Integer> functionSubTermMultimap = substitution.getImmutableMap().entrySet().stream()
                .filter(e -> e.getValue() instanceof ImmutableFunctionalTerm)
                .flatMap(e -> {
                    ImmutableList<? extends ImmutableTerm> subTerms = ((ImmutableFunctionalTerm) e.getValue()).getTerms();
                    return IntStream.range(0, subTerms.size())
                            .filter(i -> subTerms.get(i) instanceof ImmutableFunctionalTerm)
                            .boxed()
                            .map(i -> Maps.immutableEntry(e.getKey(), i));
                })
                .collect(ImmutableCollectors.toMultimap());

        if (functionSubTermMultimap.isEmpty())
            return Stream.of(substitution);

        ImmutableTable<Variable, Integer, Variable> subTermNames = functionSubTermMultimap.entries().stream()
                .map(e -> Tables.immutableCell(e.getKey(), e.getValue(), variableGenerator.generateNewVariable()))
                .collect(ImmutableCollectors.toTable());

        ImmutableMap<Variable, ImmutableTerm> parentSubstitutionMap = substitution.getImmutableMap().entrySet().stream()
                .map(e ->
                        Optional.ofNullable(functionSubTermMultimap.get(e.getKey()))
                                .map(indexes -> {
                                    Variable v = e.getKey();
                                    ImmutableFunctionalTerm def = (ImmutableFunctionalTerm) substitution.get(v);
                                    ImmutableList<ImmutableTerm> newArgs = IntStream.range(0, def.getArity())
                                            .boxed()
                                            .map(i -> Optional.ofNullable((ImmutableTerm) subTermNames.get(v, i))
                                                    .orElseGet(() -> def.getTerm(i)))
                                            .collect(ImmutableCollectors.toList());

                                    ImmutableTerm newDef = termFactory.getImmutableFunctionalTerm(
                                            def.getFunctionSymbol(), newArgs);
                                    return Maps.immutableEntry(v, newDef);
                                })
                                .orElse(e))
                .collect(ImmutableCollectors.toMap());

        ImmutableSubstitution<ImmutableTerm> parentSubstitution = substitutionFactory.getSubstitution(parentSubstitutionMap);


        ImmutableSubstitution<ImmutableTerm> childSubstitution = substitutionFactory.getSubstitution(
                subTermNames.cellSet().stream()
                    .collect(ImmutableCollectors.toMap(
                        Table.Cell::getValue,
                        c -> ((ImmutableFunctionalTerm) substitution.get(c.getRowKey())).getTerm(c.getColumnKey()))));

        return Stream.concat(
                // Recursive
                splitSubstitution(childSubstitution, variableGenerator),
                Stream.of(parentSubstitution));
    }
760823
public static <T, U> Collector<T, ?, Long> bitOrLong(ToLongFunction<? super T> function) {
        return Collector.of(() -> new long[1],
            (s, v) -> {
                s[0] = s[0] | function.applyAsLong(v);
            },
            (s1, s2) -> {
                s1[0] = s1[0] | s2[0];
                return s1;
            },
            s -> s[0]
        );
    }
1343668
public <T> void spliterator(Spliterator<T> s, ResultStream<T> result)
  {
    ArrayList<Spliterator<T>> splits = new ArrayList<>();
    
    splits.add(s);
    
    int count = 2 * getTaskManager().getWorkers();
    split(splits, count);
    
    int size = splits.size();
    
    if (size == 1) {
      getTaskManager().run(new ComputeTask<T>(splits.get(0), result));
      // _workers.compute(splits.get(0), new ResultSinkWrapper<T>(result));
      return;
    }

    /*
    if (true) {
      throw new UnsupportedOperationException(L.l("fork unsupported for {0}", result));
    }
    */
    
    ServiceRefAmp serviceRef = ServiceRefAmp.current();
    
    //ResultStreamAmp<T> resultAmp = (ResultStreamAmp<T>) result;
    
    ResultStreamJoin<T> join = new ResultStreamJoin<T>(result, serviceRef.inbox());
    for (int i = 0; i < size; i++) {
      //resultSinkFork[i].begin(0);
      //_workers.compute(splits.get(i), new ResultSinkWrapper<T>(resultSinkFork[i]));
      
      getTaskManager().run(new ComputeTask<T>(splits.get(i), join.fork()));
    }
    
    join.ok();
  }
854853
public static MutableLongTuple of(long x, long y, long z, long w)
    {
        return new DefaultLongTuple(new long[]{ x, y, z, w });
    }
988832
protected NumberedSplit<InputSplit> allocateSplit(final String evaluatorId,
      final BlockingQueue<NumberedSplit<InputSplit>> value) {
    if (value == null) {
      LOG.log(Level.FINE, "Queue of splits can't be empty. Returning null");
      return null;
    }
    while (true) {
      final NumberedSplit<InputSplit> split = value.poll();
      if (split == null) {
        return null;
      }
      if (value == unallocatedSplits || unallocatedSplits.remove(split)) {
        LOG.log(Level.FINE, "Found split-" + split.getIndex() + " in the queue");
        final NumberedSplit<InputSplit> old = evaluatorToSplits.putIfAbsent(evaluatorId, split);
        if (old != null) {
          throw new RuntimeException("Trying to assign different splits to the same evaluator is not supported");
        } else {
          LOG.log(Level.FINE, "Returning " + split.getIndex());
          return split;
        }
      }
    }
  }
210550
public void writeLong(long value) throws UnsupportedEncodingException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "writeLong", Long.valueOf(value));
    getBodyList().add(Long.valueOf(value));
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "writeLong");
  }
1308565
public static <T, E extends Exception> LongList mapToLong(final Collection<? extends T> c, final int fromIndex, final int toIndex,
            final Try.ToLongFunction<? super T, E> func) throws E {
        checkFromToIndex(fromIndex, toIndex, size(c));
        N.checkArgNotNull(func);

        if (N.isNullOrEmpty(c) && fromIndex == 0 && toIndex == 0) {
            return new LongList();
        }

        final LongList result = new LongList(toIndex - fromIndex);

        if (c instanceof List && c instanceof RandomAccess) {
            final List<T> list = (List<T>) c;

            for (int i = fromIndex; i < toIndex; i++) {
                result.add(func.applyAsLong(list.get(i)));
            }
        } else {
            int idx = 0;

            for (T e : c) {
                if (idx++ < fromIndex) {
                    continue;
                }

                result.add(func.applyAsLong(e));

                if (idx >= toIndex) {
                    break;
                }
            }
        }

        return result;
    }
1203997
public static LongStream of(final Supplier<LongList> supplier) {
        final LongIterator iter = new LongIteratorEx() {
            private LongIterator iterator = null;

            @Override
            public boolean hasNext() {
                if (iterator == null) {
                    init();
                }

                return iterator.hasNext();
            }

            @Override
            public long nextLong() {
                if (iterator == null) {
                    init();
                }

                return iterator.nextLong();
            }

            private void init() {
                final LongList c = supplier.get();

                if (N.isNullOrEmpty(c)) {
                    iterator = LongIterator.empty();
                } else {
                    iterator = c.iterator();
                }
            }
        };

        return of(iter);
    }
1253383
public static <T> Set<T> toSet(BaseStream<T, ? extends BaseStream> stream) {
        return StreamSupport.stream(
                Spliterators.spliteratorUnknownSize(stream.iterator(), Spliterator.ORDERED),
                false).collect(Collectors.<T>toSet());
    }
328124
public static Function<Object,Long> l(final String methodName, final Object... optionalParameters) {
        return methodForLong(methodName, optionalParameters);
    }
1179975
public static Function<? super ReactiveSeq<Long>, ? extends ReactiveSeq<Long>> mapLongs(LongUnaryOperator b){

        return a->a.longs(i->i,s->s.map(b));
    }
803680
@SuppressWarnings("unchecked")
  public static <T> Parser<T> longer(Parser<? extends T> p1, Parser<? extends T> p2) {
    return longest(p1, p2);
  }
1025317
private static Long[] castToLong( long[] d )
    {
        Long[] dest = new Long[d.length];
        for ( int i = 0; i < d.length; i++ )
        {
            dest[i] = (long)d[i];
        }
        return dest;
    }
829355
public void add(InputSplit s) throws IOException {
    if (null == splits) {
      throw new IOException("Uninitialized InputSplit");
    }
    if (fill == splits.length) {
      throw new IOException("Too many splits");
    }
    splits[fill++] = s;
    totsize += s.getLength();
  }
1160033
public JBBPOut Long(final long... value) throws IOException {
    assertNotEnded();
    assertArrayNotNull(value);
    if (this.processCommands) {
      for (final long l : value) {
        _writeLong(l);
      }
    }
    return this;
  }