List of usage examples for java.util ArrayList subList
public List<E> subList(int fromIndex, int toIndex)
From source file:de.alpharogroup.collections.ListExtensions.java
/** * The Method removeLastValues(ArrayList, int) remove the last Values. * * @param <T>//from w w w .j a va2 s . c o m * the generic type * @param v * The Vector with the received Messages. * @param remove * How much to remove. * @return the list */ public static <T> List<T> removeLastValues(final ArrayList<T> v, final int remove) { if (remove < v.size()) { final List<T> l = v.subList(remove, v.size()); return l; } throw new IllegalArgumentException("You cannot remove " + "more element than in the ArrayList exists. \nSize from ArrayList:" + v.size() + "\n" + "Elements to be removed:" + remove + "\n The same ArrayList will be returned."); }
From source file:Framework.DBFramework.java
/** * Return CSV string which represent the dataset * * @param testFolder the folder in which the files for test are located * @param featureExtractor a Feature Extractor object * @param selectedFeatures the top selected features to build the dataset * with/* w ww .j a v a2 s.com*/ * @param topFeatures the number of top features to extract * @param numOfElementsInTrainset number of elements in the training from * which the classifier were trained * @param featureRepresentation featureRepresentation * @param addElementIDColumn add prefix column identifying the record * @param addClassificationColumn add suffix column identifying the class of * the record * @return CSV string which represent the dataset */ public static StringBuilder GenerateTestSet(String testFolder, AFeatureExtractor<String> featureExtractor, ArrayList<Pair<String, Integer>> selectedFeatures, int topFeatures, int numOfElementsInTrainset, FeatureRepresentation featureRepresentation, boolean addElementIDColumn, boolean addClassificationColumn) { DatasetCSVBuilder<String> datasetBuilder = new DatasetCSVBuilder<>(); ArrayList<String> testElements = Directories.GetDirectoryFilesPaths(testFolder); selectedFeatures = new ArrayList<>(selectedFeatures.subList(0, topFeatures)); StringBuilder datasetCSVHeader = DatasetCSVBuilder.GetDatasetHeaderCSV(topFeatures, addElementIDColumn, addClassificationColumn); StringBuilder datasetCSV = datasetBuilder.BuildDatabaseCSV(testElements, featureExtractor, selectedFeatures, numOfElementsInTrainset, featureRepresentation, Classification.Unknown, addElementIDColumn, addClassificationColumn); return datasetCSVHeader.append("\n").append(datasetCSV); }
From source file:org.samjoey.graphing.GraphUtility.java
/** * * @param games the games to graph//from w ww . j ava2 s. c o m * @param key the variable to create the graph with * @param start if index, the index at which to start, else the percent in * the game at which to start * @param stop if index, the index at which to end, else the percent in the * game at which to end * @param index * @return */ public static ChartPanel getCustomGraph(Game[] games, String key, double start, double stop, boolean index) { XYSeriesCollection dataset = new XYSeriesCollection(); for (Game game : games) { ArrayList<Double> data = game.getVar(key); int begin; int end; if (index) { begin = (int) start; end = (int) stop; } else { begin = (int) (data.size() / start); end = (int) (data.size() / stop); } XYSeries series = GraphUtility.createSeries(data.subList(begin, end), "" + game.getId()); dataset.addSeries(series); } JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.length; i++) { Game g = games[i]; if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
From source file:org.apache.hadoop.hive.ql.io.orc.RecordReaderFactory.java
private static List<OrcProto.Type> getSchemaOnRead(int numCols, Configuration conf) { String columnTypeProperty = conf.get(serdeConstants.LIST_COLUMN_TYPES); final String columnNameProperty = conf.get(serdeConstants.LIST_COLUMNS); if (columnTypeProperty == null || columnNameProperty == null) { return null; }//from www . jav a 2 s . c o m ArrayList<String> columnNames = Lists.newArrayList(columnNameProperty.split(",")); ArrayList<TypeInfo> fieldTypes = TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty); StructTypeInfo structTypeInfo = new StructTypeInfo(); // Column types from conf includes virtual and partition columns at the end. We consider only // the actual columns in the file. structTypeInfo.setAllStructFieldNames(Lists.newArrayList(columnNames.subList(0, numCols))); structTypeInfo.setAllStructFieldTypeInfos(Lists.newArrayList(fieldTypes.subList(0, numCols))); ObjectInspector oi = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(structTypeInfo); return getOrcTypes(oi); }
From source file:org.mycore.common.MCRUtils.java
/** * The method cut an ArrayList for a maximum of items. * /*from ww w . java 2 s . co m*/ * @param arrayin * The incoming ArrayList * @param maxitems * The maximum number of items * @return the cutted ArrayList * @deprecated use {@link List#subList(int, int)} instead */ @Deprecated public static <T> ArrayList<T> cutArrayList(ArrayList<T> arrayin, int maxitems) { return new ArrayList<>(arrayin.subList(0, Math.max(0, maxitems))); }
From source file:eionet.cr.web.action.admin.harvestscripts.HarvestScriptParser.java
/** * * @param str// w ww .j ava 2 s . co m * @param token * @return */ private static String substringBeforeToken(String str, String token) { if (str == null || str.trim().length() == 0 || token == null || token.trim().length() == 0) { return str; } StringTokenizer st = new StringTokenizer(str, " \t\n\r\f", true); ArrayList<String> originalTokens = new ArrayList<String>(); ArrayList<String> upperCaseTokens = new ArrayList<String>(); while (st.hasMoreTokens()) { String nextToken = st.nextToken(); originalTokens.add(nextToken); upperCaseTokens.add(nextToken.toUpperCase()); } int tokenIndex = upperCaseTokens.indexOf(token.toUpperCase()); if (tokenIndex >= 0) { return tokensToString(originalTokens.subList(0, tokenIndex)); } else { return str; } }
From source file:eionet.cr.web.action.admin.harvestscripts.HarvestScriptParser.java
/** * * @param str/* ww w . ja va 2s .com*/ * @param token * @return */ private static String substringAfterToken(String str, String token) { if (str == null || str.trim().length() == 0 || token == null || token.trim().length() == 0) { return str; } StringTokenizer st = new StringTokenizer(str, " \t\n\r\f", true); ArrayList<String> originalTokens = new ArrayList<String>(); ArrayList<String> upperCaseTokens = new ArrayList<String>(); while (st.hasMoreTokens()) { String nextToken = st.nextToken(); originalTokens.add(nextToken); upperCaseTokens.add(nextToken.toUpperCase()); } int tokenIndex = upperCaseTokens.indexOf(token.toUpperCase()); if (tokenIndex >= 0) { String afterToken = ""; int tokensSize = originalTokens.size(); if (tokenIndex < tokensSize - 1) { afterToken = tokensToString(originalTokens.subList(tokenIndex + 1, tokensSize)); } return afterToken; } else { return str; } }
From source file:ch.unil.genescore.pathway.GeneSetLibrary.java
License:asdf
public static List<Gene> getRandomSample(ArrayList<Gene> items, int m) { for (int i = 0; i < m; i++) { int pos = i + rand.nextInt(items.size() - i); Gene tmp = items.get(pos);//from ww w. java 2 s . c o m items.set(pos, items.get(i)); items.set(i, tmp); } return items.subList(0, m); }
From source file:graph.core.cli.AddCycEdgeCommand.java
@Override protected void executeImpl() { DAGPortHandler dagHandler = (DAGPortHandler) handler; if (data.isEmpty()) { printErrorNoData();/*from ww w.ja v a 2 s. co m*/ return; } ArrayList<String> split = UtilityMethods.split(data, ' '); // Extract microtheory (if one exists) ArrayList<String> edgeMt = UtilityMethods.split(split.get(0), ':'); String edgeStr = edgeMt.get(0); String microtheory = (edgeMt.size() > 1) ? StringUtils.join(edgeMt.subList(1, edgeMt.size()), ':') : null; Node creator = null; if (split.size() > 1) { try { creator = dagHandler.getDAG().findOrCreateNode(UtilityMethods.shrinkString(split.get(1), 1), creator); } catch (Exception e) { print("-1|Invalid creator node.\n"); return; } } try { Node[] nodes = dagHandler.getDAG().parseNodes(edgeStr, creator, dagHandler.get(DAGPortHandler.DYNAMICALLY_ADD_NODES).equals("true"), false); if (nodes == null) { print("-1|Problem parsing nodes.\n"); return; } boolean[] flags = dagHandler.asBooleanArray(DAGPortHandler.EDGE_FLAGS); if (flags.length < 1) flags = new boolean[1]; flags[0] = true; Edge edge = ((CycDAG) dagHandler.getDAG()).findOrCreateEdge(nodes, creator, microtheory, flags); dagHandler.getDAG().writeCommand("addedge " + data); if (edge instanceof ErrorEdge) { print("-1|" + ((ErrorEdge) edge).getError() + "\n"); } else { DAGEdge dagEdge = (DAGEdge) edge; print(dagEdge.getID() + "|" + edge.toString(!dagHandler.get(DAGPortHandler.PRETTY_RESULTS).equals("true")) + "|" + dagEdge.getCreator() + "|" + dagEdge.getCreationDate() + "\n"); } } catch (Exception e) { e.printStackTrace(); print("-1|Problem parsing nodes.\n"); return; } }
From source file:com.example.androidthings.doorbell.DoorbellEntryAdapter.java
@Override protected void populateViewHolder(DoorbellEntryViewHolder viewHolder, DoorbellEntry model, int position) { // Display the timestamp CharSequence prettyTime = DateUtils.getRelativeDateTimeString(mApplicationContext, model.getTimestamp(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); viewHolder.time.setText(prettyTime); // Display the image if (model.getImage() != null) { // Decode image data encoded by the Cloud Vision library byte[] imageBytes = Base64.decode(model.getImage(), Base64.NO_WRAP | Base64.URL_SAFE); Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); if (bitmap != null) { viewHolder.image.setImageBitmap(bitmap); } else {// www. j a va2 s. c om Drawable placeholder = ContextCompat.getDrawable(mApplicationContext, R.drawable.ic_image); viewHolder.image.setImageDrawable(placeholder); } } // Display the metadata if (model.getAnnotations() != null) { ArrayList<String> keywords = new ArrayList<>(model.getAnnotations().keySet()); int limit = Math.min(keywords.size(), 3); viewHolder.metadata.setText(TextUtils.join("\n", keywords.subList(0, limit))); } else { viewHolder.metadata.setText("no annotations yet"); } }