diff --git a/src/main/java/cokr/xit/foundation/ApplicationException.java b/src/main/java/cokr/xit/foundation/ApplicationException.java index afe43ee..be70e16 100644 --- a/src/main/java/cokr/xit/foundation/ApplicationException.java +++ b/src/main/java/cokr/xit/foundation/ApplicationException.java @@ -13,9 +13,7 @@ public class ApplicationException extends RuntimeException { * @return ApplicationException */ public static ApplicationException get(Throwable cause) { - return cause instanceof ApplicationException ? - ApplicationException.class.cast(cause) : - new ApplicationException(cause); + return cause instanceof ApplicationException ae ? ae : new ApplicationException(cause); } private DataObject objs; diff --git a/src/main/java/cokr/xit/foundation/Assert.java b/src/main/java/cokr/xit/foundation/Assert.java index c1dc8c5..bfa3911 100644 --- a/src/main/java/cokr/xit/foundation/Assert.java +++ b/src/main/java/cokr/xit/foundation/Assert.java @@ -18,12 +18,10 @@ public class Assert { */ public static final boolean isEmpty(Object obj) { if (obj == null) return true; - if (obj instanceof String) { - String str = (String)obj; - return str.trim().isEmpty(); + if (obj instanceof String str) { + return str.isEmpty() || str.isBlank(); } - if (obj instanceof Iterable) { - Iterable objs = (Iterable)obj; + if (obj instanceof Iterable objs) { return !objs.iterator().hasNext(); } if (obj.getClass().isArray()) { @@ -94,8 +92,8 @@ public class Assert { public static final Throwable rootCause(Throwable t) { Throwable cause = t != null ? t.getCause() : null; if (cause == null - && t instanceof InvocationTargetException) - cause = ((InvocationTargetException)t).getTargetException(); + && t instanceof InvocationTargetException e) + cause = e.getTargetException(); return cause == null || cause == t ? t : rootCause(cause); } @@ -105,7 +103,7 @@ public class Assert { */ public static final RuntimeException runtimeException(Throwable t) { t = rootCause(t); - return t instanceof RuntimeException ? RuntimeException.class.cast(t) : new RuntimeException(t); + return t instanceof RuntimeException re ? re : new RuntimeException(t); } /**{@link Assert}에 대한 인터페이스. diff --git a/src/main/java/cokr/xit/foundation/data/Convert.java b/src/main/java/cokr/xit/foundation/data/Convert.java index 8f6a9fb..e122c84 100644 --- a/src/main/java/cokr/xit/foundation/data/Convert.java +++ b/src/main/java/cokr/xit/foundation/data/Convert.java @@ -79,8 +79,7 @@ public class Convert { return Integer.valueOf(0); if (obj instanceof Number) return Number.class.cast(obj); - if (obj instanceof String) { - String s = (String)obj; + if (obj instanceof String s) { return Double.valueOf(s.replace(",", "").trim()); } throw inconvertible(obj, Number.class); diff --git a/src/main/java/cokr/xit/foundation/data/DataFormat.java b/src/main/java/cokr/xit/foundation/data/DataFormat.java index 8463a86..08eb01a 100644 --- a/src/main/java/cokr/xit/foundation/data/DataFormat.java +++ b/src/main/java/cokr/xit/foundation/data/DataFormat.java @@ -90,8 +90,8 @@ public class DataFormat extends AbstractComponent { } catch (Exception e) { return str; } - } else if (obj instanceof Date) - return dateFormat.format((Date)obj); + } else if (obj instanceof Date date) + return dateFormat.format(date); else throw new IllegalArgumentException(obj + " is not a Date"); } @@ -106,10 +106,10 @@ public class DataFormat extends AbstractComponent { Number num = null; if (obj == null) num = 0; - else if (obj instanceof String) - num = Double.valueOf(ifEmpty((String)obj, "0")); - else if (obj instanceof Number) - num = (Number)obj; + else if (obj instanceof String str) + num = Double.valueOf(ifEmpty(str, "0")); + else if (obj instanceof Number n) + num = n; else throw new IllegalArgumentException(obj + " is not a number"); diff --git a/src/main/java/cokr/xit/foundation/data/DataObject.java b/src/main/java/cokr/xit/foundation/data/DataObject.java index 5d06712..7056b53 100644 --- a/src/main/java/cokr/xit/foundation/data/DataObject.java +++ b/src/main/java/cokr/xit/foundation/data/DataObject.java @@ -19,7 +19,7 @@ public class DataObject extends StringMap { */ public static DataObject create(Map map) { if (map == null) return null; - if (map instanceof DataObject) return (DataObject)map; + if (map instanceof DataObject dataObject) return dataObject; DataObject result = new DataObject(); map.forEach(result::put); @@ -88,7 +88,7 @@ public class DataObject extends StringMap { */ public String string(String name) { Object obj = get(name); - return isEmpty(obj) ? "" : obj instanceof String ? (String)obj : obj.toString().trim(); + return isEmpty(obj) ? "" : obj instanceof String str ? str : obj.toString().trim(); } /**지정하는 이름의 값을 Number로 변환하여 반환한다. @@ -102,10 +102,10 @@ public class DataObject extends StringMap { Object obj = get(name); if (obj == null) return Integer.valueOf(0); - if (obj instanceof Number) - return Number.class.cast(obj); - if (obj instanceof String) - return Double.valueOf((String)obj); + if (obj instanceof Number num) + return num; + if (obj instanceof String str) + return Double.valueOf(str); throw new RuntimeException("The Object named '" + name + "' is not a Number"); } @@ -121,7 +121,7 @@ public class DataObject extends StringMap { if (obj == null) return false; - Boolean bool = obj instanceof Boolean ? Boolean.class.cast(obj) : Boolean.valueOf(obj.toString()); + Boolean bool = obj instanceof Boolean b ? b : Boolean.valueOf(obj.toString()); return bool.booleanValue(); } } \ No newline at end of file diff --git a/src/main/java/cokr/xit/foundation/data/JSON.java b/src/main/java/cokr/xit/foundation/data/JSON.java index 5bc4ae5..75970b0 100644 --- a/src/main/java/cokr/xit/foundation/data/JSON.java +++ b/src/main/java/cokr/xit/foundation/data/JSON.java @@ -126,8 +126,8 @@ public class JSON extends AbstractComponent { * @return 객체를 변환한 JSON 문자열 */ public String stringify(Object obj, boolean indent) { - if (obj instanceof String) - return (String)obj; + if (obj instanceof String str) + return str; ObjectMapper mapper = getObjectMapper(); ObjectWriter writer = null; diff --git a/src/main/java/cokr/xit/foundation/data/XML.java b/src/main/java/cokr/xit/foundation/data/XML.java index 5aa9037..1ca624c 100644 --- a/src/main/java/cokr/xit/foundation/data/XML.java +++ b/src/main/java/cokr/xit/foundation/data/XML.java @@ -109,8 +109,8 @@ public class XML extends AbstractComponent { * @return 객체를 변환한 XML 문자열 */ public String stringify(Object obj, boolean indent) { - if (obj instanceof String) - return (String)obj; + if (obj instanceof String str) + return str; XmlMapper mapper = getXmlMapper(); ObjectWriter writer = !indent ? mapper.writer() : mapper.writerWithDefaultPrettyPrinter(); diff --git a/src/main/java/cokr/xit/foundation/data/paging/BoundedList.java b/src/main/java/cokr/xit/foundation/data/paging/BoundedList.java index 49ca6b8..3747adb 100644 --- a/src/main/java/cokr/xit/foundation/data/paging/BoundedList.java +++ b/src/main/java/cokr/xit/foundation/data/paging/BoundedList.java @@ -55,8 +55,7 @@ public class BoundedList extends ArrayList { if (first instanceof Map) { Map row = (Map)first; totalSize = Pageable.getTotalSize(row); - } else if (first instanceof Pageable) { - Pageable row = (Pageable)first; + } else if (first instanceof Pageable row) { totalSize = row.getTotalSize(); } } diff --git a/src/main/java/cokr/xit/foundation/data/paging/MapperSupport.java b/src/main/java/cokr/xit/foundation/data/paging/MapperSupport.java index 7ea1b29..9e9d3cb 100644 --- a/src/main/java/cokr/xit/foundation/data/paging/MapperSupport.java +++ b/src/main/java/cokr/xit/foundation/data/paging/MapperSupport.java @@ -41,10 +41,9 @@ public class MapperSupport extends MybatisPlugin { Object obj = super.handle(resultSetHandler, statement); Pageable.Info paging = pagingInfo.get(); - if (paging != null && (obj instanceof List)) { + if (paging != null && (obj instanceof List list)) { pagingInfo.remove(); - List list = (List)obj; BoundedList boundedList = new BoundedList<>(); boundedList.setFetchSize(paging.fetchSize); boundedList.addAll(list); @@ -69,14 +68,12 @@ public class MapperSupport extends MybatisPlugin { if (isEmpty(arg)) return; now = ifEmpty(now, () -> dateFormat.format(new Date())); - if (arg instanceof AbstractEntity) { - setTimestamp(sqlType, (AbstractEntity)arg, now); - } else if (arg instanceof Map) { - Map map = (Map)arg; + if (arg instanceof AbstractEntity entity) { + setTimestamp(sqlType, entity, now); + } else if (arg instanceof Map map) { for (Object o: map.values()) setEntityTimestamp(sqlType, o, now); - } else if (arg instanceof Iterable) { - Iterable iterable = (Iterable)arg; + } else if (arg instanceof Iterable iterable) { for (Object o: iterable) setEntityTimestamp(sqlType, o, now); } else if (arg.getClass().isArray()) { diff --git a/src/main/java/cokr/xit/foundation/data/paging/MybatisPlugin.java b/src/main/java/cokr/xit/foundation/data/paging/MybatisPlugin.java index f731b0f..010744f 100644 --- a/src/main/java/cokr/xit/foundation/data/paging/MybatisPlugin.java +++ b/src/main/java/cokr/xit/foundation/data/paging/MybatisPlugin.java @@ -125,11 +125,9 @@ public class MybatisPlugin extends AbstractComponent implements Interceptor { } protected void process(Object obj, Consumer processor) { - if (obj instanceof Map) { - Map map = (Map)obj; + if (obj instanceof Map map) { map.values().forEach(processor); - } else if (obj instanceof Iterable) { - Iterable objs = (Iterable)obj; + } else if (obj instanceof Iterable objs) { for (Object o: objs) processor.accept(o); } else if (obj.getClass().isArray()) { diff --git a/src/main/java/cokr/xit/foundation/data/paging/Pageable.java b/src/main/java/cokr/xit/foundation/data/paging/Pageable.java index 4217bec..21ff74e 100644 --- a/src/main/java/cokr/xit/foundation/data/paging/Pageable.java +++ b/src/main/java/cokr/xit/foundation/data/paging/Pageable.java @@ -79,14 +79,12 @@ public interface Pageable { Pageable.getPageNum(params), Pageable.getFetchSize(params) ); - } else if (obj instanceof QueryRequest) { - QueryRequest req = (QueryRequest)obj; + } else if (obj instanceof QueryRequest req) { return new Pageable.Info( req.getPageNum(), req.getFetchSize() ); - } else if (obj instanceof Pageable) { - Pageable pageable = (Pageable)obj; + } else if (obj instanceof Pageable pageable) { return new Pageable.Info( pageable.getPageNum(), pageable.getFetchSize() diff --git a/src/main/java/cokr/xit/foundation/util/ListSupport.java b/src/main/java/cokr/xit/foundation/util/ListSupport.java index a1dc08a..8cb47e0 100644 --- a/src/main/java/cokr/xit/foundation/util/ListSupport.java +++ b/src/main/java/cokr/xit/foundation/util/ListSupport.java @@ -32,8 +32,8 @@ public class ListSupport { */ public static List asList(Iterable iterable) { return iterable == null ? Collections.emptyList() : - iterable instanceof List ? - (List)iterable : + iterable instanceof List list ? + list : StreamSupport.stream(iterable.spliterator(), false).toList(); } diff --git a/src/main/java/cokr/xit/foundation/web/AbstractController.java b/src/main/java/cokr/xit/foundation/web/AbstractController.java index 529fe54..6b6d49d 100644 --- a/src/main/java/cokr/xit/foundation/web/AbstractController.java +++ b/src/main/java/cokr/xit/foundation/web/AbstractController.java @@ -142,6 +142,7 @@ public abstract class AbstractController extends AbstractComponent { * @return ModelAndView */ protected ModelAndView setCollectionInfo(ModelAndView mav, Collection collection, String prefixKey, String prefix) { + boolean toJson = !"jsonView".equals(mav.getViewName()); mav.addObject(prefixKey, prefix) .addObject(prefix + "List", collection) .addObject(prefix + "Start", 0) @@ -173,8 +174,7 @@ public abstract class AbstractController extends AbstractComponent { * @return ModelAndView */ protected ModelAndView setPagingInfo(ModelAndView mav, Collection collection, String prefix) { - if (collection instanceof BoundedList) { - BoundedList bounded = (BoundedList)collection; + if (collection instanceof BoundedList bounded) { Map map = Map.of( "start", bounded.getStart(), "totalSize", bounded.getTotalSize(), diff --git a/src/main/java/cokr/xit/foundation/web/DownloadView.java b/src/main/java/cokr/xit/foundation/web/DownloadView.java index cf0dc92..4d9f9b5 100644 --- a/src/main/java/cokr/xit/foundation/web/DownloadView.java +++ b/src/main/java/cokr/xit/foundation/web/DownloadView.java @@ -20,8 +20,7 @@ import cokr.xit.foundation.Downloadable; public class DownloadView extends AbstractView { public static String getFilename(Map model) { Object obj = model.get("download"); - if (obj instanceof Downloadable) { - Downloadable downloadable = (Downloadable)obj; + if (obj instanceof Downloadable downloadable) { return downloadable.getFilename(); } return null; diff --git a/src/main/java/cokr/xit/foundation/web/WebClient.java b/src/main/java/cokr/xit/foundation/web/WebClient.java index 53ea8b2..236fc7c 100644 --- a/src/main/java/cokr/xit/foundation/web/WebClient.java +++ b/src/main/java/cokr/xit/foundation/web/WebClient.java @@ -551,8 +551,7 @@ public class WebClient { byteList.add(separator); Object value = entry.getValue(); - if (value instanceof Path) { - Path path = (Path)value; + if (value instanceof Path path) { String mimeType = Files.probeContentType(path); byteList.add(("\"" + entry.getKey() + "\"; filename=\"" + path.getFileName() + "\"\r\nContent-Type: " + mimeType + "\r\n\r\n").getBytes(charset)); byteList.add(Files.readAllBytes(path));