mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-10 02:21:55 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -25,12 +25,12 @@
|
||||
package com.iluwatar.visitor;
|
||||
|
||||
/**
|
||||
* <p>Visitor pattern defines a mechanism to apply operations on nodes in a hierarchy. New
|
||||
* operations can be added without altering the node interface.</p>
|
||||
* Visitor pattern defines a mechanism to apply operations on nodes in a hierarchy. New operations
|
||||
* can be added without altering the node interface.
|
||||
*
|
||||
* <p>In this example there is a unit hierarchy beginning from {@link Commander}. This hierarchy is
|
||||
* traversed by visitors. {@link SoldierVisitor} applies its operation on {@link Soldier}s, {@link
|
||||
* SergeantVisitor} on {@link Sergeant}s and so on.</p>
|
||||
* SergeantVisitor} on {@link Sergeant}s and so on.
|
||||
*/
|
||||
public class App {
|
||||
|
||||
@@ -41,10 +41,10 @@ public class App {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
var commander = new Commander(
|
||||
new Sergeant(new Soldier(), new Soldier(), new Soldier()),
|
||||
new Sergeant(new Soldier(), new Soldier(), new Soldier())
|
||||
);
|
||||
var commander =
|
||||
new Commander(
|
||||
new Sergeant(new Soldier(), new Soldier(), new Soldier()),
|
||||
new Sergeant(new Soldier(), new Soldier(), new Soldier()));
|
||||
commander.accept(new SoldierVisitor());
|
||||
commander.accept(new SergeantVisitor());
|
||||
commander.accept(new CommanderVisitor());
|
||||
|
||||
@@ -1,50 +1,49 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
/**
|
||||
* Commander.
|
||||
*/
|
||||
public class Commander extends Unit {
|
||||
|
||||
public Commander(Unit... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a Visitor.
|
||||
* @param visitor UnitVisitor to be accepted
|
||||
*/
|
||||
@Override
|
||||
public void accept(UnitVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
super.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "commander";
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
/** Commander. */
|
||||
public class Commander extends Unit {
|
||||
|
||||
public Commander(Unit... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a Visitor.
|
||||
*
|
||||
* @param visitor UnitVisitor to be accepted
|
||||
*/
|
||||
@Override
|
||||
public void accept(UnitVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
super.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "commander";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,62 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* CommanderVisitor.
|
||||
*/
|
||||
@Slf4j
|
||||
public class CommanderVisitor implements UnitVisitor {
|
||||
|
||||
/**
|
||||
* Soldier Visitor method.
|
||||
* @param soldier Soldier to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Soldier soldier) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Sergeant Visitor method.
|
||||
* @param sergeant Sergeant to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Sergeant sergeant) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Commander Visitor method.
|
||||
* @param commander Commander to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Commander commander) {
|
||||
LOGGER.info("Good to see you {}", commander);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** CommanderVisitor. */
|
||||
@Slf4j
|
||||
public class CommanderVisitor implements UnitVisitor {
|
||||
|
||||
/**
|
||||
* Soldier Visitor method.
|
||||
*
|
||||
* @param soldier Soldier to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Soldier soldier) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Sergeant Visitor method.
|
||||
*
|
||||
* @param sergeant Sergeant to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Sergeant sergeant) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Commander Visitor method.
|
||||
*
|
||||
* @param commander Commander to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Commander commander) {
|
||||
LOGGER.info("Good to see you {}", commander);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,49 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
/**
|
||||
* Sergeant.
|
||||
*/
|
||||
public class Sergeant extends Unit {
|
||||
|
||||
public Sergeant(Unit... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a Visitor.
|
||||
* @param visitor UnitVisitor to be accepted
|
||||
*/
|
||||
@Override
|
||||
public void accept(UnitVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
super.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "sergeant";
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
/** Sergeant. */
|
||||
public class Sergeant extends Unit {
|
||||
|
||||
public Sergeant(Unit... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a Visitor.
|
||||
*
|
||||
* @param visitor UnitVisitor to be accepted
|
||||
*/
|
||||
@Override
|
||||
public void accept(UnitVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
super.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "sergeant";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,62 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* SergeantVisitor.
|
||||
*/
|
||||
@Slf4j
|
||||
public class SergeantVisitor implements UnitVisitor {
|
||||
|
||||
/**
|
||||
* Soldier Visitor method.
|
||||
* @param soldier Soldier to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Soldier soldier) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Sergeant Visitor method.
|
||||
* @param sergeant Sergeant to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Sergeant sergeant) {
|
||||
LOGGER.info("Hello {}", sergeant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Commander Visitor method.
|
||||
* @param commander Commander to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Commander commander) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** SergeantVisitor. */
|
||||
@Slf4j
|
||||
public class SergeantVisitor implements UnitVisitor {
|
||||
|
||||
/**
|
||||
* Soldier Visitor method.
|
||||
*
|
||||
* @param soldier Soldier to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Soldier soldier) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Sergeant Visitor method.
|
||||
*
|
||||
* @param sergeant Sergeant to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Sergeant sergeant) {
|
||||
LOGGER.info("Hello {}", sergeant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Commander Visitor method.
|
||||
*
|
||||
* @param commander Commander to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Commander commander) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,49 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
/**
|
||||
* Soldier.
|
||||
*/
|
||||
public class Soldier extends Unit {
|
||||
|
||||
public Soldier(Unit... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a Visitor.
|
||||
* @param visitor UnitVisitor to be accepted
|
||||
*/
|
||||
@Override
|
||||
public void accept(UnitVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
super.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "soldier";
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
/** Soldier. */
|
||||
public class Soldier extends Unit {
|
||||
|
||||
public Soldier(Unit... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a Visitor.
|
||||
*
|
||||
* @param visitor UnitVisitor to be accepted
|
||||
*/
|
||||
@Override
|
||||
public void accept(UnitVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
super.accept(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "soldier";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,62 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* SoldierVisitor.
|
||||
*/
|
||||
@Slf4j
|
||||
public class SoldierVisitor implements UnitVisitor {
|
||||
|
||||
/**
|
||||
* Soldier Visitor method.
|
||||
* @param soldier Soldier to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Soldier soldier) {
|
||||
LOGGER.info("Greetings {}", soldier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sergeant Visitor method.
|
||||
* @param sergeant Sergeant to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Sergeant sergeant) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Commander Visitor method.
|
||||
* @param commander Commander to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Commander commander) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** SoldierVisitor. */
|
||||
@Slf4j
|
||||
public class SoldierVisitor implements UnitVisitor {
|
||||
|
||||
/**
|
||||
* Soldier Visitor method.
|
||||
*
|
||||
* @param soldier Soldier to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Soldier soldier) {
|
||||
LOGGER.info("Greetings {}", soldier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sergeant Visitor method.
|
||||
*
|
||||
* @param sergeant Sergeant to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Sergeant sergeant) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Commander Visitor method.
|
||||
*
|
||||
* @param commander Commander to be visited
|
||||
*/
|
||||
@Override
|
||||
public void visit(Commander commander) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ package com.iluwatar.visitor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Interface for the nodes in hierarchy.
|
||||
*/
|
||||
/** Interface for the nodes in hierarchy. */
|
||||
public abstract class Unit {
|
||||
|
||||
private final Unit[] children;
|
||||
@@ -37,9 +35,7 @@ public abstract class Unit {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept visitor.
|
||||
*/
|
||||
/** Accept visitor. */
|
||||
public void accept(UnitVisitor visitor) {
|
||||
Arrays.stream(children).forEach(child -> child.accept(visitor));
|
||||
}
|
||||
|
||||
@@ -1,38 +1,35 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
/**
|
||||
* Visitor interface.
|
||||
*/
|
||||
public interface UnitVisitor {
|
||||
|
||||
void visit(Soldier soldier);
|
||||
|
||||
void visit(Sergeant sergeant);
|
||||
|
||||
void visit(Commander commander);
|
||||
|
||||
}
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.visitor;
|
||||
|
||||
/** Visitor interface. */
|
||||
public interface UnitVisitor {
|
||||
|
||||
void visit(Soldier soldier);
|
||||
|
||||
void visit(Sergeant sergeant);
|
||||
|
||||
void visit(Commander commander);
|
||||
}
|
||||
|
||||
@@ -24,17 +24,15 @@
|
||||
*/
|
||||
package com.iluwatar.visitor;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* Application test.
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Application test. */
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,15 +27,10 @@ package com.iluwatar.visitor;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* CommanderTest
|
||||
*
|
||||
*/
|
||||
/** CommanderTest */
|
||||
class CommanderTest extends UnitTest<Commander> {
|
||||
|
||||
/**
|
||||
* Create a new test instance for the given {@link Commander}.
|
||||
*/
|
||||
/** Create a new test instance for the given {@link Commander}. */
|
||||
public CommanderTest() {
|
||||
super(Commander::new);
|
||||
}
|
||||
@@ -44,5 +39,4 @@ class CommanderTest extends UnitTest<Commander> {
|
||||
void verifyVisit(Commander unit, UnitVisitor mockedVisitor) {
|
||||
verify(mockedVisitor).visit(eq(unit));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,24 +24,11 @@
|
||||
*/
|
||||
package com.iluwatar.visitor;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* CommanderVisitorTest
|
||||
*
|
||||
*/
|
||||
/** CommanderVisitorTest */
|
||||
class CommanderVisitorTest extends VisitorTest<CommanderVisitor> {
|
||||
|
||||
/**
|
||||
* Create a new test instance for the given visitor.
|
||||
*/
|
||||
/** Create a new test instance for the given visitor. */
|
||||
public CommanderVisitorTest() {
|
||||
super(
|
||||
new CommanderVisitor(),
|
||||
("Good to see you commander"),
|
||||
null,
|
||||
null
|
||||
);
|
||||
super(new CommanderVisitor(), ("Good to see you commander"), null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,15 +27,10 @@ package com.iluwatar.visitor;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* SergeantTest
|
||||
*
|
||||
*/
|
||||
/** SergeantTest */
|
||||
class SergeantTest extends UnitTest<Sergeant> {
|
||||
|
||||
/**
|
||||
* Create a new test instance for the given {@link Sergeant}.
|
||||
*/
|
||||
/** Create a new test instance for the given {@link Sergeant}. */
|
||||
public SergeantTest() {
|
||||
super(Sergeant::new);
|
||||
}
|
||||
@@ -44,5 +39,4 @@ class SergeantTest extends UnitTest<Sergeant> {
|
||||
void verifyVisit(Sergeant unit, UnitVisitor mockedVisitor) {
|
||||
verify(mockedVisitor).visit(eq(unit));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,24 +24,11 @@
|
||||
*/
|
||||
package com.iluwatar.visitor;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* SergeantVisitorTest
|
||||
*
|
||||
*/
|
||||
/** SergeantVisitorTest */
|
||||
class SergeantVisitorTest extends VisitorTest<SergeantVisitor> {
|
||||
|
||||
/**
|
||||
* Create a new test instance for the given visitor.
|
||||
*/
|
||||
/** Create a new test instance for the given visitor. */
|
||||
public SergeantVisitorTest() {
|
||||
super(
|
||||
new SergeantVisitor(),
|
||||
null,
|
||||
("Hello sergeant"),
|
||||
null
|
||||
);
|
||||
super(new SergeantVisitor(), null, ("Hello sergeant"), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,15 +27,10 @@ package com.iluwatar.visitor;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* SoldierTest
|
||||
*
|
||||
*/
|
||||
/** SoldierTest */
|
||||
class SoldierTest extends UnitTest<Soldier> {
|
||||
|
||||
/**
|
||||
* Create a new test instance for the given {@link Soldier}.
|
||||
*/
|
||||
/** Create a new test instance for the given {@link Soldier}. */
|
||||
public SoldierTest() {
|
||||
super(Soldier::new);
|
||||
}
|
||||
@@ -44,5 +39,4 @@ class SoldierTest extends UnitTest<Soldier> {
|
||||
void verifyVisit(Soldier unit, UnitVisitor mockedVisitor) {
|
||||
verify(mockedVisitor).visit(eq(unit));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,24 +24,11 @@
|
||||
*/
|
||||
package com.iluwatar.visitor;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* SoldierVisitorTest
|
||||
*
|
||||
*/
|
||||
/** SoldierVisitorTest */
|
||||
class SoldierVisitorTest extends VisitorTest<SoldierVisitor> {
|
||||
|
||||
/**
|
||||
* Create a new test instance for the given visitor.
|
||||
*/
|
||||
/** Create a new test instance for the given visitor. */
|
||||
public SoldierVisitorTest() {
|
||||
super(
|
||||
new SoldierVisitor(),
|
||||
null,
|
||||
null,
|
||||
("Greetings soldier")
|
||||
);
|
||||
super(new SoldierVisitor(), null, null, ("Greetings soldier"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
public abstract class UnitTest<U extends Unit> {
|
||||
|
||||
/**
|
||||
* Factory to create new instances of the tested unit.
|
||||
*/
|
||||
/** Factory to create new instances of the tested unit. */
|
||||
private final Function<Unit[], U> factory;
|
||||
|
||||
/**
|
||||
@@ -73,9 +71,8 @@ public abstract class UnitTest<U extends Unit> {
|
||||
/**
|
||||
* Verify if the correct visit method is called on the mock, depending on the tested instance.
|
||||
*
|
||||
* @param unit The tested unit instance
|
||||
* @param unit The tested unit instance
|
||||
* @param mockedVisitor The mocked {@link UnitVisitor} who should have gotten a visit by the unit
|
||||
*/
|
||||
abstract void verifyVisit(final U unit, final UnitVisitor mockedVisitor);
|
||||
|
||||
}
|
||||
|
||||
@@ -55,39 +55,30 @@ public abstract class VisitorTest<V extends UnitVisitor> {
|
||||
appender.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tested visitor instance.
|
||||
*/
|
||||
/** The tested visitor instance. */
|
||||
private final V visitor;
|
||||
|
||||
/**
|
||||
* The expected response when being visited by a commander.
|
||||
*/
|
||||
/** The expected response when being visited by a commander. */
|
||||
private final String commanderResponse;
|
||||
|
||||
/**
|
||||
* The expected response when being visited by a sergeant.
|
||||
*/
|
||||
/** The expected response when being visited by a sergeant. */
|
||||
private final String sergeantResponse;
|
||||
|
||||
/**
|
||||
* The expected response when being visited by a soldier.
|
||||
*/
|
||||
/** The expected response when being visited by a soldier. */
|
||||
private final String soldierResponse;
|
||||
|
||||
/**
|
||||
* Create a new test instance for the given visitor.
|
||||
*
|
||||
* @param commanderResponse The expected response when being visited by a commander
|
||||
* @param sergeantResponse The expected response when being visited by a sergeant
|
||||
* @param soldierResponse The expected response when being visited by a soldier
|
||||
* @param sergeantResponse The expected response when being visited by a sergeant
|
||||
* @param soldierResponse The expected response when being visited by a soldier
|
||||
*/
|
||||
public VisitorTest(
|
||||
final V visitor,
|
||||
final String commanderResponse,
|
||||
final String sergeantResponse,
|
||||
final String soldierResponse
|
||||
) {
|
||||
final String soldierResponse) {
|
||||
this.visitor = visitor;
|
||||
this.commanderResponse = commanderResponse;
|
||||
this.sergeantResponse = sergeantResponse;
|
||||
|
||||
Reference in New Issue
Block a user