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
Expand Up @@ -2,5 +2,94 @@

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

private DatabaseConfigurationBuilder() {
}

public Builder builder() {
return new Builder();
}

public static class Builder {

private DatabaseConfigurationBuilder databaseConfigurationBuilder;

Builder() {
databaseConfigurationBuilder = new DatabaseConfigurationBuilder();
}

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

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

public Builder setPassword(String password) {
this.databaseConfigurationBuilder.password = password;
return this;

}

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

public Builder setEnableCache(boolean enableCache) {
this.databaseConfigurationBuilder.enableCache = enableCache;
return this;

}

public Builder setReadOnly(boolean isReadOnly) {
this.databaseConfigurationBuilder.isReadOnly = isReadOnly;
return this;
}

public DatabaseConfigurationBuilder build(){
DatabaseConfigurationBuilder db=new DatabaseConfigurationBuilder();
db.databaseUrl=this.databaseConfigurationBuilder.databaseUrl;
db.enableCache=this.databaseConfigurationBuilder.enableCache;
db.isReadOnly=this.databaseConfigurationBuilder.isReadOnly;
db.maxConnections=this.databaseConfigurationBuilder.maxConnections;
db.password=this.databaseConfigurationBuilder.password;
db.username=this.databaseConfigurationBuilder.username;
return db;
}
}

public String getDatabaseUrl() {
return databaseUrl;
}

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public int getMaxConnections() {
return maxConnections;
}

public boolean isEnableCache() {
return enableCache;
}

public boolean isReadOnly() {
return isReadOnly;
}

}
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 All @@ -19,6 +19,44 @@ public Configuration(String themeColor, Boolean autoSave, String language, Boole
this.type = type;
}

public Configuration(Configuration reference) {
this.themeColor = reference.themeColor;
this.autoSave = reference.autoSave;
this.language = reference.language;
this.darkMode = reference.darkMode;
this.fontSize = reference.fontSize;
this.fontFamily = reference.fontFamily;
this.type = reference.type;
}

public void setThemeColor(String themeColor) {
this.themeColor = themeColor;
}

public void setAutoSave(Boolean autoSave) {
this.autoSave = autoSave;
}

public void setLanguage(String language) {
this.language = language;
}

public void setDarkMode(Boolean darkMode) {
this.darkMode = darkMode;
}

public void setFontSize(Integer fontSize) {
this.fontSize = fontSize;
}

public void setFontFamily(String fontFamily) {
this.fontFamily = fontFamily;
}

public void setType(ConfigurationType type) {
this.type = type;
}

public String getThemeColor() {
return themeColor;
}
Expand Down Expand Up @@ -46,4 +84,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
@@ -1,7 +1,9 @@
package com.scaler.lld.design.assignments.prototype;

public interface ConfigurationPrototypeRegistry {
import java.util.HashMap;
import java.util.Map;

public interface ConfigurationPrototypeRegistry {
void addPrototype(Configuration user);

Configuration getPrototype(ConfigurationType type);
Expand Down
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 Registry implements ConfigurationPrototypeRegistry{
private 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) {
Configuration configuration = registry.get(type);
return configuration.cloneObject();
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,70 @@
package com.scaler.lld.design.assignments.singleton;

public class FileBasedConfigurationManagerImpl extends FileBasedConfigurationManager {
private static FileBasedConfigurationManager INSTANCE;

private FileBasedConfigurationManagerImpl() {
}

@Override
public String getConfiguration(String key) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
//throw new UnsupportedOperationException("Unimplemented method 'getConfiguration'");
return this.properties.getProperty(key);
}

@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 result = null;
String configuration = this.properties.getProperty(key);
if (configuration != null) {
result = convert(configuration, type);
}
return result;
}

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

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

@Override
public void removeConfiguration(String key) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'removeConfiguration'");
//throw new UnsupportedOperationException("Unimplemented method 'removeConfiguration'");
this.properties.remove(key);
}

@Override
public void clear() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'clear'");
//throw new UnsupportedOperationException("Unimplemented method 'clear'");
this.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() {
INSTANCE = null;
// TODO Auto-generated method stub
}

Expand Down