I can’t seem to figure out the time complexity for this algorithm. I know that the while loop will execute at O(log n) times because n keeps halving. But I’m not super sure how to represent the time complexity of the inner for loop. Answer Each while loop divides n by 2. Therefore, the first for l…
Tag: java
Protect a SXSSFWorkbook (Excel) and convert it to a byte array
I am working on a Java function which is expected to return a protected Excel file (xlsx) in byte array. I found a solution which used the Encryption support of Apache POI: How to Protect Excel Workbook Via SXSSF? However, OutputStream cannot be cast into ByteArrayOutputStream. I tried to find a way to conver…
How to reuse validator class in spring boot app?
I am currently writing custom validator for Spring Boot app and its idea is mainly to do some validations depending on other validations. For example, I want one field to be @NotNull if some other field is null, but the idea is to make it more generic, so that this conditional validations can be changed. For …
JPA pagination query becomes slower with every subsequent call
Project has Spring Boot with JPA. We have a table vehicle with 1m+ records. Table has an indexed field type. We have a use case, where we want to fetch all the records by type. For each type, we get all the vehicle records, then for next type, then for next and so on. Since there are 1m+ records, we
Java ParallelStream: several map or single map
Introduction I’m currently developing a program in which I use Java.util.Collection.parallelStream(), and wondering if it’s possible to make it more Multi-threaded. Several small map I was wondering if using multiple map might allow the Java.util.Collection.parallelStream() to distribute the tasks…
Spring Boot cannot create database table in mysql 5.7
I’d like to create a table called dni with that information in mysql server. Querys that failed: 1.”create table dni (id bigint not null, apellidos varchar(255), codigo_dni varchar(255), direccion varchar(255), fecha_nacimiento varchar(255), foto_perfil varchar(255), nombre varchar(255), primary k…
How to query mongodb with query Builder in java?
I need to make a query in java to MongoDB, how could I do it with QueryBuilder, this is my query: By the way, if anyone knows where I can find documentation to make these queries, I would appreciate it. Answer You should Refer this documentation Create a MongoCollection object. Create a list to have aggregate…
Suspicious call to ‘LinkedHashMap.get’
Hello I have the following code Since the Object I use as a Key is dynamically generated I have no knowledge about it so I have to find it before I can use it to get its value. This code gives me the warning Suspicious call to ‘LinkedHashMap.get’, is that a problem and how would I get rid of the
Unable to load config data to springboot application from mounted volume in kubernetes
I have springboot application and I am trying to load additional configuration from a volume mounted location /tmp/secret-config.yaml and getting below error: java.lang.IllegalStateException: Unable to load config data from ‘/tmp/secret-config.yaml’ I do not want to use configmap or secrets for th…
Does the Kafka Streams StreamBuilder always detect “duplicate” input topics?
This code creates two KStream instances separately, both are reading from the same topic: The topology looks like this: There is only one source definition which is then used two times: Now my question is: Is it always safe to assume that the StreamBuilder creates only one source (= only one consumer for the …