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
public class Application { | |
public static void main(String[] args) { | |
Path file = Path.of(args[0]); | |
DocumentType.forPath(file).processFile(file); | |
} | |
} |
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
public interface Processor { | |
void processFile(Path file); | |
} |
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
public class Processor { | |
public void processFile(Path file) { | |
switch (DocumentType.forPath(file)) { | |
case TXT: | |
processTextFile(file); | |
break; | |
case MD: | |
processMarkdownFile(file); | |
break; | |
case HTML: |
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
public enum DocumentType { | |
TXT("txt", "text"), | |
MD("md", "markdown"), | |
HTML("html", "htm"); | |
String[] extensions; | |
DocumentType(String... extensions) { | |
this.extensions = Arrays.copyOf(extensions, extensions.length); | |
} |
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
public class Application { | |
public static void main(String[] args) { | |
new Processor().processFile(Path.of(args[0])); | |
} | |
} |
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
public class Processor { | |
public void processFile(Path file) { | |
switch (FileNameHelper.getLowercaseExtension(file)) { | |
case DocumentType.TXT: | |
case DocumentType.TEXT: | |
processTextFile(file); | |
break; | |
case DocumentType.MD: | |
case DocumentType.MARKDOWN: | |
processMarkdownFile(file); |
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
public class CommentController { | |
// ... fields and constructor omitted ... | |
public Comment postComment(PostCommentPayload payload) { | |
// .. validation omitted ... | |
CommentUserGroup cug = cugDao.find(payload.getCommentUserGroupId()); | |
ExternalGroupHelper groupHelper = extGroupHelperProvider.getHelperForType(cug.getExtGroupType()); | |
if (groupHelper.isMember(securityContextHelper.getCurrentUser(), cug.getExtGroupId())) { | |
Comment persistedComment = commentDao.persist(payload.toComment()); | |
fireCommentAddedEvent(persistedComment); | |
return persistedComment; |
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
public class CommentController { | |
private static final Logger LOG = LoggerFactory.getLogger(CommentController.class); | |
// implementation of listeners might need to be thread safe | |
// depending on whether you allow dynamic change to | |
// listener registration | |
private Set<CommentAddedListener> listeners; | |
// ... some fields and constructor omitted ... |
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
public interface CommentAddedListener { | |
void processComment(Comment comment); | |
} |
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
public class Comment { | |
private String commentUserGroupId; | |
private User author; | |
private Object payload; | |
// ... constructor, getters, equals, hashCode ... | |
} |