/*
Fluent transform operation using primitive types
e.g.
<pre>
{@code
import static cyclops.ReactiveSeq.mapDoubles;

ReactiveSeq.ofDoubles(1d,2d,3d)
.to(mapDoubles(i->i*2));

//[2d,4d,6d]
}
</pre>
164499
public static Function<? super ReactiveSeq<Double>, ? extends ReactiveSeq<Double>> mapDoubles(DoubleUnaryOperator b){

        return a->a.doubles(i->i,s->s.map(b));
    }
704628
public static Function<? super ReactiveSeq<Double>, ? extends ReactiveSeq<Double>> concatDoubles( ReactiveSeq<Double> b){

        return a->ReactiveSeq.fromSpliterator(DoubleStream.concat(a.mapToDouble(i->i),b.mapToDouble(i->i)).spliterator());
    }
225973
private boolean dispatch(Class<?> t, Object o) throws IOException {
		// is it a primitive array?
		Class<?> componentType = t.getComponentType();
		if(componentType!=null) {
			if(componentType.isPrimitive()) {
				put_arrayOfPrimitives(componentType, o);
			} else {
				put_arrayOfObjects((Object[])o);
			}

			return true;
		}

		// first the primitive types
		if(o instanceof Boolean || t.equals(Boolean.TYPE)) {
			put_bool((Boolean)o);
			return true;
		}
		if(o instanceof Byte || t.equals(Byte.TYPE)) {
			put_long(((Byte)o).longValue());
			return true;
		}
		if(o instanceof Short || t.equals(Short.TYPE)) {
			put_long(((Short)o).longValue());
			return true;
		}
		if(o instanceof Integer || t.equals(Integer.TYPE)) {
			put_long(((Integer)o).longValue());
			return true;
		}
		if(o instanceof Long || t.equals(Long.TYPE)) {
			put_long(((Long)o).longValue());
			return true;
		}
		if(o instanceof Float || t.equals(Float.TYPE)) {
			put_float(((Float)o).doubleValue());
			return true;
		}
		if(o instanceof Double || t.equals(Double.TYPE)) {
			put_float(((Double)o).doubleValue());
			return true;
		}
		if(o instanceof Character || t.equals(Character.TYPE)) {
			put_string(""+o);
			return true;
		}

		// check registry
		IObjectPickler custompickler=getCustomPickler(t);
		if(custompickler!=null) {
			custompickler.pickle(o, this.out, this);
			writeMemo(o);
			return true;
		}

		// more complex types
		if(o instanceof String) {
			put_string((String)o);
			return true;
		}
		if(o instanceof BigInteger) {
			put_bigint((BigInteger)o);
			return true;
		}
		if(o instanceof BigDecimal) {
			put_decimal((BigDecimal)o);
			return true;
		}
		if(o instanceof java.sql.Time) {
			java.sql.Time sqltime = (java.sql.Time)o;
			Time time = new Time(sqltime.getTime());
			put_time(time);
			return true;
		}
		if(o instanceof java.sql.Date) {
			put_sqldate((java.sql.Date)o);
			return true;
		}
		if(o instanceof Calendar) {
			put_calendar((Calendar)o);
			return true;
		}
		if(o instanceof Time) {
			put_time((Time)o);
			return true;
		}
		if(o instanceof TimeDelta) {
			put_timedelta((TimeDelta)o);
			return true;
		}
		if(o instanceof java.util.Date) {
			// a java Date contains a date+time so map this on Calendar
			// which will be pickled as a datetime.
			java.util.Date date=(java.util.Date)o;
			Calendar cal=GregorianCalendar.getInstance();
			cal.setTime(date);
			put_calendar(cal);
			return true;
		}
		if(o instanceof java.util.TimeZone) {
			put_timezone((TimeZone)o);
			return true;
		}
		if(o instanceof Enum) {
			put_string(o.toString());
			return true;
		}
		if(o instanceof Set<?>) {
			put_set((Set<?>)o);
			return true;
		}
		if(o instanceof Map<?,?>) {
			put_map((Map<?,?>)o);
			return true;
		}
		if(o instanceof List<?>) {
			put_collection((List<?>)o);
			return true;
		}
		if(o instanceof Collection<?>) {
			put_collection((Collection<?>)o);
			return true;
		}
		// javabean
		if(o instanceof java.io.Serializable ) {
			put_javabean(o);
			return true;
		}

		return false;
	}
873204
@Override
	@PublicEvolving
	public <R> SingleOutputStreamOperator<R> transform(String operatorName,
			TypeInformation<R> outTypeInfo, OneInputStreamOperator<T, R> operator) {

		SingleOutputStreamOperator<R> returnStream = super.transform(operatorName, outTypeInfo, operator);

		// inject the key selector and key type
		OneInputTransformation<T, R> transform = (OneInputTransformation<T, R>) returnStream.getTransformation();
		transform.setStateKeySelector(keySelector);
		transform.setStateKeyType(keyType);

		return returnStream;
	}
659669
function getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors) {
            var members = ts.createMap();
            var hasComputedProperties = false;
            ts.forEach(pattern.elements, function (e) {
                var name = e.propertyName || e.name;
                if (isComputedNonLiteralName(name)) {
                    // do not include computed properties in the implied type
                    hasComputedProperties = true;
                    return;
                }
                var text = getTextOfPropertyName(name);
                var flags = 4 /* Property */ | 67108864 /* Transient */ | (e.initializer ? 536870912 /* Optional */ : 0);
                var symbol = createSymbol(flags, text);
                symbol.type = getTypeFromBindingElement(e, includePatternInType, reportErrors);
                symbol.bindingElement = e;
                members[symbol.name] = symbol;
            });
            var result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined);
            if (includePatternInType) {
                result.pattern = pattern;
            }
            if (hasComputedProperties) {
                result.flags |= 536870912 /* ObjectLiteralPatternWithComputedProperties */;
            }
            return result;
        }
