X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fapplication%2FFileOption.java;h=4c38286148c9aa60850b0242d0320786cbf7c2ed;hb=7ec476fcc83a2ebe74a9faf3251d9d60fd03f58e;hp=c8824de1b90861caeac9a71ec8ee8e02e3309984;hpb=9e6e70c28963fde2a6c8b120974f8a70d4da25bc;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..4c38286 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–2014 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,11 @@ package de.todesbaum.jsite.application; +import static com.google.common.base.Optional.absent; +import static com.google.common.base.Optional.of; + +import com.google.common.base.Optional; + /** * Container for various file options. * @@ -34,9 +39,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 +64,7 @@ public class FileOption { private String customKey; /** The changed name. */ - private String changedName; + private Optional changedName = absent(); /** The default MIME type. */ private final String defaultMimeType; @@ -80,7 +82,6 @@ public class FileOption { insert = DEFAULT_INSERT; insertRedirect = DEFAULT_INSERT_REDIRECT; customKey = DEFAULT_CUSTOM_KEY; - changedName = DEFAULT_CHANGED_NAME; this.defaultMimeType = defaultMimeType; mimeType = defaultMimeType; } @@ -278,24 +279,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 +297,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)) ? of(changedName) : Optional.absent(); } /** @@ -349,7 +339,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)) {