gpt4 book ai didi

com.metamx.common.guava.Yielder类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 09:53:31 27 4
gpt4 key购买 nike

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

Yielder介绍

[英]A Yielder is an object that tries to act like the yield() command/continuations in other languages. It's not necessarily good at this job, but it works. I think. Essentially, you can think of a Yielder as a linked list of items where the Yielder gives you access to the current head via get() and it will give you another Yielder representing the next item in the chain via next(). A Yielder that isDone() may return anything from both get() and next(), there is no contract and depending on those return values will likely lead to bugs. Once next is called, there is no guarantee and no requirement that references to old Yielder objects will continue to obey the contract. Yielders are Closeable and must be closed in order to prevent resource leaks. Once close() is called, the behavior of the whole chain of Yielders is undefined.
[中]Yielder是一个试图像其他语言中的yield()命令/continuations那样工作的对象。它不一定擅长这项工作,但它很管用。我想。本质上,你可以把一个Yielder看作是一个项目的链表,Yielder通过get()让你访问当前头部,它会给你另一个Yielder,通过next()代表链中的下一个项目。如果isDone()可能同时返回get()和next()中的任何内容,则没有约定,根据这些返回值可能会导致错误。一旦调用next,就不能保证也不要求对老Yielder对象的引用将继续遵守合同。YiElder是可关闭的,必须关闭,以防止资源泄漏。一旦调用close(),整个数据链的行为就没有定义。

代码示例

代码示例来源:origin: com.n3twork.druid/druid-common

@Override
 public void close() throws IOException
 {
  yielder.close();
 }
};

代码示例来源:origin: com.metamx/java-util

@Override
public T get()
{
 return baseYielder.get();
}

代码示例来源:origin: metamx/java-util

@Override
public boolean isDone()
{
 return baseYielder.isDone();
}

代码示例来源:origin: com.metamx/java-util

public <OutType> Yielder<OutType> makeYielder(
  Yielder<Sequence<T>> yielderYielder,
  OutType initValue,
  YieldingAccumulator<OutType, T> accumulator
)
{
 if (yielderYielder.isDone()) {
  return Yielders.done(initValue, yielderYielder);
 }
 while (!yielderYielder.isDone()) {
  Yielder<OutType> yielder = yielderYielder.get().toYielder(initValue, accumulator);
  if (accumulator.yielded()) {
   return wrapYielder(yielder, yielderYielder, accumulator);
  }
  initValue = yielder.get();
  try {
   yielder.close();
  }
  catch (IOException e) {
   throw Throwables.propagate(e);
  }
  yielderYielder = yielderYielder.next(null);
 }
 return Yielders.done(initValue, yielderYielder);
}

代码示例来源:origin: metamx/java-util

OutType nextInit = yielder.get();
try {
 yielder.close();
return makeYielder(yielderYielder.next(null), nextInit, accumulator);

代码示例来源:origin: com.n3twork.druid/druid-common

@Override
public Yielder<OutType> next(OutType outType)
{
 T nextIn = yielder.get();
 combiningAccumulator.setRetVal(outType);
 final Yielder<T> baseYielder = yielder.next(nextIn);
 if (baseYielder.isDone()) {
  final OutType outValue = combiningAccumulator.getAccumulator().accumulate(outType, baseYielder.get());
  return Yielders.done(outValue, baseYielder);
 }
 return makeYielder(baseYielder, combiningAccumulator);
}

代码示例来源:origin: com.metamx/java-util

@Override
 public PriorityQueue<Yielder<T>> accumulate(PriorityQueue<Yielder<T>> queue, Sequence<T> in)
 {
  final Yielder<T> yielder = in.toYielder(
    null,
    new YieldingAccumulator<T, T>()
    {
     @Override
     public T accumulate(T accumulated, T in)
     {
      yield();
      return in;
     }
    }
  );
  if (!yielder.isDone()) {
   queue.add(yielder);
  } else {
   try {
    yielder.close();
   }
   catch (IOException e) {
    throw Throwables.propagate(e);
   }
  }
  return queue;
 }
}

代码示例来源:origin: metamx/java-util

@Override
public Yielder<OutType> next(OutType initValue)
{
 return wrapYielder(yielder.next(initValue), yielderYielder, accumulator);
}

代码示例来源:origin: metamx/java-util

Assert.assertEquals(9, yielder.get().intValue());
yielder.close();
Assert.assertEquals(2, closedCount[0]);

