de.uniks.networkparser.list.AbstractList Maven / Gradle / Ivy
package de.uniks.networkparser.list;
/*
NetworkParser
The MIT License
Copyright (c) 2010-2016 Stefan Lindel https://github.com/fujaba/NetworkParser/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import java.util.Collection;
import java.util.Iterator;
import java.util.ListIterator;
import de.uniks.networkparser.interfaces.BaseItem;
import de.uniks.networkparser.interfaces.Condition;
/**
* The Class is for generic implementation of List and Sets
* @author Stefan
*
* @param generic Parameter for Simple-Collection
*/
public abstract class AbstractList extends AbstractArray implements Iterable {
/**
* This implementation iterates over the specified collection, and adds
* each object returned by the iterator to this collection, in turn.
*
*
Note that this implementation will throw an
* UnsupportedOperationException unless add is
* overridden (assuming the specified collection is non-empty).
* @param c List of Elements for adding
* @return success
* @see #add(Object...)
*/
public boolean addAll(Collection extends V> c) {
if(c==null){
return false;
}
boolean modified = false;
for (V e : c)
if (add(e))
modified = true;
return modified;
}
public ListIterator listIterator() {
return new SimpleIterator(this);
}
public ListIterator listIterator(int index) {
return new SimpleIterator(this, index);
}
public ListIterator iteratorReverse() {
return new SimpleIterator(this, size());
}
@Override
public AbstractList withList(Collection> values) {
super.withList(values);
return this;
}
public void copyEntity(BaseItem target, int pos) {
if(target != null)
target.add(get(pos));
}
public BaseItem subSet(V fromElement, V toElement) {
BaseItem newList = getNewList(false);
int end = indexOf(toElement);
// MUST COPY
for(int pos = indexOf(fromElement);pos=0) {
grow(size + 1);
addKey(index, element,size + 1);
}
}
public V set(int index, V element) {
if(index<0 || index>size) {
return null;
}
setValue(index, element, SMALL_KEY);
return element;
}
@SuppressWarnings("unchecked")
public V remove(int index) {
if(index<0 || index>size) {
return null;
}
return (V)removeByIndex(index, SMALL_KEY, this.index);
}
public boolean addAll(int index, Collection extends V> values) {
if(values==null) {
return false;
}
boolean allAdded=true;
int newSize = size + values.size();
grow(newSize);
for(Iterator extends V> i = values.iterator();i.hasNext();){
if(addKey(index++, i.next(), newSize)<0){
allAdded=false;
}
}
return allAdded;
}
@SuppressWarnings("unchecked")
protected > ST filterItems(ST filterCollection, Condition> newValue) {
for(int i=0;i filter = (Condition