forked from Speiger/Primitive-Collections
New Content patch getting big progress on base and progress on lists.
-Changed: Build Task no longer Sync's because it is 9x slower and a File Builder never collides with another File Builder. -Added: getEquals() function for faster compare builders. -Changed: getNonClassType to getNonFileType() -Added: New Rule to the Rule Sheet. -Added: Regex Helper so recursion is supported -Added: FunctionMapper that supports more then 1 argument. -Changed: Injection & FunctionMapper support recursion- -Added: Loads of Variables to the GlobalVariables as they were added for templates. -Added: AbstractCollection, AbstractList, List, ListIterator, BidirectionalIterator, Arrays and ArrayList template.master
parent
c61c8a7806
commit
5cc4f35407
@ -0,0 +1,65 @@
|
||||
package speiger.src.builder.mappers;
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import speiger.src.builder.misc.RegexUtil;
|
||||
|
||||
public class ArgumentMapper implements UnaryOperator<String>
|
||||
{
|
||||
Pattern pattern;
|
||||
String replacement;
|
||||
String argumentBreaker;
|
||||
String braces = "()";
|
||||
boolean removeBraces;
|
||||
|
||||
public ArgumentMapper(String pattern, String replacement, String argumentBreaker)
|
||||
{
|
||||
this.pattern = Pattern.compile(pattern);
|
||||
this.replacement = replacement;
|
||||
this.argumentBreaker = argumentBreaker;
|
||||
}
|
||||
|
||||
public ArgumentMapper setBraceType(String s)
|
||||
{
|
||||
if(s.length() != 2) throw new IllegalStateException("Start and End char only");
|
||||
braces = s;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArgumentMapper removeBraces()
|
||||
{
|
||||
removeBraces = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(String t)
|
||||
{
|
||||
Matcher matcher = pattern.matcher(t);
|
||||
if(matcher.find())
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
do
|
||||
{
|
||||
String text = RegexUtil.searchUntil(t, matcher.end()-1, braces.charAt(0), braces.charAt(1));
|
||||
if(!text.isEmpty())
|
||||
{
|
||||
RegexUtil.skip(matcher.appendReplacement(buffer, ""), text.length());
|
||||
buffer.append(String.format(replacement, (Object[])getString(text).split(argumentBreaker)));
|
||||
}
|
||||
}
|
||||
while(matcher.find());
|
||||
matcher.appendTail(buffer);
|
||||
return buffer.toString();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
protected String getString(String s)
|
||||
{
|
||||
return removeBraces ? s.substring(1, s.length() - 1) : s;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package speiger.src.builder.misc;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class RegexUtil
|
||||
{
|
||||
static Field LAST_POS;
|
||||
|
||||
public static Matcher skip(Matcher matcher, int amount)
|
||||
{
|
||||
try
|
||||
{
|
||||
LAST_POS.setInt(matcher, LAST_POS.getInt(matcher) + amount);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return matcher;
|
||||
}
|
||||
|
||||
public static String searchUntil(String text, int startIndex, char increase, char decrease)
|
||||
{
|
||||
if(text.charAt(startIndex + 1) != increase)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
int inc = 0;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for(int i = startIndex + 1;i<text.length();i++)
|
||||
{
|
||||
char current = text.charAt(i);
|
||||
if(current == '\\' && i < text.length() - 1 && text.charAt(i+1) == 'n')
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else if(current == increase)
|
||||
{
|
||||
inc++;
|
||||
}
|
||||
else if(current == decrease)
|
||||
{
|
||||
inc--;
|
||||
if(inc <= 0)
|
||||
{
|
||||
return builder.append(decrease).toString();
|
||||
}
|
||||
}
|
||||
builder.append(current);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
Field field = Matcher.class.getDeclaredField("lastAppendPosition");
|
||||
field.setAccessible(true);
|
||||
LAST_POS = field;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package speiger.src.collections.utils;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface BidirectionalIterator<E> extends Iterator<E>
|
||||
{
|
||||
public E previous();
|
||||
|
||||
public boolean hasPrevious();
|
||||
|
||||
public default int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Can't go forward");
|
||||
int i = 0;
|
||||
for(;i<amount && hasPrevious();previous(),i++);
|
||||
return i;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
|
||||
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE, ObjectBidirectionalIterator<CLASS_TYPE>
|
||||
#else
|
||||
import speiger.src.collections.utils.BidirectionalIterator;
|
||||
|
||||
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE, BidirectionalIterator<CLASS_TYPE>
|
||||
#endif
|
||||
{
|
||||
public KEY_TYPE PREVIOUS();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE previous() {
|
||||
return KEY_TO_OBJ(PREVIOUS());
|
||||
}
|
||||
|
||||
@Override
|
||||
default int skip(int amount)
|
||||
{
|
||||
return ITERATOR.super.skip(amount);
|
||||
}
|
||||
#endif
|
||||
}
|
@ -0,0 +1,296 @@
|
||||
package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e) {
|
||||
add(size(), e);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(COLLECTION c) {
|
||||
boolean modified = false;
|
||||
for(KEY_TYPE e : c)
|
||||
modified |= add(e);
|
||||
return modified;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean addAll(LIST KEY_GENERIC_TYPE c) {
|
||||
boolean modified = false;
|
||||
for(KEY_TYPE e : c)
|
||||
modified |= add(e);
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator();
|
||||
#if TYPE_OBJECT
|
||||
if(o == null) {
|
||||
while(iter.hasNext()) {
|
||||
if(iter.NEXT() == null)
|
||||
return iter.previousIndex();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
if(o == null) return -1;
|
||||
#endif
|
||||
while(iter.hasNext()) {
|
||||
if(EQUALS_KEY_TYPE(iter.NEXT(), o))
|
||||
return iter.previousIndex();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(size());
|
||||
#if TYPE_OBJECT
|
||||
if(o == null) {
|
||||
while(iter.hasPrevious()) {
|
||||
if(iter.PREVIOUS() == null)
|
||||
return iter.nextIndex();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
if(o == null) return -1;
|
||||
#endif
|
||||
while(iter.hasPrevious()) {
|
||||
if(EQUALS_KEY_TYPE(iter.PREVIOUS(), o))
|
||||
return iter.nextIndex();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public int indexOf(KEY_TYPE e) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator();
|
||||
while(iter.hasNext()) {
|
||||
if(EQUALS(iter.NEXT(), e))
|
||||
return iter.previousIndex();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(KEY_TYPE e) {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE iter = listIterator(size());
|
||||
while(iter.hasPrevious()) {
|
||||
if(EQUALS(iter.PREVIOUS(), e))
|
||||
return iter.nextIndex();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||
return new SUB_LIST(this, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return listIterator(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
|
||||
return listIterator(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||
return new LIST_ITER(index);
|
||||
}
|
||||
|
||||
private class SUB_LIST extends ABSTRACT_LIST KEY_GENERIC_TYPE {
|
||||
ABSTRACT_LIST KEY_GENERIC_TYPE l;
|
||||
int offset;
|
||||
int size;
|
||||
|
||||
SUB_LIST(ABSTRACT_LIST KEY_GENERIC_TYPE l, int from, int to) {
|
||||
if (from < 0) throw new IndexOutOfBoundsException("fromIndex = " + from);
|
||||
else if (to > l.size()) throw new IndexOutOfBoundsException("toIndex = " + to);
|
||||
else if (from > to) throw new IllegalArgumentException("fromIndex(" + from + ") > toIndex(" + to + ")");
|
||||
this.l = l;
|
||||
offset = from;
|
||||
size = to - from;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, KEY_TYPE e) {
|
||||
checkAddRange(index);
|
||||
l.add(index+offset, e);
|
||||
size++;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void add(int index, CLASS_TYPE element) {
|
||||
add(index, OBJ_TO_KEY(element));
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
|
||||
checkAddRange(index);
|
||||
int size = c.size();
|
||||
if(size == 0) return false;
|
||||
l.addAll(index + offset, l);
|
||||
offset += size;
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
||||
checkAddRange(index);
|
||||
int size = c.size();
|
||||
if(size == 0) return false;
|
||||
l.addAll(index + offset, l);
|
||||
offset += size;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
||||
checkAddRange(index);
|
||||
int size = c.size();
|
||||
if(size == 0) return false;
|
||||
l.addAll(index + offset, l);
|
||||
offset += size;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_KEY(int index) {
|
||||
checkRange(index);
|
||||
return l.GET_KEY(index + offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE set(int index, KEY_TYPE e) {
|
||||
checkRange(index);
|
||||
return l.set(index + offset, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index) {
|
||||
checkRange(index);
|
||||
size--;
|
||||
return l.REMOVE(index + offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
private void checkRange(int index) {
|
||||
if (index < 0 || index >= size)
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
}
|
||||
|
||||
private void checkAddRange(int index) {
|
||||
if (index < 0 || index > size)
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
}
|
||||
}
|
||||
|
||||
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
LIST_ITER(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
return GET_KEY(index++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
return GET_KEY(index--);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == -1)
|
||||
throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.REMOVE(lastReturned);
|
||||
if(lastReturned < index)
|
||||
index--;
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(KEY_TYPE e) {
|
||||
if(lastReturned == -1)
|
||||
throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(KEY_TYPE e) {
|
||||
if(lastReturned == -1)
|
||||
throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.add(index++, e);
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, (size() - 1) - index);
|
||||
index += steps;
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#endif
|
||||
|
||||
public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
{
|
||||
transient KEY_TYPE[] data;
|
||||
private int size = 0;
|
||||
|
||||
public ARRAY_LIST(int size)
|
||||
{
|
||||
#if TYPE_OBJECT
|
||||
data = (KEY_TYPE[])new Object[size];
|
||||
#else
|
||||
data = new KEY_TYPE[size];
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, CLASS_TYPE element)
|
||||
{
|
||||
checkAddRange(index);
|
||||
ensureCapacity(size + 1);
|
||||
if(index != size) System.arraycopy(data, index, data, index+1, size - index);
|
||||
data[index] = OBJ_TO_KEY(element);
|
||||
size++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e)
|
||||
{
|
||||
ensureCapacity(size + 1);
|
||||
data[size++] = e;
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void add(int index, KEY_TYPE e)
|
||||
{
|
||||
checkAddRange(index);
|
||||
ensureCapacity(size + 1);
|
||||
if(index != size) System.arraycopy(data, index, data, index+1, size - index);
|
||||
data[index] = e;
|
||||
size++;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c)
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
if(c instanceof COLLECTION) return addAll((COLLECTION)c);
|
||||
#endif
|
||||
int add = c.size();
|
||||
if(add <= 0) return false;
|
||||
ensureCapacity(size + add);
|
||||
if(index != size) System.arraycopy(data, index, data, index+add, size - index);
|
||||
size+=add;
|
||||
Iterator<? extends CLASS_TYPE> iter = c.iterator();
|
||||
while(add != 0) data[index++] = OBJ_TO_KEY(iter.next());
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c)
|
||||
{
|
||||
if(c instanceof LIST) return addAll((LIST)c);
|
||||
int add = c.size();
|
||||
if(add <= 0) return false;
|
||||
ensureCapacity(size + add);
|
||||
if(index != size) System.arraycopy(data, index, data, index+add, size - index);
|
||||
size+=add;
|
||||
ITERATOR KEY_GENERIC_TYPE iter = c.iterator();
|
||||
while(add != 0) data[index++] = iter.NEXT();
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_KEY(int index)
|
||||
{
|
||||
if (index >= size) throw new IndexOutOfBoundsException("Index (" + index + ") is not in lists size (" + size + ")");
|
||||
return data[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE set(int index, KEY_TYPE e)
|
||||
{
|
||||
if (index >= size) throw new IndexOutOfBoundsException("Index (" + index + ") is not in lists size (" + size + ")");
|
||||
KEY_TYPE old = data[index];
|
||||
data[index] = e;
|
||||
return old;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE(int index)
|
||||
{
|
||||
if (index >= size) throw new IndexOutOfBoundsException("Index (" + index + ") is not in lists size (" + size + ")");
|
||||
KEY_TYPE old = data[index];
|
||||
if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
||||
#if TYPE_OBJECT
|
||||
data[size] = null;
|
||||
#endif
|
||||
size--;
|
||||
return old;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
#if TYPE_OBJECT
|
||||
for(int i = 0;i<size;data[i] = null,i++);
|
||||
#endif
|
||||
size = 0;
|
||||
}
|
||||
|
||||
protected void ensureCapacity(int capacity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void checkAddRange(int index)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
import java.util.List;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
|
||||
public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List<CLASS_TYPE>
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
public boolean add(KEY_TYPE e);
|
||||
|
||||
public void add(int index, KEY_TYPE e);
|
||||
|
||||
public boolean addAll(int index, COLLECTION c);
|
||||
|
||||
#endif
|
||||
public boolean addAll(LIST KEY_GENERIC_TYPE c);
|
||||
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c);
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
public KEY_TYPE GET_KEY(int index);
|
||||
|
||||
public KEY_TYPE set(int index, KEY_TYPE e);
|
||||
|
||||
public KEY_TYPE REMOVE(int index);
|
||||
|
||||
public int indexOf(KEY_TYPE e);
|
||||
|
||||
public int lastIndexOf(KEY_TYPE e);
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator();
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index);
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to);
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(CLASS_TYPE e) {
|
||||
return COLLECTION.super.add(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE get(int index) {
|
||||
return KEY_TO_OBJ(GET_KEY(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE set(int index, CLASS_TYPE e) {
|
||||
return KEY_TO_OBJ(set(index, OBJ_TO_KEY(e)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default int indexOf(Object o) {
|
||||
return indexOf(CLASS_TO_KEY(o));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default int lastIndexOf(Object o) {
|
||||
return indexOf(CLASS_TO_KEY(o));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) {
|
||||
return COLLECTION.super.contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) {
|
||||
return COLLECTION.super.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE remove(int index) {
|
||||
return KEY_TO_OBJ(REMOVE(index));
|
||||
}
|
||||
#endif
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package speiger.src.collections.PACKAGE.lists;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
|
||||
public interface LIST_ITERATOR KEY_GENERIC_TYPE extends ListIterator<CLASS_TYPE>, BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
public void set(KEY_TYPE e);
|
||||
|
||||
public void add(KEY_TYPE e);
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE previous() {
|
||||
return BI_ITERATOR.super.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE next() {
|
||||
return BI_ITERATOR.super.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default void set(CLASS_TYPE e) {
|
||||
set(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default void add(CLASS_TYPE e) {
|
||||
add(OBJ_TO_KEY(e));
|
||||
}
|
||||
#endif
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
public class ARRAYS
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
public static CLASS_TYPE[] wrap(KEY_TYPE[] a) {
|
||||
CLASS_TYPE[] result = new CLASS_TYPE[a.length];
|
||||
for(int i = 0,m=a.length;i<m;i++)
|
||||
result[i] = KEY_TO_OBJ(a[i]);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static KEY_TYPE[] unwrap(CLASS_TYPE[] a) {
|
||||
KEY_TYPE[] result = new KEY_TYPE[a.length];
|
||||
for(int i = 0,m=a.length;i<m;i++)
|
||||
result[i] = OBJ_TO_KEY(a[i]);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
public class ITERATORS
|
||||
{
|
||||
public static GENERIC_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
return new ArrayIteratorBRACES(a, start, end);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
||||
return unwrap(a, i, 0, a.length);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
||||
return unwrap(a, i, offset, a.length);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
||||
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
||||
if(offset + max >= a.length) throw new IllegalStateException("largest array index exceeds array size");
|
||||
int index = 0;
|
||||
for(;index<max && i.hasNext();index++) a[index+offset] = i.NEXT();
|
||||
return index;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
public static GENERIC_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
||||
return unwrap(a, i, 0, a.length);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
||||
return unwrap(a, i, offset, a.length);
|
||||
}
|
||||
|
||||
public static GENERIC_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
||||
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
||||
if(offset + max >= a.length) throw new IllegalStateException("largest array index exceeds array size");
|
||||
int index = 0;
|
||||
for(;index<max && i.hasNext();index++) a[index+offset] = KEY_TO_OBJ(i.NEXT());
|
||||
return index;
|
||||
}
|
||||
|
||||
#endif
|
||||
private static class ArrayIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
KEY_TYPE[] a;
|
||||
int from;
|
||||
int to;
|
||||
|
||||
ArrayIterator(KEY_TYPE[] a, int from, int to) {
|
||||
this.a = a;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return from < to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
return a[from++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int left = Math.min(amount, to - from);
|
||||
from += left;
|
||||
return amount - left;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue