+++ /dev/null
-/* Copyright (c) 2009 Peter Troshin\r
- * \r
- * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 \r
- * \r
- * This library is free software; you can redistribute it and/or modify it under the terms of the\r
- * Apache License version 2 as published by the Apache Software Foundation\r
- * \r
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
- * License for more details.\r
- * \r
- * A copy of the license is in apache_license.txt. It is also available here:\r
- * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
- * \r
- * Any republication or derived work distributed in source code form\r
- * must include this copyright and license notice.\r
- */\r
-\r
-package compbio.engine.conf;\r
-\r
-import javax.management.openmbean.InvalidKeyException;\r
-\r
-import compbio.util.Util;\r
-\r
-@Deprecated\r
-public final class _Key {\r
-\r
- public final static String DELIM = "#";\r
-\r
- private final String cname;\r
- private final long id;\r
-\r
- public _Key(Class<?> clazz) {\r
- if (clazz == null) {\r
- throw new IllegalArgumentException("Class or Id is NULL");\r
- }\r
- this.cname = clazz.getSimpleName();\r
- this.id = getNonRepeatableNumber();\r
- }\r
-\r
- _Key(Class<?> clazz, long id) {\r
- if (clazz == null) {\r
- throw new IllegalArgumentException("Class or Id is NULL");\r
- }\r
- this.cname = clazz.getSimpleName();\r
- this.id = id;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj == null) {\r
- return false;\r
- }\r
- _Key ckey = null;\r
- if (obj instanceof _Key) {\r
- ckey = (_Key) obj;\r
- } else {\r
- return false;\r
- }\r
- if (ckey.cname.equals(this.cname) && id == ckey.id) {\r
- return true;\r
- }\r
- return false;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return cname + DELIM + id;\r
- }\r
-\r
- /*\r
- * id = 533411011589881 - 15 or 16 chars depending on the OS\r
- * \r
- * @see java.lang.Object#hashCode()\r
- */\r
- @Override\r
- public int hashCode() {\r
- return new Integer(cname.hashCode()\r
- * new Integer(new Long(id).toString().substring(9))).intValue();\r
- }\r
-\r
- static long getNonRepeatableNumber() {\r
- // Keep the random number 2 digits wide to simplify the task Id parsing\r
- // if required\r
- // The random value is concatenated with time value not added to it and\r
- // then converted to long.\r
- return Long.parseLong(Util.getRandomNumber(10, 99) + ""\r
- + System.nanoTime());\r
- }\r
-\r
- public static _Key parse(String key) {\r
- if (Util.isEmpty(key)) {\r
- throw new NullPointerException("Key must be provided!");\r
- }\r
- if (!key.contains(DELIM)) {\r
- throw new InvalidKeyException("Key " + key\r
- + " is not a valid task id");\r
- }\r
-\r
- int idx = key.indexOf(DELIM);\r
- if (idx < 0) {\r
- throw new InvalidKeyException("Key " + key\r
- + " is not a valid task id");\r
- }\r
- String runnerName = key.substring(0, idx);\r
- long id = 0;\r
- Class<?> runner = null;\r
- try {\r
- runner = Class.forName(runnerName);\r
- id = Long.parseLong(key.substring(idx + 1));\r
- } catch (NumberFormatException e) {\r
- throw new InvalidKeyException("Key " + key\r
- + " is not a valid task id");\r
- } catch (ClassNotFoundException e) {\r
- throw new InvalidKeyException("Key " + key\r
- + " is not a valid task id");\r
- }\r
- return new _Key(runner, id);\r
- }\r
-\r
-}\r