-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created enum Region.java to retrieve Regions without doing request. #4309
Merged
andreamlin
merged 6 commits into
googleapis:master
from
charlesliqlogic:gcp-static-region
Jan 10, 2019
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32a47d2
Created enum Region.java to retrieve Regions without doing request.
charlesliqlogic 34fe386
update comments
charlesliqlogic e39a7d1
added unit test for Region enum
charlesliqlogic 915a99b
add space between methods and move instance variables after all stati…
charlesliqlogic 2672520
update test case name
charlesliqlogic 2a2cf8b
rename enum Region to Regions for IDE autocomplete and readability pu…
charlesliqlogic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
google-cloud-clients/google-cloud-compute/src/main/java/com/google/cloud/compute/Region.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.cloud.compute; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Enumeration of Regions. | ||
* | ||
* @see <a href="https://cloud.google.com/compute/docs/regions-zones/">Regions and Zones</a> | ||
*/ | ||
public enum Region { | ||
ASIA_EAST1("asia-east1", new String[] {"asia-east1-a", "asia-east1-b", "asia-east1-c"}), | ||
ASIA_EAST2("asia-east2", new String[] {"asia-east2-a", "asia-east2-b", "asia-east2-c"}), | ||
ASIA_NORTHEAST1( | ||
"asia-northeast1", | ||
new String[] {"asia-northeast1-a", "asia-northeast1-b", "asia-northeast1-c"}), | ||
ASIA_SOUTH1("asia-south1", new String[] {"asia-south1-a", "asia-south1-b", "asia-south1-c"}), | ||
ASIA_SOUTHEAST1( | ||
"asia-southeast1", | ||
new String[] {"asia-southeast1-a", "asia-southeast1-b", "asia-southeast1-c"}), | ||
AUSTRALIA_SOUTHEAST1( | ||
"australia-southeast1", | ||
new String[] {"australia-southeast1-a", "australia-southeast1-b", "australia-southeast1-c"}), | ||
EUROPE_NORTH1( | ||
"europe-north1", new String[] {"europe-north1-a", "europe-north1-b", "europe-north1-c"}), | ||
EUROPE_WEST1("europe-west1", new String[] {"europe-west1-b", "europe-west1-c", "europe-west1-d"}), | ||
EUROPE_WEST2("europe-west2", new String[] {"europe-west2-a", "europe-west2-b", "europe-west2-c"}), | ||
EUROPE_WEST3("europe-west3", new String[] {"europe-west3-a", "europe-west3-b", "europe-west3-c"}), | ||
EUROPE_WEST4("europe-west4", new String[] {"europe-west4-a", "europe-west4-b", "europe-west4-c"}), | ||
NORTHAMERICA_NORTHEAST1( | ||
"northamerica-northeast1", | ||
new String[] { | ||
"northamerica-northeast1-a", "northamerica-northeast1-b", "northamerica-northeast1-c" | ||
}), | ||
SOUTHAMERICA_EAST1( | ||
"southamerica-east1", | ||
new String[] {"southamerica-east1-a", "southamerica-east1-b", "southamerica-east1-c"}), | ||
US_CENTRAL1( | ||
"us-central1", | ||
new String[] {"us-central1-a", "us-central1-b", "us-central1-c", "us-central1-f"}), | ||
US_EAST1("us-east1", new String[] {"us-east1-b", "us-east1-c", "us-east1-d"}), | ||
US_EAST4("us-east4", new String[] {"us-east4-a", "us-east4-b", "us-east4-c"}), | ||
US_WEST1("us-west1", new String[] {"us-west1-a", "us-west1-b", "us-west1-c"}), | ||
US_WEST2("us-west2", new String[] {"us-west2-a", "us-west2-b", "us-west2-c"}); | ||
|
||
private static final Map<String, Region> REGIONS = new HashMap<>(); | ||
|
||
static { | ||
for (Region region : Region.values()) { | ||
REGIONS.put(region.name, region); | ||
} | ||
} | ||
|
||
private final String name; | ||
private final String[] zones; | ||
|
||
private Region(String name, String[] zones) { | ||
this.name = name; | ||
this.zones = zones; | ||
} | ||
|
||
/** The name of this region. */ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** The zones of this region. */ | ||
andreamlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public String[] getZones() { | ||
return zones; | ||
} | ||
|
||
/** | ||
* Returns a region enum corresponding to the given region name. | ||
* | ||
* @param regionName The name of the region. | ||
* @return Region enum representing the given region name, or a null if there is no Region enum | ||
* that is representing the given region name. | ||
*/ | ||
public static Region fromName(String regionName) { | ||
return REGIONS.get(regionName); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...cloud-clients/google-cloud-compute/src/test/java/com/google/cloud/compute/RegionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.cloud.compute; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class RegionTest { | ||
@Test | ||
public void fromName_null_returnNull() { | ||
andreamlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Assert.assertNull(Region.fromName(null)); | ||
} | ||
|
||
@Test | ||
public void fromName_empty_returnNull() { | ||
Assert.assertNull(Region.fromName("")); | ||
} | ||
|
||
@Test | ||
public void fromName_invalid_returnNull() { | ||
Assert.assertNull(Region.fromName("mars")); | ||
} | ||
|
||
@Test | ||
public void fromName_valid_returnRegion() { | ||
Assert.assertEquals(Region.ASIA_EAST1, Region.fromName("asia-east1")); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.