Input:
    private void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = null;
        String action = request.getParameter("Action");
        long ts1 = System.currentTimeMillis();
        try {
            valueAccumulator.initializeAllCounters();
        	requestInit();
            response.setContentType("text/xml");
            if (!isValidAction(action)) {
                throw new CMBException(CMBErrorCodes.InvalidAction, action + " is not a valid action");
            }
            if (isAuthenticationRequired(action)) {
                user = authModule.authenticateByRequest(request);
            } else {
                user = null;
            }
            long ts3 = System.currentTimeMillis();
            valueAccumulator.addToCounter(AccumulatorName.CMBControllerPreHandleAction, (ts3 - ts1));
            boolean actionPerformed = handleAction(action, user, request, response);
            response.setStatus(200);
            long ts2 = System.currentTimeMillis();
            if (action != null && action.equals("ReceiveMessage") && !actionPerformed && user != null && user.getUserName().equals(CMBProperties.getInstance().getCnsUserName())) {
            } else if (action != null && action.equals("GetQueueUrl") && user != null && user.getUserName().equals(CMBProperties.getInstance().getCnsUserName())) {
            } else {
	            logger.info(
	            		"event=handleRequest status=success client_ip=" + request.getRemoteAddr() + " action=" + action + " responseTimeMS=" + (ts2-ts1) +
	                    (request.getParameter("TopicArn") != null ? " topic_arn=" + request.getParameter("TopicArn") : "") +
	                    (request.getParameter("SubscriptionArn") != null ? " subscription_arn=" + request.getParameter("SubscriptionArn") : "") +
	                    (request.getParameter("Label") != null ? " label=" + request.getParameter("Label") : "") +
	                    (request.getParameter("NextToken") != null ? " next_token=" + request.getParameter("NextToken") : "") +
	                    (request.getParameter("Name") != null ? " name=" + request.getParameter("Name") : "") +
	                    (request.getParameter("Token") != null ? " token=" + request.getParameter("Token") : "") +
	                    (request.getParameter("Endpoint") != null ? " endpoint=" + request.getParameter("Endpoint") : "") +
	                    (request.getParameter("Protocol") != null ? " protocol=" + request.getParameter("Protocol") : "") +
	                    (request.getParameter("ReceiptHandle") != null ? " receipt_handle=" + request.getParameter("ReceiptHandle") : "") +
	                    (request.getParameter("VisibilityTimeout") != null ? " visibility_timeout=" + request.getParameter("VisibilityTimeout") : "") +
	                    (request.getParameter("QueueName") != null ? " queue_name=" + request.getParameter("QueueName") : "") +
	                    (request.getParameter("QueueNamePrefix") != null ? " queue_name_prefix=" + request.getParameter("QueueNamePrefix") : "") +
	                    (request.getParameter("DelaySeconds") != null ? " delay_seconds=" + request.getParameter("DelaySeconds") : "") +
	                    ((this instanceof CQSControllerServlet) ? (" queue_url=" + request.getRequestURL().toString()) : "") +
	            		" CassandraTimeMS=" + valueAccumulator.getCounter(AccumulatorName.CassandraTime) +
	                    " CassandraReadNum=" + valueAccumulator.getCounter(AccumulatorName.CassandraRead) +
	                    " CassandraWriteNum=" + valueAccumulator.getCounter(AccumulatorName.CassandraWrite) +
	                    ((this instanceof CNSControllerServlet) ? (" CNSCQSTimeMS=" + CMBControllerServlet.valueAccumulator.getCounter(AccumulatorName.CNSCQSTime)) : "") +
	                    ((this instanceof CQSControllerServlet) ? (" RedisTimeMS=" + valueAccumulator.getCounter(AccumulatorName.RedisTime)) : "") +
	                    (user != null ? " user_name=" + user.getUserName() : "")
	            );
            }
        } catch (Exception ex) {
        	long ts2 = System.currentTimeMillis();
            logger.error(
            		"event=handleRequest status=failed client_ip=" + request.getRemoteAddr() + " action=" + action + " responseTimeMS=" + (ts2-ts1) +
                    (request.getParameter("TopicArn") != null ? " topic_arn=" + request.getParameter("TopicArn") : "") +
                    (request.getParameter("SubscriptionArn") != null ? " subscription_arn=" + request.getParameter("SubscriptionArn") : "") +
                    (request.getParameter("Label") != null ? " label=" + request.getParameter("Label") : "") +
                    (request.getParameter("NextToken") != null ? " next_token=" + request.getParameter("NextToken") : "") +
                    (request.getParameter("Name") != null ? " name=" + request.getParameter("Name") : "") +
                    (request.getParameter("Token") != null ? " token=" + request.getParameter("Token") : "") +
                    (request.getParameter("Endpoint") != null ? " endpoint=" + request.getParameter("Endpoint") : "") +
                    (request.getParameter("Protocol") != null ? " protocol=" + request.getParameter("Protocol") : "") +
                    (request.getParameter("ReceiptHandle") != null ? " receipt_handle=" + request.getParameter("ReceiptHandle") : "") +
                    (request.getParameter("VisibilityTimeout") != null ? " visibility_timeout=" + request.getParameter("VisibilityTimeout") : "") +
                    (request.getParameter("QueueName") != null ? " queue_name=" + request.getParameter("QueueName") : "") +
                    (request.getParameter("QueueNamePrefix") != null ? " queue_name_prefix=" + request.getParameter("QueueNamePrefix") : "") +
                    (request.getParameter("DelaySeconds") != null ? " delay_seconds=" + request.getParameter("DelaySeconds") : "") +
                    ((this instanceof CQSControllerServlet) ? (" queue_url=" + request.getRequestURL().toString()) : "") +
            		" CassandraTimeMS=" + valueAccumulator.getCounter(AccumulatorName.CassandraTime) +
                    " CassandraReadNum=" + valueAccumulator.getCounter(AccumulatorName.CassandraRead) +
                    " CassandraWriteNum=" + valueAccumulator.getCounter(AccumulatorName.CassandraWrite) +
                    ((this instanceof CNSControllerServlet) ? (" CNSCQSTimeMS=" + CMBControllerServlet.valueAccumulator.getCounter(AccumulatorName.CNSCQSTime)) : "") +
                    ((this instanceof CQSControllerServlet) ? (" RedisTimeMS=" + valueAccumulator.getCounter(AccumulatorName.RedisTime)) : "") +
                    (user != null ? " user_name=" + user.getUserName() : ""), ex
            );
            int httpCode = CMBErrorCodes.InternalError.getHttpCode();
            String code = CMBErrorCodes.InternalError.getCMBCode();
            String message = "There is an internal problem with CMB";
            if (ex instanceof CMBException) {
                httpCode = ((CMBException) ex).getHttpCode();
                code = ((CMBException) ex).getCMBCode();
                message = ex.getMessage();
            }
            String errXml = createErrorResponse(code, message);
            response.setStatus(httpCode);
            response.getWriter().println(errXml);
        } finally {
            valueAccumulator.deleteAllCounters();
        }
    }

