Commit 82f91a1c authored by Andre Freyssinet's avatar Andre Freyssinet
Browse files

Code cleaning.

parent c3d2d769
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2006 - 2020 ScalAgent Distributed Technologies
* Copyright (C) 2006 - 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
......@@ -47,6 +47,10 @@ import fr.dyade.aaa.common.encoding.Encoder;
@SuppressWarnings("serial")
public class Properties implements Serializable, Cloneable, Encodable {
/* ***** ***** ***** ***** ***** ***** ***** *****
* Property implementation
* ***** ***** ***** ***** ***** ***** ***** ***** */
/** The total number of entries in the hash table. */
private transient int count;
/** The hash table data. */
......@@ -60,15 +64,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
/** The load factor for the hashtable. */
private transient float loadFactor;
/**
* The number of times this Properties has been structurally modified
* Structural modifications are those that change the number of entries in
* the Properties or otherwise modify its internal structure (e.g.,
* rehash). This field is used to make iterators on Collection-views of
* the Properties fail-fast. (See ConcurrentModificationException).
*/
private transient int modCount = 0;
/**
* Constructs a new, empty hashtable with the specified initial
......@@ -215,7 +210,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
int newCapacity = oldCapacity * 2 + 1;
Entry newMap[] = new Entry[newCapacity];
modCount++;
threshold = (int)(newCapacity * loadFactor);
table = newMap;
......@@ -283,7 +277,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
}
}
modCount++;
if (count >= threshold) {
// Rehash the table if the threshold is exceeded
rehash();
......@@ -314,7 +307,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index], prev = null ; e != null ; prev = e, e = e.next) {
if ((e.hash == hash) && e.key.equals(key)) {
modCount++;
if (prev != null) {
prev.next = e.next;
} else {
......@@ -334,7 +326,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
*/
public synchronized void clear() {
Entry tab[] = table;
modCount++;
for (int index = tab.length; --index >= 0; )
tab[index] = null;
count = 0;
......@@ -355,7 +346,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
t.table[i] = (table[i] != null)
? (Entry)table[i].clone() : null;
}
t.modCount = 0;
return t;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
......@@ -422,71 +412,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
return h;
}
// /**
// * Save the state of the Properties to a stream (i.e., serialize it).
// *
// * @serialData The <i>capacity</i> of the Properties (the length of the
// * bucket array) is emitted (int), followed by the
// * <i>size</i> of the Properties (the number of key-value
// * mappings), followed by the key (Object) and value (Object)
// * for each key-value mapping represented by the Properties
// * The key-value mappings are emitted in no particular order.
// */
// private synchronized void writeObject(java.io.ObjectOutputStream s)
// throws IOException
// {
// // Write out the length, threshold, loadfactor
// s.defaultWriteObject();
// // Write out length, count of elements and then the key/value objects
// s.writeInt(table.length);
// s.writeInt(count);
// for (int index = table.length-1; index >= 0; index--) {
// Entry entry = table[index];
// while (entry != null) {
// s.writeObject(entry.key);
// s.writeObject(entry.value);
// entry = entry.next;
// }
// }
// }
// /**
// * Reconstitute the Properties from a stream (i.e., deserialize it).
// */
// private void readObject(java.io.ObjectInputStream s)
// throws IOException, ClassNotFoundException
// {
// // Read in the length, threshold, and loadfactor
// s.defaultReadObject();
// // Read the original length of the array and number of elements
// int origlength = s.readInt();
// int elements = s.readInt();
// // Compute new size with a bit of room 5% to grow but
// // No larger than the original size. Make the length
// // odd if it's large enough, this helps distribute the entries.
// // Guard against the length ending up zero, that's not valid.
// int length = (int)(elements * loadFactor) + (elements / 20) + 3;
// if (length > elements && (length & 1) == 0)
// length--;
// if (origlength > 0 && length > origlength)
// length = origlength;
// table = new Entry[length];
// count = 0;
// // Read the number of elements and then all the key/value objects
// for (; elements > 0; elements--) {
// String key = (String) s.readObject();
// Object value = s.readObject();
// put(key, value); // synch could be eliminated for performance
// }
// }
/**
* Properties collision list.
*/
......@@ -560,27 +485,11 @@ public class Properties implements Serializable, Cloneable, Encodable {
Entry[] table = Properties.this.table;
int index = table.length;
Entry entry = null;
// Entry lastReturned = null;
int type;
// TODO (AF): To remove.
// /**
// * Indicates whether this Enumerator is serving as an Iterator
// * or an Enumeration. (true -> Iterator).
// */
// boolean iterator;
// TODO (AF): To remove.
// /**
// * The modCount value that the iterator believes that the backing
// * List should have. If this expectation is violated, the iterator
// * has detected concurrent modification.
// */
// protected int expectedModCount = modCount;
Enumerator(int type, boolean iterator) {
this.type = type;
// this.iterator = iterator;
}
public boolean hasMoreElements() {
......@@ -607,55 +516,12 @@ public class Properties implements Serializable, Cloneable, Encodable {
entry = et;
index = i;
if (et != null) {
// Entry e = lastReturned = entry;
Entry e = entry;
entry = e.next;
return type == KEYS ? e.key : (type == VALUES ? e.value : e);
}
throw new NoSuchElementException("Properties Enumerator");
}
// TODO (AF): To remove.
// // Iterator methods
// public boolean hasNext() {
// return hasMoreElements();
// }
//
// public Object next() {
// if (modCount != expectedModCount)
// throw new ConcurrentModificationException();
// return nextElement();
// }
//
// public void remove() {
// if (!iterator)
// throw new UnsupportedOperationException();
// if (lastReturned == null)
// throw new IllegalStateException("Properties Enumerator");
// if (modCount != expectedModCount)
// throw new ConcurrentModificationException();
//
// synchronized(Properties.this) {
// Entry[] tab = Properties.this.table;
// int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length;
//
// for (Entry e = tab[index], prev = null; e != null;
// prev = e, e = e.next) {
// if (e == lastReturned) {
// modCount++;
// expectedModCount++;
// if (prev == null)
// tab[index] = e.next;
// else
// prev.next = e.next;
// count--;
// lastReturned = null;
// return;
// }
// }
// throw new ConcurrentModificationException();
// }
// }
}
private static EmptyEnumerator emptyEnumerator = new EmptyEnumerator();
......@@ -703,7 +569,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
*/
public void writeTo(OutputStream os) throws IOException {
StreamUtil.writeTo(count, os);
// logger.log(BasicLevel.DEBUG, "write count=" + count);
if (count == 0) return;
for (int index = table.length-1; index >= 0; index--) {
Entry entry = table[index];
......@@ -711,7 +576,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
while (entry != null) {
StreamUtil.writeTo(entry.key, os);
StreamUtil.writeObjectTo(entry.value, os);
// logger.log(BasicLevel.DEBUG, "write entry=" + entry.key + ", " + entry.value);
entry = entry.next;
}
}
......@@ -726,7 +590,6 @@ public class Properties implements Serializable, Cloneable, Encodable {
*/
public static Properties readFrom(InputStream is) throws IOException {
int count = StreamUtil.readIntFrom(is);
// logger.log(BasicLevel.DEBUG, "read count=" + count);
if (count == -1) return null;
Properties p = new Properties(((4*count)/3) +1);
......@@ -740,10 +603,8 @@ public class Properties implements Serializable, Cloneable, Encodable {
for (int i=0; i<count; i++) {
key = StreamUtil.readStringFrom(is);
value = StreamUtil.readObjectFrom(is);
// logger.log(BasicLevel.DEBUG, "read entry=" + key + ", " + value);
put(key, value);
}
// logger.log(BasicLevel.DEBUG, "read this.count=" + this.count);
}
/* ***** ***** ***** ***** ***** ***** ***** *****
......@@ -756,19 +617,19 @@ public class Properties implements Serializable, Cloneable, Encodable {
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
int count = StreamUtil.readIntFrom(in);
// logger.log(BasicLevel.DEBUG, "read count=" + count);
if (count <= 0) return;
// try {
initialize(((4*count)/3) +1, 0.75f);
readFrom(in, count);
// } catch (Exception exc) {
// logger.log(BasicLevel.DEBUG, "read", exc);
// }
initialize(((4*count)/3) +1, 0.75f);
readFrom(in, count);
}
/* ***** ***** ***** ***** ***** ***** ***** *****
* Encodable interface
* ***** ***** ***** ***** ***** ***** ***** ***** */
@Override
public int getEncodedSize() throws IOException {
int size = 0;
size += INT_ENCODED_SIZE;
int size = INT_ENCODED_SIZE;
for (int index = table.length-1; index >= 0; index--) {
Entry entry = table[index];
......@@ -782,10 +643,12 @@ public class Properties implements Serializable, Cloneable, Encodable {
return size;
}
@Override
public int getEncodableClassId() {
return EncodableFactoryRepository.PROPERTIES_CLASS_ID;
}
@Override
public void encode(Encoder encoder) throws Exception {
encoder.encodeUnsignedInt(count);
for (int index = table.length-1; index >= 0; index--) {
......@@ -799,6 +662,7 @@ public class Properties implements Serializable, Cloneable, Encodable {
}
}
@Override
public void decode(Decoder decoder) throws Exception {
int count = decoder.decodeUnsignedInt();
if (count == -1) return;
......
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