scribbledecobble
scribbledecobble.blogspot.com
Pages
Home
Contents
A
…
K
Land of the Lost
README
See also
Your Ad Here
Code
import java.util.Map; public class LandOfTheLost { public static void main(String[] args) { String valuableData; final StringBuilder message = new StringBuilder(); try { final Map
treasureMap = System.getenv(); for (String key : treasureMap.keySet()) { if (message.length() > 0) { message.append("\n"); } valuableData = treasureMap.get(key); message.append(key + ": " + valuableData); } } catch (SecurityException e) { message.append("FREEDOM OF INFORMATION? FACT:\n"); message.append("Your request has been denied.\n"); message.append("Information is valuable.\n"); message.append("(Your Ad Here)"); } System.out.print(message.toString()); } }
import java.util.Map; public class LandOfTheLost { public static void main(String[] args) { String valuableData; final ExtensibleMessage message = new VarMessage(); try { final Map
treasureMap = System.getenv(); for (String key : treasureMap.keySet()) { if (message.length() > 0) { message.append("\n"); } valuableData = treasureMap.get(key); message.append(key + ": " + valuableData); } } catch (SecurityException e) { message.append("FREEDOM OF INFORMATION? FACT:\n"); message.append("Your request has been denied.\n"); message.append("Information is valuable.\n"); message.append("(Your Ad Here)"); } output(message.toString()); } private static void output(String text) { System.out.print(text); } } interface Message { public int length(); public String toString(); } interface ExtensibleString { public void append(String text); } abstract class ExtensibleMessage implements Message, ExtensibleString { } class VarMessage extends ExtensibleMessage { final private StringBuilder message; public VarMessage() { message = new StringBuilder(); } public void append(String text) { message.append(text); } public int length() { return message.length(); } public String toString() { return message.toString(); } } class ConstMessage implements Message { final private String message; public ConstMessage(String text) { message = text; } public void append(String text) { throw new UnsupportedOperationException(); } public int length() { return message.length(); } public String toString() { return message.toString(); } }
Newer Post
Older Post
Home