Created
May 29, 2020 03:08
-
-
Save LouiS0616/49075fe22ac120a8a8098901738c9fcb to your computer and use it in GitHub Desktop.
突合処理用のラッパー群;普通に書くのが面倒なので
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.util.Iterator; | |
import java.util.NoSuchElementException; | |
public class BRIterator implements Iterator<String> { | |
private final BufferedReader br; | |
public BRIterator(BufferedReader bufferedReader) { | |
br = bufferedReader; | |
} | |
@Override | |
public String next() { | |
try { | |
if(hasNext()) { return br.readLine(); } | |
} | |
catch(IOException e) {} | |
throw new NoSuchElementException(); | |
} | |
@Override | |
public boolean hasNext() { | |
try { | |
return br.ready(); | |
} | |
catch(IOException e) { | |
return false; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Iterator; | |
import java.util.NoSuchElementException; | |
public class EOFWrapper<T> { | |
private final Iterator<T> it; | |
public EOFWrapper(Iterator<T> it) { | |
this.it = it; | |
this.isEOF = !it.hasNext(); | |
} | |
// | |
private boolean isEOF; | |
public boolean isEOF() { return isEOF; } | |
public T next() { | |
try { | |
return it.next(); | |
} | |
catch(NoSuchElementException e) { | |
isEOF = true; | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment