Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
AbstractRatingExtension | 32 | 13 | 0% | 10 | 12 |
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.extension; | |
21 | ||
22 | import org.xwiki.extension.rating.ExtensionRating; | |
23 | import org.xwiki.extension.rating.RatingExtension; | |
24 | import org.xwiki.extension.repository.ExtensionRepository; | |
25 | ||
26 | /** | |
27 | * Base class for {@link RatingExtension} implementations. | |
28 | * | |
29 | * @version $Id: d1a34e9ba413e6e78789ec296c684339d615eab6 $ | |
30 | * @since 7.2M1 | |
31 | */ | |
32 | public abstract class AbstractRatingExtension extends AbstractRemoteExtension implements RatingExtension | |
33 | { | |
34 | /** | |
35 | * @see #getRating() | |
36 | */ | |
37 | protected ExtensionRating rating; | |
38 | ||
39 | /** | |
40 | * @param repository the repository where this extension comes from | |
41 | * @param id the extension identifier | |
42 | * @param type the extension type | |
43 | */ | |
44 | 67 | ![]() |
45 | { | |
46 | 67 | super(repository, id, type); |
47 | } | |
48 | ||
49 | /** | |
50 | * Create new extension descriptor by copying provided one. | |
51 | * | |
52 | * @param repository the repository where this extension comes from | |
53 | * @param extension the extension to copy | |
54 | */ | |
55 | 0 | ![]() |
56 | { | |
57 | 0 | super(repository, extension); |
58 | } | |
59 | ||
60 | 30 | ![]() |
61 | public ExtensionRating getRating() | |
62 | { | |
63 | 30 | return this.rating; |
64 | } | |
65 | ||
66 | /** | |
67 | * @param rating an extension's rating | |
68 | */ | |
69 | 67 | ![]() |
70 | { | |
71 | 67 | this.rating = rating; |
72 | } | |
73 | ||
74 | 11 | ![]() |
75 | public <T> T get(String fieldName) | |
76 | { | |
77 | 11 | switch (fieldName.toLowerCase()) { |
78 | 0 | case FIELD_AVERAGE_VOTE: |
79 | 0 | return (T) (Float) (getRating() != null ? getRating().getAverageVote() : -1f); |
80 | 0 | case FIELD_TOTAL_VOTES: |
81 | 0 | return (T) (Integer) (getRating() != null ? getRating().getTotalVotes() : 0); |
82 | 0 | case FIELD_RATING: |
83 | 0 | return (T) getRating(); |
84 | ||
85 | 11 | default: |
86 | 11 | return super.get(fieldName); |
87 | } | |
88 | } | |
89 | } |