projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Return nullable Post instead of Optional
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
fcp
/
AbstractSoneCommand.java
diff --git
a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
index
1c4fd2e
..
9942af7
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
+++ b/
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
@@
-161,11
+161,11
@@
public abstract class AbstractSoneCommand extends AbstractCommand {
if (mandatory && (soneId == null)) {
throw new FcpException("Could not load Sone ID from “" + parameterName + "”.");
}
if (mandatory && (soneId == null)) {
throw new FcpException("Could not load Sone ID from “" + parameterName + "”.");
}
-
Optional<Sone>
sone = core.getSone(soneId);
- if ((mandatory &&
!sone.isPresent()) || (sone.isPresent() && localOnly && !sone.get()
.isLocal())) {
+
Sone
sone = core.getSone(soneId);
+ if ((mandatory &&
(sone == null)) || ((sone != null) && localOnly && !sone
.isLocal())) {
throw new FcpException("Could not load Sone from “" + soneId + "”.");
}
throw new FcpException("Could not load Sone from “" + soneId + "”.");
}
- return
sone
;
+ return
Optional.fromNullable(sone)
;
}
/**
}
/**
@@
-184,11
+184,11
@@
public abstract class AbstractSoneCommand extends AbstractCommand {
protected Post getPost(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException {
try {
String postId = simpleFieldSet.getString(parameterName);
protected Post getPost(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException {
try {
String postId = simpleFieldSet.getString(parameterName);
-
Optional<Post>
post = core.getPost(postId);
- if (
!post.isPresent()
) {
+
Post
post = core.getPost(postId);
+ if (
post == null
) {
throw new FcpException("Could not load post from “" + postId + "”.");
}
throw new FcpException("Could not load post from “" + postId + "”.");
}
- return post
.get()
;
+ return post;
} catch (FSParseException fspe1) {
throw new FcpException("Could not post ID from “" + parameterName + "”.", fspe1);
}
} catch (FSParseException fspe1) {
throw new FcpException("Could not post ID from “" + parameterName + "”.", fspe1);
}
@@
-210,11
+210,11
@@
public abstract class AbstractSoneCommand extends AbstractCommand {
protected PostReply getReply(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException {
try {
String replyId = simpleFieldSet.getString(parameterName);
protected PostReply getReply(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException {
try {
String replyId = simpleFieldSet.getString(parameterName);
-
Optional<PostReply>
reply = core.getPostReply(replyId);
- if (
!reply.isPresent()
) {
+
PostReply
reply = core.getPostReply(replyId);
+ if (
reply == null
) {
throw new FcpException("Could not load reply from “" + replyId + "”.");
}
throw new FcpException("Could not load reply from “" + replyId + "”.");
}
- return reply
.get()
;
+ return reply;
} catch (FSParseException fspe1) {
throw new FcpException("Could not reply ID from “" + parameterName + "”.", fspe1);
}
} catch (FSParseException fspe1) {
throw new FcpException("Could not reply ID from “" + parameterName + "”.", fspe1);
}
@@
-237,6
+237,7
@@
public abstract class AbstractSoneCommand extends AbstractCommand {
protected static SimpleFieldSet encodeSone(Sone sone, String prefix, Optional<Sone> localSone) {
SimpleFieldSetBuilder soneBuilder = new SimpleFieldSetBuilder();
protected static SimpleFieldSet encodeSone(Sone sone, String prefix, Optional<Sone> localSone) {
SimpleFieldSetBuilder soneBuilder = new SimpleFieldSetBuilder();
+ soneBuilder.put(prefix + "ID", sone.getId());
soneBuilder.put(prefix + "Name", sone.getName());
soneBuilder.put(prefix + "NiceName", SoneAccessor.getNiceName(sone));
soneBuilder.put(prefix + "LastUpdated", sone.getTime());
soneBuilder.put(prefix + "Name", sone.getName());
soneBuilder.put(prefix + "NiceName", SoneAccessor.getNiceName(sone));
soneBuilder.put(prefix + "LastUpdated", sone.getTime());
@@
-272,10
+273,7
@@
public abstract class AbstractSoneCommand extends AbstractCommand {
soneBuilder.put(prefix + "Count", sones.size());
for (Sone sone : sones) {
String sonePrefix = prefix + soneIndex++ + ".";
soneBuilder.put(prefix + "Count", sones.size());
for (Sone sone : sones) {
String sonePrefix = prefix + soneIndex++ + ".";
- soneBuilder.put(sonePrefix + "ID", sone.getId());
- soneBuilder.put(sonePrefix + "Name", sone.getName());
- soneBuilder.put(sonePrefix + "NiceName", SoneAccessor.getNiceName(sone));
- soneBuilder.put(sonePrefix + "Time", sone.getTime());
+ soneBuilder.put(encodeSone(sone, sonePrefix, Optional.<Sone>absent()));
}
return soneBuilder.get();
}
return soneBuilder.get();