java.util.LinkedList.offerFirst()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中java.util.LinkedList.offerFirst()方法的一些代码示例,展示了LinkedList.offerFirst()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LinkedList.offerFirst()方法的具体详情如下:
包路径:java.util.LinkedList
类名称:LinkedList
方法名:offerFirst

LinkedList.offerFirst介绍

[英]Inserts the specified element at the front of this list.
[中]在此列表的前面插入指定的元素。

代码示例

代码示例来源:origin: apache/flink

/**
 * Adds a single input split
 *
 * @param split The input split to add
 */
public void addInputSplit(LocatableInputSplitWithCount split) {
  int localCount = split.getLocalCount();
  if (minLocalCount == -1) {
    // first split to add
    this.minLocalCount = localCount;
    this.elementCycleCount = 1;
    this.splits.offerFirst(split);
  } else if (localCount < minLocalCount) {
    // split with new min local count
    this.nextMinLocalCount = this.minLocalCount;
    this.minLocalCount = localCount;
    // all other splits have more local host than this one
    this.elementCycleCount = 1;
    splits.offerFirst(split);
  } else if (localCount == minLocalCount ) {
    this.elementCycleCount++;
    this.splits.offerFirst(split);
  } else {
    if (localCount < nextMinLocalCount) {
      nextMinLocalCount = localCount;
    }
    splits.offerLast(split);
  }
}

代码示例来源:origin: apache/hbase

@Test
public void testParseOptsMultiPuts() {
 Queue<String> opts = new LinkedList<>();
 String cmdName = "sequentialWrite";
 opts.offer("--multiPut=10");
 opts.offer(cmdName);
 opts.offer("64");
 PerformanceEvaluation.TestOptions options = null;
 try {
  options = PerformanceEvaluation.parseOpts(opts);
  fail("should fail");
 } catch (IllegalArgumentException  e) {
  System.out.println(e.getMessage());
 }
 ((LinkedList<String>) opts).offerFirst("--multiPut=10");
 ((LinkedList<String>) opts).offerFirst("--autoFlush=true");
 options = PerformanceEvaluation.parseOpts(opts);
 assertNotNull(options);
 assertNotNull(options.getCmdName());
 assertEquals(cmdName, options.getCmdName());
 assertTrue(options.getMultiPut() == 10);
}

代码示例来源:origin: apache/hbase

@Test
 public void testParseOptsConnCount() {
  Queue<String> opts = new LinkedList<>();
  String cmdName = "sequentialWrite";
  opts.offer("--oneCon=true");
  opts.offer("--connCount=10");
  opts.offer(cmdName);
  opts.offer("64");
  PerformanceEvaluation.TestOptions options = null;
  try {
   options = PerformanceEvaluation.parseOpts(opts);
   fail("should fail");
  } catch (IllegalArgumentException  e) {
   System.out.println(e.getMessage());
  }
  ((LinkedList<String>) opts).offerFirst("--connCount=10");
  options = PerformanceEvaluation.parseOpts(opts);
  assertNotNull(options);
  assertNotNull(options.getCmdName());
  assertEquals(cmdName, options.getCmdName());
  assertTrue(options.getConnCount() == 10);
 }
}

代码示例来源:origin: com.jtransc/jtransc-rt

@Override
public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException {
  return queue.offerFirst(e);
}

代码示例来源:origin: com.jtransc/jtransc-rt

@Override
public boolean offerFirst(E e) {
  return queue.offerFirst(e);
}

代码示例来源:origin: org.apache.openjpa/openjpa-all

@Override
public boolean offerFirst(Object paramObject) {
  if (_directAccess) {
    return super.offerFirst(paramObject);
  }
  if (isDelayLoad()) {
    load();
  }
  return super.offerFirst(paramObject);
}

代码示例来源:origin: org.apache.openejb.patch/openjpa

@Override
public boolean offerFirst(Object paramObject) {
  if (_directAccess) {
    return super.offerFirst(paramObject);
  }
  if (isDelayLoad()) {
    load();
  }
  return super.offerFirst(paramObject);
}

代码示例来源:origin: org.onehippo.cms7/hippo-cms7-utilities

@Override
public boolean offerFirst(E element) {
  validateCapacityAndPollFirstIfNeeded();
  return super.offerFirst(element);
}

代码示例来源:origin: org.apache.openjpa/openjpa-kernel

@Override
public boolean offerFirst(Object paramObject) {
  if (_directAccess) {
    return super.offerFirst(paramObject);
  }
  if (isDelayLoad()) {
    load();
  }
  return super.offerFirst(paramObject);
}

代码示例来源:origin: uk.org.retep.tools/collections

@Override
public boolean offerFirst( E e )
{
  if( size() >= maxElements )
  {
    return false;
  }
  return super.offerFirst( e );
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-kernel

@Override
public boolean offerFirst(Object paramObject) {
  if (_directAccess) {
    return super.offerFirst(paramObject);
  }
  if (isDelayLoad()) {
    load();
  }
  return super.offerFirst(paramObject);
}

代码示例来源:origin: com.virjar/dungproxy-client

@Override
public boolean offerFirst(T t) {
  lock.lock();
  try {
    boolean ret = super.offerFirst(t);
    notifyIfNotEmpty();
    return ret;
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: stackoverflow.com

public class StreamHistory<T> {

  private final int numberOfElementsToRemember;
  private LinkedList<T> queue = new LinkedList<T>(); // queue will store at most numberOfElementsToRemember

  public StreamHistory(int numberOfElementsToRemember) {
    this.numberOfElementsToRemember = numberOfElementsToRemember;
  }

  public StreamHistory save(T curElem) {

    if (queue.size() == numberOfElementsToRemember) {
      queue.pollLast(); // remove last to keep only requested number of elements
    }

    queue.offerFirst(curElem);

    return this;
  }

  public LinkedList<T> getLastElements() {
    return queue; // or return immutable copy or immutable view on the queue. Depends on what you want.
  }
}

代码示例来源:origin: org.apache.flink/flink-core

/**
 * Adds a single input split
 *
 * @param split The input split to add
 */
public void addInputSplit(LocatableInputSplitWithCount split) {
  int localCount = split.getLocalCount();
  if (minLocalCount == -1) {
    // first split to add
    this.minLocalCount = localCount;
    this.elementCycleCount = 1;
    this.splits.offerFirst(split);
  } else if (localCount < minLocalCount) {
    // split with new min local count
    this.nextMinLocalCount = this.minLocalCount;
    this.minLocalCount = localCount;
    // all other splits have more local host than this one
    this.elementCycleCount = 1;
    splits.offerFirst(split);
  } else if (localCount == minLocalCount ) {
    this.elementCycleCount++;
    this.splits.offerFirst(split);
  } else {
    if (localCount < nextMinLocalCount) {
      nextMinLocalCount = localCount;
    }
    splits.offerLast(split);
  }
}

代码示例来源:origin: stackoverflow.com

offerFirst(curElem);

代码示例来源:origin: stackoverflow.com

offerFirst(curElem);
return this;

代码示例来源:origin: net.digitalid.utility/utility-collections

@Impure
@Override
@NonFrozenRecipient
public boolean offerFirst(@Captured E element) {
  return super.offerFirst(element);
}

代码示例来源:origin: org.apache.hbase/hbase-mapreduce

@Test
public void testParseOptsMultiPuts() {
 Queue<String> opts = new LinkedList<>();
 String cmdName = "sequentialWrite";
 opts.offer("--multiPut=10");
 opts.offer(cmdName);
 opts.offer("64");
 PerformanceEvaluation.TestOptions options = null;
 try {
  options = PerformanceEvaluation.parseOpts(opts);
  fail("should fail");
 } catch (IllegalArgumentException e) {
  System.out.println(e.getMessage());
 }
 ((LinkedList<String>) opts).offerFirst("--multiPut=10");
 ((LinkedList<String>) opts).offerFirst("--autoFlush=true");
 options = PerformanceEvaluation.parseOpts(opts);
 assertNotNull(options);
 assertNotNull(options.getCmdName());
 assertEquals(cmdName, options.getCmdName());
 assertTrue(options.getMultiPut() == 10);
}

代码示例来源:origin: jmacglashan/burlap

trajectory.offerFirst(csh);

代码示例来源:origin: org.apache.hbase/hbase-mapreduce

@Test
 public void testParseOptsConnCount() {
  Queue<String> opts = new LinkedList<>();
  String cmdName = "sequentialWrite";
  opts.offer("--oneCon=true");
  opts.offer("--connCount=10");
  opts.offer(cmdName);
  opts.offer("64");
  PerformanceEvaluation.TestOptions options = null;
  try {
   options = PerformanceEvaluation.parseOpts(opts);
   fail("should fail");
  } catch (IllegalArgumentException e) {
   System.out.println(e.getMessage());
  }
  ((LinkedList<String>) opts).offerFirst("--connCount=10");
  options = PerformanceEvaluation.parseOpts(opts);
  assertNotNull(options);
  assertNotNull(options.getCmdName());
  assertEquals(cmdName, options.getCmdName());
  assertTrue(options.getConnCount() == 10);
 }
}

相关文章

微信公众号

最新文章

更多