Created
February 19, 2013 11:14
-
-
Save ludovicc/4984963 to your computer and use it in GitHub Desktop.
Unicorn for this puzzle: http://zeroturnaround.com/fun/magical-java-puzzle-pat-the-unicorns/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Unicorn { | |
private static StackTraceElement[] previousTrace; | |
public static boolean pat() { | |
Throwable t = new Exception(); | |
StackTraceElement[] trace = t.getStackTrace(); | |
if (previousTrace == null) { | |
previousTrace = trace; | |
return true; | |
} | |
boolean newTrace = false; | |
for (int i = 0; i < trace.length; i++) { | |
if (!trace[i].equals(previousTrace[i])) { | |
newTrace = true; | |
break; | |
} | |
} | |
if (newTrace) { | |
previousTrace = trace; | |
} | |
return newTrace; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment