Skip to content

Commit

Permalink
Small changes to DataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Jun 16, 2020
1 parent 34bc4b6 commit 079823c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/src/main/java/me/retrodaredevil/solarthing/DataSource.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package me.retrodaredevil.solarthing;


import me.retrodaredevil.solarthing.annotations.Nullable;

/**
* A helper class to create and parse the source string
*/
public class DataSource {
private final String sender;
private final long dateMillis;
private final String data;

public DataSource(String sender, long dateMillis, String data) {
this.sender = sender;
this.dateMillis = dateMillis;
this.data = data;
}

/**
* NOTE: dateMillis has a radix of 16 while in string form
* @param string The string representing the sender, dateMillis, and data
* @return The {@link DataSource} represented by {@code string} or null
*/
public static DataSource createFromStringOrNull(String string){
public static @Nullable DataSource createFromStringOrNull(String string){
String[] split = string.split("\\|", 3);
if(split.length != 3){
return null;
Expand All @@ -36,12 +38,12 @@ public static DataSource createFromStringOrNull(String string){
}
return new DataSource(sender, dateMillis, data);
}

@Override
public String toString() {
return sender + "|" + Long.toHexString(dateMillis) + "|" + data;
}

public String getSender() {
return sender;
}
Expand Down

0 comments on commit 079823c

Please sign in to comment.