Skip to content

Commit

Permalink
MTS refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
aligungr committed Aug 27, 2020
1 parent 645bd05 commit 5f02259
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public String getString(String key) {
}

public <T> T getConstructed(MtsContext mts, String key, Class<T> type) {
return mts.construct.construct(type, (ImplicitTypedObject) get(key), true);
return mts.constructor.construct(type, (ImplicitTypedObject) get(key), true);
}

public <T> T asConstructed(MtsContext mts, Class<T> type) {
return mts.construct.construct(type, this, true);
return mts.constructor.construct(type, this, true);
}

public <T> T getConverted(MtsContext mts,String key, Class<T> type) {
return (T) mts.convert.convert(get(key), type, true).get(0).value;
return (T) mts.converter.convert(get(key), type, true).get(0).value;
}
}
6 changes: 3 additions & 3 deletions mts/src/main/java/tr/havelsan/ueransim/mts/MtsConstruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private boolean parameterTypeMatches(Constructor<?> constructor, Map<String, Obj
return false;
}
}
if (!ctx.convert.isConvertable(object.getClass(), param.getType(), includeCustoms))
if (!ctx.converter.isConvertable(object.getClass(), param.getType(), includeCustoms))
return false;
}
return true;
Expand All @@ -89,7 +89,7 @@ private boolean parameterTypeExactMatches(Constructor<?> constructor, Map<String
return false;
for (var param : constructor.getParameters()) {
var object = parameters.get(param.getName());
var conversion = ctx.convert.convert(object, param.getType(), includeCustoms);
var conversion = ctx.converter.convert(object, param.getType(), includeCustoms);
if (conversion.stream().noneMatch(c -> c.depth == 0 && (c.level == ConversionLevel.SAME_TYPE))) {
return false;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ public <T> T construct(Class<T> type, Map<String, Object> args, boolean includeC
value = construct(param.getType(), (ImplicitTypedObject) value, includeCustoms);
}

var conversions = ctx.convert.convert(value, param.getType(), includeCustoms);
var conversions = ctx.converter.convert(value, param.getType(), includeCustoms);

var shallowConversions = Utils.streamToList(conversions.stream().filter(conversion -> conversion.depth == 0));
var deepConversions = Utils.streamToList(conversions.stream().filter(conversion -> conversion.depth != 0));
Expand Down
8 changes: 4 additions & 4 deletions mts/src/main/java/tr/havelsan/ueransim/mts/MtsContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
public class MtsContext {

public final TypeRegistry typeRegistry;
public final MtsConvert convert;
public final MtsConstruct construct;
public final MtsConvert converter;
public final MtsConstruct constructor;
public final MtsDecoder decoder;

public MtsContext() {
this.typeRegistry = new TypeRegistry();
this.convert = new MtsConvert(this);
this.construct = new MtsConstruct(this);
this.converter = new MtsConvert(this);
this.constructor = new MtsConstruct(this);
this.decoder = new MtsDecoder(this);
}
}
2 changes: 1 addition & 1 deletion mts/src/main/java/tr/havelsan/ueransim/mts/MtsConvert.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void convertArray(Object from, Class<?> to, List<Conversion<?>> list, in

for (int i = 0; i < sourceArray.length; i++) {
if (sourceArray[i] instanceof ImplicitTypedObject) {
sourceArray[i] = ctx.construct.construct(targetType, (ImplicitTypedObject) sourceArray[i], includeCustoms);
sourceArray[i] = ctx.constructor.construct(targetType, (ImplicitTypedObject) sourceArray[i], includeCustoms);
}

var conversions = convert(sourceArray[i], targetType, includeCustoms);
Expand Down
2 changes: 1 addition & 1 deletion mts/src/main/java/tr/havelsan/ueransim/mts/MtsDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public Object decode(JsonElement json) {
if (type == null) {
throw new MtsException("declared type not registered: %s", typeName);
}
return ctx.construct.construct(type, properties, true);
return ctx.constructor.construct(type, properties, true);
} else {
return new ImplicitTypedObject(properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SimulationContext createSimContext(INodeMessagingListener nodeMessagingLi
}

public GnbSimContext createGnbSimContext(SimulationContext simCtx, ImplicitTypedObject config) {
return createGnbSimContext(simCtx, mts.construct.construct(GnbConfig.class, config, true));
return createGnbSimContext(simCtx, mts.constructor.construct(GnbConfig.class, config, true));
}

public GnbSimContext createGnbSimContext(SimulationContext simCtx, GnbConfig config) {
Expand Down

0 comments on commit 5f02259

Please sign in to comment.