-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
commit #12
Open
shaileshexp
wants to merge
3
commits into
kanmaytacker:master
Choose a base branch
from
shaileshexp:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
commit #12
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/main/java/com/scaler/lld/design/assignments/builder/DatabaseConfigurationBuilder.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,80 @@ | ||
package com.scaler.lld.design.assignments.builder; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@WithBuilder | ||
@Getter | ||
public class DatabaseConfigurationBuilder { | ||
|
||
private String databaseUrl; | ||
private String username; | ||
private String password; | ||
private int maxConnections; | ||
private boolean enableCache; | ||
private boolean isReadOnly; | ||
|
||
|
||
private DatabaseConfigurationBuilder(String databaseUrl, String username, String password, int maxConnections, boolean enableCache, boolean isReadOnly) { | ||
this.databaseUrl = databaseUrl; | ||
this.username = username; | ||
this.password = password; | ||
this.maxConnections = maxConnections; | ||
this.enableCache = enableCache; | ||
this.isReadOnly = isReadOnly; | ||
} | ||
|
||
public static Builder getBuilder(){ | ||
return new Builder(); | ||
} | ||
|
||
@Setter | ||
@Getter | ||
public static class Builder{ | ||
|
||
private String databaseUrl; | ||
private String username; | ||
private String password; | ||
private int maxConnections; | ||
private boolean enableCache; | ||
private boolean isReadOnly; | ||
|
||
|
||
|
||
public Builder setDatabaseUrl(String databaseUrl) { | ||
this.databaseUrl = databaseUrl; | ||
return this; | ||
} | ||
|
||
public Builder setUsername(String username) { | ||
this.username = username; | ||
return this; | ||
} | ||
|
||
public Builder setPassword(String password) { | ||
this.password = password; | ||
return this; | ||
} | ||
|
||
public Builder setMaxConnections(int maxConnections) { | ||
this.maxConnections = maxConnections; | ||
return this; | ||
} | ||
|
||
public Builder setEnableCache(boolean enableCache) { | ||
this.enableCache = enableCache; | ||
return this; | ||
} | ||
|
||
public Builder setReadOnly(boolean readOnly) { | ||
isReadOnly = readOnly; | ||
return this; | ||
} | ||
|
||
public DatabaseConfigurationBuilder build(){ | ||
return new DatabaseConfigurationBuilder | ||
(this.databaseUrl, this.username, this.password, this.maxConnections, this.enableCache, this.isReadOnly); | ||
} | ||
|
||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
.../java/com/scaler/lld/design/assignments/prototype/ConfigurationPrototypeRegistryImpl.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.scaler.lld.design.assignments.prototype; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ConfigurationPrototypeRegistryImpl implements ConfigurationPrototypeRegistry{ | ||
|
||
private Map<ConfigurationType, Configuration> registryMap = new HashMap<>(); | ||
|
||
|
||
@Override | ||
public void addPrototype(Configuration user) { | ||
registryMap.putIfAbsent(user.getType(), user); | ||
} | ||
|
||
@Override | ||
public Configuration getPrototype(ConfigurationType type) { | ||
return registryMap.get(type); | ||
} | ||
|
||
@Override | ||
public Configuration clone(ConfigurationType type) { | ||
return registryMap.get(type).cloneObject(); | ||
} | ||
} |
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
42 changes: 27 additions & 15 deletions
42
...n/java/com/scaler/lld/design/assignments/singleton/FileBasedConfigurationManagerImpl.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,62 @@ | ||
package com.scaler.lld.design.assignments.singleton; | ||
|
||
import java.util.Optional; | ||
|
||
public class FileBasedConfigurationManagerImpl extends FileBasedConfigurationManager { | ||
|
||
private static FileBasedConfigurationManagerImpl INSTANCE = null; | ||
|
||
private FileBasedConfigurationManagerImpl() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public String getConfiguration(String key) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'"); | ||
return properties.getProperty(key); | ||
} | ||
|
||
@Override | ||
public <T> T getConfiguration(String key, Class<T> type) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'"); | ||
return convert(properties.getProperty(key), type); | ||
} | ||
|
||
@Override | ||
public void setConfiguration(String key, String value) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'setConfiguration'"); | ||
properties.setProperty(key, value); | ||
} | ||
|
||
@Override | ||
public <T> void setConfiguration(String key, T value) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'setConfiguration'"); | ||
properties.setProperty(key, String.valueOf((value))); | ||
} | ||
|
||
@Override | ||
public void removeConfiguration(String key) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'removeConfiguration'"); | ||
properties.remove(key); | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'clear'"); | ||
if(!properties.isEmpty()) { | ||
properties.clear(); | ||
} | ||
} | ||
|
||
public static FileBasedConfigurationManager getInstance() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
if(INSTANCE == null ){ | ||
synchronized (FileBasedConfigurationManager.class){ | ||
if(INSTANCE == null){ | ||
INSTANCE = new FileBasedConfigurationManagerImpl() ; | ||
} | ||
} | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
public static void resetInstance() { | ||
// TODO Auto-generated method stub | ||
if(INSTANCE != null ){ | ||
INSTANCE = null; | ||
} | ||
} | ||
|
||
} |
11 changes: 10 additions & 1 deletion
11
src/main/java/com/scaler/lld/design/creational/parleg/Button.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
package com.scaler.lld.design.creational.parleg;public class Button { | ||
package com.scaler.lld.design.creational.parleg; | ||
public abstract class Button { | ||
private Double border; | ||
public Button(Double border) { | ||
this.border = border; | ||
} | ||
|
||
abstract public void onClick() ; | ||
|
||
abstract public void render(); | ||
} |
60 changes: 55 additions & 5 deletions
60
src/main/java/com/scaler/lld/design/creational/simplefactory/button/ButtonFactory.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,66 @@ | ||
package com.scaler.lld.design.creational.simplefactory.button; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class ButtonFactory { | ||
|
||
private ScreenSize screenSize; | ||
private Double border; | ||
private Double radius; | ||
private Double length; | ||
|
||
private ButtonFactory(){ | ||
|
||
} | ||
public static Builder getBuilder(){ | ||
return new Builder(); | ||
} | ||
@Setter | ||
@Getter | ||
static class Builder{ | ||
private ScreenSize screenSize; | ||
private Double border; | ||
private Double radius; | ||
private Double length; | ||
|
||
public Builder setScreenSize(ScreenSize screenSize) { | ||
this.screenSize = screenSize; | ||
return this; | ||
} | ||
|
||
public Builder setBorder(Double border) { | ||
this.border = border; | ||
return this; | ||
} | ||
|
||
public Builder setRadius(Double radius) { | ||
this.radius = radius; | ||
return this; | ||
} | ||
|
||
public Builder setLength(Double length) { | ||
this.length = length; | ||
return this; | ||
} | ||
|
||
public Button build(){ | ||
return createButton(this); | ||
} | ||
} | ||
|
||
// Step 3 - Create a static factory method | ||
public static Button createButton(ScreenSize screenSize, Double border, Double radius, Double length) { | ||
switch (screenSize) { | ||
public static Button createButton(Builder build) { | ||
switch (build.getScreenSize()) { | ||
case PHONE: | ||
case TABLET: return new RoundButton(border, radius); | ||
case DESKTOP: return new SquareButton(border, length); | ||
case TABLET: return new RoundButton(build.getBorder(), build.getRadius()); | ||
case DESKTOP: return new SquareButton(build.getBorder(), build.getLength()); | ||
} | ||
|
||
throw new IllegalArgumentException("Invalid type: " + screenSize); | ||
throw new IllegalArgumentException("Invalid type: " + build.getScreenSize()); | ||
|
||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented the review comments