List of usage examples for java.util LinkedList size
int size
To view the source code for java.util LinkedList size.
Click Source Link
From source file:Main.java
public static String[] parseStringList(String list) { // final Pattern patWs = Pattern.compile("\\s+"); final Matcher matchWs = Pattern.compile("[^\\s]+").matcher(""); matchWs.reset(list);//www. jav a2 s .com LinkedList<String> matchList = new LinkedList<String>(); while (matchWs.find()) { matchList.add(matchWs.group()); } String[] retArr = new String[matchList.size()]; return (String[]) matchList.toArray(retArr); }
From source file:com.abuabdul.notedovn.util.NoteDovnUtil.java
public static LinkedList<NotesFolder> wrapInFolder(LinkedList<ScratchNote> notes) { int size = notes.size(); int folderSize = (size % 3) == 0 ? size / 3 : size / 3 + 1; LinkedList<NotesFolder> notesFolders = new LinkedList<>(new ArrayList<NotesFolder>(folderSize)); if (!isEmpty(notes)) { notes = groupByCategoryOrDate(notes); for (int j = 0; j < folderSize; j++) { NotesFolder folder = new NotesFolder(); for (int i = 1; i <= 3; i++) { folder.set(i, when(size - 1, notes)); size--;/*from www .j ava2 s . com*/ } notesFolders.add(folder); } } return notesFolders; }
From source file:com.abuabdul.notedovn.util.NoteDovnUtil.java
public static ScratchNote when(int actual, LinkedList<ScratchNote> notes) { if (actual >= 0 && actual < notes.size()) { return notes.get(actual); }// w ww . ja v a2s . co m return new ScratchNote(); }
From source file:de.vandermeer.asciitable.CWC_LongestWord.java
/** * Returns an array with the width of the longest word per column calculated from the given table. * Default padding will be added per column. * Padding for individual columns will be added if defined. * @param rows the table rows for calculations * @param colNumbers number of columns in the table * @return array with width of longest word for each column, null if input table was null *///from ww w .j a va2 s . co m public static int[] longestWord(LinkedList<AT_Row> rows, int colNumbers) { if (rows == null) { return null; } if (rows.size() == 0) { return new int[0]; } int[] ret = new int[colNumbers]; for (AT_Row row : rows) { if (row.getType() == TableRowType.CONTENT) { LinkedList<AT_Cell> cells = row.getCells(); for (int i = 0; i < cells.size(); i++) { if (cells.get(i).getContent() != null) { String[] ar = StringUtils .split(Object_To_StrBuilder.convert(cells.get(i).getContent()).toString()); for (int k = 0; k < ar.length; k++) { int count = ar[k].length() + cells.get(i).getContext().getPaddingLeft() + cells.get(i).getContext().getPaddingRight(); if (count > ret[i]) { ret[i] = count; } } } } } } return ret; }
From source file:fi.smaa.libror.MaximalVectorComputation.java
private static int[] listOfIntegersToIntArray(LinkedList<Integer> results) { int[] res = new int[results.size()]; int index = 0; for (Integer in : results) { res[index] = in;//from w ww .j a va 2 s. c om index++; } return res; }
From source file:Main.java
/** * Sorts a collection using a comparator and returns it as a {@link List} * * @param c Collection to be sorted * @param k Comparator to sort by/*from w w w . j a v a 2 s .c o m*/ * @param reverse Whether to reverse the sort order * @return a {@link List} of the sorted elements * @throws IllegalAccessException when unable to access the comparator class * @throws InstantiationException when unable to instantiate to comparator class */ public static <E> List<E> sortByCompare(Collection<E> c, Class<? extends Comparator<E>> k, boolean reverse) throws IllegalAccessException, InstantiationException { Comparator<E> comp = k.newInstance(); int moves = 0; boolean firstRun = true; LinkedList<E> l = new LinkedList<>(c); while (moves > 0 || firstRun) { firstRun = false; moves = 0; for (int i = 1; i < l.size(); i++) { E a = l.get(i - 1); E b = l.get(i); if (reverse ? comp.compare(a, b) < 0 : comp.compare(a, b) > 0) { l.set(i - 1, b); l.set(i, a); moves++; } } } return l; }
From source file:de.cubeisland.engine.core.util.McUUID.java
private static void getProfiles(List<Profile> profiles, LinkedList<String> players) { int amount = players.size(); CubeEngine.getLog().debug("Query UUID for: " + StringUtils.implode(",", players)); ArrayNode node = mapper.createArrayNode(); while (!players.isEmpty()) { ObjectNode criteria = mapper.createObjectNode(); criteria.put("name", players.poll()); criteria.put("agent", AGENT); node.add(criteria);/*from www . j a v a 2 s. com*/ } int page = 1; try { CubeEngine.getLog().info("Query Mojang for {} UUIDs", amount); while (amount > 0) { int read = readProfilesFromInputStream(postQuery(node, page++).getInputStream(), profiles); if (read == 0) { CubeEngine.getLog().info("No Answer for {} players", amount); } else if (read != amount) { amount -= read; continue; } return; } } catch (IOException e) { CubeEngine.getLog().error(e, "Could not retrieve UUID for given names!"); } }
From source file:fi.smaa.libror.MaximalVectorComputation.java
private static RealMatrix listOfRowsToMatrix(LinkedList<RealVector> results) { RealMatrix res = new Array2DRowRealMatrix(results.size(), results.getFirst().getDimension()); for (int i = 0; i < results.size(); i++) { res.setRowVector(i, results.get(i)); }/*w w w . j a va 2 s.c o m*/ return res; }
From source file:com.salsaberries.narchiver.Writer.java
/** * Writes all the pages to file.//from w w w.j a va2 s. c om * * @param pages * @param location */ public static void storePages(LinkedList<Page> pages, String location) { logger.info("Dumping " + pages.size() + " pages to file at " + location + "/"); File file = new File(location); // Make sure the directory exists if (!file.exists()) { try { file.mkdirs(); logger.info("Directory " + file.getAbsolutePath() + " does not exist, creating."); } catch (SecurityException e) { logger.error(e.getMessage()); } } // Write them to the file if they haven't been already written while (!pages.isEmpty()) { Page page = pages.removeFirst(); String fileName = file.getAbsolutePath() + "/" + page.getDate() + "|" + URLEncoder.encode(page.getTagURL()); try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) { writer.write(page.toString()); } catch (IOException e) { logger.warn(e.getMessage()); } // Temporarily try to reduce memory page.setHtml(""); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.webservice.WebServiceUtilFastTest.java
/** * Check that the given {@link WebApplicationException} is a <code>ValidationErrors</code> response with the expected values. * * @param response the {@link Response} to check * @param expectedStatusCode the expected status code * @param expectedInvalidValue the expected invalid value * @param expectedErrorMessage the expected error message * @param expectedMediaType the expected media type *//*from w ww . j a va 2s . c o m*/ public static void checkValidationErrorsResponse(final Response response, final int expectedStatusCode, final String expectedInvalidValue, final String expectedErrorMessage, final String expectedMediaType) { Assert.assertEquals(expectedStatusCode, response.getStatus()); final Object entity = response.getEntity(); Assert.assertEquals(ValidationErrors.class, entity.getClass()); final ValidationErrors validationErrors = (ValidationErrors) entity; Assert.assertNotNull(validationErrors); final List<ValidationErrors.ValidationError> validationErrorList = validationErrors.getValidationError(); Assert.assertNotNull(validationErrorList); Assert.assertEquals(1, validationErrorList.size()); final ValidationErrors.ValidationError validationError = validationErrorList.get(0); Assert.assertNotNull(validationError); Assert.assertEquals(expectedInvalidValue, validationError.getInvalidValue()); Assert.assertEquals(expectedErrorMessage, validationError.getErrorMessage()); final MultivaluedMap<String, Object> multivaluedMap = response.getMetadata(); Assert.assertNotNull(multivaluedMap); final Object contentType = multivaluedMap.get("Content-Type"); Assert.assertNotNull(contentType); assertTrue(contentType instanceof LinkedList); final LinkedList linkedList = (LinkedList) contentType; Assert.assertEquals(1, linkedList.size()); Assert.assertEquals(expectedMediaType, linkedList.get(0).toString()); }