Conditions | 71 |
Total Lines | 79 |
Code Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like de.pewpewproject.lasertag.block.models.BlockModelProvider.loadModelResource(Identifier,ModelProviderContext) often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | package de.pewpewproject.lasertag.block.models; |
||
108 | @Override |
||
109 | public @Nullable UnbakedModel loadModelResource(Identifier resourceId, ModelProviderContext context) throws ModelProviderException { |
||
110 | if (resourceId.equals(ORANGE_ARENA_BLOCK) || resourceId.equals(ORANGE_ARENA_BLOCK_ITEM)) { |
||
111 | return new OrangeArenaBlockModel(); |
||
112 | } else if(resourceId.equals(PINK_ARENA_BLOCK) || resourceId.equals(PINK_ARENA_BLOCK_ITEM)){ |
||
113 | return new PinkArenaBlockModel(); |
||
114 | } else if(resourceId.equals(BLUE_ARENA_BLOCK) || resourceId.equals(BLUE_ARENA_BLOCK_ITEM)){ |
||
115 | return new BlueArenaBlockModel(); |
||
116 | } else if(resourceId.equals(YELLOW_ARENA_BLOCK) || resourceId.equals(YELLOW_ARENA_BLOCK_ITEM)){ |
||
117 | return new YellowArenaBlockModel(); |
||
118 | } else if(resourceId.equals(GREEN_ARENA_BLOCK) || resourceId.equals(GREEN_ARENA_BLOCK_ITEM)){ |
||
119 | return new GreenArenaBlockModel(); |
||
120 | } else if(resourceId.equals(PURPLE_ARENA_BLOCK) || resourceId.equals(PURPLE_ARENA_BLOCK_ITEM)){ |
||
121 | return new PurpleArenaBlockModel(); |
||
122 | } else if(resourceId.equals(RED_ARENA_BLOCK) || resourceId.equals(RED_ARENA_BLOCK_ITEM)){ |
||
123 | return new RedArenaBlockModel(); |
||
124 | |||
125 | } else if (resourceId.equals(ORANGE_ARENA_PILLAR_BLOCK) || resourceId.equals(ORANGE_ARENA_PILLAR_BLOCK_ITEM)) { |
||
126 | return new OrangeArenaPillarBlockModel(); |
||
127 | } else if (resourceId.equals(PINK_ARENA_PILLAR_BLOCK) || resourceId.equals(PINK_ARENA_PILLAR_BLOCK_ITEM)) { |
||
128 | return new PinkArenaPillarBlockModel(); |
||
129 | } else if (resourceId.equals(BLUE_ARENA_PILLAR_BLOCK) || resourceId.equals(BLUE_ARENA_PILLAR_BLOCK_ITEM)) { |
||
130 | return new BlueArenaPillarBlockModel(); |
||
131 | } else if (resourceId.equals(YELLOW_ARENA_PILLAR_BLOCK) || resourceId.equals(YELLOW_ARENA_PILLAR_BLOCK_ITEM)) { |
||
132 | return new YellowArenaPillarBlockModel(); |
||
133 | } else if (resourceId.equals(GREEN_ARENA_PILLAR_BLOCK) || resourceId.equals(GREEN_ARENA_PILLAR_BLOCK_ITEM)) { |
||
134 | return new GreenArenaPillarBlockModel(); |
||
135 | } else if (resourceId.equals(PURPLE_ARENA_PILLAR_BLOCK) || resourceId.equals(PURPLE_ARENA_PILLAR_BLOCK_ITEM)) { |
||
136 | return new PurpleArenaPillarBlockModel(); |
||
137 | } else if (resourceId.equals(RED_ARENA_PILLAR_BLOCK) || resourceId.equals(RED_ARENA_PILLAR_BLOCK_ITEM)) { |
||
138 | return new RedArenaPillarBlockModel(); |
||
139 | |||
140 | } else if (resourceId.equals(ORANGE_ARENA_BLOCK_STAIRS) || resourceId.equals(ORANGE_ARENA_BLOCK_STAIRS_ITEM)) { |
||
141 | return new OrangeArenaBlockStairsModel(); |
||
142 | } else if (resourceId.equals(PINK_ARENA_BLOCK_STAIRS) || resourceId.equals(PINK_ARENA_BLOCK_STAIRS_ITEM)) { |
||
143 | return new PinkArenaBlockStairsModel(); |
||
144 | } else if (resourceId.equals(BLUE_ARENA_BLOCK_STAIRS) || resourceId.equals(BLUE_ARENA_BLOCK_STAIRS_ITEM)) { |
||
145 | return new BlueArenaBlockStairsModel(); |
||
146 | } else if (resourceId.equals(YELLOW_ARENA_BLOCK_STAIRS) || resourceId.equals(YELLOW_ARENA_BLOCK_STAIRS_ITEM)) { |
||
147 | return new YellowArenaBlockStairsModel(); |
||
148 | } else if (resourceId.equals(GREEN_ARENA_BLOCK_STAIRS) || resourceId.equals(GREEN_ARENA_BLOCK_STAIRS_ITEM)) { |
||
149 | return new GreenArenaBlockStairsModel(); |
||
150 | } else if (resourceId.equals(PURPLE_ARENA_BLOCK_STAIRS) || resourceId.equals(PURPLE_ARENA_BLOCK_STAIRS_ITEM)) { |
||
151 | return new PurpleArenaBlockStairsModel(); |
||
152 | } else if (resourceId.equals(RED_ARENA_BLOCK_STAIRS) || resourceId.equals(RED_ARENA_BLOCK_STAIRS_ITEM)) { |
||
153 | return new RedArenaBlockStairsModel(); |
||
154 | |||
155 | } else if (resourceId.equals(ORANGE_ARENA_DIVIDER) || resourceId.equals(ORANGE_ARENA_DIVIDER_ITEM)) { |
||
156 | return new OrangeArenaDividerBlockModel(); |
||
157 | } else if (resourceId.equals(PINK_ARENA_DIVIDER) || resourceId.equals(PINK_ARENA_DIVIDER_ITEM)) { |
||
158 | return new PinkArenaDividerBlockModel(); |
||
159 | } else if (resourceId.equals(BLUE_ARENA_DIVIDER) || resourceId.equals(BLUE_ARENA_DIVIDER_ITEM)) { |
||
160 | return new BlueArenaDividerBlockModel(); |
||
161 | } else if (resourceId.equals(YELLOW_ARENA_DIVIDER) || resourceId.equals(YELLOW_ARENA_DIVIDER_ITEM)) { |
||
162 | return new YellowArenaDividerBlockModel(); |
||
163 | } else if (resourceId.equals(GREEN_ARENA_DIVIDER) || resourceId.equals(GREEN_ARENA_DIVIDER_ITEM)) { |
||
164 | return new GreenArenaDividerBlockModel(); |
||
165 | } else if (resourceId.equals(PURPLE_ARENA_DIVIDER) || resourceId.equals(PURPLE_ARENA_DIVIDER_ITEM)) { |
||
166 | return new PurpleArenaDividerBlockModel(); |
||
167 | } else if (resourceId.equals(RED_ARENA_DIVIDER) || resourceId.equals(RED_ARENA_DIVIDER_ITEM)) { |
||
168 | return new RedArenaDividerBlockModel(); |
||
169 | |||
170 | } else if (resourceId.equals(ORANGE_ARENA_BLOCK_SLAB) || resourceId.equals(ORANGE_ARENA_BLOCK_SLAB_ITEM)) { |
||
171 | return new OrangeArenaBlockSlabModel(); |
||
172 | } else if (resourceId.equals(PINK_ARENA_BLOCK_SLAB) || resourceId.equals(PINK_ARENA_BLOCK_SLAB_ITEM)) { |
||
173 | return new PinkArenaBlockSlabModel(); |
||
174 | } else if (resourceId.equals(BLUE_ARENA_BLOCK_SLAB) || resourceId.equals(BLUE_ARENA_BLOCK_SLAB_ITEM)) { |
||
175 | return new BlueArenaBlockSlabModel(); |
||
176 | } else if (resourceId.equals(YELLOW_ARENA_BLOCK_SLAB) || resourceId.equals(YELLOW_ARENA_BLOCK_SLAB_ITEM)) { |
||
177 | return new YellowArenaBlockSlabModel(); |
||
178 | } else if (resourceId.equals(GREEN_ARENA_BLOCK_SLAB) || resourceId.equals(GREEN_ARENA_BLOCK_SLAB_ITEM)) { |
||
179 | return new GreenArenaBlockSlabModel(); |
||
180 | } else if (resourceId.equals(PURPLE_ARENA_BLOCK_SLAB) || resourceId.equals(PURPLE_ARENA_BLOCK_SLAB_ITEM)) { |
||
181 | return new PurpleArenaBlockSlabModel(); |
||
182 | } else if (resourceId.equals(RED_ARENA_BLOCK_SLAB) || resourceId.equals(RED_ARENA_BLOCK_SLAB_ITEM)) { |
||
183 | return new RedArenaBlockSlabModel(); |
||
184 | } |
||
185 | |||
186 | return null; |
||
187 | } |
||
189 |