Coverage report

  %line %branch
org.apache.jetspeed.om.impl.LocalizedFieldImpl
0% 
0% 

 1  
 /* 
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.om.impl;
 18  
 import java.util.Locale;
 19  
 
 20  
 import org.apache.jetspeed.om.common.LocalizedField;
 21  
 import org.apache.jetspeed.util.HashCodeBuilder;
 22  
 import org.apache.jetspeed.util.JetspeedLongObjectID;
 23  
 import org.apache.pluto.om.common.ObjectID;
 24  
 
 25  
 /**
 26  
  * LocalizedFieldImpl
 27  
  * <br/>
 28  
  * Implementation that represents a string value and the locale of that string
 29  
  * 
 30  
  * @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
 31  
  * @version $Id: LocalizedFieldImpl.java 516448 2007-03-09 16:25:47Z ate $
 32  
  *
 33  
  */
 34  
 public class LocalizedFieldImpl implements LocalizedField
 35  
 {
 36  
     protected String value;
 37  
     protected String name;
 38  
     protected Locale locale;
 39  
     
 40  
     protected long parentId;
 41  
     protected JetspeedLongObjectID id;
 42  
     
 43  
     public LocalizedFieldImpl()
 44  0
     {
 45  
         
 46  0
     }
 47  
     
 48  
     public LocalizedFieldImpl(Locale locale, String value)
 49  0
     {
 50  0
         this.locale = locale;
 51  0
         this.value = value;
 52  0
     }
 53  
 
 54  
     /* (non-Javadoc)
 55  
      * @see org.apache.jetspeed.om.common.LocalizedField#getLocale()
 56  
      */
 57  
     public Locale getLocale()
 58  
     {
 59  0
         return locale;
 60  
     }
 61  
 
 62  
     /* (non-Javadoc)
 63  
      * @see org.apache.jetspeed.om.common.LocalizedField#setLocale(java.util.Locale)
 64  
      */
 65  
     public void setLocale(Locale locale)
 66  
     {
 67  0
         this.locale = locale;        
 68  0
     }
 69  
 
 70  
     /* (non-Javadoc)
 71  
      * @see org.apache.jetspeed.om.common.LocalizedField#getValue()
 72  
      */
 73  
     public String getValue()
 74  
     {
 75  0
         return value;
 76  
     }
 77  
 
 78  
     /* (non-Javadoc)
 79  
      * @see org.apache.jetspeed.om.common.LocalizedField#setValue(java.lang.String)
 80  
      */
 81  
     public void setValue(String value)
 82  
     {
 83  0
         this.value = value;        
 84  0
     }
 85  
 
 86  
     /**
 87  
      * 
 88  
      */
 89  
     public ObjectID getId()
 90  
     {
 91  0
         return id;
 92  
     }
 93  
 
 94  
     public void setLanguage(String language)
 95  
     {
 96  0
 		if (language != null)
 97  
         {
 98  0
             String[] localeArray = language.split("[-|_]");
 99  0
             String country = "";
 100  0
             String variant = "";
 101  0
             for (int i = 0; i < localeArray.length; i++)
 102  
             {
 103  0
                 if (i == 0)
 104  
                 {
 105  0
                     language = localeArray[i];
 106  
                 }
 107  0
                 else if (i == 1)
 108  
                 {
 109  0
                     country = localeArray[i];
 110  
                 }
 111  0
                 else if (i == 2)
 112  
                 {
 113  0
                     variant = localeArray[i];
 114  
                 }
 115  
             }
 116  
 
 117  0
             this.locale = new Locale(language, country, variant);
 118  
         }
 119  0
     }
 120  
 
 121  
     public String getLanguage()
 122  
     {
 123  0
         if (this.locale != null)
 124  
         {
 125  0
             return this.locale.toString();
 126  
         }
 127  0
         return null;
 128  
     }
 129  
 
 130  
     /* (non-Javadoc)
 131  
      * @see org.apache.jetspeed.om.common.LocalizedField#getName()
 132  
      */
 133  
     public String getName()
 134  
     {
 135  0
         return name;
 136  
     }
 137  
 
 138  
     /* (non-Javadoc)
 139  
      * @see org.apache.jetspeed.om.common.LocalizedField#setName(java.lang.String)
 140  
      */
 141  
     public void setName(String name)
 142  
     {
 143  0
         this.name = name;        
 144  0
     }
 145  
     
 146  
     public String toString()
 147  
     {
 148  0
         return "Name: " + name + " Value: " + value + " Locale: " + locale;
 149  
     }
 150  
     
 151  
     public boolean equals(Object o)
 152  
     {
 153  0
         boolean result = false;
 154  
         
 155  0
         if(o instanceof LocalizedFieldImpl && o != null)
 156  
         {
 157  0
             LocalizedFieldImpl localField = (LocalizedFieldImpl)o;
 158  
             
 159  0
             result = (this.name == null) ? (localField.name == class="keyword">null) : (class="keyword">this.name.equals(localField.name));
 160  0
             result = result && ((this.value == null) ? (localField.value == class="keyword">null) : (class="keyword">this.value.equals(localField.value)));
 161  0
             result = result && ((this.locale == null) ? (localField.locale == class="keyword">null) : (class="keyword">this.locale.equals(localField.locale)));
 162  
         }
 163  
         
 164  0
         return result;
 165  
     }
 166  
     
 167  
     /**
 168  
      * @see java.lang.Object#hashCode()
 169  
      */
 170  
     public int hashCode()
 171  
     {
 172  0
         HashCodeBuilder hasher = new HashCodeBuilder(27, 101);
 173  0
         hasher.append(name).append(value);
 174  0
         if(locale != null)
 175  
         {    
 176  0
             hasher.append(locale.getCountry()).append(locale.getLanguage()).append(locale.getVariant());
 177  
         }
 178  0
         return hasher.toHashCode();
 179  
     }
 180  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.