This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final val LowerBound: Int = 0 | |
private final val UpperBound: Int = 100000 | |
@Test | |
def runUnitAsParallelTest { | |
def runnable = { | |
(LowerBound to UpperBound).foreach { | |
i => Hero.findRoot(i) | |
} | |
log.debug("Unit: FindRoot({}) returns [{}]", UpperBound, Hero.findRoot(UpperBound)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T, V> List<V> run(final Iterable<T> elements, final Function1<T, V> function) { | |
shouldNotBeNull(elements, "elements"); | |
shouldNotBeNull(function, "function"); | |
ExecutorService executor = Executors.newFixedThreadPool(PROCESS_COUNT); | |
final List<V> results = new ArrayList<V>(); | |
if (log.isDebugEnabled()) | |
log.debug("작업을 병렬로 수행합니다. 작업 스레드 수=[{}]", PROCESS_COUNT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T, V> List<V> run(final Iterable<T> elements, final Function1<T, V> function) { | |
shouldNotBeNull(elements, "elements"); | |
shouldNotBeNull(function, "function"); | |
ExecutorService executor = Executors.newFixedThreadPool(getProcessCount()); | |
if (log.isDebugEnabled()) | |
log.debug("작업을 병렬로 수행합니다. 작업 스레드 수=[{}]", getProcessCount()); | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Slf4j | |
public class ParallelsTest { | |
private static final int LowerBound = 0; | |
private static final int UpperBound = 99999; | |
@Test | |
public void parallelRunAction() { | |
final Action1<Integer> action1 = | |
new Action1<Integer>() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kr.kth.timeperiod | |
import org.joda.time.DateTimeConstants | |
/** | |
* 한 주의 요일을 표현합니다. | |
* User: [email protected] | |
* Date: 13. 1. 13. | |
*/ | |
object ScalaDayOfWeek extends Enumeration { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kr.kth.timeperiod | |
import kr.kth.commons.slf4j.Logging | |
import org.junit.{Assert, Test} | |
import org.joda.time.DateTimeConstants | |
/** | |
* kr.kth.timeperiod.ScalaDayOfWeekTest | |
* User: [email protected] | |
* Date: 13. 1. 13. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 지정된 수형의 새로운 인스턴스를 생성합니다. | |
* | |
* @param clazz 생성할 수형 | |
* @param <T> 수형 | |
* @return 지정한 수형의 새로운 인스턴스, 생성 실패시에는 null을 반환합니다. | |
*/ | |
public static <T> T createInstance(Class<T> clazz) { | |
Guard.shouldNotBeNull(clazz, "clazz"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> T createInstance(Class<T> clazz) { | |
Guard.shouldNotBeNull(clazz, "clazz"); | |
if (log.isDebugEnabled()) | |
log.debug("수형 [{}] 의 새로운 인스턴스를 생성합니다...", clazz.getName()); | |
try { | |
return (T) clazz.newInstance(); | |
} catch (Exception e) { | |
if (log.isWarnEnabled()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generic 수형의 클래스에 대해 기본 생성자를 통한 인스턴스를 생성합니다. | |
*/ | |
def newInstance[T: ClassTag](): T = { | |
classTag[T].runtimeClass.newInstance().asInstanceOf[T] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generic 수형의 클래스에 대해 지정된 생성자 인자에 해당하는 생성자를 통해 인스턴스를 생성합니다. | |
*/ | |
def newInstance[T: ClassTag](initArgs: Any*): T = { | |
if (initArgs == null || initArgs.length == 0) | |
return newInstance[T]() | |
val parameterTypes = initArgs.map(getClass(_)).toArray | |
val constructor = classTag[T].runtimeClass.getConstructor(parameterTypes: _*) | |
constructor.newInstance(initArgs.map(_.asInstanceOf[AnyRef]): _*).asInstanceOf[T] |