The Parallel objects of PPL(Parallel Pattern Library).
Brief introduction of Concurrency::combinable class, example,
discussion
PPL(병렬 패턴 라이브러리)의 병렬 객체
Concurrency::combinable 클래스에 대한 간단한 소개, 예제, 여담
The Parallel objects of PPL(Parallel Pattern Library).
Brief introduction of Concurrency::combinable class, example,
discussion
PPL(병렬 패턴 라이브러리)의 병렬 객체
Concurrency::combinable 클래스에 대한 간단한 소개, 예제, 여담
스프링 컨테이너는 base-package의 클래스를 검색해서 자동으로 자바빈으로 등록하는데 이에 해당하는것이 @Component, @Repository, @Service, @Contoroller, @RestController 어노테이션이다.
자동스캔을 위해서는 <context:component-scan /> 과 같이 base-package를 기술하며, 패키지가 여럿인 경우, 콤마로 구분하여
기술한다.
The document discusses MapStruct, which is a code generation library that simplifies mapping between Java bean classes. It provides several features for mapping source objects to target objects, including:
1. Mapping fields with the same name automatically.
2. Mapping fields with different names using the @Mapping annotation.
3. Mapping to nested/child objects by composing mappings and using additional mappers.
4. Mapping collection properties like lists.
5. Updating an existing target object instance by mapping from a source object.
It demonstrates how to configure MapStruct and implement mappings between simple POJO classes to copy and transform data between them. The generated implementation code handles null checking and population of the
The document discusses MapStruct, an open-source code generation library that simplifies object mapping in Java. It provides examples of how to configure MapStruct for different mapping use cases, including: basic property mapping between objects with same property names; mapping to objects with different property names; mapping multiple source objects to a single target object; and mapping collections. The examples demonstrate how to define mappings using annotations and how MapStruct generates implementation classes to perform the mappings.
2. Content
1. 기본
2. Enum 원리
3. 코드 단순화
4. 서비스 호출
소스 : https://github.com/hyomee/JAVABASIC
3. 1. 기본
1. Class 처럼 사용 : enum
2. Class 내부에 enum 사용 : 내부 class처럼
3. enum의 생성자는 private
4. 관련 Method
- valueOf(String) : String값을 enum에서 가져옴
- valueOf(Class String) : 넘겨받은 class에서 String찾아, enum에 가져옴
- values() : enum의 요소들을 순서대로 enum타입의 배열로 리턴
관련이 있는 상수들의 집합으로 완전한 Class로 Enum 사용시 1. 코드가 단순해지고, 가독성이 좋아짐 2. 상수값의 타입 안정성이 보장(컴파일 시점
에 체크, 인스턴스 생성과 상속 방지) 3. 구도 의도가 열거형 임을 명확이 함
1. Class Type
public enum ClassTypeEnum {
NAC, SUS, RSP, CAN
}
2. Inner Class Type
public class InnerClassTypeEnum {
public enum EventCode {
NAC, SUS, RSP, CAN
}
}
public static void main(String[] args) {
// 열거형에 있는 요소 전체 참조
ClassTypeEnum[] enumValues = ClassTypeEnum.values();
Arrays.stream(enumValues).forEach(classTypeEnum -> System.out.println(classTypeEnum));
// 요소 검사
String compValue = "NAC";
if (Arrays.stream(enumValues).anyMatch(classTypeEnum-> compValue.equals(String.valueOf(classTypeEnum)))) {
System.out.print(compValue + " 는 존재 합니다.");
} else {
System.out.print(compValue + " 는 존재 하지 않습니다..");
};.
}
결과 :
NAC
SUS
RSP
CAN
NAC 는 존재 합니다.
public static void main(String[] args) {
InnerClassTypeEnum.EventCode[] eventCode = InnerClassTypeEnum.EventCode.values();
Arrays.stream(eventCode).forEach(code -> System.out.println(code));
}
결과 :
NAC
SUS
RSP
CAN
4. 2. Enum 원리
@Getter
public enum EventNm {
NAC("개통"),
SUS("일시정지"),
RSP("일시정지해제"),
CAN("해지");
private String eventNm;
EventNm(String eventNm) {
this.eventNm = eventNm;
}
}
public static void main(String[] args) {
InnerClassTypeEnum.EventNm eventNm = InnerClassTypeEnum.EventNm.valueOf("SUS");
System.out.print(eventNm.getEventNm());
}
1. 생성시점 : static 으로 생성 함 2. 값 취득
3. 실제 Value 얻음
일시정지
5. 3. 코드 단순, 가독성
여러 조건이 만족 하는 IF문과 같은 곳에서 코드가 단순해 지며, 가독성이 좋아 지며, 코드의 추가 시 업무 로직의 변경 없이 Enum 객체만 수정 하면 되므로 유지보수 입장
에서 보면 효과적임
public static enum ONLINE_RUNDTTM_PRCTYPE {
CYB, CAS, ARS, PPS, FCG, MNT;
}
If (Arrays.stream(SvcCodeVal.ONLINE_RUNDTTM_PRCTYPE.values())
.anyMatch(items -> String.valueOf(items).equals(prcType))) {
// 업무 로직
}
If (SVC_PRC_TYPE_CYB.equals(prcType) ||
SVC_PRC_TYPE_ CAS.equals(prcType) ||
SVC_PRC_TYPE_ ARS.equals(prcType) ||
SVC_PRC_TYPE_ PPS.equals(prcType) ||
SVC_PRC_TYPE_ FCG.equals(prcType) ||
SVC_PRC_TYPE_ MNT.equals(prcType)
// 업무 로직
}
public static final String SVC_PRC_TYPE_CYB = "CYB"; // Mylgt
public static final String SVC_PRC_TYPE_MOB = "MOB"; // 모바일고객센터
public static final String SVC_PRC_TYPE_FCG = "FCG"; // FCG
public static final String SVC_PRC_TYPE_ARS = "ARS"; // ARS
public static final String SVC_PRC_TYPE_CAS = "CAS"; // CAS
public static final String SVC_PRC_TYPE_VPM = "VPM"; // 음성비화 등록화면
public static final String SVC_PRC_TYPE_DEV = "DEV"; // 기기변경
public static final String SVC_PRC_TYPE_DOC = "DOC"; // 개통서류
6. 4. 서비스 호출
서비스 업무 로직
Enum 에서 서비스 호출
public interface EnumService {
String service1(String code);
String service2(String code);
}
@Service
class EnumServiceImpl implements EnumService {
@Override
public String service1(String code) {
return "nservice1:: service1";
}
@Override
public String service2(String code) {
return "nservice2:: service2";
}
}
EnumService service = new EnumServiceImpl();
InnerClassTypeEnum.EventServcie eventServcie = InnerClassTypeEnum.EventServcie.valueOf("NAC");
String vv = eventServcie.handleTask(service, "NAC");
System.out.print(vv);
public enum EventServcie {
NAC {
String handleTask(EnumService service, String code) {
return service.service1(code);
}
},
SUS {
String handleTask(EnumService service, String code) {
return service.service1(code);
}
};
abstract String handleTask(EnumService service, String code);
}