@@ -0,0 +1,1608 @@
+package ru.nsu.ccfit.bogush.chat.server;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0A%0Apublic class ConcurrentRollingArray%3CE%3E %7B%0A%09private Object%5B%5D elements;%0A%09private final int capacity;%0A%09private int last = -1;%0A%09private boolean full = false;%0A%0A%09public ConcurrentRollingArray(int capacity) %7B%0A%09%09if (capacity %3C= 0) throw new IllegalArgumentException(%22Capacity must be positive%22);%0A%09%09this.capacity = capacity;%0A%09%09elements = new Object%5Bcapacity%5D;%0A%09%7D%0A%0A%09public int getCapacity() %7B%0A%09%09return capacity;%0A%09%7D%0A%0A%09public synchronized int size() %7B%0A%09%09return full ? capacity : last + 1;%0A%09%7D%0A%0A%09@SuppressWarnings(%22unchecked%22)%0A%09public synchronized E get(int index) %7B%0A%09%09int i = last == capacity-1 ? (last + 1 + index) %25 capacity : index;%0A%09%09return (E) elements%5Bi%5D;%0A%09%7D%0A%0A%09public synchronized Object%5B%5D toArray() %7B%0A%09%09ArrayList%3CObject%3E arrayList = new ArrayList%3C%3E(size());%0A%09%09if (full) %7B%0A%09%09%09arrayList.addAll(Arrays.asList(elements).subList(last + 1, capacity));%0A%09%09%09arrayList.addAll(Arrays.asList(elements).subList(0, last + 1));%0A%09%09%7D else %7B%0A%09%09%09arrayList.addAll(Arrays.asList(elements).subList(0, last + 1));%0A%09%09%7D%0A%09%09return arrayList.toArray();%0A%09%7D%0A%0A%09@SuppressWarnings(%22unchecked%22)%0A%09public synchronized %3CT%3E T%5B%5D toArray(T%5B%5D a) %7B%0A%09%09Object%5B%5D data = toArray();%0A%09%09if (a.length %3C size())%0A%09%09%09// Make a new array of a's runtime type, but my contents:%0A%09%09%09return (T%5B%5D) Arrays.copyOf(data, size(), a.getClass());%0A%09%09System.arraycopy(data, 0, a, 0, size());%0A%09%09if (a.length %3E size())%0A%09%09%09a%5Bsize()%5D = null;%0A%09%09return a;%0A%09%7D%0A%0A%09public synchronized void add(E e) %7B%0A%09%09last++;%0A%09%09if (last %3E= capacity) %7B%0A%09%09%09last = 0;%0A%09%09%09full = true;%0A%09%09%7D%0A%09%09elements%5Blast%5D = e;%0A%09%7D%0A%7D%0A

Implement ConcurrentRollingArray for storing message history