본문 바로가기

Java24

[JAVA] Thread-safe collections(동기화된 콜렉션 선언) 리스트 private List forceInsertItemCdList = Collections.synchronizedList(new ArrayList()); 내부 코드 /** * Returns a synchronized (thread-safe) list backed by the specified * list. In order to guarantee serial access, it is critical that * all access to the backing list is accomplished * through the returned list. * * It is imperative that the user manually synchronize on the returned * list when itera.. 2024. 2. 15.
모든 HTML 태그 제거하는 정규식 String regex = "]*>?";// 모든 HTML 태그 제거하는 정규식 String html = "~~~나나나나누나나나"; println(html.replaceAll(regex, ""); >> ~~~나나나나누나나나 2023. 5. 18.
method를 찾고 invoke 하는 함수 작업하다 사용하지 않을 것 같아서 코드만 여기에 정리. package com.gsretail.pbu.common.util; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import com.gsretail.pbu.common.exception.BusinessException; import com.gsretail.pbu.common.status.ErrorEnum; public class MethodUtils { /** * obj의 name 메소드를 찾아 .. 2023. 1. 5.
Java8 Bigdecimal 지수 표현 제거 8.124E-7 이 있을 때, Double로 파싱 > new Bigdecimal() 생성 안됨 기타 다른 서칭 답안들 안됨 Bigdecimal.toPlainString() 됨 eg) Bigdecimal b = 8.124E-7; b.toPlainString() 2022. 11. 28.
try ~ catch의 inline, outline 사이에 exception이 발생하는 case 기본 베이스 코드 fun inline() { try { throw Exception("inline exception") throw NullPointerException("inline exception") } catch(e: NullPointerException) { println("inline에서 null pointer exception발생!!") } catch(e: Exception){ println("inline에서 exception발생!!") } } @Test fun outline() { try { inline() } catch(e: NullPointerException) { println("outline에서 null pointer exception발생!!") } catch(e: Exception).. 2020. 7. 15.
Commons-lang Commons Lang Commons Lang란 Commons-Lang은 java.lang에 있는 클래스처럼 기능적으로 필요한 유틸리티들을 모아놓은 클래스들의 집합입니다. 아마도 여러분들 역시 직접 유틸리티 클래스들을 만들어 사용하고 있을겁니다. 즉 코딩을 하다보면 이렇거 있었으면 좋겠다 싶은것들이 Commons Lang에 다 있다고 생각하시면 됩니다 II. 다운로드 및 설치 http://jakarta.apache.org/site/downloads/downloads_commons-lang.cgi 에서 다운받자! 설치는 각 어플리케이션의 클래스 패스에 복사합니다. III. org.apache.commons.lang.SystemUtils SystemUtils는 java.lang.System 클래스 처럼 시스.. 2020. 1. 31.
log4j의 logback.xml에 로그 저장경로를 os별로 다르게 하고 싶을 때(janino) log4j는 기본적으로 실행 패키지 안에 logback.xml 파일을 읽게 되어있다. 자동으로 읽기 때문에 크로스 플랫폼을 지원하는 애플리케이션의 경우 해당 파일에 경로를 os별로 구분해야 했다. 처음 아이디어는 build.gradle에 설정을 추가하여 os별로 xml파일을 구분하여 복사하고 빌드하는 것이었는데... 별로 좋지 않은 것 같아 logback.xml에 설정할 수 있는 방법이 있는지 찾아보았다. janino plugin log4j에만 해당되는지는 모르겠으나, xml에 if condition문을 사용할 수 있게 하는 플러그인을 찾았다. 설정은 아래 링크를 참조 https://mvnrepository.com/artifact/org.codehaus.janino/janino Maven Reposito.. 2020. 1. 30.
isEmpty()와 isBlank()의 차이 둘은 언뜻 같아보이지만 다르다. 결론부터 말하면 isBlank는 공백을 true로 판단하고 Empty는 공백도 false로 판단한다. 값(value) isEmpty() isBlank() null true true "" true true " " false true "sdnfi" false false " sdnfi " false false 둘 사이의 동작방식 차이는 무얼까? isEmpty를 살펴보자. public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract { returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } null 혹은 .. 2019. 9. 9.
replace()에서 replacement parameter로 File.separator를 사용할 때 character to be escaped is missing String을 replace() 해야할 때 File.separator를 사용할 때 character to be escaped is missing 메세지를 볼 수 있을 것이다. 아마도 윈도우 환경에서만 발생할 것이고, 원인은 File.separator가 '\'를 반환하는데 \가 escape문자이기 때문에 발생한다. 예를 들면 \를 문자로 사용하기 위해서는 \\, /를 쓰기 위해서는 \/ 이런식으로 특수문자를 쓰는데 사용되는 문자인데 \만 단독으로 사용되니 문제가 발생하는 것이다. 근데 에러 메세지도 그렇고 내부를 찾아봐도 if (nextChar == '\\') { cursor++; if (cursor == replacement.length()) throw new IllegalArgumentException.. 2019. 7. 29.