Skip to content

Instantly share code, notes, and snippets.

package seqtest;
//メイン処理。
public class Main {
private static final int TASK_COUNT = 1000000;
public static void main(String[] argv) {
// 非同期タスクたちを順番に実行させる。
SequentialAsyncTask[] tasks = new SequentialAsyncTask[TASK_COUNT];
@ryoasai
ryoasai / gist:1178781
Created August 29, 2011 16:34
Print a numerical value in bit pattern.
public class BinaryStringPrinter {
public static void print(byte value) {
System.out.println(zeroPadding(8, Integer.toBinaryString(value)));
}
public static void print(short value) {
System.out.println(zeroPadding(16, Integer.toBinaryString(value)));
}
@ryoasai
ryoasai / gist:1040238
Created June 22, 2011 14:43
Adding destructive String operation.
String.metaClass.destructiveReverse << {
def chars = delegate.value;
chars.eachWithIndex {e, i ->
chars[- i - 1] = e
}
}
def s = 'groovy'
s.destructiveReverse()
assert s == 'yvoorg'
@ryoasai
ryoasai / gist:953075
Created May 3, 2011 09:39
Spring's bean property access and conversion tests.
package com.github.ryoasai;
import java.util.Date;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.joda.time.DateMidnight;
import org.springframework.format.annotation.DateTimeFormat;
@ryoasai
ryoasai / gist:952819
Created May 3, 2011 04:35
Spring's TypeDescriptor cannot resolve parameterized property type.
package com.github.ryoasai;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.util.List;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.springframework.beans.BeanWrapper;
@ryoasai
ryoasai / gist:948627
Created April 29, 2011 17:06
You can instantiate an inner class without an enclosing instance.
import java.lang.reflect.*;
public class Outer {
private String outer = "outer";
public class Inner {
public void hello() {
System.out.println("Hello World" + outer); // NullPointerException at this line.
}
@ryoasai
ryoasai / gist:946477
Created April 28, 2011 14:43
Spring TypeDescriptor test.
package com.github.ryoasai;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ryoasai
ryoasai / gist:890851
Created March 28, 2011 17:06
Object.getClass() return type.
import java.util.ArrayList;
import java.util.List;
/**
* <p>Demonstrating why the Object.getClass() method's return type should be
* Class<? extends |T|> but not Class<? extends T>, where |T| is the erasure
* of the static type T. </p>
* <p>
* Type parameter of every Class instance should always be reifiable type
* or wildcard type with reifiable upper bound.
@ryoasai
ryoasai / gist:888253
Created March 26, 2011 12:45
Various Java5 type patterns to demonstrate generics reflection API.
import static org.junit.Assert.*;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.List;
@ryoasai
ryoasai / gist:878041
Created March 20, 2011 03:29
Java's Type API sample showing how to obtain the actual type of parameterized type.
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
public class GenericTypeSample {
public List<Integer>[] testField;
public static void main(String[] args) throws Exception {