From c13e6e20bc3d2fa82b7115cc5b08e46b9ce93285 Mon Sep 17 00:00:00 2001 From: Alasdair Hodge Date: Wed, 21 Dec 2011 12:59:59 +0000 Subject: [PATCH] Use varargs for tags() to make life easier for callers; preserve tag order for easier unit testing --- .../cloudsigma/options/CloneDriveOptions.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java index 9cef0740ce..fcb59d2cd5 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/options/CloneDriveOptions.java @@ -21,6 +21,7 @@ package org.jclouds.cloudsigma.options; import static com.google.common.base.Preconditions.checkArgument; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -61,16 +62,18 @@ public class CloneDriveOptions { return this; } - public CloneDriveOptions tags(Iterable tags) { + public CloneDriveOptions tags(String... tags) { // Affinity is conveyed using regular tags; make sure to preserve any already-set affinity tag. String currentTagsString = options.remove("tags"); Set currentTags = (currentTagsString == null) ? new HashSet() : - Sets.newHashSet(Splitter.on(' ').split(currentTagsString)); + Sets.newLinkedHashSet(Splitter.on(' ').split(currentTagsString)); - Set newTags = Sets.newHashSet(tags); - if (currentTags.contains(SSD_AFFINITY_TAG)) { + Set newTags = new LinkedHashSet(); + for (String tag : tags) + newTags.add(tag); + + if (currentTags.contains(SSD_AFFINITY_TAG)) newTags.add(SSD_AFFINITY_TAG); - } options.put("tags", Joiner.on(' ').join(newTags)); return this; @@ -83,8 +86,8 @@ public class CloneDriveOptions { public CloneDriveOptions affinity(AffinityType affinity) { // Affinity is conveyed using regular tags; make sure to avoid multiple affinity tags in the options. String currentTagsString = options.remove("tags"); - Set tags = (currentTagsString == null) ? new HashSet() : - Sets.newHashSet(Splitter.on(' ').split(currentTagsString)); + Set tags = (currentTagsString == null) ? new LinkedHashSet() : + Sets.newLinkedHashSet(Splitter.on(' ').split(currentTagsString)); switch (affinity) { // SSD affinity is conveyed as a special tag: "affinity:ssd". @@ -117,7 +120,7 @@ public class CloneDriveOptions { /** * @see CloneDriveOptions#tags */ - public static CloneDriveOptions tags(Iterable tags) { + public static CloneDriveOptions tags(String... tags) { CloneDriveOptions options = new CloneDriveOptions(); return options.tags(tags); }