guoshilong
2023-11-16 3823dc87eb8ef4d5cd25390ec9b17c856d10fafd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.dji.sample.map.model.enums;
 
import com.dji.sample.map.model.dto.ElementLineStringDTO;
import com.dji.sample.map.model.dto.ElementPointDTO;
import com.dji.sample.map.model.dto.ElementPolygonDTO;
import com.dji.sample.map.model.dto.ElementType;
 
import java.util.Optional;
 
/**
 * @author sean
 * @version 0.2
 * @date 2021/11/30
 */
public enum ElementTypeEnum {
 
    POINT(0, "Point"),
 
    LINE_STRING(1, "LineString"),
 
    POLYGON(2, "Polygon"),
 
    UNKNOWN(-1, "Unknown");
 
    private int val;
 
    private String desc;
 
    ElementTypeEnum(int val, String desc) {
        this.val = val;
        this.desc = desc;
    }
 
    public static Optional<ElementType> findType(int val) {
        if (POINT.val == val) {
            return Optional.of(new ElementPointDTO());
        }
 
        if (LINE_STRING.val == val) {
            return Optional.of(new ElementLineStringDTO());
        }
 
        if (POLYGON.val == val) {
            return Optional.of(new ElementPolygonDTO());
        }
 
        return Optional.empty();
    }
 
    public String getDesc() {
        return desc;
    }
 
    public static int findVal(String desc) {
        if (POINT.desc.equals(desc)) {
            return POINT.val;
        }
 
        if (LINE_STRING.desc.equals(desc)) {
            return LINE_STRING.val;
        }
 
        if (POLYGON.desc.equals(desc)) {
            return POLYGON.val;
        }
 
        return UNKNOWN.val;
    }
}