Merge branch 'master' into extension-objects
This commit is contained in:
commit
09fb79099f
@ -27,6 +27,22 @@ Use the Abstract Factory pattern when
|
||||
* a system should be configured with one of multiple families of products
|
||||
* a family of related product objects is designed to be used together, and you need to enforce this constraint
|
||||
* you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations
|
||||
* the lifetime of the dependency is conceptually shorter than the lifetime of the consumer.
|
||||
* you need a run-time value to construct a particular dependency
|
||||
* you want to decide which product to call from a family at runtime.
|
||||
* you need to supply one or more parameters only known at run-time before you can resolve a dependency.
|
||||
|
||||
## Use Cases:
|
||||
|
||||
* Selecting to call the appropriate implementation of FileSystemAcmeService or DatabaseAcmeService or NetworkAcmeService at runtime.
|
||||
* Unit test case writing becomes much easier
|
||||
|
||||
## Consequences:
|
||||
|
||||
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time.
|
||||
|
||||
|
||||
|
||||
|
||||
## Real world examples
|
||||
|
||||
|
@ -1,3 +1,25 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
|
@ -1,3 +1,25 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
|
@ -1,3 +1,25 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
|
@ -1,3 +1,25 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.databus;
|
||||
|
||||
import org.junit.Before;
|
||||
|
@ -1,3 +1,25 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.databus.members;
|
||||
|
||||
import com.iluwatar.databus.data.MessageData;
|
||||
|
@ -1,3 +1,25 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.databus.members;
|
||||
|
||||
import com.iluwatar.databus.DataBus;
|
||||
|
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.dependency.injection;
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014-2017 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* <p>
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
* <p>
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* AdvancedSorceress implements inversion of control. It depends on abstraction that can be injected
|
||||
* through its setter.
|
||||
*/
|
||||
public class AdvancedSorceress implements Wizard {
|
||||
|
||||
private Tobacco tobacco;
|
||||
|
||||
public void setTobacco(Tobacco tobacco) {
|
||||
this.tobacco = tobacco;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void smoke() {
|
||||
tobacco.smoke(this);
|
||||
}
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
*
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* <p>
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* <p>
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@ -26,7 +26,6 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
*
|
||||
* Dependency Injection pattern deals with how objects handle their dependencies. The pattern
|
||||
* implements so called inversion of control principle. Inversion of control has two specific rules:
|
||||
* - High-level modules should not depend on low-level modules. Both should depend on abstractions.
|
||||
@ -36,21 +35,21 @@ import com.google.inject.Injector;
|
||||
* naive implementation violating the inversion of control principle. It depends directly on a
|
||||
* concrete implementation which cannot be changed.
|
||||
* <p>
|
||||
* The second wizard ({@link AdvancedWizard}) is more flexible. It does not depend on any concrete
|
||||
* implementation but abstraction. It utilizes Dependency Injection pattern allowing its
|
||||
* {@link Tobacco} dependency to be injected through its constructor. This way, handling the
|
||||
* dependency is no longer the wizard's responsibility. It is resolved outside the wizard class.
|
||||
* The second and third wizards({@link AdvancedWizard} and {@link AdvancedSorceress}) are more flexible.
|
||||
* They do not depend on any concrete implementation but abstraction. They utilizes Dependency Injection
|
||||
* pattern allowing their {@link Tobacco} dependency to be injected through constructor ({@link AdvancedWizard})
|
||||
* or setter ({@link AdvancedSorceress}). This way, handling the dependency is no longer the wizard's
|
||||
* responsibility. It is resolved outside the wizard class.
|
||||
* <p>
|
||||
* The third example takes the pattern a step further. It uses Guice framework for Dependency
|
||||
* The fourth example takes the pattern a step further. It uses Guice framework for Dependency
|
||||
* Injection. {@link TobaccoModule} binds a concrete implementation to abstraction. Injector is then
|
||||
* used to create {@link GuiceWizard} object with correct dependencies.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
@ -60,6 +59,10 @@ public class App {
|
||||
AdvancedWizard advancedWizard = new AdvancedWizard(new SecondBreakfastTobacco());
|
||||
advancedWizard.smoke();
|
||||
|
||||
AdvancedSorceress advancedSorceress = new AdvancedSorceress();
|
||||
advancedSorceress.setTobacco(new SecondBreakfastTobacco());
|
||||
advancedSorceress.smoke();
|
||||
|
||||
Injector injector = Guice.createInjector(new TobaccoModule());
|
||||
GuiceWizard guiceWizard = injector.getInstance(GuiceWizard.class);
|
||||
guiceWizard.smoke();
|
||||
|
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* <p>
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
* <p>
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.dependency.injection;
|
||||
|
||||
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Date: 28/04/17 - 7:40 AM
|
||||
*
|
||||
* @author Stanislav Kapinus
|
||||
*/
|
||||
|
||||
public class AdvancedSorceressTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
appender = new InMemoryAppender(Tobacco.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
appender.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the {@link AdvancedSorceress} smokes whatever instance of {@link Tobacco} is passed to her
|
||||
* through the setter's parameter
|
||||
*/
|
||||
@Test
|
||||
public void testSmokeEveryThing() throws Exception {
|
||||
|
||||
final Tobacco[] tobaccos = {
|
||||
new OldTobyTobacco(), new RivendellTobacco(), new SecondBreakfastTobacco()
|
||||
};
|
||||
|
||||
for (final Tobacco tobacco : tobaccos) {
|
||||
final AdvancedSorceress advancedSorceress = new AdvancedSorceress();
|
||||
advancedSorceress.setTobacco(tobacco);
|
||||
advancedSorceress.smoke();
|
||||
// Verify if the sorceress is smoking the correct tobacco ...
|
||||
assertEquals("AdvancedSorceress smoking " + tobacco.getClass().getSimpleName(), appender.getLastMessage());
|
||||
|
||||
}
|
||||
|
||||
// ... and nothing else is happening.
|
||||
assertEquals(tobaccos.length, appender.getLogSize());
|
||||
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ Use an Event-driven architecture when
|
||||
|
||||
## Credits
|
||||
|
||||
* [Event-driven architecture - Wikipedia](http://www.computerweekly.com/feature/Write-through-write-around-write-back-Cache-explained)
|
||||
* [Event-driven architecture - Wikipedia](https://en.wikipedia.org/wiki/Event-driven_architecture)
|
||||
* [Fundamental Components of an Event-Driven Architecture](http://giocc.com/fundamental-components-of-an-event-driven-architecture.html)
|
||||
* [Real World Applications/Event Driven Applications](https://wiki.haskell.org/Real_World_Applications/Event_Driven_Applications)
|
||||
* [Event-driven architecture definition](http://searchsoa.techtarget.com/definition/event-driven-architecture)
|
||||
|
29
event-queue/README.md
Normal file
29
event-queue/README.md
Normal file
@ -0,0 +1,29 @@
|
||||
---
|
||||
layout: pattern
|
||||
title: Event Queue
|
||||
folder: event-queue
|
||||
permalink: /patterns/event-queue/
|
||||
categories: Concurrency
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty Intermediate
|
||||
- Queue
|
||||
---
|
||||
|
||||
## Intent
|
||||
Event Queue is a good pattern if You have a limited accesibility resource (for example:
|
||||
Audio or Database), but You need to handle all the requests that want to use that.
|
||||
It puts all the requests in a queue and process them asynchronously.
|
||||
Gives the resource for the event when it is the next in the queue and in same time
|
||||
removes it from the queue.
|
||||
|
||||

|
||||
|
||||
## Applicability
|
||||
Use the Event Queue pattern when
|
||||
|
||||
* You have a limited accesibility resource and the asynchronous process is acceptable to reach that
|
||||
|
||||
## Credits
|
||||
|
||||
* [Mihaly Kuprivecz - Event Queue] (http://gameprogrammingpatterns.com/event-queue.html)
|
BIN
event-queue/etc/Bass-Drum-1.aif
Normal file
BIN
event-queue/etc/Bass-Drum-1.aif
Normal file
Binary file not shown.
BIN
event-queue/etc/Bass-Drum-1.wav
Normal file
BIN
event-queue/etc/Bass-Drum-1.wav
Normal file
Binary file not shown.
BIN
event-queue/etc/Closed-Hi-Hat-1.aif
Normal file
BIN
event-queue/etc/Closed-Hi-Hat-1.aif
Normal file
Binary file not shown.
BIN
event-queue/etc/Closed-Hi-Hat-1.wav
Normal file
BIN
event-queue/etc/Closed-Hi-Hat-1.wav
Normal file
Binary file not shown.
26
event-queue/etc/event-queue.urm.puml
Normal file
26
event-queue/etc/event-queue.urm.puml
Normal file
@ -0,0 +1,26 @@
|
||||
@startuml
|
||||
package com.iluwatar.event.queue {
|
||||
class App {
|
||||
+ App()
|
||||
+ getAudioStream(filePath : String) : AudioInputStream {static}
|
||||
+ main(args : String[]) {static}
|
||||
}
|
||||
class Audio {
|
||||
- MAX_PENDING : int {static}
|
||||
- headIndex : int {static}
|
||||
- pendingAudio : PlayMessage[] {static}
|
||||
- tailIndex : int {static}
|
||||
- updateThread : Thread {static}
|
||||
+ Audio()
|
||||
+ init() {static}
|
||||
+ playSound(stream : AudioInputStream, volume : float) {static}
|
||||
+ stopService() {static}
|
||||
+ update() {static}
|
||||
}
|
||||
class PlayMessage {
|
||||
~ stream : AudioInputStream
|
||||
~ volume : float
|
||||
+ PlayMessage()
|
||||
}
|
||||
}
|
||||
@enduml
|
BIN
event-queue/etc/model.png
Normal file
BIN
event-queue/etc/model.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
36
event-queue/etc/model.ucls
Normal file
36
event-queue/etc/model.ucls
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<class-diagram version="1.2.0" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||
<class id="1" language="java" name="com.iluwatar.event.queue.Audio" project="event-queue"
|
||||
file="/event-queue/src/main/java/com/iluwatar/event/queue/Audio.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="285" y="179"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<class id="2" language="java" name="com.iluwatar.event.queue.PlayMessage" project="event-queue"
|
||||
file="/event-queue/src/main/java/com/iluwatar/event/queue/PlayMessage.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="633" y="179"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<association id="3">
|
||||
<end type="SOURCE" refId="1" navigable="false">
|
||||
<attribute id="4" name="pendingAudio"/>
|
||||
<multiplicity id="5" minimum="0" maximum="2147483647"/>
|
||||
</end>
|
||||
<end type="TARGET" refId="2" navigable="true"/>
|
||||
<display labels="true" multiplicity="true"/>
|
||||
</association>
|
||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</classifier-display>
|
||||
<association-display labels="true" multiplicity="true"/>
|
||||
</class-diagram>
|
43
event-queue/pom.xml
Normal file
43
event-queue/pom.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.16.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>event-queue</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
59
event-queue/src/main/java/com/iluwatar/event/queue/App.java
Normal file
59
event-queue/src/main/java/com/iluwatar/event/queue/App.java
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.event.queue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
/**
|
||||
* Event or message queues provide an asynchronous communications protocol, meaning that the sender
|
||||
* and receiver of the message do not need to interact with the message queue at the same time.
|
||||
* Events or messages placed onto the queue are stored until the recipient retrieves them. Event
|
||||
* or message queues have implicit or explicit limits on the size of data that may be transmitted
|
||||
* in a single message and the number of messages that may remain outstanding on the queue.
|
||||
* A queue stores a series of notifications or requests in first-in, first-out order.
|
||||
* Sending a notification enqueues the request and returns. The request processor then processes
|
||||
* items from the queue at a later time.
|
||||
*/
|
||||
public class App {
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args command line args
|
||||
* @throws IOException when there is a problem with the audio file loading
|
||||
* @throws UnsupportedAudioFileException when the loaded audio file is unsupported
|
||||
*/
|
||||
public static void main(String[] args) throws UnsupportedAudioFileException, IOException {
|
||||
Audio.playSound(Audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f);
|
||||
Audio.playSound(Audio.getAudioStream("./etc/Closed-Hi-Hat-1.wav"), -8.0f);
|
||||
|
||||
System.out.println("Press Enter key to stop the program...");
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
br.read();
|
||||
Audio.stopService();
|
||||
}
|
||||
}
|
169
event-queue/src/main/java/com/iluwatar/event/queue/Audio.java
Normal file
169
event-queue/src/main/java/com/iluwatar/event/queue/Audio.java
Normal file
@ -0,0 +1,169 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.event.queue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
/**
|
||||
* This class implements the Event Queue pattern.
|
||||
* @author mkuprivecz
|
||||
*
|
||||
*/
|
||||
public class Audio {
|
||||
|
||||
private static final int MAX_PENDING = 16;
|
||||
|
||||
private static int headIndex;
|
||||
|
||||
private static int tailIndex;
|
||||
|
||||
private static Thread updateThread = null;
|
||||
|
||||
private static PlayMessage[] pendingAudio = new PlayMessage[MAX_PENDING];
|
||||
|
||||
/**
|
||||
* This method stops the Update Method's thread.
|
||||
*/
|
||||
public static synchronized void stopService() {
|
||||
if (updateThread != null) {
|
||||
updateThread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method stops the Update Method's thread.
|
||||
* @return boolean
|
||||
*/
|
||||
public static synchronized boolean isServiceRunning() {
|
||||
if (updateThread != null && updateThread.isAlive() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the thread for the Update Method pattern if it was not started previously.
|
||||
* Also when the thread is is ready initializes the indexes of the queue
|
||||
*/
|
||||
public static void init() {
|
||||
if (updateThread == null) {
|
||||
updateThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
Audio.update();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
startThread();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a synchronized thread starter
|
||||
*/
|
||||
public static synchronized void startThread() {
|
||||
if (!updateThread.isAlive()) {
|
||||
updateThread.start();
|
||||
headIndex = 0;
|
||||
tailIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds a new audio into the queue.
|
||||
* @param stream is the AudioInputStream for the method
|
||||
* @param volume is the level of the audio's volume
|
||||
*/
|
||||
public static void playSound(AudioInputStream stream, float volume) {
|
||||
init();
|
||||
// Walk the pending requests.
|
||||
for (int i = headIndex; i != tailIndex; i = (i + 1) % MAX_PENDING) {
|
||||
if (getPendingAudio()[i].getStream() == stream) {
|
||||
// Use the larger of the two volumes.
|
||||
getPendingAudio()[i].setVolume(Math.max(volume, getPendingAudio()[i].getVolume()));
|
||||
|
||||
// Don't need to enqueue.
|
||||
return;
|
||||
}
|
||||
}
|
||||
getPendingAudio()[tailIndex] = new PlayMessage(stream, volume);
|
||||
tailIndex = (tailIndex + 1) % MAX_PENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method uses the Update Method pattern.
|
||||
* It takes the audio from the queue and plays it
|
||||
*/
|
||||
public static void update() {
|
||||
// If there are no pending requests, do nothing.
|
||||
if (headIndex == tailIndex) {
|
||||
return;
|
||||
}
|
||||
Clip clip = null;
|
||||
try {
|
||||
AudioInputStream audioStream = getPendingAudio()[headIndex].getStream();
|
||||
headIndex++;
|
||||
clip = AudioSystem.getClip();
|
||||
clip.open(audioStream);
|
||||
clip.start();
|
||||
} catch (LineUnavailableException e) {
|
||||
System.err.println("Error occoured while loading the audio: The line is unavailable");
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Input/Output error while loading the audio");
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.err.println("The system doesn't support the sound: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the AudioInputStream of a file
|
||||
* @param filePath is the path of the audio file
|
||||
* @return AudioInputStream
|
||||
* @throws UnsupportedAudioFileException when the audio file is not supported
|
||||
* @throws IOException when the file is not readable
|
||||
*/
|
||||
public static AudioInputStream getAudioStream(String filePath)
|
||||
throws UnsupportedAudioFileException, IOException {
|
||||
return AudioSystem.getAudioInputStream(new File(filePath).getAbsoluteFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns with the message array of the queue
|
||||
* @return PlayMessage[]
|
||||
*/
|
||||
public static PlayMessage[] getPendingAudio() {
|
||||
return pendingAudio;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.event.queue;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
|
||||
/**
|
||||
* The Event Queue's queue will store the instances of this class.
|
||||
* @author mkuprivecz
|
||||
*
|
||||
*/
|
||||
public class PlayMessage {
|
||||
|
||||
private AudioInputStream stream;
|
||||
|
||||
private float volume;
|
||||
|
||||
public PlayMessage(AudioInputStream stream, float volume) {
|
||||
setStream(stream);
|
||||
setVolume(volume);
|
||||
}
|
||||
|
||||
public AudioInputStream getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
private void setStream(AudioInputStream stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public float getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(float volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.event.queue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Testing the Audio service of the Queue
|
||||
* @author mkuprivecz
|
||||
*
|
||||
*/
|
||||
public class AudioTest {
|
||||
|
||||
/**
|
||||
* Test here that the playSound method works correctly
|
||||
* @throws UnsupportedAudioFileException when the audio file is not supported
|
||||
* @throws IOException when the file is not readable
|
||||
* @throws InterruptedException when the test is interrupted externally
|
||||
*/
|
||||
@Test
|
||||
public void testPlaySound() throws UnsupportedAudioFileException, IOException, InterruptedException {
|
||||
Audio.playSound(Audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f);
|
||||
// test that service is started
|
||||
assertTrue(Audio.isServiceRunning());
|
||||
// adding a small pause to be sure that the sound is ended
|
||||
Thread.sleep(5000);
|
||||
// test that service is finished
|
||||
assertFalse(!Audio.isServiceRunning());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test here that the Queue
|
||||
* @throws UnsupportedAudioFileException when the audio file is not supported
|
||||
* @throws IOException when the file is not readable
|
||||
* @throws InterruptedException when the test is interrupted externally
|
||||
*/
|
||||
@Test
|
||||
public void testQueue() throws UnsupportedAudioFileException, IOException, InterruptedException {
|
||||
Audio.playSound(Audio.getAudioStream("./etc/Bass-Drum-1.aif"), -10.0f);
|
||||
Audio.playSound(Audio.getAudioStream("./etc/Bass-Drum-1.aif"), -10.0f);
|
||||
Audio.playSound(Audio.getAudioStream("./etc/Bass-Drum-1.aif"), -10.0f);
|
||||
assertTrue(Audio.getPendingAudio().length > 0);
|
||||
// test that service is started
|
||||
assertTrue(Audio.isServiceRunning());
|
||||
// adding a small pause to be sure that the sound is ended
|
||||
Thread.sleep(10000);
|
||||
// test that service is finished
|
||||
assertFalse(!Audio.isServiceRunning());
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ package com.iluwatar.featuretoggle;
|
||||
|
||||
import com.iluwatar.featuretoggle.pattern.Service;
|
||||
import com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion;
|
||||
import com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion;
|
||||
import com.iluwatar.featuretoggle.user.User;
|
||||
import com.iluwatar.featuretoggle.user.UserGroup;
|
||||
import org.slf4j.Logger;
|
||||
@ -85,6 +86,8 @@ public class App {
|
||||
LOGGER.info(welcomeMessageturnedOff);
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
Service service2 = new TieredFeatureToggleVersion();
|
||||
|
||||
final User paidUser = new User("Jamie Coder");
|
||||
final User freeUser = new User("Alan Defect");
|
||||
@ -92,8 +95,8 @@ public class App {
|
||||
UserGroup.addUserToPaidGroup(paidUser);
|
||||
UserGroup.addUserToFreeGroup(freeUser);
|
||||
|
||||
final String welcomeMessagePaidUser = service.getWelcomeMessage(paidUser);
|
||||
final String welcomeMessageFreeUser = service.getWelcomeMessage(freeUser);
|
||||
final String welcomeMessagePaidUser = service2.getWelcomeMessage(paidUser);
|
||||
final String welcomeMessageFreeUser = service2.getWelcomeMessage(freeUser);
|
||||
LOGGER.info(welcomeMessageFreeUser);
|
||||
LOGGER.info(welcomeMessagePaidUser);
|
||||
}
|
||||
|
1
marker/.gitignore
vendored
Normal file
1
marker/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target/
|
30
marker/README.md
Normal file
30
marker/README.md
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
layout: pattern
|
||||
title: Marker Interface
|
||||
folder: marker
|
||||
permalink: /patterns/marker/
|
||||
categories: Design
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
## Intent
|
||||
Using empty interfaces as markers to distinguish special treated objects.
|
||||
|
||||

|
||||
|
||||
## Applicability
|
||||
Use the Marker Interface pattern when
|
||||
|
||||
* 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.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
|
||||
|
||||
* [Effective Java 2nd Edition by Joshua Bloch](https://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683)
|
BIN
marker/etc/MarkerDiagram.png
Normal file
BIN
marker/etc/MarkerDiagram.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
41
marker/etc/MarkerDiagram.ucls
Normal file
41
marker/etc/MarkerDiagram.ucls
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<class-diagram version="1.2.0" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||
<class id="1" language="java" name="Guard" project="marker" file="/marker/src/main/java/Guard.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="416" y="348"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<interface id="2" language="java" name="Permission" project="marker" file="/marker/src/main/java/Permission.java"
|
||||
binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="261" y="175"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</interface>
|
||||
<class id="3" language="java" name="Thief" project="marker" file="/marker/src/main/java/Thief.java" binary="false"
|
||||
corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="236" y="355"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<realization id="4">
|
||||
<end type="SOURCE" refId="1"/>
|
||||
<end type="TARGET" refId="2"/>
|
||||
</realization>
|
||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</classifier-display>
|
||||
<association-display labels="true" multiplicity="true"/>
|
||||
</class-diagram>
|
2
marker/etc/marker.urm.puml
Normal file
2
marker/etc/marker.urm.puml
Normal file
@ -0,0 +1,2 @@
|
||||
@startuml
|
||||
@enduml
|
41
marker/pom.xml
Normal file
41
marker/pom.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
The MIT License
|
||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.16.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>marker</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
70
marker/src/main/java/App.java
Normal file
70
marker/src/main/java/App.java
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
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.
|
||||
* Basically it is just to identify the special objects from normal objects.
|
||||
* Like in case of serialization , objects that need to be serialized must implement serializable interface
|
||||
* (it is empty interface) and down the line writeObject() method must be checking
|
||||
* if it is a instance of serializable or not.
|
||||
* <p>
|
||||
* Marker interface vs annotation
|
||||
* Marker interfaces and marker annotations both have their uses,
|
||||
* neither of them is obsolete or always better then the other one.
|
||||
* If you want to define a type that does not have any new methods associated with it,
|
||||
* a marker interface is the way to go.
|
||||
* If you want to mark program elements other than classes and interfaces,
|
||||
* to allow for the possibility of adding more information to the marker in the future,
|
||||
* or to fit the marker into a framework that already makes heavy use of annotation types,
|
||||
* then a marker annotation is the correct choice
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
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 {
|
||||
logger.info("You have no permission to enter, please leave this area");
|
||||
}
|
||||
|
||||
if (thief instanceof Permission) {
|
||||
thief.steal();
|
||||
} else {
|
||||
thief.doNothing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
marker/src/main/java/Guard.java
Normal file
37
marker/src/main/java/Guard.java
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Class defining Guard
|
||||
*/
|
||||
public class Guard implements Permission {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Guard.class);
|
||||
|
||||
protected static void enter() {
|
||||
|
||||
LOGGER.info("You can enter");
|
||||
}
|
||||
}
|
28
marker/src/main/java/Permission.java
Normal file
28
marker/src/main/java/Permission.java
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
* Interface without any methods
|
||||
* Marker interface is based on that assumption
|
||||
*/
|
||||
public interface Permission {
|
||||
}
|
40
marker/src/main/java/Thief.java
Normal file
40
marker/src/main/java/Thief.java
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Class defining Thief
|
||||
*/
|
||||
public class Thief {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Thief.class);
|
||||
|
||||
protected static void steal() {
|
||||
LOGGER.info("Steal valuable items");
|
||||
}
|
||||
|
||||
protected static void doNothing() {
|
||||
LOGGER.info("Pretend nothing happened and just leave");
|
||||
}
|
||||
}
|
35
marker/src/test/java/AppTest.java
Normal file
35
marker/src/test/java/AppTest.java
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Application test
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
38
marker/src/test/java/GuardTest.java
Normal file
38
marker/src/test/java/GuardTest.java
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Guard test
|
||||
*/
|
||||
public class GuardTest {
|
||||
|
||||
@Test
|
||||
public void testGuard() {
|
||||
Guard guard = new Guard();
|
||||
assertThat(guard, instanceOf(Permission.class));
|
||||
}
|
||||
}
|
36
marker/src/test/java/ThiefTest.java
Normal file
36
marker/src/test/java/ThiefTest.java
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* Thief test
|
||||
*/
|
||||
public class ThiefTest {
|
||||
@Test
|
||||
public void testThief() {
|
||||
Thief thief = new Thief();
|
||||
assertFalse(thief instanceof Permission);
|
||||
}
|
||||
}
|
39
pom.xml
39
pom.xml
@ -122,7 +122,7 @@
|
||||
<module>factory-kit</module>
|
||||
<module>feature-toggle</module>
|
||||
<module>value-object</module>
|
||||
<module>module</module>
|
||||
<module>module</module>
|
||||
<module>monad</module>
|
||||
<module>mute-idiom</module>
|
||||
<module>mutex</module>
|
||||
@ -133,6 +133,7 @@
|
||||
<module>promise</module>
|
||||
<module>page-object</module>
|
||||
<module>event-asynchronous</module>
|
||||
<module>event-queue</module>
|
||||
<module>queue-load-leveling</module>
|
||||
<module>object-mother</module>
|
||||
<module>data-bus</module>
|
||||
@ -140,6 +141,8 @@
|
||||
<module>guarded-suspension</module>
|
||||
<module>balking</module>
|
||||
<module>extension-objects</module>
|
||||
<module>marker</module>
|
||||
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -303,23 +306,23 @@
|
||||
</action>
|
||||
</pluginExecution>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>
|
||||
com.github.markusmo3.urm
|
||||
</groupId>
|
||||
<artifactId>
|
||||
urm-maven-plugin
|
||||
</artifactId>
|
||||
<versionRange>
|
||||
[1.4.1,)
|
||||
</versionRange>
|
||||
<goals>
|
||||
<goal>map</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore/>
|
||||
</action>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>
|
||||
com.github.markusmo3.urm
|
||||
</groupId>
|
||||
<artifactId>
|
||||
urm-maven-plugin
|
||||
</artifactId>
|
||||
<versionRange>
|
||||
[1.4.1,)
|
||||
</versionRange>
|
||||
<goals>
|
||||
<goal>map</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore/>
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
</lifecycleMappingMetadata>
|
||||
|
Loading…
x
Reference in New Issue
Block a user