001 // Copyright 2007 Waterken Inc. under the terms of the MIT X license 002 // found at http://www.opensource.org/licenses/mit-license.html 003 package org.waterken.bounce; 004 005 import static org.ref_send.promise.Eventual.ref; 006 007 import java.io.Serializable; 008 import java.math.BigDecimal; 009 import java.math.BigInteger; 010 011 import org.joe_e.Struct; 012 import org.joe_e.array.BooleanArray; 013 import org.joe_e.array.ByteArray; 014 import org.joe_e.array.CharArray; 015 import org.joe_e.array.ConstArray; 016 import org.joe_e.array.DoubleArray; 017 import org.joe_e.array.FloatArray; 018 import org.joe_e.array.ImmutableArray; 019 import org.joe_e.array.IntArray; 020 import org.joe_e.array.LongArray; 021 import org.joe_e.array.PowerlessArray; 022 import org.joe_e.array.ShortArray; 023 import org.ref_send.promise.Deferred; 024 import org.ref_send.promise.Eventual; 025 import org.ref_send.promise.Promise; 026 import org.ref_send.promise.Receiver; 027 import org.ref_send.promise.Vat; 028 029 /** 030 * A {@link Wall} implementation. 031 */ 032 public final class 033 Bounce { 034 private Bounce() {} 035 036 /** 037 * Constructs an instance. 038 * @param _ eventual operator 039 */ 040 static public Wall 041 make(final Eventual _) { 042 final Deferred<Boolean> d = _.defer(); 043 final Receiver<Boolean> normal = d.resolver; 044 final Promise<Boolean> p = ref(false); 045 class WallX extends Struct implements Wall, Serializable { 046 static private final long serialVersionUID = 1L; 047 048 public Promise<ConstArray<AllTypes>> 049 getAll() { 050 return ref(ConstArray.array(new AllTypes( 051 BooleanArray.array(true, false), 052 CharArray.array('a', '\"', '\\', '<', '>', '/', '\b', 053 '\f', '\n', '\r', '\t', '\u0085'), 054 FloatArray.array(0.0F, 055 Float.MAX_VALUE, Float.MIN_VALUE, 056 -Float.MAX_VALUE, -Float.MIN_VALUE, 057 Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 058 Float.NaN), 059 DoubleArray.array(0.0, 060 Double.MAX_VALUE, Double.MIN_VALUE, 061 -Double.MAX_VALUE, -Double.MIN_VALUE, 062 Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 063 Double.NaN), 064 ByteArray.array((byte)0, Byte.MAX_VALUE, Byte.MIN_VALUE), 065 ShortArray.array((short)0, Short.MAX_VALUE,Short.MIN_VALUE), 066 IntArray.array(0, Integer.MAX_VALUE, Integer.MIN_VALUE), 067 LongArray.array(0L, 1L << 53, -(1L << 53)), 068 "a \" \\ / </ < > \b \f \n \r \t \u0085", 069 ConstArray.array(normal, null), 070 ConstArray.array(d.promise, p), 071 ConstArray.array(new Vat<Deferred<?>>(d, normal)), 072 ConstArray.array( 073 ImmutableArray.array(PowerlessArray.array(true)), 074 10, 075 BigInteger.TEN, 076 new BigDecimal("3.14") 077 )))); 078 } 079 080 public <A> Promise<A> 081 bounce(final A a) { return ref(a); } 082 083 public Promise<Integer> 084 sum(int... num) { 085 int total = 0; 086 for (int a : num) { 087 total += a; 088 } 089 return ref(total); 090 } 091 } 092 return new WallX(); 093 } 094 }