Output:
    private void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = null;
        String action = request.getParameter("Action");
        long ts1 = System.currentTimeMillis();
        try {
            valueAccumulator.initializeAllCounters();
        	requestInit();
            response.setContentType("text/xml");
            if (!isValidAction(action)) {
                throw new CMBException(CMBErrorCodes.InvalidAction, action + " is not a valid action");
            }
            if (isAuthenticationRequired(action)) {
                user = authModule.authenticateByRequest(request);
            } else {
                user = null;
            }
            long ts3 = System.currentTimeMillis();
            valueAccumulator.addToCounter(AccumulatorName.CMBControllerPreHandleAction, (ts3 - ts1));
            boolean actionPerformed = handleAction(action, user, request, response);
            response.setStatus(200);
            long ts2 = System.currentTimeMillis();
            if (action != null && action.equals("ReceiveMessage") && !actionPerformed && user != null && user.getUserName().equals(CMBProperties.getInstance().getCnsUserName())) {
            } else if (action != null && action.equals("GetQueueUrl") && user != null && user.getUserName().equals(CMBProperties.getInstance().getCnsUserName())) {
            } else {
	            logger.info(
	            		"event=handleRequest status=success client_ip=" + request.getRemoteAddr() + " action=" + action + " responseTimeMS=" + (ts2-ts1) +
	                    (request.getParameter("TopicArn") != null ? " topic_arn=" + request.getParameter("TopicArn") : "") +
	                    (request.getParameter("SubscriptionArn") != null ? " subscription_arn=" + request.getParameter("SubscriptionArn") : "") +
	                    (request.getParameter("Label") != null ? " label=" + request.getParameter("Label") : "") +
	                    (request.getParameter("NextToken") != null ? " next_token=" + request.getParameter("NextToken") : "") +
	                    (request.getParameter("Name") != null ? " name=" + request.getParameter("Name") : "") +
	                    (request.getParameter("Token") != null ? " token=" + request.getParameter("Token") : "") +
	                    (request.getParameter("Endpoint") != null ? " endpoint=" + request.getParameter("Endpoint") : "") +
	                    (request.getParameter("Protocol") != null ? " protocol=" + request.getParameter("Protocol") : "") +
	                    (request.getParameter("ReceiptHandle") != null ? " receipt_handle=" + request.getParameter("ReceiptHandle") : "") +
	                    (request.getParameter("VisibilityTimeout") != null ? " visibility_timeout=" + request.getParameter("VisibilityTimeout") : "") +
	                    (request.getParameter("QueueName") != null ? " queue_name=" + request.getParameter("QueueName") : "") +
	                    (request.getParameter("QueueNamePrefix") != null ? " queue_name_prefix=" + request.getParameter("QueueNamePrefix") : "") +
	                    (request.getParameter("DelaySeconds") != null ? " delay_seconds=" + request.getParameter("DelaySeconds") : "") +
	                    ((this instanceof CQSControllerServlet) ? (" queue_url=" + request.getRequestURL()) : "") +
	            		" CassandraTimeMS=" + valueAccumulator.getCounter(AccumulatorName.CassandraTime) +
	                    " CassandraReadNum=" + valueAccumulator.getCounter(AccumulatorName.CassandraRead) +
	                    " CassandraWriteNum=" + valueAccumulator.getCounter(AccumulatorName.CassandraWrite) +
	                    ((this instanceof CNSControllerServlet) ? (" CNSCQSTimeMS=" + CMBControllerServlet.valueAccumulator.getCounter(AccumulatorName.CNSCQSTime)) : "") +
	                    ((this instanceof CQSControllerServlet) ? (" RedisTimeMS=" + valueAccumulator.getCounter(AccumulatorName.RedisTime)) : "") +
	                    (user != null ? " user_name=" + user.getUserName() : "")
	            );
            }
        } catch (Exception ex) {
        	long ts2 = System.currentTimeMillis();
            logger.error(
            		"event=handleRequest status=failed client_ip=" + request.getRemoteAddr() + " action=" + action + " responseTimeMS=" + (ts2-ts1) +
                    (request.getParameter("TopicArn") != null ? " topic_arn=" + request.getParameter("TopicArn") : "") +
                    (request.getParameter("SubscriptionArn") != null ? " subscription_arn=" + request.getParameter("SubscriptionArn") : "") +
                    (request.getParameter("Label") != null ? " label=" + request.getParameter("Label") : "") +
                    (request.getParameter("NextToken") != null ? " next_token=" + request.getParameter("NextToken") : "") +
                    (request.getParameter("Name") != null ? " name=" + request.getParameter("Name") : "") +
                    (request.getParameter("Token") != null ? " token=" + request.getParameter("Token") : "") +
                    (request.getParameter("Endpoint") != null ? " endpoint=" + request.getParameter("Endpoint") : "") +
                    (request.getParameter("Protocol") != null ? " protocol=" + request.getParameter("Protocol") : "") +
                    (request.getParameter("ReceiptHandle") != null ? " receipt_handle=" + request.getParameter("ReceiptHandle") : "") +
                    (request.getParameter("VisibilityTimeout") != null ? " visibility_timeout=" + request.getParameter("VisibilityTimeout") : "") +
                    (request.getParameter("QueueName") != null ? " queue_name=" + request.getParameter("QueueName") : "") +
                    (request.getParameter("QueueNamePrefix") != null ? " queue_name_prefix=" + request.getParameter("QueueNamePrefix") : "") +
                    (request.getParameter("DelaySeconds") != null ? " delay_seconds=" + request.getParameter("DelaySeconds") : "") +
                    ((this instanceof CQSControllerServlet) ? (" queue_url=" + request.getRequestURL()) : "") +
            		" CassandraTimeMS=" + valueAccumulator.getCounter(AccumulatorName.CassandraTime) +
                    " CassandraReadNum=" + valueAccumulator.getCounter(AccumulatorName.CassandraRead) +
                    " CassandraWriteNum=" + valueAccumulator.getCounter(AccumulatorName.CassandraWrite) +
                    ((this instanceof CNSControllerServlet) ? (" CNSCQSTimeMS=" + CMBControllerServlet.valueAccumulator.getCounter(AccumulatorName.CNSCQSTime)) : "") +
                    ((this instanceof CQSControllerServlet) ? (" RedisTimeMS=" + valueAccumulator.getCounter(AccumulatorName.RedisTime)) : "") +
                    (user != null ? " user_name=" + user.getUserName() : ""), ex
            );
            int httpCode = CMBErrorCodes.InternalError.getHttpCode();
            String code = CMBErrorCodes.InternalError.getCMBCode();
            String message = "There is an internal problem with CMB";
            if (ex instanceof CMBException) {
                httpCode = ((CMBException) ex).getHttpCode();
                code = ((CMBException) ex).getCMBCode();
                message = ex.getMessage();
            }
            String errXml = createErrorResponse(code, message);
            response.setStatus(httpCode);
            response.getWriter().println(errXml);
        } finally {
            valueAccumulator.deleteAllCounters();
        }
    }


Input:
	public static Set findApplicable(HttpServletRequest request, boolean instructorPrefOnly, boolean examPref) throws Exception {
    	User user = Web.getUser(request.getSession());
    	Session session = Session.getCurrentAcadSession(user);
    	TimetableManager mgr = TimetableManager.getManager(user);
    	if (user.isAdmin()) return findAll(instructorPrefOnly, examPref);
    	TreeSet ret = new TreeSet();
    	for (Iterator i=findAll(instructorPrefOnly,examPref).iterator();i.hasNext();) {
    		DistributionType dt = (DistributionType)i.next();
    		Set depts = dt.getDepartments(session.getUniqueId());
    		if (depts.isEmpty()) {
    			ret.add(dt);
    		} else {
    			boolean contains = false;
    			for (Iterator j=mgr.getDepartments().iterator();!contains && j.hasNext();) {
    				Department d = (Department)j.next();
    				if (depts.contains(d)) contains = true;
    			}
    			if (contains)
    				ret.add(dt);
    		}
    	}
    	return ret;
    }

Output:
	public static Set findApplicable(HttpServletRequest request, boolean instructorPrefOnly, boolean examPref) throws Exception {
    	User user = Web.getUser(request.getSession());
    	Session session = Session.getCurrentAcadSession(user);
    	TimetableManager mgr = TimetableManager.getManager(user);
    	if (user.isAdmin()) return findAll(instructorPrefOnly, examPref);
    	TreeSet ret = new TreeSet();
    	for (Iterator i=findAll(instructorPrefOnly,examPref).iterator();i.hasNext();) {
    		DistributionType dt = (DistributionType)i.next();
    		Set depts = dt.getDepartments(session==null?null:session.getUniqueId());
    		if (depts.isEmpty()) {
    			ret.add(dt);
    		} else {
    			boolean contains = false;
    			for (Iterator j=mgr.getDepartments().iterator();!contains && j.hasNext();) {
    				Department d = (Department)j.next();
    				if (depts.contains(d)) contains = true;
    			}
    			if (contains)
    				ret.add(dt);
    		}
    	}
    	return ret;
    }


Input:
    public List<Path> generate() throws IOException {
        List<Path> paths = new ArrayList<>();
        Map<String, List<Tick>> demomap = new LinkedHashMap<>();
        Map<String, String> peeknext = new LinkedHashMap<>();
        String previous = null;
        for (Tick tick : ticklist) {
            List<Tick> ticks;
            if (!demomap.containsKey(tick.getDemoname())) {
                ticks = new ArrayList<>();
                demomap.put(tick.getDemoname(), ticks);
            } else {
                ticks = demomap.get(tick.getDemoname());
            }
            ticks.add(tick);
            if (previous != null) {
                if (!peeknext.containsKey(previous) && !previous.equals(tick.getDemoname())) {
                    peeknext.put(previous, tick.getDemoname());
                }
            }
            previous = tick.getDemoname();
        }
        for (Entry<String, List<Tick>> e : demomap.entrySet()) {
            String demo = e.getKey();
            log.finer("creating vdm for demo: " + demo);
            List<String> lines = new ArrayList<>();
            lines.add("demoactions\n{");
            int count = 1;
            int previousEndTick = 0;
            for (Tick tick : e.getValue()) {
                lines.add(segment(count++, "SkipAhead", "skip",
                        "starttick \"" + (previousEndTick + 1) + "\"",
                        "skiptotick \"" + (tick.getStart() - 1) + "\""));
                lines.add(segment(count++, "PlayCommands", "startrec",
                        "commands \"startrecording\""));
                lines.add(segment(count++, "PlayCommands", "stoprec",
                        "starttick \"" + tick.getEnd() + "\"",
                        "commands \"stoprecording\""));
                previousEndTick = tick.getEnd();
            }
            String nextdemo = peeknext.get(demo);
            if (nextdemo != null) {
                lines.add(segment(count++, "PlayCommands", "nextdem",
                        "starttick \"" + (previousEndTick + 1) + "\"",
                        "commands \"playdemo " + nextdemo + "\""));
            } else {
                lines.add(segment(count++, "PlayCommands", "stopdem",
                        "starttick \"" + (previousEndTick + 1) + "\"",
                        "commands \"stopdemo\""));
            }
            lines.add("}\n");
            Path added = Files.write(
                    tfpath.resolve(demo.substring(0, demo.indexOf(".dem")) + ".vdm"), lines,
                    Charset.defaultCharset());
            paths.add(added);
            log.fine("VDM file written to " + added);
        }
        return paths;
    }

Output:
    public List<Path> generate() throws IOException {
        List<Path> paths = new ArrayList<>();
        Map<String, List<Tick>> demomap = new LinkedHashMap<>();
        Map<String, String> peeknext = new LinkedHashMap<>();
        String previous = null;
        for (Tick tick : ticklist) {
            List<Tick> ticks;
            if (!demomap.containsKey(tick.getDemoname())) {
                ticks = new ArrayList<>();
                demomap.put(tick.getDemoname(), ticks);
            } else {
                ticks = demomap.get(tick.getDemoname());
            }
            ticks.add(tick);
            if (previous != null) {
                if (!peeknext.containsKey(previous) && !previous.equals(tick.getDemoname())) {
                    peeknext.put(previous, tick.getDemoname());
                }
            }
            previous = tick.getDemoname();
        }
        for (Entry<String, List<Tick>> e : demomap.entrySet()) {
            String demo = e.getKey();
            log.finer("creating vdm for demo: " + demo);
            List<String> lines = new ArrayList<>();
            lines.add("demoactions\n{");
            int count = 1;
            int previousEndTick = 0;
            for (Tick tick : e.getValue()) {
                lines.add(segment(count++, "SkipAhead", "skip",
                        "starttick \"" + (previousEndTick + 1) + "\"",
                        "skiptotick \"" + (tick.getStart() - 1) + "\""));
                lines.add(segment(count++, "PlayCommands", "startrec",
                        "starttick \"" + tick.getStart() + "\"",
                        "commands \"startrecording\""));
                lines.add(segment(count++, "PlayCommands", "stoprec",
                        "starttick \"" + tick.getEnd() + "\"",
                        "commands \"stoprecording\""));
                previousEndTick = tick.getEnd();
            }
            String nextdemo = peeknext.get(demo);
            if (nextdemo != null) {
                lines.add(segment(count++, "PlayCommands", "nextdem",
                        "starttick \"" + (previousEndTick + 1) + "\"",
                        "commands \"playdemo " + nextdemo + "\""));
            } else {
                lines.add(segment(count++, "PlayCommands", "stopdem",
                        "starttick \"" + (previousEndTick + 1) + "\"",
                        "commands \"stopdemo\""));
            }
            lines.add("}\n");
            Path added = Files.write(
                    tfpath.resolve(demo.substring(0, demo.indexOf(".dem")) + ".vdm"), lines,
                    Charset.defaultCharset());
            paths.add(added);
            log.fine("VDM file written to " + added);
        }
        return paths;
    }


