From 1253e22ce1e047e6f754ef08b8139862662c4f1f Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 20 Jul 2024 02:59:17 +0200 Subject: [PATCH] Added new file detection in FilesLineIterator. --- .../statoolinfos/util/FilesLineIterator.java | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/fr/devinsy/statoolinfos/util/FilesLineIterator.java b/src/fr/devinsy/statoolinfos/util/FilesLineIterator.java index ce8fdfc..a78c529 100644 --- a/src/fr/devinsy/statoolinfos/util/FilesLineIterator.java +++ b/src/fr/devinsy/statoolinfos/util/FilesLineIterator.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Christian Pierre MOMON + * Copyright (C) 2022-2024 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -34,6 +34,7 @@ public class FilesLineIterator implements Iterator private Iterator fileIterator; private LineIterator lineIterator; + private boolean newFile; private boolean print; /** @@ -44,9 +45,7 @@ public class FilesLineIterator implements Iterator */ 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 { 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 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 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 } } + /** + * 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 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 try { - forward(); if (this.lineIterator == null) @@ -166,6 +209,7 @@ public class FilesLineIterator implements Iterator else { result = this.lineIterator.next(); + this.newFile = false; } } catch (IOException exception)