Package com.cn.list.base;
Import java.util.ArrayList;
Import java.util.List;
/**
* Basic operation based on List thread table
*
*/
public class Listoperation<t> {
Private list<t> List = null;
/**
* Initialize List linear table
*
* @param initialcapacity Thread table capacity
* @return List
*/
Public list<t> initlist (int initialcapacity) {
list = null;
List = new arraylist<t> (initialcapacity);
return list;
}
/**
* <p>
* Determine if the linear table is empty.
* <p>
*
* <li>true-Linear table is empty
* <li>false-linear table is not empty
*
* @return Boolean
*/
public Boolean isEmpty () {
if (null = = List | | list.size () <= 0) {
return true;
}
return false;
}
/**
* Empty Linear table
*/
public void Clearlist () {
List.clear ();
}
/**
* Returns the element of the specified index
*
* @param I index value
* @return elements in linear table
*/
@SuppressWarnings ({"Unchecked", "hiding"})
Public <T> T Getelem (int i) {
Return (T) list.get (i);
}
/**
* Find out if a t element exists in a linear table
*
* <li>true-Presence
* <li>false-not present
*
* @param t contrast element
* @return Boolean
*/
public boolean Locateelem (T-t) {
for (int i = 0;i < List.size (); i++) {
if (List.get (i). Equals (t)) {
return true;
}
}
return false;
}
/**
* Insert Element
*
* @param t element
*/
public void Insert (T t) {
List.add (t);
}
/**
* Return thread table length
*
* @return Thread table length
*/
public int Length () {
return List.size ();
}
/**
* Merge the specified linear table with the same element overlay
*
* @param lis to merge the linear table
*/
public void Union (listoperation<t> lis) {
for (int i = 0;i < Lis.length (); i++) {
T t = Lis.getelem (i);
if (!this.locateelem (t)) {
This.insert (t);
}
}
}
/**
* Print all elements in a linear table
*/
public void All () {
SYSTEM.OUT.PRINTLN (list);
}
}
Basic operation based on List thread table