Input:
	public static ProjectData getGlobalProjectData()
	{
		if (globalProjectData != null)
			return globalProjectData;
		File dataFile = CoverageDataFileHandler.getDefaultDataFile();
		if (dataFile.isFile())
		{
			globalProjectData = CoverageDataFileHandler
					.loadCoverageData(dataFile);
		}
		if (globalProjectData == null)
		{
			System.out.println("Cobertura: Coverage data file "
							+ dataFile.getAbsolutePath()
							+ " either does not exist or is not readable.  Creating a new data file.");
			globalProjectData = new ProjectData();
			saveTimer = new SaveTimer();
			Runtime.getRuntime().addShutdownHook(new Thread(saveTimer));
		}
		return globalProjectData;
	}

Output:
	public static ProjectData getGlobalProjectData()
	{
		if (globalProjectData != null)
			return globalProjectData;
		File dataFile = CoverageDataFileHandler.getDefaultDataFile();
		if (dataFile.isFile())
		{
			globalProjectData = CoverageDataFileHandler
					.loadCoverageData(dataFile);
		}
		if (globalProjectData == null)
		{
			System.out.println("Cobertura: Coverage data file "
							+ dataFile.getAbsolutePath()
							+ " either does not exist or is not readable.  Creating a new data file.");
			globalProjectData = new ProjectData();
		}
		saveTimer = new SaveTimer();
		Runtime.getRuntime().addShutdownHook(new Thread(saveTimer));
		return globalProjectData;
	}


Input:
	public static void main(String[] args) {
		System.out.println("prueba trabajo 1");
	}

Output:
	public static void main(String[] args) {
		System.out.println("prueba trabajo 1qwdqwdqwd");
	}


Input:
    protected void initField(com.redhat.ceylon.compiler.typechecker.model.Declaration decl, java.lang.Class<?> javaClass, java.lang.Class<?> getterReturnType, Object instance) {
        if(decl instanceof JavaBeanValue){
            String setterName = ((JavaBeanValue) decl).getSetterName();
            try {
                Method m = javaClass.getMethod(setterName, getterReturnType);
                setter = MethodHandles.lookup().unreflect(m);
                setter = setter.bindTo(instance);
                setter = setter.asType(MethodType.methodType(void.class, getterReturnType));
                setter = MethodHandleUtil.unboxArguments(setter, 0, 1, new java.lang.Class[]{getterReturnType});
            } catch (NoSuchMethodException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            } catch (SecurityException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            }
        }else if(decl instanceof LazyValue){
            String setterName = Naming.getSetterName(decl);
            try {
                Method m = javaClass.getMethod(setterName, getterReturnType);
                setter = MethodHandles.lookup().unreflect(m);
                setter = setter.asType(MethodType.methodType(void.class, getterReturnType));
                setter = MethodHandleUtil.unboxArguments(setter, 0, 0, new java.lang.Class[]{getterReturnType});
            } catch (NoSuchMethodException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            } catch (SecurityException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            }
        }else
            throw new RuntimeException("Unsupported attribute type: "+decl);
    }

Output:
    protected void initField(com.redhat.ceylon.compiler.typechecker.model.Declaration decl, java.lang.Class<?> javaClass, java.lang.Class<?> getterReturnType, Object instance) {
        if(decl instanceof JavaBeanValue){
            String setterName = ((JavaBeanValue) decl).getSetterName();
            try {
                Method m = javaClass.getMethod(setterName, getterReturnType);
                setter = MethodHandles.lookup().unreflect(m);
                setter = setter.bindTo(instance);
                setter = setter.asType(MethodType.methodType(void.class, getterReturnType));
                setter = MethodHandleUtil.unboxArguments(setter, 0, 0, new java.lang.Class[]{getterReturnType});
            } catch (NoSuchMethodException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            } catch (SecurityException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            }
        }else if(decl instanceof LazyValue){
            String setterName = Naming.getSetterName(decl);
            try {
                Method m = javaClass.getMethod(setterName, getterReturnType);
                setter = MethodHandles.lookup().unreflect(m);
                setter = setter.asType(MethodType.methodType(void.class, getterReturnType));
                setter = MethodHandleUtil.unboxArguments(setter, 0, 0, new java.lang.Class[]{getterReturnType});
            } catch (NoSuchMethodException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            } catch (SecurityException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException("Failed to find setter method "+setterName+" for: "+decl, e);
            }
        }else
            throw new RuntimeException("Unsupported attribute type: "+decl);
    }


Input:
    protected static JPanel customFileChooser(final JDialog dlg, final JFileChooser chooser, final Action action) {
	Insets insets = null;
	if (chooser.getBorder() instanceof EmptyBorder)
	    insets = ((EmptyBorder)chooser.getBorder()).getBorderInsets();
	chooser.setControlButtonsAreShown(false);
	chooser.setApproveButtonText((String)action.getValue(Action.NAME));
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
	panel.add(chooser);
	JPanel contentpane = new JPanel();
	contentpane.setLayout(new BoxLayout(contentpane, BoxLayout.Y_AXIS));
	if (insets!=null) contentpane.setBorder(BorderFactory.createEmptyBorder(0, insets.left, 0, insets.right));
	panel.add(contentpane);
	JPanel btns = new JPanel();
	if (insets!=null) btns.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
	btns.add(Box.createHorizontalGlue());
	btns.setLayout(new BoxLayout(btns, BoxLayout.X_AXIS));
	final JButton activate = new JButton(new AbstractAction((String)action.getValue(Action.NAME)) {
	    public void actionPerformed(ActionEvent e) {
		chooser.approveSelection();
	    }
	});
	btns.add(activate);
	final JButton cancel = new JButton(new AbstractAction("Cancel") {
	    public void actionPerformed(ActionEvent e) {
		chooser.cancelSelection();
	    }
	});
	btns.add(cancel);
	panel.add(btns);
	dlg.getContentPane().add(panel);
	dlg.getRootPane().setDefaultButton(activate);
	dlg.setModal(true);
	chooser.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		if (JFileChooser.APPROVE_SELECTION.equals(e.getActionCommand())) {
		    if (chooser.getUI() instanceof BasicFileChooserUI) {
		        BasicFileChooserUI ui = (BasicFileChooserUI)chooser.getUI();
		        chooser.setSelectedFile(new File(ui.getFileName()));
		    }
		    action.actionPerformed(e);
		}
		dlg.removeAll();
		dlg.dispose();
	    }
	});
	return contentpane;
    }

Output:
    protected static JPanel customFileChooser(final JDialog dlg, final JFileChooser chooser, final Action action) {
	Insets insets = null;
	if (chooser.getBorder() instanceof EmptyBorder)
	    insets = ((EmptyBorder)chooser.getBorder()).getBorderInsets();
	chooser.setControlButtonsAreShown(false);
	chooser.setApproveButtonText((String)action.getValue(Action.NAME));
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
	panel.add(chooser);
	JPanel contentpane = new JPanel();
	contentpane.setLayout(new BoxLayout(contentpane, BoxLayout.Y_AXIS));
	if (insets!=null) contentpane.setBorder(BorderFactory.createEmptyBorder(0, insets.left, 0, insets.right));
	panel.add(contentpane);
	JPanel btns = new JPanel();
	if (insets!=null) btns.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
	btns.add(Box.createHorizontalGlue());
	btns.setLayout(new BoxLayout(btns, BoxLayout.X_AXIS));
	final JButton activate = new JButton(new AbstractAction((String)action.getValue(Action.NAME)) {
	    public void actionPerformed(ActionEvent e) {
		chooser.approveSelection();
	    }
	});
	btns.add(activate);
	final JButton cancel = new JButton(new AbstractAction("Cancel") {
	    public void actionPerformed(ActionEvent e) {
		chooser.cancelSelection();
	    }
	});
	btns.add(cancel);
	panel.add(btns);
	dlg.getContentPane().add(panel);
	dlg.getRootPane().setDefaultButton(activate);
	dlg.setModal(true);
	chooser.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		if (JFileChooser.APPROVE_SELECTION.equals(e.getActionCommand())) {
		    if (chooser.getUI() instanceof BasicFileChooserUI) {
		        BasicFileChooserUI ui = (BasicFileChooserUI)chooser.getUI();
		        File f = new File(chooser.getCurrentDirectory(), ui.getFileName());
		        chooser.setSelectedFile(f);
		    }
		    action.actionPerformed(e);
		}
		dlg.removeAll();
		dlg.dispose();
	    }
	});
	return contentpane;
    }


Input:
	public void handle(Willie bot, Channel channel, User sender, String[] args){
		if(args.length <= 0){
			channel.sendMessage("(" + sender.getNick() + ") Usage: !utime <time>[s|ms] [timezone]");
		}else{
			String time = args[0];
			String timezone = "GMT";
			if(args.length > 1){
				timezone = args[1];
			}
			long realTime = System.currentTimeMillis();
			String lowerTime = time.toLowerCase();
			long multiplier = 1000;
			if(lowerTime.endsWith("ms")){
				time = time.substring(0, time.length() - 2);
				multiplier = 1;
			}else if(lowerTime.endsWith("s")){
				time = time.substring(0, time.length() - 1);
			}
			if(!time.equalsIgnoreCase("now")){
				try{
					realTime = Long.parseLong(time);
				}catch(NumberFormatException e){
					channel.sendMessage("(" + sender.getNick() + ") [Invalid time format] Usage: !utime <time>[s|ms] [timezone]");
					return;
				}
			}
			realTime = realTime * multiplier;
			Date d = new Date(realTime);
			String formatted = new String();
			DateFormat dateFormat = DateFormat.getDateTimeInstance();
			TimeZone tz = TimeZone.getTimeZone(timezone);
			dateFormat.setTimeZone(tz);
			formatted = dateFormat.format(d) + " " + tz.getDisplayName();
			channel.sendMessage("(" + sender.getNick() + ") " + formatted);
		}
	}

Output:
	public void handle(Willie bot, Channel channel, User sender, String[] args){
		if(args.length <= 0){
			channel.sendMessage("(" + sender.getNick() + ") Usage: !utime <time>[s|ms] [timezone]");
		}else{
			String time = args[0];
			String timezone = "GMT";
			if(args.length > 1){
				timezone = args[1];
			}
			long realTime = System.currentTimeMillis();
			String lowerTime = time.toLowerCase();
			long multiplier = 1000;
			if(lowerTime.endsWith("ms")){
				time = time.substring(0, time.length() - 2);
				multiplier = 1;
			}else if(lowerTime.endsWith("s")){
				time = time.substring(0, time.length() - 1);
			}
			if(!time.equalsIgnoreCase("now")){
				try{
					realTime = Long.parseLong(time);
					multiplier = 1;
				}catch(NumberFormatException e){
					channel.sendMessage("(" + sender.getNick() + ") [Invalid time format] Usage: !utime <time>[s|ms] [timezone]");
					return;
				}
			}
			realTime = realTime * multiplier;
			Date d = new Date(realTime);
			String formatted = new String();
			DateFormat dateFormat = DateFormat.getDateTimeInstance();
			TimeZone tz = TimeZone.getTimeZone(timezone);
			dateFormat.setTimeZone(tz);
			formatted = dateFormat.format(d) + " " + tz.getDisplayName();
			channel.sendMessage("(" + sender.getNick() + ") " + formatted);
		}
	}


Input:
	public void test() {
		FileFinder2 finder = new FileFinder2();
		ArrayList<File> files = finder.getAllFiles(new File("C:/z/pleiades/workspace/S3ParallelUploader/testdirs/a"));
		assertThat(files.size()   , is(1));
	}

Output:
	public void test() {
		ArrayList<File> files = FileFinder.find("C:/z/pleiades/workspace/S3ParallelUploader/testdirs/a");
		assertThat(files.size()   , is(2));
	}


Input:
    public ID3v24Tag(AbstractTag mp3tag)
    {
        logger.info("Creating tag from a tag of a different version");
        if (mp3tag != null)
        {
            if ((mp3tag instanceof ID3v24Tag == true))
            {
                throw new UnsupportedOperationException("Copy Constructor not called. Please type cast the argument");
            }
            else if (mp3tag instanceof AbstractID3v2Tag)
            {
                copyPrimitives((AbstractID3v2Tag) mp3tag);
                copyFrames((AbstractID3v2Tag) mp3tag);
            }
            else if (mp3tag instanceof ID3v1Tag)
            {
                ID3v1Tag id3tag = (ID3v1Tag) mp3tag;
                ID3v24Frame newFrame;
                AbstractID3v2FrameBody newBody;
                if (id3tag.title.length() > 0)
                {
                    newBody = new FrameBodyTIT2((byte) 0, id3tag.title);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_TITLE);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (id3tag.artist.length() > 0)
                {
                    newBody = new FrameBodyTPE1((byte) 0, id3tag.artist);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_ARTIST);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (id3tag.album.length() > 0)
                {
                    newBody = new FrameBodyTALB((byte) 0, id3tag.album);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_ALBUM);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (id3tag.year.length() > 0)
                {
                    newBody  = new FrameBodyTDRC((byte) 0, id3tag.year);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_YEAR);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (id3tag.comment.length() > 0)
                {
                    newBody = new FrameBodyCOMM((byte) 0, "ENG", "", id3tag.comment);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_COMMENT);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (id3tag.genre >= 0)
                {
                    String genre = "(" + Byte.toString(id3tag.genre) + ") " +
                        GenreTypes.getInstanceOf().getValueForId(id3tag.genre);
                    newBody = new FrameBodyTCON((byte) 0, genre);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_GENRE);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (mp3tag instanceof ID3v11Tag)
                {
                    ID3v11Tag id3tag2 = (ID3v11Tag) mp3tag;
                    if (id3tag2.track > 0)
                    {
                        newBody = new FrameBodyTRCK((byte) 0, Byte.toString(id3tag2.track));
                        newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_TRACK);
                        newFrame.setBody(newBody);
                        frameMap.put(newFrame.getIdentifier(), newFrame);
                    }
                }
            }
            else if (mp3tag instanceof AbstractLyrics3)
            {
                Lyrics3v2 lyric;
                if (mp3tag instanceof Lyrics3v2)
                {
                    lyric = new Lyrics3v2((Lyrics3v2) mp3tag);
                }
                else
                {
                    lyric = new Lyrics3v2(mp3tag);
                }
                Iterator iterator = lyric.iterator();
                Lyrics3v2Field field;
                ID3v24Frame newFrame;
                while (iterator.hasNext())
                {
                    try
                    {
                        field = (Lyrics3v2Field) iterator.next();
                        newFrame = new ID3v24Frame(field);
                        frameMap.put(newFrame.getIdentifier(), newFrame);
                    }
                    catch (InvalidTagException ex)
                    {
                        logger.warning("Unable to convert Lyrics3 to v24 Frame:Frame Identifier");
                    }
                }
            }
        }
    }

Output:
    public ID3v24Tag(AbstractTag mp3tag)
    {
        logger.info("Creating tag from a tag of a different version");
        if (mp3tag != null)
        {
            if ((mp3tag instanceof ID3v24Tag == true))
            {
                throw new UnsupportedOperationException("Copy Constructor not called. Please type cast the argument");
            }
            else if (mp3tag instanceof AbstractID3v2Tag)
            {
                copyPrimitives((AbstractID3v2Tag) mp3tag);
                copyFrames((AbstractID3v2Tag) mp3tag);
            }
            else if (mp3tag instanceof ID3v1Tag)
            {
                ID3v1Tag id3tag = (ID3v1Tag) mp3tag;
                ID3v24Frame newFrame;
                AbstractID3v2FrameBody newBody;
                if (id3tag.title.length() > 0)
                {
                    newBody = new FrameBodyTIT2((byte) 0, id3tag.title);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_TITLE);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (id3tag.artist.length() > 0)
                {
                    newBody = new FrameBodyTPE1((byte) 0, id3tag.artist);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_ARTIST);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (id3tag.album.length() > 0)
                {
                    newBody = new FrameBodyTALB((byte) 0, id3tag.album);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_ALBUM);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (id3tag.year.length() > 0)
                {
                    newBody  = new FrameBodyTDRC((byte) 0, id3tag.year);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_YEAR);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (id3tag.comment.length() > 0)
                {
                    newBody = new FrameBodyCOMM((byte) 0, "ENG", "", id3tag.comment);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_COMMENT);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
               if ((id3tag.genre & 0xff) >= 0)
                {
                    String genre = "(" + Byte.toString(id3tag.genre) + ") " +
                        GenreTypes.getInstanceOf().getValueForId(id3tag.genre);
                    newBody = new FrameBodyTCON((byte) 0, genre);
                    newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_GENRE);
                    newFrame.setBody(newBody);
                    frameMap.put(newFrame.getIdentifier(), newFrame);
                }
                if (mp3tag instanceof ID3v11Tag)
                {
                    ID3v11Tag id3tag2 = (ID3v11Tag) mp3tag;
                    if (id3tag2.track > 0)
                    {
                        newBody = new FrameBodyTRCK((byte) 0, Byte.toString(id3tag2.track));
                        newFrame = new ID3v24Frame(ID3v24Frames.FRAME_ID_TRACK);
                        newFrame.setBody(newBody);
                        frameMap.put(newFrame.getIdentifier(), newFrame);
                    }
                }
            }
            else if (mp3tag instanceof AbstractLyrics3)
            {
                Lyrics3v2 lyric;
                if (mp3tag instanceof Lyrics3v2)
                {
                    lyric = new Lyrics3v2((Lyrics3v2) mp3tag);
                }
                else
                {
                    lyric = new Lyrics3v2(mp3tag);
                }
                Iterator iterator = lyric.iterator();
                Lyrics3v2Field field;
                ID3v24Frame newFrame;
                while (iterator.hasNext())
                {
                    try
                    {
                        field = (Lyrics3v2Field) iterator.next();
                        newFrame = new ID3v24Frame(field);
                        frameMap.put(newFrame.getIdentifier(), newFrame);
                    }
                    catch (InvalidTagException ex)
                    {
                        logger.warning("Unable to convert Lyrics3 to v24 Frame:Frame Identifier");
                    }
                }
            }
        }
    }


