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

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

}
/// immutable
private DatabaseConfigurationBuilder() {

}

//// friend class
public static class Builder {

private String databaseUrl;
private String username;
private String password;
private int maxConnections;
private boolean enableCache;
private boolean isReadOnly;

private Builder(){

}


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

public Builder setUsernameAndPassword(String username, String password) {
this.username = username;
this.password = password;
return this;
}

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

public Builder isEnableCache(boolean enableCache) {
this.enableCache = enableCache;
return this;
}

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

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

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,21 @@

public abstract class AudioPlayer {

private int volume;
private double playBackRate;

AudioPlayer(int volume, double playBackRate) {
this.playBackRate = playBackRate;
this.volume = volume;
}

public abstract MediaFormat supportsType();

public abstract void play();

public abstract void pause();

public abstract void stop();


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
package com.scaler.lld.design.assignments.factory;

public class AudioPlayerFactory {
static AudioPlayer createAudioPlayer(MediaFormat format, int volume, double playBackRate) {
if (format == MediaFormat.FLAC) {
FLACPlayer FlacObj = new FLACPlayer(volume, playBackRate);
return FlacObj;
} else if (format == MediaFormat.MP3) {
MP3Player Mp3Obj = new MP3Player(volume, playBackRate);
return Mp3Obj;
} else {
WAVPlayer WavObj = new WAVPlayer(volume, playBackRate);
return WavObj;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.scaler.lld.design.assignments.factory;

public class FLACPlayer {
public class FLACPlayer extends AudioPlayer {
private int volume;
private double playBackRate;

public FLACPlayer(int volume, double playBackRate) {
this.volume = volume;
this.playBackRate = playBackRate;
super(volume, playBackRate);
}

public void play() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.scaler.lld.design.assignments.factory;

public class MP3Player {
public class MP3Player extends AudioPlayer {
private int volume;
private double playBackRate;

public MP3Player(int volume, double playBackRate) {
this.volume = volume;
this.playBackRate = playBackRate;
super(volume, playBackRate);
}

public void play() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.scaler.lld.design.assignments.factory;

public class WAVPlayer {
public class WAVPlayer extends AudioPlayer {
private int volume;
private double playBackRate;

public WAVPlayer(int volume, double playBackRate) {
this.volume = volume;
this.playBackRate = playBackRate;
super(volume, playBackRate);
}

public void play() {
Expand Down
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 @@ -9,7 +9,8 @@ public class Configuration {
private String fontFamily;
private ConfigurationType type;

public Configuration(String themeColor, Boolean autoSave, String language, Boolean darkMode, Integer fontSize, String fontFamily, ConfigurationType type) {
public Configuration(String themeColor, Boolean autoSave, String language, Boolean darkMode, Integer fontSize,
String fontFamily, ConfigurationType type) {
this.themeColor = themeColor;
this.autoSave = autoSave;
this.language = language;
Expand All @@ -19,6 +20,21 @@ public Configuration(String themeColor, Boolean autoSave, String language, Boole
this.type = type;
}

public Configuration() {

}

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

public String getThemeColor() {
return themeColor;
}
Expand Down Expand Up @@ -46,4 +62,12 @@ public String getFontFamily() {
public ConfigurationType getType() {
return type;
}

@Override
public Object cloneObject() {
Configuration ref = new Configuration();
return Configuration(ref);

}

}
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;

public class Registry implements ConfigurationPrototypeRegistry {

HashMap<ConfigurationType, Configuration> storage = new HashMap<>();

@Override
public void addPrototype(Configuration user) {

storage.put(user.getType(), user);

}

@Override
public Configuration getPrototype(ConfigurationType type) {

return storage.get(type);
}

@Override
public Configuration clone(ConfigurationType type) {

return (Configuration) storage.get(type).cloneObject();

}

}
Original file line number Diff line number Diff line change
@@ -1,50 +1,81 @@
package com.scaler.lld.design.assignments.singleton;

import java.util.Properties;

public class FileBasedConfigurationManagerImpl extends FileBasedConfigurationManager {

private static FileBasedConfigurationManagerImpl instance = null;
Properties s = this.properties;

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'");
if (s.containsKey(key)) {
return s.getProperty(key);
} else {
return null;
}

}

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

@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'");
s.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'");
}

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

@Override
public void clear() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'clear'");
// throw new UnsupportedOperationException("Unimplemented method 'clear'");
s.clear();
}

public static FileBasedConfigurationManager getInstance() {
// TODO Auto-generated method stub
return null;
if (instance == null) {
instance = new FileBasedConfigurationManagerImpl();
return instance;
} else {
return instance;
}
}

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

}