{"id":"b4c8a0c2-04af-4bef-8a8c-1732f9ed03d2","shortId":"nUQgWU","kind":"skill","title":"java-refactoring-extract-method","tagline":"Refactoring using Extract Methods in Java Language","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","agent-skills","agents","custom-agents","github-copilot","hacktoberfest"],"capabilities":["skill","source-github","skill-java-refactoring-extract-method","topic-agent-skills","topic-agents","topic-awesome","topic-custom-agents","topic-github-copilot","topic-hacktoberfest","topic-prompt-engineering"],"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":{"cli":"npx skills add github/awesome-copilot","source_repo":"https://github.com/github/awesome-copilot","install_from":"skills.sh"}},"qualityScore":"0.700","qualityRationale":"deterministic score 0.70 from registry signals: · indexed on github topic:agent-skills · 33270 github stars · SKILL.md body (3,376 chars)","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-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T18:52:15.230Z","embedding":null,"createdAt":"2026-04-18T20:25:53.517Z","updatedAt":"2026-05-18T18:52:15.230Z","lastSeenAt":"2026-05-18T18:52:15.230Z","tsv":"'0':61,138,140,199,201 '1':47,71,135,196 '10':284,288 '15':279 '17':261 '2':30,104,165 'add':108,169 'alway':253 'analyz':267 'appli':238 'assertnotbuild':58 'assess':350 'block':295,322 'bpartner':52,63,91 'bpartnerid':57,60,65,77,78,80,83,84 'bpartnerid.ofrepoidornull':99 'bpartneridifnotnul':75,98 'bpartnerrepoid':96,100 'cc':285 'code':34,37,44,68,101,162,278,294,317,345 'cohes':248 'comment':337 'compil':258 'complet':256 'complex':287,355 'consist':252 'coupl':250 'cyclomat':286 'defaultexpand':107,159,168,219,234 'describ':342 'descript':311 'direct':111,112,113,125,147,152,153,156,172,173,174,186,208,213,214,217,230,231,236 'directions.get':115,176 'els':85,130,191 'exampl':31 'exceed':273 'existingdirect':114,121,124,175,182,185 'expert':23 'extract':4,8,17,42,239,299,303,360 'factlinebuild':50,74,89 'final':55,76,94,117,178 'first':266 'function':327 'hashmap':150,211 'high':354 'id':53,64,92 'identifi':271,293 'ifvalid':54,93 'improv':242 'includ':332 'insid':318 'int':56,95 'intermedi':263 'intern':265 'java':2,11,14,26,48,72,105,166,260,321 'java-refactoring-extract-method':1 'languag':12 'least':305 'line':276,336 'loc':275 'low':249 'maintain':245 'map':145,206,228 'method':5,9,15,18,27,43,240,259,269,292,302,308,331,341,352,361 'modular':247 'name':312 'new':132,149,158,193,210,233,307,340 'newdirect':148,161,209,222 'newdirections.put':154,215 'newexpand':220,225 'newtyp':119,128,131,139,142,160,180,189,192,200,203,221 'nom':280 'null':81,122,183 'number':281 'one':306,335 'one-lin':334 'origin':330 'output':313 'perform':262 'protect':223 'public':49,73,88,106,167 'purpos':344 'qualifi':291 'readabl':243 'refactor':3,6,13,25,39,46,70,103,164,316,348,357 'relationshipexpand':224 'relationshiptyp':109,118,133,170,179,194,226 'remov':325 'repres':41 'return':66,82,86,97,126,157,187,218,232,254 'reusabl':246 'role':19 'separ':301 'setc':51,62,90 'singl':320 'skill' 'skill-java-refactoring-extract-method' 'source-github' 'statement':283 'step':264 'string':146,151,207,212,229 'system.arraycopy':136,197 'task':237 'testabl':244 'threshold':274 'titl':33 'topic-agent-skills' 'topic-agents' 'topic-awesome' 'topic-custom-agents' 'topic-github-copilot' 'topic-hacktoberfest' 'topic-prompt-engineering' 'type':110,129,137,144,171,190,198,205,227,235 'type.name':116,155,177,216 'types.length':134,141,143,195,202,204 'use':7,359","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-05-18T18:52:15.230Z"},{"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-05-07T22:40:18.152Z"}],"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","github":{"repo":"github/awesome-copilot","stars":33270,"topics":["agent-skills","agents","ai","awesome","custom-agents","github-copilot","hacktoberfest","prompt-engineering"],"license":"mit","html_url":"https://github.com/github/awesome-copilot","pushed_at":"2026-05-18T01:26:59Z","description":"Community-contributed instructions, agents, skills, and configurations to help you make the most of GitHub Copilot.","skill_md_sha":"173e6d7811b60c75a8cb67f261e1528efa5733ad","skill_md_path":"skills/java-refactoring-extract-method/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/github/awesome-copilot/tree/main/skills/java-refactoring-extract-method"},"layout":"multi","source":"github","category":"awesome-copilot","frontmatter":{"name":"java-refactoring-extract-method","description":"Refactoring using Extract Methods in Java Language"},"skills_sh_url":"https://skills.sh/github/awesome-copilot/java-refactoring-extract-method"},"updatedAt":"2026-05-18T18:52:15.230Z"}}