From 76f2e602ece8900433379228e8ab5487a84b7e02 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Tue, 5 Nov 2013 10:48:23 +0100 Subject: [PATCH] JCLOUDS-369: Added a new predicate to capture disk links Added a new predicate to capture disk links --- .../jclouds/abiquo/predicates/LinkPredicates.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java index 524fcfe..33c3314 100644 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java +++ b/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java @@ -18,7 +18,11 @@ import static com.google.common.base.Preconditions.checkNotNull; +import java.util.regex.Pattern; + import com.abiquo.model.rest.RESTLink; +import com.abiquo.server.core.infrastructure.network.NicDto; +import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; import com.google.common.base.Predicate; /** @@ -27,6 +31,10 @@ * @author Ignasi Barrera */ public class LinkPredicates { + + private static final Pattern IS_NIC_REL_PATTERN = Pattern.compile("^" + NicDto.REL_PREFIX + "[0-9]+$"); + private static final Pattern IS_DISK_REL_PATTERN = Pattern.compile("^" + VolumeManagementDto.REL_PREFIX + "[0-9]+$"); + public static Predicate rel(final String rel) { checkNotNull(rel, "rel must be defined"); return new Predicate() { @@ -41,8 +49,18 @@ public boolean apply(final RESTLink link) { return new Predicate() { @Override public boolean apply(final RESTLink link) { - return link.getRel().matches("^nic[0-9]+$"); + return IS_NIC_REL_PATTERN.matcher(link.getRel()).matches(); + } + }; + } + + public static Predicate isDisk() { + return new Predicate() { + @Override + public boolean apply(RESTLink link) { + return IS_DISK_REL_PATTERN.matcher(link.getRel()).matches(); } }; } + } -- 1.8.4