Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java language level syntactic sugaring #249

Merged

Conversation

spannm
Copy link
Contributor

@spannm spannm commented Jan 26, 2024

Non-functional change - make use of new Java language features available up to Java 17 LTS

  • Use String.repeat()
  • Replace statements with enhanced switch
  • Use pattern variable
  • Convert to enhanced for-loop
  • Prefer StringBuilder over StringBuffer
  • Remove unnecessary boxing/unboxing
  • Use Objects.equals() rather than equals() expression
  • Replace explicit types by diamond operator
  • Use lambdas for anonymous types
  • Use Comparator combinator
  • Introduce method references for lambdas
  • Change statement to expression lambdas
  • Check for null using method call

Copy link
Owner

@hypfvieh hypfvieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the 2 marked files. Rest looks good

@@ -137,7 +138,7 @@ public static <T extends Struct> T createStructFromVariant(Variant<?> _variant,
}

if (_variant.getType() instanceof DBusStructType && _variant.getValue() instanceof Object[]) {
Class<?>[] argTypes = Arrays.stream((Object[]) _variant.getValue()).map(Object::getClass).toArray(size -> new Class<?>[size]);
Class<?>[] argTypes = Arrays.stream((Object[]) _variant.getValue()).map(Object::getClass).toArray((IntFunction<Class<?>[]>) Class[]::new);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to Class<?>[] argTypes = Arrays.stream((Object[]) _variant.getValue()).map(Object::getClass).toArray(Class<?>[]::new);

Non-functional change - make use of new Java language features available up to Java 17 LTS

- Use String.repeat()
- Replace statements with enhanced switch
- Use pattern variable
- Convert to enhanced for-loop
- Prefer StringBuilder over StringBuffer
- Remove unnecessary boxing/unboxing
- Use Objects.equals() rather than equals() expression
- Replace explicit types by diamond operator
- Use lambdas for anonymous types
- Use Comparator combinator
- Introduce method references for lambdas
- Change statement to expression lambdas
- Check for null using method call
@spannm spannm force-pushed the dbus-java-lang-lvl-syntactic-sugaring branch from 954b11a to f5937d2 Compare January 30, 2024 07:36
@hypfvieh hypfvieh merged commit bebdc55 into hypfvieh:master Jan 30, 2024
2 of 3 checks passed
@spannm spannm deleted the dbus-java-lang-lvl-syntactic-sugaring branch January 30, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants