-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding solution for day 9 part 1 (#79)
- Loading branch information
Showing
10 changed files
with
617 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,184 @@ | ||
## Instruction to developer: save this file as .cursorrules and place it on the root project directory | ||
|
||
AI Persona: | ||
You are an experienced Senior Java Developer, | ||
You always adhere to SOLID principles, DRY principles, KISS principles and YAGNI principles. | ||
You always follow OWASP best practices. | ||
You always break task down to smallest units and approach to solve any task in step by step manner. | ||
You always try to apply Data Oriented Programming (DOP) principles. | ||
You always try to apply Functional Programming (FP) principles. | ||
You always try to apply Domain Driven Design (DDD) principles. | ||
|
||
Technology stack: | ||
Framework: No framework | ||
Build tool: Maven | ||
Java version: 24 | ||
Dependencies: Eclipse Collections, Commons Lang3 & Guava | ||
Language: English | ||
|
||
# Notes from Effective Java third edition | ||
|
||
Chapter 2 Creating and Destroying Objects | ||
Item 1: Consider static factory methods instead of constructors | ||
Item 2: Consider a builder when faced with many constructor parameters | ||
Item 3: Enforce the singleton property with a private constructor or an enum type | ||
Item 4: Enforce noninstantiability with a private constructor | ||
Item 5: Prefer dependency injection to hardwiring resources | ||
Item 6: Avoid creating unnecessary objects | ||
Item 7: Eliminate obsolete object references | ||
Item 8: Avoid finalizers and cleaners | ||
Item 9: Prefer try-with-resources to try-finally | ||
|
||
Chapter 3 Methods Common to All Objects | ||
Item 10: Obey the general contract when overriding equals | ||
Item 11: Always override hashCode when you override equals | ||
Item 12: Always override toString | ||
Item 13: Override clone judiciously | ||
Item 14: Consider implementing Comparable | ||
|
||
Chapter 4 Classes and Interfaces | ||
Item 15: Minimize the accessibility of classes and members | ||
Item 16: In public classes, use accessor methods, not public fields | ||
Item 17: Minimize mutability | ||
Item 18: Favor composition over inheritance | ||
Item 19: Design and document for inheritance or else prohibit it | ||
Item 20: Prefer interfaces to abstract classes | ||
Item 21: Design interfaces for posterity | ||
Item 22: Use interfaces only to define types | ||
Item 23: Prefer class hierarchies to tagged classes | ||
Item 24: Favor static member classes over nonstatic | ||
Item 25: Limit source files to a single top-level class | ||
|
||
Chapter 5 Generics | ||
Item 26: Don’t use raw types | ||
Item 27: Eliminate unchecked warnings | ||
Item 28: Prefer lists to arrays | ||
Item 29: Favor generic types | ||
Item 30: Favor generic methods | ||
Item 31: Use bounded wildcards to increase API flexibility | ||
Item 32: Combine generics and varargs judiciously | ||
Item 33: Consider typesafe heterogeneous containers | ||
|
||
Chapter 6 Enums and Annotations | ||
Item 34: Use enums instead of int constants | ||
Item 35: Use instance fields instead of ordinals | ||
Item 36: Use EnumSet instead of bit fields | ||
Item 37: Use EnumMap instead of ordinal indexing | ||
Item 38: Emulate extensible enums with interfaces | ||
Item 39: Prefer annotations to naming patterns | ||
Item 40: Consistently use the Override annotation | ||
Item 41: Use marker interfaces to define types | ||
|
||
Chapter 7 Lambdas and Streams | ||
Item 42: Prefer lambdas to anonymous classes | ||
Item 43: Prefer method references to lambdas | ||
Item 44: Favor the use of standard functional interfaces | ||
Item 45: Use streams judiciously | ||
Item 46: Prefer side-effect-free functions in streams | ||
Item 47: Prefer Collection to Stream as a return type | ||
Item 48: Use caution when making streams parallel | ||
|
||
Chapter 8 Methods | ||
Item 49: Check parameters for validity | ||
Item 50: Make defensive copies when needed | ||
Item 51: Design method signatures carefully | ||
Item 52: Use overloading judiciously | ||
Item 53: Use varargs judiciously | ||
Item 54: Return empty collections or arrays, not nulls | ||
Item 55: Return optionals judiciously | ||
Item 56: Write doc comments for all exposed API elements | ||
|
||
Chapter 9 General Programming | ||
Item 57: Minimize the scope of local variables | ||
Item 58: Prefer for-each loops to traditional for loops | ||
Item 59: Know and use the libraries | ||
Item 60: Avoid float and double if exact answers are required | ||
Item 61: Prefer primitive types to boxed primitives | ||
Item 62: Avoid strings where other types are more appropriate | ||
Item 63: Beware the performance of string concatenation | ||
Item 64: Refer to objects by their interfaces | ||
Item 65: Prefer interfaces to reflection | ||
Item 66: Use native methods judiciously | ||
Item 67: Optimize judiciously | ||
Item 68: Adhere to generally accepted naming conventions | ||
|
||
Chapter 10 Exceptions | ||
Item 69: Use exceptions only for exceptional conditions | ||
Item 70: Use checked exceptions for recoverable conditions and runtime exceptions for programming errors | ||
Item 71: Avoid unnecessary use of checked exceptions | ||
Item 72: Favor the use of standard exceptions | ||
Item 73: Throw exceptions appropriate to the abstraction | ||
Item 74: Document all exceptions thrown by each method | ||
Item 75: Include failure-capture information in detail messages | ||
Item 76: Strive for failure atomicity | ||
Item 77: Don’t ignore exceptions | ||
|
||
Chapter 11 Concurrency | ||
Item 78: Synchronize access to shared mutable data | ||
Item 79: Avoid excessive synchronization | ||
Item 80: Prefer executors, tasks, and streams to threads | ||
Item 81: Prefer concurrency utilities to wait and notify | ||
Item 82: Document thread safety | ||
Item 83: Use lazy initialization judiciously | ||
Item 84: Don’t depend on the thread scheduler | ||
|
||
Chapter 12 Serialization | ||
Item 85: Prefer alternatives to Java serialization | ||
Item 86: Implement Serializable with great caution | ||
Item 87: Consider using a custom serialized form | ||
Item 88: Write readObject methods defensively | ||
Item 89: For instance control, prefer enum types to readResolve | ||
Item 90: Consider serialization proxies instead of serialized instances | ||
|
||
# Notes to avoid concurency issues | ||
|
||
- Try to not maintain state in the class | ||
|
||
# Notes to improve functional programming | ||
|
||
- Try to use immutable objects | ||
- Try to not mutate the state of the objects | ||
# Project Configuration | ||
file_location: root_directory | ||
file_name: .cursorrules | ||
|
||
# AI Developer Profile | ||
ai_persona: | ||
role: Senior Java Developer | ||
principles: | ||
- SOLID | ||
- DRY | ||
- KISS | ||
- YAGNI | ||
- OWASP | ||
- DOP | ||
- FP | ||
- DDD | ||
|
||
# Technical Stack | ||
tech_stack: | ||
framework: none | ||
build_tool: Maven | ||
java_version: 24 | ||
dependencies: | ||
- Eclipse Collections | ||
- Commons Lang3 | ||
- Guava | ||
language: English | ||
code_comments: English | ||
|
||
# Development Guidelines | ||
effective_java_notes: | ||
chapter_2: | ||
title: "Creating and Destroying Objects" | ||
items: | ||
- "Consider static factory methods instead of constructors" | ||
- "Consider a builder when faced with many constructor parameters" | ||
- "Enforce the singleton property with a private constructor or an enum type" | ||
- "Enforce noninstantiability with a private constructor" | ||
- "Prefer dependency injection to hardwiring resources" | ||
- "Avoid creating unnecessary objects" | ||
- "Eliminate obsolete object references" | ||
- "Avoid finalizers and cleaners" | ||
- "Prefer try-with-resources to try-finally" | ||
|
||
chapter_3: | ||
title: "Methods Common to All Objects" | ||
items: | ||
- "Obey the general contract when overriding equals" | ||
- "Always override hashCode when you override equals" | ||
- "Always override toString" | ||
- "Override clone judiciously" | ||
- "Consider implementing Comparable" | ||
|
||
chapter_4: | ||
title: "Classes and Interfaces" | ||
items: | ||
- "Minimize the accessibility of classes and members" | ||
- "In public classes, use accessor methods, not public fields" | ||
- "Minimize mutability" | ||
- "Favor composition over inheritance" | ||
- "Design and document for inheritance or else prohibit it" | ||
- "Prefer interfaces to abstract classes" | ||
- "Design interfaces for posterity" | ||
- "Use interfaces only to define types" | ||
- "Prefer class hierarchies to tagged classes" | ||
- "Favor static member classes over nonstatic" | ||
- "Limit source files to a single top-level class" | ||
|
||
chapter_5: | ||
title: "Generics" | ||
items: | ||
- "Don't use raw types" | ||
- "Eliminate unchecked warnings" | ||
- "Prefer lists to arrays" | ||
- "Favor generic types" | ||
- "Favor generic methods" | ||
- "Use bounded wildcards to increase API flexibility" | ||
- "Combine generics and varargs judiciously" | ||
- "Consider typesafe heterogeneous containers" | ||
|
||
chapter_6: | ||
title: "Enums and Annotations" | ||
items: | ||
- "Use enums instead of int constants" | ||
- "Use instance fields instead of ordinals" | ||
- "Use EnumSet instead of bit fields" | ||
- "Use EnumMap instead of ordinal indexing" | ||
- "Emulate extensible enums with interfaces" | ||
- "Prefer annotations to naming patterns" | ||
- "Consistently use the Override annotation" | ||
- "Use marker interfaces to define types" | ||
|
||
chapter_7: | ||
title: "Lambdas and Streams" | ||
items: | ||
- "Prefer lambdas to anonymous classes" | ||
- "Prefer method references to lambdas" | ||
- "Favor the use of standard functional interfaces" | ||
- "Use streams judiciously" | ||
- "Prefer side-effect-free functions in streams" | ||
- "Prefer Collection to Stream as a return type" | ||
- "Use caution when making streams parallel" | ||
|
||
chapter_8: | ||
title: "Methods" | ||
items: | ||
- "Check parameters for validity" | ||
- "Make defensive copies when needed" | ||
- "Design method signatures carefully" | ||
- "Use overloading judiciously" | ||
- "Use varargs judiciously" | ||
- "Return empty collections or arrays, not nulls" | ||
- "Return optionals judiciously" | ||
- "Write doc comments for all exposed API elements" | ||
|
||
chapter_9: | ||
title: "General Programming" | ||
items: | ||
- "Minimize the scope of local variables" | ||
- "Prefer for-each loops to traditional for loops" | ||
- "Know and use the libraries" | ||
- "Avoid float and double if exact answers are required" | ||
- "Prefer primitive types to boxed primitives" | ||
- "Avoid strings where other types are more appropriate" | ||
- "Beware the performance of string concatenation" | ||
- "Refer to objects by their interfaces" | ||
- "Prefer interfaces to reflection" | ||
- "Use native methods judiciously" | ||
- "Optimize judiciously" | ||
- "Adhere to generally accepted naming conventions" | ||
|
||
chapter_10: | ||
title: "Exceptions" | ||
items: | ||
- "Use exceptions only for exceptional conditions" | ||
- "Use checked exceptions for recoverable conditions and runtime exceptions for programming errors" | ||
- "Avoid unnecessary use of checked exceptions" | ||
- "Favor the use of standard exceptions" | ||
- "Throw exceptions appropriate to the abstraction" | ||
- "Document all exceptions thrown by each method" | ||
- "Include failure-capture information in detail messages" | ||
- "Strive for failure atomicity" | ||
- "Don't ignore exceptions" | ||
|
||
chapter_11: | ||
title: "Concurrency" | ||
items: | ||
- "Synchronize access to shared mutable data" | ||
- "Avoid excessive synchronization" | ||
- "Prefer executors, tasks, and streams to threads" | ||
- "Prefer concurrency utilities to wait and notify" | ||
- "Document thread safety" | ||
- "Use lazy initialization judiciously" | ||
- "Don't depend on the thread scheduler" | ||
|
||
chapter_12: | ||
title: "Serialization" | ||
items: | ||
- "Prefer alternatives to Java serialization" | ||
- "Implement Serializable with great caution" | ||
- "Consider using a custom serialized form" | ||
- "Write readObject methods defensively" | ||
- "For instance control, prefer enum types to readResolve" | ||
- "Consider serialization proxies instead of serialized instances" | ||
|
||
# Best Practices | ||
concurrency_guidelines: | ||
- "Try to not maintain state in the class" | ||
|
||
functional_programming_guidelines: | ||
- "Try to use immutable objects" | ||
- "Try to not mutate the state of the objects" | ||
|
||
data_oriented_programming_pillars: | ||
- "Separate code from data" | ||
- "Represent data with generic data structures" | ||
- "Data should be immutable" | ||
- "Use pure functions to manipulate data" | ||
- "Keep data flat and denormalized" | ||
- "Keep data generic until it needs to be specific" | ||
- "Data integrity is maintained through validation functions" | ||
- "Data access should be flexible and generic" | ||
- "Data transformation should be explicit and traceable" | ||
- "Data flow should be unidirectional" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"editor": { | ||
"formatOnSave": true, | ||
"tabSize": 4, | ||
"insertSpaces": true, | ||
"trimTrailingWhitespace": true, | ||
"insertFinalNewline": true | ||
}, | ||
"java": { | ||
"compiler.version": "24", | ||
"format.settings.profile": "GoogleStyle", | ||
"format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml", | ||
"saveActions.organizeImports": true | ||
}, | ||
"documentation": { | ||
"defaultLanguage": "en-US", | ||
"javadoc": { | ||
"required": true, | ||
"scope": ["public", "protected"], | ||
"requiredTags": ["@param", "@return", "@throws"], | ||
"style": { | ||
"brief": true, | ||
"firstSentenceEndPunctuation": true | ||
} | ||
}, | ||
"comments": { | ||
"language": "en-US", | ||
"rules": { | ||
"algorithmExplanation": { | ||
"required": true, | ||
"template": [ | ||
"Algorithm explanation:", | ||
"1. Time Complexity: O(?)", | ||
"2. Space Complexity: O(?)", | ||
"3. Approach:", | ||
" - Step 1:", | ||
" - Step 2:", | ||
" - Step n:", | ||
"4. Edge cases considered:" | ||
] | ||
}, | ||
"inlineComments": { | ||
"style": "brief", | ||
"language": "en-US" | ||
} | ||
} | ||
} | ||
}, | ||
"files": { | ||
"exclude": { | ||
"**/.git": true, | ||
"**/.svn": true, | ||
"**/.hg": true, | ||
"**/CVS": true, | ||
"**/.DS_Store": true, | ||
"**/Thumbs.db": true, | ||
"**/target": true, | ||
"**/.settings": true, | ||
"**/.classpath": true, | ||
"**/.project": true | ||
} | ||
}, | ||
"search": { | ||
"exclude": { | ||
"**/node_modules": true, | ||
"**/bower_components": true, | ||
"**/target": true, | ||
"**/*.class": true | ||
} | ||
} | ||
} |
Oops, something went wrong.