package rocks.zipcode; import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author leon on 16/11/2018. */ public class AlphaCharDocument extends Document { public AlphaCharDocument(String fileName) throws IOException { super(fileName); } @Override public void write(String contentToBeWritten) throws IOException { if (this.isAlpha(contentToBeWritten)){ super.write(contentToBeWritten); }else{ throw new IllegalArgumentException(); } } private Boolean isAlpha(String s) { // boolean allLetters = s.chars().allMatch(Character::isLetter); // return allLetters; // return (s.matches("[a-zA-Z]+")); Pattern pattern = Pattern.compile("[a-z]", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(s); boolean b = matcher.find(); return b; } }