java

Log4j appender for debug output if test fails

╄→гoц情女王★ 提交于 2021-02-19 01:35:15
问题 I would like to set up my test-logging so that log output is mainly suppressed - unless a test fails. then I would like to have the debug output. I know the manual solution of just modifying the log4j.properties in the test classpath or just having debug logging always active for tests - but I don't want to spam the console with unnessesary output for green tests. For failing tests I want the automatic build to give me the debug output in case there are some weired environment issues going on

Java 8 streams adding values from two or more lists

百般思念 提交于 2021-02-19 01:33:19
问题 I am trying to get into Java 8 and get my head around streams and lambdas to solve various problems and got stuck on this specific one which I normally use a forEach and store the values in a Map to solve. How would you write the code to get the expected list using the new features in Java 8 ? List<Integer> voterA = Arrays.asList(1,2,3,4,5); List<Integer> voterB = Arrays.asList(1,2,3,4,5); List<List<Integer>> votes = Arrays.asList(voterA, voterB); // expected list = (2,4,6,8,10) List<Integer>

What's the meaning of “CGC” and “CGCT” in JDK11 “jstat -gc <PID>”?

若如初见. 提交于 2021-02-19 01:33:13
问题 There are two items called CGC and CGCT. I cannot found the documention and man page describing their meaning. # jstat -gc 139934 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT CGC CGCT GCT 0.0 15360.0 0.0 15360.0 113664.0 9216.0 88064.0 23552.0 82304.0 80084.2 10112.0 9360.4 10 0.157 0 0.000 6 0.018 0.175 # java -version openjdk version "11.0.2" 2019-01-15 LTS OpenJDK Runtime Environment Corretto-11.0.2.9.3 (build 11.0.2+9-LTS) OpenJDK 64-Bit Server VM Corretto-11.0.2.9.3

Cloud Firestore - Dynamic Querying

独自空忆成欢 提交于 2021-02-19 01:32:05
问题 I have a Collection in Cloud Firestore that has a certain number of items, let's call it Collection "X". This number of items will constantly be changing. At any given time, I want to listen for the number of items in this Collection and create several whereEqualto() calls on a Query object that is based on another 'Collection', let's call it "Y": Query queryStore = FirebaseFirestore.getInstance() .collection("Y") .whereEqualTo(USER_ID_LABEL, "item 1 from X") .whereEqualTo(USER_ID_LABEL,

Are there any drawbacks with ConcurrentHashMap?

好久不见. 提交于 2021-02-19 01:31:55
问题 I need a HashMap that is accessible from multiple threads. There are two simple options, using a normal HashMap and synchronizing on it or using a ConcurrentHashMap. Since ConcurrentHashMap does not block on read operations it seems much better suited for my needs (almost exclusively reads, almost never updates). On the other hand, I expect very low concurrency anyway, so there should be no blocking (just the cost of managing the lock). The Map will also be very small (under ten entries), if

Jsoup Import Errors

大城市里の小女人 提交于 2021-02-19 01:30:08
问题 I'm looking to do some web crawling/scraping and I did some research and discovered Jsoup. The only problem I'm having is with the imports. The videos I've watched and examples I've seen have all had matching code to mine but for whatever reason their imports worked and mine don't. All four of mine give the error: The import org.jsoup cannot be resolved. Please help. package com.stackoverflow.q2835505; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element;

Remove empty line from a multi-line string with Java

旧时模样 提交于 2021-02-19 01:28:45
问题 I have a multi-line string and some empty lines between other lines. It looks like: def msg = """ AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE TEST FFFFF GGGGGG """ I tried some regex expression with : msg = msg.replaceAll('(\n\\\\s+\n)+', '') Or msg = msg.replaceAll('(\r?\n){2,}', '$1'); But nothing is good about what I'm looking... Is it possible to remove only empty lines? to get something like that : def msg = """ AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE TEST FFFFF GGGGGG """ 回答1: Use regex (?m)^[ \t]*\r

Remove empty line from a multi-line string with Java

元气小坏坏 提交于 2021-02-19 01:27:10
问题 I have a multi-line string and some empty lines between other lines. It looks like: def msg = """ AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE TEST FFFFF GGGGGG """ I tried some regex expression with : msg = msg.replaceAll('(\n\\\\s+\n)+', '') Or msg = msg.replaceAll('(\r?\n){2,}', '$1'); But nothing is good about what I'm looking... Is it possible to remove only empty lines? to get something like that : def msg = """ AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE TEST FFFFF GGGGGG """ 回答1: Use regex (?m)^[ \t]*\r

Use jackson annotation JsonUnwrapped on a field with name different from its getter

穿精又带淫゛_ 提交于 2021-02-19 01:26:07
问题 I have a class like: class Car { private Engine myEngine; @JsonProperty("color") private String myColor; @JsonProperty("maxspeed") private int myMaxspeed; @JsonGetter("color") public String getColor() { return myColor; } @JsonGetter("maxspeed") public String getMaxspeed() { return myMaxspeed; } public Engine getEngine() { return myEngine; } } and Engine class like class Engine { @JsonProperty("fueltype") private String myFueltype; @JsonProperty("enginetype") private String myEnginetype;

Significance of a PATH explained

大城市里の小女人 提交于 2021-02-19 01:20:18
问题 This is probably a rudimentary question but I am still kinda new to programming and I've wondered for awhile. I've done multiple projects in Python, C#, and Java, and when I try to use new libraries (especially for Python) people always say to make sure its in the right PATH and such. I just followed an online tutorial on how to install Java on a new computer and it rekindled my question of what a path really is. Is the Path just were the programming language looks for a library in the file