Skip to content
Open

Cleanup #1550

Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion framework/src/play/Invoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public InvocationContext getInvocationContext() {
*/
static {
int core = Integer.parseInt(Play.configuration.getProperty("play.pool",
Play.mode == Mode.DEV ? "1" : ((Runtime.getRuntime().availableProcessors() + 1) + "")));
Play.mode == Mode.DEV ? "1" : Integer.toString(Runtime.getRuntime().availableProcessors() + 1)));
executor = new ScheduledThreadPoolExecutor(core, new PThreadFactory("play"), new ThreadPoolExecutor.AbortPolicy());
}

Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ static boolean niceThrowable(org.apache.logging.log4j.Level level, Throwable e,
}
cleanTrace.add(se);
}
toClean.setStackTrace(cleanTrace.toArray(new StackTraceElement[cleanTrace.size()]));
toClean.setStackTrace(cleanTrace.toArray(StackTraceElement[]::new));
toClean = toClean.getCause();
if (toClean == null) {
break;
Expand Down
10 changes: 5 additions & 5 deletions framework/src/play/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ private static Properties readOneConfigurationFile(String filename) {
Properties newConfiguration = new OrderSafeProperties();
Pattern pattern = Pattern.compile("^%([a-zA-Z0-9_\\-]+)\\.(.*)$");
for (Object key : propsFromFile.keySet()) {
Matcher matcher = pattern.matcher(key + "");
Matcher matcher = pattern.matcher(String.valueOf(key));
if (!matcher.matches()) {
newConfiguration.put(key, propsFromFile.get(key).toString().trim());
}
}
for (Object key : propsFromFile.keySet()) {
Matcher matcher = pattern.matcher(key + "");
Matcher matcher = pattern.matcher(String.valueOf(key));
if (matcher.matches()) {
String instance = matcher.group(1);
if (instance.equals(id)) {
Expand Down Expand Up @@ -512,7 +512,7 @@ public static synchronized void start() {

// Locales
langs = new ArrayList<>(Arrays.asList(configuration.getProperty("application.langs", "").split(",")));
if (langs.size() == 1 && langs.get(0).trim().length() == 0) {
if (langs.size() == 1 && langs.get(0).isBlank()) {
langs = new ArrayList<>(16);
}

Expand All @@ -521,7 +521,7 @@ public static synchronized void start() {

// SecretKey
secretKey = configuration.getProperty("application.secret", "").trim();
if (secretKey.length() == 0) {
if (secretKey.isEmpty()) {
Logger.warn("No secret key defined. Sessions will not be encrypted");
}

Expand Down Expand Up @@ -729,7 +729,7 @@ public static void loadModules() {
public static void loadModules(VirtualFile appRoot) {
if (System.getenv("MODULES") != null) {
// Modules path is prepended with a env property
if (System.getenv("MODULES") != null && System.getenv("MODULES").trim().length() > 0) {
if (System.getenv("MODULES") != null && !System.getenv("MODULES").isBlank()) {

for (String m : System.getenv("MODULES").split(File.pathSeparator)) {
File modulePath = new File(m);
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/PlayPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ public String getName() {

// I don't want to add any additional dependencies to the project or use JDK 8 features
// so I'm just rolling my own 1 arg function interface... there must be a better way to do this...
public static interface Function1<I, O> {
public O apply(I arg) throws Throwable;
public interface Function1<I, O> {
O apply(I arg) throws Throwable;
}
}

Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/ant/PlayConfigurationLoadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ private Map<String, String> properties() {
continue;
}
if (line.startsWith("%")) {
if (playId.length() > 0 && line.startsWith(playId + ".")) {
line = line.substring((playId + ".").length());
if (!playId.isEmpty() && line.startsWith(playId + '.')) {
line = line.substring(playId.length() + 1);
String[] sa = splitLine(line);
if (sa != null) {
idSpecific.put(sa[0], sa[1]);
Expand Down
28 changes: 14 additions & 14 deletions framework/src/play/cache/CacheImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@
*/
public interface CacheImpl {

public void add(String key, Object value, int expiration);
void add(String key, Object value, int expiration);

public boolean safeAdd(String key, Object value, int expiration);
boolean safeAdd(String key, Object value, int expiration);

public void set(String key, Object value, int expiration);
void set(String key, Object value, int expiration);

public boolean safeSet(String key, Object value, int expiration);
boolean safeSet(String key, Object value, int expiration);

public void replace(String key, Object value, int expiration);
void replace(String key, Object value, int expiration);

public boolean safeReplace(String key, Object value, int expiration);
boolean safeReplace(String key, Object value, int expiration);

public Object get(String key);
Object get(String key);

public Map<String, Object> get(String[] keys);
Map<String, Object> get(String[] keys);

public long incr(String key, int by);
long incr(String key, int by);

public long decr(String key, int by);
long decr(String key, int by);

public void clear();
void clear();

public void delete(String key);
void delete(String key);

public boolean safeDelete(String key);
boolean safeDelete(String key);

public void stop();
void stop();
}
2 changes: 1 addition & 1 deletion framework/src/play/cache/CacheKeyGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* Allow custom cache key to be used by applications.
*/
public interface CacheKeyGenerator {
public String generate(Request request);
String generate(Request request);
}
2 changes: 1 addition & 1 deletion framework/src/play/classloading/ApplicationClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static class ApplicationClass {
/**
* Last time than this class was compiled
*/
public Long timestamp = 0L;
public long timestamp = 0L;
/**
* Is this class compiled
*/
Expand Down
6 changes: 3 additions & 3 deletions framework/src/play/classloading/ApplicationClassloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public void detectChanges() throws RestartNeededException {
Cache.clear();
if (HotswapAgent.enabled) {
try {
HotswapAgent.reload(newDefinitions.toArray(new ClassDefinition[newDefinitions.size()]));
HotswapAgent.reload(newDefinitions.toArray(ClassDefinition[]::new));
} catch (Throwable e) {
throw new RestartNeededException(newDefinitions.size() + " classes changed", e);
}
Expand Down Expand Up @@ -416,7 +416,7 @@ public List<Class<?>> getAllClasses() {
}
}

Play.classes.compiler.compile(classNames.toArray(new String[classNames.size()]));
Play.classes.compiler.compile(classNames.toArray(String[]::new));

}

Expand Down Expand Up @@ -521,7 +521,7 @@ private List<ApplicationClass> getAllClasses(VirtualFile path) {
}

private List<ApplicationClass> getAllClasses(VirtualFile path, String basePackage) {
if (basePackage.length() > 0 && !basePackage.endsWith(".")) {
if (!basePackage.isEmpty() && !basePackage.endsWith(".")) {
basePackage += ".";
}
List<ApplicationClass> res = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void edit(Handler handler) throws CannotCompileException {
/**
* Mark class that need controller enhancement
*/
public static interface ControllerSupport {
public interface ControllerSupport {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void enhanceThisClass(ApplicationClass applicationClass) throws Exception

try {
// The instruction at which this local variable has been created
Integer pc = localVariableAttribute.startPc(i);
int pc = localVariableAttribute.startPc(i);

// Move to the next instruction (insertionPc)
CodeIterator codeIterator = codeAttribute.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void enhanceThisClass(ApplicationClass applicationClass) throws Exception
try {

// The instruction at which this local variable has been created
Integer pc = localVariableAttribute.startPc(i);
int pc = localVariableAttribute.startPc(i);

// Move to the next instruction (insertionPc)
CodeIterator codeIterator = codeAttribute.iterator();
Expand Down Expand Up @@ -190,15 +190,15 @@ public void enhanceThisClass(ApplicationClass applicationClass) throws Exception
ctClass.defrost();
}

public static Integer computeMethodHash(CtClass[] parameters) {
public static int computeMethodHash(CtClass[] parameters) {
String[] names = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
names[i] = parameters[i].getName();
}
return computeMethodHash(names);
}

public static Integer computeMethodHash(Class<?>[] parameters) {
public static int computeMethodHash(Class<?>[] parameters) {
String[] names = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
Class<?> param = parameters[i];
Expand All @@ -222,12 +222,12 @@ public static Integer computeMethodHash(Class<?>[] parameters) {
return computeMethodHash(names);
}

public static Integer computeMethodHash(String[] parameters) {
public static int computeMethodHash(String[] parameters) {
StringBuilder buffer = new StringBuilder();
for (String param : parameters) {
buffer.append(param);
}
Integer hash = buffer.toString().hashCode();
int hash = buffer.toString().hashCode();
if (hash < 0) {
return -hash;
}
Expand Down
6 changes: 3 additions & 3 deletions framework/src/play/data/FileUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public FileUpload(FileItem fileItem) {
this.fileItem = fileItem;
File tmp = TempFilePlugin.createTempFolder();
// Check that the file has a name to avoid to override the field folder
if (fileItem.getName().trim().length() > 0) {
if (!fileItem.getName().isBlank()) {
defaultFile = new File(tmp, FilenameUtils.getName(fileItem.getFieldName()) + File.separator
+ FilenameUtils.getName(fileItem.getName()));
try {
Expand Down Expand Up @@ -88,8 +88,8 @@ public String getFieldName() {
}

@Override
public Long getSize() {
return defaultFile == null ? null : defaultFile.length();
public long getSize() {
return defaultFile == null ? 0L : defaultFile.length();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/data/MemoryUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String getFieldName() {
}

@Override
public Long getSize() {
public long getSize() {
return fileItem.getSize();
}

Expand Down
16 changes: 8 additions & 8 deletions framework/src/play/data/Upload.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

public interface Upload {

public byte[] asBytes();
public InputStream asStream();
public String getContentType();
public String getFileName();
public String getFieldName();
public Long getSize();
public boolean isInMemory();
public File asFile();
byte[] asBytes();
InputStream asStream();
String getContentType();
String getFileName();
String getFieldName();
long getSize();
boolean isInMemory();
File asFile();
}
4 changes: 2 additions & 2 deletions framework/src/play/data/binding/Binder.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected static Object internalBind(ParamNode paramNode, Class<?> clazz, Type t
return MISSING;
}

if (paramNode.getValues() == null && paramNode.getAllChildren().size() == 0) {
if (paramNode.getValues() == null && paramNode.getAllChildren().isEmpty()) {
return MISSING;
}

Expand Down Expand Up @@ -531,7 +531,7 @@ private static Object bindCollection(Class<?> clazz, Type type, ParamNode paramN
logBindingNormalFailure(paramNode, e); // TODO debug or error?
}
}
if (hasMissing && l.size() == 0) {
if (hasMissing && l.isEmpty()) {
return MISSING;
}
return l;
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/data/binding/Unbinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private static void unBind(Map<String, Object> result, Object src, Class<?> srcC
}

try {
internalUnbind(result, field.get(src), field.getType(), newName, allAnnotations.toArray(new Annotation[0]));
internalUnbind(result, field.get(src), field.getType(), newName, allAnnotations.toArray(Annotation[]::new));
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException("Object " + field.getType() + " won't unbind field " + newName, e);
} finally{
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/data/binding/types/BinaryBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BinaryBinder implements TypeBinder<Model.BinaryField> {
@SuppressWarnings("unchecked")
@Override
public Object bind(String name, Annotation[] annotations, String value, Class actualClass, Type genericType) {
if (value == null || value.trim().length() == 0) {
if (value == null || value.isBlank()) {
return null;
}
try {
Expand All @@ -26,7 +26,7 @@ public Object bind(String name, Annotation[] annotations, String value, Class ac
List<Upload> uploads = (List<Upload>) req.args.get("__UPLOADS");
if(uploads != null){
for (Upload upload : uploads) {
if (upload.getFieldName().equals(value) && upload.getFileName().trim().length() > 0) {
if (upload.getFieldName().equals(value) && !upload.getFileName().isBlank()) {
b.set(upload.asStream(), upload.getContentType());
return b;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ByteArrayArrayBinder implements TypeBinder<byte[][]> {
@SuppressWarnings("unchecked")
@Override
public byte[][] bind(String name, Annotation[] annotations, String value, Class actualClass, Type genericType) {
if (value == null || value.trim().length() == 0) {
if (value == null || value.isBlank()) {
return null;
}
Request req = Request.current();
Expand All @@ -32,7 +32,7 @@ public byte[][] bind(String name, Annotation[] annotations, String value, Class
}
}
}
return byteList.toArray(new byte[byteList.size()][]);
return byteList.toArray(byte[][]::new);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/data/binding/types/ByteArrayBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ByteArrayBinder implements TypeBinder<byte[]> {
@SuppressWarnings("unchecked")
@Override
public byte[] bind(String name, Annotation[] annotations, String value, Class actualClass, Type genericType) {
if (value == null || value.trim().length() == 0) {
if (value == null || value.isBlank()) {
return null;
}
Request req = Request.current();
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/data/binding/types/CalendarBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CalendarBinder implements TypeBinder<Calendar> {

@Override
public Calendar bind(String name, Annotation[] annotations, String value, Class actualClass, Type genericType) throws Exception {
if (value == null || value.trim().length() == 0) {
if (value == null || value.isBlank()) {
return null;
}
Calendar cal = Calendar.getInstance(Lang.getLocale());
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/data/binding/types/FileArrayBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public File[] bind(String name, Annotation[] annotations, String value, Class ac
if (uploads != null) {
for (Upload upload : uploads) {
if (upload.getFieldName().equals(value)) {
if (upload.getSize() != null && upload.getSize() > 0) {
if (upload.getSize() > 0L) {
File file = upload.asFile();
if (file.length() > 0) {
fileArray.add(file);
Expand All @@ -38,7 +38,7 @@ public File[] bind(String name, Annotation[] annotations, String value, Class ac
}
}
}
return fileArray.toArray(new File[fileArray.size()]);
return fileArray.toArray(File[]::new);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/data/binding/types/FileBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public File bind(String name, Annotation[] annotations, String value, Class actu
if (uploads != null) {
for (Upload upload : uploads) {
if (upload.getFieldName().equals(value)) {
if (upload.getFileName().trim().length() > 0) {
if (!upload.getFileName().isBlank()) {
File file = upload.asFile();
return file;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Upload[] bind(String name, Annotation[] annotations, String value, Class
uploadArray.add(upload);
}
}
return uploadArray.toArray(new Upload[uploadArray.size()]);
return uploadArray.toArray(Upload[]::new);
}
}
return null;
Expand Down
Loading
Loading