Input:
	public void createEdge(List<Point2D> edgePoints) {
		if (edgePoints == null || edgePoints.size() < 2)
			return;
		Map<Point2D, IDataGraphNode> pointsOnBoundingBoxes = new HashMap<Point2D, IDataGraphNode>();
		for (int i = 1; i < edgePoints.size(); i++) {
			Point2D point1 = edgePoints.get(i - 1);
			Point2D point2 = edgePoints.get(i);
			for (IDataGraphNode node : dataGraph.getNodes()) {
				Rectangle2D box = node.getBoundingBox();
				int code1 = box.outcode(point1);
				int code2 = box.outcode(point2);
				boolean isPoint1OnBoundingBox = (pointsOnBoundingBoxes
						.get(point1) == node);
				boolean isPoint2OnBoundingBox = (pointsOnBoundingBoxes
						.get(point2) == node);
				if (((code1 & code2) != 0)
						|| (code1 == 0 && !isPoint1OnBoundingBox)
						|| (code2 == 0 && !isPoint2OnBoundingBox)
						|| (isPoint1OnBoundingBox && isPoint2OnBoundingBox)) {
					continue;
				}
				Point2D intersection1 = (isPoint1OnBoundingBox) ? (point1)
						: (calcIntersectionPoint(point1, point2, box, code1));
				Point2D intersection2 = (isPoint2OnBoundingBox) ? (point2)
						: (calcIntersectionPoint(point2, point1, box, code2));
				if (intersection1 != null && intersection2 != null) {
					if (intersection1.getX() == intersection2.getX()
							&& intersection1.getY() == intersection2.getY()) {
						continue;
					}
					Point2D[] corners = new Point2D[4];
					corners[0] = new Point2D.Double(box.getMinX(),
							box.getMinY());
					corners[1] = new Point2D.Double(box.getMaxX(),
							box.getMinY());
					corners[2] = new Point2D.Double(box.getMaxX(),
							box.getMaxY());
					corners[3] = new Point2D.Double(box.getMinX(),
							box.getMaxY());
					double minDistance = Double.MAX_VALUE;
					Point2D bendPoint = null;
					for (int j = 0; j < 4; j++) {
						if ((corners[j].getX() == point1.getX()
								&& corners[j].getY() == point1.getY() && isPoint1OnBoundingBox)
								|| (corners[j].getX() == point2.getX() && corners[j]
										.getY() == point2.getY())
								&& isPoint2OnBoundingBox) {
							continue;
						}
						double currentSummedDistance = intersection1
								.distanceSq(corners[j])
								+ intersection2.distanceSq(corners[j]);
						if (currentSummedDistance < minDistance) {
							minDistance = currentSummedDistance;
							bendPoint = corners[j];
						}
					}
					if (bendPoint == null) {
						System.out.println("null");
					}
					boolean isPointAlreadyAdded = false;
					for (Point2D point : edgePoints) {
						if (point.getX() == bendPoint.getX()
								&& point.getY() == bendPoint.getY()) {
							isPointAlreadyAdded = true;
							break;
						}
					}
					if (isPointAlreadyAdded) {
						continue;
					}
					edgePoints.add(i, bendPoint);
					pointsOnBoundingBoxes.put(bendPoint, node);
					i--;
					break;
				}
			}
		}
		for (int step = edgePoints.size() - 2; step >= 2; step--) {
			for (int i = 0; i + step < edgePoints.size(); i++) {
				Point2D point1 = edgePoints.get(i);
				Point2D point2 = edgePoints.get(i + step);
				boolean hasIntersection = false;
				for (IDataGraphNode node : dataGraph.getNodes()) {
					Rectangle2D box = node.getBoundingBox();
					int code1 = box.outcode(point1);
					int code2 = box.outcode(point2);
					boolean isPoint1OnBoundingBox = (pointsOnBoundingBoxes
							.get(point1) == node);
					boolean isPoint2OnBoundingBox = (pointsOnBoundingBoxes
							.get(point2) == node);
					if ((code1 & code2) != 0) {
						continue;
					}
					if ((code1 == 0 && !isPoint1OnBoundingBox)
							|| (code2 == 0 && !isPoint2OnBoundingBox)
							|| (isPoint1OnBoundingBox && isPoint2OnBoundingBox)) {
						hasIntersection = true;
						break;
					}
					Point2D intersection1 = (isPoint1OnBoundingBox) ? (point1)
							: (calcIntersectionPoint(point1, point2, box, code1));
					Point2D intersection2 = (isPoint2OnBoundingBox) ? (point2)
							: (calcIntersectionPoint(point2, point1, box, code2));
					if (intersection1 == null || intersection2 == null) {
						continue;
					}
					if (intersection1.distance(intersection2) < 0.000001
							&& (isPoint1OnBoundingBox || isPoint2OnBoundingBox)) {
						continue;
					}
					hasIntersection = true;
					break;
				}
				if (!hasIntersection) {
					for (int j = i + 1; j < i + step; j++) {
						edgePoints.remove(i + 1);
					}
					step = edgePoints.size() - 2;
					break;
				}
			}
		}
	}

Output:
	public void createEdge(List<Point2D> edgePoints) {
		if (edgePoints == null || edgePoints.size() < 2)
			return;
		Map<Point2D, IDataGraphNode> pointsOnBoundingBoxes = new HashMap<Point2D, IDataGraphNode>();
		for (int i = 1; i < edgePoints.size(); i++) {
			Point2D point1 = edgePoints.get(i - 1);
			Point2D point2 = edgePoints.get(i);
			for (IDataGraphNode node : dataGraph.getNodes()) {
				Rectangle2D box = node.getBoundingBox();
				int code1 = box.outcode(point1);
				int code2 = box.outcode(point2);
				boolean isPoint1OnBoundingBox = (pointsOnBoundingBoxes
						.get(point1) == node);
				boolean isPoint2OnBoundingBox = (pointsOnBoundingBoxes
						.get(point2) == node);
				if (((code1 & code2) != 0)
						|| (code1 == 0 && !isPoint1OnBoundingBox)
						|| (code2 == 0 && !isPoint2OnBoundingBox)
						|| (isPoint1OnBoundingBox && isPoint2OnBoundingBox)) {
					continue;
				}
				Point2D intersection1 = (isPoint1OnBoundingBox) ? (point1)
						: (calcIntersectionPoint(point1, point2, box, code1));
				Point2D intersection2 = (isPoint2OnBoundingBox) ? (point2)
						: (calcIntersectionPoint(point2, point1, box, code2));
				if (intersection1 != null && intersection2 != null) {
					if (intersection1.getX() <= intersection2.getX() + 0.0000001
							&& intersection1.getX() >= intersection2.getX() - 0.0000001
							&& intersection1.getY() <= intersection2.getY() + 0.0000001
							&& intersection1.getY() >= intersection2.getY() - 0.0000001) {
						continue;
					}
					Point2D[] corners = new Point2D[4];
					corners[0] = new Point2D.Double(box.getMinX(),
							box.getMinY());
					corners[1] = new Point2D.Double(box.getMaxX(),
							box.getMinY());
					corners[2] = new Point2D.Double(box.getMaxX(),
							box.getMaxY());
					corners[3] = new Point2D.Double(box.getMinX(),
							box.getMaxY());
					double minDistance = Double.MAX_VALUE;
					Point2D bendPoint = null;
					for (int j = 0; j < 4; j++) {
						if ((corners[j].getX() == point1.getX()
								&& corners[j].getY() == point1.getY() && isPoint1OnBoundingBox)
								|| (corners[j].getX() == point2.getX() && corners[j]
										.getY() == point2.getY())
								&& isPoint2OnBoundingBox) {
							continue;
						}
						double currentSummedDistance = intersection1
								.distanceSq(corners[j])
								+ intersection2.distanceSq(corners[j]);
						if (currentSummedDistance < minDistance) {
							minDistance = currentSummedDistance;
							bendPoint = corners[j];
						}
					}
					if (bendPoint == null) {
						System.out.println("null");
					}
					boolean isPointAlreadyAdded = false;
					for (Point2D point : edgePoints) {
						if (point.getX() == bendPoint.getX()
								&& point.getY() == bendPoint.getY()) {
							isPointAlreadyAdded = true;
							break;
						}
					}
					if (isPointAlreadyAdded) {
						continue;
					}
					edgePoints.add(i, bendPoint);
					pointsOnBoundingBoxes.put(bendPoint, node);
					i--;
					break;
				}
			}
		}
		for (int step = edgePoints.size() - 2; step >= 2; step--) {
			for (int i = 0; i + step < edgePoints.size(); i++) {
				Point2D point1 = edgePoints.get(i);
				Point2D point2 = edgePoints.get(i + step);
				boolean hasIntersection = false;
				for (IDataGraphNode node : dataGraph.getNodes()) {
					Rectangle2D box = node.getBoundingBox();
					int code1 = box.outcode(point1);
					int code2 = box.outcode(point2);
					boolean isPoint1OnBoundingBox = (pointsOnBoundingBoxes
							.get(point1) == node);
					boolean isPoint2OnBoundingBox = (pointsOnBoundingBoxes
							.get(point2) == node);
					if ((code1 & code2) != 0) {
						continue;
					}
					if ((code1 == 0 && !isPoint1OnBoundingBox
							&& edgePoints.indexOf(point1) != 0 && edgePoints
							.indexOf(point1) != edgePoints.size() - 1)
							|| (code2 == 0 && !isPoint2OnBoundingBox
									&& edgePoints.indexOf(point2) != 0 && edgePoints
									.indexOf(point2) != edgePoints.size() - 1)
							|| (isPoint1OnBoundingBox && isPoint2OnBoundingBox)) {
						hasIntersection = true;
						break;
					}
					Point2D intersection1 = (isPoint1OnBoundingBox) ? (point1)
							: (calcIntersectionPoint(point1, point2, box, code1));
					Point2D intersection2 = (isPoint2OnBoundingBox) ? (point2)
							: (calcIntersectionPoint(point2, point1, box, code2));
					if (intersection1 == null || intersection2 == null) {
						continue;
					}
					if (intersection1.distance(intersection2) < 0.000001
							&& (isPoint1OnBoundingBox || isPoint2OnBoundingBox)) {
						continue;
					}
					hasIntersection = true;
					break;
				}
				if (!hasIntersection) {
					for (int j = i + 1; j < i + step; j++) {
						edgePoints.remove(i + 1);
					}
					step = edgePoints.size() - 2;
					break;
				}
			}
		}
	}


