35. どうなってるの?
クイックソートのメインとなるメソッドです。
def quicksort(int[] a, int L, int R) {
int m = a[(L+R) >> 1]
int i=L
int j=R
while (i<=j) {
while (a[i]<m) i++
while (a[j]>m) j--
if (i<=j) {
swap(a, i, j)
i++
j--
}
}
if (L<j) quicksort(a,L,j)
if (R>i) quicksort(a,i,R)
}
36. どうなってるの?
@Typed 付けない場合です。
public Object quicksort(int a[], int L, int R) {
CallSite acallsite[] = $getCallSiteArray();
Integer m = (Integer)ScriptBytecodeAdapter.castToType(acallsite[19].call(a, acallsite[20].call(acallsite[21].call(DefaultTypeTransformation.box(L), DefaultTypeTransformation.box(R)), $const$3)), $get$$class$java$lang$Integer());
Integer i = (Integer)ScriptBytecodeAdapter.castToType(DefaultTypeTransformation.box(L), $get$$class$java$lang$Integer());
Integer j = (Integer)ScriptBytecodeAdapter.castToType(DefaultTypeTransformation.box(R), $get$$class$java$lang$Integer());
do {
if(!ScriptBytecodeAdapter.compareLessThanEqual(i, j))
break;
while(ScriptBytecodeAdapter.compareLessThan(acallsite[22].call(a, i), m)) {
Integer integer = i;
i = ((Integer) (acallsite[23].call(i)));
Integer _tmp = integer;
}
while(ScriptBytecodeAdapter.compareGreaterThan(acallsite[24].call(a, j), m)) {
Integer integer1 = j;
j = ((Integer) (acallsite[25].call(j)));
Integer _tmp1 = integer1;
}
if(ScriptBytecodeAdapter.compareLessThanEqual(i, j)) {
acallsite[26].callCurrent(this, a, i, j);
Integer integer2 = i;
i = ((Integer) (acallsite[27].call(i)));
Integer _tmp2 = integer2;
integer2 = j;
j = ((Integer) (acallsite[28].call(j)));
Integer _tmp3 = integer2;
}
} while(true);
if(ScriptBytecodeAdapter.compareLessThan(DefaultTypeTransformation.box(L), j))
acallsite[29].callCurrent(this, a, DefaultTypeTransformation.box(L), j);
if(ScriptBytecodeAdapter.compareGreaterThan(DefaultTypeTransformation.box(R), i))
return acallsite[30].callCurrent(this, a, i, DefaultTypeTransformation.box(R));
else
return null;
}
37. どうなってるの?
@Typed 付けた場合です。
public Object quicksort(int a[], int L, int R) {
do {
int m = ArraysMethods.getAt(a, L + R >> 1);
int i = L;
int j = R;
do {
if(i > j)
break;
for(; ArraysMethods.getAt(a, i) < m; i++);
for(; ArraysMethods.getAt(a, j) > m; j--);
if(i <= j) {
swap(a, i, j);
i++;
j--;
}
} while(true);
if(L < j)
quicksort(a, L, j);
if(R > i) {
R = R;
L = i;
a = a;
this = this;
} else {
return null;
}
} while(true);
}
51. コンパイル時にエラー
Groovy は実行時にエラーになります。
Caught: groovy.lang.MissingMethodException: No signature of
method: java.lang.String.toStrings() is applicable for argument
types: () values: []
Possible solutions: toString(), toString(), toString(),
contains(java.lang.CharSequence), contains(java.lang.String),
substring(int)
at example.ex02.run(ex02.groovy:4)
58. アクセス修飾子
Groovy では private のプロパティ・メソッドもア
クセスできます。
package example
class Person {
private String name
private int age
public Person(String name, int age) {
this.name = name
this.age = age
}
private dump() {
println "name = ${name}, age = ${age}"
}
}
def p = new Person("Mike", 25)
p.dump()
59. アクセス修飾子
Groovy++ では
@Typed
package example
class Person {
private String name
private int age
public Person(String name, int age) {
this.name = name
this.age = age
}
private dump() {
println "name = ${name}, age = ${age}"
}
}
def p = new Person("Mike", 25)
p.dump()