List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:com.liveramp.cascading_ext.counters.Counters.java
private static String prettyTaps(Map<String, Tap> taps) { if (taps.keySet().isEmpty()) { return "[]"; }/*www. j ava 2 s . c o m*/ Collection<Tap> values = taps.values(); Tap first = values.toArray(new Tap[values.size()])[0]; if (first == null) { return "[null tap]"; } if (taps.keySet().size() == 1) { return "[\"" + first.getIdentifier() + "\"]"; } else { return "[\"" + first.getIdentifier() + "\",...]"; } }
From source file:imperial.modaclouds.monitoring.sda.weka.CreateArff.java
/** * Create arff file given the data/*from w w w . j a v a 2 s .c o m*/ * * @param timestamps_str the timestamps data * @param data the values of the metrics * @param metricName the metric name * @param fileName the file name to keep the arff file */ public static void create(ArrayList<ArrayList<String>> timestamps_str, ArrayList<ArrayList<String>> data, ArrayList<String> metricName, String fileName) { System.out.println("data: " + data.get(0)); long min_timestamp = Long.valueOf(Collections.min(timestamps_str.get(0))); long max_timestamp = Long.valueOf(Collections.max(timestamps_str.get(0))); for (int i = 1; i < timestamps_str.size(); i++) { long min_temp = Long.valueOf(Collections.min(timestamps_str.get(i))); long max_temp = Long.valueOf(Collections.max(timestamps_str.get(i))); if (max_temp < max_timestamp) { max_timestamp = max_temp; } if (min_temp > min_timestamp) { min_timestamp = min_temp; } } for (int i = 0; i < timestamps_str.size(); i++) { Iterator<String> iter_time = timestamps_str.get(i).iterator(); Iterator<String> iter_data = data.get(i).iterator(); while (iter_time.hasNext()) { long temp_timestamps = Long.valueOf(iter_time.next()); if (temp_timestamps < min_timestamp || temp_timestamps > max_timestamp) { iter_time.remove(); iter_data.next(); iter_data.remove(); } } } double[] timestamps = convertDoubles(timestamps_str.get(0)); double[] targetData = convertDoubles(data.get(0)); double[][] otherData = new double[data.size() - 1][timestamps.length]; for (int i = 0; i < data.size() - 1; i++) { double[] timestamps_temp = convertDoubles(timestamps_str.get(i)); double[] targetData_temp = convertDoubles(data.get(i)); SplineInterpolator spline = new SplineInterpolator(); Map<Double, Integer> map = new TreeMap<Double, Integer>(); for (int j = 0; j < timestamps_temp.length; j++) { map.put(timestamps_temp[j], j); } Collection<Integer> indices = map.values(); int[] indices_int = ArrayUtils.toPrimitive(indices.toArray(new Integer[indices.size()])); double[] timestamps_temp_new = new double[indices_int.length]; double[] targetData_temp_new = new double[indices_int.length]; for (int j = 0; j < indices_int.length; j++) { timestamps_temp_new[j] = timestamps_temp[indices_int[j]]; targetData_temp_new[j] = targetData_temp[indices_int[j]]; } PolynomialSplineFunction polynomical = spline.interpolate(timestamps_temp_new, targetData_temp_new); for (int j = 0; j < timestamps.length; j++) { try { otherData[i][j] = polynomical.value(timestamps[j]); } catch (Exception ex) { otherData[i][j] = targetData_temp_new[j]; } } } ArrayList<Attribute> attributes; Instances dataSet; attributes = new ArrayList<Attribute>(); for (String metric : metricName) { attributes.add(new Attribute(metric)); } dataSet = new Instances("data", attributes, 0); for (int i = 0; i < timestamps.length; i++) { double[] instanceValue1 = new double[dataSet.numAttributes()]; instanceValue1[0] = timestamps[i]; instanceValue1[1] = targetData[i]; for (int j = 0; j < data.size() - 1; j++) { instanceValue1[2 + j] = otherData[j][i]; } DenseInstance denseInstance1 = new DenseInstance(1.0, instanceValue1); dataSet.add(denseInstance1); } ArffSaver saver = new ArffSaver(); saver.setInstances(dataSet); try { String workingDir = System.getProperty("user.dir"); System.out.println("workingDir: " + workingDir); saver.setFile(new File(workingDir + "/" + fileName)); saver.writeBatch(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.malaguna.springsec.taglibs.SpringSecurityELLibrary.java
private static GrantedAuthority[] getUserAuthorities() { if (SecurityContextHolder.getContext() == null) { System.out.println("security context is empty, this seems to be a bug/misconfiguration!"); return new GrantedAuthority[0]; }//ww w. j a v a2 s.c om Authentication currentUser = SecurityContextHolder.getContext().getAuthentication(); if (currentUser == null) return new GrantedAuthority[0]; Collection<? extends GrantedAuthority> authorities = currentUser.getAuthorities(); if (authorities == null) return new GrantedAuthority[0]; return authorities.toArray(new GrantedAuthority[] {}); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T[] toArray(Collection<T> c, Class<T> clazz) { if (c == null || c.size() == 0) { T[] a = (T[]) java.lang.reflect.Array.newInstance(clazz, 0); return Collections.<T>emptyList().toArray(a); } else {// w w w.j a va2 s .c o m T[] a = (T[]) java.lang.reflect.Array.newInstance(clazz, c.size()); return c.toArray(a); } }
From source file:com.qwazr.QwazrConfiguration.java
private static FileFilter buildEtcFileFilter(Collection<String> etcs) { if (etcs == null || etcs.isEmpty()) return FileFileFilter.FILE; return new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(etcs.toArray(new String[etcs.size()]))); }
From source file:com.puppycrawl.tools.checkstyle.filters.SuppressionCommentFilterTest.java
private static String[] removeSuppressed(String[] from, String... remove) { final Collection<String> coll = Lists.newArrayList(Arrays.asList(from)); coll.removeAll(Arrays.asList(remove)); return coll.toArray(new String[coll.size()]); }
From source file:iddb.core.util.Functions.java
public static String join(Collection<String> list, String token) { return join(list.toArray(new String[0]), token); }
From source file:com.espertech.esper.event.vaevent.PropertyUtility.java
/** * Analyze multiple event types and determine common property sets that form property groups. * @param allProperties property names to look at * @param deltaEventTypes all types contributing * @param names names of properies//from w ww. ja v a 2 s . c o m * @return groups */ public static PropertyGroupDesc[] analyzeGroups(String[] allProperties, EventType[] deltaEventTypes, String[] names) { if (deltaEventTypes.length != names.length) { throw new IllegalArgumentException("Delta event type number and name number of elements don't match"); } allProperties = copyAndSort(allProperties); Map<MultiKey<String>, PropertyGroupDesc> result = new LinkedHashMap<MultiKey<String>, PropertyGroupDesc>(); int currentGroupNum = 0; for (int i = 0; i < deltaEventTypes.length; i++) { MultiKey<String> props = getPropertiesContributed(deltaEventTypes[i], allProperties); if (props.getArray().length == 0) { log.warn("Event type named '" + names[i] + "' does not contribute (or override) any properties of the revision event type"); continue; } PropertyGroupDesc propertyGroup = result.get(props); Map<EventType, String> typesForGroup; if (propertyGroup == null) { typesForGroup = new HashMap<EventType, String>(); propertyGroup = new PropertyGroupDesc(currentGroupNum++, typesForGroup, props.getArray()); result.put(props, propertyGroup); } else { typesForGroup = propertyGroup.getTypes(); } typesForGroup.put(deltaEventTypes[i], names[i]); } Collection<PropertyGroupDesc> outColl = result.values(); PropertyGroupDesc[] array = outColl.toArray(new PropertyGroupDesc[outColl.size()]); if (log.isDebugEnabled()) { log.debug(".analyzeGroups " + Arrays.toString(array)); } return array; }
From source file:com.dsh105.commodus.StringUtil.java
/** * Combines a collection of strings into a single string, separated by the given character set * * @param separator character set included between each part of the given array * @param stringCollection collection of strings to combine * @return the combined string//from www. j a v a 2s. c om */ public static String combine(String separator, Collection<String> stringCollection) { return combineArray(separator, stringCollection.toArray(EMPTY_STRING_ARRAY)); }
From source file:ArrayHelper.java
public static Type[] toTypeArray(Collection coll) { return (Type[]) coll.toArray(EMPTY_TYPE_ARRAY); }