Skip to content

Commit

Permalink
cleaning.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcGuiot committed Sep 5, 2024
1 parent 183e4e7 commit 182767e
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.concurrent.ConcurrentHashMap;

public class DefaultGlobUnionArrayField extends AbstractField implements GlobArrayUnionField {
private Map<String, GlobType> targetTypes;
private final Map<String, GlobType> targetTypes;

public DefaultGlobUnionArrayField(String name, GlobType globType, Collection<GlobType> targetTypes,
int index, boolean isKeyField, final int keyIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.concurrent.ConcurrentHashMap;

public class DefaultGlobUnionField extends AbstractField implements GlobUnionField {
private Map<String, GlobType> targetTypes;
private final Map<String, GlobType> targetTypes;

public DefaultGlobUnionField(String name, GlobType globType, Collection<GlobType> targetTypes,
int index, boolean isKeyField, final int keyIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public DefaultAnnotations(Glob[] annotations) {

public DefaultAnnotations(Annotations annotations) {
annotations.streamAnnotations()
.forEach(annotation -> this.annotations.put(annotation.getKey(), annotation)
);
.forEach(annotation -> this.annotations.put(annotation.getKey(), annotation));
}

public MutableAnnotations addAnnotation(Glob glob) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Collection;

public class DefaultFieldFactory {
private DefaultGlobType type;
private final DefaultGlobType type;

public DefaultFieldFactory(DefaultGlobType type) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

public class DefaultGlobFactory implements GlobFactory {
private final GlobType type;
private final GlobGetAccessor getAccessor[];
private final GlobSetAccessor setAccessor[];
private final GlobGetAccessor[] getAccessor;
private final GlobSetAccessor[] setAccessor;

public DefaultGlobFactory(GlobType type) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public boolean isSet(Field field) throws ItemNotFound {
abstract public void clearSetAt(int index);

public MutableGlob unset(Field field) {
values[field.getIndex()] = null;
clearSetAt(field.getIndex());
int index = field.getIndex();
values[index] = null;
clearSetAt(index);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public String toString() {
return buffer.toString();
}

// we don't want to add a dependency on any json framework here : we output a json like string here => need help : may be a bad idea
private void toString(StringBuilder buffer) {
buffer.append("{ \"_kind\":\"").append(escapeQuote(getType().getName())).append("\"");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.nio.channels.SeekableByteChannel;

public class ByteBufferInputStream extends InputStream {
ByteBuffer byteBuffer;
SeekableByteChannel channel;
private final ByteBuffer byteBuffer;
private final SeekableByteChannel channel;
boolean eofReach = false;

public ByteBufferInputStream(ByteBuffer byteBuffer, SeekableByteChannel channel) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public int[] readIntArray() {
if (length == -1) {
return null;
}
int array[] = new int[length];
int[] array = new int[length];
for (int i = 0; i < array.length; i++) {
array[i] = readNotNullInt();
}
Expand All @@ -126,7 +126,7 @@ public long[] readLongArray() {
if (length == -1) {
return null;
}
long array[] = new long[length];
long[] array = new long[length];
for (int i = 0; i < array.length; i++) {
array[i] = readNotNullLong();
}
Expand All @@ -138,7 +138,7 @@ public double[] readDoubleArray() {
if (length == -1) {
return null;
}
double array[] = new double[length];
double[] array = new double[length];
for (int i = 0; i < array.length; i++) {
array[i] = readNotNullDouble();
}
Expand All @@ -151,7 +151,7 @@ public boolean[] readBooleanArray() {
if (length == -1) {
return null;
}
boolean array[] = new boolean[length];
boolean[] array = new boolean[length];
for (int i = 0; i < array.length; i++) {
array[i] = readBoolean();
}
Expand All @@ -176,7 +176,7 @@ public String[] readStringArray() {
if (length == -1) {
return null;
}
String array[] = new String[length];
String[] array = new String[length];
for (int i = 0; i < array.length; i++) {
array[i] = readUtf8String();
}
Expand All @@ -187,8 +187,8 @@ public void close() {
}

static class FieldReader implements FieldVisitor {
private ByteBufferSerializationInput input;
private FieldValuesBuilder builder;
private final ByteBufferSerializationInput input;
private final FieldValuesBuilder builder;

public FieldReader(ByteBufferSerializationInput input, FieldValuesBuilder builder) {
this.input = input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Map;

public class CompressedSerializationOutput extends DefaultSerializationOutput {
private Map<String, Integer> strings = new HashMap<String, Integer>();
private final Map<String, Integer> strings = new HashMap<String, Integer>();
private int count = 0;

public CompressedSerializationOutput(OutputStream outputStream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.*;

public class DefaultSerializationInput implements SerializedInput {
public static final String ORG_GLOBSFRAMWORK_SERIALIZATION_MAX_LEN = "org.globsframwork.serialization.max.len";
public static final int MAX_SIZE_FOR_BYTES = Integer.getInteger(ORG_GLOBSFRAMWORK_SERIALIZATION_MAX_LEN, 512 * 1024);
private InputStream inputStream;
private final InputStream inputStream;
private final InputStreamFieldVisitor fieldVisitorInput = new InputStreamFieldVisitor();
public int count;

Expand Down Expand Up @@ -108,7 +109,7 @@ public int[] readIntArray() {
if (length == -1) {
return null;
}
int array[] = new int[length];
int[] array = new int[length];
for (int i = 0; i < array.length; i++) {
array[i] = readNotNullInt();
}
Expand All @@ -120,7 +121,7 @@ public long[] readLongArray() {
if (length == -1) {
return null;
}
long array[] = new long[length];
long[] array = new long[length];
for (int i = 0; i < array.length; i++) {
array[i] = readNotNullLong();
}
Expand All @@ -132,7 +133,7 @@ public double[] readDoubleArray() {
if (length == -1) {
return null;
}
double array[] = new double[length];
double[] array = new double[length];
for (int i = 0; i < array.length; i++) {
array[i] = readNotNullDouble();
}
Expand All @@ -145,7 +146,7 @@ public boolean[] readBooleanArray() {
if (length == -1) {
return null;
}
boolean array[] = new boolean[length];
boolean[] array = new boolean[length];
for (int i = 0; i < array.length; i++) {
array[i] = readBoolean();
}
Expand All @@ -157,7 +158,7 @@ public BigDecimal[] readBigDecimalArray() {
if (length == -1) {
return null;
}
BigDecimal array[] = new BigDecimal[length];
BigDecimal[] array = new BigDecimal[length];
for (int i = 0; i < array.length; i++) {
array[i] = readBigDecimal();
}
Expand All @@ -170,7 +171,7 @@ public String[] readStringArray() {
if (length == -1) {
return null;
}
String array[] = new String[length];
String[] array = new String[length];
for (int i = 0; i < array.length; i++) {
array[i] = readUtf8String();
}
Expand All @@ -186,8 +187,8 @@ public void close() {
}

static class FieldReader implements FieldVisitor {
private DefaultSerializationInput input;
private FieldValuesBuilder builder;
private final DefaultSerializationInput input;
private final FieldValuesBuilder builder;

public FieldReader(DefaultSerializationInput input, FieldValuesBuilder builder) {
this.input = input;
Expand Down Expand Up @@ -302,8 +303,8 @@ public BigDecimal readBigDecimal() {
}

static class FieldWithPreviousReader implements FieldVisitor {
private DefaultSerializationInput input;
private FieldValuesWithPreviousBuilder builder;
private final DefaultSerializationInput input;
private final FieldValuesWithPreviousBuilder builder;

public FieldWithPreviousReader(DefaultSerializationInput input, FieldValuesWithPreviousBuilder builder) {
this.input = input;
Expand Down Expand Up @@ -505,11 +506,7 @@ public String readUtf8String() {
if (bytes == null) {
return null;
}
try {
return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new InvalidFormat(e);
}
return new String(bytes, StandardCharsets.UTF_8);
}

public Boolean readBoolean() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import static org.globsframework.utils.serialization.DefaultSerializationInput.ORG_GLOBSFRAMWORK_SERIALIZATION_MAX_LEN;

public class DefaultSerializationOutput implements SerializedOutput, ChangeSetVisitor {
private OutputStream outputStream;
private FieldValues.Functor fieldValuesFunctor = new FieldValuesFunctor();
private FieldValuesWithPrevious.FunctorWithPrevious fieldValuesWithPreviousFunctor = new FieldValuesWithPreviousFunctor();
private final OutputStream outputStream;
private final FieldValues.Functor fieldValuesFunctor = new FieldValuesFunctor();
private final FieldValuesWithPrevious.FunctorWithPrevious fieldValuesWithPreviousFunctor = new FieldValuesWithPreviousFunctor();

DefaultSerializationOutput(OutputStream outputStream) {
this.outputStream = outputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.time.ZonedDateTime;

public class SerializationInputChecker implements SerializedInput {
private SerializedInput serializedInput;
private final SerializedInput serializedInput;

public SerializationInputChecker(SerializedInput serializedInput) {
this.serializedInput = serializedInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.io.OutputStream;

public class SerializedInputOutputFactory {
private static boolean checked = false;
private static final boolean checked = false;

static public SerializedOutput init(OutputStream outputStream) {
DefaultSerializationOutput serializationOutput = new DefaultSerializationOutput(outputStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.io.InputStream;

public class YANBuffereInputStream extends InputStream {
private byte[] buffer;
private final byte[] buffer;
private int currentPos;
private int count;
private InputStream inputStream;
private final InputStream inputStream;

public YANBuffereInputStream(InputStream inputStream) {
this(inputStream, 8 * 1024);
Expand All @@ -31,10 +31,10 @@ public int read() throws IOException {
return buffer[currentPos++] & 0xFF;
}

public int read(byte b[], int off, int len) throws IOException {
int availlable = count - currentPos;
if (availlable > 0) {
int length = availlable > len ? len : availlable;
public int read(byte[] b, int off, int len) throws IOException {
int available = count - currentPos;
if (available > 0) {
int length = Math.min(available, len);
System.arraycopy(buffer, currentPos, b, off, length);
currentPos += length;
return length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testEncodesPrimitiveTypes() throws Exception {
assertNull(input.readInteger());
assertEquals(1L, input.readNotNullLong());
assertNull(input.readLong());
assertTrue(Arrays.equals(new byte[]{2, 2, 3, 4}, input.readBytes()));
assertArrayEquals(new byte[]{2, 2, 3, 4}, input.readBytes());
assertNull(input.readBytes());
assertEquals(1.3, input.readDouble(), 0.001);
assertNull(input.readDouble());
Expand Down Expand Up @@ -67,8 +67,8 @@ public void testEncodesGlobs() throws Exception {
assertEquals(1, decodedGlob.get(ID).intValue());
assertEquals(linkId, decodedGlob.get(LINK_ID).intValue());
assertEquals(name, decodedGlob.get(NAME));
assertTrue(Arrays.equals(blob, decodedGlob.get(PASSWORD)));
assertEquals(present, decodedGlob.get(PRESENT).booleanValue());
assertArrayEquals(blob, decodedGlob.get(PASSWORD));
assertEquals(present, decodedGlob.get(PRESENT));
assertEquals(value, decodedGlob.get(VALUE), 0.001);
}
}

0 comments on commit 182767e

Please sign in to comment.