X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FFileOption.java;h=500206ecfebb4b039b4115bf4f42e3fa21e7abc4;hb=8db42d2121e8ee465ab8380a66febde1949a0106;hp=c8824de1b90861caeac9a71ec8ee8e02e3309984;hpb=0e88169c3e8decfcd99f39f5ecf3a85df50c3fca;p=jSite.git diff --git a/src/main/java/de/todesbaum/jsite/application/FileOption.java b/src/main/java/de/todesbaum/jsite/application/FileOption.java index c8824de..500206e 100644 --- a/src/main/java/de/todesbaum/jsite/application/FileOption.java +++ b/src/main/java/de/todesbaum/jsite/application/FileOption.java @@ -1,5 +1,5 @@ /* - * jSite - FileOption.java - Copyright © 2006–2012 David Roden + * jSite - FileOption.java - Copyright © 2006–2019 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 the Free Software @@ -18,6 +18,10 @@ package de.todesbaum.jsite.application; +import static java.util.Optional.empty; + +import java.util.Optional; + /** * Container for various file options. * @@ -34,9 +38,6 @@ public class FileOption { /** The default for the custom key. */ private static final String DEFAULT_CUSTOM_KEY = "CHK@"; - /** The default changed name. */ - private static final String DEFAULT_CHANGED_NAME = null; - /** The insert state. */ private boolean insert; @@ -62,7 +63,7 @@ public class FileOption { private String customKey; /** The changed name. */ - private String changedName; + private Optional changedName = empty(); /** The default MIME type. */ private final String defaultMimeType; @@ -80,11 +81,24 @@ public class FileOption { insert = DEFAULT_INSERT; insertRedirect = DEFAULT_INSERT_REDIRECT; customKey = DEFAULT_CUSTOM_KEY; - changedName = DEFAULT_CHANGED_NAME; this.defaultMimeType = defaultMimeType; mimeType = defaultMimeType; } + public FileOption(FileOption other) { + this.insert = other.insert; + this.forceInsert = other.forceInsert; + this.insertRedirect = other.insertRedirect; + this.lastInsertHash = other.lastInsertHash; + this.lastInsertEdition = other.lastInsertEdition; + this.lastInsertFilename = other.lastInsertFilename; + this.currentHash = other.currentHash; + this.customKey = other.customKey; + this.changedName = other.changedName; + this.defaultMimeType = other.defaultMimeType; + this.mimeType = other.mimeType; + } + /** * Returns the custom key. The custom key is only used when * {@link #isInsert()} and {@link #isInsertRedirect()} both return {@code @@ -278,24 +292,13 @@ public class FileOption { } /** - * Returns whether this file has a changed name. Use - * {@link #getChangedName()} is this method returns {@code true}. - * - * @return {@code true} if this file has a changed name, {@code false} - * otherwise - */ - public boolean hasChangedName() { - return (changedName != null) && (changedName.length() > 0); - } - - /** * Returns the changed name for this file. This method will return {@code * null} or an empty {@link String} if this file should not be renamed. * * @return The changed name, or {@code null} if this file should not be * renamed */ - public String getChangedName() { + public Optional getChangedName() { return changedName; } @@ -307,7 +310,7 @@ public class FileOption { * The new changed name for this file */ public void setChangedName(String changedName) { - this.changedName = changedName; + this.changedName = ((changedName != null) && (changedName.length() > 0)) ? Optional.of(changedName) : Optional.empty(); } /** @@ -349,7 +352,7 @@ public class FileOption { if (!customKey.equals(DEFAULT_CUSTOM_KEY)) { return true; } - if (((changedName != null) && !changedName.equals(DEFAULT_CHANGED_NAME)) || ((DEFAULT_CHANGED_NAME != null) && !DEFAULT_CHANGED_NAME.equals(changedName))) { + if (changedName.isPresent()) { return true; } if (!defaultMimeType.equals(mimeType)) {