Added new file detection in FilesLineIterator.

This commit is contained in:
Christian P. MOMON 2024-07-20 02:59:17 +02:00
parent d453979eef
commit 1253e22ce1

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Christian Pierre MOMON <christian@momon.org>
* Copyright (C) 2022-2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of StatoolInfos, simple service statistics tool.
*
@ -34,6 +34,7 @@ public class FilesLineIterator implements Iterator<String>
private Iterator<File> fileIterator;
private LineIterator lineIterator;
private boolean newFile;
private boolean print;
/**
@ -44,9 +45,7 @@ public class FilesLineIterator implements Iterator<String>
*/
public FilesLineIterator(final File source)
{
this.fileIterator = new Files(source).iterator();
this.lineIterator = null;
setPrintOn();
this(new Files(source));
}
/**
@ -59,9 +58,21 @@ public class FilesLineIterator implements Iterator<String>
{
this.fileIterator = source.iterator();
this.lineIterator = null;
this.newFile = true;
setPrintOn();
}
/**
* Close.
*/
public void close()
{
if (this.lineIterator != null)
{
this.lineIterator.close();
}
}
/**
* Forward.
*/
@ -82,6 +93,7 @@ public class FilesLineIterator implements Iterator<String>
System.out.println("Iterating file [" + file.getAbsolutePath() + "]");
}
this.lineIterator = new LineIterator(file);
this.newFile = true;
}
else
{
@ -103,6 +115,7 @@ public class FilesLineIterator implements Iterator<String>
System.out.println("Iterating file [" + file.getAbsolutePath() + "]");
}
this.lineIterator = new LineIterator(file);
this.newFile = true;
}
else
{
@ -123,6 +136,22 @@ public class FilesLineIterator implements Iterator<String>
}
}
/**
* Gets the current file.
*
* @return the current file
*/
public File getCurrentFile()
{
File result;
forward();
result = this.lineIterator.getFile();
//
return result;
}
/* (non-Javadoc)
* @see java.util.Iterator#hasNext()
*/
@ -146,6 +175,21 @@ public class FilesLineIterator implements Iterator<String>
return result;
}
/**
* Checks if is new file.
*
* @return true, if is new file
*/
public boolean isNewFile()
{
boolean result;
result = this.newFile;
//
return result;
}
/* (non-Javadoc)
* @see java.util.Iterator#next()
*/
@ -156,7 +200,6 @@ public class FilesLineIterator implements Iterator<String>
try
{
forward();
if (this.lineIterator == null)
@ -166,6 +209,7 @@ public class FilesLineIterator implements Iterator<String>
else
{
result = this.lineIterator.next();
this.newFile = false;
}
}
catch (IOException exception)