X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=33e57c7228c276cfc164f95eec4db4ca0bc36ed1;hb=8503021c00d63885288c507d9930fefabd5d7678;hp=7e68521fe9ee6b191481032cfa151af8016f0b51;hpb=e0bd82bad92df6e78c510c07c42da099cb50df97;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java
index 7e68521..33e57c7 100644
--- a/src/main/java/net/pterodactylus/sone/core/Core.java
+++ b/src/main/java/net/pterodactylus/sone/core/Core.java
@@ -1,5 +1,5 @@
/*
- * Sone - Core.java - Copyright © 2010â2012 David Roden
+ * Sone - Core.java - Copyright © 2010â2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -32,6 +32,8 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -54,7 +56,11 @@ import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostBuilder;
+import net.pterodactylus.sone.data.PostBuilderFactory;
import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.data.PostReplyBuilder;
+import net.pterodactylus.sone.data.PostReplyBuilderFactory;
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Profile.Field;
import net.pterodactylus.sone.data.Reply;
@@ -62,7 +68,6 @@ import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.sone.data.TemporaryImage;
-import net.pterodactylus.sone.data.impl.PostImpl;
import net.pterodactylus.sone.fcp.FcpInterface;
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
import net.pterodactylus.sone.freenet.wot.Identity;
@@ -74,19 +79,21 @@ import net.pterodactylus.sone.freenet.wot.event.IdentityUpdatedEvent;
import net.pterodactylus.sone.freenet.wot.event.OwnIdentityAddedEvent;
import net.pterodactylus.sone.freenet.wot.event.OwnIdentityRemovedEvent;
import net.pterodactylus.sone.main.SonePlugin;
+import net.pterodactylus.sone.utils.IntegerRangePredicate;
import net.pterodactylus.util.config.Configuration;
import net.pterodactylus.util.config.ConfigurationException;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.service.AbstractService;
import net.pterodactylus.util.thread.NamedThreadFactory;
-import net.pterodactylus.util.thread.Ticker;
-import net.pterodactylus.util.validation.EqualityValidator;
-import net.pterodactylus.util.validation.IntegerRangeValidator;
-import net.pterodactylus.util.validation.OrValidator;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Ordering;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
@@ -98,7 +105,7 @@ import freenet.keys.FreenetURI;
*
* @author David âBombeâ Roden
*/
-public class Core extends AbstractService implements SoneProvider, PostProvider {
+public class Core extends AbstractService implements SoneProvider, PostProvider, PostReplyProvider {
/** The logger. */
private static final Logger logger = Logging.getLogger(Core.class);
@@ -167,12 +174,18 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
/** All known Sones. */
private final Set knownSones = new HashSet();
+ /** The post builder. */
+ private final PostBuilderFactory postBuilderFactory;
+
/** All posts. */
private final Map posts = new HashMap();
/** All known posts. */
private final Set knownPosts = new HashSet();
+ /** The post reply builder factory. */
+ private final PostReplyBuilderFactory postReplyBuilderFactory;
+
/** All replies. */
private final Map replies = new HashMap();
@@ -196,7 +209,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
private final Map temporaryImages = new HashMap();
/** Ticker for threads that mark own elements as known. */
- private final Ticker localElementTicker = new Ticker();
+ private final ScheduledExecutorService localElementTicker = Executors.newScheduledThreadPool(1);
/** The time the configuration was last touched. */
private volatile long lastConfigurationUpdate;
@@ -214,9 +227,13 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
* The WebOfTrust updater
* @param eventBus
* The event bus
+ * @param postBuilderFactory
+ * The post builder
+ * @param postReplyBuilderFactory
+ * The post reply builder factory
*/
@Inject
- public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus) {
+ public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, PostBuilderFactory postBuilderFactory, PostReplyBuilderFactory postReplyBuilderFactory) {
super("Sone Core");
this.configuration = configuration;
this.freenetInterface = freenetInterface;
@@ -226,6 +243,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
this.updateChecker = new UpdateChecker(eventBus, freenetInterface);
this.webOfTrustUpdater = webOfTrustUpdater;
this.eventBus = eventBus;
+ this.postBuilderFactory = postBuilderFactory;
+ this.postReplyBuilderFactory = postReplyBuilderFactory;
}
//
@@ -510,35 +529,21 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
}
/**
- * Returns the post with the given ID.
+ * Returns a post builder.
*
- * @param postId
- * The ID of the post to get
- * @return The post with the given ID, or a new post with the given ID
+ * @return A new post builder
*/
- public Post getPost(String postId) {
- return getPost(postId, true);
+ public PostBuilder postBuilder() {
+ return postBuilderFactory.newPostBuilder();
}
/**
- * Returns the post with the given ID, optionally creating a new post.
- *
- * @param postId
- * The ID of the post to get
- * @param create
- * {@code true} it create a new post if no post with the given ID
- * exists, {@code false} to return {@code null}
- * @return The post, or {@code null} if there is no such post
+ * {@inheritDoc}
*/
@Override
- public Post getPost(String postId, boolean create) {
+ public Optional getPost(String postId) {
synchronized (posts) {
- Post post = posts.get(postId);
- if ((post == null) && create) {
- post = new PostImpl(postId);
- posts.put(postId, post);
- }
- return post;
+ return Optional.fromNullable(posts.get(postId));
}
}
@@ -564,47 +569,42 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
}
/**
- * Returns the reply with the given ID. If there is no reply with the given
- * ID yet, a new one is created, unless {@code create} is false in which
- * case {@code null} is returned.
+ * Returns a post reply builder.
*
- * @param replyId
- * The ID of the reply to get
- * @param create
- * {@code true} to always return a {@link Reply}, {@code false}
- * to return {@code null} if no reply can be found
- * @return The reply, or {@code null} if there is no such reply
+ * @return A new post reply builder
*/
- public PostReply getPostReply(String replyId, boolean create) {
+ public PostReplyBuilder postReplyBuilder() {
+ return postReplyBuilderFactory.newPostReplyBuilder();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Optional getPostReply(String replyId) {
synchronized (replies) {
- PostReply reply = replies.get(replyId);
- if (create && (reply == null)) {
- reply = new PostReply(replyId);
- replies.put(replyId, reply);
- }
- return reply;
+ return Optional.fromNullable(replies.get(replyId));
}
}
/**
- * Returns all replies for the given post, order ascending by time.
- *
- * @param post
- * The post to get all replies for
- * @return All replies for the given post
+ * {@inheritDoc}
*/
- public List getReplies(Post post) {
- Set sones = getSones();
- List replies = new ArrayList();
- for (Sone sone : sones) {
- for (PostReply reply : sone.getReplies()) {
- if (reply.getPost().equals(post)) {
- replies.add(reply);
- }
+ @Override
+ public List getReplies(final Post post) {
+ return Ordering.from(Reply.TIME_COMPARATOR).sortedCopy(FluentIterable.from(getSones()).transformAndConcat(new Function>() {
+
+ @Override
+ public Iterable apply(Sone sone) {
+ return sone.getReplies();
}
- }
- Collections.sort(replies, Reply.TIME_COMPARATOR);
- return replies;
+ }).filter(new Predicate() {
+
+ @Override
+ public boolean apply(PostReply reply) {
+ return post.equals(reply.getPost());
+ }
+ }));
}
/**
@@ -676,9 +676,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
Set posts = new HashSet();
synchronized (bookmarkedPosts) {
for (String bookmarkedPostId : bookmarkedPosts) {
- Post post = getPost(bookmarkedPostId, false);
- if (post != null) {
- posts.add(post);
+ Optional post = getPost(bookmarkedPostId);
+ if (!post.isPresent()) {
+ posts.add(post.get());
}
}
}
@@ -877,7 +877,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
synchronized (sones) {
final Sone sone = getRemoteSone(identity.getId(), true).setIdentity(identity);
boolean newSone = sone.getRequestUri() == null;
- sone.setRequestUri(getSoneUri(identity.getRequestUri()));
+ sone.setRequestUri(SoneUri.create(identity.getRequestUri()));
sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
if (newSone) {
synchronized (knownSones) {
@@ -1109,16 +1109,18 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
List storedPosts = storedSone.getPosts();
synchronized (knownPosts) {
for (Post post : sone.getPosts()) {
- post.setSone(storedSone).setKnown(knownPosts.contains(post.getId()));
- if (!storedPosts.contains(post)) {
- if (post.getTime() < getSoneFollowingTime(sone)) {
- knownPosts.add(post.getId());
- post.setKnown(true);
- } else if (!knownPosts.contains(post.getId())) {
- eventBus.post(new NewPostFoundEvent(post));
+ PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
+ postBuilder.copyPost(post).from(storedSone);
+ Post newPost = postBuilder.build().setKnown(knownPosts.contains(post.getId()));
+ if (!storedPosts.contains(newPost)) {
+ if (newPost.getTime() < getSoneFollowingTime(sone)) {
+ knownPosts.add(newPost.getId());
+ newPost.setKnown(true);
+ } else if (!knownPosts.contains(newPost.getId())) {
+ eventBus.post(new NewPostFoundEvent(newPost));
}
}
- posts.put(post.getId(), post);
+ posts.put(newPost.getId(), newPost);
}
}
}
@@ -1311,11 +1313,11 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
logger.log(Level.WARNING, "Invalid post found, aborting load!");
return;
}
- Post post = getPost(postId).setSone(sone).setTime(postTime).setText(postText);
+ PostBuilder postBuilder = postBuilder().withId(postId).from(sone).withTime(postTime).withText(postText);
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
- post.setRecipient(getSone(postRecipientId));
+ postBuilder.to(getSone(postRecipientId));
}
- posts.add(post);
+ posts.add(postBuilder.build());
}
/* load replies. */
@@ -1333,7 +1335,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
logger.log(Level.WARNING, "Invalid reply found, aborting load!");
return;
}
- replies.add(getPostReply(replyId, true).setSone(sone).setPost(getPost(postId)).setTime(replyTime).setText(replyText));
+ PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
+ postReplyBuilder.withId(replyId).from(sone).to(postId).withTime(replyTime).withText(replyText);
+ replies.add(postReplyBuilder.build());
}
/* load post likes. */
@@ -1537,17 +1541,19 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
return null;
}
- final Post post = new PostImpl(sone, time, text.trim());
+ PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
+ postBuilder.from(sone).randomId().withTime(time).withText(text.trim());
if (recipient != null) {
- post.setRecipient(recipient);
+ postBuilder.to(recipient);
}
+ final Post post = postBuilder.build();
synchronized (posts) {
posts.put(post.getId(), post);
}
eventBus.post(new NewPostFoundEvent(post));
sone.addPost(post);
touchConfiguration();
- localElementTicker.registerEvent(System.currentTimeMillis() + 10 * 1000, new Runnable() {
+ localElementTicker.schedule(new Runnable() {
/**
* {@inheritDoc}
@@ -1556,7 +1562,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
public void run() {
markPostKnown(post);
}
- }, "Mark " + post + " read.");
+ }, 10, TimeUnit.SECONDS);
return post;
}
@@ -1656,30 +1662,15 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
* @return The created reply
*/
public PostReply createReply(Sone sone, Post post, String text) {
- return createReply(sone, post, System.currentTimeMillis(), text);
- }
-
- /**
- * Creates a new reply.
- *
- * @param sone
- * The Sone that creates the reply
- * @param post
- * The post that this reply refers to
- * @param time
- * The time of the reply
- * @param text
- * The text of the reply
- * @return The created reply
- */
- public PostReply createReply(Sone sone, Post post, long time, String text) {
checkNotNull(text, "text must not be null");
checkArgument(text.trim().length() > 0, "text must not be empty");
if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
return null;
}
- final PostReply reply = new PostReply(sone, post, System.currentTimeMillis(), text.trim());
+ PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
+ postReplyBuilder.randomId().from(sone).to(post.getId()).currentTime().withText(text.trim());
+ final PostReply reply = postReplyBuilder.build();
synchronized (replies) {
replies.put(reply.getId(), reply);
}
@@ -1688,7 +1679,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
}
sone.addReply(reply);
touchConfiguration();
- localElementTicker.registerEvent(System.currentTimeMillis() + 10 * 1000, new Runnable() {
+ localElementTicker.schedule(new Runnable() {
/**
* {@inheritDoc}
@@ -1697,7 +1688,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
public void run() {
markReplyKnown(reply);
}
- }, "Mark " + reply + " read.");
+ }, 10, TimeUnit.SECONDS);
return reply;
}
@@ -1940,6 +1931,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
*/
@Override
public void serviceStop() {
+ localElementTicker.shutdownNow();
synchronized (sones) {
for (Entry soneInserter : soneInserters.entrySet()) {
soneInserter.getValue().stop();
@@ -2016,7 +2008,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
for (PostReply reply : sone.getReplies()) {
String replyPrefix = sonePrefix + "/Replies/" + replyCounter++;
configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId());
- configuration.getStringValue(replyPrefix + "/Post/ID").setValue(reply.getPost().getId());
+ configuration.getStringValue(replyPrefix + "/Post/ID").setValue(reply.getPostId());
configuration.getLongValue(replyPrefix + "/Time").setValue(reply.getTime());
configuration.getStringValue(replyPrefix + "/Text").setValue(reply.getText());
}
@@ -2187,7 +2179,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
@SuppressWarnings("unchecked")
private void loadConfiguration() {
/* create options. */
- options.addIntegerOption("InsertionDelay", new DefaultOption(60, new IntegerRangeValidator(0, Integer.MAX_VALUE), new OptionWatcher() {
+ options.addIntegerOption("InsertionDelay", new DefaultOption(60, new IntegerRangePredicate(0, Integer.MAX_VALUE), new OptionWatcher() {
@Override
public void optionChanged(Option option, Integer oldValue, Integer newValue) {
@@ -2195,13 +2187,13 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
}
}));
- options.addIntegerOption("PostsPerPage", new DefaultOption(10, new IntegerRangeValidator(1, Integer.MAX_VALUE)));
- options.addIntegerOption("ImagesPerPage", new DefaultOption(9, new IntegerRangeValidator(1, Integer.MAX_VALUE)));
- options.addIntegerOption("CharactersPerPost", new DefaultOption(400, new OrValidator(new IntegerRangeValidator(50, Integer.MAX_VALUE), new EqualityValidator(-1))));
- options.addIntegerOption("PostCutOffLength", new DefaultOption(200, new OrValidator(new IntegerRangeValidator(50, Integer.MAX_VALUE), new EqualityValidator(-1))));
+ options.addIntegerOption("PostsPerPage", new DefaultOption(10, new IntegerRangePredicate(1, Integer.MAX_VALUE)));
+ options.addIntegerOption("ImagesPerPage", new DefaultOption(9, new IntegerRangePredicate(1, Integer.MAX_VALUE)));
+ options.addIntegerOption("CharactersPerPost", new DefaultOption(400, Predicates. or(new IntegerRangePredicate(50, Integer.MAX_VALUE), Predicates.equalTo(-1))));
+ options.addIntegerOption("PostCutOffLength", new DefaultOption(200, Predicates. or(new IntegerRangePredicate(50, Integer.MAX_VALUE), Predicates.equalTo(-1))));
options.addBooleanOption("RequireFullAccess", new DefaultOption(false));
- options.addIntegerOption("PositiveTrust", new DefaultOption(75, new IntegerRangeValidator(0, 100)));
- options.addIntegerOption("NegativeTrust", new DefaultOption(-25, new IntegerRangeValidator(-100, 100)));
+ options.addIntegerOption("PositiveTrust", new DefaultOption(75, new IntegerRangePredicate(0, 100)));
+ options.addIntegerOption("NegativeTrust", new DefaultOption(-25, new IntegerRangePredicate(-100, 100)));
options.addStringOption("TrustComment", new DefaultOption("Set from Sone Web Interface"));
options.addBooleanOption("ActivateFcpInterface", new DefaultOption(false, new OptionWatcher() {
@@ -2318,23 +2310,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
}
/**
- * Generate a Sone URI from the given URI and latest edition.
- *
- * @param uriString
- * The URI to derive the Sone URI from
- * @return The derived URI
- */
- private static FreenetURI getSoneUri(String uriString) {
- try {
- FreenetURI uri = new FreenetURI(uriString).setDocName("Sone").setMetaString(new String[0]);
- return uri;
- } catch (MalformedURLException mue1) {
- logger.log(Level.WARNING, String.format("Could not create Sone URI from URI: %s", uriString), mue1);
- return null;
- }
- }
-
- /**
* Notifies the core that a new {@link OwnIdentity} was added.
*
* @param ownIdentityAddedEvent
@@ -2465,358 +2440,4 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
touchConfiguration();
}
- /**
- * Convenience interface for external classes that want to access the coreâs
- * configuration.
- *
- * @author David âBombeâ Roden
- */
- public static class Preferences {
-
- /** The wrapped options. */
- private final Options options;
-
- /**
- * Creates a new preferences object wrapped around the given options.
- *
- * @param options
- * The options to wrap
- */
- public Preferences(Options options) {
- this.options = options;
- }
-
- /**
- * Returns the insertion delay.
- *
- * @return The insertion delay
- */
- public int getInsertionDelay() {
- return options.getIntegerOption("InsertionDelay").get();
- }
-
- /**
- * Validates the given insertion delay.
- *
- * @param insertionDelay
- * The insertion delay to validate
- * @return {@code true} if the given insertion delay was valid,
- * {@code false} otherwise
- */
- public boolean validateInsertionDelay(Integer insertionDelay) {
- return options.getIntegerOption("InsertionDelay").validate(insertionDelay);
- }
-
- /**
- * Sets the insertion delay
- *
- * @param insertionDelay
- * The new insertion delay, or {@code null} to restore it to
- * the default value
- * @return This preferences
- */
- public Preferences setInsertionDelay(Integer insertionDelay) {
- options.getIntegerOption("InsertionDelay").set(insertionDelay);
- return this;
- }
-
- /**
- * Returns the number of posts to show per page.
- *
- * @return The number of posts to show per page
- */
- public int getPostsPerPage() {
- return options.getIntegerOption("PostsPerPage").get();
- }
-
- /**
- * Validates the number of posts per page.
- *
- * @param postsPerPage
- * The number of posts per page
- * @return {@code true} if the number of posts per page was valid,
- * {@code false} otherwise
- */
- public boolean validatePostsPerPage(Integer postsPerPage) {
- return options.getIntegerOption("PostsPerPage").validate(postsPerPage);
- }
-
- /**
- * Sets the number of posts to show per page.
- *
- * @param postsPerPage
- * The number of posts to show per page
- * @return This preferences object
- */
- public Preferences setPostsPerPage(Integer postsPerPage) {
- options.getIntegerOption("PostsPerPage").set(postsPerPage);
- return this;
- }
-
- /**
- * Returns the number of images to show per page.
- *
- * @return The number of images to show per page
- */
- public int getImagesPerPage() {
- return options.getIntegerOption("ImagesPerPage").get();
- }
-
- /**
- * Validates the number of images per page.
- *
- * @param imagesPerPage
- * The number of images per page
- * @return {@code true} if the number of images per page was valid,
- * {@code false} otherwise
- */
- public boolean validateImagesPerPage(Integer imagesPerPage) {
- return options.getIntegerOption("ImagesPerPage").validate(imagesPerPage);
- }
-
- /**
- * Sets the number of images per page.
- *
- * @param imagesPerPage
- * The number of images per page
- * @return This preferences object
- */
- public Preferences setImagesPerPage(Integer imagesPerPage) {
- options.getIntegerOption("ImagesPerPage").set(imagesPerPage);
- return this;
- }
-
- /**
- * Returns the number of characters per post, or -1
if the
- * posts should not be cut off.
- *
- * @return The numbers of characters per post
- */
- public int getCharactersPerPost() {
- return options.getIntegerOption("CharactersPerPost").get();
- }
-
- /**
- * Validates the number of characters per post.
- *
- * @param charactersPerPost
- * The number of characters per post
- * @return {@code true} if the number of characters per post was valid,
- * {@code false} otherwise
- */
- public boolean validateCharactersPerPost(Integer charactersPerPost) {
- return options.getIntegerOption("CharactersPerPost").validate(charactersPerPost);
- }
-
- /**
- * Sets the number of characters per post.
- *
- * @param charactersPerPost
- * The number of characters per post, or -1
to
- * not cut off the posts
- * @return This preferences objects
- */
- public Preferences setCharactersPerPost(Integer charactersPerPost) {
- options.getIntegerOption("CharactersPerPost").set(charactersPerPost);
- return this;
- }
-
- /**
- * Returns the number of characters the shortened post should have.
- *
- * @return The number of characters of the snippet
- */
- public int getPostCutOffLength() {
- return options.getIntegerOption("PostCutOffLength").get();
- }
-
- /**
- * Validates the number of characters after which to cut off the post.
- *
- * @param postCutOffLength
- * The number of characters of the snippet
- * @return {@code true} if the number of characters of the snippet is
- * valid, {@code false} otherwise
- */
- public boolean validatePostCutOffLength(Integer postCutOffLength) {
- return options.getIntegerOption("PostCutOffLength").validate(postCutOffLength);
- }
-
- /**
- * Sets the number of characters the shortened post should have.
- *
- * @param postCutOffLength
- * The number of characters of the snippet
- * @return This preferences
- */
- public Preferences setPostCutOffLength(Integer postCutOffLength) {
- options.getIntegerOption("PostCutOffLength").set(postCutOffLength);
- return this;
- }
-
- /**
- * Returns whether Sone requires full access to be even visible.
- *
- * @return {@code true} if Sone requires full access, {@code false}
- * otherwise
- */
- public boolean isRequireFullAccess() {
- return options.getBooleanOption("RequireFullAccess").get();
- }
-
- /**
- * Sets whether Sone requires full access to be even visible.
- *
- * @param requireFullAccess
- * {@code true} if Sone requires full access, {@code false}
- * otherwise
- */
- public void setRequireFullAccess(Boolean requireFullAccess) {
- options.getBooleanOption("RequireFullAccess").set(requireFullAccess);
- }
-
- /**
- * Returns the positive trust.
- *
- * @return The positive trust
- */
- public int getPositiveTrust() {
- return options.getIntegerOption("PositiveTrust").get();
- }
-
- /**
- * Validates the positive trust.
- *
- * @param positiveTrust
- * The positive trust to validate
- * @return {@code true} if the positive trust was valid, {@code false}
- * otherwise
- */
- public boolean validatePositiveTrust(Integer positiveTrust) {
- return options.getIntegerOption("PositiveTrust").validate(positiveTrust);
- }
-
- /**
- * Sets the positive trust.
- *
- * @param positiveTrust
- * The new positive trust, or {@code null} to restore it to
- * the default vlaue
- * @return This preferences
- */
- public Preferences setPositiveTrust(Integer positiveTrust) {
- options.getIntegerOption("PositiveTrust").set(positiveTrust);
- return this;
- }
-
- /**
- * Returns the negative trust.
- *
- * @return The negative trust
- */
- public int getNegativeTrust() {
- return options.getIntegerOption("NegativeTrust").get();
- }
-
- /**
- * Validates the negative trust.
- *
- * @param negativeTrust
- * The negative trust to validate
- * @return {@code true} if the negative trust was valid, {@code false}
- * otherwise
- */
- public boolean validateNegativeTrust(Integer negativeTrust) {
- return options.getIntegerOption("NegativeTrust").validate(negativeTrust);
- }
-
- /**
- * Sets the negative trust.
- *
- * @param negativeTrust
- * The negative trust, or {@code null} to restore it to the
- * default value
- * @return The preferences
- */
- public Preferences setNegativeTrust(Integer negativeTrust) {
- options.getIntegerOption("NegativeTrust").set(negativeTrust);
- return this;
- }
-
- /**
- * Returns the trust comment. This is the comment that is set in the web
- * of trust when a trust value is assigned to an identity.
- *
- * @return The trust comment
- */
- public String getTrustComment() {
- return options.getStringOption("TrustComment").get();
- }
-
- /**
- * Sets the trust comment.
- *
- * @param trustComment
- * The trust comment, or {@code null} to restore it to the
- * default value
- * @return This preferences
- */
- public Preferences setTrustComment(String trustComment) {
- options.getStringOption("TrustComment").set(trustComment);
- return this;
- }
-
- /**
- * Returns whether the {@link FcpInterface FCP interface} is currently
- * active.
- *
- * @see FcpInterface#setActive(boolean)
- * @return {@code true} if the FCP interface is currently active,
- * {@code false} otherwise
- */
- public boolean isFcpInterfaceActive() {
- return options.getBooleanOption("ActivateFcpInterface").get();
- }
-
- /**
- * Sets whether the {@link FcpInterface FCP interface} is currently
- * active.
- *
- * @see FcpInterface#setActive(boolean)
- * @param fcpInterfaceActive
- * {@code true} to activate the FCP interface, {@code false}
- * to deactivate the FCP interface
- * @return This preferences object
- */
- public Preferences setFcpInterfaceActive(boolean fcpInterfaceActive) {
- options.getBooleanOption("ActivateFcpInterface").set(fcpInterfaceActive);
- return this;
- }
-
- /**
- * Returns the action level for which full access to the FCP interface
- * is required.
- *
- * @return The action level for which full access to the FCP interface
- * is required
- */
- public FullAccessRequired getFcpFullAccessRequired() {
- return FullAccessRequired.values()[options.getIntegerOption("FcpFullAccessRequired").get()];
- }
-
- /**
- * Sets the action level for which full access to the FCP interface is
- * required
- *
- * @param fcpFullAccessRequired
- * The action level
- * @return This preferences
- */
- public Preferences setFcpFullAccessRequired(FullAccessRequired fcpFullAccessRequired) {
- options.getIntegerOption("FcpFullAccessRequired").set((fcpFullAccessRequired != null) ? fcpFullAccessRequired.ordinal() : null);
- return this;
- }
-
- }
-
}