代码示例来源:origin: metamx/java-util

public <OutType> Yielder<OutType> makeYielder(
  Yielder<Sequence<T>> yielderYielder,
  OutType initValue,
  YieldingAccumulator<OutType, T> accumulator
)
{
 if (yielderYielder.isDone()) {
  return Yielders.done(initValue, yielderYielder);
 }
 while (!yielderYielder.isDone()) {
  Yielder<OutType> yielder = yielderYielder.get().toYielder(initValue, accumulator);
  if (accumulator.yielded()) {
   return wrapYielder(yielder, yielderYielder, accumulator);
  }
  initValue = yielder.get();
  try {
   yielder.close();
  }
  catch (IOException e) {
   throw Throwables.propagate(e);
  }
  yielderYielder = yielderYielder.next(null);
 }
 return Yielders.done(initValue, yielderYielder);
}

代码示例来源:origin: com.metamx/java-util

OutType nextInit = yielder.get();
try {
 yielder.close();
return makeYielder(yielderYielder.next(null), nextInit, accumulator);

代码示例来源:origin: metamx/java-util

@Override
 public PriorityQueue<Yielder<T>> accumulate(PriorityQueue<Yielder<T>> queue, Sequence<T> in)
 {
  final Yielder<T> yielder = in.toYielder(
    null,
    new YieldingAccumulator<T, T>()
    {
     @Override
     public T accumulate(T accumulated, T in)
     {
      yield();
      return in;
     }
    }
  );
  if (!yielder.isDone()) {
   queue.add(yielder);
  } else {
   try {
    yielder.close();
   }
   catch (IOException e) {
    throw Throwables.propagate(e);
   }
  }
  return queue;
 }
}

代码示例来源:origin: com.metamx/java-util

@Override
public Yielder<OutType> next(OutType initValue)
{
 return wrapYielder(yielder.next(initValue), accumulator);
}

代码示例来源:origin: com.n3twork.druid/druid-common

while (!accumulator.yielded() && (!pQueue.isEmpty() || !oldDudeAtCrosswalk.isDone())) {
 Yielder<T> yielder;
 if (oldDudeAtCrosswalk.isDone()) {
  yielder = pQueue.remove();
  yielder = oldDudeAtCrosswalk.get();
  oldDudeAtCrosswalk = oldDudeAtCrosswalk.next(null);
  Yielder<T> iterYielder = oldDudeAtCrosswalk.get();
  if (ordering.compare(queueYielder.get(), iterYielder.get()) <= 0) {
   yielder = pQueue.remove();
   yielder = oldDudeAtCrosswalk.get();
   oldDudeAtCrosswalk = oldDudeAtCrosswalk.next(null);
 retVal = accumulator.accumulate(retVal, yielder.get());
 yielder = yielder.next(null);
 if (yielder.isDone()) {
  try {
   yielder.close();

代码示例来源:origin: com.metamx/java-util

@Override
public OutType get()
{
 return yielder.get();
}

代码示例来源:origin: com.metamx/java-util

@Override
 public void close() throws IOException
 {
  yielder.close();
  yielderYielder.close();
 }
};

代码示例来源:origin: com.n3twork.druid/druid-common

@Override
 public Yielder<T> accumulate(Yielder<T> accumulated, Sequence<T> in)
 {
  final Yielder<T> retVal = in.toYielder(
    null,
    new YieldingAccumulator<T, T>()
    {
     @Override
     public T accumulate(T accumulated, T in)
     {
      yield();
      return in;
     }
    }
  );
  if (retVal.isDone()) {
   try {
    retVal.close();
   }
   catch (IOException e) {
    throw Throwables.propagate(e);
   }
   return null;
  }
  else {
   yield();
  }
  return retVal;
 }
}

代码示例来源:origin: com.metamx/java-util

@Override
public boolean isDone()
{
 return baseYielder.isDone();
}

代码示例来源:origin: metamx/java-util

@Override
public Yielder<OutType> next(OutType initValue)
{
 return wrapYielder(yielder.next(initValue), accumulator);
}

代码示例来源:origin: metamx/java-util

while (!accumulator.yielded() && !pQueue.isEmpty()) {
 Yielder<T> yielder = pQueue.remove();
 retVal = accumulator.accumulate(retVal, yielder.get());
 yielder = yielder.next(null);
 if (yielder.isDone()) {
  try {
   yielder.close();

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com