semi-auto cleanup

This commit is contained in:
gnembon committed 2023-02-04 13:26:21 +01:00
1 parent cad80f82c6
commit 8f61271606
99 files changed
+11463 -8007

No files matched your search

@@ -1,35 +1,41 @@
package carpet.script.value;
import carpet.script.exception.InternalExpressionException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
public abstract class LazyListValue extends AbstractListValue implements Iterator<Value>
{
public static LazyListValue rangeDouble(double from, double to, double step)
public static LazyListValue rangeDouble(final double from, final double to, final double step)
{
return new LazyListValue()
{
{
if (step == 0)
{
throw new InternalExpressionException("Range will never end with a zero step");
}
this.start = from;
this.current = this.start;
this.limit = to;
this.stepp = step;
}
private final double start;
private double current;
private final double limit;
private final double stepp;
@Override
public Value next()
{
Value val = new NumericValue(current);
final Value val = new NumericValue(current);
current += stepp;
return val;
}
@@ -43,36 +49,41 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
@Override
public boolean hasNext()
{
return stepp > 0?(current < limit):(current > limit);
return stepp > 0 ? (current < limit) : (current > limit);
}
@Override
public String getString()
{
return String.format(Locale.ROOT, "[%s, %s, ..., %s)",NumericValue.of(start).getString(), NumericValue.of(start+stepp).getString(), NumericValue.of( limit).getString());
return String.format(Locale.ROOT, "[%s, %s, ..., %s)", NumericValue.of(start).getString(), NumericValue.of(start + stepp).getString(), NumericValue.of(limit).getString());
}
};
}
public static LazyListValue rangeLong(long from, long to, long step)
public static LazyListValue rangeLong(final long from, final long to, final long step)
{
return new LazyListValue()
{
{
if (step == 0)
{
throw new InternalExpressionException("Range will never end with a zero step");
}
this.start = from;
this.current = this.start;
this.limit = to;
this.stepp = step;
}
private final long start;
private long current;
private final long limit;
private final long stepp;
@Override
public Value next()
{
Value val = new NumericValue(current);
final Value val = new NumericValue(current);
current += stepp;
return val;
}
@@ -86,13 +97,13 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
@Override
public boolean hasNext()
{
return stepp > 0?(current < limit):(current > limit);
return stepp > 0 ? (current < limit) : (current > limit);
}
@Override
public String getString()
{
return String.format(Locale.ROOT, "[%s, %s, ..., %s)",NumericValue.of(start).getString(), NumericValue.of(start+stepp).getString(), NumericValue.of( limit).getString());
return String.format(Locale.ROOT, "[%s, %s, ..., %s)", NumericValue.of(start).getString(), NumericValue.of(start + stepp).getString(), NumericValue.of(limit).getString());
}
};
}
@@ -108,20 +119,24 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
{
return hasNext();
}
@Override public abstract boolean hasNext();
@Override public abstract Value next();
@Override
public void fatality() {reset();}
public void fatality()
{
reset();
}
public abstract void reset();
@Override
public Iterator<Value> iterator() {return this;}
public Iterator<Value> iterator()
{
return this;
}
public List<Value> unroll()
{
List<Value> result = new ArrayList<>();
final List<Value> result = new ArrayList<>();
this.forEachRemaining(result::add);
fatality();
return result;
@@ -130,26 +145,38 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
@Override
public Value slice(long from, Long to)
{
if (to == null || to < 0) to = (long) Integer.MAX_VALUE;
if (from < 0) from = 0;
if (to == null || to < 0)
{
to = (long) Integer.MAX_VALUE;
}
if (from < 0)
{
from = 0;
}
if (from > to)
{
return ListValue.of();
List<Value> result = new ArrayList<>();
}
final List<Value> result = new ArrayList<>();
int i;
for (i = 0; i < from; i++)
{
if (hasNext())
{
next();
}
else
{
fatality();
return ListValue.wrap(result);
}
}
for (i = (int)from; i < to; i++)
for (i = (int) from; i < to; i++)
{
if (hasNext())
{
result.add(next());
}
else
{
fatality();
@@ -158,8 +185,9 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
}
return ListValue.wrap(result);
}
@Override
public Value add(Value other)
public Value add(final Value other)
{
throw new InternalExpressionException("Cannot add to iterators");
}
@@ -175,37 +203,42 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
{
return "iterator";
}
@Override
public Object clone()
{
Object copy;
final Object copy;
try
{
copy = super.clone();
}
catch (CloneNotSupportedException e)
catch (final CloneNotSupportedException e)
{
throw new InternalExpressionException("Cannot copy iterators");
}
((LazyListValue)copy).reset();
((LazyListValue) copy).reset();
return copy;
}
@Override
public Value fromConstant() {
return (Value)clone();
public Value fromConstant()
{
return (Value) clone();
}
@Override
public int hashCode()
{
return ("i"+getString()).hashCode();
return ("i" + getString()).hashCode();
}
@Override
public Tag toTag(boolean force)
public Tag toTag(final boolean force)
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
if (!force)
{
throw new NBTSerializableValue.IncompatibleTypeException(this);
}
return StringTag.valueOf(getString());
}
}