Polishing

This commit is contained in:
Juergen Hoeller 2014-01-26 00:11:11 +01:00
parent e0fd54b8c2
commit bb28d198f5
3 changed files with 21 additions and 15 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* 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.
@ -193,27 +193,30 @@ public abstract class CommandLinePropertySource<T> extends EnumerablePropertySou
/** The default name of the property representing non-option arguments: {@value} */ /** The default name of the property representing non-option arguments: {@value} */
public static final String DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME = "nonOptionArgs"; public static final String DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME = "nonOptionArgs";
private String nonOptionArgsPropertyName = DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME; private String nonOptionArgsPropertyName = DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME;
/** /**
* Create a new {@code CommandLinePropertySource} having the default name {@value * Create a new {@code CommandLinePropertySource} having the default name
* #COMMAND_LINE_PROPERTY_SOURCE_NAME} and backed by the given source object. * {@value #COMMAND_LINE_PROPERTY_SOURCE_NAME} and backed by the given source object.
*/ */
public CommandLinePropertySource(T source) { public CommandLinePropertySource(T source) {
super(COMMAND_LINE_PROPERTY_SOURCE_NAME, source); super(COMMAND_LINE_PROPERTY_SOURCE_NAME, source);
} }
/** /**
* Create a new {@link CommandLinePropertySource} having the given name and backed by * Create a new {@link CommandLinePropertySource} having the given name
* the given source object. * and backed by the given source object.
*/ */
public CommandLinePropertySource(String name, T source) { public CommandLinePropertySource(String name, T source) {
super(name, source); super(name, source);
} }
/** /**
* Specify the name of the special "non-option arguments" property. The default is * Specify the name of the special "non-option arguments" property.
* {@value #DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME}. * The default is {@value #DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME}.
*/ */
public void setNonOptionArgsPropertyName(String nonOptionArgsPropertyName) { public void setNonOptionArgsPropertyName(String nonOptionArgsPropertyName) {
this.nonOptionArgsPropertyName = nonOptionArgsPropertyName; this.nonOptionArgsPropertyName = nonOptionArgsPropertyName;
@ -265,6 +268,7 @@ public abstract class CommandLinePropertySource<T> extends EnumerablePropertySou
} }
} }
/** /**
* Return whether the set of option arguments parsed from the command line contains * Return whether the set of option arguments parsed from the command line contains
* an option with the given name. * an option with the given name.

View File

@ -44,10 +44,11 @@ import org.springframework.util.Assert;
* *
* See {@link CommandLinePropertySource} for complete general usage examples. * See {@link CommandLinePropertySource} for complete general usage examples.
* *
* <p>Requires JOpt version 3.0 or higher. Tested against JOpt up until 4.6. * <p>Requires JOpt version 4.3 or higher. Tested against JOpt up until 4.6.
* *
* @author Chris Beams * @author Chris Beams
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Dave Syer
* @since 3.1 * @since 3.1
* @see CommandLinePropertySource * @see CommandLinePropertySource
* @see joptsimple.OptionParser * @see joptsimple.OptionParser
@ -82,7 +83,7 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource<Opt
@Override @Override
public String[] getPropertyNames() { public String[] getPropertyNames() {
List<String> names = new ArrayList<String>(); List<String> names = new ArrayList<String>();
for (OptionSpec<?> spec : source.specs()) { for (OptionSpec<?> spec : this.source.specs()) {
List<String> aliases = new ArrayList<String>(spec.options()); List<String> aliases = new ArrayList<String>(spec.options());
if (!aliases.isEmpty()) { if (!aliases.isEmpty()) {
// Only the longest name is used for enumerating // Only the longest name is used for enumerating

View File

@ -55,6 +55,7 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
private int timeToLive; private int timeToLive;
/** /**
* Provide a URL path to help identify the target request for this FlashMap. * Provide a URL path to help identify the target request for this FlashMap.
* The path may be absolute (e.g. /application/resource) or relative to the * The path may be absolute (e.g. /application/resource) or relative to the
@ -69,7 +70,7 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
* Return the target URL path or {@code null}. * Return the target URL path or {@code null}.
*/ */
public String getTargetRequestPath() { public String getTargetRequestPath() {
return targetRequestPath; return this.targetRequestPath;
} }
/** /**
@ -121,7 +122,7 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
*/ */
public boolean isExpired() { public boolean isExpired() {
if (this.expirationStartTime != 0) { if (this.expirationStartTime != 0) {
return (System.currentTimeMillis() - this.expirationStartTime) > this.timeToLive * 1000; return (System.currentTimeMillis() - this.expirationStartTime > this.timeToLive * 1000);
} }
else { else {
return false; return false;
@ -135,8 +136,8 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
*/ */
@Override @Override
public int compareTo(FlashMap other) { public int compareTo(FlashMap other) {
int thisUrlPath = (this.targetRequestPath != null) ? 1 : 0; int thisUrlPath = (this.targetRequestPath != null ? 1 : 0);
int otherUrlPath = (other.targetRequestPath != null) ? 1 : 0; int otherUrlPath = (other.targetRequestPath != null ? 1 : 0);
if (thisUrlPath != otherUrlPath) { if (thisUrlPath != otherUrlPath) {
return otherUrlPath - thisUrlPath; return otherUrlPath - thisUrlPath;
} }
@ -148,7 +149,7 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("[Attributes=").append(super.toString()); sb.append("FlashMap [attributes=").append(super.toString());
sb.append(", targetRequestPath=").append(this.targetRequestPath); sb.append(", targetRequestPath=").append(this.targetRequestPath);
sb.append(", targetRequestParams=").append(this.targetRequestParams).append("]"); sb.append(", targetRequestParams=").append(this.targetRequestParams).append("]");
return sb.toString(); return sb.toString();