Java列挙の応用について
2451 ワード
package com.cnnct.zhk.balance.inaccountmanage.bpo.Recharge;
import com.cnnct.zhk.balance.inaccountmanage.bpo.Recharge.impl.BankCardRechargeImpl;
import com.cnnct.zhk.balance.inaccountmanage.bpo.Recharge.impl.CardRechargeImpl;
import com.cnnct.zhk.balance.inaccountmanage.bpo.Recharge.impl.CoBCRechargeImpl;
public enum PayWay {
MR(1), MRS(2), MS(3),MQ(4);
private final int title;
private PayWay(int t) {
title = t;
}
public IRecharge format() {
switch (title) {
case 4: case 1:
return new BankCardRechargeImpl();
case 3:
return new CardRechargeImpl();
case 2:
return new CoBCRechargeImpl();
default:
break;
}
return null;
}
};
package com.cnnct.zhk.balance.inaccountmanage.bpo.Recharge.impl;
import com.cnnct.zhk.balance.inaccountmanage.bpo.Recharge.IRecharge;
import com.cnnct.zhk.balance.inaccountmanage.bpo.Recharge.IRechargeFactory;
import com.cnnct.zhk.balance.inaccountmanage.bpo.Recharge.PayWay;
import com.cnnct.zhk.balance.inaccountmanage.entity.Recharge4DTO;
public class RechargeFactoryImpl implements IRechargeFactory {
@Override
public IRecharge getRecharge(Recharge4DTO dto) {
// TODO Auto-generated method stub
return null;
}
public static void main(String[] args) {
System.out.println(PayWay.MR.name());
System.out.println(PayWay.MR.name().getClass());
System.out.println(PayWay.MR.ordinal());
System.out.println(PayWay.MRS.ordinal());
System.out.println(PayWay.valueOf(PayWay.class, "MRS")+"##########");
PayWay p=PayWay.valueOf(PayWay.class, "MRS");
System.out.println(p.getClass()+"############");
System.out.println(p.name());
System.out.println(p.format());
switch (p) {
case MRS:
System.out.println(1);
break;
case MR:
System.out.println(1);
break;
case MS:
System.out.println(1);
break;
default:
System.out.println("no know");
break;
}
System.out.println(p.format());
}
}