Java List Merge mergeCoords(List x, List y)

Here you can find the source of mergeCoords(List x, List y)

Description

This will merge the coordinates of the given coordinate system.

License

Apache License

Parameter

Parameter Description
x the x coordinates
y the y coordinates

Return

a vector such that each (x,y) pair is at ret[i],ret[i+1]

Declaration

public static List<Double> mergeCoords(List<Double> x, List<Double> y) 

Method Source Code

//package com.java2s;
/*//  w  w w  .  jav  a  2  s.co m
 *
 *  * Copyright 2015 Skymind,Inc.
 *  *
 *  *    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.
 *
 */

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**
     * This will merge the coordinates of the given coordinate system.
     * @param x the x coordinates
     * @param y the y coordinates
     * @return a vector such that each (x,y) pair is at ret[i],ret[i+1]
     */
    public static double[] mergeCoords(double[] x, double[] y) {
        if (x.length != y.length)
            throw new IllegalArgumentException(
                    "Sample sizes must be the same for each data applyTransformToDestination.");
        double[] ret = new double[x.length + y.length];

        for (int i = 0; i < x.length; i++) {
            ret[i] = x[i];
            ret[i + 1] = y[i];
        }
        return ret;
    }

    /**
     * This will merge the coordinates of the given coordinate system.
     * @param x the x coordinates
     * @param y the y coordinates
     * @return a vector such that each (x,y) pair is at ret[i],ret[i+1]
     */
    public static List<Double> mergeCoords(List<Double> x, List<Double> y) {
        if (x.size() != y.size())
            throw new IllegalArgumentException(
                    "Sample sizes must be the same for each data applyTransformToDestination.");

        List<Double> ret = new ArrayList<>();

        for (int i = 0; i < x.size(); i++) {
            ret.add(x.get(i));
            ret.add(y.get(i));
        }
        return ret;
    }
}

Related

  1. merge(String[] list)
  2. merge2ListsWithoutDup(List list1, List list2)
  3. mergeBandY(List A, int z, int y, int yn)
  4. mergeBytes(List packages)
  5. mergeCollectionsToList(Collection... cols)
  6. mergeData(List lstMain, List lstData, List lstKey)
  7. mergedView(final List left, final List right)
  8. mergeErrorMsgList(List errorMsgs)
  9. mergeException(List t)