Skip to content

How can this Java tree be 1000 x faster?

I am programming an AI for a chess-like game, based on two types of pieces on a 8 x 8 grid. I want to build a kind of minmax tree, which represents each possible move in a game, played by white players in first, and by black players in second. I have this generate() method which is call recursively. I

JUnit: testing helper class with only static methods

I am testing a helper class with only static methods with JUnit4 and Cobertura. Testing methods was easy task and is done already. However, cobertura shows that the class is not covered by tests completely, as it is not instantiated anywhere. I don’t want to create an instance of this class (it is a hel…

android – How to detect application being activated

When the app is launched, Application onCreate is called. How to detect when the app is brought to front from running in background? Answer Look for onResume() method. Its is always called when your app comes foreground. As per google docs: The foreground lifetime of an activity happens between a call to onRe…

Get domain name from given url

Given a URL, I want to extract domain name(It should not include ‘www’ part). Url can contain http/https. Here is the java code that I wrote. Though It seems to work fine, is there any better approach or are there some edge cases, that could fail. Input: http://google.com/blah Output: google.com A…