Java List Sort getNumberListSorted(String pagesStr)

Here you can find the source of getNumberListSorted(String pagesStr)

Description

get Number List Sorted

License

Open Source License

Declaration

public static List<Integer> getNumberListSorted(String pagesStr) throws NumberFormatException 

Method Source Code

//package com.java2s;
/* /*from w w  w  .  j ava2s.  com*/
 *  Copyright (C) 2000 - 2008 TagServlet Ltd
 *
 *  This file is part of Open BlueDragon (OpenBD) CFML Server Engine.
 *  
 *  OpenBD is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  Free Software Foundation,version 3.
 *  
 *  OpenBD 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 General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with OpenBD.  If not, see http://www.gnu.org/licenses/
 *  
 *  Additional permission under GNU GPL version 3 section 7
 *  
 *  If you modify this Program, or any covered work, by linking or combining 
 *  it with any of the JARS listed in the README.txt (or a modified version of 
 *  (that library), containing parts covered by the terms of that JAR, the 
 *  licensors of this Program grant you additional permission to convey the 
 *  resulting work. 
 *  README.txt @ http://www.openbluedragon.org/license/README.txt
 *  
 *  http://www.openbluedragon.org/
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import java.util.Set;

public class Main {
    public static List<Integer> getNumberListSorted(String pagesStr) throws NumberFormatException {
        Set<Integer> set = getNumberSet(pagesStr);
        List<Integer> list = new ArrayList<Integer>(set.size());
        Iterator<Integer> it = set.iterator();
        while (it.hasNext())
            list.add(it.next());

        Collections.sort(list);
        return list;
    }

    public static Set<Integer> getNumberSet(String pagesStr) throws NumberFormatException {
        if (pagesStr.length() == 0) {
            return null;
        } else {
            HashSet<Integer> pages = new HashSet<Integer>();
            String[] pageArr = pagesStr.split(",");
            for (int i = 0; i < pageArr.length; i++) {
                String nextPage = pageArr[i].trim();
                int rangeIndx = pageArr[i].indexOf('-');
                if (rangeIndx < 0) {
                    pages.add(Integer.parseInt(nextPage));
                } else {
                    int start = Integer.parseInt(nextPage.substring(0, rangeIndx));
                    int end = Integer.parseInt(nextPage.substring(rangeIndx + 1));
                    for (int j = start; j <= end; j++) {
                        pages.add(j);
                    }
                }
            }
            return pages;
        }
    }
}

Related

  1. descendingSortByCreationTime(List tasks)
  2. equalUnsorted(List list1, List list2)
  3. extractRankedProducts( List unsortedProducts)
  4. formatAsSortUniqCSVString(List s)
  5. getIndexForSortedInsert(final List listSorted, final String item)
  6. getOverlapCount(List list1, List list2, boolean sorted)
  7. getSortedFilesList(String filesList)
  8. getSortedKetList(HashMap numKnownGenesHashMap)
  9. getSortedList(Collection collection)