Skip to content

Commit

Permalink
support getting values as long
Browse files Browse the repository at this point in the history
  • Loading branch information
philipparndt committed Jan 22, 2021
1 parent 0df8841 commit ddfe726
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/de/bausdorf/avm/tr064/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ public int getValueAsInteger(String argument) throws ClassCastException, NoSuchF
return ret;
}

public long getValueAsLong(String argument) throws ClassCastException, NoSuchFieldException {
if (!argumentState.containsKey(argument) || !data.containsKey(argument)) {
throw new NoSuchFieldException(argument);
}
if (stateToType.get(argumentState.get(argument)) != Long.class && stateToType.get(argumentState.get(argument)) != Integer.class) {
throw new ClassCastException(argument);
}

long ret = -1;

try {
ret = Long.parseLong(data.get(argument));
} catch (NumberFormatException e) {
throw new ClassCastException(argument + " " + e.getMessage());
}

return ret;
}

public boolean getValueAsBoolean(String argument) throws ClassCastException, NoSuchFieldException {
if (!argumentState.containsKey(argument) || !data.containsKey(argument))
throw new NoSuchFieldException(argument);
Expand Down

0 comments on commit ddfe726

Please sign in to comment.