Java enum ile int değerleri eşleştirip kullanma kod örneği (Java enum and integer values usage code example)

package net.yazilimcity.mypack.lov;

import java.util.HashMap;
import java.util.Map;

public enum ActiveStatus {

	ACTIVE(1), 
	PASSIVE(-1);

	private int activeStatus;

	private static Map<Integer, ActiveStatus> map = new HashMap<Integer, ActiveStatus>();

	static {
		for (ActiveStatus activeStatusEnum : ActiveStatus.values()) {
			map.put(activeStatusEnum.activeStatus, activeStatusEnum);
		}
	}

	private ActiveStatus(final int active) {
		activeStatus = active;
	}

	public static ActiveStatus getOrdinal(int activeStatus) {
		return map.get(activeStatus);
	}
}

kullanımı ise aşağıdaki gibi mümkün olacaktır.

ActiveStatus.getOrdinal(rs.getInt(“is_active”))
ActiveStatus.getOrdinal(1)
ActiveStatus.getOrdinal(-1)

Share on Facebook0Tweet about this on TwitterShare on Google+0Share on StumbleUpon0Share on Reddit0

Leave a Reply


*