465254
public static PixelTransform<Point2D_F32> createPixelTransform(InvertibleTransform transform) {
		PixelTransform<Point2D_F32> pixelTran;
		if( transform instanceof Homography2D_F64) {
			Homography2D_F32 t = ConvertFloatType.convert((Homography2D_F64) transform, null);
			pixelTran = new PixelTransformHomography_F32(t);
		} else if( transform instanceof Homography2D_F32) {
				pixelTran = new PixelTransformHomography_F32((Homography2D_F32)transform);
		} else if( transform instanceof Affine2D_F64) {
			Affine2D_F32 t = UtilAffine.convert((Affine2D_F64) transform, null);
			pixelTran = new PixelTransformAffine_F32(t);
		} else if( transform instanceof Affine2D_F32) {
			pixelTran = new PixelTransformAffine_F32((Affine2D_F32)transform);
		} else {
			throw new RuntimeException("Unknown model type");
		}
		return pixelTran;
	}
326198
@Override
    public Object mapSequence(Object sequence) {
        List<List<Float>> seq = (List<List<Float>>) sequence;
        List<Float> ret = new ArrayList<>();
        for (List<Float> step : seq)
            ret.add((Float) map(step));
        return ret;
    }
135537
static BindTransform getPrimitiveTransform(TypeName type) {

		if (Integer.TYPE.toString().equals(type.toString())) {
			return new IntegerBindTransform(false);
		}
		if (Boolean.TYPE.toString().equals(type.toString())) {
			return new BooleanBindTransform(false);
		}
		if (Long.TYPE.toString().equals(type.toString())) {
			return new LongBindTransform(false);
		}
		if (Double.TYPE.toString().equals(type.toString())) {
			return new DoubleBindTransform(false);
		}
		if (Float.TYPE.toString().equals(type.toString())) {
			return new FloatBindTransform(false);
		}
		if (Short.TYPE.toString().equals(type.toString())) {
			return new ShortBindTransform(false);
		}
		if (Byte.TYPE.toString().equals(type.toString())) {
			return new ByteBindTransform(false);
		}
		if (Character.TYPE.toString().equals(type.toString())) {
			return new CharacterBindTransform(false);
		}
		return null;
	}
1188578
public static <K, V1, V2> Maps.EntryTransformer<K, V1, V2> valueTransformer(
      final Function<? super V1, V2> valueFunction) {
    checkNotNull(valueFunction);
    return new Maps.EntryTransformer<K, V1, V2>() {
      @Override
      public V2 transformEntry(final K key, final V1 value) {
        return valueFunction.apply(value);
      }
    };
  }
985533
@Deprecated
  public static <InType, OutType> Iterable<OutType> applyOneToManyTransform(
      final Iterable<InType> input,
      final Function<? super InType, ? extends Iterable<OutType>> function) {
    return FluentIterable.from(input)
        .transformAndConcat(function);
  }
