List of usage examples for java.util List toArray
Object[] toArray();
From source file:com.ejoysoft.util.CacheSizes.java
/** * Returns the size in bytes of a List object. All elements * <b>must be Strings</b>./*w w w . j a va 2 s .c o m*/ * * @param list the List object to determine the size of. * @return the size of the List object. */ public static int sizeOfList(List list) { if (list == null) { return 0; } // Base list object (approximate) int size = 36; // Add in size of each value Object[] values = list.toArray(); for (int i = 0; i < values.length; i++) { size += sizeOfString((String) values[i]); } return size; }
From source file:springobjectmapper.ReflectionHelper.java
public static Object[] getValues(List<Field> fields, Object o) { List<Object> results = new ArrayList<Object>(); for (Field field : fields) { try {/*from w w w . j a va 2 s.c om*/ results.add(field.get(o)); } catch (Exception e) { ReflectionUtils.handleReflectionException(e); } } return results.toArray(); }
From source file:com.abssh.util.ReflectionUtils.java
/** * ????(getter), ??.// w w w .java 2 s . c o m * * @param collection * ???. * @param propertyName * ??????. * @param separator * . */ @SuppressWarnings("unchecked") public static String convertElementPropertyToString(final Collection collection, final String propertyName, final String separator) { List list = convertElementPropertyToList(collection, propertyName); return StringUtils.join(list.toArray(), separator); }
From source file:com.evolveum.midpoint.util.logging.LoggingUtils.java
private static void logExceptionInternal(Level first, Level second, Trace LOGGER, String message, Throwable ex, Object... objects) {//from w w w .ja va2s .c om Validate.notNull(LOGGER, "Logger can't be null."); Validate.notNull(ex, "Exception can't be null."); List<Object> args = new ArrayList<>(); args.addAll(Arrays.asList(objects)); args.add(ex.getMessage() + " (" + ex.getClass() + ")"); if (!first.equals(second)) { log(LOGGER, first, message + ", reason: {}", args.toArray()); } // Add exception to the list. It will be the last argument without {} in the message, // therefore the stack trace will get logged args.add(ex); log(LOGGER, second, message + ".", args.toArray()); }
From source file:com.wolvencraft.yasp.util.Util.java
/** * Compresses a List into a single-line json array * * @param source List to compress//from www . j a v a 2 s . c o m * @return String json array */ public static String toJsonArray(List<?> source) { return Statistics.getGson().toJson(source.toArray()); }
From source file:Utils.java
public static TreePath getPath(TreeNode treeNode) { List<Object> nodes = new ArrayList<Object>(); if (treeNode != null) { nodes.add(treeNode);//from w w w .j ava2 s. co m treeNode = treeNode.getParent(); while (treeNode != null) { nodes.add(0, treeNode); treeNode = treeNode.getParent(); } } return nodes.isEmpty() ? null : new TreePath(nodes.toArray()); }
From source file:cz.lbenda.rcp.DialogHelper.java
/** Open dialog with chooser when user can choose single option * @param question question which is show to user * @param items list of items which user can choose * @param <T> type of item//w ww.j a v a 2s . c o m * @return null if user click on cancel or don't choose anything, elsewhere choosed item */ public static <T> T chooseSingOption(String question, List<T> items) { //noinspection unchecked return chooseSingOption(question, (T[]) items.toArray()); }
From source file:Lists.java
@SuppressWarnings("unchecked") public static <T> List<T> normalizeUnmodifiable(List<T> list) { if (list.size() < 2) { return normalize(list); } else {/*www. ja va2 s . c o m*/ return (List<T>) Arrays.asList(list.toArray()); } }
From source file:Main.java
/** * /*w w w. j a v a2 s.c o m*/ * @return */ public static Object[] flatternMultipleValues(Object[] values) { if (values == null || values.length == 0) return new Object[0]; List flattern = new ArrayList(); for (int i = 0; i < values.length; i++) { if (values[i] instanceof Object[]) { Object[] flatternObj = (Object[]) values[i]; flattern.addAll(Arrays.asList(flatternMultipleValues(flatternObj))); } else { flattern.add(values[i]); } } return flattern.toArray(); }
From source file:eu.citadel.converter.io.index.CitadelIndexUtil.java
/** * Upload file on citadel index/*from w w w. j av a 2 s . c om*/ * @param requestURL Url for request * @param uploadFile File to be uploaded * @param charset Charset * @param userAgent User Agent of request * @return Response as String * @throws IOException */ private static String uploadFile(String requestURL, File uploadFile, String charset, String userAgent) throws IOException { MultipartUtility multipart = new MultipartUtility(requestURL, charset, userAgent); multipart.addHeaderField("User-Agent", "Converter"); multipart.addFilePart("fileUpload", uploadFile); List<String> response = multipart.finish(); log.trace("uploadFile server reply: "); for (String line : response) { log.trace(line); } return StringUtils.join(response.toArray()); }