Skip to content
Open
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}



}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.scaler.lld.design.assignments.prototype;
import java.io.ObjectInputFilter;

public class Configuration {
public class Configuration implements ClonableObject<Configuration>{
private String themeColor;
private Boolean autoSave;
private String language;
Expand All @@ -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;
Expand Down Expand Up @@ -46,4 +56,9 @@ public String getFontFamily() {
public ConfigurationType getType() {
return type;
}

@Override
public Configuration cloneObject() {
return new Configuration(this);
}
}
Original file line number Diff line number Diff line change
@@ -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<ConfigurationType, Configuration> 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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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> T getConfiguration(String key, Class<T> 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 <T> 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;
}

}