57 lines
1.3 KiB
Java
57 lines
1.3 KiB
Java
package CollectionGenericObjects;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
|
private List<T> _collection;
|
|
private int _maxCount;
|
|
@Override
|
|
public int Count() {
|
|
return _collection.size();
|
|
}
|
|
|
|
@Override
|
|
public void SetMaxCount(int value, Class<T> type) {
|
|
if (value > 0) {
|
|
_maxCount = value;
|
|
}
|
|
}
|
|
public ListGenericObjects() {
|
|
_collection = new ArrayList<T>();
|
|
}
|
|
|
|
@Override
|
|
public int Insert(T obj) {
|
|
if (Count() == _maxCount) return -1;
|
|
_collection.add(obj);
|
|
return Count();
|
|
}
|
|
|
|
@Override
|
|
public int Insert(T obj, int position) {
|
|
if (Count() == _maxCount) return -1;
|
|
if (position > Count() || position < 0) return -1;
|
|
_collection.add(position, obj);
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public T Remove(int position) {
|
|
if (position >= _maxCount || position < 0) {
|
|
return null;
|
|
}
|
|
T myObj = _collection.get(position);
|
|
_collection.remove(position);
|
|
return myObj;
|
|
}
|
|
|
|
@Override
|
|
public T Get(int position) {
|
|
if (position >= Count() || position < 0) {
|
|
return null;
|
|
}
|
|
return _collection.get(position);
|
|
}
|
|
}
|