mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Implement context merging, fixes #85
This commit is contained in:
1 parent
c79c1bcbee
commit
2ee3392308
2 files changed
+67
-10
No files matched your search
@@ -70,10 +70,29 @@ public class ChannelOptions {
|
|||||||
return this.color;
|
return this.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Context context(final @NonNull String key) {
|
||||||
|
final Context localContext;
|
||||||
|
|
||||||
|
if (this.contexts != null) {
|
||||||
|
localContext = this.contexts.get(key);
|
||||||
|
} else {
|
||||||
|
localContext = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localContext == null) {
|
||||||
|
if (this.defaultOptions().contexts() != null) {
|
||||||
|
return this.defaultOptions().contexts().get(key);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return localContext;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Map<String, Context> contexts() {
|
public Map<String, Context> contexts() {
|
||||||
// TODO: properly implement default context inheritence
|
|
||||||
// TODO: perhaps add an option to make it so overriding any context overrides all?
|
|
||||||
if (this.contexts == null) {
|
if (this.contexts == null) {
|
||||||
return this.defaultOptions().contexts();
|
return this.defaultOptions().contexts();
|
||||||
}
|
}
|
||||||
@@ -82,18 +101,40 @@ public class ChannelOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String format(final String key) {
|
public Map<String, Context> contextsAndDefault() {
|
||||||
if (this.formats == null) {
|
if (this.contexts == null) {
|
||||||
return this.defaultOptions().formats().get(key);
|
return this.defaultOptions().contexts();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String format = this.formats.get(key);
|
if (this.defaultOptions().contexts() == null) {
|
||||||
|
return this.contexts;
|
||||||
if (format != null) {
|
|
||||||
return format;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Map<String, Context> contexts = new HashMap<>(this.defaultOptions().contexts());
|
||||||
|
contexts.putAll(this.contexts);
|
||||||
|
|
||||||
|
return contexts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String format(final @NonNull String key) {
|
||||||
|
final String localFormat;
|
||||||
|
|
||||||
|
if (this.formats() != null) {
|
||||||
|
localFormat = this.formats().get(key);
|
||||||
|
} else {
|
||||||
|
localFormat = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localFormat == null) {
|
||||||
|
if (this.defaultOptions().formats() != null) {
|
||||||
return this.defaultOptions().formats().get(key);
|
return this.defaultOptions().formats().get(key);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return localFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -105,6 +146,22 @@ public class ChannelOptions {
|
|||||||
return this.formats;
|
return this.formats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Map<String, String> formatsAndDefault() {
|
||||||
|
if (this.formats == null) {
|
||||||
|
return this.defaultOptions().formats();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.defaultOptions().formats() == null) {
|
||||||
|
return this.formats;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Map<String, String> formats = new HashMap<>(this.defaultOptions().formats());
|
||||||
|
formats.putAll(this.formats);
|
||||||
|
|
||||||
|
return formats;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String defaultFormatName() {
|
public String defaultFormatName() {
|
||||||
if (this.defaultFormatName == null || this.defaultFormatName.isEmpty()) {
|
if (this.defaultFormatName == null || this.defaultFormatName.isEmpty()) {
|
||||||
|
|||||||
+1
-1
@@ -515,7 +515,7 @@ public class CarbonChatChannel implements ChatChannel {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Context context(final @NonNull String key) {
|
public Context context(final @NonNull String key) {
|
||||||
return this.options().contexts().get(key);
|
return this.options().context(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user