
com.landawn.abacus.core.ParametersUtil Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2015, Haiyang Li.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.landawn.abacus.core;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.landawn.abacus.annotation.Internal;
import com.landawn.abacus.util.N;
// TODO: Auto-generated Javadoc
/**
* please don't use it in your application.
*
* @author Haiyang Li
* @since 0.8
*/
@Internal
final class ParametersUtil {
/**
*
* @param
* @param a
* @return
*/
@SafeVarargs
public static List asList(T... a) {
List list = (a.length == 0) ? new ArrayList<>() : new ArrayList<>(a.length);
for (int i = 0; i < a.length; i++) {
list.add(a[i]);
}
return list;
}
/**
*
* @param
* @param a
* @return
*/
@SafeVarargs
public static Set asSet(T... a) {
Set set = (a.length == 0) ? N.newHashSet() : N.newHashSet(a.length + 3);
for (int i = 0; i < a.length; i++) {
set.add(a[i]);
}
return set;
}
/**
*
* @param the key type
* @param the value type
* @param a
* @return
*/
@SuppressWarnings("unchecked")
@SafeVarargs
public static Map asMap(Object... a) {
if (0 != (a.length % 2)) {
throw new IllegalArgumentException("The property name and value are not paired. ");
}
Map map = (a.length == 0) ? new HashMap<>() : new HashMap<>(a.length / 2 + 3);
for (int i = 0; i < a.length; i++) {
map.put((K) a[i], (V) a[++i]);
}
return map;
}
/**
*
* @param propNameValues
* @return
*/
@SafeVarargs
public static Map asProps(Object... propNameValues) {
return asMap(propNameValues);
}
/**
*
* @param a
* @return
*/
@SafeVarargs
public static Map asOptions(Object... a) {
return asMap(a);
}
/**
*
* @param
* @param c
* @return
*/
public static Collection copy(Collection c) {
if (c instanceof List) {
return copy((List) c);
} else if (c instanceof Set) {
return copy((Set) c);
} else {
@SuppressWarnings("unchecked")
Collection copy = N.newInstance(c.getClass());
copy.addAll(c);
return copy;
}
}
/**
*
* @param
* @param c
* @return
*/
public static List copy(List c) {
if (c == null) {
return new ArrayList<>();
} else {
return (c instanceof Local) ? c : new ArrayList<>(c);
}
}
/**
*
* @param
* @param c
* @return
*/
public static Set copy(Set c) {
if (c == null) {
return N.newLinkedHashSet();
} else {
return (c instanceof Local) ? c : N.newLinkedHashSet(c);
}
}
/**
*
* @param the key type
* @param the value type
* @param m
* @return
*/
public static Map copy(Map m) {
if (m == null) {
return new LinkedHashMap<>();
} else {
return (m instanceof Local) ? m : new LinkedHashMap<>(m);
}
}
/**
* The Interface Local.
*/
static interface Local {
}
/**
* The Class HashMap.
*
* @param the key type
* @param the value type
*/
static final class HashMap extends java.util.HashMap implements Local {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -8221642996729977229L;
/**
* Instantiates a new hash map.
*/
public HashMap() {
super();
}
/**
* Instantiates a new hash map.
*
* @param initialCapacity
*/
public HashMap(int initialCapacity) {
super(initialCapacity);
}
/**
* Instantiates a new hash map.
*
* @param initialCapacity
* @param loadFactor
*/
public HashMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
}
/**
* Instantiates a new hash map.
*
* @param m
*/
public HashMap(Map extends K, ? extends V> m) {
super(m);
}
}
/**
* The Class LinkedHashMap.
*
* @param the key type
* @param the value type
*/
static final class LinkedHashMap extends java.util.HashMap implements Local {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 3744016416795543777L;
/**
* Instantiates a new linked hash map.
*/
public LinkedHashMap() {
super();
}
/**
* Instantiates a new linked hash map.
*
* @param initialCapacity
*/
public LinkedHashMap(int initialCapacity) {
super(initialCapacity);
}
/**
* Instantiates a new linked hash map.
*
* @param initialCapacity
* @param loadFactor
*/
public LinkedHashMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
}
/**
* Instantiates a new linked hash map.
*
* @param m
*/
public LinkedHashMap(Map extends K, ? extends V> m) {
super(m);
}
}
/**
* The Class HashSet.
*
* @param
*/
static final class HashSet extends java.util.HashSet implements Local {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 9081027352330623445L;
/**
* Instantiates a new hash set.
*/
public HashSet() {
super();
}
/**
* Instantiates a new hash set.
*
* @param initialCapacity
*/
public HashSet(int initialCapacity) {
super(initialCapacity);
}
/**
* Instantiates a new hash set.
*
* @param initialCapacity
* @param loadFactor
*/
public HashSet(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
}
/**
* Instantiates a new hash set.
*
* @param c
*/
public HashSet(Collection extends E> c) {
super(c);
}
}
/**
* The Class LinkedHashSet.
*
* @param
*/
static final class LinkedHashSet extends java.util.LinkedHashSet implements Local {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -8427957578044492143L;
/**
* Instantiates a new linked hash set.
*/
public LinkedHashSet() {
super();
}
/**
* Instantiates a new linked hash set.
*
* @param initialCapacity
*/
public LinkedHashSet(int initialCapacity) {
super(initialCapacity);
}
/**
* Instantiates a new linked hash set.
*
* @param initialCapacity
* @param loadFactor
*/
public LinkedHashSet(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
}
/**
* Instantiates a new linked hash set.
*
* @param c
*/
public LinkedHashSet(Collection extends E> c) {
super(c);
}
}
/**
* The Class ArrayList.
*
* @param
*/
static final class ArrayList extends java.util.ArrayList implements Local {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -6177282621875675144L;
/**
* Instantiates a new array list.
*/
public ArrayList() {
super();
}
/**
* Instantiates a new array list.
*
* @param initialCapacity
*/
public ArrayList(int initialCapacity) {
super(initialCapacity);
}
/**
* Instantiates a new array list.
*
* @param c
*/
public ArrayList(Collection extends E> c) {
super(c);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy