Copyright (c) 2013, Jamie Furness (jamie@jamierf.co.uk)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following...
If you think the Android project rcdroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.jamierf.rcdroid.http;
/*fromwww.java2s.com*/import com.google.common.base.Objects;
import com.google.common.base.Optional;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Map;
publicclass Packet {
publicstaticenum Type {
LOCATION_UPDATED, ACCELERATION_UPDATED, ROTATION_UPDATED, BATTERY_UPDATED, // sensors
SET_SPEED, SET_ROTATION, // servo control
PLAY_ALARM; // other control
}
@JsonProperty
privatefinal Type type;
@JsonProperty
privatefinal Map<String, Object> data;
@JsonProperty
privatefinallong timestamp;
@JsonCreator
public Packet(@JsonProperty("type") Type type, @JsonProperty("data") Map<String, Object> data, @JsonProperty("timestamp") long timestamp) {
this.type = type;
this.data = data;
this.timestamp = timestamp;
}
public Type getType() {
return type;
}
public <T> Optional<T> get(String key) {
return Optional.fromNullable((T) data.get(key));
}
publiclong getTimestamp() {
return timestamp;
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("type", type)
.add("data", data)
.add("timestamp", timestamp)
.toString();
}
}