import {terminalOps, TerminalOps, terminalSink} from "./TerminalOps"; import {Spliterator} from "../utils/Spliterator"; import {StreamShape} from "./StreamShape"; import {IntConsumer} from "../Consumer"; import {ofInt} from "./Sink"; import {consumerFn, IConsumer, supplierFn} from "../Interface"; import {UnsupportedOperationException} from "../Exception"; import {PipelineHelper} from "./PipelineHelper"; import {Objects} from "../type/Objects"; /** * @ForEachOps * */ export class ForEachOps { /***/ private constructor() {} /***/ private static ForEachOp = class ForEachOp extends TerminalOps implements terminalOps, terminalSink { accept: consumerFn; get: supplierFn = ()=> void 0; begin(value: number): void {throw new UnsupportedOperationException("Method is not implemented !");} end(): void {throw new UnsupportedOperationException("Method is not implemented !");} cancellationRequested(): boolean {throw new UnsupportedOperationException("Method is not implemented !");} /**@TerminalSink**/ getOpFlag(): number {return 0;} inputShape(): StreamShape {return undefined;} evaluateSequential(helper: PipelineHelper, spliterator: Spliterator): void { return helper.wrapAndCopyInto(this,spliterator).get(); } }; public static OfRef = class OfRef extends ForEachOps.ForEachOp{ readonly consumer:IConsumer; constructor(consumer:IConsumer) { super(); this.consumer=consumer; } public accept = (value:T) => this.consumer.accept(value); public inputShape(): StreamShape {return StreamShape.REFERENCE;} begin(value: number): void {} cancellationRequested(): boolean { return false; } end(): void {} }; public static OfInt = class OfInt extends ForEachOps.OfRef implements ofInt{ constructor(consumer:IntConsumer) {super(consumer);} public accept = (value:number) => this.consumer.accept(value); public inputShape(): StreamShape {return StreamShape.INT_VALUE;} }; public static makeRef(consumer:IConsumer):TerminalOps{ return new ForEachOps.OfRef(Objects.requireNotNull(consumer)); } public static makeInt(consumer:IntConsumer):TerminalOps{ return new ForEachOps.OfInt(Objects.requireNotNull(consumer)); } } Object.package(this);