Changeset 18503


Ignore:
Timestamp:
2009-02-11T15:44:57+13:00 (15 years ago)
Author:
oranfry
Message:

whitespace fixes

Location:
greenstone3/trunk/src/java/org/greenstone/gsdl3/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/util/OID.java

    r16869 r18503  
    2626   
    2727    /** returns everything up to the first dot
    28     if no dot, returns oid */
     28      if no dot, returns oid */
    2929    public static String getTop(String oid) {
    30     int pos = oid.indexOf('.');
    31     if (pos == -1) {
    32         return oid;
    33     }
    34     return oid.substring(0, pos);
    35    
     30      int pos = oid.indexOf('.');
     31      if (pos == -1) {
     32          return oid;
     33      }
     34      return oid.substring(0, pos);
     35     
    3636    }
    3737    /** returns true is oid is top level (ie has no dots)
    3838     returns false for an empty oid */
    3939    public static boolean isTop(String oid) {
    40     if (oid.equals("")) {
    41         return false;
    42     }
    43     return (oid.indexOf('.')==-1);
     40      if (oid.equals("")) {
     41          return false;
     42      }
     43      return (oid.indexOf('.')==-1);
    4444    }
    45    
     45     
    4646    /** returns the parent of oid (everything up to last dot)
    4747     returns oid if oid has no parent */
    4848    public static String getParent(String oid) {
    49     int pos = oid.lastIndexOf('.');
    50     if (pos == -1) {
    51         return oid;
    52     }
    53     return oid.substring(0, pos);
     49      int pos = oid.lastIndexOf('.');
     50      if (pos == -1) {
     51          return oid;
     52      }
     53      return oid.substring(0, pos);
    5454    }
    5555
    5656    /** returns the full name - replaces all " with parent */
    5757    public static String translateParent(String oid, String parent) {
    58     return oid.replaceAll("\"", parent);
     58      return oid.replaceAll("\"", parent);
    5959    }
    6060    /** does the opposite to translate_parent */
    6161    public static String shrinkParent(String oid) {
    62     int pos = oid.lastIndexOf('.');
    63     if (pos==-1) return oid;
    64     return "\""+oid.substring(pos);
     62      int pos = oid.lastIndexOf('.');
     63      if (pos==-1) return oid;
     64      return "\""+oid.substring(pos);
    6565    }
    6666    /** returns true if oid uses .fc, .lc, .pr, .ns, .ps .rt (root) .ss (specified sibling)*/
    6767    public static boolean needsTranslating(String oid) {
    68     if (oid.length()<4) return false;
    69     String tail = oid.substring(oid.length()-3);
    70     return (tail.equals(".fc") || tail.equals(".lc") ||
    71         tail.equals(".pr") || tail.equals(".ns") ||
    72         tail.equals(".ps") || tail.equals(".rt") ||
    73         tail.equals(".ss") || tail.equals(".np") ||
    74         tail.equals(".pp"));
     68      if (oid.length()<4) return false;
     69      String tail = oid.substring(oid.length()-3);
     70      return (tail.equals(".fc") || tail.equals(".lc") ||
     71            tail.equals(".pr") || tail.equals(".ns") ||
     72            tail.equals(".ps") || tail.equals(".rt") ||
     73            tail.equals(".ss") || tail.equals(".np") ||
     74            tail.equals(".pp"));
    7575    }
    7676    /** strips suffix from end */
    7777    public static String stripSuffix(String oid) {
    78     String tail = oid.substring(oid.length()-3);
    79     while (tail.equals(".fc") || tail.equals(".lc") ||
    80            tail.equals(".pr") || tail.equals(".ns") ||
    81            tail.equals(".ps") || tail.equals(".ss") ||
    82            tail.equals(".np") || tail.equals(".pp") ||
    83            tail.equals(".rt") ) {
    84         if (tail.equals(".ss")) { // have doc.sibnum.ss
    85         oid = oid.substring(0, oid.length()-3);
    86         int pos = oid.lastIndexOf('.');
    87         //strip that too
    88         oid = oid.substring(0, pos);
    89         }
    90         oid = oid.substring(0, oid.length()-3);
    91         tail = oid.substring(oid.length()-3);
    92     }
    93    
    94     return oid;
     78      String tail = oid.substring(oid.length()-3);
     79      while (tail.equals(".fc") || tail.equals(".lc") ||
     80             tail.equals(".pr") || tail.equals(".ns") ||
     81             tail.equals(".ps") || tail.equals(".ss") ||
     82             tail.equals(".np") || tail.equals(".pp") ||
     83             tail.equals(".rt") ) {
     84          if (tail.equals(".ss")) { // have doc.sibnum.ss
     85            oid = oid.substring(0, oid.length()-3);
     86            int pos = oid.lastIndexOf('.');
     87            //strip that too
     88            oid = oid.substring(0, pos);
     89          }
     90          oid = oid.substring(0, oid.length()-3);
     91          tail = oid.substring(oid.length()-3);
     92      }
     93     
     94      return oid;
    9595    }
    9696    /** returns true if child is a child of parent
    9797     an oid is not a child of itself */
    9898    public static boolean isChildOf(String parent, String child) {
    99     if (parent.equals(child)) {
    100         return false;
    101     }
    102     return child.startsWith(parent);
     99      if (parent.equals(child)) {
     100          return false;
     101      }
     102      return child.startsWith(parent);
    103103    }
    104104}
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/util/OIDTest.java

    r16869 r18503  
    3737
    3838    public OIDTest(String name) {
    39     super(name);
     39      super(name);
    4040    }
    4141
    4242    /** test suite that dynamically runs all the tests */
    4343    public static Test suite() {
    44     return new TestSuite(OIDTest.class);
     44      return new TestSuite(OIDTest.class);
    4545    }
    4646
    4747    public void testGetTop() {
    48    
    49     assertEquals(oid1, OID.getTop(oid1));
    50     assertEquals(oid1, OID.getTop(oid2));
    51     assertEquals(empty, OID.getTop(empty));
     48      assertEquals(oid1, OID.getTop(oid1));
     49      assertEquals(oid1, OID.getTop(oid2));
     50      assertEquals(empty, OID.getTop(empty));
    5251    }
    5352 
    5453    public void testIsTop() {
    55     assertTrue(!OID.isTop(empty));
    56     assertTrue(OID.isTop(oid1));
    57     assertTrue(!OID.isTop(oid2));
     54      assertTrue(!OID.isTop(empty));
     55      assertTrue(OID.isTop(oid1));
     56      assertTrue(!OID.isTop(oid2));
    5857    }
    5958
    6059    public void testGetParent() {
    61 
    62     assertEquals(empty, OID.getParent(oid1));
    63     assertEquals(oid1, OID.getParent(oid2));
    64     assertEquals(empty, OID.getParent(empty));
    65    
     60      assertEquals(empty, OID.getParent(oid1));
     61      assertEquals(oid1, OID.getParent(oid2));
     62      assertEquals(empty, OID.getParent(empty));
    6663    }
    6764
    6865    public void testTranslateParent() {
    69     String short_id = "\".1";
    70     assertEquals(oid2, OID.translateParent(short_id, oid1));
    71     // should return the original oid if its not a shortened form
    72     assertEquals(oid2, OID.translateParent(oid2, oid1));
    73    
     66      String short_id = "\".1";
     67      assertEquals(oid2, OID.translateParent(short_id, oid1));
     68      // should return the original oid if its not a shortened form
     69      assertEquals(oid2, OID.translateParent(oid2, oid1));
    7470    }
    7571
    7672    public void testShrinkParent() {
    77     String short_oid2 = "\".1";
    78     String short_oid3 = "\".2";
     73      String short_oid2 = "\".1";
     74      String short_oid3 = "\".2";
    7975
    80     assertEquals(oid1, OID.shrinkParent(oid1));
    81     assertEquals(short_oid2, OID.shrinkParent(oid2));
    82     assertEquals(short_oid3, OID.shrinkParent(oid3));
     76      assertEquals(oid1, OID.shrinkParent(oid1));
     77      assertEquals(short_oid2, OID.shrinkParent(oid2));
     78      assertEquals(short_oid3, OID.shrinkParent(oid3));
    8379    }
    8480
    8581    public void testNeedsTranslating() {
    86     assertTrue(!OID.needsTranslating(oid1));
    87     assertTrue(!OID.needsTranslating(oid2));
    88     assertTrue(OID.needsTranslating(oidfc));
    89     assertTrue(OID.needsTranslating(oidlc));
    90     assertTrue(OID.needsTranslating(oidpr));
    91     assertTrue(OID.needsTranslating(oidns));
    92     assertTrue(OID.needsTranslating(oidps));
     82      assertTrue(!OID.needsTranslating(oid1));
     83      assertTrue(!OID.needsTranslating(oid2));
     84      assertTrue(OID.needsTranslating(oidfc));
     85      assertTrue(OID.needsTranslating(oidlc));
     86      assertTrue(OID.needsTranslating(oidpr));
     87      assertTrue(OID.needsTranslating(oidns));
     88      assertTrue(OID.needsTranslating(oidps));
    9389
    9490    }
    9591
    9692    public void testStripSuffix() {
    97     assertEquals(oid1, OID.stripSuffix(oidfc));
    98     assertEquals(oid1, OID.stripSuffix(oidlc));
    99     assertEquals(oid1, OID.stripSuffix(oidpr));
    100     assertEquals(oid1, OID.stripSuffix(oidns));
    101     assertEquals(oid1, OID.stripSuffix(oidps));
     93      assertEquals(oid1, OID.stripSuffix(oidfc));
     94      assertEquals(oid1, OID.stripSuffix(oidlc));
     95      assertEquals(oid1, OID.stripSuffix(oidpr));
     96      assertEquals(oid1, OID.stripSuffix(oidns));
     97      assertEquals(oid1, OID.stripSuffix(oidps));
    10298    }
    10399
    104100    public void testIsChildOf() {
    105     assertTrue(OID.isChildOf(oid1, oid2));
    106     assertTrue(OID.isChildOf(oid1, oid3));
    107     assertTrue(OID.isChildOf(oid2, oid3));
    108     assertTrue(!OID.isChildOf(oid3, oid1));
    109     assertTrue(!OID.isChildOf(oid1, oid1));
     101      assertTrue(OID.isChildOf(oid1, oid2));
     102      assertTrue(OID.isChildOf(oid1, oid3));
     103      assertTrue(OID.isChildOf(oid2, oid3));
     104      assertTrue(!OID.isChildOf(oid3, oid1));
     105      assertTrue(!OID.isChildOf(oid1, oid1));
    110106    }
    111107
Note: See TracChangeset for help on using the changeset viewer.