枚举类是我一直没有疏忽掉的东西,做了一个demo发现还是比较容易的。
例子:
PayType.java
/*
*Project Name: Woqi
* File Name: PayType.java
* Class Name: PayType
*
* Copyright 2014 Hengtian Software Inc
*
* Licensed under the Hengtiansoft
*
* http://www.hengtiansoft.com
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Description:
*
* @author bindizhang
*
*/
public enum PayType {
/** 资信支付 **/
credit_pay("资信支付", 0),
/** 网银 **/
E_bank_wap("银联支付", 1),
/** 线下支付 **/
under_pay("线下支付", 2),
/** 网银对公支付 **/
E_bank_pub("网银银联对公支付", 3),
/** ERP下单 **/
ERP_order("ERP下单", 4),
/** ERP充值 **/
ERP_add_credit("ERP充值", 5),
/** 支付宝 **/
alipay("支付宝", 6),
/** 财付通 **/
tenpay("财付通", 7),
/** 线下出账 **/
under_clear("线下出账", 8),
/*** 备用金 - 退款金额 **/
store_pay("退款金额", 9),
/** 在增加资信时,审核状态为待审核的时候,支付状态为待审核 **/
verify("待审核", 10);
private final String typeDesc;
private final Integer typePosition;
private PayType(String typeDesc, Integer typePosition) {
this.typeDesc = typeDesc;
this.typePosition = typePosition;
}
/**
* @return the typeDesc
*/
public String getTypeDesc() {
return typeDesc;
}
/**
* @return the typePosition
*/
public Integer getTypePosition() {
return typePosition;
}
public static PayType getPayTypeFromPosition(Integer position) {
PayType payType;
switch (position) {
case 0:
payType = credit_pay;
break;
case 1:
payType = E_bank_wap;
break;
case 2:
payType = under_pay;
break;
case 3:
payType = E_bank_pub;
break;
default:
payType = null;
}
return payType;
}
}
public class HelloEnum {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("helloworld");
System.out.println(PayType.alipay.getTypeDesc());
System.out.println(PayType.getPayTypeFromPosition(2).getTypeDesc());
System.out.println(PayType.getPayTypeFromPosition(3).getTypePosition());
}
}
测试结果
helloworld
支付宝
线下支付
3