{
try
{
int dotIndex = f.getName().indexOf('.');
String unextendedName = (dotIndex > 0) ? f.getName().substring(0, dotIndex) : f.getName();
CCDB2Instance instance = new CCDB2Instance(this, f.getParentFile(), unextendedName, fParameters.getBackgroundPutLength());
if ( (System.currentTimeMillis() - instance.getCreationTime()) < (fParameters.getMaxAgeMilliseconds() * 2) )
{
localList.add(instance);
}
else
{
instance.delete();
}
}
catch ( CCDB2Instance.OldFileException e )
{
System.out.println(e.getMessage());
}
catch ( IOException e )
{
log("", e, true);
}
}
Collections.sort
(
localList,
new Comparator<CCDB2Instance>()
{
@Override
public int compare(CCDB2Instance o1, CCDB2Instance o2)
{
long diff = o1.getCreationTime() - o2.getCreationTime();
return (diff < 0) ? -1 : ((diff > 0) ? 1 : 0);
}
}
);
if ( localList.size() == 0 )
{
CCDB2Instance newInstance = makeNewInstance();
localList.add(newInstance);
}
while ( localList.size() > fParameters.getMaxInstances() )
{
CCDB2Instance instance = localList.remove(0);
instance.delete();
}
CCDB2InstanceLoader loader = new CCDB2InstanceLoader
(
this,
localList,
new CCDB2InstanceLoader.ProcessDriver()
{
@Override
public void process(CCDB2Instance instance, AtomicInteger percentDone) throws IOException
{
instance.loadFile(percentDone);
}
}
);
log("Loading...", null, true);
loader.load();