You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "maksaska (via GitHub)" <gi...@apache.org> on 2025/04/15 12:24:11 UTC

[PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

maksaska opened a new pull request, #12001:
URL: https://github.com/apache/ignite/pull/12001

   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "shishkovilja (via GitHub)" <gi...@apache.org>.
shishkovilja commented on code in PR #12001:
URL: https://github.com/apache/ignite/pull/12001#discussion_r2049265756


##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -93,10 +93,76 @@ public class BinaryUtils {
     public static final String MAPPING_FILE_EXTENSION = ".classname";
 
     /** */
-    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = new HashMap<>();
+    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = Map.ofEntries(
+        Map.entry(Byte.class, GridBinaryMarshaller.BYTE),
+        Map.entry(Short.class, GridBinaryMarshaller.SHORT),
+        Map.entry(Integer.class, GridBinaryMarshaller.INT),
+        Map.entry(Long.class, GridBinaryMarshaller.LONG),
+        Map.entry(Float.class, GridBinaryMarshaller.FLOAT),
+        Map.entry(Double.class, GridBinaryMarshaller.DOUBLE),
+        Map.entry(Character.class, GridBinaryMarshaller.CHAR),
+        Map.entry(Boolean.class, GridBinaryMarshaller.BOOLEAN),
+        Map.entry(BigDecimal.class, GridBinaryMarshaller.DECIMAL),
+        Map.entry(String.class, GridBinaryMarshaller.STRING),
+        Map.entry(UUID.class, GridBinaryMarshaller.UUID),
+        Map.entry(Date.class, GridBinaryMarshaller.DATE),
+        Map.entry(Timestamp.class, GridBinaryMarshaller.TIMESTAMP),
+        Map.entry(Time.class, GridBinaryMarshaller.TIME),
+        Map.entry(byte[].class, GridBinaryMarshaller.BYTE_ARR),
+        Map.entry(short[].class, GridBinaryMarshaller.SHORT_ARR),
+        Map.entry(int[].class, GridBinaryMarshaller.INT_ARR),
+        Map.entry(long[].class, GridBinaryMarshaller.LONG_ARR),
+        Map.entry(float[].class, GridBinaryMarshaller.FLOAT_ARR),
+        Map.entry(double[].class, GridBinaryMarshaller.DOUBLE_ARR),
+        Map.entry(char[].class, GridBinaryMarshaller.CHAR_ARR),
+        Map.entry(boolean[].class, GridBinaryMarshaller.BOOLEAN_ARR),
+        Map.entry(BigDecimal[].class, GridBinaryMarshaller.DECIMAL_ARR),
+        Map.entry(String[].class, GridBinaryMarshaller.STRING_ARR),
+        Map.entry(UUID[].class, GridBinaryMarshaller.UUID_ARR),
+        Map.entry(Date[].class, GridBinaryMarshaller.DATE_ARR),
+        Map.entry(Timestamp[].class, GridBinaryMarshaller.TIMESTAMP_ARR),
+        Map.entry(Time[].class, GridBinaryMarshaller.TIME_ARR),
+        Map.entry(byte.class, GridBinaryMarshaller.BYTE),
+        Map.entry(short.class, GridBinaryMarshaller.SHORT),
+        Map.entry(int.class, GridBinaryMarshaller.INT),
+        Map.entry(long.class, GridBinaryMarshaller.LONG),
+        Map.entry(float.class, GridBinaryMarshaller.FLOAT),
+        Map.entry(double.class, GridBinaryMarshaller.DOUBLE),
+        Map.entry(char.class, GridBinaryMarshaller.CHAR),
+        Map.entry(boolean.class, GridBinaryMarshaller.BOOLEAN)
+    );
 
     /** */
-    public static final Map<Byte, Class<?>> FLAG_TO_CLASS = new HashMap<>();
+    public static final Map<Byte, Class<?>> FLAG_TO_CLASS = Map.ofEntries(

Review Comment:
   As I see `FLAG_TO_CLASS` and `PLAIN_CLASS_TO_FLAG` maps differ only in that the second one contains primitive classes, so we can generate `FLAG_TO_CLASS` in a such way:
   ```
       public static final Map<Byte, Class<?>> FLAG_TO_CLASS = PLAIN_CLASS_TO_FLAG.entrySet()
           .stream()
           .filter(e -> !e.getKey().isPrimitive())
           .collect(Collectors.toUnmodifiableMap(Map.Entry::getValue, Map.Entry::getKey));
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -93,10 +93,76 @@ public class BinaryUtils {
     public static final String MAPPING_FILE_EXTENSION = ".classname";
 
     /** */
-    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = new HashMap<>();
+    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = Map.ofEntries(
+        Map.entry(Byte.class, GridBinaryMarshaller.BYTE),

Review Comment:
   Let's do static import of `Map.entry` method in order to avoid unnecessary duplications.



##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -109,7 +175,12 @@ public class BinaryUtils {
     private static final boolean[] PLAIN_TYPE_FLAG = new boolean[102];
 
     /** Binary classes. */
-    private static final Collection<Class<?>> BINARY_CLS = new HashSet<>();
+    private static final Collection<Class<?>> BINARY_CLS = Set.of(

Review Comment:
   Let's insert each element in a separate line.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "shishkovilja (via GitHub)" <gi...@apache.org>.
shishkovilja commented on code in PR #12001:
URL: https://github.com/apache/ignite/pull/12001#discussion_r2049266502


##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -109,7 +175,12 @@ public class BinaryUtils {
     private static final boolean[] PLAIN_TYPE_FLAG = new boolean[102];
 
     /** Binary classes. */
-    private static final Collection<Class<?>> BINARY_CLS = new HashSet<>();
+    private static final Collection<Class<?>> BINARY_CLS = Set.of(

Review Comment:
   Let's insert each element in a separate line, like it was done in a static block.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "sergey-chugunov-1985 (via GitHub)" <gi...@apache.org>.
sergey-chugunov-1985 merged PR #12001:
URL: https://github.com/apache/ignite/pull/12001


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "shishkovilja (via GitHub)" <gi...@apache.org>.
shishkovilja commented on code in PR #12001:
URL: https://github.com/apache/ignite/pull/12001#discussion_r2056397712


##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -662,7 +630,7 @@ public static boolean isBinaryType(Class<?> cls) {
 
         return BinaryObject.class.isAssignableFrom(cls) ||
             Proxy.class.isAssignableFrom(cls) ||
-            BINARY_CLS.contains(cls);
+            FLAG_TO_CLASS.containsValue(cls);

Review Comment:
   We can get performance drop here, because`Map#containsValue`JavaDoc says:
   > This operation will probably require time linear in the map size for most implementations of the `Map` interface.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #12001:
URL: https://github.com/apache/ignite/pull/12001#issuecomment-2919075744

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=12001) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=12001&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=12001&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ignite&pullRequest=12001&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=12001&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=12001&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=12001)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #12001:
URL: https://github.com/apache/ignite/pull/12001#discussion_r2050642710


