Fix issues around all-zero UUIDs.
This commit is contained in:
parent
b9879e7210
commit
eac9f78dfa
2 changed files with 17 additions and 2 deletions
|
@ -24,6 +24,7 @@ class LogSectionStories : LogSection {
|
||||||
output.append("Database ID : ${myStoryRecord.id}\n")
|
output.append("Database ID : ${myStoryRecord.id}\n")
|
||||||
output.append("Distribution ID: ${myStoryRecord.distributionId} (Matches expected value? ${myStoryRecord.distributionId == DistributionId.MY_STORY})\n")
|
output.append("Distribution ID: ${myStoryRecord.distributionId} (Matches expected value? ${myStoryRecord.distributionId == DistributionId.MY_STORY})\n")
|
||||||
output.append("Recipient ID : ${presentRecipientId(myStoryRecipientId)}\n")
|
output.append("Recipient ID : ${presentRecipientId(myStoryRecipientId)}\n")
|
||||||
|
output.append("toString() Test: ${DistributionId.MY_STORY} | ${DistributionId.MY_STORY.asUuid()}")
|
||||||
} else {
|
} else {
|
||||||
output.append("< My story does not exist >\n")
|
output.append("< My story does not exist >\n")
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,18 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
public final class DistributionId {
|
public final class DistributionId {
|
||||||
|
|
||||||
public static final DistributionId MY_STORY = DistributionId.from("00000000-0000-0000-0000-000000000000");
|
private static final String MY_STORY_STRING = "00000000-0000-0000-0000-000000000000";
|
||||||
|
|
||||||
|
public static final DistributionId MY_STORY = DistributionId.from(MY_STORY_STRING);
|
||||||
|
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some devices appear to have a bad UUID.toString() that misrenders an all-zero UUID as "0000-0000".
|
||||||
|
* To account for this, we will keep our own string value, to prevent queries from going awry and such.
|
||||||
|
*/
|
||||||
|
private final String stringValue;
|
||||||
|
|
||||||
public static DistributionId from(String id) {
|
public static DistributionId from(String id) {
|
||||||
return new DistributionId(UuidUtil.parseOrThrow(id));
|
return new DistributionId(UuidUtil.parseOrThrow(id));
|
||||||
}
|
}
|
||||||
|
@ -31,6 +39,12 @@ public final class DistributionId {
|
||||||
|
|
||||||
private DistributionId(UUID uuid) {
|
private DistributionId(UUID uuid) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
|
||||||
|
if (uuid.getLeastSignificantBits() == 0 && uuid.getMostSignificantBits() == 0) {
|
||||||
|
this.stringValue = MY_STORY_STRING;
|
||||||
|
} else {
|
||||||
|
this.stringValue = this.uuid.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID asUuid() {
|
public UUID asUuid() {
|
||||||
|
@ -39,7 +53,7 @@ public final class DistributionId {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return uuid.toString();
|
return stringValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue