NumericCharDocument.java 547B

12345678910111213141516171819202122232425
  1. package rocks.zipcode;
  2. import java.io.IOException;
  3. /**
  4. * @author leon on 16/11/2018.
  5. */
  6. public class NumericCharDocument extends Document {
  7. public NumericCharDocument(String fileName) throws IOException {
  8. super(fileName);
  9. }
  10. @Override
  11. public void write(String contentToBeWritten) {
  12. if (isNumeric(contentToBeWritten)) {
  13. super.write(contentToBeWritten);
  14. } else throw new IllegalArgumentException();
  15. }
  16. private Boolean isNumeric(String s) {
  17. return s.matches("[0-9]*");
  18. }
  19. }