Created
August 26, 2015 06:12
-
-
Save esamson/1712958ddbfc4bb7d1ad to your computer and use it in GitHub Desktop.
Dump all PlantUML skinparams to standard output as a nested structure. Use as a starting point for defining a custom PlantUML skin.
This file contains hidden or 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
import com.google.common.collect.ComparisonChain; | |
import com.google.common.collect.Ordering; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.TreeSet; | |
import net.sourceforge.plantuml.SkinParam; | |
/** | |
* Dump skinparams skeleton so stdout | |
*/ | |
public class PlantUmlSkinParams { | |
public static void main(String[] args) { | |
Collection<String> params = SkinParam.getPossibleValues(); | |
Param root = new Param("root", -1); | |
for (String param : params) { | |
List<String> tokens = tokenize(param); | |
Param current = root; | |
for (int i = 0; i < tokens.size(); i++) { | |
String token = tokens.get(i); | |
current = current.add(token, i); | |
} | |
} | |
System.out.println(root.toString()); | |
} | |
static List<String> tokenize(String param) { | |
ArrayList<String> tokens = new ArrayList<>(); | |
int start = 0; | |
char current; | |
for (int i = 1; i < param.length(); i++) { | |
current = param.charAt(i); | |
if (Character.isUpperCase(current)) { | |
tokens.add(param.substring(start, i)); | |
start = i; | |
} | |
} | |
tokens.add(param.substring(start)); | |
return tokens; | |
} | |
static class Param { | |
final String name; | |
final int level; | |
HashMap<String, Param> children; | |
public Param(String name, int level) { | |
this.name = name; | |
this.level = level; | |
} | |
private Param add(String name, int level) { | |
if (children == null) { | |
children = new HashMap<>(); | |
} | |
Param child = children.get(name); | |
if (child == null) { | |
child = new Param(name, level); | |
children.put(name, child); | |
} | |
return child; | |
} | |
@Override | |
public String toString() { | |
StringBuilder s = new StringBuilder(); | |
if (level >= 0) { | |
s.append('\n'); | |
if (level == 0) { | |
s.append("skinparam "); | |
} else { | |
indent(s); | |
} | |
s.append(name); | |
} | |
if (children != null) { | |
if (level >= 0) { | |
s.append(' ').append('{'); | |
} | |
TreeSet<Param> sortedChildren = new TreeSet<>( | |
(Param o1, Param o2) -> ComparisonChain.start() | |
.compare(o1.children, o2.children, Ordering.allEqual() | |
.nullsFirst()) | |
.compare(o1.name, o2.name) | |
.result()); | |
sortedChildren.addAll(children.values()); | |
for (Param value : sortedChildren) { | |
s.append(value); | |
} | |
if (level >= 0) { | |
s.append('\n'); | |
indent(s); | |
s.append('}'); | |
} | |
} | |
if (level == 0) { | |
s.append('\n'); | |
} | |
return s.toString(); | |
} | |
private void indent(StringBuilder s) { | |
for (int i = 0; i < level; i++) { | |
s.append(" "); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment