List of usage examples for java.util LinkedList add
public boolean add(E e)
From source file:eu.stratosphere.test.operators.UnionITCase.java
@Parameters public static Collection<Object[]> getConfigurations() throws FileNotFoundException, IOException { LinkedList<Configuration> testConfigs = new LinkedList<Configuration>(); //second input empty Configuration config = new Configuration(); config.setInteger("UnionTest#NoSubtasks", 4); config.setString("UnionTest#ExpectedResult", RESULT); config.setString("UnionTest#Input1Path", "non-empty"); config.setString("UnionTest#Input2Path", "empty"); testConfigs.add(config); //first input empty config = new Configuration(); config.setInteger("UnionTest#NoSubtasks", 4); config.setString("UnionTest#ExpectedResult", RESULT); config.setString("UnionTest#Input1Path", "empty"); config.setString("UnionTest#Input2Path", "non-empty"); testConfigs.add(config);/*from w ww .ja va2s. c o m*/ //both inputs full config = new Configuration(); config.setInteger("UnionTest#NoSubtasks", 4); config.setString("UnionTest#ExpectedResult", MAP_RESULT_TWICE); config.setString("UnionTest#Input1Path", "non-empty"); config.setString("UnionTest#Input2Path", "non-empty"); testConfigs.add(config); //both inputs empty config = new Configuration(); config.setInteger("UnionTest#NoSubtasks", 4); config.setString("UnionTest#ExpectedResult", EMPTY_RESULT); config.setString("UnionTest#Input1Path", "empty"); config.setString("UnionTest#Input2Path", "empty"); testConfigs.add(config); return toParameterList(testConfigs); }
From source file:com.allinfinance.startup.init.MenuInfoUtil.java
/** * ???//from ww w . j av a2s. c om * @param degree */ @SuppressWarnings("unchecked") public static LinkedHashMap<String, Object> setOperatorMenuWithDegree(String degree, String contextPath) { String sql = "select VALUE_ID FROM TBL_ROLE_FUNC_MAP ,TBL_ROLE_INF WHERE ROLE_ID = KEY_ID and KEY_ID = " + degree; ICommQueryDAO commQueryDAO = (ICommQueryDAO) ContextUtil.getBean("CommQueryDAO"); List<Object> funcMapList = commQueryDAO.findBySQLQuery(sql); List<Object> menuLvl1List = allMenuBean.getDataList(); LinkedHashMap<String, Object> menuIndexMap = new LinkedHashMap<String, Object>(); //????? for (int i = 0, n = menuLvl1List.size(); i < n; i++) { Map<String, Object> menuLvl1Map = (Map<String, Object>) menuLvl1List.get(i); LinkedList<Object> menuLvl2List = (LinkedList<Object>) menuLvl1Map.get(Constants.MENU_CHILDREN); for (int j = 0, m = menuLvl2List.size(); j < m; j++) { Map<String, Object> menuLvl2Map = (Map<String, Object>) menuLvl2List.get(j); LinkedList<Object> menuLvl3List = (LinkedList<Object>) menuLvl2Map.get(Constants.MENU_CHILDREN); for (int k = 0, l = menuLvl3List.size(); k < l; k++) { Map<String, Object> menuLvl3Map = (Map<String, Object>) menuLvl3List.get(k); for (int a = 0, b = funcMapList.size(); a < b; a++) { if (StringUtils.trim(funcMapList.get(a).toString()) .equals(StringUtils.trim(menuLvl3Map.get(Constants.MENU_ID).toString()))) { if (!menuIndexMap.containsKey(menuLvl1Map.get(Constants.MENU_ID).toString())) { Map<String, Object> menuLvl1HashMap = new LinkedHashMap<String, Object>(); menuLvl1HashMap.put(Constants.MENU_ID, menuLvl1Map.get(Constants.MENU_ID)); menuLvl1HashMap.put(Constants.MENU_TEXT, menuLvl1Map.get(Constants.MENU_TEXT)); menuLvl1HashMap.put(Constants.MENU_CLS, menuLvl1Map.get(Constants.MENU_CLS)); menuLvl1HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL1_FUNC); menuLvl1HashMap.put(Constants.TOOL_BAR_TYPE, Constants.TOOL_BAR_BUTTON); menuLvl1HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENU); Map<String, Object> menuLvl2HashMap = new LinkedHashMap<String, Object>(); menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID)); menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT)); menuLvl2HashMap.put(Constants.MENU_PARENT_ID, menuLvl2Map.get(Constants.MENU_PARENT_ID)); menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS)); // menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM); // menuLvl2HashMap.put(Constants.TOOLBAR_ICON, menuLvl2Map.get(Constants.TOOLBAR_ICON)); Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>(); menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID)); menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT)); menuLvl3HashMap.put(Constants.MENU_PARENT_ID, menuLvl3Map.get(Constants.MENU_PARENT_ID)); menuLvl3HashMap.put(Constants.MENU_LEAF, true); menuLvl3HashMap.put(Constants.MENU_URL, contextPath + menuLvl3Map.get(Constants.MENU_URL)); menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS)); menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC); //menuLvl3HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM); menuLvl3HashMap.put(Constants.TOOLBAR_ICON, menuLvl3Map.get(Constants.TOOLBAR_ICON)); LinkedList<Object> menuLvl3Child = new LinkedList<Object>(); menuLvl3Child.add(menuLvl3HashMap); menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child); menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child); LinkedList<Object> menuLvl2Child = new LinkedList<Object>(); menuLvl2Child.add(menuLvl2HashMap); menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child); menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child); menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap); } else { Map<String, Object> menuLvl1HashMap = (Map<String, Object>) menuIndexMap .get(menuLvl1Map.get(Constants.MENU_ID).toString()); LinkedList<Object> menuLvl2Child = (LinkedList<Object>) menuLvl1HashMap .get(Constants.MENU_CHILDREN); boolean hasMenu = false; for (int c = 0, d = menuLvl2Child.size(); c < d; c++) { Map<String, Object> menuLvl2HashMap = (Map<String, Object>) menuLvl2Child .get(c); if (StringUtils.trim(menuLvl2HashMap.get(Constants.MENU_ID).toString()).equals( StringUtils.trim(menuLvl2Map.get(Constants.MENU_ID).toString()))) { LinkedList<Object> menuLvl3Child = (LinkedList<Object>) menuLvl2HashMap .get(Constants.MENU_CHILDREN); Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>(); menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID)); menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT)); menuLvl3HashMap.put(Constants.MENU_PARENT_ID, menuLvl3Map.get(Constants.MENU_PARENT_ID)); menuLvl3HashMap.put(Constants.MENU_LEAF, true); menuLvl3HashMap.put(Constants.MENU_URL, contextPath + menuLvl3Map.get(Constants.MENU_URL)); menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS)); menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC); //menuLvl3HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM); menuLvl3HashMap.put(Constants.TOOLBAR_ICON, menuLvl3Map.get(Constants.TOOLBAR_ICON)); menuLvl3Child.add(menuLvl3HashMap); menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child); menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child); menuLvl2Child.set(c, menuLvl2HashMap); hasMenu = true; break; } } if (!hasMenu) { Map<String, Object> menuLvl2HashMap = new HashMap<String, Object>(); menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID)); menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT)); menuLvl2HashMap.put(Constants.MENU_PARENT_ID, menuLvl2Map.get(Constants.MENU_PARENT_ID)); menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS)); // menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM); // menuLvl2HashMap.put(Constants.TOOLBAR_ICON, menuLvl2Map.get(Constants.TOOLBAR_ICON)); LinkedList<Object> menuLvl3Child = new LinkedList<Object>(); Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>(); menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID)); menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT)); menuLvl3HashMap.put(Constants.MENU_PARENT_ID, menuLvl3Map.get(Constants.MENU_PARENT_ID)); menuLvl3HashMap.put(Constants.MENU_LEAF, true); menuLvl3HashMap.put(Constants.MENU_URL, contextPath + menuLvl3Map.get(Constants.MENU_URL)); menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS)); menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC); //menuLvl3HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM); menuLvl3HashMap.put(Constants.TOOLBAR_ICON, menuLvl3Map.get(Constants.TOOLBAR_ICON)); menuLvl3Child.add(menuLvl3HashMap); menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child); menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child); menuLvl2Child.add(menuLvl2HashMap); } menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child); menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child); menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap); } } } } } } return menuIndexMap; }
From source file:coolmapplugin.util.CMCyCommunicationUtil.java
private static List<Long> iterRowAndMatchNodeName(String jsonStringRows, Set<String> nodeNames) { LinkedList<Long> matchedNodeSUIDs = new LinkedList<>(); try {//from w w w . j a v a2 s .c o m JSONArray jsonRows = new JSONArray(jsonStringRows); for (int i = 0; i < jsonRows.length(); ++i) { JSONObject jsonRow = jsonRows.getJSONObject(i); String nodeName = jsonRow.getString("name"); if (nodeNames.contains(nodeName)) { matchedNodeSUIDs.add(jsonRow.getLong("SUID")); } } } catch (JSONException e) { return null; } return matchedNodeSUIDs; }
From source file:org.opennms.core.test.MockLogAppender.java
/** * <p>getEventsGreaterOrEqual</p> * *//*from www . ja v a 2 s .c om*/ public static LoggingEvent[] getEventsGreaterOrEqual(final Level level) { LinkedList<LoggingEvent> matching = new LinkedList<LoggingEvent>(); synchronized (s_events) { for (final LoggingEvent event : s_events) { if (event.getLevel().ge(level)) { matching.add(event); } } } return matching.toArray(EMPTY_LOGGING_EVENT); }
From source file:controllers.Service.java
public static void toPreview(String surveyId, String resultIDs) { // Find the survey Survey survey = Survey.findById(Long.decode(surveyId)); // make an array of results Collection<NdgResult> results = new ArrayList<NdgResult>(); NdgResult result = null;//from w ww .j a v a 2s. c o m // Get the result result = NdgResult.find("byId", Long.parseLong(resultIDs)).first(); if (result != null) { results.add(result); } // loop the result for (NdgResult current : results) { List<Question> questions = new ArrayList<Question>(); questions = survey.getQuestions(); LinkedList preview = new LinkedList(); if (questions.isEmpty()) { preview.add("No question"); } // loop the questions in the result for (Question question : questions) { preview.add(question.label); // get answers which correspond with questions Collection<Answer> answers = CollectionUtils.intersection(question.answerCollection, current.answerCollection); if (answers.isEmpty()) { preview.add("No answer"); } else if (answers.size() == 1) { Answer answer = answers.iterator().next(); //System.out.println("Answer " + answer.textData); if (answer.question.questionType.typeName.equalsIgnoreCase(QuestionTypesConsts.IMAGE)) { preview.add(answer.binaryData); } else { preview.add(answer.textData); } } } JSONSerializer previewSerializer = new JSONSerializer(); previewSerializer.rootName("preview"); renderJSON(previewSerializer.serialize(preview)); } }
From source file:org.dswarm.common.model.util.AttributePathUtil.java
public static LinkedList<AttributePath> parseAttributePathsNode(final JsonNode attributePathsNode, final Map<String, Attribute> attributeMap, final Map<String, AttributePath> attributePathMap) { if (attributePathsNode == null || !ArrayNode.class.isInstance(attributePathsNode)) { return null; }//from w w w .j ava 2 s. com final LinkedList<AttributePath> attributePaths = new LinkedList<>(); for (final JsonNode attributePathNode : attributePathsNode) { final AttributePath attributePath = parseAttributePathNode(attributePathNode, attributeMap, attributePathMap); if (attributePath != null) { attributePaths.add(attributePath); } } return attributePaths; }
From source file:org.opennms.core.test.MockLogAppender.java
/** * <p>getEventsAtLevel</p>// ww w.j a va2 s . c om * * Returns events that were logged at the specified level * */ public static LoggingEvent[] getEventsAtLevel(final Level level) { final LinkedList<LoggingEvent> matching = new LinkedList<LoggingEvent>(); synchronized (s_events) { for (final LoggingEvent event : s_events) { if (event.getLevel().ge(level)) { matching.add(event); } } } return matching.toArray(EMPTY_LOGGING_EVENT); }
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 w ww .j av a 2s.com*/ } notesFolders.add(folder); } } return notesFolders; }
From source file:com.frochr123.helper.CachedFileDownloader.java
public synchronized static SimpleEntry<String, SimpleEntry<String, File>> downloadFile(String url, String commaSeperatedAllowedFileTypes) throws IOException { // On invalid URL return null if (url == null || url.isEmpty()) { return null; }//from w w w . j a v a 2s . co m // Prepare check file extensions String allowedFileTypesString = commaSeperatedAllowedFileTypes; // Fallback to default allowed file types if (allowedFileTypesString == null || allowedFileTypesString.isEmpty()) { allowedFileTypesString = CACHE_DOWNLOADER_DEFAULT_FILETYPES; } // Get seperate file types from string and normalize to lowercase String[] allowedFileTypesArray = allowedFileTypesString.split(","); if (allowedFileTypesArray.length > 0) { // Normalize file extensions to lower case for (int i = 0; i < allowedFileTypesArray.length; ++i) { if (allowedFileTypesArray[i] != null && !allowedFileTypesArray[i].isEmpty()) { allowedFileTypesArray[i] = allowedFileTypesArray[i].toLowerCase(); } } } File file = null; String finalUrl = null; String fileExtension = null; String fileBaseName = null; SimpleEntry<String, File> innerResult = null; SimpleEntry<String, SimpleEntry<String, File>> finalResult = null; // Check if URL is already stored in cache map if (cacheMap.containsKey(url)) { if (cacheMap.get(url) != null) { innerResult = cacheMap.get(url); file = (File) (cacheMap.get(url).getValue()); } } // URL is not stored in cache, download and store it in cache else { // Resize cache if needed, LinkedHashMap keeps insertion order, oldest entries are first entries // Temporary store keys in list and remove afterwards to avoid read / write issues // Get one free space for new download LinkedList<String> deleteKeys = new LinkedList<String>(); for (Entry<String, SimpleEntry<String, File>> cacheEntry : cacheMap.entrySet()) { if ((cacheMap.size() - deleteKeys.size()) >= CACHE_DOWNLOADER_MAX_ENTRIES) { deleteKeys.add(cacheEntry.getKey()); } else { break; } } // Remove keys if (!deleteKeys.isEmpty()) { for (String key : deleteKeys) { // Delete old files if (cacheMap.get(key) != null && cacheMap.get(key).getValue() != null) { cacheMap.get(key).getValue().delete(); } // Remove entry in cache map cacheMap.remove(key); } } // Download file SimpleEntry<String, ByteArrayOutputStream> download = getResultFromURL(url); if (download == null || download.getKey() == null || download.getKey().isEmpty() || download.getValue() == null) { return null; } // Check for file type if (allowedFileTypesArray.length > 0) { finalUrl = download.getKey(); fileExtension = FilenameUtils.getExtension(finalUrl); // Check for valid fileExtension if (fileExtension == null || fileExtension.isEmpty()) { return null; } // Check if fileExtension is contained in allowed file extensions // Normalize file extensions to lower case boolean foundAllowedFileExtension = false; for (int i = 0; i < allowedFileTypesArray.length; ++i) { if (allowedFileTypesArray[i].equals(fileExtension)) { foundAllowedFileExtension = true; break; } } // File extension was not found, abort if (!foundAllowedFileExtension) { return null; } } // Write result to file, it is allowed file type fileBaseName = FilenameUtils.getBaseName(finalUrl); file = FileUtils.getNonexistingWritableFile(fileBaseName + "." + fileExtension); file.deleteOnExit(); FileOutputStream filestream = new FileOutputStream(file); download.getValue().writeTo(filestream); // Insert into cache and result variable innerResult = new SimpleEntry<String, File>(finalUrl, file); cacheMap.put(url, innerResult); } if (innerResult != null) { finalResult = new SimpleEntry<String, SimpleEntry<String, File>>(url, innerResult); } return finalResult; }
From source file:com.ibm.wala.cast.js.nodejs.NodejsRequireTargetSelector.java
/** * NODE_MODULES_PATHS(START)/* w ww .j a va2 s . com*/ * 1. let PARTS = path split(START) * 2. let I = count of PARTS - 1 * 3. let DIRS = [] * 4. while I >= 0, * a. if PARTS[I] = "node_modules" CONTINUE * b. DIR = path join(PARTS[0 .. I] + "node_modules") * c. DIRS = DIRS + DIR * d. let I = I - 1 * 5. return DIRS * * @param d * @throws IOException */ private static List<File> nodeModulePaths(File rootDir, File d) throws IOException { LinkedList<File> dirs = new LinkedList<>(); while (d.getCanonicalPath().startsWith(rootDir.getCanonicalPath()) && d.toPath().getNameCount() > 0) { // 4.a. if (!d.getName().equals("node_modules")) { // 4.b. and 4.c. dirs.add(new File(d, "node_modules")); } // 4.d. d = d.getParentFile(); } return dirs; }