Java Array Join joinAttributes(final String[] atts1, final String[] atts2)

Here you can find the source of joinAttributes(final String[] atts1, final String[] atts2)

Description

Creates a set of attribute names from the two input lists of names, maintaining the order of the first list and appending the non repeated names of the second.

License

Open Source License

Parameter

Parameter Description
atts1 the first list of attribute names, who's order will be maintained
atts2 the second list of attribute names, from wich the non repeated names will be appended to the resulting list

Return

Set of attribute names from atts1 and atts2

Declaration

private static String[] joinAttributes(final String[] atts1, final String[] atts2) 

Method Source Code

//package com.java2s;
/*//from w  w w.  j  a  v a  2  s  .c om
 *    Geotoolkit - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2009-2010, Geomatys
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

import java.util.Arrays;

import java.util.LinkedList;
import java.util.List;

public class Main {
    /**
     * Creates a set of attribute names from the two input lists of names,
     * maintaining the order of the first list and appending the non repeated
     * names of the second.
     * <p>
     * In the case where both lists are <code>null</code>, <code>null</code>
     * is returned.
     * </p>
     *
     * @param atts1 the first list of attribute names, who's order will be
     *        maintained
     * @param atts2 the second list of attribute names, from wich the non
     *        repeated names will be appended to the resulting list
     *
     * @return Set of attribute names from <code>atts1</code> and
     *         <code>atts2</code>
     */
    private static String[] joinAttributes(final String[] atts1, final String[] atts2) {
        if (atts1 == null && atts2 == null) {
            return null;
        }

        final List atts = new LinkedList();

        if (atts1 != null) {
            atts.addAll(Arrays.asList(atts1));
        }

        if (atts2 != null) {
            for (int i = 0; i < atts2.length; i++) {
                if (!atts.contains(atts2[i])) {
                    atts.add(atts2[i]);
                }
            }
        }

        final String[] propNames = new String[atts.size()];
        atts.toArray(propNames);

        return propNames;
    }
}

Related

  1. join(T[] array, String separator)
  2. join(T[] array1, T[] array2)
  3. join(T[] first, T[] second)
  4. join(T[] objs, String splitString)
  5. joinArrays(T[] a, T[] b)
  6. joinByComma(String[] values)
  7. joinByteArrays(final byte[] array1, byte[] array2)
  8. joinBytesArrays(byte[]... args)
  9. joiner(int[] ints, String split)