List of usage examples for java.util ArrayList get
public E get(int index)
From source file:com.clust4j.algo.NearestCentroid.java
static double[][] getDeviationMinShrink(ArrayList<double[]> centroids, double[] centroid, double[][] ms, double shrinkage) { final int m = centroids.size(), n = centroid.length; double[] cent; final double[][] dev = new double[m][n]; for (int i = 0; i < m; i++) { cent = centroids.get(i); int sign = 1; for (int j = 0; j < n; j++) { double val = (cent[j] - centroid[j]) / ms[i][j]; sign = val > 0 ? 1 : -1; dev[i][j] = ms[i][j] * sign * FastMath.max(0, FastMath.abs(val) - shrinkage); }/* w w w .j a v a2 s . c o m*/ } return dev; }
From source file:com.pros.jsontransform.plugin.sort.ArraySortByAvgAge.java
public static void sort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer) throws ObjectTransformerException { // target array does not contain age information so // we need to use the source array from transformer context to perform the sort ArrayNode sourceArray = (ArrayNode) transformer.getSourceNode(); // move source and target array nodes to sorting array int size = arrayNode.size(); ArrayList<JsonNode> sortingArray = new ArrayList<JsonNode>(arrayNode.size()); for (int i = 0; i < size; i++) { ObjectNode sortingElement = transformer.mapper.createObjectNode(); sortingElement.put("source", sourceArray.get(i)); sortingElement.put("target", arrayNode.remove(0)); sortingArray.add(sortingElement); }//from w ww . j a va 2 s. c o m // sort array sortingArray.sort(new AvgAgeComparator(sortNode)); // move nodes back to targetArray for (int i = 0; i < sortingArray.size(); i++) { arrayNode.add(sortingArray.get(i).get("target")); } }
From source file:au.org.ala.layers.grid.GridCacheBuilder.java
private static void writeGroup(String dir, ArrayList<Grid> group) throws IOException { File f = null;/*from www .ja va 2 s . c o m*/ int count = 0; while ((f = new File(dir + File.separator + "group_" + count + ".txt")).exists()) { count++; } logger.info("writing: " + f.getName()); for (int i = 0; i < group.size(); i++) { logger.info(" has: " + group.get(i).filename); } writeGroupHeader(f, group); writeGroupGRD(new File(dir + File.separator + "group_" + count), group); writeGroupGRI(new File(dir + File.separator + "group_" + count + ".gri"), group); }
From source file:eulermind.importer.LineNode.java
private static void nestingListToTree(LineNode root, int maxIndent, int minIndent) { ArrayList<LineNode> detachedChildren = new ArrayList<LineNode>(); moveChildrenToList(root, detachedChildren); if (detachedChildren.get(0).m_indent > minIndent) { LineNode fakeFirstLine = new LineNode("fake first node"); fakeFirstLine.m_indent = minIndent; detachedChildren.add(0, fakeFirstLine); }/*w w w . j a va2s. c o m*/ root.add(detachedChildren.get(0)); for (int i = 1; i < detachedChildren.size(); i++) { LineNode detachedChild = detachedChildren.get(i); //?? // ? //?? for (int j = i - 1; j >= 0; j--) { LineNode attachedChild = detachedChildren.get(j); if (attachedChild.m_indent < detachedChild.m_indent) { attachedChild.add(detachedChild); break; } else if (attachedChild.m_indent == detachedChild.m_indent) { attachedChild.getParent().add(detachedChild); break; } } assert (detachedChild.getParent() != null); } }
From source file:com.web.server.util.ClassLoaderUtil.java
public static CopyOnWriteArrayList closeClassLoader(ClassLoader cl) { CopyOnWriteArrayList jars = new CopyOnWriteArrayList(); boolean res = false; Class classURLClassLoader = null; if (cl instanceof URLClassLoader) classURLClassLoader = URLClassLoader.class; else if (cl instanceof VFSClassLoader) { classURLClassLoader = VFSClassLoader.class; }//from ww w . j a v a 2s. co m Field f = null; try { f = classURLClassLoader.getDeclaredField("ucp"); System.out.println(f); } catch (NoSuchFieldException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (f != null) { f.setAccessible(true); Object obj = null; try { obj = f.get(cl); } catch (IllegalAccessException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (obj != null) { final Object ucp = obj; f = null; try { f = ucp.getClass().getDeclaredField("loaders"); System.out.println(f); } catch (NoSuchFieldException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (f != null) { f.setAccessible(true); ArrayList loaders = null; try { loaders = (ArrayList) f.get(ucp); res = true; } catch (IllegalAccessException e1) { // e1.printStackTrace(); } for (int i = 0; loaders != null && i < loaders.size(); i++) { obj = loaders.get(i); f = null; try { f = obj.getClass().getDeclaredField("jar"); // log.info(f); } catch (NoSuchFieldException e) { // e.printStackTrace(); // log.info(e.getMessage(), e); } if (f != null) { f.setAccessible(true); try { obj = f.get(obj); } catch (IllegalAccessException e1) { // e1.printStackTrace(); // log.info(e1.getMessage(), e1); } if (obj instanceof JarFile) { final JarFile jarFile = (JarFile) obj; System.out.println(jarFile.getName()); jars.add(jarFile.getName().replace("/", "\\").trim().toUpperCase()); // try { // jarFile.getManifest().clear(); // } catch (IOException e) { // // ignore // } try { jarFile.close(); } catch (IOException e) { e.printStackTrace(); // ignore // log.info(e.getMessage(), e); } } } } } } } return jars; }
From source file:DatasetCreation.DatasetCSVBuilder.java
/** * Print CSV string contain list of selected features * * @param selectedFeatures ArrayList of selected features selected features * @param featuresDocumentFrequencies all features document frequencies * (Benign, Malicious)//from www . j a v a2 s . c om * @return StringBuilder */ public static StringBuilder GetSelectedFeaturesCSV(ArrayList<Pair<String, Integer>> selectedFeatures, Map<String, int[]> featuresDocumentFrequencies) { StringBuilder sb = new StringBuilder(); sb.append("#,Feature,InBenignFiles,InMaliciousFiles,Total\n"); Pair pair; String feature; int[] benignMaliciousFrequencies; for (int i = 0; i < selectedFeatures.size(); i++) { pair = selectedFeatures.get(i); feature = pair.getKey().toString(); benignMaliciousFrequencies = featuresDocumentFrequencies.get(feature); sb.append(String.format("f%s,%s,%s,%s,%s", i + 1, feature, benignMaliciousFrequencies[0], benignMaliciousFrequencies[1], pair.getValue())).append("\n"); } return sb; }
From source file:com.clustercontrol.monitor.util.MonitorFilterPropertyUtil.java
/** * DTO?????//from ww w .j a va2 s . c o m * * @param property * @return */ public static MonitorFilterInfo property2dto(Property property) { MonitorFilterInfo info = new MonitorFilterInfo(); String monitorId = null; // ID String monitorTypeId = null;// ID String description = null; // String facilityId = null; // ID String calendarId = null; // String regUser = null; // ?? Timestamp regFromDate = null; // ?(From) Timestamp regToDate = null; // ?(To) String updateUser = null; // Timestamp updateFromDate = null; // (From) Timestamp updateToDate = null; // (To) Boolean monitorFlg = null; // Boolean collectorFlg = null; // ? String ownerRoleId = null; // ID ArrayList<?> values = null; //ID values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.MONITOR_ID); if (!"".equals(values.get(0))) { monitorId = (String) values.get(0); info.setMonitorId(monitorId); } //ID values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.MONITOR_TYPE_ID); if (!"".equals(values.get(0))) { monitorTypeId = (String) values.get(0); info.setMonitorTypeId(monitorTypeId); } // values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.DESCRIPTION); if (!"".equals(values.get(0))) { description = (String) values.get(0); info.setDescription(description); } //ID values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.FACILITY_ID); if (!"".equals(values.get(0))) { FacilityTreeItem item = (FacilityTreeItem) values.get(0); facilityId = item.getData().getFacilityId(); info.setFacilityId(facilityId); } // values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.CALENDAR_ID); if (!"".equals(values.get(0))) { calendarId = (String) values.get(0); info.setCalendarId(calendarId); } //?? values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.REG_USER); if (!"".equals(values.get(0))) { regUser = (String) values.get(0); info.setRegUser(regUser); } //?(From) values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.REG_FROM_DATE); if (values.get(0) instanceof Date) { regFromDate = new Timestamp(((Date) values.get(0)).getTime()); regFromDate.setNanos(999999999); info.setRegFromDate(regFromDate.getTime()); } //?(To) values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.REG_TO_DATE); if (values.get(0) instanceof Date) { regToDate = new Timestamp(((Date) values.get(0)).getTime()); regToDate.setNanos(999999999); info.setRegToDate(regToDate.getTime()); } // values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.UPDATE_USER); if (!"".equals(values.get(0))) { updateUser = (String) values.get(0); info.setUpdateUser(updateUser); } //(From) values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.UPDATE_FROM_DATE); if (values.get(0) instanceof Date) { updateFromDate = new Timestamp(((Date) values.get(0)).getTime()); updateFromDate.setNanos(999999999); info.setUpdateFromDate(updateFromDate.getTime()); } //(To) values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.UPDATE_TO_DATE); if (values.get(0) instanceof Date) { updateToDate = new Timestamp(((Date) values.get(0)).getTime()); updateToDate.setNanos(999999999); info.setUpdateToDate(updateToDate.getTime()); } // values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.MONITOR_FLG); if (!"".equals(values.get(0))) { if (ValidMessage.STRING_VALID.equals(values.get(0))) { monitorFlg = true; } else { monitorFlg = false; } } info.setMonitorFlg(monitorFlg); // ? values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.COLLECTOR_FLG); if (!"".equals(values.get(0))) { if (ValidMessage.STRING_VALID.equals(values.get(0))) { collectorFlg = true; } else { collectorFlg = false; } } info.setCollectorFlg(collectorFlg); //ID values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.OWNER_ROLE_ID); if (!"".equals(values.get(0))) { ownerRoleId = (String) values.get(0); info.setOwnerRoleId(ownerRoleId); } return info; }
From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.opt.OptimizationWrapper.java
/** * /* w w w. j a v a 2 s .com*/ * @param sb * @param pb */ private static void rfindParForProgramBlocks(StatementBlock sb, ProgramBlock pb, HashMap<Long, ParForStatementBlock> sbs, HashMap<Long, ParForProgramBlock> pbs) { if (pb instanceof ParForProgramBlock) { //put top-level parfor into map, but no recursion ParForProgramBlock pfpb = (ParForProgramBlock) pb; ParForStatementBlock pfsb = (ParForStatementBlock) sb; LOG.trace("ParFOR: found ParForProgramBlock with POptMode=" + pfpb.getOptimizationMode().toString()); if (pfpb.getOptimizationMode() != POptMode.NONE) { //register programblock tree for optimization long pfid = pfpb.getID(); pbs.put(pfid, pfpb); sbs.put(pfid, pfsb); } } else if (pb instanceof ForProgramBlock) { //recursive find ArrayList<ProgramBlock> fpbs = ((ForProgramBlock) pb).getChildBlocks(); ArrayList<StatementBlock> fsbs = ((ForStatement) ((ForStatementBlock) sb).getStatement(0)).getBody(); for (int i = 0; i < fpbs.size(); i++) rfindParForProgramBlocks(fsbs.get(i), fpbs.get(i), sbs, pbs); } else if (pb instanceof WhileProgramBlock) { //recursive find ArrayList<ProgramBlock> wpbs = ((WhileProgramBlock) pb).getChildBlocks(); ArrayList<StatementBlock> wsbs = ((WhileStatement) ((WhileStatementBlock) sb).getStatement(0)) .getBody(); for (int i = 0; i < wpbs.size(); i++) rfindParForProgramBlocks(wsbs.get(i), wpbs.get(i), sbs, pbs); } else if (pb instanceof IfProgramBlock) { //recursive find IfProgramBlock ifpb = (IfProgramBlock) pb; IfStatement ifs = (IfStatement) ((IfStatementBlock) sb).getStatement(0); ArrayList<ProgramBlock> ipbs1 = ifpb.getChildBlocksIfBody(); ArrayList<ProgramBlock> ipbs2 = ifpb.getChildBlocksElseBody(); ArrayList<StatementBlock> isbs1 = ifs.getIfBody(); ArrayList<StatementBlock> isbs2 = ifs.getElseBody(); for (int i = 0; i < ipbs1.size(); i++) rfindParForProgramBlocks(isbs1.get(i), ipbs1.get(i), sbs, pbs); for (int i = 0; i < ipbs2.size(); i++) rfindParForProgramBlocks(isbs2.get(i), ipbs2.get(i), sbs, pbs); } }
From source file:mt.LengthDistribution.java
public static void GetLengthDistributionArray(ArrayList<File> AllMovies, double[] calibration) { ArrayList<Double> maxlist = new ArrayList<Double>(); for (int i = 0; i < AllMovies.size(); ++i) { double maxlength = LengthDistribution.Lengthdistro(AllMovies.get(i)); if (maxlength != Double.NaN && maxlength > 0) maxlist.add(maxlength);/* ww w. j ava2 s . c o m*/ } Collections.sort(maxlist); int min = 0; int max = (int) Math.round(maxlist.get(maxlist.size() - 1)) + 1; XYSeries counterseries = new XYSeries("MT length distribution"); XYSeries Logcounterseries = new XYSeries("MT Log length distribution"); final ArrayList<Point> points = new ArrayList<Point>(); for (int length = 0; length < max; ++length) { HashMap<Integer, Integer> frameseed = new HashMap<Integer, Integer>(); int count = 0; for (int i = 0; i < AllMovies.size(); ++i) { File file = AllMovies.get(i); double currentlength = LengthDistribution.Lengthdistro(file); ArrayList<FLSobject> currentobject = Tracking.loadMTStat(file); if (currentlength > length) { for (int index = 0; index < currentobject.size(); ++index) { ArrayList<Integer> seedlist = new ArrayList<Integer>(); if (currentobject.get(index).length >= length) { seedlist.add(currentobject.get(index).seedID); if (frameseed.get(currentobject.get(index).Framenumber) != null && frameseed.get(currentobject.get(index).Framenumber) != Double.NaN) { int currentcount = frameseed.get(currentobject.get(index).Framenumber); frameseed.put(currentobject.get(index).Framenumber, seedlist.size() + currentcount); } else if (currentobject.get(index) != null) frameseed.put(currentobject.get(index).Framenumber, seedlist.size()); } } } } // Get maxima length, count int maxvalue = Integer.MIN_VALUE; for (int key : frameseed.keySet()) { int Count = frameseed.get(key); if (Count >= maxvalue) maxvalue = Count; } if (maxvalue != Integer.MIN_VALUE) { counterseries.add(length, maxvalue); if (maxvalue > 0) { Logcounterseries.add((length), Math.log(maxvalue)); points.add(new Point(new double[] { length, Math.log(maxvalue) })); } } } final XYSeriesCollection dataset = new XYSeriesCollection(); final XYSeriesCollection nofitdataset = new XYSeriesCollection(); dataset.addSeries(counterseries); nofitdataset.addSeries(counterseries); final XYSeriesCollection Logdataset = new XYSeriesCollection(); Logdataset.addSeries(Logcounterseries); final JFreeChart chart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", dataset); final JFreeChart nofitchart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", nofitdataset); // Fitting line to log of the length distribution interpolation.Polynomial poly = new interpolation.Polynomial(1); try { poly.fitFunction(points); } catch (NotEnoughDataPointsException e) { // TODO Auto-generated catch block e.printStackTrace(); } DisplayPoints.display(nofitchart, new Dimension(800, 500)); dataset.addSeries(Tracking.drawexpFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Exponential fit")); NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setMaximumFractionDigits(3); TextTitle legendText = new TextTitle("Mean Length" + " : " + nf.format(-1.0 / poly.getCoefficients(1)) + " " + "Standard Deviation" + " : " + nf.format(poly.SSE)); legendText.setPosition(RectangleEdge.RIGHT); DisplayPoints.display(chart, new Dimension(800, 500)); chart.addSubtitle(legendText); final JFreeChart logchart = ChartFactory.createScatterPlot("MT Log length distribution", "Number of MT", "Length (micrometer)", Logdataset); // DisplayPoints.display(logchart, new Dimension(800, 500)); for (int i = 1; i >= 0; --i) System.out.println(poly.getCoefficients(i) + " " + "x" + " X to the power of " + i); // Logdataset.addSeries(Tracking.drawFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Straight line fit")); WriteLengthdistroFile(AllMovies, counterseries, 0); }
From source file:org.amanzi.splash.chart.Charts.java
/** * @param categories/*ww w . j a v a 2 s .c om*/ * @param values * @return */ public static DefaultCategoryDataset getBarChartDataset(ArrayList<CellNode> categories, ArrayList<CellNode> values) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int n = categories.size(); int m = values.size(); int k = m / n; try { for (int i = 0; i < n; i++) { CellNode catNode = categories.get(i); for (int j = 0; j < k; j++) { CellNode valNode = values.get(i + n * j); dataset.addValue(Double.parseDouble((String) valNode.getValue()), "Series " + j, (String) catNode.getValue()); } } } catch (final NumberFormatException e) { showErrorDlg(e); } return dataset; }