下面列出了java.util.LinkedList#pop ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/*******************
* Handle a string element.
*
* @param obj The RMIObject to populate with class names.
******************/
private void handleStringElement(LinkedList<Byte> dataStack) throws BaRMIeInvalidReplyDataPacketException {
//Handle a string based on the type
switch(dataStack.pop()) {
//Standard string
case ObjectStreamConstants.TC_STRING:
this.extractUtf8(dataStack);
break;
//Long string
case ObjectStreamConstants.TC_LONGSTRING:
this.extractLongUtf8(dataStack);
break;
//References
case ObjectStreamConstants.TC_REFERENCE:
this.extractInt(dataStack);
break;
//Invalid string type
default:
throw new BaRMIeInvalidReplyDataPacketException("Invalid string element type.");
}
}
@Override
public MemoryBlock allocate(long size) throws OutOfMemoryError {
if (shouldPool(size)) {
synchronized (this) {
final LinkedList<WeakReference<MemoryBlock>> pool = bufferPoolsBySize.get(size);
if (pool != null) {
while (!pool.isEmpty()) {
final WeakReference<MemoryBlock> blockReference = pool.pop();
final MemoryBlock memory = blockReference.get();
if (memory != null) {
assert (memory.size() == size);
return memory;
}
}
bufferPoolsBySize.remove(size);
}
}
}
long[] array = new long[(int) ((size + 7) / 8)];
return new MemoryBlock(array, Platform.LONG_ARRAY_OFFSET, size);
}
@Override
public Object visit(FuncDef df){
currentFD.push(df);
toCheckOnExit.put(df, new LinkedList<FuncDef>());
Object ret = super.visit(df);
LinkedList<FuncDef> toCheckOnExitx = toCheckOnExit.get(df);
if(null != toCheckOnExitx && !toCheckOnExitx.isEmpty()){
//LinkedList<FuncDef> proce = toCheckOnExitx;
while(!toCheckOnExitx.isEmpty()){
super.visit(toCheckOnExitx.pop());
/*if(!toCheckOnExitx.isEmpty()){
proce.push(toCheckOnExitx.pop());
}*/
}
}
//toCheckOnExit.remove(df);//comment out side something is causing early exit... maybe a copy?
currentFD.pop();
return ret;
}
protected <S> void findCycles(Nfa<S> nfa, S node, IAcceptor<List<S>> cycleAcceptor, Map<S, Integer> dfsMark,
LinkedList<S> dfsStack) {
dfsStack.push(node);
dfsMark.put(node, DFS_ON_STACK);
for (S follower : nfa.getFollowers(node)) {
Integer followerMark = dfsMark.get(follower);
if (followerMark == null) {
// The follower is not visited yet, so go deeper.
findCycles(nfa, follower, cycleAcceptor, dfsMark, dfsStack);
} else if (followerMark == DFS_ON_STACK) {
// If the follower is on the stack that means we have a cycle
// that includes all nodes between
// the follower node and the current node.
LinkedList<S> cycle = Lists.newLinkedList();
Iterator<S> stackIter = dfsStack.iterator();
S cycleNode;
do {
cycleNode = stackIter.next();
cycle.addFirst(cycleNode);
} while (cycleNode != follower && stackIter.hasNext());
cycleAcceptor.accept(cycle);
}
}
dfsStack.pop();
dfsMark.put(node, DFS_VISITED);
}
private static List<String> stubsToList(String[] stubIdsToPortMapping) {
List<String> list = new ArrayList<>();
if (stubIdsToPortMapping.length == 1 && !containsRange(stubIdsToPortMapping[0])) {
list.addAll(StringUtils.commaDelimitedListToSet(stubIdsToPortMapping[0]));
return list;
}
else if (stubIdsToPortMapping.length == 1
&& containsRange(stubIdsToPortMapping[0])) {
LinkedList<String> linkedList = new LinkedList<>();
String[] split = stubIdsToPortMapping[0].split(",");
for (String string : split) {
if (containsClosingRange(string)) {
String last = linkedList.pop();
linkedList.push(last + "," + string);
}
else {
linkedList.push(string);
}
}
list.addAll(linkedList);
return list;
}
Collections.addAll(list, stubIdsToPortMapping);
return list;
}
public BreadthFirstSorterImpl(FastDirectedGraph<N, FastGraphEdge<N>> graph, N entry) {
LinkedList<N> queue = new LinkedList<>();
queue.add(entry);
Set<N> visited = new HashSet<>(graph.size());
bfs = new ArrayList<>();
while(!queue.isEmpty()) {
entry = queue.pop();
if(visited.contains(entry)) {
continue;
}
visited.add(entry);
bfs.add(entry);
for(FastGraphEdge<N> e : graph.getEdges(entry)) {
N s = e.dst();
queue.addLast(s);
}
}
}
private Thread createCopyThread2(PipedHostTelService service) {
LinkedList<String> preCommand = new LinkedList<String>() {{
this.addAll(Arrays.asList("help", "test", "exit"));
}};
return new Thread(() -> {
while (!preCommand.isEmpty()) {
try {
Thread.sleep(200);
String pop = preCommand.pop();
if (StringUtils.isNotBlank(pop)) {
service.sendCommand(pop);
}
} catch (Exception e) { /**/ }
}
});
}
private String applyDatabaseSpecificOperators(LinkedList<String> operandStack, LinkedList<Operator> operatorStack) {
List<String> operands = new ArrayList<>();
while (operatorStack.size() != 0) {
Operator operator = operatorStack.pop();
while (operands.size() != operator.getOperandsCount()) {
operands.add(operandStack.pop());
}
Collections.reverse(operands);
operandStack.push(operator.process(operands));
operands.clear();
}
return applyWordProcessors(operandStack.stream().collect(Collectors.joining()));
}
public List<EObjectChange> getAllEObjectRecordings() {
LinkedList<EObjectChange> todo = new LinkedList<>();
todo.addAll(roots);
List<EObjectChange> result = Lists.newArrayList();
while (!todo.isEmpty()) {
EObjectChange next = todo.pop();
result.add(next);
todo.addAll(next.getChildren());
}
return result;
}
/**
* Propagates node table of given DAG to all of it ancestors.
*/
private void bubbleUpNodeTable(DAGraph<DataT, NodeT> from, LinkedList<String> path) {
if (path.contains(from.rootNode.key())) {
path.push(from.rootNode.key()); // For better error message
throw new IllegalStateException("Detected circular dependency: " + StringUtils.join(path, " -> "));
}
path.push(from.rootNode.key());
for (DAGraph<DataT, NodeT> to : from.parentDAGs) {
this.merge(from.nodeTable, to.nodeTable);
this.bubbleUpNodeTable(to, path);
}
path.pop();
}
/**
* 处理Span内部含有换行符转换为占满剩余行空间的多个元素队列
*
* @param seq 待处理Span队列
* @return 处理后含有占满剩余行空间的Span队列
*/
private LinkedList<Span> spanLinebreakSplit(LinkedList<Span> seq) {
LinkedList<Span> sps = new LinkedList<>();
if (seq == null || seq.isEmpty()) {
return sps;
}
while (!seq.isEmpty()) {
Span pop = seq.pop();
// 通过换行符对span内容进行分割,获取新的队列
LinkedList<Span> spans = pop.splitLineBreak();
sps.addAll(spans);
}
return sps;
}
private static void addDirectoryRecursively(
TarArchiveOutputStream tarOut,
String parentPath,
File dir,
long modTime,
FilenameFilter filter)
throws IOException {
final int parentPathLength = parentPath.length() + 1;
final LinkedList<File> q = new LinkedList<>();
q.add(dir);
while (!q.isEmpty()) {
final File current = q.pop();
final File[] list = current.listFiles();
if (list != null) {
for (File f : list) {
if (filter.accept(current, f.getName())) {
final String entryName =
f.getAbsolutePath().substring(parentPathLength).replace('\\', '/');
if (f.isDirectory()) {
addDirectoryEntry(tarOut, entryName, f, modTime);
q.push(f);
} else if (f.isFile()) {
addFileEntry(tarOut, entryName, f, modTime);
}
}
}
}
}
}
public void middleDfs(TreeNode root, List<Integer> list) {
if (root == null) {
return;
}
LinkedList<TreeNode> stack = new LinkedList<>();
while (root != null || !stack.isEmpty()) {
while (root != null) {
stack.push(root);
root = root.left;
}
root = stack.pop();
list.add(root.val);
root = root.right;
}
}
@Override
public Set<PackingPlan.ContainerPlan> addContainers(
Set<PackingPlan.ContainerPlan> containersToAdd) {
Set<PackingPlan.ContainerPlan> remapping = new HashSet<>();
if ("prompt".equalsIgnoreCase(Context.updatePrompt(config))
&& !hasConfirmedWithUser(containersToAdd.size())) {
LOG.warning("Scheduler updated topology canceled.");
return remapping;
}
// Do the actual containers adding
LinkedList<Integer> newAddedContainerIds = new LinkedList<>(
controller.addContainers(containersToAdd.size()));
if (newAddedContainerIds.size() != containersToAdd.size()) {
throw new RuntimeException(
"Aurora returned different container count " + newAddedContainerIds.size()
+ "; input count was " + containersToAdd.size());
}
// Do the remapping:
// use the `newAddedContainerIds` to replace the container id in the `containersToAdd`
for (PackingPlan.ContainerPlan cp : containersToAdd) {
PackingPlan.ContainerPlan newContainerPlan =
new PackingPlan.ContainerPlan(
newAddedContainerIds.pop(), cp.getInstances(),
cp.getRequiredResource(), cp.getScheduledResource().orNull());
remapping.add(newContainerPlan);
}
LOG.info("The remapping structure: " + remapping);
return remapping;
}
private LinkedList<Integer> findActiveBreakpointsChildren(int selectedNodeNumber) {
//a list of breakpoints...
LinkedList<Integer> linkedList = new LinkedList<Integer>();
int[] nodeBreakpointNumber = new int[numNodes];
//int[] nodeStatus = new int[numNodes];
//for(int i=0; i < numNodes; i ++){
// nodeStatus[i] = -1;
//}
//convert to easy process format.
//for(int i=0; i < (binSize ); i++){
// if((int) indicators.getParameterValue(i) ==1){
// nodeStatus[(int)breakPoints.getParameterValue(i)] = i;
// }
//}
//process the tree and get the vLoc of the viruses..
//breadth first depth first..
NodeRef cNode = treeModel.getRoot();
LinkedList<NodeRef> visitlist = new LinkedList<NodeRef>();
visitlist.add(cNode);
//I am not sure if it still works......
int countProcessed=0;
while(visitlist.size() > 0){
countProcessed++;
//assign value to the current node...
if(treeModel.getParent(cNode) == null){
//Parameter curMu = mu.getParameter(0);
nodeBreakpointNumber[cNode.getNumber()] = cNode.getNumber();
}
else{
nodeBreakpointNumber[cNode.getNumber()] = nodeBreakpointNumber[treeModel.getParent(cNode).getNumber()];
//System.out.println("node#" + cNode.getNumber() + " is " + nodeBreakpointNumber[cNode.getNumber()]);
if( (int) indicators.getParameterValue(cNode.getNumber()) == 1){
//System.out.println(cNode.getNumber() + " is a break point");
//Parameter curMu = mu.getParameter(cNode.getNumber() +1); //+1 because mu0 is reserved for the root.
//Parameter curMu = mu.getParameter(cNode.getNumber() ); //+1 because mu0 is reserved for the root.
//see if parent's status is the same as the selectedIndex
if( nodeBreakpointNumber[cNode.getNumber()] == selectedNodeNumber ){
//System.out.println("hihi");
linkedList.add( cNode.getNumber() );
}
//now, replace this nodeBreakpointNumber with its own node number
nodeBreakpointNumber[cNode.getNumber()] = cNode.getNumber();
}
}
//add all the children to the queue
for(int childNum=0; childNum < treeModel.getChildCount(cNode); childNum++){
NodeRef node= treeModel.getChild(cNode,childNum);
visitlist.add(node);
}
visitlist.pop(); //now that we have finished visiting this node, pops it out of the queue
if(visitlist.size() > 0){
cNode = visitlist.getFirst(); //set the new first node in the queue to visit
}
}
//System.out.println("Now printing children of " + selectedNodeNumber+":");
//for(int i=0; i < linkedList.size(); i++){
// System.out.println( linkedList.get(i) );
//}
return linkedList;
}
public static int simulateCuboidGeneration(CubeDesc cubeDesc, boolean validate) {
CuboidScheduler scheduler = cubeDesc.getInitialCuboidScheduler();
long baseCuboid = Cuboid.getBaseCuboidId(cubeDesc);
Collection<Long> cuboidSet = new TreeSet<Long>();
cuboidSet.add(baseCuboid);
LinkedList<Long> cuboidQueue = new LinkedList<Long>();
cuboidQueue.push(baseCuboid);
while (!cuboidQueue.isEmpty()) {
long cuboid = cuboidQueue.pop();
Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(cuboid);
for (Long sc : spnanningCuboids) {
boolean notfound = cuboidSet.add(sc);
if (!notfound) {
throw new IllegalStateException("Find duplicate spanning cuboid " + sc + " from cuboid " + cuboid);
}
cuboidQueue.push(sc);
}
}
boolean enableDimCap = false;
for (AggregationGroup agg : cubeDesc.getAggregationGroups()) {
if (agg.getDimCap() > 0) {
enableDimCap = true;
break;
}
}
if (validate) {
if (enableDimCap) {
if (cubeDesc.getAllCuboids().size() != cuboidSet.size()) {
throw new IllegalStateException("Expected cuboid set " + cubeDesc.getAllCuboids() + "; but actual cuboid set " + cuboidSet);
}
} else {
//only run this for test purpose, performance is bad when # of dims is large
TreeSet<Long> enumCuboids = enumCalcCuboidCount(cubeDesc);
System.out.println(Arrays.toString(enumCuboids.toArray(new Long[enumCuboids.size()])));
if (enumCuboids.equals(cuboidSet) == false) {
throw new IllegalStateException("Expected cuboid set " + enumCuboids + "; but actual cuboid set " + cuboidSet);
}
//check all valid and invalid
for (long i = 0; i < baseCuboid; ++i) {
if (cuboidSet.contains(i)) {
if (!scheduler.isValid(i)) {
throw new RuntimeException();
}
if (scheduler.findBestMatchCuboid(i) != i) {
throw new RuntimeException();
}
} else {
if (scheduler.isValid(i)) {
throw new RuntimeException();
}
long corrected = scheduler.findBestMatchCuboid(i);
if (corrected == i) {
throw new RuntimeException();
}
if (!scheduler.isValid(corrected)) {
throw new RuntimeException();
}
if (scheduler.findBestMatchCuboid(corrected) != corrected) {
throw new RuntimeException();
}
}
}
}
}
return cuboidSet.size();
}
private static void copy(
File source, File target, FilenameFilter filter, boolean nio, boolean replaceIfExists)
throws IOException {
if (source.isDirectory()) {
if (!(target.exists() || target.mkdirs())) {
throw new IOException(
String.format("Unable create directory '%s'. ", target.getAbsolutePath()));
}
if (filter == null) {
filter = ANY_FILTER;
}
String sourceRoot = source.getAbsolutePath();
LinkedList<File> q = new LinkedList<>();
q.add(source);
while (!q.isEmpty()) {
File current = q.pop();
File[] list = current.listFiles();
if (list != null) {
for (File f : list) {
if (!filter.accept(current, f.getName())) {
continue;
}
File newFile = new File(target, f.getAbsolutePath().substring(sourceRoot.length() + 1));
if (f.isDirectory()) {
if (!(newFile.exists() || newFile.mkdirs())) {
throw new IOException(
String.format("Unable create directory '%s'. ", newFile.getAbsolutePath()));
}
if (!f.equals(target)) {
q.push(f);
}
} else {
if (nio) {
nioCopyFile(f, newFile, replaceIfExists);
} else {
copyFile(f, newFile, replaceIfExists);
}
}
}
}
}
} else {
File parent = target.getParentFile();
if (!(parent.exists() || parent.mkdirs())) {
throw new IOException(
String.format("Unable create directory '%s'. ", parent.getAbsolutePath()));
}
if (nio) {
nioCopyFile(source, target, replaceIfExists);
} else {
copyFile(source, target, replaceIfExists);
}
}
}
private void getDiscreteLevels(String species, SpeciesCollection S, Experiments experiments, Encodings L, int levels)
{
int col = S.getColumn(species);
double[] level = new double[levels + 1];
double v = Double.NaN, vp = Double.NaN;
int steps = 0;
level[0] = 0;
level[levels] = Double.POSITIVE_INFINITY;
LinkedList<Double> values = new LinkedList<Double>();
for (List<List<Double>> experiment : experiments.getExperiments())
{
for (int i = 0; i < experiment.size(); i++)
{
double value = experiment.get(i).get(col);
values.add(value);
}
}
Collections.sort(values);
for (int j = 1; j < levels - 1; j++)
{
int count = 0;
level[j] = Double.POSITIVE_INFINITY;
steps = values.size() / (levels - j + 1);
while (values.size() > 0 && count < steps)
{
v = values.pop();
count++;
}
do
{
vp = values.pop();
}
while (values.size() > 0 && v == vp);
if (values.size() > 0)
{
level[j] = v;
values.addFirst(vp);
}
}
L.addDiscreteSpecies(col, level);
}
private static int extractJsonObjectEndPosition(String responseString, int beginPosition) {
//记录当前尚未发现配对闭合的大括号
LinkedList<String> braces = new LinkedList<String>();
//记录当前字符是否在双引号中
boolean inQuotes = false;
//记录当前字符前面连续的转义字符个数
int consecutiveEscapeCount = 0;
//从待验签字符的起点开始遍历后续字符串,找出待验签字符串的终止点,终点即是与起点{配对的}
for (int index = beginPosition; index < responseString.length(); ++index) {
//提取当前字符
char currentChar = responseString.charAt(index);
//如果当前字符是"且前面有偶数个转义标记(0也是偶数)
if (currentChar == '"' && consecutiveEscapeCount % 2 == 0) {
//是否在引号中的状态取反
inQuotes = !inQuotes;
}
//如果当前字符是{且不在引号中
else if (currentChar == '{' && !inQuotes) {
//将该{加入未闭合括号中
braces.push("{");
}
//如果当前字符是}且不在引号中
else if (currentChar == '}' && !inQuotes) {
//弹出一个未闭合括号
braces.pop();
//如果弹出后,未闭合括号为空,说明已经找到终点
if (braces.isEmpty()) {
return index + 1;
}
}
//如果当前字符是转义字符
if (currentChar == '\\') {
//连续转义字符个数+1
++consecutiveEscapeCount;
} else {
//连续转义字符个数置0
consecutiveEscapeCount = 0;
}
}
//如果没有找到配对的闭合括号,说明验签内容片段提取失败,直接尝试选取剩余整个响应字符串进行验签
return responseString.length();
}
public List<MenuItem> layoutMainPanelItems(List<MenuItem> menuItems, final int toolbarWidth) {
int availableWidth = toolbarWidth;
final LinkedList<MenuItem> remainingMenuItems = new LinkedList<>(menuItems);
/*final LinkedList<MenuItem> overflowMenuItems = new LinkedList<>();
for (MenuItem menuItem : menuItems) {
if (menuItem.requiresOverflow()) {
overflowMenuItems.add(menuItem); TODO
} else {
remainingMenuItems.add(menuItem);
}
}
remainingMenuItems.addAll(overflowMenuItems);*/
mMainPanel.removeAllViews();
mMainPanel.setPaddingRelative(0, 0, 0, 0);
boolean isFirstItem = true;
while (!remainingMenuItems.isEmpty()) {
final MenuItem menuItem = remainingMenuItems.peek();
/*if (!isFirstItem && menuItem.requiresOverflow()) {
break;
}*/
final View menuItemButton = createMenuItemButton(mContext, menuItem, mIconTextSpacing);
if (menuItemButton instanceof LinearLayout) {
((LinearLayout) menuItemButton).setGravity(Gravity.CENTER);
}
if (isFirstItem) {
menuItemButton.setPaddingRelative((int) (1.5 * menuItemButton.getPaddingStart()), menuItemButton.getPaddingTop(), menuItemButton.getPaddingEnd(), menuItemButton.getPaddingBottom());
}
boolean isLastItem = remainingMenuItems.size() == 1;
if (isLastItem) {
menuItemButton.setPaddingRelative(menuItemButton.getPaddingStart(), menuItemButton.getPaddingTop(), (int) (1.5 * menuItemButton.getPaddingEnd()), menuItemButton.getPaddingBottom());
}
menuItemButton.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
final int menuItemButtonWidth = Math.min(menuItemButton.getMeasuredWidth(), toolbarWidth);
final boolean canFitWithOverflow = menuItemButtonWidth <= availableWidth - mOverflowButtonSize.getWidth();
final boolean canFitNoOverflow = isLastItem && menuItemButtonWidth <= availableWidth;
if (canFitWithOverflow || canFitNoOverflow) {
setButtonTagAndClickListener(menuItemButton, menuItem);
//menuItemButton.setTooltipText(menuItem.getTooltipText()); TODO
mMainPanel.addView(menuItemButton);
final ViewGroup.LayoutParams params = menuItemButton.getLayoutParams();
params.width = menuItemButtonWidth;
menuItemButton.setLayoutParams(params);
availableWidth -= menuItemButtonWidth;
remainingMenuItems.pop();
} else {
break;
}
isFirstItem = false;
}
if (!remainingMenuItems.isEmpty()) {
mMainPanel.setPaddingRelative(0, 0, mOverflowButtonSize.getWidth(), 0);
}
mMainPanelSize = measure(mMainPanel);
return remainingMenuItems;
}