All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fuwjax.oss.util.Arrays2 Maven / Gradle / Ivy

There is a newer version: 1.44
Show newest version
/*
 * Copyright (C) 2015 fuwjax.org ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fuwjax.oss.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.util.Comparator;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * Created by fuwjax on 2/18/15.
 */
public class Arrays2 {
    public static  T[] transform(F[] source, T[] dest, Function transform) {
        if(dest.length < source.length){
            dest = (T[])Array.newInstance(dest.getClass().getComponentType(), source.length);
        }
        for (int i = 0; i < source.length; i++) {
            dest[i] = transform.apply(source[i]);
        }
        return dest;

    }

    public static  Comparator comparingArray(Comparator elementComparator) {
        return Comparator.comparingInt(a -> a.length).thenComparing((a1, a2) -> {
            for(int i=0;i T[] zip(F1[] source1, F2[] source2, T[] dest, BiFunction transform) {
        assert source1 != null && source2 != null && dest != null;
        assert source1.length == source2.length && source1.length == dest.length;
        for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy