Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 118   Methods: 8
NCLOC: 96   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
Language.java 40% 60,8% 75% 55,1%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.instance.data;
 11   
 
 12   
 import java.util.ArrayList;
 13   
 import java.util.Collections;
 14   
 import java.util.Enumeration;
 15   
 import java.util.Iterator;
 16   
 import java.util.List;
 17   
 import java.util.StringTokenizer;
 18   
 
 19   
 import org.jbind.xml.base.ILanguage;
 20   
 import org.jbind.xml.base.StringUtil;
 21   
 
 22   
 public class Language implements ILanguage {
 23   
 
 24  13
   public static Language createLanguage(String aString) {
 25  13
     if (StringUtil.containsWhiteSpace(aString)) {
 26  0
       return null;
 27   
     }
 28  13
     Enumeration e = new StringTokenizer(aString, "-");
 29  13
     if (!e.hasMoreElements()) {
 30  0
       return null;
 31   
     }
 32  13
     String pl = (String)e.nextElement();
 33  13
     if ((pl.length() < 1) || (pl.length() > 8)) {
 34  0
       return null;
 35   
     }
 36  13
     if (!e.hasMoreElements()) {
 37  1
       return new Language(pl, null, Collections.EMPTY_LIST);
 38   
     }
 39  12
     String cc = (String)e.nextElement();
 40  12
     if ((cc.length() < 1) || (cc.length() > 8)) {
 41  0
       return null;
 42   
     }
 43  12
     List l = new ArrayList();
 44  12
     while (e.hasMoreElements()) {
 45  0
       String s = (String)e.nextElement();
 46  0
       if ((s.length() < 1) || (s.length() > 8)) {
 47  0
         return null;
 48   
       }
 49  0
       l.add(s);
 50   
     }
 51  12
     return new Language(pl, cc, l);
 52   
   }
 53   
 
 54   
   private String myPrimaryLanguage = null;
 55   
   private String myCountryCode = null;
 56   
   private List mySubTags = null;
 57   
 
 58  13
   private Language(String aPrimaryLanguage, String aCountryCode, List aSubTags) {
 59  13
     myPrimaryLanguage = aPrimaryLanguage.toLowerCase();
 60  13
     myCountryCode = (null != aCountryCode) ? aCountryCode.toUpperCase() : null;
 61  13
     mySubTags = new ArrayList();
 62  13
     for (Iterator i = aSubTags.iterator(); i.hasNext(); ) {
 63  0
       mySubTags.add(((String)i.next()).toLowerCase());
 64   
     }
 65   
   }
 66   
 
 67  6
   public String getCountryCode() {
 68  6
     return myCountryCode;
 69   
   }
 70   
 
 71  3
   public String getPrimaryLanguage() {
 72  3
     return myPrimaryLanguage;
 73   
   }
 74   
 
 75  3
   public Iterator iterSubTags() {
 76  3
     return mySubTags.iterator();
 77   
   }
 78   
 
 79  0
   public String toString() {
 80  0
     StringBuffer sb = new StringBuffer(myPrimaryLanguage);
 81  0
     if (null != myCountryCode) {
 82  0
       sb.append("-").append(myCountryCode);
 83  0
       for (Iterator i = mySubTags.iterator(); i.hasNext(); ) {
 84  0
         sb.append("-").append(i.next());
 85   
       }
 86   
     }
 87  0
     return sb.toString();
 88   
   }
 89   
 
 90  3
   public boolean equals(Object anObject) {
 91  3
     boolean res = anObject instanceof ILanguage;
 92  3
     if (res) {
 93  3
       ILanguage l = (ILanguage)anObject;
 94  3
       res = myPrimaryLanguage.equals(l.getPrimaryLanguage());
 95  3
       if (res) {
 96  3
         res = ((null == myCountryCode) && (null == l.getCountryCode())) || ((null != myCountryCode) && myCountryCode.equals(l.getCountryCode()));
 97  3
         if (res) {
 98  3
           Iterator i1 = mySubTags.iterator();
 99  3
           Iterator i2 = l.iterSubTags();
 100  3
           while (i1.hasNext() && i2.hasNext() && res) {
 101  0
             res = i1.next().equals(i2.next());
 102   
           }
 103  3
           res &= !i1.hasNext() && !i2.hasNext();
 104   
         }
 105   
       }
 106   
     }
 107  3
     return res;
 108   
   }
 109   
 
 110  0
   public int hashCode() {
 111  0
     int res = myPrimaryLanguage.hashCode();
 112  0
     if (null != myCountryCode) {
 113  0
       res += myCountryCode.hashCode();
 114   
     }
 115  0
     return res;
 116   
   }
 117   
 }
 118