Java List Combine getCombinedColumnName(final List columnNames, final boolean sortByName)

Here you can find the source of getCombinedColumnName(final List columnNames, final boolean sortByName)

Description

get Combined Column Name

License

Apache License

Declaration

public static String getCombinedColumnName(final List<String> columnNames, final boolean sortByName) 

Method Source Code

//package com.java2s;
/*//from  www.  ja  v a 2s  .co m
 * @(#)$Id$
 *
 * Copyright 2006-2008 Makoto YUI
 *
 * 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.
 * 
 * Contributors:
 *     Makoto YUI - initial implementation
 */

import java.util.Collections;

import java.util.List;

public class Main {
    public static String getCombinedColumnName(final List<String> columnNames, final boolean sortByName) {
        final int size = columnNames.size();
        if (size == 0) {
            throw new IllegalArgumentException();
        }
        if (size == 1) {
            return columnNames.get(0);
        }
        if (sortByName) {
            Collections.sort(columnNames);
        }
        final StringBuilder buf = new StringBuilder(32);
        for (int i = 0; i < size; i++) {
            if (i != 0) {
                buf.append('&');
            }
            String name = columnNames.get(i);
            buf.append(name);
        }
        return buf.toString();
    }
}

Related

  1. combineLists(List keys, List values)
  2. combineLists(List a, List b)
  3. combineString(List lstInput, String strToken)
  4. combineStringList(List sList)
  5. combineSubtractArrays(List a1, List a2)
  6. putCombinedList(Map map, Object key, Object value)
  7. recursiveCombine(List>> toCombinate, int index)