| 123456789101112131415161718192021222324252627282930313233343536373839 |
- package rocks.zipcode;
-
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
-
- /**
- * @author leon on 18/11/2018.
- */
- public class SpecialCharDocument extends Document {
- public SpecialCharDocument(String fileName) throws IOException {
- super(fileName);
- }
-
- @Override
- public void write(String contentToBeWritten) throws IOException {
-
- if (this.isSpecialCharacters(contentToBeWritten)){
- super.write(contentToBeWritten);
-
-
- }else{
-
- throw new IllegalArgumentException();
- }
- }
-
- private Boolean isSpecialCharacters(String s) {
-
- Pattern pattern = Pattern.compile("[$&+,:;=?@#|'<>.^*()%!-]", Pattern.CASE_INSENSITIVE);
- Matcher matcher = pattern.matcher(s);
- boolean b = matcher.find();
- return b;
-
- }
- }
|