我需要找出第一个最外层(不是嵌套)括号索引.
例如
[] output: 0, 1
1[2] output: 1, 3
3[a2[c]]2[abc]3[cd] output: 1, 7
Run Code Online (Sandbox Code Playgroud)
我可以通过很多条件找到它,当前代码:
public static void main(String[] args) {
String input = "3[a2[c]]2[abc]3[cd]ef";
int first = 0;
int second = 0;
int count = 0;
boolean found = false;
for (int index = 0; index < input.length(); index++) {
if (input.charAt(index) == '[') {
count++;
if (found == false) {
found = true;
first = index;
}
} else if (input.charAt(index) == ']') {
count--;
if (found && …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Data Jpa,这是我的项目结构:
App
ConfigPackage
MyConfig
ServicePackage
MyService
RepositoryPackage
MyRepository
Run Code Online (Sandbox Code Playgroud)
这是MyRepository:
public interface MyRepository extends JpaRepository<MyEntity, Long> {
}
Run Code Online (Sandbox Code Playgroud)
这是MyService:
@Service
public class MyService {
@Autowired
private MyRepository myRepository; <---here
...
}
Run Code Online (Sandbox Code Playgroud)
这是MyConfig:
@Configuration
@EnableJpaRepositories(
basePackages = "RepositoryPackage",
entityManagerFactoryRef = "xxx",
transactionManagerRef = "xxx"
)
public class MyConfig {
}
Run Code Online (Sandbox Code Playgroud)
我用@Autowired注入MyRepository到MyService,但的IntelliJ总是抱怨
无法自动接线。找不到“ MyRepository”类型的bean
即使代码可以编译并成功运行。
为什么IntelliJ无法识别这不是错误?如何清除IntelliJ的警告?
IntelliJ版本:2018.2.6
假设我有一个处理器生成的 100 个流文件,每个文件都包含不同的行。我想要一个包含 100 行的新流文件。我怎样才能做到这一点?
我尝试过 MergeContent 处理器,但它给了我原始 100 个流文件。
当前配置:
更新:
MergeContent我调试了第一步的输出JOIN,看起来没问题,因为数据576.34 KB包含 100 行。但第二步ATTRIBUTES_MODIFIED似乎只输出1行到最终结果。
更新:
这就是我的整个过程。
现在我陷入了第3步,无法将它们一一合并。我不在乎顺序或属性,我只需要限制数量。
更新:
我尝试设置 correlation attribute为${kafka.topic},因为来自同一 kafka 主题的所有流文件,但它们仍然无法合并:
看来,HALF_EVEN舍入模式在Java中的工作方式不同DecimalFormat比BigDecimal.有什么办法DecimalFormat可以保持一致吗?
// Using BigDecimal scale
System.out.println("Big decimal scale (HALF_EVEN) of 21.255 ==> " + new BigDecimal("21.255").setScale(2, RoundingMode.HALF_EVEN));
System.out.println("Big decimal scale (HALF_EVEN) of 21.265 ==> " + new BigDecimal("21.265").setScale(2, RoundingMode.HALF_EVEN));
// Using DecimalFormat
DecimalFormat cdf = new DecimalFormat("#,##0.00");
cdf.setRoundingMode(RoundingMode.HALF_EVEN); // default anyway
System.out.println("Decimal format (HALF_EVEN) of 21.255 ==> " + cdf.format(21.255));
System.out.println("Decimal format (HALF_EVEN) of 21.265 ==> " + cdf.format(21.265));
Output:
Big decimal scale (HALF_EVEN) of 21.255 ==> 21.26
Big decimal scale (HALF_EVEN) …Run Code Online (Sandbox Code Playgroud) 我使用的List<String[]>是一些较小的案例字段.
List<String[]> csvBody = reader.readAll();
Run Code Online (Sandbox Code Playgroud)
我的输出应该是相同的数据类型List<String[]>.
是否有可能将我的Container中的每个String转换为一个伸展的大写?
我有以下代码:
public Trail getNewestTrail() {
return trails.stream().max(Comparator.comparing(Trail::getTimestamp)).orElseThrow(NoSuchElementException::new);
}
Run Code Online (Sandbox Code Playgroud)
如果没有将getNewestTrail声明为抛出异常,我没有看到任何错误 - 为什么?
我知道如何获得int[]一系列数字:
int[] array = IntStream.of(0, 3).toArray();
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能得到固定长度和一个特定数字呢?
我很难理解为什么以下代码不是异常的子类,但为什么会编译:
class Test
{
public void run() throws IOException
{
System.out.println("Test");
}
}
class SubTest extends Test
{
//not a subclass of IOException, still compiles
public void run() throws RuntimeException
{
System.out.println("Test from sub");
}
}
class Sub2Test extends Test
{
//not a subclass of IOException, does not compile
public void run() throws Exception
{
System.out.println("Test from sub");
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这RuntimeException是一个未经检查的异常,但是我认为规则是它必须是父异常的子类?
据我所知,.是java正则表达式中的一个元字符。但是当我如下使用它时:
String s = "1.2.3.4";
Pattern pattern = Pattern.compile("[\\.]");
Run Code Online (Sandbox Code Playgroud)
我收到Redundant Character Escape来自 IntelliJ IDEA 的警告。有什么解释吗?
java ×8
exception ×2
string ×2
algorithm ×1
apache-flink ×1
apache-nifi ×1
bigdecimal ×1
double ×1
java-8 ×1
java-stream ×1
regex ×1
rounding ×1
spring ×1
spring-boot ×1