本文整理汇总了Java中java.util.ArrayDeque.removeFirst方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayDeque.removeFirst方法的具体用法?Java ArrayDeque.removeFirst怎么用?Java ArrayDeque.removeFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ArrayDeque
的用法示例。
在下文中一共展示了ArrayDeque.removeFirst方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.ArrayDeque; //导入方法依赖的package包/类
public static void main(String[] args) {
HashMap<Integer, Integer> map = new HashMap<>();
ArrayDeque<Integer> deque = new ArrayDeque<>();
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int max = 0;
for (int i = 0; i < n; i++) {
/* Remove old value (if necessary) */
if (i >= m) {
int old = deque.removeFirst();
if (map.get(old) == 1) {
map.remove(old);
} else {
map.merge(old, -1, Integer::sum);
}
}
/* Add new value */
int num = scan.nextInt();
deque.addLast(num);
map.merge(num, 1, Integer::sum);
max = Math.max(max, map.size());
}
scan.close();
System.out.println(max);
}
示例2: testEmpty
import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
* isEmpty is true before add, false after
*/
public void testEmpty() {
ArrayDeque q = new ArrayDeque();
assertTrue(q.isEmpty());
q.add(new Integer(1));
assertFalse(q.isEmpty());
q.add(new Integer(2));
q.removeFirst();
q.removeFirst();
assertTrue(q.isEmpty());
}
示例3: testSize
import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
* size changes when elements added and removed
*/
public void testSize() {
ArrayDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(SIZE - i, q.size());
q.removeFirst();
}
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.size());
q.add(new Integer(i));
}
}
示例4: testRemoveFirst
import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
* removeFirst() removes first element, or throws NSEE if empty
*/
public void testRemoveFirst() {
ArrayDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.removeFirst());
}
try {
q.removeFirst();
shouldThrow();
} catch (NoSuchElementException success) {}
assertNull(q.peekFirst());
}
示例5: testRetainAll
import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
* retainAll(c) retains only those elements of c and reports true if changed
*/
public void testRetainAll() {
ArrayDeque q = populatedDeque(SIZE);
ArrayDeque p = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
boolean changed = q.retainAll(p);
assertEquals(changed, (i > 0));
assertTrue(q.containsAll(p));
assertEquals(SIZE - i, q.size());
p.removeFirst();
}
}
示例6: loadModulesFromList
import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
* Loads modules (and their dependencies) specified in the list
* @param configMods The fully-qualified module names
* @return The ModuleContext containing all the loaded modules
* @throws FloodlightModuleException
*/
public synchronized IFloodlightModuleContext
loadModulesFromList(Collection<String> configMods,
Properties prop)
throws FloodlightModuleException {
logger.debug("Starting module loader");
findAllModules(configMods);
ArrayList<IFloodlightModule> moduleList = new ArrayList<>();
Map<Class<? extends IFloodlightService>, IFloodlightModule> moduleMap =
new HashMap<>();
HashSet<String> modsVisited = new HashSet<>();
ArrayDeque<String> modsToLoad = new ArrayDeque<>(configMods);
while (!modsToLoad.isEmpty()) {
String moduleName = modsToLoad.removeFirst();
traverseDeps(moduleName, modsToLoad,
moduleList, moduleMap, modsVisited);
}
parseConfigParameters(prop);
loadedModuleList = moduleList;
initModules(moduleList);
if(startupModules)
startupModules(moduleList);
return floodlightModuleContext;
}