{"id":"b4c8a0c2-04af-4bef-8a8c-1732f9ed03d2","shortId":"nUQgWU","kind":"skill","title":"Java Refactoring Extract Method","tagline":"Awesome Copilot skill by Github","description":"# Refactoring Java Methods with Extract Method\n\n## Role\n\nYou are an expert in refactoring Java methods.\n\nBelow are **2 examples** (with titles code before and code after refactoring) that represents **Extract Method**.\n\n## Code Before Refactoring 1:\n```java\npublic FactLineBuilder setC_BPartner_ID_IfValid(final int bpartnerId) {\n\tassertNotBuild();\n\tif (bpartnerId > 0) {\n\t\tsetC_BPartner_ID(bpartnerId);\n\t}\n\treturn this;\n}\n```\n\n## Code After Refactoring 1:\n```java\npublic FactLineBuilder bpartnerIdIfNotNull(final BPartnerId bpartnerId) {\n\tif (bpartnerId != null) {\n\t\treturn bpartnerId(bpartnerId);\n\t} else {\n\t\treturn this;\n\t}\n}\npublic FactLineBuilder setC_BPartner_ID_IfValid(final int bpartnerRepoId) {\n\treturn bpartnerIdIfNotNull(BPartnerId.ofRepoIdOrNull(bpartnerRepoId));\n}\n```\n\n## Code Before Refactoring 2:\n```java\npublic DefaultExpander add(RelationshipType type, Direction direction) {\n     Direction existingDirection = directions.get(type.name());\n     final RelationshipType[] newTypes;\n     if (existingDirection != null) {\n          if (existingDirection == direction) {\n               return this;\n          }\n          newTypes = types;\n     } else {\n          newTypes = new RelationshipType[types.length + 1];\n          System.arraycopy(types, 0, newTypes, 0, types.length);\n          newTypes[types.length] = type;\n     }\n     Map<String, Direction> newDirections = new HashMap<String, Direction>(directions);\n     newDirections.put(type.name(), direction);\n     return new DefaultExpander(newTypes, newDirections);\n}\n```\n\n## Code After Refactoring 2:\n```java\npublic DefaultExpander add(RelationshipType type, Direction direction) {\n     Direction existingDirection = directions.get(type.name());\n     final RelationshipType[] newTypes;\n     if (existingDirection != null) {\n          if (existingDirection == direction) {\n               return this;\n          }\n          newTypes = types;\n     } else {\n          newTypes = new RelationshipType[types.length + 1];\n          System.arraycopy(types, 0, newTypes, 0, types.length);\n          newTypes[types.length] = type;\n     }\n     Map<String, Direction> newDirections = new HashMap<String, Direction>(directions);\n     newDirections.put(type.name(), direction);\n     return (DefaultExpander) newExpander(newTypes, newDirections);\n}\nprotected RelationshipExpander newExpander(RelationshipType[] types,\n          Map<String, Direction> directions) {\n     return new DefaultExpander(types, directions);\n}\n```\n\n## Task\n\nApply **Extract Method** to improve readability, testability, maintainability, reusability, modularity, cohesion, low coupling, and consistency.\n\nAlways return a complete and compilable method (Java 17).\n\nPerform intermediate steps internally:\n- First, analyze each method and identify those exceeding thresholds:\n  * LOC (Lines of Code) > 15\n  * NOM (Number of Statements) > 10\n  * CC (Cyclomatic Complexity) > 10\n- For each qualifying method, identify code blocks that can be extracted into separate methods.\n- Extract at least one new method with a descriptive name.\n- Output only the refactored code inside a single ```java``` block.\n- Do not remove any functionality from the original method.\n- Include a one-line comment above each new method describing its purpose.\n\n## Code to be Refactored:\n\nNow, assess all methods with high complexity and refactor them using **Extract Method**","tags":["java","refactoring","extract","method","awesome","copilot","github"],"capabilities":["skill","source-github","category-awesome-copilot"],"categories":["awesome-copilot"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/github/awesome-copilot/java-refactoring-extract-method","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"install_from":"skills.sh"}},"qualityScore":"0.300","qualityRationale":"deterministic score 0.30 from registry signals: · indexed on skills.sh · published under github/awesome-copilot","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill:v1","enrichmentVersion":1,"enrichedAt":"2026-04-22T13:40:15.169Z","embedding":null,"createdAt":"2026-04-18T20:25:53.517Z","updatedAt":"2026-04-22T13:40:15.169Z","lastSeenAt":"2026-04-22T13:40:15.169Z","tsv":"'0':58,135,137,196,198 '1':44,68,132,193 '10':281,285 '15':276 '17':258 '2':27,101,162 'add':105,166 'alway':250 'analyz':264 'appli':235 'assertnotbuild':55 'assess':347 'awesom':5 'block':292,319 'bpartner':49,60,88 'bpartnerid':54,57,62,74,75,77,80,81 'bpartnerid.ofrepoidornull':96 'bpartneridifnotnul':72,95 'bpartnerrepoid':93,97 'category-awesome-copilot' 'cc':282 'code':31,34,41,65,98,159,275,291,314,342 'cohes':245 'comment':334 'compil':255 'complet':253 'complex':284,352 'consist':249 'copilot':6 'coupl':247 'cyclomat':283 'defaultexpand':104,156,165,216,231 'describ':339 'descript':308 'direct':108,109,110,122,144,149,150,153,169,170,171,183,205,210,211,214,227,228,233 'directions.get':112,173 'els':82,127,188 'exampl':28 'exceed':270 'existingdirect':111,118,121,172,179,182 'expert':20 'extract':3,14,39,236,296,300,357 'factlinebuild':47,71,86 'final':52,73,91,114,175 'first':263 'function':324 'github':9 'hashmap':147,208 'high':351 'id':50,61,89 'identifi':268,290 'ifvalid':51,90 'improv':239 'includ':329 'insid':315 'int':53,92 'intermedi':260 'intern':262 'java':1,11,23,45,69,102,163,257,318 'least':302 'line':273,333 'loc':272 'low':246 'maintain':242 'map':142,203,225 'method':4,12,15,24,40,237,256,266,289,299,305,328,338,349,358 'modular':244 'name':309 'new':129,146,155,190,207,230,304,337 'newdirect':145,158,206,219 'newdirections.put':151,212 'newexpand':217,222 'newtyp':116,125,128,136,139,157,177,186,189,197,200,218 'nom':277 'null':78,119,180 'number':278 'one':303,332 'one-lin':331 'origin':327 'output':310 'perform':259 'protect':220 'public':46,70,85,103,164 'purpos':341 'qualifi':288 'readabl':240 'refactor':2,10,22,36,43,67,100,161,313,345,354 'relationshipexpand':221 'relationshiptyp':106,115,130,167,176,191,223 'remov':322 'repres':38 'return':63,79,83,94,123,154,184,215,229,251 'reusabl':243 'role':16 'separ':298 'setc':48,59,87 'singl':317 'skill':7 'source-github' 'statement':280 'step':261 'string':143,148,204,209,226 'system.arraycopy':133,194 'task':234 'testabl':241 'threshold':271 'titl':30 'type':107,126,134,141,168,187,195,202,224,232 'type.name':113,152,174,213 'types.length':131,138,140,192,199,201 'use':356","prices":[{"id":"52eaacb3-30a4-40c9-957b-f931fe70c9ab","listingId":"b4c8a0c2-04af-4bef-8a8c-1732f9ed03d2","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"github","category":"awesome-copilot","install_from":"skills.sh"},"createdAt":"2026-04-18T20:25:53.517Z"}],"sources":[{"listingId":"b4c8a0c2-04af-4bef-8a8c-1732f9ed03d2","source":"github","sourceId":"github/awesome-copilot/java-refactoring-extract-method","sourceUrl":"https://github.com/github/awesome-copilot/tree/main/skills/java-refactoring-extract-method","isPrimary":false,"firstSeenAt":"2026-04-18T21:49:57.239Z","lastSeenAt":"2026-04-22T12:52:15.699Z"},{"listingId":"b4c8a0c2-04af-4bef-8a8c-1732f9ed03d2","source":"skills_sh","sourceId":"github/awesome-copilot/java-refactoring-extract-method","sourceUrl":"https://skills.sh/github/awesome-copilot/java-refactoring-extract-method","isPrimary":true,"firstSeenAt":"2026-04-18T20:25:53.517Z","lastSeenAt":"2026-04-22T13:40:15.169Z"}],"details":{"listingId":"b4c8a0c2-04af-4bef-8a8c-1732f9ed03d2","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"github","slug":"java-refactoring-extract-method","source":"skills_sh","category":"awesome-copilot","skills_sh_url":"https://skills.sh/github/awesome-copilot/java-refactoring-extract-method"},"updatedAt":"2026-04-22T13:40:15.169Z"}}