package CollectionGenericObjects; import java.lang.reflect.Array; public class MassiveGenericObjects implements ICollectionGenericObjects { private T[] _collection; int Count; @Override public int getCount() { return _collection.length; } @Override public void SetMaxCount(int count, Class type) { if (count > 0) { _collection = (T[]) Array.newInstance(type, count); Count = count; } } @Override public T Get(int position) { if (position >= getCount() || position < 0) return null; return (T) _collection[position]; } @Override public int Insert(T obj) { for (int i = 0; i < _collection.length; ++i) { if (_collection[i] == null) { _collection[i] = obj; return i; } } return -1; } @Override public int Insert(T obj, int position) { if (position < 0 || position > Count) { return -1; } if (_collection[position] == null) { _collection[position] = obj; return position; } for (int i = position + 1; i < _collection.length; ++i) { if (_collection[i] == null) { _collection[i] = obj; return position; } } for (int i = 0; i < position; ++i) { if (_collection[i] == null) { _collection[i] = obj; return position; } } return -1; } @Override public T Remove(int position) { if (position >= 0 && position < Count) { T remove = _collection[position]; _collection[position]= null; return remove; } return null; } }