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
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.scaler.lld.design.assignments.builder;

import lombok.Data;
import lombok.Getter;
import lombok.With;

@WithBuilder
public class DatabaseConfiguration {

private String databaseUrl;
Expand Down Expand Up @@ -41,4 +46,53 @@ public boolean isEnableCache() {
public boolean isReadOnly() {
return isReadOnly;
}

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

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

public DatabaseConfigurationBuilder setDatabaseUrl(String databaseUrl) {
this.databaseUrl = databaseUrl;
return this;
}

public DatabaseConfigurationBuilder setUsername(String username) {
this.username = username;
return this;
}

public DatabaseConfigurationBuilder setPassword(String password) {
this.password = password;
return this;
}

public DatabaseConfigurationBuilder setMaxConnections(int maxConnections) {
this.maxConnections = maxConnections;
return this;
}

public DatabaseConfigurationBuilder setEnableCache(boolean enableCache) {
this.enableCache = enableCache;
return this;
}

public DatabaseConfigurationBuilder setReadOnly(boolean readOnly) {
isReadOnly = readOnly;
return this;
}

public DatabaseConfiguration build(){
DatabaseConfiguration config = new DatabaseConfiguration(databaseUrl, username, password, maxConnections, enableCache, isReadOnly);
// databaseUrl = null; username = null; password=null; maxConnections=0; enableCache = false; isReadOnly = false;
return config;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.scaler.lld.design.assignments.builder;

@WithBuilder
//@WithBuilder
public class DatabaseConfigurationBuilder {

}
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,18 @@ public String getFontFamily() {
public ConfigurationType getType() {
return type;
}

private Configuration(){};
@Override
public Configuration cloneObject() {
Configuration config = new Configuration();
config.themeColor = this.themeColor;
config.autoSave = this.autoSave;
config.language = this.language;
config.darkMode = this.darkMode;
config.fontSize = this.fontSize;
config.fontFamily = this.fontFamily;
config.type = this.type;
return config;
}
}
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;

public class ConfigurationPrototypeRegistryImpl implements ConfigurationPrototypeRegistry{
private HashMap<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) {
Configuration config = registry.get(type);
if(config == null) return null;
return config.cloneObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,64 @@ public class FileBasedConfigurationManagerImpl extends FileBasedConfigurationMan
@Override
public String getConfiguration(String key) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
return 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'");
String value = getConfiguration(key);
if(value == null) return null;
return convert(value, type);
// 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'");
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'");
}

private static FileBasedConfigurationManager _thisRef;
private FileBasedConfigurationManagerImpl(){}
public static FileBasedConfigurationManager getInstance() {
// TODO Auto-generated method stub
return null;
if(_thisRef == null){
synchronized (FileBasedConfigurationManagerImpl.class){
if(_thisRef == null){
_thisRef = new FileBasedConfigurationManagerImpl();
}
}
}
return _thisRef;
}

public static void resetInstance() {
// TODO Auto-generated method stub
_thisRef = null;
}

}