Polish ternary expressions

This commit is contained in:
Phillip Webb
2018-07-29 09:16:06 +01:00
parent b24bb688b8
commit aeb885192e
49 changed files with 59 additions and 60 deletions

View File

@@ -200,7 +200,7 @@ public class ImageBanner implements Banner {
private void printBanner(BufferedImage image, int margin, boolean invert,
PrintStream out) {
AnsiElement background = (invert ? AnsiBackground.BLACK : AnsiBackground.DEFAULT);
AnsiElement background = invert ? AnsiBackground.BLACK : AnsiBackground.DEFAULT;
out.print(AnsiOutput.encode(AnsiColor.DEFAULT));
out.print(AnsiOutput.encode(background));
out.println();

View File

@@ -119,7 +119,7 @@ public class ResourceBanner implements Banner {
if (version == null) {
return "";
}
return (format ? " (v" + version + ")" : version);
return format ? " (v" + version + ")" : version;
}
private PropertyResolver getAnsiResolver() {

View File

@@ -99,7 +99,7 @@ class SpringApplicationBannerPrinter {
String location = environment.getProperty(BANNER_IMAGE_LOCATION_PROPERTY);
if (StringUtils.hasLength(location)) {
Resource resource = this.resourceLoader.getResource(location);
return (resource.exists() ? new ImageBanner(resource) : null);
return resource.exists() ? new ImageBanner(resource) : null;
}
for (String ext : IMAGE_EXTENSION) {
Resource resource = this.resourceLoader.getResource("banner." + ext);

View File

@@ -66,7 +66,7 @@ public class ContextIdApplicationContextInitializer implements
private String getApplicationId(ConfigurableEnvironment environment) {
String name = environment.getProperty("spring.application.name");
return (StringUtils.hasText(name) ? name : "application");
return StringUtils.hasText(name) ? name : "application";
}
/**

View File

@@ -445,7 +445,7 @@ public class ConfigFileApplicationListener
DocumentConsumer consumer) {
getSearchLocations().forEach((location) -> {
boolean isFolder = location.endsWith("/");
Set<String> names = (isFolder ? getSearchNames() : NO_SEARCH_NAMES);
Set<String> names = isFolder ? getSearchNames() : NO_SEARCH_NAMES;
names.forEach(
(name) -> load(location, name, profile, filterFactory, consumer));
});

View File

@@ -310,7 +310,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
private void setLogLevel(LoggingSystem system, String name, String level) {
try {
name = (name.equalsIgnoreCase(LoggingSystem.ROOT_LOGGER_NAME) ? null : name);
name = name.equalsIgnoreCase(LoggingSystem.ROOT_LOGGER_NAME) ? null : name;
system.setLogLevel(name, coerceLogLevel(level));
}
catch (RuntimeException ex) {

View File

@@ -71,7 +71,7 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
}
new EntryBinder(name, resolvedTarget, elementBinder).bindEntries(source, map);
}
return (map.isEmpty() ? null : map);
return map.isEmpty() ? null : map;
}
private Bindable<?> resolveTarget(Bindable<?> target) {

View File

@@ -319,17 +319,17 @@ public final class ConfigurationPropertyName
int l1 = e1.length();
int l2 = e2.length();
boolean indexed1 = isIndexed(e1);
int offset1 = (indexed1 ? 1 : 0);
int offset1 = indexed1 ? 1 : 0;
boolean indexed2 = isIndexed(e2);
int offset2 = (indexed2 ? 1 : 0);
int offset2 = indexed2 ? 1 : 0;
int i1 = offset1;
int i2 = offset2;
while (i1 < l1 - offset1) {
if (i2 >= l2 - offset2) {
return false;
}
char ch1 = (indexed1 ? e1.charAt(i1) : Character.toLowerCase(e1.charAt(i1)));
char ch2 = (indexed2 ? e2.charAt(i2) : Character.toLowerCase(e2.charAt(i2)));
char ch1 = indexed1 ? e1.charAt(i1) : Character.toLowerCase(e1.charAt(i1));
char ch2 = indexed2 ? e2.charAt(i2) : Character.toLowerCase(e2.charAt(i2));
if (ch1 == '-' || ch1 == '_') {
i1++;
}
@@ -372,7 +372,7 @@ public final class ConfigurationPropertyName
private int getElementHashCode(CharSequence element) {
int hash = 0;
boolean indexed = isIndexed(element);
int offset = (indexed ? 1 : 0);
int offset = indexed ? 1 : 0;
for (int i = 0 + offset; i < element.length() - offset; i++) {
char ch = (indexed ? element.charAt(i)
: Character.toLowerCase(element.charAt(i)));

View File

@@ -44,7 +44,7 @@ class FilteredConfigurationPropertiesSource implements ConfigurationPropertySour
public ConfigurationProperty getConfigurationProperty(
ConfigurationPropertyName name) {
boolean filtered = getFilter().test(name);
return (filtered ? getSource().getConfigurationProperty(name) : null);
return filtered ? getSource().getConfigurationProperty(name) : null;
}
@Override

View File

@@ -100,7 +100,7 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper {
private CharSequence processElementValue(CharSequence value) {
String result = value.toString().toLowerCase(Locale.ENGLISH);
return (isNumber(result) ? "[" + result + "]" : result);
return isNumber(result) ? "[" + result + "]" : result;
}
private static boolean isNumber(String string) {

View File

@@ -140,7 +140,7 @@ public class ApplicationHome {
if (homeDir.isFile()) {
homeDir = homeDir.getParentFile();
}
homeDir = (homeDir.exists() ? homeDir : new File("."));
homeDir = homeDir.exists() ? homeDir : new File(".");
return homeDir.getAbsoluteFile();
}

View File

@@ -67,7 +67,7 @@ public class ServerPortInfoApplicationContextInitializer
private String getName(WebServerApplicationContext context) {
String name = context.getServerNamespace();
return (StringUtils.hasText(name) ? name : "server");
return StringUtils.hasText(name) ? name : "server";
}
private void setPortProperty(ApplicationContext context, String propertyName,

View File

@@ -320,7 +320,7 @@ public class TomcatWebServer implements WebServer {
StringBuilder ports = new StringBuilder();
for (Connector connector : this.tomcat.getService().findConnectors()) {
ports.append((ports.length() != 0) ? " " : "");
int port = (localPort ? connector.getLocalPort() : connector.getPort());
int port = localPort ? connector.getLocalPort() : connector.getPort();
ports.append(port + " (" + connector.getScheme() + ")");
}
return ports.toString();

View File

@@ -169,7 +169,7 @@ public class ServletContextInitializerBeans
private MultipartConfigElement getMultipartConfig(ListableBeanFactory beanFactory) {
List<Entry<String, MultipartConfigElement>> beans = getOrderedBeansOfType(
beanFactory, MultipartConfigElement.class);
return (beans.isEmpty() ? null : beans.get(0).getValue());
return beans.isEmpty() ? null : beans.get(0).getValue();
}
private <T> void addAsRegistrationBean(ListableBeanFactory beanFactory, Class<T> type,

View File

@@ -712,7 +712,7 @@ public abstract class AbstractServletWebServerFactoryTests {
}
private String getStoreType(String keyStore) {
return (keyStore.endsWith(".p12") ? "pkcs12" : null);
return keyStore.endsWith(".p12") ? "pkcs12" : null;
}
@Test