AlphaCharDocument.java 566B

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