Alachisoft.NCache.Common.DataStructures.InstantaneousIndex Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Alachisoft.NCache.Common.DataStructures;
import java.util.Iterator;
public class InstantaneousIndex implements Cloneable, Iterable {
private java.util.ArrayList _activitesList = new java.util.ArrayList();
private java.util.HashMap _table = new java.util.HashMap();
private boolean _checkDuplication;
private long privateClockTime;
private long privateMinActivityId;
private long privateMaxActivityId;
public final long getClockTime() {
return privateClockTime;
}
public final void setClockTime(long value) {
privateClockTime = value;
}
public final long getMinActivityId() {
return privateMinActivityId;
}
public final void setMinActivityId(long value) {
privateMinActivityId = value;
}
public final long getMaxActivityId() {
return privateMaxActivityId;
}
public final void setMaxActivityId(long value) {
privateMaxActivityId = value;
}
public final boolean getEnableDuplicationCheck() {
return _checkDuplication;
}
public final void setEnableDuplicationCheck(boolean value) {
_checkDuplication = value;
}
public final void AddEntry(long entryId, T activity) {
if (_checkDuplication) {
_table.put(activity, entryId);
}
_activitesList.add(activity);
if (_activitesList.size() == 1) {
setMinActivityId(entryId);
}
setMaxActivityId(entryId);
}
public final boolean CheckDuplication(T activity) {
return _table.containsKey(activity);
}
public final java.util.ArrayList GetClientActivites(long lastEnteryId) {
java.util.ArrayList clientActivities = new java.util.ArrayList();
if (lastEnteryId < getMinActivityId()) {
return _activitesList;
} else {
if (lastEnteryId < getMaxActivityId()) {
int startingIndex = (int) (lastEnteryId - getMinActivityId()) + 1;
int length = (int) (getMaxActivityId() - lastEnteryId);
return getRange(_activitesList, startingIndex, length);
}
}
return clientActivities;
}
private java.util.ArrayList getRange(java.util.ArrayList list, int start, int last) {
java.util.ArrayList temp = new java.util.ArrayList();
for (int x = start; x <= last; x++) {
temp.add(list.get(x));
}
return temp;
}
@Override
public boolean equals(Object obj) {
InstantaneousIndex other = (InstantaneousIndex) obj;
if (other != null && other.getClockTime() == this.getClockTime()) {
return true;
}
return false;
}
@Override
public int hashCode() {
return super.hashCode();
}
public final Object clone() {
InstantaneousIndex clone = new InstantaneousIndex();
clone._activitesList.addAll(getRange(this._activitesList, 0, _activitesList.size()));
return clone;
}
public final java.util.Iterator GetEnumerator() {
return _activitesList.iterator();
}
// private java.util.Iterator GetEnumerator()
// {
// return _activitesList.iterator();
// }
@Override
public Iterator iterator() {
return _activitesList.iterator();
}
}