X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FImageImpl.java;h=df901b02b3df65821bcbbd54f7440017469c978c;hb=210684b4bc499e298a0d0abeddd4008cdeb406bc;hp=58741c39fb7b6cf361d369a12bcbf13ddb2bf060;hpb=9d32a0f70e14a764946ae29edcf07304f9e5f75e;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/ImageImpl.java b/src/main/java/net/pterodactylus/sone/data/ImageImpl.java index 58741c3..df901b0 100644 --- a/src/main/java/net/pterodactylus/sone/data/ImageImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/ImageImpl.java @@ -141,7 +141,7 @@ public class ImageImpl implements Image { } public Modifier modify() throws IllegalStateException { - checkState((sone == null) || sone.isLocal(), "only local images may be modified"); + // TODO: reenable check for local images return new Modifier() { private Optional sone = absent(); @@ -201,25 +201,44 @@ public class ImageImpl implements Image { @Override public Image update() throws IllegalStateException { - checkState(!sone.isPresent() || sone.get().equals(ImageImpl.this.sone), "can not change Sone once set"); - checkState(!creationTime.isPresent() || (ImageImpl.this.creationTime == 0), "can not change creation time once set"); - checkState(!key.isPresent() || key.get().equals(ImageImpl.this.key), "can not change key once set"); - checkState(!width.isPresent() || width.get().equals(ImageImpl.this.width), "can not change width once set"); - checkState(!height.isPresent() || height.get().equals(ImageImpl.this.height), "can not change height once set"); - - ImageImpl.this.sone = sone.or(ImageImpl.this.sone); - ImageImpl.this.creationTime = creationTime.or(ImageImpl.this.creationTime); - ImageImpl.this.key = key.or(ImageImpl.this.key); - ImageImpl.this.title = title.or(ImageImpl.this.title); - ImageImpl.this.description = description.or(ImageImpl.this.description); - ImageImpl.this.width = width.or(ImageImpl.this.width); - ImageImpl.this.height = height.or(ImageImpl.this.height); + checkState(!sone.isPresent() || (ImageImpl.this.sone == null) || sone.get().equals(ImageImpl.this.sone), "can not change Sone once set"); + checkState(!creationTime.isPresent() || ((ImageImpl.this.creationTime == 0) || (ImageImpl.this.creationTime == creationTime.get())), "can not change creation time once set"); + checkState(!key.isPresent() || (ImageImpl.this.key == null) || key.get().equals(ImageImpl.this.key), "can not change key once set"); + if (title.isPresent() && title.get().trim().isEmpty()) { + throw new ImageTitleMustNotBeEmpty(); + } + checkState(!width.isPresent() || (ImageImpl.this.width == 0) || width.get().equals(ImageImpl.this.width), "can not change width once set"); + checkState(!height.isPresent() || (ImageImpl.this.height == 0) || height.get().equals(ImageImpl.this.height), "can not change height once set"); + + if (sone.isPresent()) { + ImageImpl.this.sone = sone.get(); + } + if (creationTime.isPresent()) { + ImageImpl.this.creationTime = creationTime.get(); + } + if (key.isPresent()) { + ImageImpl.this.key = key.get(); + } + if (title.isPresent()) { + ImageImpl.this.title = title.get(); + } + if (description.isPresent()) { + ImageImpl.this.description = description.get(); + } + if (width.isPresent()) { + ImageImpl.this.width = width.get(); + } + if (height.isPresent()) { + ImageImpl.this.height = height.get(); + } return ImageImpl.this; } }; } + public static class ImageTitleMustNotBeEmpty extends IllegalStateException { } + // // FINGERPRINTABLE METHODS //