diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-07 19:17:59 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-07 19:17:59 +1300 |
commit | 3bf3ade7e1e0f7abf69d0e98ed064f455e2cff69 (patch) | |
tree | 1b24cb81652b072277bbc8207c643240e809e893 /src/org | |
parent | c344d4086bb2179d485c9b25af4d737e26f23221 (diff) | |
download | traccar-server-3bf3ade7e1e0f7abf69d0e98ed064f455e2cff69.tar.gz traccar-server-3bf3ade7e1e0f7abf69d0e98ed064f455e2cff69.tar.bz2 traccar-server-3bf3ade7e1e0f7abf69d0e98ed064f455e2cff69.zip |
Clean up some model classes
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/CharacterDelimiterFrameDecoder.java | 6 | ||||
-rw-r--r-- | src/org/traccar/GlobalTimer.java | 8 | ||||
-rw-r--r-- | src/org/traccar/geocode/Address.java | 70 | ||||
-rw-r--r-- | src/org/traccar/model/Command.java | 53 | ||||
-rw-r--r-- | src/org/traccar/model/Event.java | 84 | ||||
-rw-r--r-- | src/org/traccar/model/Extensible.java | 55 |
6 files changed, 194 insertions, 82 deletions
diff --git a/src/org/traccar/CharacterDelimiterFrameDecoder.java b/src/org/traccar/CharacterDelimiterFrameDecoder.java index cc5a415a9..96e86a947 100644 --- a/src/org/traccar/CharacterDelimiterFrameDecoder.java +++ b/src/org/traccar/CharacterDelimiterFrameDecoder.java @@ -22,12 +22,12 @@ import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; public class CharacterDelimiterFrameDecoder extends DelimiterBasedFrameDecoder { private static ChannelBuffer createDelimiter(char delimiter) { - byte buf[] = { (byte) delimiter }; + byte[] buf = {(byte) delimiter}; return ChannelBuffers.wrappedBuffer(buf); } private static ChannelBuffer createDelimiter(String delimiter) { - byte buf[] = new byte[delimiter.length()]; + byte[] buf = new byte[delimiter.length()]; for (int i = 0; i < delimiter.length(); i++) { buf[i] = (byte) delimiter.charAt(i); } @@ -35,7 +35,7 @@ public class CharacterDelimiterFrameDecoder extends DelimiterBasedFrameDecoder { } private static ChannelBuffer[] convertDelimiters(String[] delimiters) { - ChannelBuffer result[] = new ChannelBuffer[delimiters.length]; + ChannelBuffer[] result = new ChannelBuffer[delimiters.length]; for (int i = 0; i < delimiters.length; i++) { result[i] = createDelimiter(delimiters[i]); } diff --git a/src/org/traccar/GlobalTimer.java b/src/org/traccar/GlobalTimer.java index 33b916c1b..f5dc9b87a 100644 --- a/src/org/traccar/GlobalTimer.java +++ b/src/org/traccar/GlobalTimer.java @@ -18,10 +18,7 @@ package org.traccar; import org.jboss.netty.util.HashedWheelTimer; import org.jboss.netty.util.Timer; -/** - * Global idle timer - */ -public class GlobalTimer { +public final class GlobalTimer { private static Timer instance = null; @@ -36,9 +33,10 @@ public class GlobalTimer { } public static Timer getTimer() { - if(instance == null) { + if (instance == null) { instance = new HashedWheelTimer(); } return instance; } + } diff --git a/src/org/traccar/geocode/Address.java b/src/org/traccar/geocode/Address.java index 660348509..68c41b356 100644 --- a/src/org/traccar/geocode/Address.java +++ b/src/org/traccar/geocode/Address.java @@ -18,31 +18,73 @@ package org.traccar.geocode; public class Address { private String postcode; - public String getPostcode() { return postcode; } - public void setPostcode(String postcode) { this.postcode = postcode; } + + public String getPostcode() { + return postcode; + } + + public void setPostcode(String postcode) { + this.postcode = postcode; + } private String country; - public String getCountry() { return country; } - public void setCountry(String country) { this.country = country; } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } private String state; - public String getState() { return state; } - public void setState(String state) { this.state = state; } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } private String district; - public String getDistrict() { return district; } - public void setDistrict(String district) { this.district = district; } + + public String getDistrict() { + return district; + } + + public void setDistrict(String district) { + this.district = district; + } private String settlement; - public String getSettlement() { return settlement; } - public void setSettlement(String settlement) { this.settlement = settlement; } + + public String getSettlement() { + return settlement; + } + + public void setSettlement(String settlement) { + this.settlement = settlement; + } private String street; - public String getStreet() { return street; } - public void setStreet(String street) { this.street = street; } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } private String house; - public String getHouse() { return house; } - public void setHouse(String house) { this.house = house; } + + public String getHouse() { + return house; + } + + public void setHouse(String house) { + this.house = house; + } } diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java index 56e709150..09bb81a74 100644 --- a/src/org/traccar/model/Command.java +++ b/src/org/traccar/model/Command.java @@ -1,32 +1,6 @@ package org.traccar.model; -import java.util.LinkedHashMap; -import java.util.Map; - -public class Command implements Factory { - - @Override - public Command create() { - return new Command(); - } - - private long deviceId; - public long getDeviceId() { return deviceId; } - public void setDeviceId(long deviceId) { this.deviceId = deviceId; } - - private String type; - public String getType() { return type; } - public void setType(String type) { this.type = type; } - - private Map<String, Object> attributes = new LinkedHashMap<>(); - public Map<String, Object> getAttributes() { return attributes; } - public void setAttributes(Map<String, Object> attributes) { this.attributes = attributes; } - - public void set(String key, boolean value) { attributes.put(key, value); } - public void set(String key, int value) { attributes.put(key, value); } - public void set(String key, long value) { attributes.put(key, value); } - public void set(String key, double value) { attributes.put(key, value); } - public void set(String key, String value) { if (value != null && !value.isEmpty()) attributes.put(key, value); } +public class Command extends Extensible implements Factory { public static final String TYPE_POSITION_SINGLE = "positionSingle"; public static final String TYPE_POSITION_PERIODIC = "positionPeriodic"; @@ -42,4 +16,29 @@ public class Command implements Factory { public static final String KEY_TIMEZONE = "timezone"; public static final String KEY_DEVICE_PASSWORD = "devicePassword"; + @Override + public Command create() { + return new Command(); + } + + private long deviceId; + + public long getDeviceId() { + return deviceId; + } + + public void setDeviceId(long deviceId) { + this.deviceId = deviceId; + } + + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + } diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index 953bd1770..9ad54adbf 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -16,40 +16,8 @@ package org.traccar.model; import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Map; -public abstract class Event { - - private long id; - public long getId() { return id; } - public void setId(long id) { this.id = id; } - - private String protocol; - public String getProtocol() { return protocol; } - public void setProtocol(String protocol) { this.protocol = protocol; } - - private long deviceId; - public long getDeviceId() { return deviceId; } - public void setDeviceId(long deviceId) { this.deviceId = deviceId; } - - private Date serverTime; - public Date getServerTime() { return serverTime; } - public void setServerTime(Date serverTime) { this.serverTime = serverTime; } - - private Date deviceTime; - public Date getDeviceTime() { return deviceTime; } - public void setDeviceTime(Date deviceTime) { this.deviceTime = deviceTime; } - - private Map<String, Object> attributes = new LinkedHashMap<>(); - public Map<String, Object> getAttributes() { return attributes; } - public void setAttributes(Map<String, Object> attributes) { this.attributes = attributes; } - - public void set(String key, boolean value) { attributes.put(key, value); } - public void set(String key, int value) { attributes.put(key, value); } - public void set(String key, long value) { attributes.put(key, value); } - public void set(String key, double value) { attributes.put(key, value); } - public void set(String key, String value) { if (value != null && !value.isEmpty()) attributes.put(key, value); } +public abstract class Event extends Extensible { // Words separated by dashes (word-second-third) public static final String KEY_INDEX = "index"; @@ -91,4 +59,54 @@ public abstract class Event { public static final String PREFIX_IO = "io"; public static final String PREFIX_COUNT = "count"; + private long id; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + private String protocol; + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + private long deviceId; + + public long getDeviceId() { + return deviceId; + } + + public void setDeviceId(long deviceId) { + this.deviceId = deviceId; + } + + private Date serverTime; + + public Date getServerTime() { + return serverTime; + } + + public void setServerTime(Date serverTime) { + this.serverTime = serverTime; + } + + private Date deviceTime; + + public Date getDeviceTime() { + return deviceTime; + } + + public void setDeviceTime(Date deviceTime) { + this.deviceTime = deviceTime; + } + } diff --git a/src/org/traccar/model/Extensible.java b/src/org/traccar/model/Extensible.java new file mode 100644 index 000000000..954f3deac --- /dev/null +++ b/src/org/traccar/model/Extensible.java @@ -0,0 +1,55 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.model; + +import java.util.LinkedHashMap; +import java.util.Map; + +public abstract class Extensible { + + private Map<String, Object> attributes = new LinkedHashMap<>(); + + public Map<String, Object> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, Object> attributes) { + this.attributes = attributes; + } + + public void set(String key, boolean value) { + attributes.put(key, value); + } + + public void set(String key, int value) { + attributes.put(key, value); + } + + public void set(String key, long value) { + attributes.put(key, value); + } + + public void set(String key, double value) { + attributes.put(key, value); + } + + public void set(String key, String value) { + if (value != null && !value.isEmpty()) { + attributes.put(key, value); + } + } + +} |