adelapena commented on code in PR #1891:
URL: https://github.com/apache/cassandra/pull/1891#discussion_r1121680912


##########
src/java/org/apache/cassandra/utils/CassandraUInt.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cassandra.utils;
+
+import com.google.common.primitives.UnsignedInteger;
+import com.google.common.primitives.UnsignedInts;
+
+/**
+ * This class packages several UInt utility methods so we can easily change 
it's implementation when needed.
+ */
+public class CassandraUInt
+{
+    
+    private static long MAX_VALUE_LONG = UnsignedInteger.MAX_VALUE.longValue();
+    private static int MAX_VALUE_UINT = UnsignedInteger.MAX_VALUE.intValue();
+    
+    /**
+     * Converts a long to int's unsigned integer representation
+     * 
+     * @param value A long between 0 and 2<sup>32</sup>-1 inclusive
+     * @return an unsigned integer representation of the long
+     * @throws IllegalArgumentException if value '< 0' or '>= 2<sup>32</sup>'
+     */
+    public static int fromLong(long value)
+    {
+        return UnsignedInts.checkedCast(value);
+    }
+
+    /**
+     * Returns the long resulting from parsing the int as an unsigned integer
+     * 
+     * @param value Unsigned integer representation of the long
+     * @return The long resulting from parsing the int as an unsigned integer
+     */
+    public static long toLong(int value)
+    {
+        return UnsignedInts.toLong(value);
+    }
+    
+    /**
+     * Returns the long representation of the maximum value we can hold
+     */
+    public static long maxValueAsLong()
+    {
+        return MAX_VALUE_LONG;
+    }
+    
+    /**
+     * Returns the UInt representation of the maximum value we can hold
+     */
+    public static int maxValueAsUInt()
+    {
+        return MAX_VALUE_UINT;
+    }

Review Comment:
   I think callers can directly access the public `MAX_VALUE_LONG` and 
`MAX_VALUE_UINT` constants, making these two getters unnecessary. The nice 
JavaDoc can be moved to the constants.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to