All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.util.sorter.AbstractSorter Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
package net.anotheria.util.sorter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;

/**
 * 

Abstract AbstractSorter class.

* * @author another * @version $Id: $Id */ public abstract class AbstractSorter implements Sorter { /** * Transfers a vector into array. * Vector should include only objects of type IComparable. * * @param src a {@link java.util.Collection} object. * @return an array of {@link net.anotheria.util.sorter.IComparable} objects. */ public static IComparable[] vector2array(Collection src){ IComparable[] ret = new IComparable[src.size()]; src.toArray(ret); return ret; } /** * Transfers a list into array. * The list should include only objects of type IComparable. * * @param src a {@link java.util.List} object. * @param a T object. * @return an array of T objects. */ public static T[] list2array(List src){ T[] tmp = (T[]) new IComparable[0]; return src.toArray(tmp); } /** * Transfers an array into Vector. * * @param src a T object. * @param a T object. * @return a {@link java.util.List} object. */ public static List array2vector(T... src){ int l = src.length; List ret = new ArrayList<>(l); Collections.addAll(ret, src); return ret; } /** *

array2list.

* * @param src a T object. * @param a T object. * @return a {@link java.util.List} object. */ public static List array2list(T... src){ return Arrays.asList(src); } /** {@inheritDoc} */ public List sort(Enumeration source, SortType how){ List list = new ArrayList<>(); while(source.hasMoreElements()){ list.add(source.nextElement()); } return sort(list,how); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy