-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BucketTagsSet common XML root element added (#182)
- Loading branch information
1 parent
38bf9a5
commit 2d5fe75
Showing
6 changed files
with
144 additions
and
159 deletions.
There are no files selected for viewing
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
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
74 changes: 74 additions & 0 deletions
74
src/main/java/com/emc/ecs/management/sdk/model/BucketTagSetRootElement.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,74 @@ | ||
package com.emc.ecs.management.sdk.model; | ||
|
||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlElementWrapper; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@XmlRootElement | ||
public class BucketTagSetRootElement { | ||
|
||
private static final String KEY = "key"; | ||
private static final String VALUE = "value"; | ||
|
||
@XmlElementWrapper(name = "TagSet") | ||
@XmlElement(name = "Tag") | ||
private List<BucketTag> TagSet; | ||
|
||
public BucketTagSetRootElement(){}; | ||
|
||
public BucketTagSetRootElement(List<Map<String, String>> tags) { | ||
super(); | ||
setTagSetAsListOfMaps(tags); | ||
} | ||
|
||
public List<BucketTag> getTagSet() { | ||
return TagSet; | ||
} | ||
|
||
public void setTagSet(List<BucketTag> tagSet) { | ||
TagSet = tagSet; | ||
} | ||
|
||
public List<Map<String, String> > getTagSetAsListOfTags() { | ||
List<Map<String, String> > list = new ArrayList<Map<String, String> >(); | ||
for (BucketTag tag: TagSet) { | ||
Map<String, String> map = new HashMap<String, String>() {{ | ||
put(KEY, tag.getKey()); | ||
put(VALUE, tag.getValue()); | ||
}}; | ||
list.add(map); | ||
} | ||
return list; | ||
} | ||
|
||
public void setTagSetAsListOfMaps(List<Map<String, String> > tags) throws IllegalArgumentException { | ||
List<BucketTag> tagList = new ArrayList<BucketTag>(); | ||
for (Map<String, String> tag: tags) { | ||
try { | ||
String key = tag.get(KEY); | ||
String value = tag.get(VALUE); | ||
tagList.add(new BucketTag(key, value)); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Key and Value should be specified for bucket tag", e); | ||
} | ||
} | ||
TagSet = tagList; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder output = new StringBuilder("{"); | ||
for (BucketTag tag: TagSet) { | ||
output.append(tag.toString()).append(", "); | ||
} | ||
int length = output.length(); | ||
if (length != 1) | ||
output.delete(length - 2, length); | ||
output.append("}"); | ||
return output.toString(); | ||
} | ||
} |
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
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
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