File: constants.go

package info (click to toggle)
android-platform-development 10.0.0%2Br36-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 135,564 kB
  • sloc: java: 160,253; xml: 127,434; python: 40,579; cpp: 17,579; sh: 2,569; javascript: 1,612; ansic: 879; lisp: 261; ruby: 183; makefile: 172; sql: 140; perl: 88
file content (77 lines) | stat: -rw-r--r-- 1,646 bytes parent folder | download | duplicates (5)
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
70
71
72
73
74
75
76
77
package constants

import (
	"fmt"

	"github.com/pkg/errors"
	"github.com/satori/go.uuid"
)

const (
	StatusIntact         = 1
	StatusDownstreamOnly = 2
	StatusModified       = 3
	StatusUpstream       = 4
	StatusForked         = 5
)

const (
	JobStatusNotStarted = "Not Started"
	JobStatusRunning    = "Running"
	JobStatusFailed     = "Failed"
	JobStatusComplete   = "Completed"
)

var StatusToDisplay = map[int]string{
	StatusIntact:         "Intact Projects",
	StatusDownstreamOnly: "Downstream Only Projects",
	StatusModified:       "Modified Projects",
	StatusUpstream:       "Upstream Only Projects",
	StatusForked:         "Forked Projects",
}

type ProjectType int

var Empty ProjectType = 0
var DifferentialSpecific ProjectType = 1
var Global ProjectType = 2

var ProjectTypeToDisplay = map[ProjectType]string{
	Empty:                "Empty",
	DifferentialSpecific: "Differential Specific",
	Global:               "Global",
}

var displayToStatus map[string]int

func makeDisplayToStatus() map[string]int {
	return invertMap(StatusToDisplay)
}

func GetStatusEnum(displayStatus string) (int, error) {
	if displayToStatus == nil {
		displayToStatus = makeDisplayToStatus()
	}
	val, ok := displayToStatus[displayStatus]
	if !ok {
		return 0, errors.New(
			fmt.Sprintf("No matching enum for %s", displayStatus),
		)
	}
	return val, nil
}

func invertMap(m map[int]string) map[string]int {
	inverted := make(map[string]int, len(m))
	for k := range StatusToDisplay {
		v := StatusToDisplay[k]
		inverted[v] = k
	}
	return inverted
}

func NullUUID() uuid.UUID {
	emptyBytes := make([]byte, 16)
	u, _ := uuid.FromBytes(emptyBytes)
	return u
}