List of usage examples for java.util LinkedList removeLast
public E removeLast()
From source file:android.net.http.Connection.java
/** * After a send/receive failure, any pipelined requests must be * cleared back to the mRequest queue/*from ww w . j a v a2 s .co m*/ * @return true if mRequests is empty after pipe cleared */ private boolean clearPipe(LinkedList<Request> pipe) { boolean empty = true; if (HttpLog.LOGV) HttpLog.v("Connection.clearPipe(): clearing pipe " + pipe.size()); synchronized (mRequestFeeder) { Request tReq; while (!pipe.isEmpty()) { tReq = (Request) pipe.removeLast(); if (HttpLog.LOGV) HttpLog.v("clearPipe() adding back " + mHost + " " + tReq); mRequestFeeder.requeueRequest(tReq); empty = false; } if (empty) empty = !mRequestFeeder.haveRequest(mHost); } return empty; }
From source file:org.springframework.core.convert.support.GenericConversionService.java
private GenericConverter findConverterForClassPair(TypeDescriptor sourceType, TypeDescriptor targetType) { Class<?> sourceObjectType = sourceType.getObjectType(); if (sourceObjectType.isInterface()) { LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>(); classQueue.addFirst(sourceObjectType); while (!classQueue.isEmpty()) { Class<?> currentClass = classQueue.removeLast(); if (logger.isTraceEnabled()) { logger.trace("Searching for converters indexed by sourceType [" + currentClass.getName() + "]"); }//ww w. jav a 2 s . com Map<Class<?>, MatchableConverters> converters = getTargetConvertersForSource(currentClass); GenericConverter converter = getMatchingConverterForTarget(sourceType, targetType, converters); if (converter != null) { return converter; } Class<?>[] interfaces = currentClass.getInterfaces(); for (Class<?> ifc : interfaces) { classQueue.addFirst(ifc); } } Map<Class<?>, MatchableConverters> objectConverters = getTargetConvertersForSource(Object.class); return getMatchingConverterForTarget(sourceType, targetType, objectConverters); } else { LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>(); classQueue.addFirst(sourceObjectType); while (!classQueue.isEmpty()) { Class<?> currentClass = classQueue.removeLast(); if (logger.isTraceEnabled()) { logger.trace("Searching for converters indexed by sourceType [" + currentClass.getName() + "]"); } Map<Class<?>, MatchableConverters> converters = getTargetConvertersForSource(currentClass); GenericConverter converter = getMatchingConverterForTarget(sourceType, targetType, converters); if (converter != null) { return converter; } if (currentClass.isArray()) { Class<?> componentType = ClassUtils .resolvePrimitiveIfNecessary(currentClass.getComponentType()); if (componentType.getSuperclass() != null) { classQueue.addFirst(Array.newInstance(componentType.getSuperclass(), 0).getClass()); } else if (componentType.isInterface()) { classQueue.addFirst(Object[].class); } } else { Class<?>[] interfaces = currentClass.getInterfaces(); for (Class<?> ifc : interfaces) { addInterfaceHierarchy(ifc, classQueue); } if (currentClass.getSuperclass() != null) { classQueue.addFirst(currentClass.getSuperclass()); } } } return null; } }
From source file:org.springframework.core.convert.support.GenericConversionService.java
private GenericConverter getMatchingConverterForTarget(TypeDescriptor sourceType, TypeDescriptor targetType, Map<Class<?>, MatchableConverters> converters) { Class<?> targetObjectType = targetType.getObjectType(); if (targetObjectType.isInterface()) { LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>(); classQueue.addFirst(targetObjectType); while (!classQueue.isEmpty()) { Class<?> currentClass = classQueue.removeLast(); if (logger.isTraceEnabled()) { logger.trace("and indexed by targetType [" + currentClass.getName() + "]"); }// w w w.j a v a2 s . c o m MatchableConverters matchable = converters.get(currentClass); GenericConverter converter = matchConverter(matchable, sourceType, targetType); if (converter != null) { return converter; } Class<?>[] interfaces = currentClass.getInterfaces(); for (Class<?> ifc : interfaces) { classQueue.addFirst(ifc); } } if (logger.isTraceEnabled()) { logger.trace("and indexed by [java.lang.Object]"); } return matchConverter(converters.get(Object.class), sourceType, targetType); } else { LinkedList<Class<?>> classQueue = new LinkedList<Class<?>>(); classQueue.addFirst(targetObjectType); while (!classQueue.isEmpty()) { Class<?> currentClass = classQueue.removeLast(); if (logger.isTraceEnabled()) { logger.trace("and indexed by targetType [" + currentClass.getName() + "]"); } MatchableConverters matchable = converters.get(currentClass); GenericConverter converter = matchConverter(matchable, sourceType, targetType); if (converter != null) { return converter; } if (currentClass.isArray()) { Class<?> componentType = ClassUtils .resolvePrimitiveIfNecessary(currentClass.getComponentType()); if (componentType.getSuperclass() != null) { classQueue.addFirst(Array.newInstance(componentType.getSuperclass(), 0).getClass()); } else if (componentType.isInterface()) { classQueue.addFirst(Object[].class); } } else { Class<?>[] interfaces = currentClass.getInterfaces(); for (Class<?> ifc : interfaces) { addInterfaceHierarchy(ifc, classQueue); } if (currentClass.getSuperclass() != null) { classQueue.addFirst(currentClass.getSuperclass()); } } } return null; } }
From source file:org.artifactory.storage.db.binstore.service.BinaryStoreImpl.java
void addBinaryProvider(BinaryProviderBase binaryProvider) { LinkedList<BinaryProviderBase> binaryProviders = Lists.newLinkedList(); BinaryProviderBase bp = getFirstBinaryProvider(); while (bp != null) { binaryProviders.add(bp);//w w w.ja va 2s. c o m bp = bp.next(); } binaryProviders.removeLast(); binaryProviders.add(binaryProvider); setBinaryProvidersContext(binaryProviders); }
From source file:org.nuxeo.apidoc.documentation.DocumentationHelper.java
/** * Transforms Nuxeo extension point {@code <documentation>} content into * HTML.//w w w . jav a 2 s. co m * <p> * <ul> * <li>standalone newlines are turned into {@code * <p/> * }</li> * <li>{@code <code>} blocks are turned into a {@code <div class="code">} * with a {@code * * <pre> * <code>}</li> * <li>{@code @author} blocks are removed</li> * </ul> */ public static String getHtml(String doc) { if (doc == null) { return ""; } HtmlSanitizerService sanitizer = Framework.getService(HtmlSanitizerService.class); if (sanitizer == null && !Framework.isTestModeSet()) { throw new RuntimeException("Cannot find HtmlSanitizerService"); } LinkedList<String> lines = new LinkedList<>(); lines.add(P); boolean newline = true; boolean firstcode = false; boolean code = false; for (String line : doc.split("\n")) { if (!code) { line = line.trim(); if ("".equals(line) || BR.equals(line) || BR2.equals(line) || BR3.equals(line) || P.equals(line) || P2.equals(line)) { if (!newline) { lines.add(P); newline = true; } } else { if ("<code>".equals(line)) { code = true; firstcode = true; line = CODE_START; if (!newline) { line = P + line; } lines.add(line); newline = false; } else if (line.startsWith(AUTHOR)) { if (!newline) { lines.add(P); } newline = true; } else { lines.add(line); newline = false; } } } else { // code if ("</code>".equals(line.trim())) { code = false; line = CODE_END + P; newline = true; } else { line = line.replace("&", "&").replace("<", "<"); } if (firstcode) { // don't add a \n at the start of the code firstcode = false; line = lines.removeLast() + line; } lines.add(line); } } if (code) { lines.add(CODE_END); } String html = StringUtils.join(lines, "\n"); if (sanitizer != null) { html = sanitizer.sanitizeString(html, null); } return secureXML(html); }
From source file:com.linuxbox.enkive.statistics.consolidation.AbstractConsolidator.java
/** * this method recurses through a given template map to add consolidated * data to a new map as defined by each key's ConsolidationDefinition * // w w w . ja v a2s . co m * @param templateData * - the map used to trace * @param consolidatedMap * - the map being built * @param path * - the path to variables being used for trace * @param statKeys * - the list of a gatherer's consolidation definitions * @param gathererData * - all the data cooresponding to a given gatherer * @return returns the built consolidatedMap variable */ protected Map<String, Object> generateConsolidatedMap(Map<String, Object> templateData, Map<String, Object> consolidatedMap, LinkedList<String> path, List<ConsolidationKeyHandler> statKeys, List<Map<String, Object>> gathererData) { for (String key : templateData.keySet()) { path.addLast(key); ConsolidationKeyHandler matchingDef = findMatchingPath(path, statKeys); if (matchingDef != null) { consolidateMaps(consolidatedMap, gathererData, matchingDef, path); } else { if (templateData.get(key) instanceof Map) { generateConsolidatedMap((Map<String, Object>) templateData.get(key), consolidatedMap, path, statKeys, gathererData); } } path.removeLast(); } return consolidatedMap; }
From source file:org.alfresco.repo.rendition.StandardRenditionLocationResolverImpl.java
private RenditionLocationImpl findOrCreateTemplatedPath(NodeRef sourceNode, String path, NodeRef companyHome) { if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("FindOrCreateTemplatedPath for ").append(sourceNode).append(", ").append(path); log.debug(msg.toString());/*from ww w. ja va2 s.c o m*/ } NodeService nodeService = serviceRegistry.getNodeService(); List<String> pathElements = Arrays.asList(path.split("/")); LinkedList<String> folderElements = new LinkedList<String>(pathElements); // We need to strip out any empty strings within the path elements. // prior to passing this path to the fileFolderService for creation. // e.g. "//foo//bar///item.txt" would cause an exception. folderElements.removeAll(Arrays.asList(new String[] { "" })); // Remove 'Company Home' if it is at the start of the path. Serializable companyHomeName = nodeService.getProperty(companyHome, ContentModel.PROP_NAME); if (folderElements.getFirst().equals(companyHomeName)) { folderElements.removeFirst(); } String fileName = folderElements.removeLast(); if (fileName == null || fileName.length() == 0) { StringBuilder msg = new StringBuilder(); msg.append("The path must include a valid filename! Path: ").append(path); if (log.isDebugEnabled()) { log.debug(msg.toString()); } throw new RenditionServiceException(msg.toString()); } FileFolderService fileFolderService = serviceRegistry.getFileFolderService(); NodeRef parent = companyHome; if (!folderElements.isEmpty()) { FileInfo parentInfo = FileFolderUtil.makeFolders(fileFolderService, companyHome, folderElements, ContentModel.TYPE_FOLDER); parent = parentInfo.getNodeRef(); } if (log.isDebugEnabled()) { log.debug("folderElements: " + folderElements); log.debug("parent: " + parent); log.debug(" " + nodeService.getType(parent) + " " + nodeService.getPath(parent)); log.debug("fileName: " + fileName); } NodeRef child = fileFolderService.searchSimple(parent, fileName); if (log.isDebugEnabled()) { StringBuilder msg = new StringBuilder(); msg.append("RenditionLocation parent=").append(parent).append(", child=").append(child) .append(", fileName=").append(fileName); log.debug(msg.toString()); if (child != null) { log.debug("child path = " + nodeService.getPath(child)); } } return new RenditionLocationImpl(parent, child, fileName); }
From source file:com.mirth.connect.client.ui.components.MirthTree.java
/** * Construct a path for a specific node. * /*from www. j a va2 s.co m*/ * @param parent * @param prefix * @param suffix * @return */ public static StringBuilder constructPath(TreeNode parent, String prefix, String suffix) { StringBuilder sb = new StringBuilder(); sb.insert(0, prefix); MirthTreeNode node = (MirthTreeNode) parent; SerializationType serializationType = node.getSerializationType(); // Get the parent if the leaf was actually passed in instead of the parent. if (node.isLeaf()) { node = (MirthTreeNode) node.getParent(); } /* * MIRTH-3196 - We now assign nodes types as we iterate from child to parent to add more * versatility to namespace drag and drop. The drag and drop can drag nodes, attribute or * namespace attributes so the user should be able to correctly do these now. If a node has * a namespace then will wildcard it. If an ancestor of the node has an implicit namespace * then we will also append a wildcard. The only exception to this is if the implicit * namespace is on the root node, we actually set this to the default namespace in * JavaScriptBuilder. */ LinkedList<PathNode> nodeQ = new LinkedList<PathNode>(); while (node != null && node.getParent() != null) { if (serializationType.equals(SerializationType.JSON) && node.isArrayElement()) { nodeQ.add(new PathNode(String.valueOf(node.getParent().getIndex(node) - 1), PathNode.NodeType.ARRAY_CHILD)); } else { PathNode.NodeType type = PathNode.NodeType.OTHER; if (serializationType.equals(SerializationType.XML)) { type = getXmlNodeType(node); } String nodeValue = node.getValue().replaceAll(" \\(.*\\)", ""); nodeQ.add(new PathNode(nodeValue, type)); if (serializationType.equals(SerializationType.XML)) { int parentIndexValue = getIndexOfNode(node); if (parentIndexValue != -1) { nodeQ.add(nodeQ.size() - 1, new PathNode(String.valueOf(parentIndexValue), PathNode.NodeType.ARRAY_CHILD)); } } } node = (MirthTreeNode) node.getParent(); } boolean foundImplicitNamespace = false; while (!nodeQ.isEmpty()) { PathNode nodeValue = nodeQ.removeLast(); //We start at the parent so if any implicit namespaces are reached then the rest of the nodes should wildcard the namespace boolean includeNamespace = false; PathNode.NodeType type = nodeValue.getType(); //We don't want to include a wildcard for attributes, ns definitions or array indices if (serializationType.equals(SerializationType.XML) && !Arrays .asList(PathNode.NodeType.XML_ATTRIBUTE, PathNode.NodeType.XMLNS_DEFINITION, PathNode.NodeType.XML_PREFIX_DEFINITION, PathNode.NodeType.ARRAY_CHILD) .contains(type)) { if (foundImplicitNamespace) { includeNamespace = true; } else if (type == PathNode.NodeType.XML_XMLNS_NODE) { foundImplicitNamespace = true; includeNamespace = true; } else if (type == PathNode.NodeType.XML_PREFIXED_NODE) { includeNamespace = true; } } if (includeNamespace) { int colonIndex = nodeValue.getValue().indexOf(':') + 1; sb.append(".*::['" + StringUtils.substring(nodeValue.getValue(), colonIndex) + "']"); } else if (serializationType.equals(SerializationType.XML) && type == PathNode.NodeType.XMLNS_DEFINITION) { sb.append(".namespace('')"); } else if (serializationType.equals(SerializationType.XML) && type == PathNode.NodeType.XML_PREFIX_DEFINITION) { sb.append(".namespace('" + StringUtils.substringAfter(nodeValue.getValue(), "@xmlns:") + "')"); } else if (type == PathNode.NodeType.XML_PREFIXED_ATTRIBUTE) { sb.append(".@*::['" + StringUtils.substringAfter(nodeValue.getValue(), ":") + "']"); } else if (type == PathNode.NodeType.ARRAY_CHILD) { sb.append("[" + nodeValue.getValue() + "]"); } else { sb.append("['" + nodeValue.getValue() + "']"); } } if (!serializationType.equals(SerializationType.JSON)) { sb.append(suffix); } return sb; }
From source file:org.grails.datastore.mapping.simpledb.util.SimpleDBTemplateImpl.java
private List<Item> queryInternal(String query, int max, int attempt) { LinkedList<Item> items = new LinkedList<Item>(); try {/*www.ja v a 2s . c o m*/ SelectRequest selectRequest = new SelectRequest(query); SelectResult result = sdb.select(selectRequest); items.addAll(result.getItems()); String nextToken = null; do { nextToken = result.getNextToken(); if (nextToken != null) { selectRequest = new SelectRequest(query).withNextToken(nextToken); result = sdb.select(selectRequest); items.addAll(result.getItems()); } } while (nextToken != null && items.size() < max); //truncate if needed while (items.size() > max) { items.removeLast(); } return items; } catch (AmazonServiceException e) { if (SimpleDBUtil.AWS_ERR_CODE_NO_SUCH_DOMAIN.equals(e.getErrorCode())) { throw new IllegalArgumentException("no such domain: " + query, e); } else if (SimpleDBUtil.AWS_ERR_CODE_SERVICE_UNAVAILABLE.equals(e.getErrorCode())) { //retry after a small pause SimpleDBUtil.sleepBeforeRetry(attempt); attempt++; return queryInternal(query, max, attempt); } else { throw e; } } }
From source file:com.multimedia.service.wallpaper.CmsWallpaperService.java
@Override public List<UploadBean> createPageFolders() { OnlyFilesFilter filenameFilter = new OnlyFilesFilter(); //getting layered pages List<Pages> pages = getCategoriesLayered(); //creating vector for results LinkedList<UploadBean> rez = new LinkedList<UploadBean>(); //creating an upload dir if it doesn't exists File upload_dir = new File(wallpaper_service.getUploadPath()); if (!upload_dir.exists()) upload_dir.mkdirs();//from ww w . j a v a2s. c o m //for saving parent catalogues Long last_layer = Long.valueOf(-1); LinkedList<File> parents = new LinkedList<File>(); parents.addLast(upload_dir); for (Pages p : pages) { while (p.getLayer() <= last_layer) { //removing last parent parents.removeLast(); last_layer--; } boolean b = false; File cur_dir = new File(parents.getLast(), String.valueOf(p.getId()) + "_" + FileUtils.toTranslit(p.getName())); if (cur_dir.exists()) { if (!cur_dir.isDirectory()) { cur_dir.delete(); b = cur_dir.mkdir(); } } else { b = cur_dir.mkdir(); } createDescriptionFile(cur_dir, p.getId(), p.getName(), false); UploadBean ub = new UploadBean(); ub.setId(p.getId()); ub.setFolder_name(cur_dir.getName()); ub.setPage_name(p.getName()); ub.setItem_count(cur_dir.listFiles(filenameFilter).length - 1); rez.addLast(ub); parents.addLast(cur_dir); last_layer = p.getLayer(); } return rez; }