LOGI - Java
type: channel
link: https://logi.im/tag/Java/
items: The Four Arithmetic Operation of BigInteger
items: Resolving Spring Boot Configuration Annotation Processor Not Configured Warning in IntelliJ IDEA
items: Field, Attribute, and Property in Java
items: Double Curly Braces Initialization in Java
items: java-concurrency-basics.html
items: directory-tree.html
items: annotations.html
items: aggregate-operations.html
items: lambda-expressions.html
items: concurrency.html

The Four Arithmetic Operation of BigInteger
type: item
date: 2022-01-04T08:32:00+00:00
description: 大整数的四则运算，很多数人都写过，本文提供一个 Java 版本的朴素实现，即模拟竖式。除法使用了递归，效率不高，递推公式如下：求商 = 连接( 被除数大于等于除数的最小前缀 / 除数, 逐位连接(上式余数, 被除数剩余部分)[期间, 若连接后的被除数小于除数, 商上零], [连接完毕后, 若被除数不小于除数, 求商(连接后的被除数, 除数)] )当商高于一千位时，递归版本栈溢出，改为等价迭代后，一亿位被除数测试通过。 Java Implementation package im.logi.math; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.function.BiFunction; import java.util.stream.IntStream; /** * @author logi * @version 1.0 * @time 2022/1/5 16:08 */ public class BigInteger implements Comparable<BigInteger>, Cloneable { private static final BigInteger ZERO = new BigInteger("0"); private static final BigInteger ONE = new BigInteger("1"); private boolean positive = true; private StringBuilder value; private BigInteger() { value = new StringBuilder(); } public BigInteger(String valueString) { int beginIndex = 0; if (valueString.charAt(0) == '-') { beginIndex = 1; positive = false; } else if (valueString.charAt(0) == '+') beginIndex = 1; while (beginIndex < valueString.length() && valueString.charAt(beginIndex) == '0') beginIndex++; // 仅是一个符号或全部为零，回退 if (beginIndex == valueString.length()) beginIndex--; value = new StringBuilder(valueString.length() - beginIndex); for (int i = beginIndex; i < valueString.length(); i++) { char c = valueString.charAt(i); if (c < '0' || c > '9') throw new IllegalArgumentException(); value.append(c); } setZeroPositive(); } // 只存正零 private void setZeroPositive() { if (value.length() == 1 && value.charAt(0) == '0') positive = true; } @Override protected Object clone() throws CloneNotSupportedException { BigInteger clone = (BigInteger) super.clone(); clone.positive = positive; clone.value = new StringBuilder(value); return clone; } @Override public boolean equals(Object obj) { if (obj instanceof BigInteger o) return positive == o.positive && value.toString().equals(o.value.toString()); return false; } @Override public int compareTo(BigInteger o) { if (positive != o.positive) return positive ? 1 : -1; int absRet = value.length() - o.valu…

Resolving Spring Boot Configuration Annotation Processor Not Configured Warning in IntelliJ IDEA
type: item
date: 2021-10-03T11:08:00+00:00
description: 在 IDEA 2021.2.2 中编写 Spring Boot 项目，打开使用了 @ConfigurationProperties 注解的类时，标签页下方会出现 Spring Boot Configuration Annotation Processor not configured 的提示，而提示给出的文档链接已经 404 了。搜索后发现 Spring Boot Configuration Annotation Processor 会扫描被 @ConfigurationProperties 注解的类，以此生成配置元数据，这些元数据可以被编译器读取用于 application.properties 中配置项的自动补全和错误检查。根据 Spring Boot 文档，只要引入相应依赖并重新编译项目便可生成配置元数据。但即便如此，IDEA 的提示有时并不消失，此时需要重载项目。之后，提示文字转为 Re-run Spring Boot Configuration Annotation Processor to update generated metadata，并且背景由红色转为深灰。这个提示只是在说，如果更改了类，记得重新编译更新元数据，并非警告，无需理会。此时打开 application.properties 就会发现自动补全已经可以正常使用了。网络上的一些文章说的打开 IDEA 设置里的 Enable annotation processing 实际是另一个功能，与此无关。[...]

Field, Attribute, and Property in Java
type: item
date: 2021-09-13T12:59:00+00:00
description: FieldA data member of a class. Unless specified otherwise, a field is not static.类的数据成员。除非指定，它不是静态的。举例：public class Customer { // Fields of Customer final String field1 = "Fixed Value"; int name; }AttributeAn attribute is another term for a field. It’s typically a public field that can be accessed directly.Field 的别称，它通常是可以直接访问的 public field，例如数组的长度。（Java SE 术语表中无此定义）PropertyCharacteristics of an object that users can set, such as the color of a window.对象的特征，用户可以设置它，例如窗户的颜色。举例：public class Window { // Property of Window private String color; public String getColor() { return this.color; } public void setColor(String color) { this.color = color; } }ReferencesWhat is the difference between field, variable, attribute, and property in JavaWhat is the difference between field, variable, attribute, and property in Java POJOs?Glossary of Terms

Double Curly Braces Initialization in Java
type: item
date: 2021-08-26T09:19:00+00:00
description: 准备给之前 Python 写的 QQ 机器人加点功能，发现升级后的依赖库变动很大，加上之前有些 Bug，瞬间不想用了，用上游框架重写吧。上游项目基于 Kotlin，我不熟悉，但提供 Java API，克隆示例代码，OK，可以运行。正准备往前推进，突然发现 有段代码 的语法我竟然看不懂，心想 Java 用了挺长时间不至于吧。[...]