// ** This class was generated with DemFGen (vers:02/27/2009) package gen; import edu.neu.ccs.demeterf.demfgen.lib.*; import edu.neu.ccs.demeterf.*; /** Representation of Customer */ public class Customer{ public final Wallet wallet; public final Apartment apartment; /** Construct a(n) Customer Instance */ public Customer(Wallet wallet, Apartment apartment){ this.wallet = wallet; this.apartment = apartment; } /** Is the given Customer Equal to this one? */ public boolean equals(Object o){ if(!(o instanceof Customer))return false; Customer oo = (Customer)o; return (((Object)wallet).equals(oo.wallet))&&(((Object)apartment).equals(oo.apartment)); } /** Parse an instance of Customer from the given String */ public static Customer parse(String inpt) throws ParseException{ return new TheParser(new java.io.StringReader(inpt)).parse_Customer(); } /** Parse an instance of Customer from the given Stream */ public static Customer parse(java.io.InputStream inpt) throws ParseException{ return new TheParser(inpt).parse_Customer(); } /** Parse an instance of Customer from the given Reader */ public static Customer parse(java.io.Reader inpt) throws ParseException{ return new TheParser(inpt).parse_Customer(); } /** Field Class for Customer.wallet */ public static class wallet extends edu.neu.ccs.demeterf.control.Fields.any{} /** Field Class for Customer.apartment */ public static class apartment extends edu.neu.ccs.demeterf.control.Fields.any{} public int moneyAvailableLoD0 () { // most structure-shy return new Traversal(new TUCombiner(){ Integer combine(Money a){return a.v;} public Integer combine(){return 0;} public Integer fold(Integer a, Integer b){return a+b;} }). traverse(this); } public int moneyAvailableLoD1 () { // most structure-shy return new Traversal(new ID(){ int combine(Money a, int v){return v;} int combine(Object a, int v){return v;} int combine(Object a){return 0;} int combine(Object c, int w, int a){ return w+a;} }). traverse(this); } public int moneyAvailableLoD2 () { // less structure-shy but wrong return new Traversal(new ID(){ int combine(Money a, int v){return v;} int combine(Object a, int v){return v;} int combine(Object a){return 0;} int combine(Apartment a, int k, int b){return k+b;} int combine(Customer c, int w, int a){ return w+a;} }). traverse(this); } public int moneyAvailableLoD3 () { // less structure-shy but correct: 2 part explicit return new Traversal(new ID(){ int combine(Money a, int v){return v;} int combine(Object a, int v){return v;} int combine(Object a){return 0;} int combine(Bedrooms bs, int p, int c){return p+c;} int combine(Apartment a, int k, int b){return k+b;} int combine(Customer c, int w, int a){ return w+a;} }). traverse(this); } public int moneyAvailableLoD4 () { // less structure-shy: 1 and 2 part explicit // this can be generated return new Traversal(new ID(){ int combine(Money a, int v){return v;} // int combine(Object a, int v){return v;} int combine(KitchenCabinet a, int v){return v;} int combine(Bedroom a, int v){return v;} int combine(Mattress a, int v){return v;} int combine(Wallet a, int v){return v;} int combine(Kitchen a, int v){return v;} int combine(Bathroom a){return 0;} // only addition needed for Bedrooms int combine(Bedrooms bs, int p, int c){return p+c;} int combine(Apartment a, int k, int b){return k+b;} int combine(Customer c, int w, int a){ return w+a;} }). traverse(this); } // create an entirely new apartment! public Customer getPayment(final int m){ // only reach "legal" money objects return new Traversal(new Bc() { int toPay = m; Money combine(Money a, int v){ int r; // return money left if (toPay > v) { toPay = toPay-v; r = 0; } else {r = v - toPay; toPay = 0;} Main.p(" still to pay " + toPay + "\n"); return new Money(r); } /* Money combine(Money m, int v) { if (v>toPay) { toPay=0; Main.p(" still to pay " + toPay + "\n"); return new Money(v-toPay); } else { toPay -= v; Main.p(" still to pay " + toPay + "\n"); return new Money(0); } } */ }). traverse(this); } /** DGP method from Class Display */ public String display(){ return gen.Display.DisplayM(this); } /** DGP method from Class Print */ public String print(){ return gen.Print.PrintM(this); } /** DGP method from Class ToStr */ public String toStr(){ return gen.ToStr.ToStrM(this); } }