/
Region.java
177 lines (159 loc) · 6.93 KB
/
Region.java
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.management.resources.fluentcore.arm;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* Enumeration of the Azure datacenter regions. See https://azure.microsoft.com/regions/
*/
public final class Region {
// This needs to be at the beginning for the initialization to happen correctly
private static final Map<String, Region> VALUES_BY_NAME = new HashMap<>();
// CHECKSTYLE IGNORE Javadoc FOR NEXT 50 LINES
/**************************************************
* Azure Cloud - Americas
**************************************************/
public static final Region US_WEST = new Region("westus", "West US");
public static final Region US_WEST2 = new Region("westus2", "West US 2");
public static final Region US_CENTRAL = new Region("centralus", "Central US");
public static final Region US_EAST = new Region("eastus", "East US");
public static final Region US_EAST2 = new Region("eastus2", "East US 2");
public static final Region US_NORTH_CENTRAL = new Region("northcentralus", "North Central US");
public static final Region US_SOUTH_CENTRAL = new Region("southcentralus", "South Central US");
public static final Region US_WEST_CENTRAL = new Region("westcentralus", "West Central US");
public static final Region CANADA_CENTRAL = new Region("canadacentral", "Canada Central");
public static final Region CANADA_EAST = new Region("canadaeast", "Canada East");
public static final Region BRAZIL_SOUTH = new Region("brazilsouth", "Brazil South");
/**************************************************
* Azure Cloud - Europe
**************************************************/
public static final Region EUROPE_NORTH = new Region("northeurope", "North Europe");
public static final Region EUROPE_WEST = new Region("westeurope", "West Europe");
public static final Region UK_SOUTH = new Region("uksouth", "UK South");
public static final Region UK_WEST = new Region("ukwest", "UK West");
/**************************************************
* Azure Cloud - Asia
**************************************************/
public static final Region ASIA_EAST = new Region("eastasia", "East Asia");
public static final Region ASIA_SOUTHEAST = new Region("southeastasia", "South East Asia");
public static final Region JAPAN_EAST = new Region("japaneast", "Japan East");
public static final Region JAPAN_WEST = new Region("japanwest", "Japan West");
public static final Region AUSTRALIA_EAST = new Region("australiaeast", "Australia East");
public static final Region AUSTRALIA_SOUTHEAST = new Region("australiasoutheast", "Australia Southeast");
public static final Region INDIA_CENTRAL = new Region("centralindia", "Central India");
public static final Region INDIA_SOUTH = new Region("southindia", "South India");
public static final Region INDIA_WEST = new Region("westindia", "West India");
public static final Region KOREA_CENTRAL = new Region("koreacentral", "Korea Central");
public static final Region KOREA_SOUTH = new Region("koreasouth", "Korea South");
/**************************************************
* Azure China Cloud
**************************************************/
public static final Region CHINA_NORTH = new Region("chinanorth", "China North");
public static final Region CHINA_EAST = new Region("chinaeast", "China East");
/**************************************************
* Azure German Cloud
**************************************************/
public static final Region GERMANY_CENTRAL = new Region("germanycentral", "Germany Central");
public static final Region GERMANY_NORTHEAST = new Region("germanynortheast", "Germany Northeast");
/**************************************************
* Azure Government Cloud
**************************************************/
public static final Region GOV_US_VIRGINIA = new Region("usgovvirginia", "US Gov Virginia");
public static final Region GOV_US_IOWA = new Region("usgoviowa", "US Gov Iowa");
private final String name;
private final String label;
/**
* @return predefined Azure regions
*/
public static Region[] values() {
Collection<Region> valuesCollection = VALUES_BY_NAME.values();
return valuesCollection.toArray(new Region[valuesCollection.size()]);
}
private Region(String name, String label) {
this.name = name;
this.label = label;
VALUES_BY_NAME.put(name.toLowerCase(), this);
}
/**
* Creates a region from a name and a label.
*
* @param name the uniquely identifiable name of the region
* @param label the label of the region
* @return the newly created region
*/
public static Region create(String name, String label) {
Region region = VALUES_BY_NAME.get(name.toLowerCase());
if (region != null) {
return region;
} else {
return new Region(name, label);
}
}
@JsonValue
@Override
public String toString() {
return name();
}
/**
* @return the name of the region
*/
public String name() {
return this.name;
}
/**
* @return the label of the region
*/
public String label() {
return this.label;
}
/**
* Finds a region based on a label or name.
* <p>
* A region name is lower-cased label with spaces removed.
* @param labelOrName the region name or label
* @return the found region or null if there's no such region
*/
public static Region findByLabelOrName(String labelOrName) {
if (labelOrName == null) {
return null;
}
return VALUES_BY_NAME.get(labelOrName.toLowerCase().replace(" ", ""));
}
/**
* Parses a name into a Region object and creates a new Region instance if not found among the existing ones.
*
* @param name a region name
* @return the parsed or created region
*/
public static Region fromName(String name) {
if (name == null) {
return null;
}
Region region = VALUES_BY_NAME.get(name.toLowerCase().replace(" ", ""));
if (region != null) {
return region;
} else {
return Region.create(name.toLowerCase().replace(" ", ""), name);
}
}
@Override
public int hashCode() {
return this.name.hashCode();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Region)) {
return false;
} else if (obj == this) {
return true;
} else {
Region rhs = (Region) obj;
return this.name.equalsIgnoreCase(rhs.name);
}
}
}