2 changed files with 312 additions and 246 deletions
@ -0,0 +1,55 @@ |
|||||
|
package com.zc.business.enums; |
||||
|
|
||||
|
import java.util.Optional; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
*/ |
||||
|
public enum LocationEnum { |
||||
|
CHANGQING_UNIVERSITY_CITY(1, "长清大学城"), |
||||
|
CHANGQING(2, "长清"), |
||||
|
XIAOLI(3, "孝里"), |
||||
|
PINGYIN_NORTH(4, "平阴北"), |
||||
|
PINGYIN(5, "平阴"), |
||||
|
PINGYIN_SOUTH(6, "平阴南"), |
||||
|
DONGPING(7, "东平"), |
||||
|
LIANGSHAN_EAST(8, "梁山东"), |
||||
|
LIANGSHAN(9, "梁山"), |
||||
|
JIAXIANG_WEST(10, "嘉祥西"); |
||||
|
|
||||
|
private final int order; |
||||
|
private final String name; |
||||
|
|
||||
|
LocationEnum(int order, String name) { |
||||
|
this.order = order; |
||||
|
this.name = name; |
||||
|
} |
||||
|
|
||||
|
public int getOrder() { |
||||
|
return order; |
||||
|
} |
||||
|
|
||||
|
public String getName() { |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
// 通过序号查找枚举值,未找到时返回null
|
||||
|
public static String findByOrder(int order) { |
||||
|
for (LocationEnum location : LocationEnum.values()) { |
||||
|
if (location.getOrder() == order) { |
||||
|
return location.getName(); |
||||
|
} |
||||
|
} |
||||
|
return " "; // 未找到匹配的枚举值
|
||||
|
} |
||||
|
|
||||
|
// 查找序号,通过地点名称
|
||||
|
public static int findOrderByName(String name) { |
||||
|
for (LocationEnum location : LocationEnum.values()) { |
||||
|
if (location.getName().equals(name)) { |
||||
|
return location.getOrder(); |
||||
|
} |
||||
|
} |
||||
|
return -1; // 未找到匹配的名称
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue