From a7cefce58cdb0f7f2d0868a1d5ee2f24f3890646 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 22 Sep 2014 16:01:18 +0200 Subject: ItemPath.fromUUIDString unnecessary as ItemPath(String) supports both plain UUIDs and an /entity prefix. Tightened that up and removed the fromUUIDString method for a simpler API. Also switched AgentPath(String) to a path argument for consistency. New AgentPaths should be created with AgentPath(new ItemPath(), String) instead. --- src/main/java/com/c2kernel/lookup/ItemPath.java | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/main/java/com/c2kernel/lookup/ItemPath.java') diff --git a/src/main/java/com/c2kernel/lookup/ItemPath.java b/src/main/java/com/c2kernel/lookup/ItemPath.java index 793a0ed..befbfff 100644 --- a/src/main/java/com/c2kernel/lookup/ItemPath.java +++ b/src/main/java/com/c2kernel/lookup/ItemPath.java @@ -11,6 +11,7 @@ package com.c2kernel.lookup; import java.nio.ByteBuffer; +import java.util.Arrays; import java.util.UUID; import com.c2kernel.common.ObjectNotFoundException; @@ -51,17 +52,21 @@ public class ItemPath extends Path public ItemPath(String path) throws InvalidItemPathException { super(path, Path.CONTEXT); + if (path == null) throw new InvalidItemPathException("Path cannot be null"); getSysKeyFromPath(); } private void getSysKeyFromPath() throws InvalidItemPathException { - if (mPath.length > 0) { + if (mPath.length == 1) { try { setSysKey(UUID.fromString(mPath[0])); + mType = Path.ENTITY; } catch (IllegalArgumentException ex) { throw new InvalidItemPathException(mPath[0]+" is not a valid UUID"); } } + else + throw new InvalidItemPathException("Not a valid item path: "+Arrays.toString(mPath)); } // EntityPaths root in /entity @@ -85,27 +90,20 @@ public class ItemPath extends Path protected void setSysKey(UUID uuid) { mUUID = uuid; - mPath = new String[1]; - mPath[0] = mUUID.toString(); mSysKey = new SystemKey(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()); - mType = Path.ENTITY; + setPathFromUUID(mUUID.toString()); } protected void setSysKey(SystemKey sysKey) { mSysKey = sysKey; mUUID = new UUID(sysKey.msb, sysKey.lsb); - mPath = new String[1]; - mPath[0] = mUUID.toString(); - mType = Path.ENTITY; + setPathFromUUID(mUUID.toString()); } - public static ItemPath fromUUIDString(String uuid) throws InvalidItemPathException { - if (uuid == null) throw new InvalidItemPathException("Null uuid"); - try { - return new ItemPath(UUID.fromString(uuid)); - } catch (IllegalArgumentException ex) { - throw new InvalidItemPathException("Illegal uuid: "+uuid); - } + private void setPathFromUUID(String uuid) { + mPath = new String[1]; + mPath[0] = uuid; + mType = Path.ENTITY; } } -- cgit v1.2.3