-
Notifications
You must be signed in to change notification settings - Fork 4
Introduce Range Query, Null and Generalized args generators in Java version #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| package contention.benchmark.workload.args.generators.abstractions; | ||
| import contention.benchmark.tools.Pair; | ||
|
|
||
| public interface ArgsGenerator { | ||
| int nextGet(); | ||
|
|
||
| int nextInsert(); | ||
|
|
||
| int nextRemove(); | ||
|
|
||
| Pair<Integer, Integer> nextRange(); | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,11 +1,11 @@ | ||||
| package contention.benchmark.workload.args.generators.builders; | ||||
|
|
||||
| import contention.benchmark.workload.args.generators.impls.DefaultArgsGenerator; | ||||
| import contention.benchmark.workload.distributions.abstractions.DistributionBuilder; | ||||
| import contention.benchmark.workload.distributions.builders.UniformDistributionBuilder; | ||||
| import contention.benchmark.workload.args.generators.abstractions.ArgsGeneratorBuilder; | ||||
| import contention.benchmark.workload.args.generators.impls.DefaultArgsGenerator; | ||||
| import contention.benchmark.workload.data.map.abstractions.DataMapBuilder; | ||||
| import contention.benchmark.workload.data.map.builders.IdDataMapBuilder; | ||||
| import contention.benchmark.workload.distributions.abstractions.DistributionBuilder; | ||||
| import contention.benchmark.workload.distributions.builders.UniformDistributionBuilder; | ||||
|
|
||||
| import static contention.benchmark.tools.StringFormat.indentedTitle; | ||||
| import static contention.benchmark.tools.StringFormat.indentedTitleWithData; | ||||
|
|
@@ -43,7 +43,7 @@ public DefaultArgsGenerator build() { | |||
| @Override | ||||
| public StringBuilder toStringBuilder(int indents) { | ||||
| return new StringBuilder() | ||||
| .append(indentedTitleWithData("Type", "Default", indents)) | ||||
| .append(indentedTitleWithData("Type", "DEFAULT", indents)) | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. можно без капса
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А у нас же у каждого Line 88 in 0248b8e
|
||||
| .append(indentedTitle("Distribution", indents)) | ||||
| .append(distributionBuilder.toStringBuilder(indents + 1)) | ||||
| .append(indentedTitle("DataMap", indents)) | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package contention.benchmark.workload.args.generators.builders; | ||
|
|
||
| import contention.benchmark.workload.args.generators.abstractions.ArgsGenerator; | ||
| import contention.benchmark.workload.args.generators.abstractions.ArgsGeneratorBuilder; | ||
| import contention.benchmark.workload.args.generators.impls.GeneralizedArgsGenerator; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import static contention.benchmark.tools.StringFormat.indentedTitle; | ||
| import static contention.benchmark.tools.StringFormat.indentedTitleWithData; | ||
|
|
||
| public class GeneralizedArgsGeneratorBuilder implements ArgsGeneratorBuilder { | ||
| private static final Set<String> OPER_TYPES = Set.of("get", "insert", "remove", "rangeQuery"); | ||
|
|
||
| private static class BuilderOperations { | ||
| ArgsGeneratorBuilder builder; | ||
| List<String> operations; | ||
|
|
||
| BuilderOperations(ArgsGeneratorBuilder builder, List<String> operations) { | ||
| this.builder = builder; | ||
| this.operations = operations; | ||
| } | ||
| } | ||
|
|
||
| private List<BuilderOperations> argsGeneratorBuilders = new ArrayList<>(); | ||
| private Set<String> undecOperTypes = new HashSet<>(OPER_TYPES); | ||
|
|
||
| public GeneralizedArgsGeneratorBuilder addArgsGeneratorBuilder(List<String> opers, | ||
| ArgsGeneratorBuilder argsGenBuilder) { | ||
| for (String operType : opers) { | ||
| if (!OPER_TYPES.contains(operType)) { | ||
| throw new IllegalArgumentException("Unsupported operation type: " + operType); | ||
| } | ||
| if (!undecOperTypes.contains(operType)) { | ||
| throw new IllegalArgumentException("Multiple declaration of operation type: " + operType); | ||
| } | ||
| undecOperTypes.remove(operType); | ||
| } | ||
|
|
||
| argsGeneratorBuilders.add(new BuilderOperations(argsGenBuilder, opers)); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public ArgsGeneratorBuilder init(int range) { | ||
| if (!undecOperTypes.isEmpty()) { | ||
| addArgsGeneratorBuilder( | ||
| new ArrayList<>(undecOperTypes), | ||
| new NullArgsGeneratorBuilder() | ||
| ); | ||
| } | ||
|
|
||
| for (BuilderOperations currentBuilder : argsGeneratorBuilders) { | ||
| currentBuilder.builder.init(range); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public ArgsGenerator build() { | ||
| Map<String, ArgsGenerator> built = new HashMap<>(); | ||
| for (BuilderOperations currentBuilder : argsGeneratorBuilders) { | ||
| ArgsGenerator generator = currentBuilder.builder.build(); | ||
| for (String operType : currentBuilder.operations) { | ||
| built.put(operType, generator); | ||
| } | ||
| } | ||
|
|
||
| return new GeneralizedArgsGenerator( | ||
| built.get("get"), | ||
| built.get("insert"), | ||
| built.get("remove"), | ||
| built.get("rangeQuery") | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public StringBuilder toStringBuilder(int indents) { | ||
| StringBuilder sb = new StringBuilder() | ||
| .append(indentedTitleWithData("Type", "GENERALIZED", indents)); | ||
|
|
||
| for (BuilderOperations currentBuilder : argsGeneratorBuilders) { | ||
| String opers = String.join(", ", currentBuilder.operations); | ||
| sb.append(indentedTitle("Args Generators (" + opers + ")", indents)); | ||
| sb.append(currentBuilder.builder.toStringBuilder(indents + 1)); | ||
| } | ||
|
|
||
| return sb; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package contention.benchmark.workload.args.generators.builders; | ||
|
|
||
| import contention.benchmark.workload.args.generators.abstractions.ArgsGenerator; | ||
| import contention.benchmark.workload.args.generators.abstractions.ArgsGeneratorBuilder; | ||
| import contention.benchmark.workload.args.generators.impls.NullArgsGenerator; | ||
|
|
||
| public class NullArgsGeneratorBuilder implements ArgsGeneratorBuilder { | ||
|
|
||
| public NullArgsGeneratorBuilder() { | ||
| } | ||
|
|
||
| @Override | ||
| public ArgsGeneratorBuilder init(int range) { | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public ArgsGenerator build() { | ||
| return new NullArgsGenerator(); | ||
| } | ||
|
|
||
| @Override | ||
| public StringBuilder toStringBuilder(int indents) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| String indentStr = " ".repeat(indents); | ||
| sb.append(indentStr).append("Type: NULL\n"); | ||
| return sb; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
как вариант, чтобы не приходилось постоянно прописывать:
можно переделать из интерфейса в абстрактный класс, и прописать под каждой операцией заглушку
UnsupportedOperationException