+++ /dev/null
-/*--------------------------------------------------------------------------\r
- * Copyright 2004 Taro L. Saito\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *--------------------------------------------------------------------------*/\r
-//--------------------------------------\r
-// XerialJ\r
-//\r
-// ECN.java\r
-// Since: 2005/09/09 10:53:52\r
-//\r
-// $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/main/java/org/xerial/util/xml/index/ECN.java $\r
-// $Author: leo $\r
-//--------------------------------------\r
-package org.xerial.util.xml.index;\r
-\r
-import java.util.Vector;\r
-\r
-import org.xerial.util.Algorithm;\r
-import org.xerial.util.MinMax;\r
-\r
-/**\r
- * This class implements the Extensible Composite Number (ECN).\r
- * @author leo\r
- *\r
- */\r
-public class ECN implements Comparable<ECN>\r
-{\r
- private Vector<Character> val = new Vector<Character>();\r
- \r
- public ECN()\r
- {\r
-\r
- }\r
- \r
- public ECN(String stringRepresentation)\r
- {\r
- String[] composite = stringRepresentation.split("\\.");\r
- for(String c : composite)\r
- {\r
- int v = Integer.valueOf(c);\r
- val.add((char) v);\r
- }\r
- }\r
- \r
- /**\r
- * @param i 8bit\92l\r
- */\r
- public void add(int i)\r
- {\r
- val.add((char)i);\r
- }\r
-\r
- /**\r
- * ECN\82Ì\92l\82ð\94ä\8ar\r
- * @param other\r
- * @return \95\89\82È\82çthis\82Ì\82Ù\82¤\82ª\8f¬\82³\82¢\81B\82O\82È\82ç\93\99\82µ\82¢\81B\90³\82È\82çother\82Ì\95û\82ª\91å\82«\82¢\r
- */\r
- public int compareTo(ECN other)\r
- {\r
- MinMax<Integer> minmax = Algorithm.minmax(this.size(), other.size());\r
- for(int i=0; i<minmax.min(); ++i)\r
- {\r
- int cmp = val.get(i) - other.get(i);\r
- if(cmp != 0)\r
- return cmp;\r
- }\r
- // \8ec\82è\82Ì\83R\83\93\83|\83W\83b\83g\82ª0\88È\8fã\82©\82Ç\82¤\82©\92²\82×\82é\r
- ECN largerECN = this.size() > other.size() ? this : other;\r
- for(int i=minmax.min(); i<minmax.max(); ++i)\r
- {\r
- int cmp = largerECN.get(i);\r
- if(cmp != 0)\r
- return cmp;\r
- }\r
- return 0;\r
- }\r
-\r
- /**\r
- * ECN\82Ì\92·\82³\82ð\95Ô\82·\r
- * @return ECN\82Ì\92·\82³\r
- */\r
- public int size() \r
- {\r
- return val.size();\r
- }\r
- \r
- /**\r
- * @param index \r
- * @return index\82Ì\88Ê\92u\82Ìcomposite\82ð\95Ô\82·\r
- */\r
- public int get(int index)\r
- {\r
- return val.get(index);\r
- }\r
- \r
-}\r