Input:
	public void handlePrintProduktBatch(HttpServletRequest request, HttpServletResponse response, IFunctionality funktionalitetsLaget) throws ServletException, IOException, DALException {
		int produktBatchId, receptId, oprId = 0, raavareId, status, raavareBatchId = 0;
		String udskrevet, receptNavn, raavareNavn, startDato, slutDato;
		double tara = 0, netto = 0, taraSum = 0, nettoSum = 0;
		produktBatchId = Integer.parseInt(request.getParameter("pbId"));
		ProduktBatchDTO pbDTO = funktionalitetsLaget.getProduktBatchDAO().getProduktBatch(produktBatchId);
		receptId = pbDTO.getReceptId();
		ReceptDTO receptDTO = funktionalitetsLaget.getReceptDAO().getRecept(receptId);
		receptNavn = receptDTO.getReceptNavn();
		List<ReceptKompDTO> receptKompList = funktionalitetsLaget.getReceptKompDAO().getReceptKompList(receptId);
		status = pbDTO.getStatus();
		startDato = pbDTO.getStartDato();
		slutDato = pbDTO.getSlutDato();
		Calendar d = Calendar.getInstance();
		DecimalFormat df = new DecimalFormat("00");
		udskrevet = d.get(Calendar.YEAR) + "-"
		+ df.format(d.get(Calendar.MONTH) + 1) + "-"
		+ df.format(d.get(Calendar.DATE)) + " "
		+ df.format(d.get(Calendar.HOUR_OF_DAY)) + ":"
		+ df.format(d.get(Calendar.MINUTE)) + ":"
		+ df.format(d.get(Calendar.SECOND));
		try {
	        Document document = new Document();
	        ByteArrayOutputStream baos = new ByteArrayOutputStream();
	        PdfWriter.getInstance(document, baos);
	        document.open();
	        Chunk SEPERATOR = new Chunk(
	                new LineSeparator(0.5f, 95, BaseColor.BLUE, Element.ALIGN_CENTER, 3.5f));
	        Chunk DOTTED = new Chunk(
	                new DottedLineSeparator());
	        document.add(new Paragraph("Udskrevet "+udskrevet));
	        document.add(new Paragraph("Produkt Batch nr. "+produktBatchId));
	        document.add(new Paragraph("Recept nr. "+receptId));
	        document.add(new Paragraph("Recept navn: "+receptNavn));
	        document.add(SEPERATOR);
	        for (ReceptKompDTO receptKomp: receptKompList) {
	        	RaavareDTO raavare = funktionalitetsLaget.getRaavareDAO().getRaavare(receptKomp.getRaavareId());
	        	raavareId = receptKomp.getRaavareId();
	        	raavareNavn = raavare.getRaavareNavn();
	        	List<ProduktBatchKompDTO> produktBatchKompList = funktionalitetsLaget.getProduktBatchKompDAO().getProduktBatchKompList(produktBatchId);
		        document.add(new Paragraph("Råvare nr. "+raavareId));
		        document.add(new Paragraph("Råvare navn: "+raavareNavn));
		        document.add(DOTTED);
		        PdfPTable table = new PdfPTable(6);
		        table.getDefaultCell().setBorder(0);
		        table.addCell("Nominel Netto");
		        table.addCell("Tolerance");
		        table.addCell("Tara");
		        table.addCell("Netto");
		        table.addCell("Batch");
		        table.addCell("Operatør");
		        for (ProduktBatchKompDTO produktBatchKomp: produktBatchKompList) {
		        	int rbId = produktBatchKomp.getRbId();
		        	RaavareBatchDTO tjekRaavareBatch = funktionalitetsLaget.getRaavareBatchDAO().getRaavareBatch(rbId);
		        	if (raavareId == tjekRaavareBatch.getRaavareId()) {
		        		tara = produktBatchKomp.getTara();
		        		taraSum += tara;
		        		netto = produktBatchKomp.getNetto();
		        		nettoSum += netto;
		        		raavareBatchId = tjekRaavareBatch.getRbId();
		        		oprId = produktBatchKomp.getOprId();
				        table.addCell(""+receptKomp.getNomNetto());
				        table.addCell(""+receptKomp.getTolerance());
		        		table.addCell(""+tara);
		        		table.addCell(""+netto);
		        		table.addCell(""+raavareBatchId);
		        		table.addCell(""+oprId);
		        	}
		        }
		        if (tara == 0) {
		        	table.addCell("");
		        	table.addCell("");
		        	table.addCell("");
		        	table.addCell("");
		        }
		        document.add(table);
		        document.add(SEPERATOR);
	        }
	        document.add(new Paragraph("Sum Tara: "+((taraSum != 0)?taraSum:"")));
	        document.add(new Paragraph("Sum Netto: "+((nettoSum != 0)?nettoSum:"")));
	        document.add(new Paragraph("\n\n"));
	        document.add(new Paragraph("Produktion Status: "+statusToString(status)));
	        document.add(new Paragraph("Produktion Startet: "+startDato));
	        document.add(new Paragraph("Produktion Slut: "+slutDato));
	        document.close();
	        response.setHeader("Expires", "0");
	        response.setHeader("Cache-Control",
	            "must-revalidate, post-check=0, pre-check=0");
	        response.setHeader("Pragma", "public");
	        response.setHeader("Content-Disposition", "attachment; filename=\"ProduktBatch"+produktBatchId+".pdf\"");
	        response.setContentType("application/pdf");
	        response.setContentLength(baos.size());
	        OutputStream os = response.getOutputStream();
	        baos.writeTo(os);
	        os.flush();
	        os.close();
		}
		catch(DocumentException e) {
			e.printStackTrace();
			System.out.println("fanget");
		}
	}

Output:
	public void handlePrintProduktBatch(HttpServletRequest request, HttpServletResponse response, IFunctionality funktionalitetsLaget) throws ServletException, IOException, DALException {
		int produktBatchId, receptId, oprId = 0, raavareId, status, raavareBatchId = 0;
		String udskrevet, receptNavn, raavareNavn, startDato, slutDato;
		double tara = 0, netto = 0, taraSum = 0, nettoSum = 0;
		produktBatchId = Integer.parseInt(request.getParameter("pbId"));
		ProduktBatchDTO pbDTO = funktionalitetsLaget.getProduktBatchDAO().getProduktBatch(produktBatchId);
		receptId = pbDTO.getReceptId();
		ReceptDTO receptDTO = funktionalitetsLaget.getReceptDAO().getRecept(receptId);
		receptNavn = receptDTO.getReceptNavn();
		List<ReceptKompDTO> receptKompList = funktionalitetsLaget.getReceptKompDAO().getReceptKompList(receptId);
		status = pbDTO.getStatus();
		startDato = pbDTO.getStartDato();
		slutDato = pbDTO.getSlutDato();
		Calendar d = Calendar.getInstance();
		DecimalFormat df = new DecimalFormat("00");
		udskrevet = d.get(Calendar.YEAR) + "-"
		+ df.format(d.get(Calendar.MONTH) + 1) + "-"
		+ df.format(d.get(Calendar.DATE)) + " "
		+ df.format(d.get(Calendar.HOUR_OF_DAY)) + ":"
		+ df.format(d.get(Calendar.MINUTE)) + ":"
		+ df.format(d.get(Calendar.SECOND));
		try {
	        Document document = new Document();
	        ByteArrayOutputStream baos = new ByteArrayOutputStream();
	        PdfWriter.getInstance(document, baos);
	        document.open();
	        Chunk SEPERATOR = new Chunk(
	                new LineSeparator(0.5f, 95, BaseColor.BLUE, Element.ALIGN_CENTER, 3.5f));
	        Chunk DOTTED = new Chunk(
	                new DottedLineSeparator());
	        document.add(new Paragraph("Udskrevet "+udskrevet));
	        document.add(new Paragraph("Produkt Batch nr. "+produktBatchId));
	        document.add(new Paragraph("Recept nr. "+receptId));
	        document.add(new Paragraph("Recept navn: "+receptNavn));
	        document.add(SEPERATOR);
	        for (ReceptKompDTO receptKomp: receptKompList) {
	        	RaavareDTO raavare = funktionalitetsLaget.getRaavareDAO().getRaavare(receptKomp.getRaavareId());
	        	raavareId = receptKomp.getRaavareId();
	        	raavareNavn = raavare.getRaavareNavn();
	        	List<ProduktBatchKompDTO> produktBatchKompList = funktionalitetsLaget.getProduktBatchKompDAO().getProduktBatchKompList(produktBatchId);
		        document.add(new Paragraph("Råvare nr. "+raavareId));
		        document.add(new Paragraph("Råvare navn: "+raavareNavn));
		        document.add(DOTTED);
		        PdfPTable table = new PdfPTable(6);
		        table.getDefaultCell().setBorder(0);
		        table.addCell("Nominel Netto");
		        table.addCell("Tolerance");
		        table.addCell("Tara");
		        table.addCell("Netto");
		        table.addCell("Batch");
		        table.addCell("Operatør");
		        for (ProduktBatchKompDTO produktBatchKomp: produktBatchKompList) {
		        	int rbId = produktBatchKomp.getRbId();
		        	RaavareBatchDTO tjekRaavareBatch = funktionalitetsLaget.getRaavareBatchDAO().getRaavareBatch(rbId);
		        	if (raavareId == tjekRaavareBatch.getRaavareId()) {
		        		tara = produktBatchKomp.getTara();
		        		taraSum += tara;
		        		netto = produktBatchKomp.getNetto();
		        		nettoSum += netto;
		        		raavareBatchId = tjekRaavareBatch.getRbId();
		        		oprId = produktBatchKomp.getOprId();
				        table.addCell(""+receptKomp.getNomNetto());
				        table.addCell(""+receptKomp.getTolerance() + " %");
		        		table.addCell(""+tara);
		        		table.addCell(""+netto);
		        		table.addCell(""+raavareBatchId);
		        		table.addCell(""+oprId);
		        	}
		        }
		        if (tara == 0 && netto == 0) {
		        	table.addCell(""+receptKomp.getNomNetto());
		        	table.addCell(""+receptKomp.getTolerance()+" %");
		        	table.addCell("");
		        	table.addCell("");
		        	table.addCell("");
		        	table.addCell("");
		        }
		        document.add(table);
		        document.add(SEPERATOR);
	        }
	        document.add(new Paragraph("Sum Tara: "+((taraSum != 0)?taraSum:"")));
	        document.add(new Paragraph("Sum Netto: "+((nettoSum != 0)?nettoSum:"")));
	        document.add(new Paragraph("\n\n"));
	        document.add(new Paragraph("Produktion Status: "+statusToString(status)));
	        document.add(new Paragraph("Produktion Startet: "+startDato));
	        document.add(new Paragraph("Produktion Slut: "+slutDato));
	        document.close();
	        response.setHeader("Expires", "0");
	        response.setHeader("Cache-Control",
	            "must-revalidate, post-check=0, pre-check=0");
	        response.setHeader("Pragma", "public");
	        response.setHeader("Content-Disposition", "attachment; filename=\"ProduktBatch"+produktBatchId+".pdf\"");
	        response.setContentType("application/pdf");
	        response.setContentLength(baos.size());
	        OutputStream os = response.getOutputStream();
	        baos.writeTo(os);
	        os.flush();
	        os.close();
		}
		catch(DocumentException e) {
			e.printStackTrace();
			System.out.println("fanget");
		}
	}


