Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
/*
* 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.acyclicvisitor;

import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,20 +9,19 @@
public class Hayes implements Modem {

/**
* Accepts all visitors but honors only HayesVisitor.
* Accepts all visitors and interacts with SpecificModemVisitor.
*/
@Override
public void accept(ModemVisitor modemVisitor) {
if (modemVisitor instanceof HayesVisitor) {
((HayesVisitor) modemVisitor).visit(this);
if (modemVisitor instanceof SpecificModemVisitor) {
((SpecificModemVisitor) modemVisitor).visit(this);
} else {
LOGGER.info("Only HayesVisitor is allowed to visit Hayes modem");
LOGGER.info("Unsupported visitor type for Hayes modem");
}

}

/**
* Hayes' modem's toString method.
* Hayes modem's toString method.
*/
@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
/*
* 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.acyclicvisitor;

/**
* HayesVisitor interface.
* HayesVisitor interface for Hayes-specific logic.
*/
public interface HayesVisitor extends ModemVisitor {
void visit(Hayes hayes);
public interface HayesVisitor extends SpecificModemVisitor {
void visit(Hayes hayes); // Supports Hayes-specific behavior
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.iluwatar.acyclicvisitor;

/**
* General visitor interface for specific modems.
*/
public interface SpecificModemVisitor extends ModemVisitor {
void visit(Modem modem);
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
/*
* 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.acyclicvisitor;

import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,14 +9,14 @@
public class Zoom implements Modem {

/**
* Accepts all visitors but honors only ZoomVisitor.
* Accepts all visitors but interacts generically with SpecificModemVisitor.
*/
@Override
public void accept(ModemVisitor modemVisitor) {
if (modemVisitor instanceof ZoomVisitor) {
((ZoomVisitor) modemVisitor).visit(this);
if (modemVisitor instanceof SpecificModemVisitor) {
((SpecificModemVisitor) modemVisitor).visit(this);
} else {
LOGGER.info("Only ZoomVisitor is allowed to visit Zoom modem");
LOGGER.info("Unsupported visitor type for Zoom modem");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
/*
* 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.acyclicvisitor;

/**
* ZoomVisitor interface.
* ZoomVisitor interface, extending SpecificModemVisitor for Zoom-specific logic.
*/
public interface ZoomVisitor extends ModemVisitor {
void visit(Zoom zoom);
public interface ZoomVisitor extends SpecificModemVisitor {
void visit(Zoom zoom); // Still supports Zoom-specific operations
}
24 changes: 24 additions & 0 deletions extension-objects/src/main/java/units/Commander.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package concreteextensions;

import abstractextensions.CommanderExtension;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
* Class defining Commander.
*/
@Slf4j
public class Commander implements CommanderExtension {
private final CommanderUnit unit;

// Constructor now injects CommanderUnit
public Commander(CommanderUnit unit) {
this.unit = unit;
}

@Override
public void commanderReady() {
LOGGER.info("[Commander] " + unit.getName() + " is ready!");
}
}
Empty file.
8 changes: 8 additions & 0 deletions extension-objects/src/main/java/units/CommanderExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package abstractextensions;

/**
* Interface for commander extensions.
*/
public interface CommanderExtension {
void commanderReady();
}
34 changes: 7 additions & 27 deletions extension-objects/src/main/java/units/CommanderUnit.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
/*
* 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 units;

import abstractextensions.UnitExtension;
Expand All @@ -33,17 +9,21 @@
*/
public class CommanderUnit extends Unit {

private CommanderExtension unitExtension;

public CommanderUnit(String name) {
super(name);
}

@Override
public UnitExtension getUnitExtension(String extensionName) {

if (extensionName.equals("CommanderExtension")) {
return Optional.ofNullable(unitExtension).orElseGet(() -> new Commander(this));
// Commander is now injected instead of being instantiated inside the method
if (unitExtension == null) {
unitExtension = new Commander(this); // Dependency injection here
}
return unitExtension;
}

return super.getUnitExtension(extensionName);
}
}
Loading