You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.7 KiB
98 lines
2.7 KiB
package com.zc.business.enums;
|
|
|
|
import lombok.Getter;
|
|
|
|
/**
|
|
* 通道拥挤度等级枚举
|
|
* @author xiepufeng
|
|
*/
|
|
@Getter
|
|
public enum ChannelCongestionLevelEnum {
|
|
|
|
/**
|
|
* 表示通道畅通,速度阈值为70 km/h
|
|
*/
|
|
FLOWING(70, 0, "畅通"),
|
|
|
|
/**
|
|
* 表示通道基本畅通,速度阈值为50 km/h
|
|
*/
|
|
BASIC_FLOWING(50, 0, "基本畅通"),
|
|
|
|
/**
|
|
* 表示通道轻度拥堵,速度阈值为40 km/h
|
|
*/
|
|
LIGHT_CONGESTION(40, 1000, "轻度拥堵"),
|
|
|
|
/**
|
|
* 表示通道中度拥堵,速度阈值为20 km/h
|
|
*/
|
|
MEDIUM_CONGESTION(20, 2000, "中度拥堵"),
|
|
|
|
/**
|
|
* 使用负数作为默认值,表示无限小,始终小于其他速度阈值,表示通道严重拥堵
|
|
*/
|
|
SEVERE_CONGESTION(-1, 4000, "严重拥堵");
|
|
|
|
/**
|
|
* 速度阈值,用于判断通道拥挤程度
|
|
*/
|
|
private final int speedThreshold;
|
|
|
|
/**
|
|
* 默认的拥堵里程数
|
|
*/
|
|
private final int defaultCongestionDistance;
|
|
|
|
/**
|
|
* 对拥挤度等级的描述
|
|
*/
|
|
private final String description;
|
|
|
|
/**
|
|
* 构造函数,初始化通道拥挤度等级。
|
|
*
|
|
* @param speedThreshold 速度阈值
|
|
* @param description 等级描述
|
|
*/
|
|
ChannelCongestionLevelEnum(int speedThreshold, int defaultCongestionDistance, String description) {
|
|
this.speedThreshold = speedThreshold;
|
|
this.defaultCongestionDistance = defaultCongestionDistance;
|
|
this.description = description;
|
|
}
|
|
|
|
/**
|
|
* 根据给定速度,返回对应的通道拥挤度等级。
|
|
*
|
|
* @param speed 速度(单位:km/h)
|
|
* @return 对应的通道拥挤度等级
|
|
*/
|
|
public static ChannelCongestionLevelEnum fromSpeed(int speed) {
|
|
for (ChannelCongestionLevelEnum level : values()) {
|
|
if (speed > level.speedThreshold) {
|
|
return level;
|
|
}
|
|
}
|
|
return SEVERE_CONGESTION; // 若速度小于等于所有等级阈值,则视为严重拥堵
|
|
}
|
|
|
|
/**
|
|
* 判断速度是否是是中度拥堵或者严重拥堵
|
|
*/
|
|
public static boolean isMediumOrSevereCongestion(int speed) {
|
|
ChannelCongestionLevelEnum level = fromSpeed(speed);
|
|
return level == MEDIUM_CONGESTION || level == SEVERE_CONGESTION;
|
|
}
|
|
|
|
/**
|
|
* 判断给定速度是否属于指定的拥挤度等级。
|
|
*
|
|
* @param speed 速度(单位:km/h)
|
|
* @param level 拥挤度等级
|
|
* @return 如果速度属于该等级,返回true;否则返回false。
|
|
*/
|
|
public static boolean isWithinLevel(int speed, ChannelCongestionLevelEnum level) {
|
|
ChannelCongestionLevelEnum currentLevel = fromSpeed(speed);
|
|
return currentLevel == level;
|
|
}
|
|
}
|
|
|