Skip to content

Commit

Permalink
Add isSuccess() and isFailure() on LwM2mResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Dec 18, 2015
1 parent 23180c7 commit c70c9d6
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* A base class for concrete LWM2M response.
*/
public class AbstractLwM2mResponse implements LwM2mResponse {
public abstract class AbstractLwM2mResponse implements LwM2mResponse {

protected final ResponseCode code;
protected final String errorMessage;
Expand All @@ -43,4 +43,9 @@ public final ResponseCode getCode() {
public String getErrorMessage() {
return errorMessage;
}

@Override
public boolean isFailure() {
return !isSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class BootstrapResponse extends AbstractLwM2mResponse {
public BootstrapResponse(final ResponseCode code, final String errorMessage) {
super(code, errorMessage);
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.CHANGED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public String getLocation() {
return location;
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.CREATED;
}

@Override
public String toString() {
if (errorMessage != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public DeleteResponse(final ResponseCode code, final String errorMessage) {
super(code, errorMessage);
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.DELETED;
}

@Override
public String toString() {
if (errorMessage != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public DeregisterResponse(final ResponseCode code, final String errorMessage) {
super(code, errorMessage);
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.DELETED;
}

@Override
public String toString() {
if (errorMessage != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public LinkObject[] getObjectLinks() {
return links != null ? links.clone() : null;
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.CONTENT;
}

@Override
public String toString() {
if (errorMessage != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public ExecuteResponse(final ResponseCode code, final String errorMessage) {
super(code, errorMessage);
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.CHANGED;
}

@Override
public String toString() {
if (errorMessage != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ public interface LwM2mResponse {
*/
String getErrorMessage();

/**
* @return true if the request was successfully done.
*/
boolean isSuccess();

/**
* @return true if we get an error or unexpected code.
*/
boolean isFailure();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public ReadResponse(ResponseCode code, LwM2mNode content, String errorMessage) {
this.content = content;
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.CONTENT;
}

/**
* Get the {@link LwM2mNode} value returned as response payload.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public String getRegistrationID() {
return registrationID;
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.CREATED;
}

@Override
public String toString() {
if (errorMessage != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public UpdateResponse(final ResponseCode code, final String errorMessage) {
super(code, errorMessage);
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.CHANGED;
}

@Override
public String toString() {
if (errorMessage != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public WriteAttributesResponse(final ResponseCode code, final String errorMessag
super(code, errorMessage);
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.CHANGED;
}

@Override
public String toString() {
if (errorMessage != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public WriteResponse(final ResponseCode code, final String errorMessage) {
super(code, errorMessage);
}

@Override
public boolean isSuccess() {
return getCode() == ResponseCode.CHANGED;
}

@Override
public String toString() {
if (errorMessage != null)
Expand Down

0 comments on commit c70c9d6

Please sign in to comment.