##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -93,10 +93,76 @@ public class BinaryUtils {
     public static final String MAPPING_FILE_EXTENSION = ".classname";
 
     /** */
-    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = new HashMap<>();
+    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = Map.ofEntries(
+        Map.entry(Byte.class, GridBinaryMarshaller.BYTE),

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "shishkovilja (via GitHub)" <gi...@apache.org>.
shishkovilja commented on code in PR #12001:
URL: https://github.com/apache/ignite/pull/12001#discussion_r2056397712


##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -662,7 +630,7 @@ public static boolean isBinaryType(Class<?> cls) {
 
         return BinaryObject.class.isAssignableFrom(cls) ||
             Proxy.class.isAssignableFrom(cls) ||
-            BINARY_CLS.contains(cls);
+            FLAG_TO_CLASS.containsValue(cls);

Review Comment:
   We can get performance drop here, because`Map#containsValue`JavaDoc says:
   > This operation will probably require time linear in the map size for most implementations of the {@code Map} interface.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #12001:
URL: https://github.com/apache/ignite/pull/12001#discussion_r2105917407


##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -102,10 +104,50 @@ public class BinaryUtils {
     public static final String MAPPING_FILE_EXTENSION = ".classname";
 
     /** */
-    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = new HashMap<>();
+    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = Map.ofEntries(

Review Comment:
   Done!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #12001:
URL: https://github.com/apache/ignite/pull/12001#discussion_r2050643344


##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -93,10 +93,76 @@ public class BinaryUtils {
     public static final String MAPPING_FILE_EXTENSION = ".classname";
 
     /** */
-    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = new HashMap<>();
+    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = Map.ofEntries(
+        Map.entry(Byte.class, GridBinaryMarshaller.BYTE),
+        Map.entry(Short.class, GridBinaryMarshaller.SHORT),
+        Map.entry(Integer.class, GridBinaryMarshaller.INT),
+        Map.entry(Long.class, GridBinaryMarshaller.LONG),
+        Map.entry(Float.class, GridBinaryMarshaller.FLOAT),
+        Map.entry(Double.class, GridBinaryMarshaller.DOUBLE),
+        Map.entry(Character.class, GridBinaryMarshaller.CHAR),
+        Map.entry(Boolean.class, GridBinaryMarshaller.BOOLEAN),
+        Map.entry(BigDecimal.class, GridBinaryMarshaller.DECIMAL),
+        Map.entry(String.class, GridBinaryMarshaller.STRING),
+        Map.entry(UUID.class, GridBinaryMarshaller.UUID),
+        Map.entry(Date.class, GridBinaryMarshaller.DATE),
+        Map.entry(Timestamp.class, GridBinaryMarshaller.TIMESTAMP),
+        Map.entry(Time.class, GridBinaryMarshaller.TIME),
+        Map.entry(byte[].class, GridBinaryMarshaller.BYTE_ARR),
+        Map.entry(short[].class, GridBinaryMarshaller.SHORT_ARR),
+        Map.entry(int[].class, GridBinaryMarshaller.INT_ARR),
+        Map.entry(long[].class, GridBinaryMarshaller.LONG_ARR),
+        Map.entry(float[].class, GridBinaryMarshaller.FLOAT_ARR),
+        Map.entry(double[].class, GridBinaryMarshaller.DOUBLE_ARR),
+        Map.entry(char[].class, GridBinaryMarshaller.CHAR_ARR),
+        Map.entry(boolean[].class, GridBinaryMarshaller.BOOLEAN_ARR),
+        Map.entry(BigDecimal[].class, GridBinaryMarshaller.DECIMAL_ARR),
+        Map.entry(String[].class, GridBinaryMarshaller.STRING_ARR),
+        Map.entry(UUID[].class, GridBinaryMarshaller.UUID_ARR),
+        Map.entry(Date[].class, GridBinaryMarshaller.DATE_ARR),
+        Map.entry(Timestamp[].class, GridBinaryMarshaller.TIMESTAMP_ARR),
+        Map.entry(Time[].class, GridBinaryMarshaller.TIME_ARR),
+        Map.entry(byte.class, GridBinaryMarshaller.BYTE),
+        Map.entry(short.class, GridBinaryMarshaller.SHORT),
+        Map.entry(int.class, GridBinaryMarshaller.INT),
+        Map.entry(long.class, GridBinaryMarshaller.LONG),
+        Map.entry(float.class, GridBinaryMarshaller.FLOAT),
+        Map.entry(double.class, GridBinaryMarshaller.DOUBLE),
+        Map.entry(char.class, GridBinaryMarshaller.CHAR),
+        Map.entry(boolean.class, GridBinaryMarshaller.BOOLEAN)
+    );
 
     /** */
-    public static final Map<Byte, Class<?>> FLAG_TO_CLASS = new HashMap<>();
+    public static final Map<Byte, Class<?>> FLAG_TO_CLASS = Map.ofEntries(

Review Comment:
   Agree



##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -109,7 +175,12 @@ public class BinaryUtils {
     private static final boolean[] PLAIN_TYPE_FLAG = new boolean[102];
 
     /** Binary classes. */
-    private static final Collection<Class<?>> BINARY_CLS = new HashSet<>();
+    private static final Collection<Class<?>> BINARY_CLS = Set.of(

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-25130 Use JDK11 Set#of, Map#of in BinaryUtils [ignite]

Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #12001:
URL: https://github.com/apache/ignite/pull/12001#discussion_r2062568603


##########
modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java:
##########
@@ -662,7 +630,7 @@ public static boolean isBinaryType(Class<?> cls) {
 
         return BinaryObject.class.isAssignableFrom(cls) ||
             Proxy.class.isAssignableFrom(cls) ||
-            BINARY_CLS.contains(cls);
+            FLAG_TO_CLASS.containsValue(cls);

Review Comment:
   Indeed. Fixed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org