de.tsl2.nano.historize.HistorizedInput Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.datastructure Show documentation
Show all versions of tsl2.nano.datastructure Show documentation
optimized implementations for trees, collections, arrays, historized input
/*
* File: $HeadURL$
* Id : $Id$
*
* created by: Thomas Schneider
* created on: Apr 22, 2010
*
* Copyright: (c) Thomas Schneider 2010, all rights reserved
*/
package de.tsl2.nano.historize;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Properties;
import de.tsl2.nano.core.ManagedException;
import de.tsl2.nano.core.util.FileUtil;
/**
* class to handle the historized entries.
*
* @param
* @author Thomas Schneider
* @version $Revision$
*/
public class HistorizedInput extends Properties {
/** serialVersionUID */
private static final long serialVersionUID = -7825644997402507863L;
File file;
Class itemType;
int maxCount;
LinkedHashSet list;
private static final String KEY_NAME_PREFIX = "entry";
/**
* constructor
*
* @param path file path
* @param name historizing name - will be used as file name, too
* @param maxCount maximum count of historized items.
* @param itemType wrapper class to store item into. must have a string constructor!
*/
HistorizedInput(String path, String name, int maxCount, Class itemType) {
super();
this.file = new File(path + FileUtil.getValidFileName(name) + ".hist");
this.itemType = itemType;
this.maxCount = maxCount;
if (file.exists()) {
try {
load(new FileReader(file));
} catch (final Exception e) {
ManagedException.forward(e);
}
}
}
/**
* property values
*
* @return stored entries as simple string values.
*/
public Collection