本文整理汇总了Java中java.util.LinkedList.peek方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedList.peek方法的具体用法?Java LinkedList.peek怎么用?Java LinkedList.peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.LinkedList
的用法示例。
在下文中一共展示了LinkedList.peek方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: close
import java.util.LinkedList; //导入方法依赖的package包/类
/**
* Closes *ALL* the player's Guis, clearing his stack histories
*
* @param player the player
*/
public void close(Player player) {
if (called) return;
called = true;
try {
LinkedList<Gui> g = histories.remove(player);
if (g == null || g.isEmpty())
return;
Gui oldGui = g.peek();
GuiCloseEvent e = new GuiCloseEvent(player, oldGui);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
histories.put(player, g);
return;
}
oldGui.onClose(player);
player.closeInventory();
g.clear();
} finally {
called = false;
}
}
示例2: open
import java.util.LinkedList; //导入方法依赖的package包/类
/**
* Opens a Gui to a player, adding it to the stack. If the closeOthers parameter is specified it will removeHotbar the stack first
*
* @param player the player that is opening the api
* @param gui the gui to be opened
* @param closeOthers if give to true the GUI histories would be cleaned
*/
public void open(Player player, Gui gui, boolean closeOthers) {
if (called) return;
called = true;
try {
LinkedList<Gui> g = getOrCreate(player);
Gui oldGui = g.peek();
GuiOpenEvent e = new GuiOpenEvent(player, gui, oldGui);
e.setCloseOthers(closeOthers);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
if (g.isEmpty())
histories.remove(player);
return;
}
closeOthers = e.isCloseOthers();
if (oldGui != null)
oldGui.onClose(player);
if (closeOthers)
g.clear();
gui.onOpen(player);
gui.show(player);
g.push(gui);
} finally {
called = false;
}
}
示例3: onClick
import java.util.LinkedList; //导入方法依赖的package包/类
/**
* Called when a player clicks on the inventory, the filters to check if the Player clicked on the GUi's inventory should be made outside of this method
*
* @param event the click event
*/
public void onClick(InventoryClickEvent event) {
HumanEntity h = event.getWhoClicked();
if (!(h instanceof Player))
return;
LinkedList<Gui> g = histories.get(h);
if (g != null && !g.isEmpty()) {
Gui gui = g.peek();
GuiClickEvent e = new GuiClickEvent(event, (Player) h, gui);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled())
return;
//Event cancelled BEFORE the method call to permit the un-cancelling
event.setCancelled(true);
gui.onClick(event);
//Creative idiots could copy the links
if (event.isShiftClick() && event.getWhoClicked().getGameMode() == GameMode.CREATIVE)
((Player) event.getWhoClicked()).updateInventory();
}
}
示例4: gatherMethods
import java.util.LinkedList; //导入方法依赖的package包/类
private Method gatherMethods ( final Class<?> clazz, final String methodName )
{
final LinkedList<Method> methods = new LinkedList<> ();
for ( final Method m : clazz.getMethods () )
{
if ( m.getName ().equals ( methodName ) )
{
methods.add ( m );
}
}
if ( methods.size () == 1 )
{
return methods.peek ();
}
else if ( methods.isEmpty () )
{
throw new IllegalStateException ( String.format ( "Method '%s' not found on class '%s'", methodName, clazz.getName () ) );
}
else
{
throw new IllegalStateException ( String.format ( "Method '%s' of class '%s' is polymorphic. This is now allowed for the recipe target classes.", methodName, clazz.getName () ) );
}
}
示例5: transferThroughList
import java.util.LinkedList; //导入方法依赖的package包/类
private String transferThroughList(String in, int index) {
LinkedList<String> list = new LinkedList<String>();
list.add(System.getenv("")); // taints the list
list.clear(); // makes the list safe again
list.add(1, "xx");
list.addFirst(in); // can taint the list
list.addLast("yy");
list.push(in);
return list.element() + list.get(index) + list.getFirst() + list.getLast()
+ list.peek() + list.peekFirst() + list.peekLast() + list.poll()
+ list.pollFirst() + list.pollLast() + list.pop() + list.remove()
+ list.remove(index) + list.removeFirst() + list.removeLast()
+ list.set(index, "safe") + list.toString();
}
示例6: reprint
import java.util.LinkedList; //导入方法依赖的package包/类
public void reprint(Player player) {
if (called) return;
called = true;
try {
LinkedList<Gui> g = getHistory(player);
if (g == null)
return;
Gui gui = g.peek();
if (gui != null)
gui.show(player);
} finally {
called = false;
}
}
示例7: peekCurrentDataSource
import java.util.LinkedList; //导入方法依赖的package包/类
public static String peekCurrentDataSource(String oldDbName) {
Map map=contextHolderMap.get();
if(map==null){
return null;
}
LinkedList list=(LinkedList) map.get(oldDbName);
if(list!=null && list.size()>0){
return (String) list.peek();
}
return null;
}
示例8: equateIntervals
import java.util.LinkedList; //导入方法依赖的package包/类
/**
* computes whether the test interval list is equivalent to master. To be equivalent, test must
* contain GenomeLocs covering every base in master, exactly once. Note that this algorithm
* assumes that master genomelocs are all discontiguous (i.e., we don't have locs like 1-3 and 4-6 but
* rather just 1-6). In order to use this algorithm with contiguous genomelocs first merge them. The algorithm
* doesn't assume that test has discontinuous genomelocs.
*
* Returns a null string if there are no differences, otherwise returns a string describing the difference
* (useful for UnitTests). Assumes both lists are sorted
*
* @param masterArg sorted master genome locs
* @param testArg sorted test genome locs
* @return null string if there are no difference, otherwise a string describing the difference
*/
public static String equateIntervals(List<GenomeLoc> masterArg, List<GenomeLoc> testArg) {
LinkedList<GenomeLoc> master = new LinkedList<GenomeLoc>(masterArg);
LinkedList<GenomeLoc> test = new LinkedList<GenomeLoc>(testArg);
while ( ! master.isEmpty() ) { // there's still unchecked bases in master
final GenomeLoc masterHead = master.pop();
final GenomeLoc testHead = test.pop();
if ( testHead.overlapsP(masterHead) ) {
// remove the parts of test that overlap master, and push the remaining
// parts onto master for further comparison.
for ( final GenomeLoc masterPart : Utils.reverse(masterHead.subtract(testHead)) ) {
master.push(masterPart);
}
} else {
// testHead is incompatible with masterHead, so we must have extra bases in testHead
// that aren't in master
return "Incompatible locs detected masterHead=" + masterHead + ", testHead=" + testHead;
}
}
if ( test.isEmpty() ) // everything is equal
return null; // no differences
else
return "Remaining elements found in test: first=" + test.peek();
}
示例9: getNext
import java.util.LinkedList; //导入方法依赖的package包/类
private E getNext (boolean remove)
{
// Always called after using a takeLock.lock
LinkedList<E> list = null;
boolean found = false;
Object listKey = null;
for (Object key : keys)
{
// save first list if lastKey is the last of the keys
if (list == null)
{
listKey = key;
list = storage.get (key);
// for first iteration, take the first list
if (lastUsedKey == null)
{
break;
}
}
if (lastUsedKey != null && lastUsedKey.equals (key))
{
found = true;
continue;
}
// if key is found, take the next list
if (found)
{
listKey = key;
list = storage.get (key);
break;
}
}
E e = remove ? list.poll () : list.peek ();
if (list.isEmpty ())
{
// remove empty list from storage and keep lastKey as it is
storage.remove (listKey);
keys.remove (listKey);
}
else
if (remove)
{
// save last used list key
lastUsedKey = listKey;
}
return e;
}
示例10: peek
import java.util.LinkedList; //导入方法依赖的package包/类
public Object peek() {
LinkedList last = getLastStack();
if (last == null) throw new RuntimeException("Trying to pop from empty chapter03_stack_queues");
return last.peek();
}
示例11: extractObjectDetails
import java.util.LinkedList; //导入方法依赖的package包/类
/*******************
* Extract object details from a ReplyData that was captured through the
* RMI registry proxy.
*
* @param objName The object name bound to the RMI registry for which data is being extracted.
* @param packetBytes The ReplyData captured from the RMI registry which contains the remote object description.
* @return An RMIObject describing the remote object.
******************/
public RMIObject extractObjectDetails(String objName, ArrayList<Byte> packetBytes) {
LinkedList<Byte> dataStack;
RMIObject obj;
byte b;
int i;
//Create the RMIObject with the given object name
obj = new RMIObject(objName);
//Copy the given buffer into a stack for parsing
dataStack = new LinkedList<Byte>();
dataStack.addAll(packetBytes);
//Set the 'recordClasses' flag to true so that class descriptions are added to the object description
this._recordClasses = true;
//Start parsing the object data
try {
//Validate the RMI packet type byte
if(dataStack.peek() != 0x51) { throw new BaRMIeInvalidReplyDataPacketException("The data buffer begins with 0x" + String.format("%02x", dataStack.peek()) + ", which is not a ReplyData packet (0x51 expected)."); }
dataStack.pop();
//Validate the serialisation header
if(dataStack.pop() != (byte)0xac || dataStack.pop() != (byte)0xed) { throw new BaRMIeInvalidReplyDataPacketException("The data buffer does not contain the serialisation magic number data."); }
//Validate the serialisation stream version
if(dataStack.pop() != 0x00 || dataStack.pop() != 0x05) { throw new BaRMIeInvalidReplyDataPacketException("The data buffer does not contain version 5 serialisation data."); }
//Parse the serialisation stream elements to extract class names, annotations, and endpoint details
while(dataStack.size() > 0) {
//Get the type of the next stream element
b = dataStack.pop();
//Process the element accordingly
switch(b) {
//Skip over top-level block data elements
case ObjectStreamConstants.TC_BLOCKDATA:
//Read the block length
b = dataStack.pop();
//Skip over the block bytes
for(i = 0; i < b; ++i) {
dataStack.pop();
}
break;
//Process the returned RMI object
case ObjectStreamConstants.TC_OBJECT:
this.handleNewObjectElement(obj, dataStack);
break;
//Unknown top-level stream element type
default:
throw new BaRMIeInvalidReplyDataPacketException("Unknown serialisation stream element (0x" + String.format("%02x", b) + ").");
}
}
} catch(Exception e) {
//Something went wrong, store the exception in the object element so it can be reviewed
obj.setParsingException(e);
}
//Return the RMIObject
return obj;
}
示例12: getCurrentHelper
import java.util.LinkedList; //导入方法依赖的package包/类
protected OnlineSectioningHelper getCurrentHelper() {
LinkedList<OnlineSectioningHelper> h = sHelper.get();
if (h == null || h.isEmpty())
return new OnlineSectioningHelper(null);
return h.peek();
}
示例13: pluginUrls
import java.util.LinkedList; //导入方法依赖的package包/类
public static List<Path> pluginUrls(Path topPath) throws IOException {
boolean containsClassFiles = false;
Set<Path> archives = new HashSet<>();
LinkedList<DirectoryEntry> dfs = new LinkedList<>();
Set<Path> visited = new HashSet<>();
if (isArchive(topPath)) {
return Collections.singletonList(topPath);
}
DirectoryStream<Path> topListing = Files.newDirectoryStream(
topPath,
PLUGIN_PATH_FILTER
);
dfs.push(new DirectoryEntry(topListing));
visited.add(topPath);
try {
while (!dfs.isEmpty()) {
Iterator<Path> neighbors = dfs.peek().iterator;
if (!neighbors.hasNext()) {
dfs.pop().stream.close();
continue;
}
Path adjacent = neighbors.next();
if (Files.isSymbolicLink(adjacent)) {
Path absolute = Files.readSymbolicLink(adjacent).toRealPath();
if (Files.exists(absolute)) {
adjacent = absolute;
} else {
continue;
}
}
if (!visited.contains(adjacent)) {
visited.add(adjacent);
if (isArchive(adjacent)) {
archives.add(adjacent);
} else if (isClassFile(adjacent)) {
containsClassFiles = true;
} else {
DirectoryStream<Path> listing = Files.newDirectoryStream(
adjacent,
PLUGIN_PATH_FILTER
);
dfs.push(new DirectoryEntry(listing));
}
}
}
} finally {
while (!dfs.isEmpty()) {
dfs.pop().stream.close();
}
}
if (containsClassFiles) {
if (archives.isEmpty()) {
return Collections.singletonList(topPath);
}
log.warn("Plugin path contains both java archives and class files. Returning only the"
+ " archives");
}
return Arrays.asList(archives.toArray(new Path[0]));
}