This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Base64Hasher implements PasswordHasher, Decryptable | |
{ | |
@Override | |
public String hashPassword(String password) | |
{ | |
return "hashed with base64"; | |
} | |
@Override | |
public String decodePasswordFromHash(String hash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Decryptable | |
{ | |
String decodePasswordFromHash(String hash); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface PasswordHasher | |
{ | |
String hashPassword(String password); | |
String decodePasswordFromHash(String hash); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Base64Hasher implements PasswordHasher | |
{ | |
@Override | |
public String hashPassword(String password) | |
{ | |
return "hashed with 64"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String hashPassword(String password, HashingType hashingType) | |
{ | |
if(HashingType.BASE64.equals(hashingType)) | |
{ | |
hashedPassword="hashed with Base64"; | |
} | |
else if(HashingType.MD5.equals(hashingType)) | |
{ | |
hashedPassword="hashed with MD5"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PasswordHasher | |
{ | |
public String hashAndSavePassword(String password) | |
{ | |
hashPassword(); | |
savePassword(); | |
} | |
public void hashPassword() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
ShipmentParameters shipmentParameters = new ShipmentParameters(); | |
shipmentParameters.setSameCity(false); | |
shipmentParameters.setDistance(40); | |
shipmentParameters.setWeight(1); | |
CargoFirm safeAndQuick = new SafeAndQuick(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FastDeliveryByDistance implements FastDeliveryBehavior | |
{ | |
private static final int distanceFor1Day = 50; | |
@Override | |
public void calculateDaysForDelivery(ShipmentParameters shipmentParameters) | |
{ | |
if(shipmentParameters.distance > distanceFor1Day) | |
{ | |
System.out.println("Will be delivered in 2 Days"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FastDeliveryByCity implements FastDeliveryBehavior | |
{ | |
@Override | |
public void calculateDaysForDelivery(ShipmentParameters shipmentParameters) | |
{ | |
if(shipmentParameters.isSameCity) | |
{ | |
System.out.println("Will be delivered in 1 Days"); | |
} | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
ShipmentParameters shipmentParameters = new ShipmentParameters(); | |
shipmentParameters.isSameCity = false; | |
shipmentParameters.distance = 70; | |
shipmentParameters.weight = 1; | |
CargoFirm safeAndQuick = new SafeAndQuick(); | |
safeAndQuick.createShipment(); |