Changeset View
Changeset View
Standalone View
Standalone View
src/main/java/net/wildfyre/posts/PostData.java
/* | /* | ||||
Lint: Lint: net.wildfyre.posts.PostTest > createDraft [01;31m[KFAILED[m[K | |||||
Lint: Lint net.wildfyre.http.RequestTest > testMultipart [01;31m[KFAILED[m[K Lint: Lint: net.wildfyre.http.RequestTest > testMultipart [01;31m[KFAILED[m[K | |||||
Lint: Lint net.wildfyre.http.RequestTest > testPatchMethod [01;31m[KFAILED[m[K Lint: Lint: net.wildfyre.http.RequestTest > testPatchMethod [01;31m[KFAILED[m[K | |||||
Lint: Lint :test [01;31m[KFAILED[m[K Lint: Lint: :test [01;31m[KFAILED[m[K | |||||
* Copyright 2018 Wildfyre.net | * Copyright 2018 Wildfyre.net | ||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | abstract class PostData extends Descriptor { | ||||
PostData(){ | PostData(){ | ||||
isAnonymous = false; | isAnonymous = false; | ||||
hasSubscribed = true; | hasSubscribed = true; | ||||
created = ZonedDateTime.now(ZoneId.ofOffset("UTC", ZoneOffset.UTC)); | created = ZonedDateTime.now(ZoneId.ofOffset("UTC", ZoneOffset.UTC)); | ||||
isActive = true; | isActive = true; | ||||
text = null; | text = null; | ||||
imageURL = null; | imageURL = null; | ||||
additionalImages = new String[0]; | additionalImages = new String[0]; | ||||
authorID = Users.myID().orElseThrow(() -> new NullPointerException("The creation of this object"+ | |||||
"requires that the library is initialized, and that the ID of the user is known.")); | |||||
areaID = null; | areaID = null; | ||||
postID = -1; | postID = -1; | ||||
comments = Collections.emptyList(); | comments = Collections.emptyList(); | ||||
Integer me = Users.INSTANCE.myID(); | |||||
if (me == null) | |||||
throw new NullPointerException("The creation of this object" + | |||||
"requires that the library is initialized, and that the ID of the user is known."); | |||||
authorID = me; | |||||
} | } | ||||
/** | /** | ||||
* Creates a PostData object by copying an other existing object. | * Creates a PostData object by copying an other existing object. | ||||
* @param other another PostData object, that is copied into this object. | * @param other another PostData object, that is copied into this object. | ||||
*/ | */ | ||||
PostData(PostData other){ | PostData(PostData other){ | ||||
update(other); | update(other); | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | abstract class PostData extends Descriptor { | ||||
* <pre>{@code !author().isPresent() && !isAnonymous();}</pre> | * <pre>{@code !author().isPresent() && !isAnonymous();}</pre> | ||||
* </p> | * </p> | ||||
* | * | ||||
* @return {@code true} if the author of this post was deleted. | * @return {@code true} if the author of this post was deleted. | ||||
* @see #isAnonymous() Is this post anonymous? | * @see #isAnonymous() Is this post anonymous? | ||||
* @see #author() The author of this post. | * @see #author() The author of this post. | ||||
*/ | */ | ||||
public boolean isAuthorDeleted(){ | public boolean isAuthorDeleted(){ | ||||
return !Users.get(authorID).isPresent() && !isAnonymous; | return Users.INSTANCE.get(authorID) == null && !isAnonymous; | ||||
} | } | ||||
/** | /** | ||||
* The date and time at which this post was created, in the UTC timezone. | * The date and time at which this post was created, in the UTC timezone. | ||||
* | * | ||||
* @return The date and time at which this post was created. | * @return The date and time at which this post was created. | ||||
* @see #createdLocalTime() In the local timezone | * @see #createdLocalTime() In the local timezone | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | abstract class PostData extends Descriptor { | ||||
* <p>There are two cases where there may not be an author: the author chose this post post to be anonymous, or the | * <p>There are two cases where there may not be an author: the author chose this post post to be anonymous, or the | ||||
* original author was deleted since this post's creation.</p> | * original author was deleted since this post's creation.</p> | ||||
* | * | ||||
* @return The author of this post, if any. | * @return The author of this post, if any. | ||||
* @see #isAnonymous() Is this post anonymous? | * @see #isAnonymous() Is this post anonymous? | ||||
* @see #isAuthorDeleted() Was the author of this post deleted? | * @see #isAuthorDeleted() Was the author of this post deleted? | ||||
*/ | */ | ||||
public Optional<User> author(){ | public Optional<User> author(){ | ||||
return authorID == -1 ? Optional.empty() | if (authorID == -1) | ||||
: Optional.of(Users.get(authorID) | return Optional.empty(); | ||||
.orElseThrow(() -> new RuntimeException("Couldn't find the author of this post!\n" | else { | ||||
+ toString()))); | User u = Users.INSTANCE.get(authorID); | ||||
if (u == null) | |||||
throw new NullPointerException("Couldn't find the author of this post!\n" + toString()); | |||||
else | |||||
return Optional.of(u); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* The area in which is post was published. | * The area in which is post was published. | ||||
* | * | ||||
* @return The area in which the post was published. | * @return The area in which the post was published. | ||||
*/ | */ | ||||
public Area area(){ | public Area area(){ | ||||
▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines |
net.wildfyre.posts.PostTest > createDraft [01;31m[KFAILED[m[K