org.mvel2.util.Make Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-realer Show documentation
Show all versions of virtdata-lib-realer Show documentation
With inspiration from other libraries
The newest version!
package org.mvel2.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
public class Make {
public static class Map {
public static Map $() {
return start();
}
public static Map start() {
return new Map(new HashMap());
}
public static Map start(Class extends java.util.Map> mapImpl) {
try {
return new Map(mapImpl.newInstance());
}
catch (Throwable t) {
throw new RuntimeException("error creating instance", t);
}
}
private java.util.Map mapInstance;
private Map(java.util.Map mapInstance) {
this.mapInstance = mapInstance;
}
public Map _(K key, V value) {
mapInstance.put(key, value);
return this;
}
public java.util.Map _() {
return finish();
}
public java.util.Map finish() {
return mapInstance;
}
}
public static class String {
public static String $() {
return start();
}
public static String start() {
return new String(new StringBuilder());
}
public java.lang.String _() {
return finish();
}
public java.lang.String finish() {
return stringAppender.toString();
}
private StringBuilder stringAppender;
String(StringBuilder stringAppender) {
this.stringAppender = stringAppender;
}
public String _(char c) {
stringAppender.append(c);
return this;
}
public String _(CharSequence cs) {
stringAppender.append(cs);
return this;
}
public String _(String s) {
stringAppender.append(s);
return this;
}
}
public static class List {
public static List $() {
return start();
}
public static List start() {
return new List(new ArrayList());
}
public static List start(Class extends java.util.List> listImpl) {
try {
return new List(listImpl.newInstance());
}
catch (Throwable t) {
throw new RuntimeException("error creating instance", t);
}
}
private java.util.List listInstance;
List(java.util.List listInstance) {
this.listInstance = listInstance;
}
public List _(V value) {
listInstance.add(value);
return this;
}
public java.util.List _() {
return finish();
}
public java.util.List finish() {
return listInstance;
}
}
public static class Set {
public static Set $() {
return start();
}
public static Set start() {
return new Set(new HashSet());
}
public static Set start(Class extends java.util.Set> listImpl) {
try {
return new Set(listImpl.newInstance());
}
catch (Throwable t) {
throw new RuntimeException("error creating instance", t);
}
}
private java.util.Set listInstance;
Set(java.util.Set listInstance) {
this.listInstance = listInstance;
}
public Set _(V value) {
listInstance.add(value);
return this;
}
public java.util.Set _() {
return finish();
}
public java.util.Set finish() {
return listInstance;
}
}
}