JavaCat.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import java.util.*;
  2. public class JavaCat
  3. {
  4. public static int add1(int a)
  5. {
  6. return a + 1;
  7. }
  8. public static String add2(String a)
  9. {
  10. return a + '1';
  11. }
  12. public static char addChar(char a)
  13. {
  14. return ++a;
  15. }
  16. public static int testThrow(int a) throws Exception
  17. {
  18. throw new Exception("Exception from Java");
  19. }
  20. public static byte[] testData(byte [] indata)
  21. {
  22. indata[0]++;
  23. return indata;
  24. }
  25. public static int add(int a, int b)
  26. {
  27. return a + b;
  28. }
  29. public static long addL(int a, int b)
  30. {
  31. return a + b;
  32. }
  33. public static Integer addI(int a, int b)
  34. {
  35. return a + b;
  36. }
  37. public static float fadd(float a, float b)
  38. {
  39. System.out.print("fadd(");
  40. System.out.print(a);
  41. System.out.print(",");
  42. System.out.print(b);
  43. System.out.println(")");
  44. return a + b;
  45. }
  46. public static double dadd(double a, double b)
  47. {
  48. System.out.print("fadd(");
  49. System.out.print(a);
  50. System.out.print(",");
  51. System.out.print(b);
  52. System.out.println(")");
  53. return a + b;
  54. }
  55. public static Double daddD(double a, double b)
  56. {
  57. System.out.print("fadd(");
  58. System.out.print(a);
  59. System.out.print(",");
  60. System.out.print(b);
  61. System.out.println(")");
  62. return a + b;
  63. }
  64. public static String cat(String a, String b)
  65. {
  66. return a + b;
  67. }
  68. public static int testArrays(boolean[] b, short[] s, int[] i, double[] d)
  69. {
  70. return b.length + s.length + i.length + d.length;
  71. }
  72. public static String[] testStringArray(String[] in)
  73. {
  74. String t = in[0];
  75. in[0] = in[1];
  76. in[1] = t;
  77. return in;
  78. }
  79. public static class NestedClass
  80. {
  81. String ufield;
  82. public NestedClass(String s)
  83. {
  84. ufield = s;
  85. }
  86. public NestedClass()
  87. {
  88. }
  89. }
  90. boolean bfield;
  91. int ifield;
  92. long lfield;
  93. double dfield;
  94. float ffield;
  95. String sfield;
  96. char cfield1;
  97. String cfield2;
  98. NestedClass n;
  99. boolean bset[];
  100. byte [] dset[];
  101. String sset[];
  102. NestedClass sub[];
  103. public JavaCat(boolean b, int i, double d)
  104. {
  105. bfield = b;
  106. ifield = i;
  107. lfield = i * 100000000;
  108. dfield = d;
  109. ffield = (float) d;
  110. sfield = "Yoohoo";
  111. cfield1 = 'X';
  112. cfield2 = "Z";
  113. n = new NestedClass("nest");
  114. bset = new boolean [5];
  115. bset[3] = b;
  116. dset = new byte[1][];
  117. dset[0] = new byte[1];
  118. dset[0][0] = 14;
  119. sset = new String[1];
  120. sset[0] = "Hello";
  121. sub = new NestedClass[1];
  122. sub[0] = new NestedClass("subnest");
  123. }
  124. public JavaCat()
  125. {
  126. n = new NestedClass("nest2");
  127. }
  128. public static JavaCat returnrec(boolean b, int i, double d)
  129. {
  130. return new JavaCat(b,i,d);
  131. }
  132. public static String passrec(JavaCat j)
  133. {
  134. return j.n.ufield;
  135. }
  136. public static JavaCat transform(JavaCat in, int lim)
  137. {
  138. return new JavaCat(in.bfield, lim, in.dfield);
  139. }
  140. public static int passDataset(Iterator<JavaCat> d)
  141. {
  142. int sum = 0;
  143. while (d.hasNext())
  144. {
  145. JavaCat r = d.next();
  146. System.out.print(r.lfield);
  147. System.out.println("");
  148. sum += r.lfield;
  149. }
  150. return sum;
  151. }
  152. public static Iterator<JavaCat> passDataset2(JavaCat d[])
  153. {
  154. return Arrays.asList(d).iterator();
  155. }
  156. }