protected static Map<String,Object> newExprVars(AppConfig config) { Map<String, Object> vars = New.hashMap(); vars.put("config", config); vars.put("properties", config.getProperties()); return vars; }
/** * Converts an iterable into a list. If the iterable is already a list, it is returned. * Otherwise, an {@link java.util.ArrayList} is created with the contents of the iterable in the same iteration order. */ public static <T> List<T> toList(Iterable<T> iterable){ return iterable instanceof List ? (List<T>)iterable : New.arrayList(iterable); }
public static <T> Map<String, T> toMap(Collection<T> c, Function<T, String> key) { if(null == c) { return New.linkedHashMap(); } Map<String,T> map = new LinkedHashMap<>(c.size()); for(T item : c) { map.put(key.apply(item), item); } return map; }
public MApiPermission[] resolvePermissions(Route route, Class<?> resourceType) { List<MApiPermission> list = New.arrayList(); String resourceName = resourceType.getSimpleName(); Map<String,Object> vars = New.hashMap("resource", resourceName); permissions.forEach(p -> { if(p.matches(route)) { String value = eval(p.getValue(), vars); String desc = eval(p.getDescription(), vars); list.add(new MApiPermission(value, desc)); } }); if(list.isEmpty() && null != defaultPermission) { list.add(new MApiPermission(defaultPermission.getValue(), defaultPermission.getDescription())); } return list.toArray(new MApiPermission[0]); }
if(propertyVal == null){ if(type.isAssignableFrom(List.class)){ ArrayList arr = New.arrayList(); tryIncreaseSize(arr,index); arr.set(index, Converts.convert(value, bp.getElementType())); bp.setValue(bean, arr); }else{ Object[] arr = New.array(type.getComponentType(), index+1); arr[index] = Converts.convert(value, type.getComponentType()); bp.setValue(bean, arr); int len = Array.getLength(arr); if(len <= index){ List<Object> newArr = New.arrayList(); for(int i=0;i<len;i++){ newArr.add(Array.get(arr,i)); Object[] arr = (Object[])propertyVal; if(arr.length <= index){ List<Object> newArr = New.arrayList(); for(Object obj : arr){ newArr.add(obj);
/** * Converts a T[] array to a {@link Set}<T>. */ @SuppressWarnings("unchecked") public static <E,T extends E> Set<E> toSet(T... elements){ return New.<E>linkedHashSet(elements); }
/** * Copies an iterable's elements into an array. * * @param iterable the iterable to copy * @param type the type of the elements * @return a newly-allocated array into which all the elements of the iterable have been copied */ public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type) { Collection<? extends T> collection = toCollection(iterable); T[] array = New.array(type, collection.size()); return collection.toArray(array); }
@Override public Set<E> toSet() { return New.linkedHashSet(this); } }
@Override public List<E> toList() { return New.arrayList(this); }
@Override public String generateIdToken(AuthzAuthentication authc) { return generateIdToken(authc,New.hashMap()); }
public static <K,V> Map<K,V> buildMap(Map<K,? extends Buildable<V>> builders) { Map<K,V> m = New.linkedHashMap(); for(Entry<K, ? extends Buildable<V>> e : builders.entrySet()) { m.put(e.getKey(), e.getValue().build()); } return m; }
@Override public void process(int rownum, String[] values) throws Exception { //skip header if(rownum == 1){ return; } //columns : singular,acronyms String singular = values[0].toLowerCase(); String acronyms = values[1].toLowerCase(); Set<String> acronymSet = New.linkedHashSet(Strings.split(acronyms,'|')); singuralToAcronyms.put(singular, acronymSet); allAcronyms.addAll(acronymSet); } });
public GenericSqlCommand(GenericDb db,String... sqls) { super(db); this.sqls = New.arrayList(sqls); }
@Override public UserPrincipal lookupUserInfo(String at, String userId) { return requestUserInfo(New.hashMap("access_token", at)); }
private Map<String, FieldMapping> createFieldNameToFieldsMap() { Map<String, FieldMapping> map = New.linkedHashMap(); for (FieldMapping fm : fieldMappings) { map.put(fm.getFieldName().toLowerCase(), fm); } return Collections.unmodifiableMap(map); }
public List<Object> arrayToList(Object[] a) { return New.arrayList(a); }
@Override public String generateIdToken(AuthzAuthentication authc) { return generateIdToken(authc,New.hashMap()); }
private Map<String, FieldMapping> createColumnNameToFieldsMap() { Map<String, FieldMapping> map = New.linkedHashMap(); for (FieldMapping fm : fieldMappings) { map.put(fm.getColumn().getName().toLowerCase(), fm); } return Collections.unmodifiableMap(map); }
protected AlterTable doDropColumn(String columnName){ if(null == columnsToDrop){ columnsToDrop = New.arrayList(columnName); }else{ columnsToDrop.add(columnName); } return this; }
public static Map<String, String> queryStringToMap(String queryString){ Map<String, String> map = New.hashMap(); if(Strings.isNotEmpty(queryString)){ String[] kvs = Strings.split(queryString,'&'); for(String kvStr : kvs){ int idx = kvStr.indexOf('='); if(idx < 0){ map.put(kvStr.trim(),null); }else if(idx >= kvStr.length()){ String k = kvStr.substring(0,idx); map.put(k,null); }else { String k = kvStr.substring(0,idx); String v = kvStr.substring(idx+1); map.put(k,v); } } } return map; }