com.spring.boxes.stream.Platform Maven / Gradle / Ivy
The newest version!
package com.spring.boxes.stream;
/**
* 平台类型
*/
public enum Platform {
/**
* iPhone / iOS 客户端
*/
iOS(1, "iOS"),
/**
* Android app客户端
*/
Android(2, "Android"),
/**
* h5
*/
H5(3, "H5"),
/**
* Web网页版
*/
Web(4, "Web"),
/**
* PC客户端
*/
PC(5, "PC"),
/**
* 微信小程序
*/
MiniProgram(6, "MiniProgram");
public static final int length = Platform.values().length;
private final int value;
private final String desc;
Platform(int value, String desc) {
this.value = value;
this.desc = desc;
}
/**
* 返回枚举值
*/
public int value() {
return this.value;
}
public String getDesc() {
return desc;
}
/**
* iOS, iPhone, Android都算作移动端
*/
public boolean isMobile() {
return (value == Platform.iOS.value || value == Platform.Android.value);
}
public boolean isIOS() {
return value == Platform.iOS.value;
}
public boolean isAndroid() {
return value == Platform.Android.value;
}
public boolean isMiniProgram() {
return value == Platform.MiniProgram.value;
}
/**
* 根据枚举值返回实例
*/
public static Platform of(int value) {
if (value >= 1 && value <= Platform.length) {
return Platform.values()[value - 1];
} else {
return null;
}
}
/**
* 根据枚举值返回实例
*/
public static Platform of(String desc) {
if (desc == null) {
return Platform.Web;
}
for (Platform platform : Platform.values()) {
if (platform.getDesc().equalsIgnoreCase(desc)) {
return platform;
}
}
if ("iPhone".equalsIgnoreCase(desc)) {
// 部分手机平台值是 iPhone,在这兼容到 iOS
return iOS;
}
return Platform.Web;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy