当前位置: 首页>>代码示例>>Java>>正文


Java Deque.offer方法代码示例

本文整理汇总了Java中java.util.Deque.offer方法的典型用法代码示例。如果您正苦于以下问题:Java Deque.offer方法的具体用法?Java Deque.offer怎么用?Java Deque.offer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Deque的用法示例。


在下文中一共展示了Deque.offer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSeqPref

import java.util.Deque; //导入方法依赖的package包/类
public void testSeqPref() throws Exception {
    JavaIndexerWorker.TEST_DO_PREFETCH = false;
    final LogHandler handler = new LogHandler();
    handler.expect("Using sequential iterator");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            final CompileTuple ct = pf.next();
            assertNull(getCache(ct.jfo));
            got.offer(ct);
            pf.remove();
        }
        assertCollectionsEqual(files,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:SourcePrefetcherTest.java

示例2: testConPref

import java.util.Deque; //导入方法依赖的package包/类
public void testConPref() throws Exception {
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            final CompileTuple ct = pf.next();
            assertNotNull(getCache(ct.jfo));
            got.offer(ct);
            pf.remove();
            assertNull(getCache(ct.jfo));
        }
        assertCollectionsEqual(files,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:SourcePrefetcherTest.java

示例3: dequeStuff

import java.util.Deque; //导入方法依赖的package包/类
static void dequeStuff() {
  Deque<Object> d = new ArrayDeque<>();
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.add(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.addFirst(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.addLast(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.offerFirst(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.offerLast(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.offer(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.push(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.toArray(null);
}
 
开发者ID:uber,项目名称:NullAway,代码行数:20,代码来源:NullAwayNativeModels.java

示例4: main

import java.util.Deque; //导入方法依赖的package包/类
public static void main(String[] args) {
    int[] nums = new int[]{1, 3, -1, -3, 5, 3, 6, 7};
    int[] res = maxSlidingWindow(nums, 3);
    StringBuilder sb = new StringBuilder();
    for (int i : res) {
        sb.append(i).append(" ");
    }
    System.out.println(sb.toString());

    Deque<Integer> deque = new ArrayDeque<>();
    deque.offer(1);
    deque.offer(2);
    deque.offer(3);
    deque.offer(4);
    deque.offer(5);
    System.out.println(deque.peek());
    System.out.println(deque.peekLast());
    System.out.println(null instanceof Object);
}
 
开发者ID:xy1m,项目名称:PlayGround,代码行数:20,代码来源:MaxSlidingWindow.java

示例5: main

import java.util.Deque; //导入方法依赖的package包/类
public static void main(String[] args) {
 
    Deque<Integer> deque = new LinkedList<>();
    
    // OFFER - add some data into queue     
    deque.offer(5);
    deque.offer(4);
    deque.offer(2);
    deque.offerFirst(1);
    deque.offerLast(9);
    System.out.println("After offer data. Size: " + deque.size()+", content: " + deque.toString());
    
    // PEEK - view data from first or last, without remove it
    System.out.println("Peek First is " + deque.peekFirst()+", Peek Last is "
            + deque.peekLast()+", Peek is "+ deque.peek());
    
    // POLL - removeing, head or tail data from queue
    System.out.println("Poll head data is " + deque.pollFirst()+
            ", poll last data is " + deque.pollLast()+
            ", poll is " + deque.poll()+
            ", content: " + deque.toString());                       
}
 
开发者ID:mkdika,项目名称:learnjava8,代码行数:23,代码来源:TestDeque.java

示例6: main

import java.util.Deque; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner scann = new Scanner(System.in);
    Deque<String> names = new ArrayDeque<>();

    Collections.addAll(names, scann.nextLine().split("\\s+"));
    int count = Integer.parseInt(scann.nextLine());
    int cycles = 1;
    while (names.size() > 1){
        for (int i = 1; i < count; i++) {
            names.offer(names.remove());
        }
        if(isPrime(cycles)){
            System.out.println("Prime " + names.peek());
        } else {
            System.out.println("Removed " + names.poll());
        }
        cycles++;
    }
    System.out.println("Last is " + names.remove());

}
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:22,代码来源:p03_MathPotato.java

示例7: maxSlidingWindow

import java.util.Deque; //导入方法依赖的package包/类
public int[] maxSlidingWindow(int[] nums, int k) {
    int len = nums.length;
    if (len == 0) return nums;
    int[] res = new int[len - k + 1];
    
    Deque<Integer> dq = new LinkedList<Integer>();
    for (int i = 0; i < len; i++) {
    	while (!dq.isEmpty() && dq.peekLast() < nums[i])
    		dq.pollLast();
    	
    	dq.offer(nums[i]);
    	
    	if (i >= k - 1) {
    		res[i - k + 1] = dq.peek();
    		if (nums[i - k + 1] == dq.peek())
    			dq.pollFirst();
    	}
    }
	return res;
}
 
开发者ID:JoeZ-EE,项目名称:Aim2Offer,代码行数:21,代码来源:065_MaxInSlidingWindow.java

示例8: visit

import java.util.Deque; //导入方法依赖的package包/类
@NonNull
private static List<JavaFileObject> visit(
        @NonNull final File folder,
        @NonNull final File root,
        @NonNull final Charset encoding,
        @NullAllowed final JavaFileFilterImplementation filter,
        final boolean recursive,
        @NonNull Function<File,JavaFileObject.Kind> accept) {
    final List<JavaFileObject> res = new ArrayList<>();
    final Deque<File> todo = new ArrayDeque<>();
    todo.offer(folder);
    while (!todo.isEmpty()) {
        final File active = todo.removeLast();  //DFS
        final File[] content = active.listFiles();
        if (content != null) {
            for (File f : content) {
                final JavaFileObject.Kind fKind = accept.apply(f);
                if (fKind != null) {
                    res.add(FileObjects.fileFileObject(
                        f,
                        root,
                        filter,
                        fKind == JavaFileObject.Kind.CLASS ?
                                UNKNOWN_CHARSET :
                                encoding));
                } else if (recursive && f.isDirectory()) {
                    todo.offer(f);
                }
            }
        }
    }
    return Collections.unmodifiableList(res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:FolderArchive.java

示例9: setUp

import java.util.Deque; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    final FileObject wdFo = FileUtil.toFileObject(getWorkDir());
    final FileObject srcFolder = FileUtil.createFolder(wdFo, "src");        //NOI18N
    final Deque<CompileTuple> q = new ArrayDeque<CompileTuple>();
    for (int i=0; i<FILE_COUNT; i++) {
        final FileObject file = FileUtil.createData(srcFolder, String.format("file%d.txt",i)); //NOI18N
        final Indexable indexable = SPIAccessor.getInstance().create(new FileObjectIndexable(srcFolder, file));
        final PrefetchableJavaFileObject jfo = FileObjects.fileFileObject(FileUtil.toFile(file), FileUtil.toFile(srcFolder), null, null);
        q.offer(new CompileTuple(jfo,indexable));
    }
    files = q;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:SourcePrefetcherTest.java

示例10: testDeadlock208663

import java.util.Deque; //导入方法依赖的package包/类
public void testDeadlock208663() throws Exception {
    CompileTuple ct = files.iterator().next();
    final FileObject fo = URLMapper.findFileObject(ct.indexable.getURL());
    final FileLock lck = fo.lock();
    try {
        final OutputStream out = new BufferedOutputStream(fo.getOutputStream(lck));
        try {
            for (int i = 0; i<101; i++) {
                out.write('a');
            }
        } finally {
            out.close();
        }
    } finally {
        lck.releaseLock();
    }
    
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    JavaIndexerWorker.BUFFER_SIZE = 100;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            ct = pf.next();
            assertNotNull(getCache(ct.jfo));
            got.offer(ct);
            pf.remove();
            assertNull(getCache(ct.jfo));
        }
        assertCollectionsEqual(files,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:SourcePrefetcherTest.java

示例11: testDeletedFile

import java.util.Deque; //导入方法依赖的package包/类
public void testDeletedFile() throws Exception {
    CompileTuple ct = files.iterator().next();
    final FileObject fo = URLMapper.findFileObject(ct.indexable.getURL());        
    fo.delete();
    
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            ct = pf.next();
            try {
                if (ct != null) {
                    assertNotNull(getCache(ct.jfo));
                    got.offer(ct);
                }
            } finally {
                pf.remove();
            }
            if (ct != null) {
                assertNull(getCache(ct.jfo));
            }
        }
        final List<CompileTuple> allButFirst = new LinkedList<CompileTuple>(files);
        allButFirst.remove(0);
        assertCollectionsEqual(allButFirst,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:SourcePrefetcherTest.java

示例12: getRootURLs

import java.util.Deque; //导入方法依赖的package包/类
@NonNull
private static URL[] getRootURLs(@NonNull final ClassPath cp) {
    final List<ClassPath.Entry> entries = cp.entries();
    final Deque<URL> res = new ArrayDeque<>(entries.size());
    for (ClassPath.Entry e : entries) {
        res.offer(e.getURL());
    }
    return res.toArray(new URL[res.size()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ClassLoaderSupport.java

示例13: flushIfNeeded

import java.util.Deque; //导入方法依赖的package包/类
private static void flushIfNeeded(
        final boolean flush,
        @NonNull final ClusteredIndexables.DocumentStore store,
        @NonNull final Deque<? super String> collector) {
    if (flush) {
        for (IndexDocument doc : store) {
            collector.offer(doc.getPrimaryKey());
        }
        store.clear();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:DocumentStoreTest.java

示例14: formatConjestionDistance

import java.util.Deque; //导入方法依赖的package包/类
private Deque<Integer> formatConjestionDistance(List<RoadConditionItem> conditionItems, int eIndex, double totalDistance) {
    Deque<Integer> dists = new ArrayDeque<Integer>();
    RoadConditionItem item;
    int t;
    double maxIndex = conditionItems.get(conditionItems.size() - 1).curItemEndIndex;
    for (RoadConditionItem conditionItem : conditionItems) {
        conditionItem.curItemEndIndex = (int) (conditionItem.curItemEndIndex / maxIndex * totalDistance);
    }
    for (int i = 0; i < eIndex; i++) {
        item = conditionItems.get(i);
        if (dists.size() == 0) {
            if (item.roadConditionType > RoadConditionItem.ROAD_CONDITION_TYPE_Straightway) {
                dists.offer(i == 0 ? item.curItemEndIndex : item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex);
            }
        } else {
            t = dists.size();
            if ((t & 1) == 1) {//奇数,拥堵长度
                if (item.roadConditionType > RoadConditionItem.ROAD_CONDITION_TYPE_Straightway) {
                    dists.offer(dists.pollLast() + (item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                } else {
                    dists.offer((item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                }
            } else {//偶数,顺畅长度
                if (item.roadConditionType > RoadConditionItem.ROAD_CONDITION_TYPE_Straightway) {
                    if (dists.getLast() <= 100) {
                        dists.pollLast();
                        dists.offer(dists.pollLast() + (item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                    } else {
                        dists.offer((item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                    }
                } else {
                    dists.offer(dists.pollLast() + (item.curItemEndIndex - conditionItems.get(i - 1).curItemEndIndex));
                }
            }
        }
    }
    return dists;
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:39,代码来源:NavigatorService.java

示例15: maxSlidingWindow

import java.util.Deque; //导入方法依赖的package包/类
public static int[] maxSlidingWindow(int[] nums, int k) {
    Deque<Integer> deque = new ArrayDeque<>();
    int n = nums.length;
    int[] res = new int[n - k + 1];
    for (int i = 0; i < n; i++) {
        if (!deque.isEmpty() && deque.peek() == i - k) deque.poll();
        while (!deque.isEmpty() && nums[deque.peekLast()] < nums[i]) deque.pollLast();
        deque.offer(i);
        if (i >= k - 1) {
            res[i + 1 - k] = nums[deque.peek()];
        }
    }
    return res;
}
 
开发者ID:xy1m,项目名称:PlayGround,代码行数:15,代码来源:MaxSlidingWindow.java


注:本文中的java.util.Deque.offer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。