Write Java code that even your CEO can read (https://github.com/libetl/ideaomatic)

Were you trying to write boilerplate code in Java lately ?

List> messageConverters = new ArrayList<>();
MappingJackson2HttpMessageConverter jackson2ConverterOther = new MappingJackson2HttpMessageConverter();
jackson2ConverterOther.setObjectMapper(pluginObjectMapper);
messageConverters.add(jackson2ConverterOther);
return messageConverters;

How much can you be far from the reality of your customers ?

try {
m_jaxbContext = JAXBContext.newInstance(m_contextPackages);
m_state = State.OPERATIONAL;
} catch (Throwable t) {
m_state = State.ERROR;
s_logger.error("Exeption creating JAXBContext for context: " + m_contextPackages, t);
}

Do you feel like understanding your own code ? And your other team members’ code too ?

Then write code that everyone will understand…
https://github.com/libetl/ideaomatic

Make the code as expressive as in English text. Here are some samples that can help you understand what is going on in this library :
https://github.com/libetl/ideaomatic/blob/master/src/test/java/outside/Tests.java

Make your own opinion on the topic and don’t hesitate to tell me if you want to add extra language elements (please post me some issues or some pull requests)

How to colorize an xml by code

The following class will help you to do that.

You can easily transform this :

<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
     http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
    <kcfgfile name=""/>
    <group name="com.librehat.yahooweather">
        <entry name="woeid" type="String">
            <default></default>
        </entry>
        <entry name="interval" type="Int">
            <default>60</default>
        </entry>
        <entry name="celsius" type="Bool">
            <default>true</default>
        </entry>
        <entry name="fahrenheit" type="Bool">
            <default>false</default>
        </entry>
        <entry name="ms" type="Bool">
            <default>false</default>
        </entry>
        <entry name="kmh" type="Bool">
            <default>true</default>
        </entry>
    </group>
</kcfg>

Into this :

coloredxml

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class XmlInColorsConverter {

    public static void main (String [] args) throws IOException {
        Scanner scanner = new Scanner(new File(args[0]));
        scanner.useDelimiter("\\A");
        System.out.println(new XmlInColorsConverter().convert(scanner.next()));
    }

    private static final Pattern NAME = Pattern.compile("(?:([a-zA-Z][a-zA-Z0-9]+):)?([a-zA-Z][a-zA-Z0-9._]+)");
    private static final Pattern VAL = Pattern.compile("\"((?:[^\"]|(?< =\\\\)\")*)\"");
    private static final Pattern ATTR = Pattern.compile("(" + NAME + ")\\s*(=)\\s*(" + VAL + ")\\s*");
    private static final Pattern MARKUP = Pattern.compile("(\\s*)(< )(/|\\?)?" + NAME + "\\s*(?:" + ATTR + ")*(/|\\?)?>");

    public String convert(String text) {
        return colorize(text, MARKUP.matcher(text));
    }

    private static String colorize(String input, Matcher matcher) {
        int lastEnd = 0;
        int level = 0;
        StringBuilder result = new StringBuilder();
        while (matcher.find()) {
            String oneMarkup = matcher.group();
            Matcher attrMatcher = ATTR.matcher(oneMarkup);
            String afterLastMatch = input.substring(lastEnd, matcher.start(2) == -1 ? 0 : matcher.start(2));
            level -= "/".equals(matcher.group(3)) ? 1 : 0;
            if (afterLastMatch.matches("\\s*")) {
                result.append("\n").append(IntStream.range(0, level).boxed().map(i -> "    ").collect(Collectors.joining()));
            }else {
                result.append(afterLastMatch);
            }
            level += matcher.group(3) == null ? 1 : 0;
            result.append("\033[1;33m< ").append((matcher.group(3) != null ? matcher.group(3) : "")).append((matcher.group(4) != null ?  "\033[34m" + matcher.group(4) + "\033[1;33m:" : "\033[1;33m")).append(matcher.group(5)).append("\033[0m");
            while (attrMatcher.find()) {
                result.append(" ").append((attrMatcher.group(2) != null ? "\033[34m" + attrMatcher.group(2) + "\033[35m:" : "\033[35m")).append(attrMatcher.group(3)).append("\033[32m=\033[36m").append(attrMatcher.group(5));
            }
            level -= "/".equals(matcher.group(12)) ? 1 : 0;
            result.append("\033[1;33m").append((matcher.group(12) != null ? matcher.group(12) : "")).append(">\033[0m");
            lastEnd = input.charAt(matcher.end()) == '\n' ? matcher.end() + 1 : matcher.end();
        }
        return result.toString();
    }
}