List of usage examples for java.util LinkedList isEmpty
boolean isEmpty();
From source file:cnedu.ustcjd.widget.MultiSlider.java
private Thumb getMostMovable(LinkedList<Thumb> thumbs, MotionEvent event) { Thumb res = null;// w w w.ja va 2 s .c om int maxChange = 0; if (thumbs != null && !thumbs.isEmpty()) { if (thumbs.getFirst().getValue() == getValue(event, thumbs.getFirst())) return null; for (Thumb thumb : thumbs) { if (thumb.getThumb() == null || !thumb.isEnabled() || mDraggingThumbs.contains(thumb)) continue; int optValue = (getValue(event, thumbs.getFirst()) > thumb.getValue()) ? mScaleMax : mScaleMin; int currChange = Math.abs(thumb.getValue() - optThumbValue(thumb, optValue)); if (currChange > maxChange) { maxChange = currChange; res = thumb; } } } return res; }
From source file:com.jaspersoft.studio.property.section.style.inerithance.StylesListSection.java
/** * Print the attributes of all the styles of the element * /*w ww .j ava 2 s . co m*/ * @param styles List of styles * @param parent composite of the main widget */ private void printStyles(LinkedList<MStyle> styles, Composite parent) { ListIterator<MStyle> itr = styles.listIterator(); boolean hasDefaultStyleInGerarchy = false; while (itr.hasNext()) { MStyle style = itr.next(); String titleLabelText = MessageFormat.format(Messages.StylesSectionList_Inherited_From_Style, new Object[] { style.getPropertyValue(JRDesignStyle.PROPERTY_NAME) }); printStyleTitle(titleLabelText, style, parent); printStyleAttribute(parent, style, null, AttributeParent.STYLE); //$NON-NLS-1$ if (style == defaultStyle) hasDefaultStyleInGerarchy = true; } //FIXME: JR has a bug where it dosen't use the default styles if the element has at least one style //unit it will be fixed, to show the effective hierarchy, the default style is print only if there //aren't other styles on the element if (styles.isEmpty() && !hasDefaultStyleInGerarchy && defaultStyle != null && defaultStyle != getElement()) { String titleLabelText = MessageFormat.format(Messages.StylesListSection_Inherited_From_Default_Style, new Object[] { defaultStyle.getPropertyValue(JRDesignStyle.PROPERTY_NAME) }); printStyleTitle(titleLabelText, defaultStyle, parent); printStyleAttribute(parent, defaultStyle, null, AttributeParent.STYLE); //$NON-NLS-1$ } }
From source file:net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl.java
/** * this method will reclassify and reconcile a device - possibilities * are - create new device(s), remove entities from this device. If the * device entity class did not change then it returns false else true. * @param device/* w ww . j a va 2 s.com*/ */ protected boolean reclassifyDevice(Device device) { // first classify all entities of this device if (device == null) { logger.debug("In reclassify for null device"); return false; } boolean needToReclassify = false; for (Entity entity : device.getEntities()) { IEntityClass entityClass = this.entityClassifier.classifyEntity(entity); if (entityClass == null || device.getEntityClass() == null) { needToReclassify = true; break; } if (!entityClass.getName().equals(device.getEntityClass().getName())) { needToReclassify = true; break; } } if (needToReclassify == false) { return false; } LinkedList<DeviceUpdate> deviceUpdates = new LinkedList<DeviceUpdate>(); // delete this device and then re-learn all the entities this.deleteDevice(device); deviceUpdates.add(new DeviceUpdate(device, DeviceUpdate.Change.DELETE, null)); if (!deviceUpdates.isEmpty()) processUpdates(deviceUpdates); for (Entity entity : device.getEntities()) { this.learnDeviceByEntity(entity); } return true; }
From source file:org.nuxeo.elasticsearch.query.NxqlQueryConverter.java
public static QueryBuilder toESQueryBuilder(final String nxql, final CoreSession session) { final LinkedList<ExpressionBuilder> builders = new LinkedList<>(); SQLQuery nxqlQuery = getSqlQuery(nxql); if (session != null) { nxqlQuery = addSecurityPolicy(session, nxqlQuery); }/*from w ww . jav a 2s .com*/ final ExpressionBuilder ret = new ExpressionBuilder(null); builders.add(ret); final ArrayList<String> fromList = new ArrayList<>(); nxqlQuery.accept(new DefaultQueryVisitor() { private static final long serialVersionUID = 1L; @Override public void visitFromClause(FromClause node) { FromList elements = node.elements; SchemaManager schemaManager = Framework.getLocalService(SchemaManager.class); for (int i = 0; i < elements.size(); i++) { String type = elements.get(i); if (NXQLQueryMaker.TYPE_DOCUMENT.equalsIgnoreCase(type)) { // From Document means all doc types fromList.clear(); return; } Set<String> types = schemaManager.getDocumentTypeNamesExtending(type); if (types != null) { fromList.addAll(types); } } } @Override public void visitMultiExpression(MultiExpression node) { for (Iterator<Operand> it = node.values.iterator(); it.hasNext();) { it.next().accept(this); if (it.hasNext()) { node.operator.accept(this); } } } @Override public void visitSelectClause(SelectClause node) { // NOP } @Override public void visitExpression(Expression node) { Operator op = node.operator; if (op == Operator.AND || op == Operator.OR || op == Operator.NOT) { builders.add(new ExpressionBuilder(op.toString())); super.visitExpression(node); ExpressionBuilder expr = builders.removeLast(); if (!builders.isEmpty()) { builders.getLast().merge(expr); } } else { Reference ref = node.lvalue instanceof Reference ? (Reference) node.lvalue : null; String name = ref != null ? ref.name : node.lvalue.toString(); String value = null; if (node.rvalue instanceof Literal) { value = ((Literal) node.rvalue).asString(); } else if (node.rvalue != null) { value = node.rvalue.toString(); } Object[] values = null; if (node.rvalue instanceof LiteralList) { LiteralList items = (LiteralList) node.rvalue; values = new Object[items.size()]; int i = 0; for (Literal item : items) { values[i++] = item.asString(); } } // add expression to the last builder EsHint hint = (ref != null) ? ref.esHint : null; builders.getLast() .add(makeQueryFromSimpleExpression(op.toString(), name, value, values, hint, session)); } } }); QueryBuilder queryBuilder = ret.get(); if (!fromList.isEmpty()) { return QueryBuilders.boolQuery().must(queryBuilder).filter(makeQueryFromSimpleExpression("IN", NXQL.ECM_PRIMARYTYPE, null, fromList.toArray(), null, null).filter); } return queryBuilder; }
From source file:uk.gov.gchq.gaffer.gafferpop.GafferPopGraph.java
private CloseableIterator<GafferPopVertex> verticesWithSeedsAndView(final List<ElementSeed> seeds, final View view) { final boolean getAll = null == seeds || seeds.isEmpty(); final LinkedList<Vertex> idVertices = new LinkedList<>(); View entitiesView = view;//w ww.j a va2s . c om if (null == entitiesView) { entitiesView = new View.Builder().entities(graph.getSchema().getEntityGroups()).build(); } else if (entitiesView.hasEdges()) { entitiesView = new View.Builder().merge(entitiesView).edges(Collections.emptyMap()).build(); } final Output<CloseableIterable<? extends Element>> getOperation; if (getAll) { getOperation = new GetAllElements.Builder().view(entitiesView).build(); } else { getOperation = new GetElements.Builder().input(seeds).view(entitiesView).build(); if (null == entitiesView || entitiesView.getEntityGroups().contains(ID_LABEL)) { for (final ElementSeed elementSeed : seeds) { if (elementSeed instanceof EntitySeed) { idVertices.add(new GafferPopVertex(ID_LABEL, ((EntitySeed) elementSeed).getVertex(), this)); } } } } final Iterable<? extends GafferPopVertex> result = execute( new OperationChain.Builder().first(getOperation).then(new GenerateObjects.Builder<GafferPopVertex>() .generator(new GafferPopVertexGenerator(this)).build()).build()); return idVertices.isEmpty() ? new WrappedCloseableIterator(result.iterator()) : new WrappedCloseableIterable<>(new ChainedIterable<GafferPopVertex>(result, idVertices)) .iterator(); }
From source file:org.eclipse.che.vfs.impl.fs.FSMountPoint.java
ContentStream zip(VirtualFileImpl virtualFile, VirtualFileFilter filter) throws ForbiddenException, ServerException { if (!virtualFile.isFolder()) { throw new ForbiddenException( String.format("Unable export to zip. Item '%s' is not a folder. ", virtualFile.getPath())); }//from ww w. j av a 2s . co m java.io.File zipFile = null; FileOutputStream out = null; try { zipFile = java.io.File.createTempFile("export", ".zip"); out = new FileOutputStream(zipFile); final ZipOutputStream zipOut = new ZipOutputStream(out); final LinkedList<VirtualFile> q = new LinkedList<>(); q.add(virtualFile); final int zipEntryNameTrim = virtualFile.getVirtualFilePath().length(); final byte[] buff = new byte[COPY_BUFFER_SIZE]; while (!q.isEmpty()) { for (VirtualFile current : doGetChildren((VirtualFileImpl) q.pop(), SERVICE_GIT_DIR_FILTER)) { // (1) Check filter. // (2) Check permission directly for current file only. // We already know parent accessible for current user otherwise we should not be here. // Ignore item if don't have permission to read it. if (filter.accept(current) && hasPermission((VirtualFileImpl) current, BasicPermissions.READ.value(), false)) { final String zipEntryName = current.getVirtualFilePath().subPath(zipEntryNameTrim) .toString().substring(1); if (current.isFile()) { final ZipEntry zipEntry = new ZipEntry(zipEntryName); zipOut.putNextEntry(zipEntry); InputStream in = null; final PathLockFactory.PathLock lock = pathLockFactory .getLock(current.getVirtualFilePath(), false).acquire(LOCK_FILE_TIMEOUT); try { zipEntry.setTime(virtualFile.getLastModificationDate()); in = new FileInputStream(((VirtualFileImpl) current).getIoFile()); int r; while ((r = in.read(buff)) != -1) { zipOut.write(buff, 0, r); } } finally { closeQuietly(in); lock.release(); } zipOut.closeEntry(); } else if (current.isFolder()) { final ZipEntry zipEntry = new ZipEntry(zipEntryName + '/'); zipEntry.setTime(0); zipOut.putNextEntry(zipEntry); q.add(current); zipOut.closeEntry(); } } } } closeQuietly(zipOut); final String name = virtualFile.getName() + ".zip"; return new ContentStream(name, new DeleteOnCloseFileInputStream(zipFile), ExtMediaType.APPLICATION_ZIP, zipFile.length(), new Date()); } catch (IOException | RuntimeException ioe) { if (zipFile != null) { zipFile.delete(); } throw new ServerException(ioe.getMessage(), ioe); } finally { closeQuietly(out); } }
From source file:de.tudarmstadt.ukp.wikipedia.parser.mediawiki.ModularParser.java
private void getLineSpans(SpanManager sm, LinkedList<Span> lineSpans) { sm.manageList(lineSpans);//from w ww . j a v a2 s .co m int start = 0; int end; while ((end = sm.indexOf(lineSeparator, start)) != -1) { lineSpans.add(new Span(start, end).trimTrail(sm)); start = end + lineSeparator.length(); } lineSpans.add(new Span(start, sm.length()).trimTrail(sm)); while (!lineSpans.isEmpty() && lineSpans.getFirst().length() == 0) { lineSpans.removeFirst(); } while (!lineSpans.isEmpty() && lineSpans.getLast().length() == 0) { lineSpans.removeLast(); } }
From source file:de.tudarmstadt.ukp.wikipedia.parser.mediawiki.ModularParser.java
private Paragraph buildParagraph(SpanManager sm, ContentElementParsingParameters cepp, LinkedList<Span> lineSpans, lineType paragraphType) { LinkedList<Span> paragraphSpans = new LinkedList<Span>(); Paragraph result = new Paragraph(); Span s = lineSpans.removeFirst();//from w w w. j a v a 2 s. c om paragraphSpans.add(s); switch (paragraphType) { case PARAGRAPH: result.setType(Paragraph.type.NORMAL); while (!lineSpans.isEmpty()) { if (paragraphType != getLineType(sm, lineSpans.getFirst())) { break; } paragraphSpans.add(lineSpans.removeFirst()); } break; case PARAGRAPH_BOXED: result.setType(Paragraph.type.BOXED); while (!lineSpans.isEmpty()) { lineType lt = getLineType(sm, lineSpans.getFirst()); if (paragraphType != lt && lineType.EMPTYLINE != lt) { break; } paragraphSpans.add(lineSpans.removeFirst()); } break; case PARAGRAPH_INDENTED: result.setType(Paragraph.type.INDENTED); s.trim(sm.setCharAt(s.getStart(), ' ')); break; default: return null; } parseContentElement(sm, cepp, paragraphSpans, result); return result; }
From source file:com.linkedin.pinot.controller.helix.core.rebalance.ReplicaGroupRebalanceSegmentStrategy.java
/** * Uniformly distribute segments across servers in a replica group. It adopts a simple algorithm that pre-computes * the number of segments per server after rebalance and tries to assign/remove segments to/from a server until it * becomes to have the correct number of segments. * * @param serversInReplicaGroup A list of servers within the same replica group * @param serverToSegments A Mapping of servers to their segments */// w ww. ja v a 2 s. co m private void rebalanceReplicaGroup(List<String> serversInReplicaGroup, Map<String, LinkedList<String>> serverToSegments, Set<String> segmentsToCover) { // Make sure that all the segments are covered only once within a replica group. Set<String> currentCoveredSegments = new HashSet<>(); for (String server : serversInReplicaGroup) { Iterator<String> segmentIter = serverToSegments.get(server).iterator(); while (segmentIter.hasNext()) { String segment = segmentIter.next(); if (currentCoveredSegments.contains(segment)) { segmentIter.remove(); } else { currentCoveredSegments.add(segment); } } } // Compute the segments to add LinkedList<String> segmentsToAdd = new LinkedList<>(segmentsToCover); segmentsToAdd.removeAll(currentCoveredSegments); // Compute the number of segments per server after rebalance than numSegmentsPerServer int numSegmentsPerServer = segmentsToCover.size() / serversInReplicaGroup.size(); // Remove segments from servers that has more segments for (String server : serversInReplicaGroup) { LinkedList<String> segmentsInServer = serverToSegments.get(server); int segmentToMove = numSegmentsPerServer - segmentsInServer.size(); if (segmentToMove < 0) { // Server has more segments than needed, remove segments from this server for (int i = 0; i < Math.abs(segmentToMove); i++) { segmentsToAdd.add(segmentsInServer.pop()); } } } // Add segments to servers that has less segments than numSegmentsPerServer for (String server : serversInReplicaGroup) { LinkedList<String> segmentsInServer = serverToSegments.get(server); int segmentToMove = numSegmentsPerServer - segmentsInServer.size(); if (segmentToMove > 0) { // Server has less segments than needed, add segments from this server for (int i = 0; i < segmentToMove; i++) { segmentsInServer.add(segmentsToAdd.pop()); } } } // Handling the remainder of segments to add int count = 0; while (!segmentsToAdd.isEmpty()) { int serverIndex = count % serversInReplicaGroup.size(); serverToSegments.get(serversInReplicaGroup.get(serverIndex)).add(segmentsToAdd.pop()); count++; } }
From source file:org.opendatakit.aggregate.odktables.api.perf.AggregateSynchronizer.java
/** * Get all the files under the given folder, excluding those directories that * are the concatenation of folder and a member of excluding. If the member of * excluding is a directory, none of its children will be synched either. * <p>/*from w ww .ja v a 2 s. c om*/ * If the folder doesn't exist it returns an empty list. * <p> * If the file exists but is not a directory, logs an error and returns an * empty list. * * @param folder * @param excluding * can be null--nothing will be excluded. Should be relative to the * given folder. * @param relativeTo * the path to which the returned paths will be relative. A null * value makes them relative to the folder parameter. If it is non * null, folder must start with relativeTo, or else the files in * folder could not possibly be relative to relativeTo. In this case * will throw an IllegalArgumentException. * @return the relative paths of the files under the folder--i.e. the paths * after the folder parameter, not including the first separator * @throws IllegalArgumentException * if relativeTo is not a substring of folder. */ private List<String> getAllFilesUnderFolder(File baseFolder, final Set<String> excludingNamedItemsUnderFolder) { String appName = ODKFileUtils.extractAppNameFromPath(baseFolder); // Return an empty list of the folder doesn't exist or is not a directory if (!baseFolder.exists()) { return new ArrayList<String>(); } else if (!baseFolder.isDirectory()) { logger.error("[getAllFilesUnderFolder] folder is not a directory: " + baseFolder.getAbsolutePath()); return new ArrayList<String>(); } // construct the set of starting directories and files to process File[] partials = baseFolder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (excludingNamedItemsUnderFolder == null) { return true; } else { return !excludingNamedItemsUnderFolder.contains(pathname.getName()); } } }); if (partials == null) { return Collections.emptyList(); } LinkedList<File> unexploredDirs = new LinkedList<File>(); List<File> nondirFiles = new ArrayList<File>(); // copy the starting set into a queue of unexploredDirs // and a list of files to be sync'd for (int i = 0; i < partials.length; ++i) { if (partials[i].isDirectory()) { unexploredDirs.add(partials[i]); } else { nondirFiles.add(partials[i]); } } while (!unexploredDirs.isEmpty()) { File exploring = unexploredDirs.removeFirst(); File[] files = exploring.listFiles(); for (File f : files) { if (f.isDirectory()) { // we'll need to explore it unexploredDirs.add(f); } else { // we'll add it to our list of files. nondirFiles.add(f); } } } List<String> relativePaths = new ArrayList<String>(); // we want the relative path, so drop the necessary bets. for (File f : nondirFiles) { // +1 to exclude the separator. relativePaths.add(ODKFileUtils.asRelativePath(appName, f)); } return relativePaths; }