One of the lang packages for JDK source code learning

JAVA programming ideas, Chapter 1, have a deep understanding of the concept of objects and access rights


JDK, see Math
The of method of the Character class, where the binary search method is used
public static UnicodeBlock of(int codePoint) {
            if (!isValidCodePoint(codePoint)) {
                throw new IllegalArgumentException();
            }

            int top, bottom, current;
            bottom = 0;
            top = blockStarts.length;
            current = top/2;

            // invariant: top > current >= bottom && codePoint >= unicodeBlockStarts[bottom]
            while (top - bottom > 1) {
                if (codePoint >= blockStarts[current]) {
                    bottom = current;
                } else {
                    top = current;
                }
                current = (top + bottom) / 2;
            }
            return blocks[current];
        }



The compare method of the Double class, which is more elegant here
 
return (thisBits == anotherBits ?  0 : // Values are equal
                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
                 1)); // (0.0, -0.0) or (NaN,! NaN)

And some displacement operators in Integer (<<, >>, >>>, etc.)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325984919&siteId=291194637