Java String Split splitOrderedDurationsIntoIntervals(String[] durations, int numberOfIntervals)

Here you can find the source of splitOrderedDurationsIntoIntervals(String[] durations, int numberOfIntervals)

Description

split Ordered Durations Into Intervals

License

Open Source License

Declaration

public static List<String[]> splitOrderedDurationsIntoIntervals(String[] durations, int numberOfIntervals) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2012 Nikita Zhiltsov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html/*from   w w  w  .j  a  v  a  2  s .c  om*/
 * 
 * Contributors:
 *     Nikita Zhiltsov - initial API and implementation
 *     Azat Khasanshin - implementation
 ******************************************************************************/

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String[]> splitOrderedDurationsIntoIntervals(String[] durations, int numberOfIntervals) {

        int sizeOfSmallSublists = durations.length / numberOfIntervals;
        int sizeOfLargeSublists = sizeOfSmallSublists + 1;
        int numberOfLargeSublists = durations.length % numberOfIntervals;
        int numberOfSmallSublists = numberOfIntervals - numberOfLargeSublists;

        List<String[]> sublists = new ArrayList<String[]>(numberOfIntervals);
        int numberOfElementsHandled = 0;
        for (int i = 0; i < numberOfIntervals; i++) {
            int size = i < numberOfSmallSublists ? sizeOfSmallSublists : sizeOfLargeSublists;
            String[] sublist = new String[size];
            System.arraycopy(durations, numberOfElementsHandled, sublist, 0, size);
            sublists.add(sublist);
            numberOfElementsHandled += size;
        }
        return sublists;
    }
}

Related

  1. splitOgnl(String ognl)
  2. splitOn(String toSplit, String splitter)
  3. splitOnNoWiki(String s)
  4. splitOnTokens(String text)
  5. splitOnTokens(String text)
  6. splitPackageName(String packageName)
  7. splitPackages(String packages)
  8. splitParagraphs(String value)
  9. splitParameters(String parameters)