Java Array Sort extractFields(String[] items, int[] fields, String delim, boolean sortKeyFields)

Here you can find the source of extractFields(String[] items, int[] fields, String delim, boolean sortKeyFields)

Description

extract Fields

License

Apache License

Parameter

Parameter Description
items a parameter
fields a parameter
delim a parameter

Declaration

public static String extractFields(String[] items, int[] fields, String delim, boolean sortKeyFields) 

Method Source Code

//package com.java2s;
/*// ww  w .j a v a  2  s  .  c  om
 * chombo: Hadoop Map Reduce utility
 * Author: Pranab Ghosh
 * 
 * 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.Collections;

import java.util.List;

public class Main {
    /**
     * @param items
     * @param fields
     * @param delim
     * @return
     */
    public static String extractFields(String[] items, int[] fields, String delim, boolean sortKeyFields) {
        StringBuilder stBld = new StringBuilder();
        List<String> keyFields = new ArrayList();

        for (int i = 0; i < fields.length; ++i) {
            keyFields.add(items[fields[i]]);
        }

        if (sortKeyFields) {
            Collections.sort(keyFields);
        }

        boolean first = true;
        for (String key : keyFields) {
            if (first) {
                stBld.append(key);
                first = false;
            } else {
                stBld.append(delim).append(key);
            }
        }
        return stBld.toString();
    }
}

Related

  1. copySortArray(String[] values)
  2. countingSort(int[] a, int low, int high)
  3. countingSort(int[] array, int low, int high)
  4. deltaMetricToSortedIndicies( final double[][] deltaMetric)
  5. difference(int[] sorted1, int[] sorted2)
  6. getLeftIndex(float[] sorted, float value)
  7. getMedianIndex(float[] sorted, float value)
  8. getNewSortedIntArray(int[] codePointArray)
  9. getSortedDistinct(int[] values)