Total Complexity | 11 |
Total Lines | 34 |
Duplicated Lines | 61.76 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | package net.labymod.serverapi; |
||
20 | @AllArgsConstructor |
||
21 | @Getter |
||
22 | public class Addon { |
||
23 | |||
24 | private UUID uuid; |
||
25 | private String name; |
||
26 | |||
27 | /** |
||
28 | * Parses the addons from the INFO plugin message |
||
29 | * |
||
30 | * @param jsonObject the json object of the message |
||
31 | * @return a list containing the message's addons |
||
32 | */ |
||
33 | View Code Duplication | @Deprecated |
|
|
|||
34 | public static List<Addon> getAddons( JsonObject jsonObject ) { |
||
35 | if ( !jsonObject.has( "addons" ) || !jsonObject.get( "addons" ).isJsonArray() ) |
||
36 | return Collections.emptyList(); |
||
37 | |||
38 | List<Addon> addons = new ArrayList<>(); |
||
39 | |||
40 | for ( JsonElement arrayElement : jsonObject.get( "addons" ).getAsJsonArray() ) { |
||
41 | if ( !arrayElement.isJsonObject() ) |
||
42 | continue; |
||
43 | |||
44 | JsonObject arrayObject = arrayElement.getAsJsonObject(); |
||
45 | |||
46 | if ( !arrayObject.has( "uuid" ) || !arrayObject.get( "uuid" ).isJsonPrimitive() || !arrayObject.get( "uuid" ).getAsJsonPrimitive().isString() |
||
47 | || !arrayObject.has( "name" ) || !arrayObject.get( "name" ).isJsonPrimitive() || !arrayObject.get( "name" ).getAsJsonPrimitive().isString() ) |
||
48 | continue; |
||
49 | |||
50 | addons.add( new Addon( UUID.fromString( arrayObject.get( "uuid" ).getAsString() ), arrayObject.get( "name" ).getAsString() ) ); |
||
51 | } |
||
52 | |||
53 | return addons; |
||
54 | } |
||
57 |