diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..1b673a0
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..56c7380
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/scaler/lld/design/assignments/builder/DatabaseConfigurationBuilder.java b/src/main/java/com/scaler/lld/design/assignments/builder/DatabaseConfigurationBuilder.java
index 592aa32..5ad0581 100644
--- a/src/main/java/com/scaler/lld/design/assignments/builder/DatabaseConfigurationBuilder.java
+++ b/src/main/java/com/scaler/lld/design/assignments/builder/DatabaseConfigurationBuilder.java
@@ -2,5 +2,51 @@
@WithBuilder
public class DatabaseConfigurationBuilder {
+ private String databaseUrl;
+ private String username;
+ private String password;
+ private int maxConnections;
+ private boolean enableCache;
+ private boolean isReadOnly;
+ public static Builder builder(){ //static builder method
+ return new Builder();
+ }
+ private DatabaseConfigurationBuilder(){} //Private constructor
+ public static class Builder{
+
+ DatabaseConfigurationBuilder obj;
+ public Builder(){
+ obj=new DatabaseConfigurationBuilder();
+ }
+ public Builder setDatabaseUrl(String databaseUrl) {
+ obj.databaseUrl = databaseUrl; return this;
+ }
+
+ public Builder setUsername(String username) {
+ obj.username = username; return this;
+ }
+
+ public Builder setPassword(String password) {
+ obj.password = password; return this;
+ }
+
+ public Builder setMaxConnections(int maxConnections) {
+ obj.maxConnections = maxConnections; return this;
+ }
+
+ public Builder setEnableCache(boolean enableCache) {
+ obj.enableCache = enableCache; return this;
+ }
+
+ public Builder setReadOnly(boolean readOnly) {
+ obj.isReadOnly = readOnly; return this;
+ }
+ public DatabaseConfigurationBuilder build(){
+ return obj;
+ }
+
+ }
+
+
}
\ No newline at end of file
diff --git a/src/main/java/com/scaler/lld/design/assignments/prototype/Configuration.java b/src/main/java/com/scaler/lld/design/assignments/prototype/Configuration.java
index 597f36e..6537060 100644
--- a/src/main/java/com/scaler/lld/design/assignments/prototype/Configuration.java
+++ b/src/main/java/com/scaler/lld/design/assignments/prototype/Configuration.java
@@ -1,6 +1,7 @@
package com.scaler.lld.design.assignments.prototype;
+import java.io.ObjectInputFilter;
-public class Configuration {
+public class Configuration implements ClonableObject{
private String themeColor;
private Boolean autoSave;
private String language;
@@ -18,6 +19,15 @@ public Configuration(String themeColor, Boolean autoSave, String language, Boole
this.fontFamily = fontFamily;
this.type = type;
}
+ private Configuration(Configuration obj){
+ this.themeColor=obj.themeColor;
+ this.autoSave=obj.autoSave;
+ this.language=obj.language;
+ this.darkMode=obj.darkMode;
+ this.fontSize= obj.fontSize;
+ this.type=obj.type;
+ this.fontFamily=obj.fontFamily;
+ }
public String getThemeColor() {
return themeColor;
@@ -46,4 +56,9 @@ public String getFontFamily() {
public ConfigurationType getType() {
return type;
}
+
+ @Override
+ public Configuration cloneObject() {
+ return new Configuration(this);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/scaler/lld/design/assignments/prototype/ConfigurationPrototypeRegistryImpl.java b/src/main/java/com/scaler/lld/design/assignments/prototype/ConfigurationPrototypeRegistryImpl.java
new file mode 100644
index 0000000..d1e8d13
--- /dev/null
+++ b/src/main/java/com/scaler/lld/design/assignments/prototype/ConfigurationPrototypeRegistryImpl.java
@@ -0,0 +1,29 @@
+package com.scaler.lld.design.assignments.prototype;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ConfigurationPrototypeRegistryImpl implements ConfigurationPrototypeRegistry{
+ Map registry=new HashMap<>();
+ @Override
+ public void addPrototype(Configuration user) {
+ registry.put(user.getType(), user);
+
+ }
+
+ @Override
+ public Configuration getPrototype(ConfigurationType type) {
+ return registry.get(type);
+ }
+
+ @Override
+ public Configuration clone(ConfigurationType type) {
+ if(registry.containsKey(type)){
+ Configuration prototype=registry.get(type);
+ return prototype.cloneObject();
+ }
+ else{
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/com/scaler/lld/design/assignments/singleton/FileBasedConfigurationManagerImpl.java b/src/main/java/com/scaler/lld/design/assignments/singleton/FileBasedConfigurationManagerImpl.java
index 15470fc..f5d82a0 100644
--- a/src/main/java/com/scaler/lld/design/assignments/singleton/FileBasedConfigurationManagerImpl.java
+++ b/src/main/java/com/scaler/lld/design/assignments/singleton/FileBasedConfigurationManagerImpl.java
@@ -1,50 +1,72 @@
package com.scaler.lld.design.assignments.singleton;
public class FileBasedConfigurationManagerImpl extends FileBasedConfigurationManager {
-
+ private static FileBasedConfigurationManagerImpl instance=null;
+ private FileBasedConfigurationManagerImpl(){
+ }
@Override
public String getConfiguration(String key) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
+ return this.properties.getProperty(key);
+ //throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
}
@Override
public T getConfiguration(String key, Class type) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
+ if(instance!=null){
+ String value=instance.properties.getProperty(key); //This retrieves the value
+ if(value!=null)
+ return convert(value,type);
+ else
+ return null;
+ }
+ else{
+ throw new NullPointerException("Configuration Manager Instance is NULL");
+ }
+ //throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
+
}
@Override
public void setConfiguration(String key, String value) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Unimplemented method 'setConfiguration'");
+ this.properties.setProperty(key, value);
+ //throw new UnsupportedOperationException("Unimplemented method 'setConfiguration'");
+
}
@Override
public void setConfiguration(String key, T value) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Unimplemented method 'setConfiguration'");
+ properties.setProperty(key, String.valueOf((value)));
+ //throw new UnsupportedOperationException("Unimplemented method 'setConfiguration'");
+
}
@Override
public void removeConfiguration(String key) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Unimplemented method 'removeConfiguration'");
+ properties.remove(key);
+ //throw new UnsupportedOperationException("Unimplemented method 'removeConfiguration'");
+
}
@Override
public void clear() {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Unimplemented method 'clear'");
+ properties.clear();
+ //throw new UnsupportedOperationException("Unimplemented method 'clear'");
+
}
public static FileBasedConfigurationManager getInstance() {
- // TODO Auto-generated method stub
- return null;
+ if(instance==null){
+ synchronized (FileBasedConfigurationManagerImpl.class){
+ if(instance==null){
+ instance=new FileBasedConfigurationManagerImpl();
+ }
+ }
+ }
+ return instance;
}
public static void resetInstance() {
- // TODO Auto-generated method stub
+ instance=null;
}
}
\ No newline at end of file