Prevent memory leaks with static classes
As cuixiaoyiyi puts it on github: "An anonymous inner class will hold a reference to the this pointer of the outer class and will not be released until the thread ends. It will hold the Activity and prevent its timely release."
Fetching a sum from a subtree
Imagine you have a domain-object which is organized in a tree structure. Additionally there are detached objects that reference a part of this structure. Now you need to collect some value from the referenced portion of the tree. You can identify the TreeOrganizedObjects by their UUID. Here is how you can do it in Java:
- Weiterlesen über Fetching a sum from a subtree
- Anmelden, um Kommentare verfassen zu können
Usage of BooleanQuery and TermsQuery in Lucene Search
When dealing with entities that have many references, you might encounter the BooleanQuery.maxClauseCount which is 1024 by default. This value is already pretty high. But if a query exceeds this value, you should be aware that this is a warning indicator for your performance.
A TermsQuery might be more appropriate in this case, looking somewhat like
result = result.filter(f.terms().field("entity_id").matchingAny(idList.stream().map(idToSearch -> String.valueOf(idToSearch)).collect(Collectors.toList())));
- Weiterlesen über Usage of BooleanQuery and TermsQuery in Lucene Search
- Anmelden, um Kommentare verfassen zu können
HashSieb des Eratosthenes
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Dijkstra
/**
* Kürzeste Wege in einem Graphen ermitteln
*
* @author neubauer 03.12.2022 create
*/
public class Dijkstra
{
// grün = leere Menge
// gelb = ausgangselement
// distanz von v = 0
// so lange menge der gelben elemente nicht leer ist
// wähle das element aus den gelben elementen mit der geringsten Entfernung als w