Here you can find the source of extractFields(String[] items, int[] fields, String delim, boolean sortKeyFields)
Parameter | Description |
---|---|
items | a parameter |
fields | a parameter |
delim | a parameter |
public static String extractFields(String[] items, int[] fields, String delim, boolean sortKeyFields)
//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(); } }