use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class CommandHistory method save.
/**
* Save the state to an ObjectOutputStream, let someone else worry where
* this stream came from and how to handle error / exception making sure the
* stream is closed no matter what.
*/
private void save(ObjectOutputStream out) throws IOException {
out.writeInt(maxSize);
out.writeInt(size());
for (Entry entry : history) {
out.writeObject(entry);
}
}
use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class CommandHistory method load.
/**
* Load the state from an InputOutputStream, let someone else worry where
* this stream came from and how to handle error / exception making sure the
* stream is closed no matter what.
* @throws ClassNotFoundException
* @throws IOException
*/
private void load(ObjectInputStream in) throws IOException, ClassNotFoundException {
int newMaxSize = in.readInt();
Entry[] elements = new Entry[in.readInt()];
for (int i = 0; i < elements.length; i++) {
elements[i] = (Entry) in.readObject();
}
// We could do this in one go, but it is slightly nicer not to modify
// the state of this history object until we are successful reading
// all the elements.
maxSize = newMaxSize;
history = new LinkedList<Entry>();
for (Entry element : elements) {
history.add(element);
}
isDirty = false;
}
use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class CommandHistoryTest method testSaveLoad.
public void testSaveLoad() throws Exception {
saveFile = new File("saveit.gch");
CommandHistory hist = new CommandHistory("test", "test", false);
hist.add(new Entry("run-app foo", "kris"));
assertFalse(hist.isEmpty());
assertEquals(new Entry("run-app foo", "kris"), hist.getLast());
hist.add(new Entry("run-app bar", "nieraj"));
assertFalse(hist.isEmpty());
assertEquals(new Entry("run-app bar", "nieraj"), hist.getLast());
assertEquals(2, hist.size());
assertTrue(hist.isDirty());
hist.save(saveFile);
assertFalse(hist.isDirty());
hist = new CommandHistory("test", "test", false);
assertTrue(hist.isEmpty());
hist.load(saveFile);
assertFalse(hist.isDirty());
assertEquals(2, hist.size());
assertIterator(hist, new Entry("run-app bar", "nieraj"), new Entry("run-app foo", "kris"));
}
use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class CommandHistoryTest method testAddElements.
public void testAddElements() throws Exception {
CommandHistory hist = new CommandHistory("test", "test", false);
assertFalse(hist.isDirty());
hist.add(new Entry("run-app foo", "kris"));
assertTrue(hist.isDirty());
assertFalse(hist.isEmpty());
assertEquals(new Entry("run-app foo", "kris"), hist.getLast());
hist.add(new Entry("run-app bar", "nieraj"));
assertTrue(hist.isDirty());
assertFalse(hist.isEmpty());
assertEquals(new Entry("run-app bar", "nieraj"), hist.getLast());
}
use of org.springsource.ide.eclipse.commons.core.Entry in project eclipse-integration-commons by spring-projects.
the class CommandHistory method toArray.
/**
* Returns an array of the elements in the history, with the newest item at
* position 0.
*/
public Entry[] toArray() {
Entry[] result = new Entry[size()];
int i = 0;
for (Entry entry : this) {
result[i++] = entry;
}
return result;
}
Aggregations