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
8 changes: 8 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
@@ -1,6 +1,78 @@
package com.scaler.lld.design.assignments.builder;

import lombok.Getter;

@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(){
}

public static DBConfigBuilder builder(){
return new DBConfigBuilder();
}

public static class DBConfigBuilder {
public String databaseUrl;
private String username;
private String password;
private int maxConnections;
private boolean enableCache;
private boolean isReadOnly;

// Creating fluent interfaces for setter
public DBConfigBuilder setDatabaseUrl(String databaseUrl){
this.databaseUrl = databaseUrl;
return this;
}
public DBConfigBuilder setUsername(String username){
this.username = username;
return this;
}
public DBConfigBuilder setPassword(String password){
this.password = password;
return this;
}
public DBConfigBuilder setMaxConnections(int maxConnections){
this.maxConnections = maxConnections;
return this;
}
public DBConfigBuilder setEnableCache(boolean enableCache){
this.enableCache = enableCache;
return this;
}
public DBConfigBuilder setIsReadOnly(boolean isReadOnly){
this.isReadOnly = isReadOnly;
return this;
}

public DatabaseConfigurationBuilder build(){
// if (!isValid()){
// throw new IllegalArgumentException("Ivalid Database Configuration");
// }
DatabaseConfigurationBuilder databaseConfigurationBuilder = new DatabaseConfigurationBuilder();
databaseConfigurationBuilder.databaseUrl = this.databaseUrl;
databaseConfigurationBuilder.username = this.username;
databaseConfigurationBuilder.password = this.password;
databaseConfigurationBuilder.maxConnections = this.maxConnections;
databaseConfigurationBuilder.enableCache = this.enableCache;
databaseConfigurationBuilder.isReadOnly = this.isReadOnly;
return databaseConfigurationBuilder;
}

// public Boolean isValid(){
// if (this.databaseUrl == null){
// return false;
// }
// return true;
// }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.scaler.lld.design.assignments.prototype;

public class Configuration {
public class Configuration implements ClonableObject{
private String themeColor;
private Boolean autoSave;
private String language;
Expand Down Expand Up @@ -46,4 +46,10 @@ public String getFontFamily() {
public ConfigurationType getType() {
return type;
}

@Override
public Object cloneObject() {
Configuration configuration = new Configuration(this.themeColor, this.autoSave, this.language, this.darkMode, this.fontSize, this.fontFamily, this.type);
return configuration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.scaler.lld.design.assignments.prototype;

import java.util.HashMap;
import java.util.Map;

public class ConfigurationRegistry implements ConfigurationPrototypeRegistry{
private Map<ConfigurationType, Configuration> registy = new HashMap<>();
@Override
public void addPrototype(Configuration user) {
registy.put(user.getType(), user);
}

@Override
public Configuration getPrototype(ConfigurationType type) {
return registy.get(type);
}

@Override
public Configuration clone(ConfigurationType type) {
Configuration config = registy.get(type);
return (Configuration) config.cloneObject();
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,80 @@
package com.scaler.lld.design.assignments.singleton;

import java.util.HashMap;
import java.util.Map;

public class FileBasedConfigurationManagerImpl extends FileBasedConfigurationManager {

private static FileBasedConfigurationManager INSTANCE = null;
// public Map<String, String> config = new HashMap<>();
// public Map<String, > configDiffType = new HashMap<>();

private FileBasedConfigurationManagerImpl(){}

@Override
public String getConfiguration(String key) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
String rvalue = null;
if (properties.containsKey(key)){
rvalue = (String) properties.get(key);
}
return rvalue;
}

@Override
public <T> T getConfiguration(String key, Class<T> type) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
// throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
T rValue = null;
if (properties.containsKey(key)){
String value = (String) properties.get(key);
rValue = (T) convert(value, type);
}
return rValue;
}

@Override
public void setConfiguration(String key, String value) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'setConfiguration'");
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'setConfiguration'");
properties.put(key, value);
}

@Override
public <T> void setConfiguration(String key, T value) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'setConfiguration'");

}

@Override
public void removeConfiguration(String key) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'removeConfiguration'");
// // 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'");
// // TODO Auto-generated method stub
// throw new UnsupportedOperationException("Unimplemented method 'clear'");
properties.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;
}

}