>           Map<String,Object> scalingPolicyMap = Maps.newHashMap();
>           scalingPoliciesList.add(scalingPolicyMap);
>           scalingPolicyMap.put("cooldown", scalingPolicy.getCooldown());
>           scalingPolicyMap.put("type", scalingPolicy.getType().toString());
>           scalingPolicyMap.put("name", scalingPolicy.getName());
>           // A couple of different scaling policies are supported, such as 
> percent or number based, or targeting specific numbers of instances
> -         scalingPolicyMap.put(scalingPolicy.getTargetType().toString(), 
> scalingPolicy.getTarget());
> +         String targetString = scalingPolicy.getTarget();
> +         Integer targetInt = Ints.tryParse(targetString);
> +         Float targetFloat;
> +         if (targetInt != null) {
> +            scalingPolicyMap.put(scalingPolicy.getTargetType().toString(), 
> targetInt);
> +         } else if ((targetFloat = Floats.tryParse(targetString)) != null) {
> +            scalingPolicyMap.put(scalingPolicy.getTargetType().toString(), 
> targetFloat);
> +         } else {
> +            scalingPolicyMap.put(scalingPolicy.getTargetType().toString(), 
> targetString);
> +         }

Hm...is there any way we could use polymorphism here? Each `TargetType` should 
_know_ how to correctly return its scaling value, no? Could we move the parsing 
logic in there and then reduce this to something like:
```
scalingPolicyMap.put(scalingPolicy.getTargetType().toString(), 
scalingPolicy.getTargetType().toValue(scalingPolicy.getTarget()));
```
or, indeed, have that on the scalingPolicy itself (since it should be able to 
access both the target type and value):
```
scalingPolicyMap.put(scalingPolicy.getTargetType().toString(), 
scalingPolicy.getTargetValue() // does the appropriate conversion);
```
?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/39/files#r7234823

Reply via email to