30251
private static <T, K> org.apache.flink.api.common.operators.SingleInputOperator<?, T, ?> translateSelectorFunctionReducer(
		SelectorFunctionKeys<T, ?> rawKeys,
		ReduceFunction<T> function,
		TypeInformation<T> inputType,
		String name,
		Operator<T> input,
		int parallelism,
		CombineHint hint) {
		@SuppressWarnings("unchecked")
		final SelectorFunctionKeys<T, K> keys = (SelectorFunctionKeys<T, K>) rawKeys;

		TypeInformation<Tuple2<K, T>> typeInfoWithKey = KeyFunctions.createTypeWithKey(keys);
		Operator<Tuple2<K, T>> keyedInput = KeyFunctions.appendKeyExtractor(input, keys);

		PlanUnwrappingReduceOperator<T, K> reducer = new PlanUnwrappingReduceOperator<>(function, keys, name, inputType, typeInfoWithKey);
		reducer.setInput(keyedInput);
		reducer.setParallelism(parallelism);
		reducer.setCombineHint(hint);

		return KeyFunctions.appendKeyRemover(reducer, keys);
	}
578738
protected void initWithPrimitiveTypeArray() {
     // =========== primitve array type ==============
        transformers.put(boolean[].class, new Transformer() {
            @Override
            public SFSDataWrapper transform(Object value) {
                return new SFSDataWrapper(SFSDataType.BOOL_ARRAY, primitiveArrayToBoolCollection((boolean[])value));
            }
        });
        transformers.put(byte[].class, new Transformer() {
            @Override
            public SFSDataWrapper transform(Object value) {
                return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, value);
            }
        });
        transformers.put(char[].class, new Transformer() {
            @Override
            public SFSDataWrapper transform(Object value) {
                return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, charArrayToByteArray((char[])value));
            }
        });
        transformers.put(double[].class, new Transformer() {
            @Override
            public SFSDataWrapper transform(Object value) {
                return new SFSDataWrapper(SFSDataType.DOUBLE_ARRAY, primitiveArrayToDoubleCollection((double[])value));
            }
        });
        transformers.put(float[].class, new Transformer() {
            @Override
            public SFSDataWrapper transform(Object value) {
                return new SFSDataWrapper(SFSDataType.FLOAT_ARRAY, primitiveArrayToFloatCollection((float[])value));
            }
        });
        transformers.put(int[].class, new Transformer() {
            @Override
            public SFSDataWrapper transform(Object value) {
                return new SFSDataWrapper(SFSDataType.INT_ARRAY, primitiveArrayToIntCollection((int[])value));
            }
        });
        transformers.put(long[].class, new Transformer() {
            @Override
            public SFSDataWrapper transform(Object value) {
                return new SFSDataWrapper(SFSDataType.LONG_ARRAY, primitiveArrayToLongCollection((long[])value));
            }
        });
        transformers.put(short[].class, new Transformer() {
            @Override
            public SFSDataWrapper transform(Object value) {
                return new SFSDataWrapper(SFSDataType.SHORT_ARRAY, primitiveArrayToShortCollection((short[])value));
            }
        });
    }
485640
private static <T, K> MapOperatorBase<Tuple2<K, T>, T, ?> translateSelectorFunctionReducer(Keys.SelectorFunctionKeys<T, ?> rawKeys,
			ReduceFunction<T> function, TypeInformation<T> inputType, String name, Operator<T> input, int dop)
	{
		@SuppressWarnings("unchecked")
		final Keys.SelectorFunctionKeys<T, K> keys = (Keys.SelectorFunctionKeys<T, K>) rawKeys;
		
		TypeInformation<Tuple2<K, T>> typeInfoWithKey = new TupleTypeInfo<Tuple2<K, T>>(keys.getKeyType(), inputType);
		
		KeyExtractingMapper<T, K> extractor = new KeyExtractingMapper<T, K>(keys.getKeyExtractor());
		
		PlanUnwrappingReduceOperator<T, K> reducer = new PlanUnwrappingReduceOperator<T, K>(function, keys, name, inputType, typeInfoWithKey);
		
		MapOperatorBase<T, Tuple2<K, T>, GenericMap<T, Tuple2<K, T>>> keyExtractingMap = new MapOperatorBase<T, Tuple2<K, T>, GenericMap<T, Tuple2<K, T>>>(extractor, new UnaryOperatorInformation<T, Tuple2<K, T>>(inputType, typeInfoWithKey), "Key Extractor");
		MapOperatorBase<Tuple2<K, T>, T, GenericMap<Tuple2<K, T>, T>> keyRemovingMap = new MapOperatorBase<Tuple2<K, T>, T, GenericMap<Tuple2<K, T>, T>>(new KeyRemovingMapper<T, K>(), new UnaryOperatorInformation<Tuple2<K, T>, T>(typeInfoWithKey, inputType), "Key Extractor");

		keyExtractingMap.setInput(input);
		reducer.setInput(keyExtractingMap);
		keyRemovingMap.setInput(reducer);
		
		// set dop
		keyExtractingMap.setDegreeOfParallelism(input.getDegreeOfParallelism());
		reducer.setDegreeOfParallelism(dop);
		keyRemovingMap.setDegreeOfParallelism(dop);
		
		return keyRemovingMap;
	}
