테스트

aion-server 4.8

Gitteol
최고관리자 · 1 · 💬 0 클론/새로받기
 4.8 61f661d · 1 commits 새로받기(Pull)
commons/src/com/aionemu/commons/configuration/PropertyTransformerFactory.java
package com.aionemu.commons.configuration;

import java.io.File;
import java.net.InetSocketAddress;
import java.time.ZoneId;
import java.util.Collection;
import java.util.TimeZone;
import java.util.regex.Pattern;

import org.quartz.CronExpression;

import com.aionemu.commons.configuration.transformers.ArrayTransformer;
import com.aionemu.commons.configuration.transformers.BooleanTransformer;
import com.aionemu.commons.configuration.transformers.CharTransformer;
import com.aionemu.commons.configuration.transformers.ClassTransformer;
import com.aionemu.commons.configuration.transformers.CollectionTransformer;
import com.aionemu.commons.configuration.transformers.CronExpressionTransformer;
import com.aionemu.commons.configuration.transformers.EnumTransformer;
import com.aionemu.commons.configuration.transformers.FileTransformer;
import com.aionemu.commons.configuration.transformers.InetSocketAddressTransformer;
import com.aionemu.commons.configuration.transformers.NumberTransformer;
import com.aionemu.commons.configuration.transformers.PatternTransformer;
import com.aionemu.commons.configuration.transformers.PropertyTransformer;
import com.aionemu.commons.configuration.transformers.StringTransformer;
import com.aionemu.commons.configuration.transformers.TimeZoneTransformer;
import com.aionemu.commons.configuration.transformers.ZoneIdTransformer;

/**
 * This class is responsible for creating property transformers. Uses shared instances to avoid overhead.
 * 
 * @author SoulKeeper, Neon
 */
public class PropertyTransformerFactory {

	/**
	 * @param targetType
	 *          The value type that strings should be transformed into.
	 * @return A shared instance of the {@link PropertyTransformer} that can transform strings into given targetType.
	 * @throws IllegalArgumentException
	 *           If there's no transformer for given target class.
	 */
	@SuppressWarnings("unchecked")
	public static <T> PropertyTransformer<T> getTransformer(Class<T> targetType) {
		if (Number.class.isAssignableFrom(NumberTransformer.toWrapper(targetType)))
			return (PropertyTransformer<T>) NumberTransformer.SHARED_INSTANCE;
		if (targetType == Boolean.class || targetType == Boolean.TYPE)
			return (PropertyTransformer<T>) BooleanTransformer.SHARED_INSTANCE;
		if (targetType == Character.class || targetType == Character.TYPE)
			return (PropertyTransformer<T>) CharTransformer.SHARED_INSTANCE;
		if (targetType == String.class)
			return (PropertyTransformer<T>) StringTransformer.SHARED_INSTANCE;
		if (targetType.isEnum())
			return (PropertyTransformer<T>) EnumTransformer.SHARED_INSTANCE;
		if (Collection.class.isAssignableFrom(targetType))
			return (PropertyTransformer<T>) CollectionTransformer.SHARED_INSTANCE;
		if (targetType.isArray())
			return (PropertyTransformer<T>) ArrayTransformer.SHARED_INSTANCE;
		if (targetType == File.class)
			return (PropertyTransformer<T>) FileTransformer.SHARED_INSTANCE;
		if (InetSocketAddress.class.isAssignableFrom(targetType))
			return (PropertyTransformer<T>) InetSocketAddressTransformer.SHARED_INSTANCE;
		if (targetType == Pattern.class)
			return (PropertyTransformer<T>) PatternTransformer.SHARED_INSTANCE;
		if (targetType == Class.class)
			return (PropertyTransformer<T>) ClassTransformer.SHARED_INSTANCE;
		if (TimeZone.class.isAssignableFrom(targetType))
			return (PropertyTransformer<T>) TimeZoneTransformer.SHARED_INSTANCE;
		if (ZoneId.class.isAssignableFrom(targetType))
			return (PropertyTransformer<T>) ZoneIdTransformer.SHARED_INSTANCE;
		if (targetType == CronExpression.class)
			return (PropertyTransformer<T>) CronExpressionTransformer.SHARED_INSTANCE;
		throw new IllegalArgumentException("Transformer for " + targetType.getSimpleName() + " is not implemented.");
	}
}

📎 첨부파일

댓글 작성 권한이 없습니다.
🏆 포인트 랭킹 TOP 10
순위 닉네임 포인트
1 no_profile 타키야겐지쪽지보내기 자기소개 아이디로 검색 전체게시물 102,949
2 no_profile 동가리쪽지보내기 자기소개 아이디로 검색 전체게시물 63,733
3 no_profile 라프텔쪽지보내기 자기소개 아이디로 검색 전체게시물 51,771
4 no_profile 불멸의행복쪽지보내기 자기소개 아이디로 검색 전체게시물 36,923
5 서번트쪽지보내기 자기소개 아이디로 검색 전체게시물 35,011
6 no_profile 닥터스쪽지보내기 자기소개 아이디로 검색 전체게시물 29,470
7 no_profile 검은고양이쪽지보내기 자기소개 아이디로 검색 전체게시물 29,077
8 no_profile Revolution쪽지보내기 자기소개 아이디로 검색 전체게시물 28,199
9 no_profile 보거스쪽지보내기 자기소개 아이디로 검색 전체게시물 26,731
10 no_profile 호롤롤로쪽지보내기 자기소개 아이디로 검색 전체게시물 17,020
알림 0