private final Configuration configuration;
private final Sone sone;
private final String sonePrefix;
- private final Map<String, Album> albums = new HashMap<String, Album>();
- private final List<Album> topLevelAlbums = new ArrayList<Album>();
- private final Map<String, Image> images = new HashMap<String, Image>();
+ private final Map<String, Album> albums = new HashMap<>();
+ private final List<Album> topLevelAlbums = new ArrayList<>();
+ private final Map<String, Image> images = new HashMap<>();
public ConfigurationSoneParser(Configuration configuration, Sone sone) {
this.configuration = configuration;
public Set<Post> parsePosts(PostBuilderFactory postBuilderFactory)
throws InvalidPostFound {
- Set<Post> posts = new HashSet<Post>();
+ Set<Post> posts = new HashSet<>();
while (true) {
String postPrefix = "/Posts/" + posts.size();
String postId = getString(postPrefix + "/ID", null);
public Set<PostReply> parsePostReplies(
PostReplyBuilderFactory postReplyBuilderFactory) {
- Set<PostReply> replies = new HashSet<PostReply>();
+ Set<PostReply> replies = new HashSet<>();
while (true) {
String replyPrefix = "/Replies/" + replies.size();
String replyId = getString(replyPrefix + "/ID", null);
}
public Set<String> parseLikedPostIds() {
- Set<String> likedPostIds = new HashSet<String>();
+ Set<String> likedPostIds = new HashSet<>();
while (true) {
String likedPostId =
getString("/Likes/Post/" + likedPostIds.size() + "/ID",
}
public Set<String> parseLikedPostReplyIds() {
- Set<String> likedPostReplyIds = new HashSet<String>();
+ Set<String> likedPostReplyIds = new HashSet<>();
while (true) {
String likedReplyId = getString(
"/Likes/Reply/" + likedPostReplyIds.size() + "/ID", null);
}
public Set<String> parseFriends() {
- Set<String> friends = new HashSet<String>();
+ Set<String> friends = new HashSet<>();
while (true) {
String friendId =
getString("/Friends/" + friends.size() + "/ID", null);
/** Locked local Sones. */
/* synchronize on itself. */
- private final Set<Sone> lockedSones = new HashSet<Sone>();
+ private final Set<Sone> lockedSones = new HashSet<>();
/** Sone inserters. */
/* synchronize access on this on sones. */
- private final Map<Sone, SoneInserter> soneInserters = new HashMap<Sone, SoneInserter>();
+ private final Map<Sone, SoneInserter> soneInserters = new HashMap<>();
/** Sone rescuers. */
/* synchronize access on this on sones. */
- private final Map<Sone, SoneRescuer> soneRescuers = new HashMap<Sone, SoneRescuer>();
+ private final Map<Sone, SoneRescuer> soneRescuers = new HashMap<>();
/** All known Sones. */
- private final Set<String> knownSones = new HashSet<String>();
+ private final Set<String> knownSones = new HashSet<>();
/** The post database. */
private final Database database;
private final Multimap<OwnIdentity, Identity> trustedIdentities = Multimaps.synchronizedSetMultimap(HashMultimap.<OwnIdentity, Identity>create());
/** All temporary images. */
- private final Map<String, TemporaryImage> temporaryImages = new HashMap<String, TemporaryImage>();
+ private final Map<String, TemporaryImage> temporaryImages = new HashMap<>();
/** Ticker for threads that mark own elements as known. */
private final ScheduledExecutorService localElementTicker = Executors.newScheduledThreadPool(1);
* @return The Sones that like the given post
*/
public Set<Sone> getLikes(Post post) {
- Set<Sone> sones = new HashSet<Sone>();
+ Set<Sone> sones = new HashSet<>();
for (Sone sone : getSones()) {
if (sone.getLikedPostIds().contains(post.getId())) {
sones.add(sone);
* @return The Sones that like the given reply
*/
public Set<Sone> getLikes(PostReply reply) {
- Set<Sone> sones = new HashSet<Sone>();
+ Set<Sone> sones = new HashSet<>();
for (Sone sone : getSones()) {
if (sone.getLikedReplyIds().contains(reply.getId())) {
sones.add(sone);
private final RequestClient requestClient = new RequestClientBuilder().realTime().build();
/** The USK callbacks. */
- private final Map<String, USKCallback> soneUskCallbacks = new HashMap<String, USKCallback>();
+ private final Map<String, USKCallback> soneUskCallbacks = new HashMap<>();
/** The not-Sone-related USK callbacks. */
private final Map<FreenetURI, USKCallback> uriUskCallbacks = Collections.synchronizedMap(new HashMap<FreenetURI, USKCallback>());
private final EventBus eventBus;
private final Option<Integer> insertionDelay =
- new DefaultOption<Integer>(60, range(0, MAX_VALUE));
+ new DefaultOption<>(60, range(0, MAX_VALUE));
private final Option<Integer> postsPerPage =
- new DefaultOption<Integer>(10, range(1, MAX_VALUE));
+ new DefaultOption<>(10, range(1, MAX_VALUE));
private final Option<Integer> imagesPerPage =
- new DefaultOption<Integer>(9, range(1, MAX_VALUE));
+ new DefaultOption<>(9, range(1, MAX_VALUE));
private final Option<Integer> charactersPerPost =
- new DefaultOption<Integer>(400, Predicates.<Integer>or(
+ new DefaultOption<>(400, Predicates.<Integer>or(
range(50, MAX_VALUE), equalTo(-1)));
private final Option<Integer> postCutOffLength =
- new DefaultOption<Integer>(200, range(50, MAX_VALUE));
+ new DefaultOption<>(200, range(50, MAX_VALUE));
private final Option<Boolean> requireFullAccess =
- new DefaultOption<Boolean>(false);
+ new DefaultOption<>(false);
private final Option<Integer> positiveTrust =
- new DefaultOption<Integer>(75, range(0, 100));
+ new DefaultOption<>(75, range(0, 100));
private final Option<Integer> negativeTrust =
- new DefaultOption<Integer>(-25, range(-100, 100));
+ new DefaultOption<>(-25, range(-100, 100));
private final Option<String> trustComment =
- new DefaultOption<String>("Set from Sone Web Interface");
+ new DefaultOption<>("Set from Sone Web Interface");
private final Option<Boolean> activateFcpInterface =
- new DefaultOption<Boolean>(false);
+ new DefaultOption<>(false);
private final Option<FullAccessRequired> fcpFullAccessRequired =
- new DefaultOption<FullAccessRequired>(ALWAYS);
+ new DefaultOption<>(ALWAYS);
public Preferences(EventBus eventBus) {
this.eventBus = eventBus;
private final FreenetInterface freenetInterface;
/** The sones to update. */
- private final Set<Sone> sones = new HashSet<Sone>();
+ private final Set<Sone> sones = new HashSet<>();
@Inject
SoneDownloaderImpl(UpdatedSoneProcessor updatedSoneProcessor, FreenetInterface freenetInterface, SoneParser soneParser) {
class InsertInformation implements Closeable {
/** All properties of the Sone, copied for thread safety. */
- private final Map<String, Object> soneProperties = new HashMap<String, Object>();
+ private final Map<String, Object> soneProperties = new HashMap<>();
private final String fingerprint;
private final ManifestCreator manifestCreator;
*/
public InsertInformation(Sone sone) {
this.fingerprint = sone.getFingerprint();
- Map<String, Object> soneProperties = new HashMap<String, Object>();
+ Map<String, Object> soneProperties = new HashMap<>();
soneProperties.put("id", sone.getId());
soneProperties.put("name", sone.getName());
soneProperties.put("time", currentTimeMillis());
soneProperties.put("profile", sone.getProfile());
soneProperties.put("posts", Ordering.from(Post.NEWEST_FIRST).sortedCopy(sone.getPosts()));
soneProperties.put("replies", Ordering.from(Reply.TIME_COMPARATOR).reverse().sortedCopy(sone.getReplies()));
- soneProperties.put("likedPostIds", new HashSet<String>(sone.getLikedPostIds()));
- soneProperties.put("likedReplyIds", new HashSet<String>(sone.getLikedReplyIds()));
+ soneProperties.put("likedPostIds", new HashSet<>(sone.getLikedPostIds()));
+ soneProperties.put("likedReplyIds", new HashSet<>(sone.getLikedReplyIds()));
soneProperties.put("albums", FluentIterable.from(sone.getRootAlbum().getAlbums()).transformAndConcat(Album.FLATTENER).filter(NOT_EMPTY).toList());
manifestCreator = new ManifestCreator(core, soneProperties);
}
* @return The manifest entries for the Sone insert
*/
public HashMap<String, Object> generateManifestEntries() {
- HashMap<String, Object> manifestEntries = new HashMap<String, Object>();
+ HashMap<String, Object> manifestEntries = new HashMap<>();
/* first, create an index.html. */
manifestEntries.put("index.html", manifestCreator.createManifestElement(
private final Core core;
private final Map<String, Object> soneProperties;
- private final Set<Bucket> buckets = new HashSet<Bucket>();
+ private final Set<Bucket> buckets = new HashSet<>();
ManifestCreator(Core core, Map<String, Object> soneProperties) {
this.core = core;
/* parse posts. */
SimpleXML postsXml = soneXml.getNode("posts");
- Set<Post> posts = new HashSet<Post>();
+ Set<Post> posts = new HashSet<>();
if (postsXml == null) {
/* TODO - mark Sone as bad. */
logger.log(Level.WARNING, String.format("Downloaded Sone %s has no posts!", sone));
/* parse replies. */
SimpleXML repliesXml = soneXml.getNode("replies");
- Set<PostReply> replies = new HashSet<PostReply>();
+ Set<PostReply> replies = new HashSet<>();
if (repliesXml == null) {
/* TODO - mark Sone as bad. */
logger.log(Level.WARNING, String.format("Downloaded Sone %s has no replies!", sone));
/* parse liked post IDs. */
SimpleXML likePostIdsXml = soneXml.getNode("post-likes");
- Set<String> likedPostIds = new HashSet<String>();
+ Set<String> likedPostIds = new HashSet<>();
if (likePostIdsXml == null) {
/* TODO - mark Sone as bad. */
logger.log(Level.WARNING, String.format("Downloaded Sone %s has no post likes!", sone));
/* parse liked reply IDs. */
SimpleXML likeReplyIdsXml = soneXml.getNode("reply-likes");
- Set<String> likedReplyIds = new HashSet<String>();
+ Set<String> likedReplyIds = new HashSet<>();
if (likeReplyIdsXml == null) {
/* TODO - mark Sone as bad. */
logger.log(Level.WARNING, String.format("Downloaded Sone %s has no reply likes!", sone));
/* parse albums. */
SimpleXML albumsXml = soneXml.getNode("albums");
- Map<String, Image> allImages = new HashMap<String, Image>();
- List<Album> topLevelAlbums = new ArrayList<Album>();
+ Map<String, Image> allImages = new HashMap<>();
+ List<Album> topLevelAlbums = new ArrayList<>();
if (albumsXml != null) {
for (SimpleXML albumXml : albumsXml.getNodes("album")) {
String id = albumXml.getValue("id", null);
private final WebOfTrustConnector webOfTrustConnector;
/** The queue for jobs. */
- private final BlockingQueue<WebOfTrustUpdateJob> updateJobs = new LinkedBlockingQueue<WebOfTrustUpdateJob>();
+ private final BlockingQueue<WebOfTrustUpdateJob> updateJobs = new LinkedBlockingQueue<>();
/**
* Creates a new trust updater.
if (album == null) {
return emptyList();
}
- List<Album> albums = new ArrayList<Album>();
+ List<Album> albums = new ArrayList<>();
albums.add(album);
for (Album subAlbum : album.getAlbums()) {
albums.addAll(FluentIterable.from(ImmutableList.of(subAlbum)).transformAndConcat(FLATTENER).toList());
*/
@Nonnull
public List<Field> getFields() {
- return new ArrayList<Field>(fields);
+ return new ArrayList<>(fields);
}
/**
private final Sone sone;
/** Nested albums. */
- private final List<Album> albums = new ArrayList<Album>();
+ private final List<Album> albums = new ArrayList<>();
/** The image IDs in order. */
- private final List<String> imageIds = new ArrayList<String>();
+ private final List<String> imageIds = new ArrayList<>();
/** The images in this album. */
- private final Map<String, Image> images = new HashMap<String, Image>();
+ private final Map<String, Image> images = new HashMap<>();
/** The parent album. */
private Album parent;
@Override
public List<Album> getAlbums() {
- return new ArrayList<Album>(albums);
+ return new ArrayList<>(albums);
}
@Override
@Override
public List<Image> getImages() {
- return new ArrayList<Image>(Collections2.filter(Collections2.transform(imageIds, new Function<String, Image>() {
+ return new ArrayList<>(Collections2.filter(Collections2.transform(imageIds, new Function<String, Image>() {
@Override
@SuppressWarnings("synthetic-access")
private volatile boolean known;
/** All posts. */
- private final Set<Post> posts = new CopyOnWriteArraySet<Post>();
+ private final Set<Post> posts = new CopyOnWriteArraySet<>();
/** All replies. */
- private final Set<PostReply> replies = new CopyOnWriteArraySet<PostReply>();
+ private final Set<PostReply> replies = new CopyOnWriteArraySet<>();
/** The IDs of all liked posts. */
- private final Set<String> likedPostIds = new CopyOnWriteArraySet<String>();
+ private final Set<String> likedPostIds = new CopyOnWriteArraySet<>();
/** The IDs of all liked replies. */
- private final Set<String> likedReplyIds = new CopyOnWriteArraySet<String>();
+ private final Set<String> likedReplyIds = new CopyOnWriteArraySet<>();
/** The root album containing all albums. */
private final Album rootAlbum = new AlbumImpl(this);
public List<Post> getPosts() {
List<Post> sortedPosts;
synchronized (this) {
- sortedPosts = new ArrayList<Post>(posts);
+ sortedPosts = new ArrayList<>(posts);
}
Collections.sort(sortedPosts, Post.NEWEST_FIRST);
return sortedPosts;
}
hash.putString(")");
- List<PostReply> replies = new ArrayList<PostReply>(getReplies());
+ List<PostReply> replies = new ArrayList<>(getReplies());
Collections.sort(replies, Reply.TIME_COMPARATOR);
hash.putString("Replies(");
for (PostReply reply : replies) {
}
hash.putString(")");
- List<String> likedPostIds = new ArrayList<String>(getLikedPostIds());
+ List<String> likedPostIds = new ArrayList<>(getLikedPostIds());
Collections.sort(likedPostIds);
hash.putString("LikedPosts(");
for (String likedPostId : likedPostIds) {
}
hash.putString(")");
- List<String> likedReplyIds = new ArrayList<String>(getLikedReplyIds());
+ List<String> likedReplyIds = new ArrayList<>(getLikedReplyIds());
Collections.sort(likedReplyIds);
hash.putString("LikedReplies(");
for (String likedReplyId : likedReplyIds) {
}
private Set<String> loadIds(String prefix) {
- Set<String> ids = new HashSet<String>();
+ Set<String> ids = new HashSet<>();
int idCounter = 0;
while (true) {
String id = configuration
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private final MemoryDatabase memoryDatabase;
private final ConfigurationLoader configurationLoader;
- private final Set<String> bookmarkedPosts = new HashSet<String>();
+ private final Set<String> bookmarkedPosts = new HashSet<>();
public MemoryBookmarkDatabase(MemoryDatabase memoryDatabase,
ConfigurationLoader configurationLoader) {
private final AtomicBoolean active = new AtomicBoolean();
/** What function full access is required for. */
- private final AtomicReference<FullAccessRequired> fullAccessRequired = new AtomicReference<FullAccessRequired>(FullAccessRequired.ALWAYS);
+ private final AtomicReference<FullAccessRequired> fullAccessRequired = new AtomicReference<>(FullAccessRequired.ALWAYS);
/** All available FCP commands. */
private final Map<String, AbstractSoneCommand> commands;
int startPost = getInt(parameters, "StartPost", 0);
int maxPosts = getInt(parameters, "MaxPosts", -1);
- Collection<Post> allPosts = new HashSet<Post>();
+ Collection<Post> allPosts = new HashSet<>();
allPosts.addAll(sone.getPosts());
for (String friendSoneId : sone.getFriends()) {
Sone friendSone = getCore().getSone(friendSoneId);
allPosts.addAll(getCore().getDirectedPosts(sone.getId()));
allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER);
- List<Post> sortedPosts = new ArrayList<Post>(allPosts);
+ List<Post> sortedPosts = new ArrayList<>(allPosts);
Collections.sort(sortedPosts, Post.NEWEST_FIRST);
if (sortedPosts.size() < startPost) {
public Response execute(SimpleFieldSet parameters) {
int startSone = getInt(parameters, "StartSone", 0);
int maxSones = getInt(parameters, "MaxSones", -1);
- List<Sone> sones = new ArrayList<Sone>(getCore().getSones());
+ List<Sone> sones = new ArrayList<>(getCore().getSones());
if (sones.size() < startSone) {
return new Response("Sones", encodeSones(Collections.<Sone> emptyList(), "Sones."));
}
if (data instanceof L10nText) {
return ((L10nText) data).getParameters();
}
- List<Object> parameterValues = new ArrayList<Object>();
+ List<Object> parameterValues = new ArrayList<>();
int parameterIndex = 0;
while (parameters.containsKey(String.valueOf(parameterIndex))) {
Object value = parameters.get(String.valueOf(parameterIndex));
}
private Map<OwnIdentity, Collection<Identity>> loadTrustedIdentitiesForOwnIdentities(Collection<OwnIdentity> ownIdentities) throws PluginException {
- Map<OwnIdentity, Collection<Identity>> currentIdentities = new HashMap<OwnIdentity, Collection<Identity>>();
+ Map<OwnIdentity, Collection<Identity>> currentIdentities = new HashMap<>();
for (OwnIdentity ownIdentity : ownIdentities) {
if (identityDoesNotHaveTheCorrectContext(ownIdentity)) {
@Override
public Set<OwnIdentity> getAllOwnIdentities() {
synchronized (currentOwnIdentities) {
- return new HashSet<OwnIdentity>(currentOwnIdentities);
+ return new HashSet<>(currentOwnIdentities);
}
}
*/
@Override
protected void serviceRun() {
- Map<OwnIdentity, Collection<Identity>> oldIdentities = new HashMap<OwnIdentity, Collection<Identity>>();
+ Map<OwnIdentity, Collection<Identity>> oldIdentities = new HashMap<>();
while (!shouldStop()) {
try {
Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetOwnIdentities").get());
SimpleFieldSet fields = reply.getFields();
int ownIdentityCounter = -1;
- Set<OwnIdentity> ownIdentities = new HashSet<OwnIdentity>();
+ Set<OwnIdentity> ownIdentities = new HashSet<>();
while (true) {
String id = fields.get("Identity" + ++ownIdentityCounter);
if (id == null) {
public Set<Identity> loadTrustedIdentities(OwnIdentity ownIdentity, Optional<String> context) throws PluginException {
Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentitiesByScore").put("Truster", ownIdentity.getId()).put("Selection", "+").put("Context", context.or("")).put("WantTrustValues", "true").get());
SimpleFieldSet fields = reply.getFields();
- Set<Identity> identities = new HashSet<Identity>();
+ Set<Identity> identities = new HashSet<>();
int identityCounter = -1;
while (true) {
String id = fields.get("Identity" + ++identityCounter);
* @return The parsed contexts
*/
private static Set<String> parseContexts(String prefix, SimpleFieldSet fields) {
- Set<String> contexts = new HashSet<String>();
+ Set<String> contexts = new HashSet<>();
int contextCounter = -1;
while (true) {
String context = fields.get(prefix + "Context" + ++contextCounter);
* @return The parsed properties
*/
private static Map<String, String> parseProperties(String prefix, SimpleFieldSet fields) {
- Map<String, String> properties = new HashMap<String, String>();
+ Map<String, String> properties = new HashMap<>();
int propertiesCounter = -1;
while (true) {
String propertyName = fields.get(prefix + "Property" + ++propertiesCounter + ".Name");
@Override
public <REQ extends Request> Page<REQ> loadStaticPage(String basePath, String prefix, String mimeType) {
- return new ReloadingPage<REQ>(basePath, new File(filesystemPath, prefix).getAbsolutePath(), mimeType);
+ return new ReloadingPage<>(basePath, new File(filesystemPath, prefix).getAbsolutePath(), mimeType);
}
@Override
private final String key;
/** The list of new elements. */
- private final List<T> elements = new CopyOnWriteArrayList<T>();
+ private final List<T> elements = new CopyOnWriteArrayList<>();
/**
* Creates a new list notification.
* @return The current list of elements
*/
public List<T> getElements() {
- return new ArrayList<T>(elements);
+ return new ArrayList<>(elements);
}
/**
*/
@SuppressWarnings("unchecked")
public List<Notification> filterNotifications(Collection<? extends Notification> notifications, Sone currentSone) {
- List<Notification> filteredNotifications = new ArrayList<Notification>();
+ List<Notification> filteredNotifications = new ArrayList<>();
for (Notification notification : notifications) {
if (notification.getId().equals("new-sone-notification")) {
if ((currentSone != null) && !currentSone.getOptions().isShowNewSoneNotifications()) {
if (newPosts.size() == postNotification.getElements().size()) {
return Optional.of(postNotification);
}
- ListNotification<Post> filteredNotification = new ListNotification<Post>(postNotification);
+ ListNotification<Post> filteredNotification = new ListNotification<>(postNotification);
filteredNotification.setElements(newPosts);
filteredNotification.setLastUpdateTime(postNotification.getLastUpdatedTime());
return Optional.of(filteredNotification);
if (newReplies.size() == newReplyNotification.getElements().size()) {
return Optional.of(newReplyNotification);
}
- ListNotification<PostReply> filteredNotification = new ListNotification<PostReply>(newReplyNotification);
+ ListNotification<PostReply> filteredNotification = new ListNotification<>(newReplyNotification);
filteredNotification.setElements(newReplies);
filteredNotification.setLastUpdateTime(newReplyNotification.getLastUpdatedTime());
return Optional.of(filteredNotification);
public Object get(TemplateContext templateContext, Object object, String member) {
Album album = (Album) object;
if ("backlinks".equals(member)) {
- List<Link> backlinks = new ArrayList<Link>();
+ List<Link> backlinks = new ArrayList<>();
Album currentAlbum = album;
while (!currentAlbum.isRoot()) {
backlinks.add(0, new Link("imageBrowser.html?album=" + currentAlbum.getId(), currentAlbum.getTitle()));
public Object get(TemplateContext templateContext, Object object, String member) {
Collection<?> collection = (Collection<?>) object;
if (member.equals("soneNames")) {
- List<Sone> sones = new ArrayList<Sone>();
+ List<Sone> sones = new ArrayList<>();
for (Object sone : collection) {
if (!(sone instanceof Sone)) {
continue;
public class FilesystemTemplate extends Template {
private final String filename;
- private final AtomicReference<LastLoadedTemplate> lastTemplate = new AtomicReference<LastLoadedTemplate>();
+ private final AtomicReference<LastLoadedTemplate> lastTemplate = new AtomicReference<>();
private final TemplateContext initialContext = new TemplateContext();
- private final List<Part> parts = new ArrayList<Part>();
+ private final List<Part> parts = new ArrayList<>();
public FilesystemTemplate(String filename) {
this.filename = filename;
String name = String.valueOf(parameters.get("name"));
String value = String.valueOf(parameters.get("value"));
- Map<String, String> values = new HashMap<String, String>();
+ Map<String, String> values = new HashMap<>();
Collection<String> parameterNames = request.getHttpRequest().getParameterNames();
for (String parameterName : parameterNames) {
values.put(parameterName, request.getHttpRequest().getParam(parameterName));
if (!(data instanceof Collection<?>)) {
return data;
}
- return new HashSet<Object>((Collection<?>) data);
+ return new HashSet<>((Collection<?>) data);
}
}
private final SonePlugin sonePlugin;
/** The registered toadlets. */
- private final List<PageToadlet> pageToadlets = new ArrayList<PageToadlet>();
+ private final List<PageToadlet> pageToadlets = new ArrayList<>();
/** The form password. */
private final String formPassword;
private final ListNotification<Post> mentionNotification;
/** Notifications for sone inserts. */
- private final Map<Sone, TemplateNotification> soneInsertNotifications = new HashMap<Sone, TemplateNotification>();
+ private final Map<Sone, TemplateNotification> soneInsertNotifications = new HashMap<>();
/** Sone locked notification ticker objects. */
private final Map<Sone, ScheduledFuture<?>> lockedSonesTickerObjects = Collections.synchronizedMap(new HashMap<Sone, ScheduledFuture<?>>());
/* create notifications. */
Template newSoneNotificationTemplate = loaders.loadTemplate("/templates/notify/newSoneNotification.html");
- newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate, false);
+ newSoneNotification = new ListNotification<>("new-sone-notification", "sones", newSoneNotificationTemplate, false);
Template newPostNotificationTemplate = loaders.loadTemplate("/templates/notify/newPostNotification.html");
- newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate, false);
+ newPostNotification = new ListNotification<>("new-post-notification", "posts", newPostNotificationTemplate, false);
Template localPostNotificationTemplate = loaders.loadTemplate("/templates/notify/newPostNotification.html");
- localPostNotification = new ListNotification<Post>("local-post-notification", "posts", localPostNotificationTemplate, false);
+ localPostNotification = new ListNotification<>("local-post-notification", "posts", localPostNotificationTemplate, false);
Template newReplyNotificationTemplate = loaders.loadTemplate("/templates/notify/newReplyNotification.html");
- newReplyNotification = new ListNotification<PostReply>("new-reply-notification", "replies", newReplyNotificationTemplate, false);
+ newReplyNotification = new ListNotification<>("new-reply-notification", "replies", newReplyNotificationTemplate, false);
Template localReplyNotificationTemplate = loaders.loadTemplate("/templates/notify/newReplyNotification.html");
- localReplyNotification = new ListNotification<PostReply>("local-reply-notification", "replies", localReplyNotificationTemplate, false);
+ localReplyNotification = new ListNotification<>("local-reply-notification", "replies", localReplyNotificationTemplate, false);
Template mentionNotificationTemplate = loaders.loadTemplate("/templates/notify/mentionNotification.html");
- mentionNotification = new ListNotification<Post>("mention-notification", "posts", mentionNotificationTemplate, false);
+ mentionNotification = new ListNotification<>("mention-notification", "posts", mentionNotificationTemplate, false);
Template lockedSonesTemplate = loaders.loadTemplate("/templates/notify/lockedSonesNotification.html");
- lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
+ lockedSonesNotification = new ListNotification<>("sones-locked-notification", "sones", lockedSonesTemplate);
Template newVersionTemplate = loaders.loadTemplate("/templates/notify/newVersionNotification.html");
newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate);
Template insertingImagesTemplate = loaders.loadTemplate("/templates/notify/inserting-images-notification.html");
- insertingImagesNotification = new ListNotification<Image>("inserting-images-notification", "images", insertingImagesTemplate);
+ insertingImagesNotification = new ListNotification<>("inserting-images-notification", "images", insertingImagesTemplate);
Template insertedImagesTemplate = loaders.loadTemplate("/templates/notify/inserted-images-notification.html");
- insertedImagesNotification = new ListNotification<Image>("inserted-images-notification", "images", insertedImagesTemplate);
+ insertedImagesNotification = new ListNotification<>("inserted-images-notification", "images", insertedImagesTemplate);
Template imageInsertFailedTemplate = loaders.loadTemplate("/templates/notify/image-insert-failed-notification.html");
- imageInsertFailedNotification = new ListNotification<Image>("image-insert-failed-notification", "images", imageInsertFailedTemplate);
+ imageInsertFailedNotification = new ListNotification<>("image-insert-failed-notification", "images", imageInsertFailedTemplate);
}
//
*/
private Collection<Sone> getMentionedSones(String text) {
/* we need no context to find mentioned Sones. */
- Set<Sone> mentionedSones = new HashSet<Sone>();
+ Set<Sone> mentionedSones = new HashSet<>();
for (Part part : soneTextParser.parse(text, null)) {
if (part instanceof SonePart) {
mentionedSones.add(((SonePart) part).getSone());
try (AutoCloseableBucket pageBucket = new AutoCloseableBucket(pageRequest.getToadletContext().getBucketFactory().makeBucket(-1));
OutputStream pageBucketOutputStream = pageBucket.getBucket().getOutputStream()) {
Response pageResponse = page.handleRequest(pageRequest, new Response(pageBucketOutputStream));
- MultiValueTable<String, String> headers = new MultiValueTable<String, String>();
+ MultiValueTable<String, String> headers = new MultiValueTable<>();
if (pageResponse.getHeaders() != null) {
for (Header header : pageResponse.getHeaders()) {
for (String value : header) {
@Test
public void insertingADirectory() throws InsertException, SoneException {
FreenetURI freenetUri = mock(FreenetURI.class);
- HashMap<String, Object> manifestEntries = new HashMap<String, Object>();
+ HashMap<String, Object> manifestEntries = new HashMap<>();
String defaultFile = "index.html";
FreenetURI resultingUri = mock(FreenetURI.class);
when(highLevelSimpleClient.insertManifest(eq(freenetUri), eq(manifestEntries), eq(defaultFile))).thenReturn(resultingUri);
@Test
public void templateIsRenderedCorrectlyForManifestElement()
throws IOException {
- Map<String, Object> soneProperties = new HashMap<String, Object>();
+ Map<String, Object> soneProperties = new HashMap<>();
soneProperties.put("id", "SoneId");
ManifestCreator manifestCreator = new ManifestCreator(core, soneProperties);
long now = currentTimeMillis();
@Test
public void invalidTemplateReturnsANullManifestElement() {
- Map<String, Object> soneProperties = new HashMap<String, Object>();
+ Map<String, Object> soneProperties = new HashMap<>();
ManifestCreator manifestCreator = new ManifestCreator(core, soneProperties);
assertThat(manifestCreator.createManifestElement("test.txt",
"plain/text; charset=utf-8",
@Test
public void errorWhileRenderingTemplateReturnsANullManifestElement() {
- Map<String, Object> soneProperties = new HashMap<String, Object>();
+ Map<String, Object> soneProperties = new HashMap<>();
ManifestCreator manifestCreator = new ManifestCreator(core, soneProperties);
when(core.toString()).thenThrow(NullPointerException.class);
assertThat(manifestCreator.createManifestElement("test.txt",
private final Sone sone = mock(Sone.class);
private FreenetURI requestUri = mock(FreenetURI.class);
private final PostBuilder postBuilder = mock(PostBuilder.class);
- private final List<Post> createdPosts = new ArrayList<Post>();
+ private final List<Post> createdPosts = new ArrayList<>();
private Post post = mock(Post.class);
private final PostReplyBuilder postReplyBuilder = mock(PostReplyBuilder.class);
- private final Set<PostReply> createdPostReplies = new HashSet<PostReply>();
+ private final Set<PostReply> createdPostReplies = new HashSet<>();
private PostReply postReply = mock(PostReply.class);
private final AlbumBuilder albumBuilder = mock(AlbumBuilder.class);
private final ListMultimap<Album, Album>
nestedAlbums = ArrayListMultimap.create();
private final ListMultimap<Album, Image> albumImages = ArrayListMultimap.create();
private Album album = mock(Album.class);
- private final Map<String, Album> albums = new HashMap<String, Album>();
+ private final Map<String, Album> albums = new HashMap<>();
private final ImageBuilder imageBuilder = mock(ImageBuilder.class);
private Image image = mock(Image.class);
- private final Map<String, Image> images = new HashMap<String, Image>();
+ private final Map<String, Image> images = new HashMap<>();
@Before
public void setupSone() {
mock(ConfigurationLoader.class);
private final MemoryBookmarkDatabase bookmarkDatabase =
new MemoryBookmarkDatabase(memoryDatabase, configurationLoader);
- private final Map<String, Post> posts = new HashMap<String, Post>();
+ private final Map<String, Post> posts = new HashMap<>();
@Before
public void setupMemoryDatabase() {
@Test
public void bookmarkDatabaseRetainsBookmarkedPosts() {
- Set<Post> allPosts = new HashSet<Post>(posts.values());
+ Set<Post> allPosts = new HashSet<>(posts.values());
for (Post post : allPosts) {
bookmarkDatabase.bookmarkPost(post);
}
@Test
public void removingABookmarkRemovesTheCorrectBookmark() {
- Set<Post> allPosts = new HashSet<Post>(posts.values());
+ Set<Post> allPosts = new HashSet<>(posts.values());
for (Post post : allPosts) {
bookmarkDatabase.bookmarkPost(post);
}
.withTime(4000L)
.withText("reply2")
.build();
- Set<PostReply> postReplies = new HashSet<PostReply>(
+ Set<PostReply> postReplies = new HashSet<>(
asList(firstPostFirstReply, firstPostSecondReply,
secondPostReply));
when(sone.getReplies()).thenReturn(postReplies);
}
private Map<OwnIdentity, Collection<Identity>> createNewIdentities() {
- Map<OwnIdentity, Collection<Identity>> oldIdentities = new HashMap<OwnIdentity, Collection<Identity>>();
+ Map<OwnIdentity, Collection<Identity>> oldIdentities = new HashMap<>();
oldIdentities.put(ownIdentities.get(1), asList(identities.get(3), identities.get(2)));
oldIdentities.put(ownIdentities.get(2), asList(identities.get(1), identities.get(2)));
return oldIdentities;
}
private Map<OwnIdentity, Collection<Identity>> createOldIdentities() {
- Map<OwnIdentity, Collection<Identity>> oldIdentities = new HashMap<OwnIdentity, Collection<Identity>>();
+ Map<OwnIdentity, Collection<Identity>> oldIdentities = new HashMap<>();
oldIdentities.put(ownIdentities.get(0), asList(identities.get(0), identities.get(1)));
oldIdentities.put(ownIdentities.get(1), asList(identities.get(0), identities.get(1)));
return oldIdentities;
public ListNotificationTest() {
when(template.getInitialContext()).thenReturn(templateInitialContext);
- listNotification = new ListNotification<Object>(ID, KEY, template);
+ listNotification = new ListNotification<>(ID, KEY, template);
}
@Test
public class CollectionAccessorTest {
private final CollectionAccessor accessor = new CollectionAccessor();
- private final Collection<Object> collection = new ArrayList<Object>();
+ private final Collection<Object> collection = new ArrayList<>();
@Before
public void setupCollection() {
private final File tempFile;
private final FilesystemTemplate filesystemTemplate;
- private final AtomicReference<StringWriter> stringWriter = new AtomicReference<StringWriter>(new StringWriter());
+ private final AtomicReference<StringWriter> stringWriter = new AtomicReference<>(new StringWriter());
private final TemplateContext templateContext = new TemplateContext();
public FilesystemTemplateTest() throws IOException {
private final TemplateContext context = mock(TemplateContext.class);
private final FreenetRequest request = mock(FreenetRequest.class);
private final Map<String, String> parameters =
- new HashMap<String, String>();
+ new HashMap<>();
private HTTPRequest httpRequest = mock(HTTPRequest.class);
@Before
public class TestAlbumBuilder implements AlbumBuilder {
private final Album album = mock(Album.class);
- private final List<Album> albums = new ArrayList<Album>();
- private final List<Image> images = new ArrayList<Image>();
+ private final List<Album> albums = new ArrayList<>();
+ private final List<Image> images = new ArrayList<>();
private Album parentAlbum;
private String title;
private String description;
*/
public class TestValue<T> implements Value<T> {
- private final AtomicReference<T> value = new AtomicReference<T>();
+ private final AtomicReference<T> value = new AtomicReference<>();
public TestValue(@Nullable T originalValue) {
value.set(originalValue);
@Nonnull
public static <T> Value<T> from(@Nullable T value) {
- return new TestValue<T>(value);
+ return new TestValue<>(value);
}
}
@Test
public void defaultOptionReturnsDefaultValueWhenUnset() {
- DefaultOption<Object> defaultOption = new DefaultOption<Object>(defaultValue);
+ DefaultOption<Object> defaultOption = new DefaultOption<>(defaultValue);
assertThat(defaultOption.get(), is(defaultValue));
}
@Test
public void defaultOptionReturnsNullForRealWhenUnset() {
- DefaultOption<Object> defaultOption = new DefaultOption<Object>(defaultValue);
+ DefaultOption<Object> defaultOption = new DefaultOption<>(defaultValue);
assertThat(defaultOption.getReal(), nullValue());
}
@Test
public void defaultOptionWillReturnSetValue() {
- DefaultOption<Object> defaultOption = new DefaultOption<Object>(defaultValue);
+ DefaultOption<Object> defaultOption = new DefaultOption<>(defaultValue);
Object newValue = new Object();
defaultOption.set(newValue);
assertThat(defaultOption.get(), is(newValue));
@Test
public void defaultOptionWithValidatorAcceptsValidValues() {
- DefaultOption<Object> defaultOption = new DefaultOption<Object>(defaultValue, matchesAcceptedValue);
+ DefaultOption<Object> defaultOption = new DefaultOption<>(defaultValue, matchesAcceptedValue);
defaultOption.set(acceptedValue);
assertThat(defaultOption.get(), is(acceptedValue));
}
@Test(expected = IllegalArgumentException.class)
public void defaultOptionWithValidatorRejectsInvalidValues() {
- DefaultOption<Object> defaultOption = new DefaultOption<Object>(defaultValue, matchesAcceptedValue);
+ DefaultOption<Object> defaultOption = new DefaultOption<>(defaultValue, matchesAcceptedValue);
defaultOption.set(new Object());
}
@Test
public void defaultOptionValidatesObjectsCorrectly() {
- DefaultOption<Object> defaultOption = new DefaultOption<Object>(defaultValue, matchesAcceptedValue);
+ DefaultOption<Object> defaultOption = new DefaultOption<>(defaultValue, matchesAcceptedValue);
assertThat(defaultOption.validate(acceptedValue), is(true));
assertThat(defaultOption.validate(new Object()), is(false));
}
@Test
public void settingToNullWillRestoreDefaultValue() {
- DefaultOption<Object> defaultOption = new DefaultOption<Object>(defaultValue);
+ DefaultOption<Object> defaultOption = new DefaultOption<>(defaultValue);
defaultOption.set(null);
assertThat(defaultOption.get(), is(defaultValue));
}
@Test
public void validateWithoutValidatorWillValidateNull() {
- DefaultOption<Object> defaultOption = new DefaultOption<Object>(defaultValue);
+ DefaultOption<Object> defaultOption = new DefaultOption<>(defaultValue);
assertThat(defaultOption.validate(null), is(true));
}
@Test
public void validateWithValidatorWillValidateNull() {
- DefaultOption<Object> defaultOption = new DefaultOption<Object>(defaultValue, matchesAcceptedValue);
+ DefaultOption<Object> defaultOption = new DefaultOption<>(defaultValue, matchesAcceptedValue);
assertThat(defaultOption.validate(null), is(true));
}