1072311
static BindTransform getTransform(TypeName typeName) {
		if (typeName.isPrimitive()) {
			return getPrimitiveTransform(typeName);
		}

		if (typeName instanceof ArrayTypeName) {
			ArrayTypeName typeNameArray = (ArrayTypeName) typeName;

			if (TypeUtility.isEquals(typeNameArray.componentType, Byte.TYPE.toString())) {
				return new ByteArrayBindTransform();
			} else {
				return new ArrayBindTransform(typeNameArray.componentType, typeNameArray.componentType.isPrimitive());
			}
		} else if (typeName instanceof ParameterizedTypeName) {
			ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName;
			if (TypeUtility.isList(parameterizedTypeName.rawType)) {
				return new ListBindTransformation(parameterizedTypeName);
			} else if (TypeUtility.isSet(parameterizedTypeName.rawType)) {
				return new SetBindTransformation(parameterizedTypeName);
			} else if (TypeUtility.isMap(parameterizedTypeName.rawType)) {
				return new MapBindTransformation(parameterizedTypeName);
			}
		}

		String name = typeName.toString();

		if (name.startsWith("java.lang")) {
			return getLanguageTransform(typeName);
		}

		if (name.startsWith("java.util")) {
			return getUtilTransform(typeName);
		}

		if (name.startsWith("java.math")) {
			return getMathTransform(typeName);
		}

		if (name.startsWith("java.net")) {
			return getNetTransform(typeName);
		}

		if (name.startsWith("java.sql")) {
			return getSqlTransform(typeName);
		}

		if (TypeUtility.isEnum(typeName)) {
			return new EnumBindTransform(typeName);
		}

		// for default is treated as object
		return new ObjectBindTransform();
	}
1108408
static <T> ConvertibleValues<T> of(Environment environment, Map<? extends CharSequence, T> values) {
        if (values == null) {
            return ConvertibleValuesMap.empty();
        } else {
            return new EnvironmentConvertibleValuesMap<>(values, environment);
        }
    }
169853
private static <IN, K> org.apache.flink.api.common.operators.SingleInputOperator<?, IN, ?> translateSelectorFunctionDistinct(
			SelectorFunctionKeys<IN, ?> rawKeys,
			ReduceFunction<IN> function,
			TypeInformation<IN> outputType,
			String name,
			Operator<IN> input,
			int parallelism,
			CombineHint hint) {
		@SuppressWarnings("unchecked")
		final SelectorFunctionKeys<IN, K> keys = (SelectorFunctionKeys<IN, K>) rawKeys;

		TypeInformation<Tuple2<K, IN>> typeInfoWithKey = KeyFunctions.createTypeWithKey(keys);
		Operator<Tuple2<K, IN>> keyedInput = KeyFunctions.appendKeyExtractor(input, keys);

		PlanUnwrappingReduceOperator<IN, K> reducer =
				new PlanUnwrappingReduceOperator<>(function, keys, name, outputType, typeInfoWithKey);
		reducer.setInput(keyedInput);
		reducer.setCombineHint(hint);
		reducer.setParallelism(parallelism);

		return KeyFunctions.appendKeyRemover(reducer, keys);
	}
1117936
static BindTransform getMathTransform(TypeName typeName) {
		if (BigDecimal.class.getName().equals(typeName.toString())) {
			return new BigDecimalBindTransform();
		} else if (BigInteger.class.getName().equals(typeName.toString())) {
			return new BigIntegerBindTransform();
		}

		return null;
	}