Skip to content

Instantly share code, notes, and snippets.

View debop's full-sized avatar

Sunghyouk Bae debop

View GitHub Profile
@debop
debop / ScalaTestToolTest.scala
Last active December 10, 2015 22:08
run unit as parallel
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))
@debop
debop / Parallels.java
Created January 10, 2013 14:31
병렬로 프로그래밍 실행하기
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);
@debop
debop / Parallels.java
Created January 11, 2013 10:01
병렬 실행
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 {
@debop
debop / ParallelsTest.java
Created January 11, 2013 10:05
Parallels Test Code
@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>() {
@debop
debop / ScalaDayOfWeek.scala
Created January 13, 2013 09:03
DayOfWeek
package kr.kth.timeperiod
import org.joda.time.DateTimeConstants
/**
* 한 주의 요일을 표현합니다.
* User: sunghyouk.bae@gmail.com
* Date: 13. 1. 13.
*/
object ScalaDayOfWeek extends Enumeration {
@debop
debop / ScalaDayOfWeekTest.scala
Created January 13, 2013 09:14
DayOfWeek Test Code
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: sunghyouk.bae@gmail.com
* Date: 13. 1. 13.
@debop
debop / ActivatorTool.java
Created January 19, 2013 09:48
Java Refelection으로 객채 생성
/**
* 지정된 수형의 새로운 인스턴스를 생성합니다.
*
* @param clazz 생성할 수형
* @param <T> 수형
* @return 지정한 수형의 새로운 인스턴스, 생성 실패시에는 null을 반환합니다.
*/
public static <T> T createInstance(Class<T> clazz) {
Guard.shouldNotBeNull(clazz, "clazz");
@debop
debop / ActivatorTool.java
Created January 19, 2013 09:50
Java reflection을 이용한 인스턴스 생성
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())
@debop
debop / ScalaReflects.scala
Created January 19, 2013 09:57
Scala reflection을 이용한 객체 생성
/**
* Generic 수형의 클래스에 대해 기본 생성자를 통한 인스턴스를 생성합니다.
*/
def newInstance[T: ClassTag](): T = {
classTag[T].runtimeClass.newInstance().asInstanceOf[T]
}
@debop
debop / ScalaReflects.scala
Created January 19, 2013 10:00
인자가 있는 동적 생성
/**
* 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]