Updated to 1.11.2 API version

Does not mean the added functions are implemented in the prior versions, but it means they all compile against the same API and ZS version
This commit is contained in:
kindlich committed 2019-10-20 18:00:11 +02:00
1 parent 0f74091da5
commit 1c0344a25b
140 files changed
+6307 -6387

No files matched your search

@@ -1,222 +1,220 @@
package minetweaker.api.data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Contains a byte array.
*
*
* @author Stan Hebben
*/
public class DataByteArray implements IData {
private final byte[] data;
private final boolean immutable;
public DataByteArray(byte[] data, boolean immutable) {
this.data = data;
this.immutable = immutable;
}
private final byte[] data;
private final boolean immutable;
@Override
public IData add(IData other) {
byte[] otherData = other.asByteArray();
byte[] result = Arrays.copyOf(data, data.length + otherData.length);
System.arraycopy(otherData, 0, result, data.length, otherData.length);
return new DataByteArray(result, immutable);
}
public DataByteArray(byte[] data, boolean immutable) {
this.data = data;
this.immutable = immutable;
}
@Override
public IData sub(IData other) {
throw new UnsupportedOperationException("Cannot subtract from a byte array");
}
@Override
public IData add(IData other) {
byte[] otherData = other.asByteArray();
byte[] result = Arrays.copyOf(data, data.length + otherData.length);
System.arraycopy(otherData, 0, result, data.length, otherData.length);
return new DataByteArray(result, immutable);
}
@Override
public IData mul(IData other) {
throw new UnsupportedOperationException("Cannot multiply with an arary");
}
@Override
public IData sub(IData other) {
throw new UnsupportedOperationException("Cannot subtract from a byte array");
}
@Override
public IData div(IData other) {
throw new UnsupportedOperationException("Cannot divide an array");
}
@Override
public IData mul(IData other) {
throw new UnsupportedOperationException("Cannot multiply with an arary");
}
@Override
public IData mod(IData other) {
throw new UnsupportedOperationException("Cannot perform modulo on an array");
}
@Override
public IData div(IData other) {
throw new UnsupportedOperationException("Cannot divide an array");
}
@Override
public IData and(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData mod(IData other) {
throw new UnsupportedOperationException("Cannot perform modulo on an array");
}
@Override
public IData or(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData and(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData xor(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData or(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData neg() {
throw new UnsupportedOperationException("Cannot negate arrays");
}
@Override
public IData xor(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData not() {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData neg() {
throw new UnsupportedOperationException("Cannot negate arrays");
}
@Override
public boolean asBool() {
throw new IllegalDataException("Cannot cast an array to bool");
}
@Override
public IData not() {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public byte asByte() {
throw new IllegalDataException("Cannot cast an array to byte");
}
@Override
public boolean asBool() {
throw new IllegalDataException("Cannot cast an array to bool");
}
@Override
public short asShort() {
throw new IllegalDataException("Cannot cast an array to short");
}
@Override
public byte asByte() {
throw new IllegalDataException("Cannot cast an array to byte");
}
@Override
public int asInt() {
throw new IllegalDataException("Cannot cast an array to int");
}
@Override
public short asShort() {
throw new IllegalDataException("Cannot cast an array to short");
}
@Override
public long asLong() {
throw new IllegalDataException("Cannot cast an array to long");
}
@Override
public int asInt() {
throw new IllegalDataException("Cannot cast an array to int");
}
@Override
public float asFloat() {
throw new IllegalDataException("Cannot cast an array to float");
}
@Override
public long asLong() {
throw new IllegalDataException("Cannot cast an array to long");
}
@Override
public double asDouble() {
throw new IllegalDataException("Cannot cast an array to double");
}
@Override
public float asFloat() {
throw new IllegalDataException("Cannot cast an array to float");
}
@Override
public String asString() {
StringBuilder result = new StringBuilder();
result.append("[");
boolean first = true;
for (byte value : data) {
if (first)
first = false;
else
result.append(", ");
@Override
public double asDouble() {
throw new IllegalDataException("Cannot cast an array to double");
}
result.append(value);
}
result.append("] as byte[]");
return result.toString();
}
@Override
public String asString() {
StringBuilder result = new StringBuilder();
result.append("[");
boolean first = true;
for(byte value : data) {
if(first)
first = false;
else
result.append(", ");
@Override
public List<IData> asList() {
List<IData> result = new ArrayList<IData>();
for (byte value : data) {
result.add(new DataByte(value));
}
return result;
}
result.append(value);
}
result.append("] as byte[]");
return result.toString();
}
@Override
public Map<String, IData> asMap() {
return null;
}
@Override
public List<IData> asList() {
List<IData> result = new ArrayList<IData>();
for(byte value : data) {
result.add(new DataByte(value));
}
return result;
}
@Override
public byte[] asByteArray() {
return data;
}
@Override
public Map<String, IData> asMap() {
return null;
}
@Override
public int[] asIntArray() {
int[] result = new int[data.length];
for (int i = 0; i < result.length; i++) {
result[i] = data[i];
}
return result;
}
@Override
public byte[] asByteArray() {
return data;
}
@Override
public IData getAt(int i) {
return new DataByte(data[i]);
}
@Override
public int[] asIntArray() {
int[] result = new int[data.length];
for(int i = 0; i < result.length; i++) {
result[i] = data[i];
}
return result;
}
@Override
public void setAt(int i, IData value) {
if (immutable) {
throw new UnsupportedOperationException("Cannot modify this byte array");
} else {
data[i] = value.asByte();
}
}
@Override
public IData getAt(int i) {
return new DataByte(data[i]);
}
@Override
public IData memberGet(String name) {
throw new UnsupportedOperationException("byte[] doesn't have members");
}
@Override
public void setAt(int i, IData value) {
if(immutable) {
throw new UnsupportedOperationException("Cannot modify this byte array");
} else {
data[i] = value.asByte();
}
}
@Override
public void memberSet(String name, IData data) {
throw new UnsupportedOperationException("cannot set byte[] members");
}
@Override
public IData memberGet(String name) {
throw new UnsupportedOperationException("byte[] doesn't have members");
}
@Override
public int length() {
return data.length;
}
@Override
public void memberSet(String name, IData data) {
throw new UnsupportedOperationException("cannot set byte[] members");
}
@Override
public boolean contains(IData data) {
return equals(data);
}
@Override
public int length() {
return data.length;
}
@Override
public int compareTo(IData data) {
throw new UnsupportedOperationException("Cannot compare arrays");
}
@Override
public boolean contains(IData data) {
return equals(data);
}
@Override
public boolean equals(IData data) {
return Arrays.equals(this.data, data.asByteArray());
}
@Override
public int compareTo(IData data) {
throw new UnsupportedOperationException("Cannot compare arrays");
}
@Override
public IData immutable() {
if (immutable) {
return this;
} else {
return new DataByteArray(Arrays.copyOf(this.data, this.data.length), true);
}
}
@Override
public boolean equals(IData data) {
return Arrays.equals(this.data, data.asByteArray());
}
@Override
public IData update(IData data) {
return data;
}
@Override
public IData immutable() {
if(immutable) {
return this;
} else {
return new DataByteArray(Arrays.copyOf(this.data, this.data.length), true);
}
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromByteArray(this.data);
}
@Override
public IData update(IData data) {
return data;
}
@Override
public String toString() {
return asString() + " as byte[]";
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromByteArray(this.data);
}
@Override
public String toString() {
return asString() + " as byte[]";
}
}