Input:
public void handleMsg(Bais msg) {
		byte i = msg.readByte();
		Command c = Command.values()[i];
		Log.d(TAG, "Received: " + c);
		switch (c) {
		case ChannelPlayers:
		case JoinChannel:
		case LeaveChannel:{
			Channel ch = channels.get(msg.readInt());
			if(ch != null)
				ch.handleChannelMsg(c, msg);
			else
				Log.e(TAG, "Received message for nonexistent channel");
			break;
		} case VersionControl: {
			ProtocolVersion serverVersion = new ProtocolVersion(msg);
			if (serverVersion.compareTo(version) > 0) {
				Log.d(TAG, "Server has newer protocol version than we expect");
			} else if (serverVersion.compareTo(version) < 0) {
				Log.d(TAG, "PO Android uses newer protocol than Server");
			}
			serverSupportsZipCompression = msg.readBool();
			ProtocolVersion lastVersionWithoutFeatures = new ProtocolVersion(msg);
			ProtocolVersion lastVersionWithoutCompatBreak = new ProtocolVersion(msg);
			ProtocolVersion lastVersionWithoutMajorCompatBreak = new ProtocolVersion(msg);
			if (serverVersion.compareTo(version) > 0) {
				if (lastVersionWithoutFeatures.compareTo(version) > 0) {
					Toast.makeText(this, R.string.new_server_features_warning, Toast.LENGTH_SHORT).show();
				} else if (lastVersionWithoutCompatBreak.compareTo(version) > 0) {
					Toast.makeText(this, R.string.minor_compat_break_warning, Toast.LENGTH_SHORT).show();
				} else if (lastVersionWithoutMajorCompatBreak.compareTo(version) > 0) {
					Toast.makeText(this, R.string.major_compat_break_warning, Toast.LENGTH_LONG).show();
				}
			}
			serverName = msg.readString();
			if (chatActivity != null) {
				chatActivity.updateTitle();
			}
			break;
		} case Register: {
			break;
		} case Login: {
			Bais flags = msg.readFlags();
			Boolean hasReconnPass = flags.readBool();
			if (hasReconnPass) {
				reconnectSecret = msg.readQByteArray();
			}
			mePlayer = new PlayerInfo(msg);
			myid = mePlayer.id;
			int numTiers = msg.readInt();
			for (int j = 0; j < numTiers; j++) {
				msg.readString();
			}
			players.put(mePlayer.id, mePlayer);
			break;
		} case TierSelection: {
			msg.readInt();
			Tier prevTier = new Tier(msg.readByte(), msg.readString());
			prevTier.parentTier = superTier;
			superTier.subTiers.add(prevTier);
			while(msg.available() != 0) {
				Tier t = new Tier(msg.readByte(), msg.readString());
				if(t.level == prevTier.level) {
					prevTier.parentTier.addSubTier(t);
					t.parentTier = prevTier.parentTier;
				}
				else if(t.level < prevTier.level) {
					while(t.level < prevTier.level)
						prevTier = prevTier.parentTier;
					prevTier.parentTier.addSubTier(t);
					t.parentTier = prevTier.parentTier;
				}
				else if(t.level > prevTier.level) {
					prevTier.addSubTier(t);
					t.parentTier = prevTier;
				}
				prevTier = t;
			}
			break;
		} case ChannelsList: {
			int numChannels = msg.readInt();
			for(int j = 0; j < numChannels; j++) {
				int chanId = msg.readInt();
				Channel ch = new Channel(chanId, msg.readString(), this);
				channels.put(chanId, ch);
			}
			Log.d(TAG, channels.toString());
			break;
		} case PlayersList: {
			while (msg.available() != 0) {
				PlayerInfo p = new PlayerInfo(msg);
				PlayerInfo oldPlayer = players.get(p.id);
				players.put(p.id, p);
				if (oldPlayer != null && chatActivity != null) {
					chatActivity.updatePlayer(p, oldPlayer);
				}
			}
			break;
		} case SendMessage: {
			Bais netFlags = msg.readFlags();
			boolean hasChannel = netFlags.readBool();
			boolean hasId = netFlags.readBool();
			Bais dataFlags = msg.readFlags();
			boolean isHtml = dataFlags.readBool();
			Channel chan = hasChannel ? channels.get(msg.readInt()) : null;
			PlayerInfo player = hasId ? players.get(msg.readInt()) : null;
			CharSequence message = msg.readString();
			if (hasId) {
				CharSequence color = (player == null ? "orange" : player.color.toHexString());
				CharSequence name = player.nick();
				if (isHtml) {
					message = Html.fromHtml("" + name +
							": " + message);
				} else {
					message = Html.fromHtml("" + name +
							": " + StringUtilities.escapeHtml((String)message));
				}
			} else {
				message = isHtml ? Html.fromHtml((String)message) : message;
			}
			if (!hasChannel) {
				if (chatActivity != null && message.toString().contains("Wrong password for this name."))
					chatActivity.makeToast(message.toString(), "long");
				else {
					Iterator<Channel> it = joinedChannels.iterator();
					while (it.hasNext()) {
						it.next().writeToHist(message);
					}
				}
			} else {
				if (chan == null) {
					Log.e(TAG, "Received message for nonexistent channel");
				} else {
					chan.writeToHist(message);
				}
			}
			break;
		}
		case BattleList: {
			msg.readInt();
			int numBattles = msg.readInt();
			for (; numBattles > 0; numBattles--) {
				int battleId = msg.readInt();
				int player1 = msg.readInt();
				int player2 = msg.readInt();
				addBattle(battleId, new BattleDesc(player1, player2));
			}
			break;
		}
		case ChannelBattle: {
			msg.readInt();
			int battleId = msg.readInt();
			int player1 = msg.readInt();
			int player2 = msg.readInt();
			addBattle(battleId, new BattleDesc(player1, player2));
		}
		 case Logout: {
			int playerID = msg.readInt();
			removePlayer(playerID);
			break;
		} case BattleFinished: {
			int battleID = msg.readInt();
			byte battleDesc = msg.readByte();
			msg.readByte();
			int id1 = msg.readInt();
			int id2 = msg.readInt();
			Log.i(TAG, "bID " + battleID + " battleDesc " + battleDesc + " id1 " + id1 + " id2 " + id2);
			String[] outcome = new String[]{" won by forfeit against ", " won against ", " tied with "};
			if (battle != null && battle.bID == battleID || spectatedBattles.containsKey(battleID)) {
				if (battle.bID == battleID) {
				}
				if (battleDesc < 2) {
					joinedChannels.peek().writeToHist(Html.fromHtml("" +
							StringUtilities.escapeHtml(playerName(id1)) + outcome[battleDesc] +
							StringUtilities.escapeHtml(playerName(id2)) + "."));
				}
				if (battleDesc == 0 || battleDesc == 3) {
					closeBattle(battleID);
				}
			}
			removeBattle(battleID);
			break;
		} case SendPM: {
			int playerID = msg.readInt();
			pmedPlayers.add(playerID);
			String pm = new String("This user is running the Pokemon Online Android client and cannot respond to private messages.");
			Baos bb = new Baos();
			bb.putInt(playerID);
			bb.putString(pm);
			socket.sendMessage(bb, Command.SendPM);
			break;
		} case BattleMessage: {
			msg.readInt();
			msg.readInt();
			if (battle != null)
				battle.receiveCommand(msg);
			break;
		} case EngageBattle: {
			int battleId = msg.readInt();
			Bais flags = msg.readFlags();
			byte mode = msg.readByte();
			int p1 = msg.readInt();
			int p2 = msg.readInt();
			addBattle(battleId, new BattleDesc(p1, p2, mode));
			if(flags.readBool()) {
				BattleConf conf = new BattleConf(msg);
				battle = new Battle(conf, msg, players.get(conf.id(0)),
						players.get(conf.id(1)), mePlayer.id, battleId, this);
				joinedChannels.peek().writeToHist("Battle between " + playerName(p1) +
						" and " + playerName(p2) + " started!");
				Intent in;
				in = new Intent(this, BattleActivity.class);
				in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(in);
				findingBattle = false;
			}
			break;
		}
		case SpectateBattle: {
			Bais flags = msg.readFlags();
			int battleId = msg.readInt();
			if (flags.readBool()) {
				if (spectatedBattles.contains(battleId)) {
					Log.e(TAG, "Already watching battle " + battleId);
					return;
				}
	            BattleConf conf = new BattleConf(msg);
	            SpectatingBattle battle = new SpectatingBattle(conf, players.get(conf.id(0)), players.get(conf.id(1)), battleId, this);
	            spectatedBattles.put(battleId, battle);
	            Intent intent = new Intent(this, BattleActivity.class);
	            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	            intent.putExtra("battleId", battleId);
	            startActivity(intent);
	        } else {
	            SpectatingBattle battle = spectatedBattles.remove(battleId);
	            if (battle != null && battle.activity != null) {
	            	battle.activity.end();
	            }
	        }
			break;
		}
		case SpectateBattleMessage: {
			int battleId = msg.readInt();
			msg.readInt();
			if (spectatedBattles.containsKey(battleId)) {
				spectatedBattles.get(battleId).receiveCommand(msg);
			}
			break;
		}
		case AskForPass: {
			salt = msg.readString();
			if (salt.length() < 6) {
				System.out.println("Protocol Error: The server requires insecure authentication");
				break;
			}
			askedForPass = true;
			if (chatActivity != null && (chatActivity.hasWindowFocus() || chatActivity.progressDialog.isShowing())) {
				chatActivity.notifyAskForPass();
			}
			break;
		} case AddChannel: {
			addChannel(msg.readString(),msg.readInt());
			break;
		} case RemoveChannel: {
			int chanId = msg.readInt();
			if (chatActivity != null)
				chatActivity.removeChannel(channels.get(chanId));
			channels.remove(chanId);
			break;
		} case ChanNameChange: {
			int chanId = msg.readInt();
			if (chatActivity != null)
				chatActivity.removeChannel(channels.get(chanId));
			channels.remove(chanId);
			channels.put(chanId, new Channel(chanId, msg.readString(), this));
			break;
		} default: {
			System.out.println("Unimplented message");
		}
		}

Output:
	public void handleMsg(Bais msg) {
		byte i = msg.readByte();
		Command c = Command.values()[i];
		Log.d(TAG, "Received: " + c);
		switch (c) {
		case ChannelPlayers:
		case JoinChannel:
		case LeaveChannel:{
			Channel ch = channels.get(msg.readInt());
			if(ch != null)
				ch.handleChannelMsg(c, msg);
			else
				Log.e(TAG, "Received message for nonexistent channel");
			break;
		} case VersionControl: {
			ProtocolVersion serverVersion = new ProtocolVersion(msg);
			if (serverVersion.compareTo(version) > 0) {
				Log.d(TAG, "Server has newer protocol version than we expect");
			} else if (serverVersion.compareTo(version) < 0) {
				Log.d(TAG, "PO Android uses newer protocol than Server");
			}
			serverSupportsZipCompression = msg.readBool();
			ProtocolVersion lastVersionWithoutFeatures = new ProtocolVersion(msg);
			ProtocolVersion lastVersionWithoutCompatBreak = new ProtocolVersion(msg);
			ProtocolVersion lastVersionWithoutMajorCompatBreak = new ProtocolVersion(msg);
			if (serverVersion.compareTo(version) > 0) {
				if (lastVersionWithoutFeatures.compareTo(version) > 0) {
					Toast.makeText(this, R.string.new_server_features_warning, Toast.LENGTH_SHORT).show();
				} else if (lastVersionWithoutCompatBreak.compareTo(version) > 0) {
					Toast.makeText(this, R.string.minor_compat_break_warning, Toast.LENGTH_SHORT).show();
				} else if (lastVersionWithoutMajorCompatBreak.compareTo(version) > 0) {
					Toast.makeText(this, R.string.major_compat_break_warning, Toast.LENGTH_LONG).show();
				}
			}
			serverName = msg.readString();
			if (chatActivity != null) {
				chatActivity.updateTitle();
			}
			break;
		} case Register: {
			break;
		} case Login: {
			Bais flags = msg.readFlags();
			Boolean hasReconnPass = flags.readBool();
			if (hasReconnPass) {
				reconnectSecret = msg.readQByteArray();
			}
			mePlayer = new PlayerInfo(msg);
			myid = mePlayer.id;
			int numTiers = msg.readInt();
			for (int j = 0; j < numTiers; j++) {
				msg.readString();
			}
			players.put(mePlayer.id, mePlayer);
			break;
		} case TierSelection: {
			msg.readInt();
			Tier prevTier = new Tier(msg.readByte(), msg.readString());
			prevTier.parentTier = superTier;
			superTier.subTiers.add(prevTier);
			while(msg.available() != 0) {
				Tier t = new Tier(msg.readByte(), msg.readString());
				if(t.level == prevTier.level) {
					prevTier.parentTier.addSubTier(t);
					t.parentTier = prevTier.parentTier;
				}
				else if(t.level < prevTier.level) {
					while(t.level < prevTier.level)
						prevTier = prevTier.parentTier;
					prevTier.parentTier.addSubTier(t);
					t.parentTier = prevTier.parentTier;
				}
				else if(t.level > prevTier.level) {
					prevTier.addSubTier(t);
					t.parentTier = prevTier;
				}
				prevTier = t;
			}
			break;
		} case ChannelsList: {
			int numChannels = msg.readInt();
			for(int j = 0; j < numChannels; j++) {
				int chanId = msg.readInt();
				Channel ch = new Channel(chanId, msg.readString(), this);
				channels.put(chanId, ch);
			}
			Log.d(TAG, channels.toString());
			break;
		} case PlayersList: {
			while (msg.available() != 0) {
				PlayerInfo p = new PlayerInfo(msg);
				PlayerInfo oldPlayer = players.get(p.id);
				players.put(p.id, p);
				if (oldPlayer != null && chatActivity != null) {
					chatActivity.updatePlayer(p, oldPlayer);
				}
			}
			break;
		} case SendMessage: {
			Bais netFlags = msg.readFlags();
			boolean hasChannel = netFlags.readBool();
			boolean hasId = netFlags.readBool();
			Bais dataFlags = msg.readFlags();
			boolean isHtml = dataFlags.readBool();
			Channel chan = hasChannel ? channels.get(msg.readInt()) : null;
			PlayerInfo player = hasId ? players.get(msg.readInt()) : null;
			CharSequence message = msg.readString();
			if (hasId) {
				CharSequence color = (player == null ? "orange" : player.color.toHexString());
				CharSequence name = player.nick();
				if (isHtml) {
					message = Html.fromHtml("<font color='" + color + "'><b>" + name +
							": </b></font>" + message);
				} else {
					message = Html.fromHtml("<font color='" + color + "'><b>" + name +
							": </b></font>" + StringUtilities.escapeHtml((String)message));
				}
			} else {
				message = isHtml ? Html.fromHtml((String)message) : message;
			}
			if (!hasChannel) {
				if (chatActivity != null && message.toString().contains("Wrong password for this name."))
					chatActivity.makeToast(message.toString(), "long");
				else {
					Iterator<Channel> it = joinedChannels.iterator();
					while (it.hasNext()) {
						it.next().writeToHist(message);
					}
				}
			} else {
				if (chan == null) {
					Log.e(TAG, "Received message for nonexistent channel");
				} else {
					chan.writeToHist(message);
				}
			}
			break;
		}
		case BattleList: {
			msg.readInt();
			int numBattles = msg.readInt();
			for (; numBattles > 0; numBattles--) {
				int battleId = msg.readInt();
				int player1 = msg.readInt();
				int player2 = msg.readInt();
				addBattle(battleId, new BattleDesc(player1, player2));
			}
			break;
		}
		case ChannelBattle: {
			msg.readInt();
			int battleId = msg.readInt();
			int player1 = msg.readInt();
			int player2 = msg.readInt();
			addBattle(battleId, new BattleDesc(player1, player2));
		}
		 case Logout: {
			int playerID = msg.readInt();
			removePlayer(playerID);
			break;
		} case BattleFinished: {
			int battleID = msg.readInt();
			byte battleDesc = msg.readByte();
			msg.readByte();
			int id1 = msg.readInt();
			int id2 = msg.readInt();
			Log.i(TAG, "bID " + battleID + " battleDesc " + battleDesc + " id1 " + id1 + " id2 " + id2);
			String[] outcome = new String[]{" won by forfeit against ", " won against ", " tied with "};
			if (battle != null && battle.bID == battleID || spectatedBattles.containsKey(battleID)) {
				if (battle != null && battle.bID == battleID) {
				}
				if (battleDesc < 2) {
					joinedChannels.peek().writeToHist(Html.fromHtml("<b><i>" +
							StringUtilities.escapeHtml(playerName(id1)) + outcome[battleDesc] +
							StringUtilities.escapeHtml(playerName(id2)) + ".</b></i>"));
				}
				if (battleDesc == 0 || battleDesc == 3) {
					closeBattle(battleID);
				}
			}
			removeBattle(battleID);
			break;
		} case SendPM: {
			int playerID = msg.readInt();
			pmedPlayers.add(playerID);
			String pm = new String("This user is running the Pokemon Online Android client and cannot respond to private messages.");
			Baos bb = new Baos();
			bb.putInt(playerID);
			bb.putString(pm);
			socket.sendMessage(bb, Command.SendPM);
			break;
		} case BattleMessage: {
			msg.readInt();
			msg.readInt();
			if (battle != null)
				battle.receiveCommand(msg);
			break;
		} case EngageBattle: {
			int battleId = msg.readInt();
			Bais flags = msg.readFlags();
			byte mode = msg.readByte();
			int p1 = msg.readInt();
			int p2 = msg.readInt();
			addBattle(battleId, new BattleDesc(p1, p2, mode));
			if(flags.readBool()) {
				BattleConf conf = new BattleConf(msg);
				battle = new Battle(conf, msg, players.get(conf.id(0)),
						players.get(conf.id(1)), mePlayer.id, battleId, this);
				joinedChannels.peek().writeToHist("Battle between " + playerName(p1) +
						" and " + playerName(p2) + " started!");
				Intent in;
				in = new Intent(this, BattleActivity.class);
				in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(in);
				findingBattle = false;
			}
			break;
		}
		case SpectateBattle: {
			Bais flags = msg.readFlags();
			int battleId = msg.readInt();
			if (flags.readBool()) {
				if (spectatedBattles.contains(battleId)) {
					Log.e(TAG, "Already watching battle " + battleId);
					return;
				}
	            BattleConf conf = new BattleConf(msg);
	            SpectatingBattle battle = new SpectatingBattle(conf, players.get(conf.id(0)), players.get(conf.id(1)), battleId, this);
	            spectatedBattles.put(battleId, battle);
	            Intent intent = new Intent(this, BattleActivity.class);
	            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	            intent.putExtra("battleId", battleId);
	            startActivity(intent);
	        } else {
	            SpectatingBattle battle = spectatedBattles.remove(battleId);
	            if (battle != null && battle.activity != null) {
	            	battle.activity.end();
	            }
	        }
			break;
		}
		case SpectateBattleMessage: {
			int battleId = msg.readInt();
			msg.readInt();
			if (spectatedBattles.containsKey(battleId)) {
				spectatedBattles.get(battleId).receiveCommand(msg);
			}
			break;
		}
		case AskForPass: {
			salt = msg.readString();
			if (salt.length() < 6) {
				System.out.println("Protocol Error: The server requires insecure authentication");
				break;
			}
			askedForPass = true;
			if (chatActivity != null && (chatActivity.hasWindowFocus() || chatActivity.progressDialog.isShowing())) {
				chatActivity.notifyAskForPass();
			}
			break;
		} case AddChannel: {
			addChannel(msg.readString(),msg.readInt());
			break;
		} case RemoveChannel: {
			int chanId = msg.readInt();
			if (chatActivity != null)
				chatActivity.removeChannel(channels.get(chanId));
			channels.remove(chanId);
			break;
		} case ChanNameChange: {
			int chanId = msg.readInt();
			if (chatActivity != null)
				chatActivity.removeChannel(channels.get(chanId));
			channels.remove(chanId);
			channels.put(chanId, new Channel(chanId, msg.readString(), this));
			break;
		} default: {
			System.out.println("Unimplented message");
		}
		}


Input:
	protected boolean isPlayerProtected(String playername)
	{
		if (System.currentTimeMillis() - playerprotecttime.get(playername) > config.protecttime)
		{
			unprotectPlayer(playername);
		}
		Player player = Bukkit.getPlayerExact(playername);
		try {
			List<String> aregions = WGBukkit.getRegionManager(player.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(player.getLocation()));
			for (String region : aregions)
			{
				if (config.disabledegions.contains(region))
				{
					return false;
				}
			}
		} catch (Exception e) {}
		return playerprotecttime.containsKey(playername);
	}

Output:
	protected boolean isPlayerProtected(String playername)
	{
		if (playerprotecttime.containsKey(playername) && System.currentTimeMillis() - playerprotecttime.get(playername) > config.protecttime)
		{
			unprotectPlayer(playername);
		}
		Player player = Bukkit.getPlayerExact(playername);
		try {
			List<String> aregions = WGBukkit.getRegionManager(player.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(player.getLocation()));
			for (String region : aregions)
			{
				if (config.disabledegions.contains(region))
				{
					return false;
				}
			}
		} catch (Exception e) {}
		return playerprotecttime.containsKey(playername);
	}