synchronized (sones) {
final Sone sone;
sone = database.newSoneBuilder().by(ownIdentity.getId()).local().build(Optional.<SoneCreated>absent());
- sone.setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), (long) 0));
+ sone.modify().setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), (long) 0)).update();
sone.setClient(new Client("Sone", SonePlugin.VERSION.toString()));
sone.setKnown(true);
/* TODO - load posts ’n stuff */
}
boolean newSone = !existingSone.isPresent();
final Sone sone = newSone ? database.newSoneBuilder().by(identity.getId()).build(Optional.<SoneCreated>absent()) : existingSone.get();
- sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
+ sone.modify().setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0)).update();
if (newSone) {
synchronized (knownSones) {
newSone = !knownSones.contains(sone.getId());
@SuppressWarnings("synthetic-access")
public void run() {
Optional<Sone> sone = getRemoteSone(identity.getId());
- sone.get().setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), sone.get().getLatestEdition()));
+ sone.get().modify().setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), sone.get().getLatestEdition())).update();
soneDownloader.addSone(sone.get());
soneDownloader.fetchSone(sone.get());
}
public void onFoundEdition(long edition, USK key, ObjectContainer objectContainer, ClientContext clientContext, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) {
logger.log(Level.FINE, String.format("Found USK update for Sone “%s” at %s, new known good: %s, new slot too: %s.", sone, key, newKnownGood, newSlotToo));
if (edition > sone.getLatestEdition()) {
- sone.setLatestEdition(edition);
+ sone.modify().setLatestEdition(edition).update();
new Thread(new Runnable() {
@Override
soneInputStream = soneBucket.getInputStream();
Sone parsedSone = parseSone(originalSone, soneInputStream);
if (parsedSone != null) {
- parsedSone.setLatestEdition(requestUri.getEdition());
+ parsedSone.modify().setLatestEdition(requestUri.getEdition()).update();
}
return parsedSone;
} catch (Exception e1) {
break;
}
sone.setTime(insertTime);
- sone.setLatestEdition(finalUri.getEdition());
+ sone.modify().setLatestEdition(finalUri.getEdition()).update();
core.touchConfiguration();
success = true;
logger.log(Level.INFO, String.format("Inserted Sone “%s” at %s.", sone.getName(), finalUri));
long getLatestEdition();
/**
- * Sets the latest edition of this Sone. If the given latest edition is not
- * greater than the current latest edition, the latest edition of this Sone is
- * not changed.
- *
- * @param latestEdition
- * The latest edition of this Sone
- */
- void setLatestEdition(long latestEdition);
-
- /**
* Return the time of the last inserted update of this Sone.
*
* @return The time of the update (in milliseconds since Jan 1, 1970 UTC)
PostReplyBuilder newPostReplyBuilder(String postId) throws IllegalStateException;
+ Modifier modify();
+
+ interface Modifier {
+
+ Modifier setLatestEdition(long latestEdition);
+ Sone update();
+
+ }
+
}
};
}
+ public Modifier modify() {
+ return new Modifier() {
+ private long latestEdition = DefaultSone.this.latestEdition;
+ @Override
+ public Modifier setLatestEdition(long latestEdition) {
+ this.latestEdition = latestEdition;
+ return this;
+ }
+
+ @Override
+ public Sone update() {
+ DefaultSone.this.latestEdition = latestEdition;
+ return DefaultSone.this;
+ }
+ };
+ }
+
//
// FINGERPRINTABLE METHODS
//