Commit 3aca56d8 authored by Andre Freyssinet's avatar Andre Freyssinet
Browse files

Code cleaning.

parent e067c94a
/*
* Copyright (C) 2013 - 2017 ScalAgent Distributed Technologies
* Copyright (C) 2013 - 2022 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -26,7 +26,7 @@ import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("serial")
public class EncodedStringList implements Serializable, Encodable {
public final class EncodedStringList implements Serializable, Encodable {
private List<EncodedString> list;
public EncodedStringList() {
......@@ -37,10 +37,12 @@ public class EncodedStringList implements Serializable, Encodable {
return list;
}
@Override
public int getEncodableClassId() {
return EncodableFactoryRepository.ENCODED_STRING_LIST_CLASS_ID;
}
@Override
public int getEncodedSize() throws Exception {
int res = 4;
for (EncodedString str : list) {
......@@ -49,6 +51,7 @@ public class EncodedStringList implements Serializable, Encodable {
return res;
}
@Override
public void encode(Encoder encoder) throws Exception {
encoder.encode32(list.size());
for (EncodedString str : list) {
......@@ -56,6 +59,7 @@ public class EncodedStringList implements Serializable, Encodable {
}
}
@Override
public void decode(Decoder decoder) throws Exception {
int l = decoder.decode32();
list = new ArrayList<EncodedString>(l);
......
/*
* Copyright (C) 2013 ScalAgent Distributed Technologies
* Copyright (C) 2013 - 2022 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -24,7 +24,7 @@ package fr.dyade.aaa.common.encoding;
/**
* Encodable object representing a pair of strings.
*/
public class StringPair implements Encodable {
public final class StringPair implements Encodable {
private EncodedString s1;
......@@ -33,24 +33,27 @@ public class StringPair implements Encodable {
public StringPair() {}
public StringPair(EncodedString s1, EncodedString s2) {
super();
this.s1 = s1;
this.s2 = s2;
}
@Override
public int getEncodableClassId() {
return EncodableFactoryRepository.STRING_PAIR_CLASS_ID;
}
@Override
public int getEncodedSize() {
return s1.getEncodedSize() + s2.getEncodedSize();
}
@Override
public void encode(Encoder encoder) throws Exception {
s1.encode(encoder);
s2.encode(encoder);
}
@Override
public void decode(Decoder decoder) throws Exception {
s1 = new EncodedString();
s1.decode(decoder);
......@@ -60,11 +63,8 @@ public class StringPair implements Encodable {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(s1.getString().length() + 1
+ s2.getString().length());
buf.append(s1);
buf.append('-');
buf.append(s2);
StringBuffer buf = new StringBuffer(s1.getString().length() +1 + s2.getString().length());
buf.append(s1).append('-').append(s2);
return buf.toString();
}
......@@ -100,11 +100,8 @@ public class StringPair implements Encodable {
}
public static class Factory implements EncodableFactory {
public Encodable createEncodable() {
return new StringPair();
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment