1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.localization.internal

File AbstractTranslationBundle.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

8
16
10
1
155
70
14
0.88
1.6
10
1.4

Classes

Class Line # Actions
AbstractTranslationBundle 36 16 0% 14 5
0.8529411685.3%
 

Contributing tests

This file is covered by 19 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software 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 GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.localization.internal;
21   
22    import java.util.Locale;
23   
24    import javax.inject.Inject;
25   
26    import org.slf4j.Logger;
27    import org.xwiki.localization.Translation;
28    import org.xwiki.localization.TranslationBundle;
29   
30    /**
31    * Base class for {@link TranslationBundle} implementations. Defines the bundle priority as an <code>integer</code>.
32    *
33    * @version $Id: 7b8c8cc34bf5fa0ee15f2e0d1933e85920c34842 $
34    * @since 4.3M2
35    */
 
36    public abstract class AbstractTranslationBundle implements TranslationBundle
37    {
38    /**
39    * An empty bundle.
40    */
41    public static final TranslationBundle EMPTY = new AbstractTranslationBundle(null)
42    {
 
43  0 toggle @Override
44    public Translation getTranslation(String key, Locale locale)
45    {
46  0 return null;
47    };
48    };
49   
50    /**
51    * The logger to log.
52    */
53    @Inject
54    protected Logger logger;
55   
56    /**
57    * @see #getId()
58    */
59    private String id;
60   
61    /**
62    * @see #getPriority()
63    * @see #compareTo(TranslationBundle)
64    */
65    private int priority = DEFAULTPRIORITY;
66   
67    /**
68    * Default constructor.
69    */
 
70  216 toggle protected AbstractTranslationBundle()
71    {
72   
73    }
74   
75    /**
76    * @param id the identifier if the bundle
77    */
 
78  114 toggle public AbstractTranslationBundle(String id)
79    {
80  114 this.id = id;
81    }
82   
83    /**
84    * @param id the identifier of the bundle
85    * @param priority the priority of the bundle
86    */
 
87  70 toggle public AbstractTranslationBundle(String id, int priority)
88    {
89  70 this.id = id;
90  70 this.priority = priority;
91    }
92   
 
93  113338 toggle @Override
94    public String getId()
95    {
96  113336 return this.id;
97    }
98   
99    /**
100    * @param id the identifier of the bundle
101    * @see #getId()
102    */
 
103  145 toggle protected void setId(String id)
104    {
105  145 this.id = id;
106    }
107   
 
108  111126 toggle @Override
109    public int getPriority()
110    {
111  111133 return this.priority;
112    }
113   
114    /**
115    * @param priority the priority
116    * @see #getPriority()
117    */
 
118  137 toggle protected void setPriority(int priority)
119    {
120  137 this.priority = priority;
121    }
122   
123    /**
124    * Compares two {@link TranslationBundle}s according to their priority. If they have the same priority, use their
125    * id as the comparison criterion.
126    *
127    * @param otherBundle The Bundle to compare to.
128    * @return Zero if the two bundles are identical, a negative number if this Bundle takes precedence over the other,
129    * a positive number otherwise.
130    * @see java.lang.Comparable#compareTo(java.lang.Object)
131    */
 
132  41756 toggle @Override
133    public int compareTo(TranslationBundle otherBundle)
134    {
135  41756 if (getPriority() != otherBundle.getPriority()) {
136  13854 return getPriority() - otherBundle.getPriority();
137    }
138   
139  27905 int result;
140   
141  27907 if (getId() == null) {
142  17 result = otherBundle.getId() == null ? 0 : 1;
143    } else {
144  27891 result = otherBundle.getId() == null ? -1 : getId().compareTo(otherBundle.getId());
145    }
146   
147  27907 return result;
148    }
149   
 
150  0 toggle @Override
151    public String toString()
152    {
153  0 return getId();
154    }
155    }