List of usage examples for java.util LinkedList addLast
public void addLast(E e)
From source file:com.commander4j.thread.InboundMessageCollectionThread.java
private LinkedList<String> getInputFilename(String inputPath) { LinkedList<String> Result = new LinkedList<String>(); File dir;/*from w ww. j av a 2 s .com*/ dir = new File(inputPath); chld = dir.listFiles((FileFilter) FileFileFilter.FILE); if (chld == null) { logger.debug("Specified directory does not exist or is not a directory. [" + inputPath + "]"); } else { Arrays.sort(chld, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); for (int i = 0; i < chld.length; i++) { fileName = chld[i].getName(); if (fileName.toLowerCase().endsWith(".xml")) { Result.addLast(fileName); } } } return Result; }
From source file:org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext.java
/** * Utility method for creating an RDD out of an in-memory matrix block. * // ww w . j a v a 2 s .com * @param sc java spark context * @param src matrix block * @param brlen block row length * @param bclen block column length * @return JavaPairRDD handle to matrix block * @throws DMLRuntimeException if DMLRuntimeException occurs */ public static JavaPairRDD<MatrixIndexes, MatrixBlock> toMatrixJavaPairRDD(JavaSparkContext sc, MatrixBlock src, int brlen, int bclen) throws DMLRuntimeException { long t0 = DMLScript.STATISTICS ? System.nanoTime() : 0; LinkedList<Tuple2<MatrixIndexes, MatrixBlock>> list = new LinkedList<Tuple2<MatrixIndexes, MatrixBlock>>(); if (src.getNumRows() <= brlen && src.getNumColumns() <= bclen) { list.addLast(new Tuple2<MatrixIndexes, MatrixBlock>(new MatrixIndexes(1, 1), src)); } else { boolean sparse = src.isInSparseFormat(); //create and write subblocks of matrix for (int blockRow = 0; blockRow < (int) Math.ceil(src.getNumRows() / (double) brlen); blockRow++) for (int blockCol = 0; blockCol < (int) Math .ceil(src.getNumColumns() / (double) bclen); blockCol++) { int maxRow = (blockRow * brlen + brlen < src.getNumRows()) ? brlen : src.getNumRows() - blockRow * brlen; int maxCol = (blockCol * bclen + bclen < src.getNumColumns()) ? bclen : src.getNumColumns() - blockCol * bclen; MatrixBlock block = new MatrixBlock(maxRow, maxCol, sparse); int row_offset = blockRow * brlen; int col_offset = blockCol * bclen; //copy submatrix to block src.sliceOperations(row_offset, row_offset + maxRow - 1, col_offset, col_offset + maxCol - 1, block); //append block to sequence file MatrixIndexes indexes = new MatrixIndexes(blockRow + 1, blockCol + 1); list.addLast(new Tuple2<MatrixIndexes, MatrixBlock>(indexes, block)); } } JavaPairRDD<MatrixIndexes, MatrixBlock> result = sc.parallelizePairs(list); if (DMLScript.STATISTICS) { Statistics.accSparkParallelizeTime(System.nanoTime() - t0); Statistics.incSparkParallelizeCount(1); } return result; }
From source file:org.openxdm.xcap.client.test.error.PreconditionFailedTest.java
@Test public void test() throws HttpException, IOException, JAXBException, InterruptedException { // exception for response codes PreconditionFailedException exception = new PreconditionFailedException(); // create content for tests String documentContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" + "<list/>" + "</resource-lists>"; String attrContent = "enemies"; String elementContent = "<list xmlns=\"urn:ietf:params:xml:ns:resource-lists\" name='friends'/>"; // 1. replace document if match // create uri UserDocumentUriKey documentKey = new UserDocumentUriKey(appUsage.getAUID(), user, documentName); // send put request and get response Response response = client.put(documentKey, appUsage.getMimetype(), documentContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be 201", response.getCode() == 201); String eTag = response.getETag(); // send put request and get response response = client.putIfMatch(documentKey, eTag + "z", appUsage.getMimetype(), documentContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 2. replace document if none match // send put request and get response response = client.putIfNoneMatch(documentKey, eTag, appUsage.getMimetype(), documentContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 3. delete document if match // send delete request and get response response = client.deleteIfMatch(documentKey, eTag + "z", null); // check delete response assertTrue("Delete response must exists", response != null); assertTrue("Delete response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 4. delete document if none match // send delete request and get response response = client.deleteIfNoneMatch(documentKey, eTag, null); // check delete response assertTrue("Delete response must exists", response != null); assertTrue("Delete response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 5. put new element if match // create uri LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>(); ElementSelectorStep step1 = new ElementSelectorStep("resource-lists"); ElementSelectorStep step2 = new ElementSelectorStepByPos("list", 2); elementSelectorSteps.add(step1);/*from w ww .ja v a 2 s . c o m*/ elementSelectorSteps.addLast(step2); ElementSelector elementSelector = new ElementSelector(elementSelectorSteps); UserElementUriKey elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, null); // send put request and get response response = client.putIfMatch(elementKey, eTag + "z", ElementResource.MIMETYPE, elementContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 6. put new element if none match // send put request and get response response = client.putIfNoneMatch(elementKey, eTag, ElementResource.MIMETYPE, elementContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 7. replace element if match // send put request and get response response = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be 201", response.getCode() == 201); eTag = response.getETag(); // send put request and get response response = client.putIfMatch(elementKey, eTag + "z", ElementResource.MIMETYPE, elementContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 8. replace element if none match // send put request and get response response = client.putIfNoneMatch(elementKey, eTag, ElementResource.MIMETYPE, elementContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 9. delete element if match // send delete request and get response response = client.deleteIfMatch(elementKey, eTag + "z", null); // check delete response assertTrue("Delete response must exists", response != null); assertTrue("Delete response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 10. delete element if none match // send delete request and get response response = client.deleteIfNoneMatch(elementKey, eTag, null); // check delete response assertTrue("Delete response must exists", response != null); assertTrue("Delete response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 11. put new attr if match UserAttributeUriKey attrKey = new UserAttributeUriKey(appUsage.getAUID(), user, documentName, new ElementSelector(elementSelectorSteps), new AttributeSelector("name"), null); // send put request and get response response = client.putIfMatch(attrKey, eTag + "z", AttributeResource.MIMETYPE, attrContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 12. put new attr if none match // send put request and get response response = client.putIfNoneMatch(attrKey, eTag, AttributeResource.MIMETYPE, attrContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 13. replace attr if match // send put request and get response response = client.put(attrKey, AttributeResource.MIMETYPE, attrContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be 200", response.getCode() == 200); eTag = response.getETag(); // send put request and get response response = client.putIfMatch(attrKey, eTag + "z", AttributeResource.MIMETYPE, attrContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 14. replace attr if none match // send put request and get response response = client.putIfNoneMatch(attrKey, eTag, AttributeResource.MIMETYPE, attrContent, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 15. delete attr if match // send delete request and get response response = client.deleteIfMatch(attrKey, eTag + "z", null); // check delete response assertTrue("Delete response must exists", response != null); assertTrue("Delete response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // 16. delete attr if none match // send delete request and get response response = client.deleteIfNoneMatch(attrKey, eTag, null); // check delete response assertTrue("Delete response must exists", response != null); assertTrue("Delete response code should be " + exception.getResponseStatus(), response.getCode() == exception.getResponseStatus()); // clean up client.delete(documentKey, null); }
From source file:bamboo.openhash.fileshare.FileShare.java
/** * Transfer wblocks from the wblocks array to the ready queue. *//* www .ja v a2s . c o m*/ public void make_parents(boolean done) { for (int l = 0; l < wblocks.size(); ++l) { logger.debug("level " + l + " of " + wblocks.size() + " size=" + wblocks.elementAt(l).size() + " done=" + done); while ((wblocks.elementAt(l).size() >= BRANCHING) || (done && (wblocks.elementAt(l).size() > 1))) { int count = min(BRANCHING, wblocks.elementAt(l).size()); logger.debug("count=" + count); for (int i = 0; i < count; ++i) { ByteBuffer bb = wblocks.elementAt(l).removeFirst(); bb.flip(); md.update(secret); md.update(bb.array(), 0, bb.limit()); byte[] dig = md.digest(); ready.addLast(new Pair<byte[], ByteBuffer>(dig, bb)); if (l + 1 >= wblocks.size()) { wblocks.setSize(max(wblocks.size(), l + 2)); wblocks.setElementAt(new LinkedList<ByteBuffer>(), l + 1); } LinkedList<ByteBuffer> next_level = wblocks.elementAt(l + 1); if (next_level.isEmpty() || (next_level.getLast().position() == 1024)) { logger.debug("adding a new block to level " + (l + 1)); next_level.addLast(ByteBuffer.wrap(new byte[1024])); next_level.getLast().putInt(l + 1); } logger.debug("adding a digest to level " + (l + 1)); next_level.getLast().put(dig); } if (done) break; } } logger.debug("make_parents done"); }
From source file:org.vast.stt.renderer.opengl.TextureManager.java
/** * Creates a new texture by transfering data from styler to GL memory * @param styler//from w w w.ja va 2 s . co m * @param tex * @param texInfo */ protected void createTexture(TextureStyler styler, RasterTileGraphic tex, GLTexture texInfo) { // fetch texture data from styler fillTexData(styler, tex, texInfo); Symbolizer sym = styler.getSymbolizer(); // if texture was successfully constructed, bind it with GL if (tex.hasRasterData) { // size of texture pool int texPoolSize = styler.getSymbolizer().getTexPoolSize(); // create new texture name and bind it int[] id = new int[1]; boolean lastNewTexture = false; // ACCORDING TO WHETHER THE TEXTURE POOL SIZE HAS BEEN REACHED // A NEW TEXTURE IS GENERATED OR THE FIRST OF THE STACK IS REUSED // FOR THE MOST RECENT RASTER DATA if ((symTexturePoolSizeReachedTable == null) || !symTexturePoolSizeReachedTable.containsKey(sym)) { // create new texture name gl.glGenTextures(1, id, 0); if (texPoolSize > 0) { if (id[0] < (texPoolSize + 1)) { if (!symTextureStackTable.containsKey(sym)) { LinkedList<Integer> TexIdStack = new LinkedList<Integer>(); TexIdStack.addLast(id[0]); symTextureStackTable.put(sym, TexIdStack); } else { LinkedList<Integer> stack = symTextureStackTable.get(sym); stack.addLast(id[0]); symTextureStackTable.put(sym, stack); if (id[0] == texPoolSize) { symTexturePoolSizeReachedTable.put(sym, true); lastNewTexture = true; } } } } } else if ((symTexturePoolSizeReachedTable != null) || symTexturePoolSizeReachedTable.containsKey(sym)) { LinkedList<Integer> stack = symTextureStackTable.get(sym); id[0] = stack.poll(); stack.addLast(id[0]); } // Bind the texture to the texture Id gl.glBindTexture(OpenGLCaps.TEXTURE_2D_TARGET, id[0]); // set texture parameters // TODO: Allow user to select between Linear (smoothed) and nearest-neighbor interp // gl.glTexParameteri(OpenGLCaps.TEXTURE_2D_TARGET, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); // gl.glTexParameteri(OpenGLCaps.TEXTURE_2D_TARGET, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); gl.glTexParameteri(OpenGLCaps.TEXTURE_2D_TARGET, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexParameteri(OpenGLCaps.TEXTURE_2D_TARGET, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(OpenGLCaps.TEXTURE_2D_TARGET, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(OpenGLCaps.TEXTURE_2D_TARGET, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); //gl.glTexParameteri(OpenGLCaps.TEXTURE_2D_TARGET, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_BORDER); //gl.glTexParameteri(OpenGLCaps.TEXTURE_2D_TARGET, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_BORDER); //gl.glTexParameterfv(OpenGLCaps.TEXTURE_2D_TARGET, GL.GL_TEXTURE_BORDER_COLOR, new float[] {0.0f,0.0f,0.0f,0.0f}, 0); // figure out image format int format = 0; switch (tex.bands) { case 1: format = GL.GL_LUMINANCE; break; case 2: format = GL.GL_LUMINANCE_ALPHA; break; case 3: format = GL.GL_RGB; break; case 4: format = GL.GL_RGBA; break; } gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); // create texture in GL memory if (!symTexturePoolSizeReachedTable.containsKey(sym) || lastNewTexture) { gl.glTexImage2D(OpenGLCaps.TEXTURE_2D_TARGET, 0, tex.bands, tex.width + texInfo.widthPadding, tex.height + texInfo.heightPadding, 0, format, GL.GL_UNSIGNED_BYTE, tex.rasterData); } else { gl.glTexImage2D(OpenGLCaps.TEXTURE_2D_TARGET, 0, tex.bands, tex.width + texInfo.widthPadding, tex.height + texInfo.heightPadding, 0, format, GL.GL_UNSIGNED_BYTE, tex.rasterData); // gl.glTexSubImage2D(OpenGLCaps.TEXTURE_2D_TARGET, 0, 0, 0, // tex.width + texInfo.widthPadding, tex.height + texInfo.heightPadding, // format, GL.GL_UNSIGNED_BYTE, tex.rasterData); } // erase temp buffer tex.rasterData = null; // set new id and reset needsUpdate flag int oldID = texInfo.id; texInfo.id = id[0]; // delete previous texture if needed if (oldID > 0) { gl.glDeleteTextures(1, new int[] { oldID }, 0); if (log.isDebugEnabled()) log.debug("Tex #" + oldID + " deleted and replaced by " + texInfo.id); } } }
From source file:org.guzz.GuzzContextImpl.java
protected void initUnOrderedService(Map services, LinkedList queuedServices, ServiceInfo serviceInfo) { if (serviceInfo.hasDependedServices()) { queuedServices.addLast(serviceInfo); String[] dependsOn = serviceInfo.getDependedServices(); for (int k = 0; k < dependsOn.length; k++) { for (int i = 0; i < queuedServices.size(); i++) { String queueServiceName = ((ServiceInfo) queuedServices.get(i)).getServiceName(); if (queueServiceName.equals(dependsOn[k])) { throw new InvalidConfigurationException("cycle dependencies found in guzz services. From [" + queueServiceName + "] to [" + dependsOn[k] + "]."); }//from ww w. jav a2 s. com } //add depended-services from un-inited-services to the queuedServices ServiceInfo si = (ServiceInfo) services.remove(dependsOn[k]); if (si != null) { //process the depended service first. initUnOrderedService(services, queuedServices, si); } else { //the service may have already been registered to the ServiceManager } } //Depended services have been inited. Start the current one. Service s = ServiceManagerImpl.createNewService(this, configServer, serviceInfo); serviceManager.registerService(s); queuedServices.remove(serviceInfo); } else { Service s = ServiceManagerImpl.createNewService(this, configServer, serviceInfo); serviceManager.registerService(s); } }
From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java
/** * Returns the result of applying a filter using breadth-first traversal. * * @param context The parent context./*from www.j ava 2s. c om*/ * @param node The root node to traverse from. * @param filter The filter to satisfy. * @return The first node reached via BFS traversal that satisfies the * filter. */ public static AccessibilityNodeInfoCompat searchFromBfs(Context context, AccessibilityNodeInfoCompat node, NodeFilter filter) { if (node == null) { return null; } final LinkedList<AccessibilityNodeInfoCompat> queue = new LinkedList<AccessibilityNodeInfoCompat>(); queue.add(AccessibilityNodeInfoCompat.obtain(node)); while (!queue.isEmpty()) { final AccessibilityNodeInfoCompat item = queue.removeFirst(); if (filter.accept(context, item)) { return AccessibilityNodeInfoCompat.obtain(item); } final int childCount = item.getChildCount(); for (int i = 0; i < childCount; i++) { final AccessibilityNodeInfoCompat child = item.getChild(i); if (child != null) { queue.addLast(child); } } } return null; }
From source file:org.openxdm.xcap.client.test.error.CannotInsertTest.java
@Test public void test() throws HttpException, IOException, JAXBException, InterruptedException { // create uri UserDocumentUriKey key = new UserDocumentUriKey(appUsage.getAUID(), user, documentName); String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<resource-lists xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" + "<list name=\"friends\" />" + "</resource-lists>"; // send put request and get response Response response = client.put(key, appUsage.getMimetype(), content, null); // check put response assertTrue("Put response must exists", response != null); assertTrue("Put response code should be 201", response.getCode() == 201); // create element selector LinkedList<ElementSelectorStep> elementSelectorSteps = new LinkedList<ElementSelectorStep>(); ElementSelectorStep step1 = new ElementSelectorStep("resource-lists"); ElementSelectorStep step2 = new ElementSelectorStepByAttr("list", "name", "friends"); elementSelectorSteps.add(step1);//w ww. j av a 2 s . c o m elementSelectorSteps.addLast(step2); ElementSelector elementSelector = new ElementSelector(elementSelectorSteps); // create exception for return codes CannotInsertConflictException exception = new CannotInsertConflictException(); // 1st test is for attr replace // create attr uri AttributeSelector attributeSelector = new AttributeSelector("name"); UserAttributeUriKey attrKey = new UserAttributeUriKey(appUsage.getAUID(), user, documentName, elementSelector, attributeSelector, null); // send put and get response Response putResponse = client.put(attrKey, AttributeResource.MIMETYPE, "enemies", null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // 2nd is for elem replace // create elem uri UserElementUriKey elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, null); // element content to put String elementContent = "<list name=\"enemies\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // element content to put elementContent = "<cannot-insert name=\"friends\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // 3rd is for new elem put by pos and attr // create elem uri elementSelectorSteps.removeLast(); step2 = new ElementSelectorStepByPosAttr("list", 1, "name", "3n3m13s"); elementSelectorSteps.addLast(step2); elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, null); // element content to put elementContent = "<list name=\"enemies\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // element content to put elementContent = "<cannot-insert name=\"3n3m13s\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // create elem uri elementSelectorSteps.removeLast(); step2 = new ElementSelectorStepByPosAttr("list", 3, "name", "3n3m13s"); elementSelectorSteps.addLast(step2); elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, null); // element content to put elementContent = "<list name=\"3n3m13s\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // 4th is for new elem put by pos // create elem uri elementSelectorSteps.removeLast(); step2 = new ElementSelectorStepByPos("list", 2); elementSelectorSteps.addLast(step2); elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, null); // element content to put elementContent = "<cannot-insert name=\"3n3m13s\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // create elem uri elementSelectorSteps.removeLast(); step2 = new ElementSelectorStepByPos("list", 3); elementSelectorSteps.addLast(step2); elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, null); // element content to put elementContent = "<list name=\"3n3m13s\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // 5th is for new elem put by attr // create elem uri elementSelectorSteps.removeLast(); step2 = new ElementSelectorStepByAttr("list", "name", "3n3m13s"); elementSelectorSteps.addLast(step2); elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, null); // element content to put elementContent = "<list name=\"enemies\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // element content to put elementContent = "<cannot-insert name=\"3n3m13s\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // 6th is for new elem put by name only // create elem uri elementSelectorSteps.removeLast(); step2 = new ElementSelectorStep("list"); elementSelectorSteps.addLast(step2); ElementSelectorStep step3 = new ElementSelectorStep("list"); elementSelectorSteps.addLast(step3); elementKey = new UserElementUriKey(appUsage.getAUID(), user, documentName, elementSelector, null); // element content to put elementContent = "<cannot-insert name=\"3n3m13s\" />"; // send put request and get response putResponse = client.put(elementKey, ElementResource.MIMETYPE, elementContent, null); assertTrue("Put response must exists", putResponse != null); assertTrue( "Put response content must be the expected and the response code should be " + exception.getResponseStatus(), putResponse.getCode() == exception.getResponseStatus() && putResponse.getContent().equals(exception.getResponseContent())); // clean up client.delete(key, null); }
From source file:com.mirth.connect.plugins.dashboardstatus.DashboardConnectorEventListener.java
public synchronized LinkedList<String[]> getChannelLog(Object object, String sessionId) { String channelName;/* w ww . j a v a 2s . com*/ LinkedList<String[]> channelLog; if (object == null) { /* * object is null - no channel is selected. return the latest entire log entries of all * channels combined. ONLY new entries. */ channelName = "No Channel Selected"; channelLog = entireConnectorInfoLogs; } else { // object is not null - a channel is selected. return the latest // (LOG_SIZE) of that particular channel. channelName = object.toString(); // return only the newly added log entries for the client with // matching sessionId. channelLog = connectorInfoLogs.get(channelName); if (channelLog == null) { channelLog = new LinkedList<String[]>(); connectorInfoLogs.put(channelName, channelLog); } } Map<String, Long> lastDisplayedLogIdByChannel; if (lastDisplayedLogIndexBySessionId.containsKey(sessionId)) { // client exist with the sessionId. lastDisplayedLogIdByChannel = lastDisplayedLogIndexBySessionId.get(sessionId); if (lastDisplayedLogIdByChannel.containsKey(channelName)) { // existing channel on an already open client. // -> only display new log entries. long lastDisplayedLogId = lastDisplayedLogIdByChannel.get(channelName); LinkedList<String[]> newChannelLogEntries = new LinkedList<String[]>(); // FYI, channelLog.size() will never be larger than LOG_SIZE // = 1000. for (String[] aChannelLog : channelLog) { if (lastDisplayedLogId < Long.parseLong(aChannelLog[0])) { newChannelLogEntries.addLast(aChannelLog); } } if (newChannelLogEntries.size() > 0) { /* * put the lastDisplayedLogId into the HashMap. index 0 is the most recent * entry, and index0 of that entry contains the logId. */ lastDisplayedLogIdByChannel.put(channelName, Long.parseLong(newChannelLogEntries.get(0)[0])); lastDisplayedLogIndexBySessionId.put(sessionId, lastDisplayedLogIdByChannel); } try { return SerializationUtils.clone(newChannelLogEntries); } catch (SerializationException e) { logger.error(e); } } else { /* * new channel viewing on an already open client. -> all log entries are new. * display them all. put the lastDisplayedLogId into the HashMap. index0 is the most * recent entry, and index0 of that entry object contains the logId. */ if (channelLog.size() > 0) { lastDisplayedLogIdByChannel.put(channelName, Long.parseLong(channelLog.get(0)[0])); lastDisplayedLogIndexBySessionId.put(sessionId, lastDisplayedLogIdByChannel); } try { return SerializationUtils.clone(channelLog); } catch (SerializationException e) { logger.error(e); } } } else { // brand new client. // thus also new channel viewing. // -> all log entries are new. display them all. lastDisplayedLogIdByChannel = new HashMap<String, Long>(); if (channelLog.size() > 0) { lastDisplayedLogIdByChannel.put(channelName, Long.parseLong(channelLog.get(0)[0])); } else { // no log exist at all. put the currentLogId-1, which is the // very latest logId. lastDisplayedLogIdByChannel.put(channelName, logId - 1); } lastDisplayedLogIndexBySessionId.put(sessionId, lastDisplayedLogIdByChannel); try { return SerializationUtils.clone(channelLog); } catch (SerializationException e) { logger.error(e); } } return null; }
From source file:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java
/** * Returns the result of applying a filter using breadth-first traversal. * * @param context The parent context./*from ww w. ja v a 2 s.c o m*/ * @param node The root node to traverse from. * @param filter The filter to satisfy. * @param maxResults The number of results to stop searching after * @return The first n nodes reached via BFS traversal that satisfies the * filter. */ public static List<AccessibilityNodeInfoCompat> searchAllFromBfs(Context context, AccessibilityNodeInfoCompat node, NodeFilter filter, int maxResults) { if (node == null) { return null; } final List<AccessibilityNodeInfoCompat> toReturn = new ArrayList<AccessibilityNodeInfoCompat>(); final LinkedList<AccessibilityNodeInfoCompat> queue = new LinkedList<AccessibilityNodeInfoCompat>(); queue.add(AccessibilityNodeInfoCompat.obtain(node)); while (!queue.isEmpty() && toReturn.size() < maxResults) { final AccessibilityNodeInfoCompat item = queue.removeFirst(); if (filter.accept(context, item)) { toReturn.add(AccessibilityNodeInfoCompat.obtain(item)); } final int childCount = item.getChildCount(); for (int i = 0; i < childCount; i++) { final AccessibilityNodeInfoCompat child = item.getChild(i); if (child != null) { queue.addLast(child); } } } return toReturn; }