public static <T> List<T> toList(Enumeration<? extends T> things) { AbstractList<T> list = new ArrayList<T>(); while (things.hasMoreElements()) { list.add(things.nextElement()); } return list; }
/** * Compile this mosaic into an optimal arrangement. * * @return true if this mosaic is used for images, false if it's empty */ public boolean compile(Component progressComponent) { this.progressComponent = progressComponent; parts = partsList.toArray(new MosaicPart[partsList.size()]); Arrangement arrangement = new Arrangement(maxHeight, parts); int lastWidth = -1; double widthFactor = Math.log(((double) maxWidth) / minWidth); for (int i = 0; i < numWidths; i++) { int width; if (numWidths > 1) { // Increase width geometrically from minWidth to maxWidth double f = widthFactor * ((double) i) / (numWidths - 1); f = Math.exp(f) * minWidth; width = (int) (f + 0.5); } else { width = maxWidth; } if (width == lastWidth) { continue; // Don't try same width twice } lastWidth = width; arrangement.arrangeWithin(width); int pixels = arrangement.getPixelsUsed(); if (pixels < currPixels) { setBestArrangement(arrangement); } } return currPixels > 0; }
public static void main(String[] args) throws IOException { String s = args[0]; char[] alphabet = new char[26]; AbstractList<Integer> characters = new ArrayList<>(); int count = 0; for (int i = 0; i < alphabet.length; i++) { alphabet[i] = (char) ('a' + i); } FileInputStream fileInputStream = new FileInputStream(s); while (fileInputStream.available() > 0) { characters.add(fileInputStream.read()); } fileInputStream.close(); for (int a : characters) { for (int i = 0; i < alphabet.length; i++) { if (a == alphabet[i]) { count++; } } } System.out.println(count); }
@Override public void onEvent(ConsoleState state, Event.Key kev) { // System.out.println("WindowChildren OnEvent.Key " + kev.key); super.onEvent(state, kev); if (active_ != null) active_.onEvent(state, kev); if (kev.state == Event.State.RELEASED) { switch (kev.key) { case TAB: if (children_.isEmpty()) { setActive(state, null); } else { Window current = active_; boolean found = false; int i = active_ != null ? children_.indexOf(active_) + 1 : 0; while (!found) { if (i >= children_.size()) { if (current == null) break; else i = 0; } Window active = children_.get(i); found = setActive(state, active); if (active == current) break; ++i; } } break; } } }
@Override public void handleMessage(Message msg) { @SuppressWarnings("unchecked") AbstractList<String> requestedUploads = (AbstractList<String>) msg.obj; if (msg.obj != null) { Iterator<String> it = requestedUploads.iterator(); while (it.hasNext()) { mService.uploadFile(it.next()); } } mService.stopSelf(msg.arg1); }
private long testingAbstractListRoleList() { AbstractList<Object> array = new RoleList(); long start = System.currentTimeMillis(); for (int i = 0; i < getMax(); i++) { array.add(i); } long end = System.currentTimeMillis(); long time = (end - start); refreshTotalTime(time); return time; }
private void renderFullBoardRecursive( Graphics g, AbstractList<Space> finished, Space origin, int x, int y, Board b) { renderSpace(g, origin, x, y); Board.Coordinates coord = b.new Coordinates(x, y); Developer dev = b.getDeveloper(coord); if (dev != null) { renderDeveloper(dev, x, y); } if (origin.getTop() != null && !finished.contains(origin.getTop())) { finished.add(origin.getTop()); renderFullBoardRecursive(g, finished, origin.getTop(), x, y - 1, b); } if (origin.getLeft() != null && !finished.contains(origin.getLeft())) { finished.add(origin.getLeft()); renderFullBoardRecursive(g, finished, origin.getLeft(), x - 1, y, b); } if (origin.getRight() != null && !finished.contains(origin.getRight())) { finished.add(origin.getRight()); renderFullBoardRecursive(g, finished, origin.getRight(), x + 1, y, b); } if (origin.getBottom() != null && !finished.contains(origin.getBottom())) { finished.add(origin.getBottom()); renderFullBoardRecursive(g, finished, origin.getBottom(), x, y + 1, b); } int givenHeight = origin.getHeight(); if (origin.getHeight() > 0 && origin.getTile().getType() == TileType.PALACE) { givenHeight = ((PalaceTile) origin.getTile()).getLevel(); } spaceHeights[x][y] = givenHeight; renderText( g, "" + givenHeight, (x + 1) * TILE_WIDTH, (y + 1) * TILE_HEIGHT + g.getFont().getSize()); }
public Iterator<Host> iterator() { AbstractList<Host> ab = new AbstractList<Host>() { public int size() { return getLength(); } public Host get(int index) { return (Host) item(index); } }; return ab.iterator(); }
public Iterator<VirtualMachine> iterator() { AbstractList<VirtualMachine> ab = new AbstractList<VirtualMachine>() { public int size() { return getLength(); } public VirtualMachine get(int index) { return (VirtualMachine) item(index); } }; return ab.iterator(); }
public Iterator<Image> iterator() { AbstractList<Image> ab = new AbstractList<Image>() { public int size() { return getLength(); } public Image get(int index) { return (Image) item(index); } }; return ab.iterator(); }
protected void removeRange(int fromIndex, int toIndex) { checkForComodification(); l.removeRange(fromIndex + offset, toIndex + offset); expectedModCount = l.modCount; size -= (toIndex - fromIndex); modCount++; }
public void add(int index, E element) { if (index < 0 || index > size) throw new IndexOutOfBoundsException(); checkForComodification(); l.add(index + offset, element); expectedModCount = l.modCount; size++; modCount++; }
public E remove(int index) { rangeCheck(index); checkForComodification(); E result = l.remove(index + offset); expectedModCount = l.modCount; size--; modCount++; return result; }
@Override public void onEvent(ConsoleState state, Event.MouseButton mbev) { super.onEvent(state, mbev); // System.err.println("WindowChildren::OnEvent " + mbev); // TODO only send if in box, unless captured if (capture_ != null) capture_.onEvent(state, mbev); else { // for (Window d : children_) // Should be in reverse order java.util.ListIterator<Window> itr = children_.listIterator(children_.size()); while (itr.hasPrevious()) { Window d = itr.previous(); if (d.inside(mbev.mx, mbev.my)) { d.onEvent(state, mbev); break; } } } }
SubList(AbstractList<E> list, int fromIndex, int toIndex) { if (fromIndex < 0) throw new IndexOutOfBoundsException("fromIndex = " + fromIndex); if (toIndex > list.size()) throw new IndexOutOfBoundsException("toIndex = " + toIndex); if (fromIndex > toIndex) throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); l = list; offset = fromIndex; size = toIndex - fromIndex; expectedModCount = l.modCount; }
/** * Helper method that prints out a list. * * @param list the list to print. * @param depth the depth of the object within other objects, used for indenting. */ @SuppressWarnings("unchecked") public static void printList(AbstractList list, int depth) { final Iterator i = list.iterator(); Object o = null; for (int k = 0; k < depth; k++) System.out.print(" "); System.out.println("List: "); while (i.hasNext() && (o = i.next()) != null) { for (int k = 0; k < depth; k++) System.out.print(" "); System.out.print(" +"); print(o, depth); } }
public boolean addAll(int index, Collection<? extends E> c) { if (index < 0 || index > size) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); int cSize = c.size(); if (cSize == 0) return false; checkForComodification(); l.addAll(offset + index, c); expectedModCount = l.modCount; size += cSize; modCount++; return true; }
public static <VertexType extends BaseVertex, EdgeType extends BaseEdge<VertexType>> BaseGraph<VertexType, EdgeType> getVertexInducedSubgraph( BaseGraph<VertexType, EdgeType> graph, AbstractList<VertexType> inducedVertices) { BaseGraph<VertexType, EdgeType> newGraph = graph.createEmptyGraph(); newGraph.registerSubgraph(graph); newGraph.setSubGraphIndex(graph.getNewSubgraphIndex()); for (VertexType v : inducedVertices) { graph.checkVertex(v); newGraph.insertVertex(v); } for (int i = 0; i < inducedVertices.size(); ++i) { for (int j = i + 1; j < inducedVertices.size(); ++j) { AbstractList<EdgeType> edges = graph.getEdges(inducedVertices.get(i), inducedVertices.get(j)); for (EdgeType edge : edges) newGraph.insertEdge(edge); } } return newGraph; }
@Override protected void finalize() { // System.out.println("finalize TempMultiFileStringList: " + this.hashCode()); for (String name : list) { File f = new File(dir, name); if (f.exists() && f.delete() == false) { System.err.println("cannot delete a temp File:" + f.getAbsolutePath()); } } try { super.finalize(); } catch (Throwable e) { e.printStackTrace(); } }
/** * a slow function in java, but the only other way is for the users of this list to do it, and * since its used as a normal java.util.List, they probably wont know to do that. */ protected void finalize() throws Throwable { acyc.oneLessRefFromOutside(pointer); super.finalize(); }
/** Removes sufficiently replicated blocks from the block list of a datanode. */ private void pruneSufficientlyReplicated( final DatanodeDescriptor datanode, AbstractList<BlockInfo> blocks) { processBlocksForDecomInternal(datanode, blocks.iterator(), null, true); }
private void check() { final Iterator<Map.Entry<DatanodeDescriptor, AbstractList<BlockInfo>>> it = new CyclicIteration<>(decomNodeBlocks, iterkey).iterator(); final LinkedList<DatanodeDescriptor> toRemove = new LinkedList<>(); while (it.hasNext() && !exceededNumBlocksPerCheck() && !exceededNumNodesPerCheck()) { numNodesChecked++; final Map.Entry<DatanodeDescriptor, AbstractList<BlockInfo>> entry = it.next(); final DatanodeDescriptor dn = entry.getKey(); AbstractList<BlockInfo> blocks = entry.getValue(); boolean fullScan = false; if (blocks == null) { // This is a newly added datanode, run through its list to schedule // under-replicated blocks for replication and collect the blocks // that are insufficiently replicated for further tracking LOG.debug( "Newly-added node {}, doing full scan to find " + "insufficiently-replicated blocks.", dn); blocks = handleInsufficientlyReplicated(dn); decomNodeBlocks.put(dn, blocks); fullScan = true; } else { // This is a known datanode, check if its # of insufficiently // replicated blocks has dropped to zero and if it can be decommed LOG.debug("Processing decommission-in-progress node {}", dn); pruneSufficientlyReplicated(dn, blocks); } if (blocks.size() == 0) { if (!fullScan) { // If we didn't just do a full scan, need to re-check with the // full block map. // // We've replicated all the known insufficiently replicated // blocks. Re-check with the full block map before finally // marking the datanode as decommissioned LOG.debug( "Node {} has finished replicating current set of " + "blocks, checking with the full block map.", dn); blocks = handleInsufficientlyReplicated(dn); decomNodeBlocks.put(dn, blocks); } // If the full scan is clean AND the node liveness is okay, // we can finally mark as decommissioned. final boolean isHealthy = blockManager.isNodeHealthyForDecommission(dn); if (blocks.size() == 0 && isHealthy) { setDecommissioned(dn); toRemove.add(dn); LOG.debug( "Node {} is sufficiently replicated and healthy, " + "marked as decommissioned.", dn); } else { if (LOG.isDebugEnabled()) { StringBuilder b = new StringBuilder("Node {} "); if (isHealthy) { b.append("is "); } else { b.append("isn't "); } b.append( "healthy and still needs to replicate {} more blocks," + " decommissioning is still in progress."); LOG.debug(b.toString(), dn, blocks.size()); } } } else { LOG.debug( "Node {} still has {} blocks to replicate " + "before it is a candidate to finish decommissioning.", dn, blocks.size()); } iterkey = dn; } // Remove the datanodes that are decommissioned for (DatanodeDescriptor dn : toRemove) { Preconditions.checkState( dn.isDecommissioned(), "Removing a node that is not yet decommissioned!"); decomNodeBlocks.remove(dn); } }
public T remove(int index) { return adapter.remove(index); }
public static GraphModel createIPGraph(Vector<Triplet> tow) { // create the DAG dag = new GraphModel(true); HashMap<Object, VertexModel> V = new HashMap<Object, VertexModel>(); for (Triplet t : tow) { VertexModel ik = getVertex(t.i, t.k, dag, V); VertexModel jk = getVertex(t.j, t.k, dag, V); VertexModel ij = getVertex(t.i, t.j, dag, V); EdgeModel e = new EdgeModel(ij, ik); e.getProp().obj = t; dag.insertEdge(e); e = new EdgeModel(ij, jk); e.getProp().obj = t; dag.insertEdge(e); } // convert it to a dag (from each cycle remove an edge) // convertToDag(dag); boolean first = true; while ((cycle = DAG.findACycle(dag)) != null) { if (first) { TripNet.println("Warning 0: Input triplets are inconsistent!"); first = false; } ArrayList<Triplet> cycleTriplets = TripNet.getCycleTriplets(cycle); Triplet minT = cycleTriplets.get(0); for (Triplet t : cycleTriplets) { if (t.w < minT.w) minT = t; } TripNet.println( "removing: " + minT + " with weight: " + minT.w + " ::: Resolving the cycle: " + cycleTriplets); if (TripNet.REAMOVE_CYCLIC_TRIPLETS) { TripNet.println("removing Triplet of tow: " + cycleTriplets); tow.remove(minT); } VertexModel ik = getVertex(minT.i, minT.k, dag, V); VertexModel jk = getVertex(minT.j, minT.k, dag, V); VertexModel ij = getVertex(minT.i, minT.j, dag, V); dag.removeEdge(dag.getEdge(ij, jk)); dag.removeEdge(dag.getEdge(ij, ik)); } // topological sort AbstractList<VertexModel> topsort = DAG.doSort(dag); if (topsort == null) { // the inputs are inconsistent, they are not a dag // GraphData gd = new GraphData(Application.blackboard); // gd.core.showGraph(dag); cycle = DAG.findACycle(dag); VertexModel p = cycle.get(0); VertexModel c = cycle.get(1); EdgeModel e = dag.getEdge(p, c); dag.removeEdge(e); TripNet.println("Err 0: please contact us for this error! :("); return null; } // set Xij // find the length of the longest chain int max = -1; for (Pair<VertexModel, Integer> p : DAG.findLongestPath(dag)) { max = Math.max(max, p.second); } // set the Xij as large as u can for (int i = topsort.size() - 1; i >= 0; i--) { VertexModel v = topsort.get(i); int min = max + 1; for (VertexModel trg : dag.getNeighbors(v)) { min = Math.min(min, trg.getColor()); } v.setColor(min - 1); // the color will be related edge's weight (or // formally Xij) } // create the network graph HashMap<Object, VertexModel> VR = new HashMap<Object, VertexModel>(); GraphModel ret = new GraphModel(false); if (TripNet.verbose) TripNet.println("Integer Programming Results:"); TripNet.ths.maxW = max; for (VertexModel v : topsort) { Pair<Integer, Integer> edge = (Pair<Integer, Integer>) getVId(v); VertexModel i = getVertex(edge.first, ret, VR); VertexModel j = getVertex(edge.second, ret, VR); EdgeModel e = new EdgeModel(i, j); int w = v.getColor(); e.setWeight(w); ret.insertEdge(e); if (TripNet.verbose) System.out.println(edge.first + "," + edge.second + ": " + w); TripNet.ths.F0.put(edge.first + "," + edge.second, w); TripNet.ths.weights.put(new Pair<Integer, Integer>(edge.first, edge.second), w); } // check consistency of results for (Triplet t : tow) { if ((TripNet.getW(t.i, t.j).intValue() <= TripNet.getW(t.i, t.k).intValue()) && (TripNet.getW(t.i, t.j).intValue() <= TripNet.getW(t.j, t.k).intValue())) continue; System.err.println("inconsistant weight"); } return ret; }
public <U> U[] toArray(U[] a) { return adapter.toArray(a); }
public Object[] toArray() { return adapter.toArray(); }
public int size() { return adapter.size(); }
public boolean remove(Object o) { return adapter.remove(o); }
public boolean retainAll(Collection<?> c) { return adapter.retainAll(c); }
public T set(int index, T element) { return adapter.set(index, element); }