Coverage Report - org.jtheque.core.utils.db.NoteImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NoteImpl
80 %
16/20
80 %
8/10
2
 
 1  
 package org.jtheque.core.utils.db;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.language.ILanguageManager;
 21  
 import org.jtheque.core.utils.db.DaoNotes.NoteType;
 22  
 import org.jtheque.utils.Constants;
 23  
 import org.jtheque.utils.bean.EqualsUtils;
 24  
 
 25  
 /**
 26  
  * A note.
 27  
  *
 28  
  * @author Baptiste Wicht
 29  
  */
 30  
 public final class NoteImpl implements Note {
 31  
     private final String key;
 32  
     private final NoteType value;
 33  
 
 34  
     /**
 35  
      * Construct a new NoteImpl with a specific value and a text key.
 36  
      *
 37  
      * @param value The value of the note.
 38  
      * @param key   The text key.
 39  
      */
 40  
     public NoteImpl(NoteType value, String key) {
 41  34
         super();
 42  
 
 43  34
         this.value = value;
 44  34
         this.key = key;
 45  34
     }
 46  
 
 47  
     @Override
 48  
     public String getInternationalizedText() {
 49  0
         return Managers.getManager(ILanguageManager.class).getMessage(key);
 50  
     }
 51  
 
 52  
     @Override
 53  
     public String toString() {
 54  0
         return getInternationalizedText();
 55  
     }
 56  
 
 57  
     @Override
 58  
     public int hashCode() {
 59  40
         int result = Constants.HASH_CODE_START;
 60  
 
 61  40
         result = Constants.HASH_CODE_PRIME * result + value.intValue();
 62  40
         result = Constants.HASH_CODE_PRIME * result + (key == null ? 0 : key.hashCode());
 63  
 
 64  40
         return result;
 65  
     }
 66  
 
 67  
     @Override
 68  
     public boolean equals(Object obj) {
 69  30
         if (this == obj) {
 70  10
             return true;
 71  
         }
 72  
 
 73  20
         if (EqualsUtils.areObjectIncompatible(this, obj)) {
 74  0
             return false;
 75  
         }
 76  
 
 77  20
         final NoteImpl other = (NoteImpl) obj;
 78  
 
 79  20
         if (value != other.value) {
 80  12
             return false;
 81  
         }
 82  
 
 83  8
         return !EqualsUtils.areNotEquals(key, other.key);
 84  
 
 85  
     }
 86  
 
 87  
     @Override
 88  
     public String getElementName() {
 89  0
         return getInternationalizedText();
 90  
     }
 91  
 
 92  
     @Override
 93  
     public NoteType getValue() {
 94  70
         return value;
 95  
     }
 96  
 }