Skip to content

Commit

Permalink
New functions [Protocol,ParameterSpecs].addDefaulteds(map).
Browse files Browse the repository at this point in the history
  • Loading branch information
bengtmartensson committed Oct 29, 2024
1 parent e0d0f43 commit b166a01
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/harctoolbox/irp/ParameterSpecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ public void removeDefaulteds(Map<String, Long> namesMap) {
}
});
}

public void addDefaulteds(Map<String, Long>params) {
NameEngine nameEngine = new NameEngine(params);
map.values().stream().filter(parameter -> (parameter.hasDefault() && !params.containsKey(parameter.getName()))).forEachOrdered(parameter -> {
try {
params.put(parameter.getName(), parameter.getDefault().toLong(nameEngine));
} catch (NameUnassignedException ex) {
// Just ignore it
}
});
}

public void removeNotInParameterSpec(Map<String, Long> namesMap) {
List<String> names = new ArrayList<>(namesMap.keySet());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/harctoolbox/irp/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,10 @@ public long getParameterMin(String parameterName) {
public void removeDefaulteds(Map<String, Long> params) {
getParameterSpecs().removeDefaulteds(params);
}

public void addDefaulteds(Map<String, Long> params) {
getParameterSpecs().addDefaulteds(params);
}

public boolean hasNonStandardParameters() {
return getParameterSpecs().hasNonStandardParameters();
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/harctoolbox/irp/ParameterSpecsNGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,19 @@ public void testSort() {
String[] result = sortedMap.keySet().toArray(new String[5]);
assertEquals(result, expResult);
}

/**
* Test of addDefaulteds method, of class ParameterSpecs.
* @throws NameUnassignedException
*/
@Test
public void testAddDefaulteds() throws NameUnassignedException {
System.out.println("addDefaulteds");
Map<String, Long> params = new HashMap<>(4);
params.put("D", 200L);
ParameterSpecs instance = nec1;
instance.addDefaulteds(params);
assertEquals(params.size(), 2);
assertEquals(params.get("S").longValue(), 55L);
}
}

0 comments on commit b166a01

Please sign in to comment.