From f2e35ec03df777b56f4af5f16c657211f0cfae4d Mon Sep 17 00:00:00 2001 From: Aleksandar Dudukovic Date: Tue, 23 May 2017 01:38:02 +0200 Subject: [PATCH] #567 fix version and javadoc --- marker/README.md | 10 +++++----- marker/pom.xml | 10 +--------- marker/src/main/java/App.java | 6 +++++- marker/src/main/java/Guard.java | 13 +++++++++---- marker/src/main/java/Permission.java | 1 - marker/src/main/java/Thief.java | 12 +++++++++--- marker/src/test/java/AppTest.java | 4 ---- marker/src/test/java/GuardTest.java | 4 ++-- marker/src/test/java/ThiefTest.java | 6 +++--- 9 files changed, 34 insertions(+), 32 deletions(-) diff --git a/marker/README.md b/marker/README.md index 8ff25100a..5bcdf9664 100644 --- a/marker/README.md +++ b/marker/README.md @@ -10,20 +10,20 @@ tags: --- ## Intent -Using empy interfaces as markers to distinguish special treated objects. +Using empty interfaces as markers to distinguish special treated objects. ![alt text](./etc/MarkerDiagram.png "Marker Interface") ## Applicability Use the Marker Interface pattern when -* you want to identify the special objects from normal objects -* define a type that is implemented by instances of the marked class, marker annotations can not do that +* you want to identify the special objects from normal objects (to treat them differently) +* you want to mark that some object is available for certain sort of operations ## Real world examples -* [javase.7.docs.api.java.io.Serializable](https://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html) -* [javase.7.docs.api.java.lang.Cloneable](https://docs.oracle.com/javase/7/docs/api/java/lang/Cloneable.html) +* [javase.8.docs.api.java.io.Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html) +* [javase.8.docs.api.java.lang.Cloneable](https://docs.oracle.com/javase/8/docs/api/java/lang/Cloneable.html) ## Credits diff --git a/marker/pom.xml b/marker/pom.xml index ab92bdbc6..2842bd739 100644 --- a/marker/pom.xml +++ b/marker/pom.xml @@ -30,18 +30,10 @@ marker - - org.junit.jupiter - junit-jupiter-api - RELEASE - - - junit - junit - junit junit + test diff --git a/marker/src/main/java/App.java b/marker/src/main/java/App.java index 10ec017df..7abdda8c4 100644 --- a/marker/src/main/java/App.java +++ b/marker/src/main/java/App.java @@ -1,3 +1,6 @@ +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Created by Alexis on 28-Apr-17. * With Marker interface idea is to make empty interface and extend it. @@ -25,13 +28,14 @@ public class App { */ public static void main(String[] args) { + final Logger logger = LoggerFactory.getLogger(App.class); Guard guard = new Guard(); Thief thief = new Thief(); if (guard instanceof Permission) { guard.enter(); } else { - System.out.println("You have no permission to enter, please leave this area"); + logger.info("You have no permission to enter, please leave this area"); } if (thief instanceof Permission) { diff --git a/marker/src/main/java/Guard.java b/marker/src/main/java/Guard.java index 93db6b4d7..14016f0b1 100644 --- a/marker/src/main/java/Guard.java +++ b/marker/src/main/java/Guard.java @@ -1,10 +1,15 @@ +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** - * Created by Alexis on 29-Apr-17. + * Class defining Guard */ public class Guard implements Permission { - protected static void enter() { - System.out.println("You can enter"); - } + private static final Logger LOGGER = LoggerFactory.getLogger(Guard.class); + protected static void enter() { + + LOGGER.info("You can enter"); + } } diff --git a/marker/src/main/java/Permission.java b/marker/src/main/java/Permission.java index a422e955c..c6e78c49d 100644 --- a/marker/src/main/java/Permission.java +++ b/marker/src/main/java/Permission.java @@ -1,5 +1,4 @@ /** - * Created by Alexis on 29-Apr-17. * Interface without any methods * Marker interface is based on that assumption */ diff --git a/marker/src/main/java/Thief.java b/marker/src/main/java/Thief.java index 33eac5aca..9105057e3 100644 --- a/marker/src/main/java/Thief.java +++ b/marker/src/main/java/Thief.java @@ -1,12 +1,18 @@ +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** - * Created by Alexis on 02-May-17. + * Class defining Thief */ public class Thief { + + private static final Logger LOGGER = LoggerFactory.getLogger(Thief.class); + protected static void steal() { - System.out.println("Steal valuable items"); + LOGGER.info("Steal valuable items"); } protected static void doNothing() { - System.out.println("Pretend nothing happened and just leave"); + LOGGER.info("Pretend nothing happened and just leave"); } } diff --git a/marker/src/test/java/AppTest.java b/marker/src/test/java/AppTest.java index 615a3c910..55fb2a17f 100644 --- a/marker/src/test/java/AppTest.java +++ b/marker/src/test/java/AppTest.java @@ -1,7 +1,3 @@ -/** - * Created by Alexis on 01-May-17. - */ - import org.junit.Test; /** diff --git a/marker/src/test/java/GuardTest.java b/marker/src/test/java/GuardTest.java index 459447367..8b33b6e7f 100644 --- a/marker/src/test/java/GuardTest.java +++ b/marker/src/test/java/GuardTest.java @@ -4,7 +4,7 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertThat; /** - * Created by Alexis on 02-May-17. + * Guard test */ public class GuardTest { @@ -13,4 +13,4 @@ public class GuardTest { Guard guard = new Guard(); assertThat(guard, instanceOf(Permission.class)); } -} +} \ No newline at end of file diff --git a/marker/src/test/java/ThiefTest.java b/marker/src/test/java/ThiefTest.java index bcc862803..71fe82b68 100644 --- a/marker/src/test/java/ThiefTest.java +++ b/marker/src/test/java/ThiefTest.java @@ -3,12 +3,12 @@ import org.junit.Test; import static org.junit.Assert.assertFalse; /** - * Created by Alexis on 02-May-17. + * Thief test */ public class ThiefTest { @Test - public void testGuard() { + public void testThief() { Thief thief = new Thief(); assertFalse(thief instanceof Permission); } -} +} \ No newline at end of file