Skip to content

Commit

Permalink
[optimization] console service code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireAchao committed Jul 30, 2023
1 parent bd66dfe commit 00cd5ae
Show file tree
Hide file tree
Showing 39 changed files with 197 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ public class RestRequest implements Serializable {
@Schema(example = "1", required = true)
private int pageNum = 1;

@Schema(example = "", description = "e.g. create_time")
@Schema(description = "e.g. create_time")
private String sortField;

@Schema(
example = "",
allowableValues = {"asc", "desc"})
@Schema(allowableValues = {"asc", "desc"})
private String sortOrder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.streampark.console.base.domain;

import org.jetbrains.annotations.NotNull;

import java.util.HashMap;

public class RestResponse extends HashMap<String, Object> {
Expand Down Expand Up @@ -60,6 +62,7 @@ public RestResponse data(Object data) {
return this;
}

@NotNull
@Override
public RestResponse put(String key, Object value) {
super.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.streampark.common.util.FileUtils;
import org.apache.streampark.console.base.exception.ApiAlertException;

import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
Expand All @@ -35,7 +36,10 @@
public class UploadFileTypeInterceptor implements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
public boolean preHandle(
@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response,
@NotNull Object handler)
throws Exception {
if (request instanceof MultipartHttpServletRequest) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Expand All @@ -54,17 +58,20 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons

@Override
public void postHandle(
HttpServletRequest request,
HttpServletResponse response,
Object handler,
@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response,
@NotNull Object handler,
ModelAndView modelAndView)
throws Exception {
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
}

@Override
public void afterCompletion(
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response,
@NotNull Object handler,
Exception ex)
throws Exception {
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.springframework.cglib.beans.BeanMap;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
Expand All @@ -32,7 +31,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -55,9 +53,8 @@ private CommonUtils() {}
* is empty
*
* @param objs handle obj
* @return Boolean
* @see <b>Returns true if the object is Null, returns true if the size of the collection is 0,
* and returns true if the iterator has no next</b>
* @return Boolean <b>Returns true if the object is Null, returns true if the size of the
* collection is 0, and returns true if the iterator has no next</b>
* @since 1.0
*/
public static Boolean isEmpty(Object... objs) {
Expand Down Expand Up @@ -93,7 +90,8 @@ public static Boolean isEmpty(Object... objs) {
}

if (obj instanceof Iterable) {
if (((Iterable<?>) obj).iterator() == null || !((Iterable<?>) obj).iterator().hasNext()) {
((Iterable<?>) obj).iterator();
if (!((Iterable<?>) obj).iterator().hasNext()) {
return true;
}
}
Expand Down Expand Up @@ -191,11 +189,11 @@ public static Float toFloat(Object val) {
return toFloat(val, 0f);
}

public static List arrayToList(Object source) {
public static List<?> arrayToList(Object source) {
return Arrays.asList(ObjectUtils.toObjectArray(source));
}

public static boolean contains(Iterator iterator, Object element) {
public static boolean contains(Iterator<Object> iterator, Object element) {
if (iterator != null) {
while (iterator.hasNext()) {
Object candidate = iterator.next();
Expand All @@ -214,7 +212,7 @@ public static boolean contains(Iterator iterator, Object element) {
* @param element the element to look for
* @return <code>true</code> if found, <code>false</code> else
*/
public static boolean contains(Enumeration enumeration, Object element) {
public static boolean contains(Enumeration<Object> enumeration, Object element) {
if (enumeration != null) {
while (enumeration.hasMoreElements()) {
Object candidate = enumeration.nextElement();
Expand Down Expand Up @@ -250,7 +248,7 @@ public static boolean deleteFile(File dir) {
* @param element the element to look for
* @return <code>true</code> if found, <code>false</code> else
*/
public static boolean containsInstance(Collection collection, Object element) {
public static boolean containsInstance(Collection<Object> collection, Object element) {
if (collection != null) {
for (Object candidate : collection) {
if (candidate == element) {
Expand All @@ -262,7 +260,7 @@ public static boolean containsInstance(Collection collection, Object element) {
}

public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
ArrayList<A> elements = new ArrayList<A>();
ArrayList<A> elements = new ArrayList<>();
while (enumeration.hasMoreElements()) {
elements.add(enumeration.nextElement());
}
Expand All @@ -277,10 +275,10 @@ public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array
*/
public static <E> Iterator<E> toIterator(Enumeration<E> enumeration) {
@SuppressWarnings("hiding")
class EnumerationIterator<E> implements Iterator<E> {
private final Enumeration<E> enumeration;
class EnumerationIterator<U> implements Iterator<U> {
private final Enumeration<U> enumeration;

public EnumerationIterator(Enumeration<E> enumeration) {
public EnumerationIterator(Enumeration<U> enumeration) {
this.enumeration = enumeration;
}

Expand All @@ -290,7 +288,7 @@ public boolean hasNext() {
}

@Override
public E next() {
public U next() {
return this.enumeration.nextElement();
}

Expand All @@ -300,79 +298,79 @@ public void remove() throws UnsupportedOperationException {
}
}

return new EnumerationIterator<E>(enumeration);
return new EnumerationIterator<>(enumeration);
}

public static String getOsName() {
return OS;
}

public static boolean isLinux() {
return OS.indexOf("linux") >= 0;
return OS.contains("linux");
}

public static boolean isMacOS() {
return OS.indexOf("mac") >= 0 && OS.indexOf("os") > 0 && OS.indexOf("x") < 0;
return OS.contains("mac") && OS.indexOf("os") > 0 && !OS.contains("x");
}

public static boolean isMacOSX() {
return OS.indexOf("mac") >= 0 && OS.indexOf("os") > 0 && OS.indexOf("x") > 0;
return OS.contains("mac") && OS.indexOf("os") > 0 && OS.indexOf("x") > 0;
}

public static boolean isWindows() {
return OS.indexOf("windows") >= 0;
return OS.contains("windows");
}

public static boolean isOS2() {
return OS.indexOf("os/2") >= 0;
return OS.contains("os/2");
}

public static boolean isSolaris() {
return OS.indexOf("solaris") >= 0;
return OS.contains("solaris");
}

public static boolean isSunOS() {
return OS.indexOf("sunos") >= 0;
return OS.contains("sunos");
}

public static boolean isMPEiX() {
return OS.indexOf("mpe/ix") >= 0;
return OS.contains("mpe/ix");
}

public static boolean isHPUX() {
return OS.indexOf("hp-ux") >= 0;
return OS.contains("hp-ux");
}

public static boolean isAix() {
return OS.indexOf("aix") >= 0;
return OS.contains("aix");
}

public static boolean isOS390() {
return OS.indexOf("os/390") >= 0;
return OS.contains("os/390");
}

public static boolean isFreeBSD() {
return OS.indexOf("freebsd") >= 0;
return OS.contains("freebsd");
}

public static boolean isIrix() {
return OS.indexOf("irix") >= 0;
return OS.contains("irix");
}

public static boolean isDigitalUnix() {
return OS.indexOf("digital") >= 0 && OS.indexOf("unix") > 0;
return OS.contains("digital") && OS.indexOf("unix") > 0;
}

public static boolean isNetWare() {
return OS.indexOf("netware") >= 0;
return OS.contains("netware");
}

public static boolean isOSF1() {
return OS.indexOf("osf1") >= 0;
return OS.contains("osf1");
}

public static boolean isOpenVMS() {
return OS.indexOf("openvms") >= 0;
return OS.contains("openvms");
}

public static boolean isUnix() {
Expand Down Expand Up @@ -441,8 +439,8 @@ public static int getPlatform() {
}

public static <K, V extends Comparable<? super V>> Map<K, V> sortMapByValue(Map<K, V> map) {
List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
Collections.sort(list, Comparator.comparing(Map.Entry::getValue));
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
list.sort(Map.Entry.comparingByValue());
Map<K, V> result = new LinkedHashMap<>();
for (Map.Entry<K, V> entry : list) {
result.put(entry.getKey(), entry.getValue());
Expand Down Expand Up @@ -482,7 +480,7 @@ public static <T> T[] arrayRemoveIndex(T[] array, int... index) {

public static <T> T[] arrayInsertIndex(T[] array, int index, T t) {
Utils.notNull(array);
List<T> arrayList = new ArrayList<T>(array.length + 1);
List<T> arrayList = new ArrayList<>(array.length + 1);
if (index == 0) {
arrayList.add(t);
Collections.addAll(arrayList, array);
Expand All @@ -508,7 +506,7 @@ public static String uuid() {
* @return uuid
*/
public static String uuid(int len) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
while (sb.length() < len) {
sb.append(uuid());
}
Expand All @@ -523,9 +521,9 @@ public static Double fixedNum(Number number, int offset) {
if (number.doubleValue() == 0.00) {
return 0D;
}
String prefix = "";
StringBuilder prefix = new StringBuilder();
while (offset > 0) {
prefix += "0";
prefix.append("0");
offset -= 1;
}

Expand Down Expand Up @@ -581,15 +579,14 @@ public static <T> T mapToBean(Map<String, Object> map, T bean) {
/**
* convert List<T> to List<Map<String, Object>>
*
* @param objList
* @return
* @throws IOException
* @param objList objList
* @return List<Map<String, Object>>
*/
public static <T> List<Map<String, Object>> objectsToMaps(List<T> objList) {
List<Map<String, Object>> list = new ArrayList<>();
if (objList != null && objList.size() > 0) {
Map<String, Object> map = null;
T bean = null;
Map<String, Object> map;
T bean;
for (T t : objList) {
bean = t;
map = beanToMap(bean);
Expand All @@ -604,9 +601,9 @@ public static <T> List<Map<String, Object>> objectsToMaps(List<T> objList) {
*
* @param maps maps
* @param clazz element class
* @return
* @throws InstantiationException
* @throws IllegalAccessException
* @return List<T>
* @throws InstantiationException InstantiationException
* @throws IllegalAccessException IllegalAccessException
*/
public static <T> List<T> mapsToObjects(List<Map<String, Object>> maps, Class<T> clazz)
throws InstantiationException, IllegalAccessException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FileUtils {
* @param file The file
* @param maxSize Maximum size of read file
* @return The file content
* @throws IOException
* @throws IOException IOException
*/
public static byte[] readEndOfFile(File file, long maxSize) throws IOException {
long readSize = maxSize;
Expand All @@ -53,7 +53,7 @@ public static byte[] readEndOfFile(File file, long maxSize) throws IOException {
* @param file The file
* @param maxSize Maximum size of read file
* @return The file content
* @throws IOException
* @throws IOException IOException
*/
public static byte[] readFileFromOffset(File file, long startOffset, long maxSize)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void deCompress(String tarZipSource, String targetDir) {
String fullFileName = createDir(targetDir, entryName, 2);
try (FileOutputStream outputStream = new FileOutputStream(fullFileName);
BufferedOutputStream bufOutput = new BufferedOutputStream(outputStream)) {
int b = -1;
int b;
while ((b = archiveInput.read()) != -1) {
bufOutput.write(b);
}
Expand All @@ -80,7 +80,7 @@ public static void deCompress(String tarZipSource, String targetDir) {
* @param baseDir baseDir
* @param entry archive entry
* @param type type: 1, dir; 2, file
* @return
* @return fullFilePath
*/
private static String createDir(String baseDir, String entry, int type) {
String[] items = entry.split("/");
Expand Down
Loading

0 comments on commit 00cd5ae

Please sign in to comment.