當前位置: 首頁>>代碼示例>>Java>>正文


Java LongSupplier.getAsLong方法代碼示例

本文整理匯總了Java中java.util.function.LongSupplier.getAsLong方法的典型用法代碼示例。如果您正苦於以下問題:Java LongSupplier.getAsLong方法的具體用法?Java LongSupplier.getAsLong怎麽用?Java LongSupplier.getAsLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.function.LongSupplier的用法示例。


在下文中一共展示了LongSupplier.getAsLong方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parse

import java.util.function.LongSupplier; //導入方法依賴的package包/類
public long parse(String text, LongSupplier now, boolean roundUp, DateTimeZone timeZone) {
    long time;
    String mathString;
    if (text.startsWith("now")) {
        try {
            time = now.getAsLong();
        } catch (Exception e) {
            throw new ElasticsearchParseException("could not read the current timestamp", e);
        }
        mathString = text.substring("now".length());
    } else {
        int index = text.indexOf("||");
        if (index == -1) {
            return parseDateTime(text, timeZone, roundUp);
        }
        time = parseDateTime(text.substring(0, index), timeZone, false);
        mathString = text.substring(index + 2);
    }

    return parseMath(mathString, time, roundUp, timeZone);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:DateMathParser.java

示例2: of

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/**
 * Create a new {@code Random64} instance, where the random numbers are
 * generated by the given long {@code supplier}.
 *
 * @param supplier the random number supplier
 * @return a new {@code Random64} instance
 * @throws java.lang.NullPointerException if the given {@code supplier} is
 *         {@code null}.
 */
public static Random64 of(final LongSupplier supplier) {
	Objects.requireNonNull(supplier);

	return new Random64() {
		private static final long serialVersionUID = 1L;

		private final Boolean _sentry = Boolean.TRUE;

		@Override
		public long nextLong() {
			return supplier.getAsLong();
		}

		@Override
		public void setSeed(final long seed) {
			if (_sentry != null) {
				throw new UnsupportedOperationException(
					"The 'setSeed(long)' method is not supported."
				);
			}
		}
	};
}
 
開發者ID:jenetics,項目名稱:prngine,代碼行數:33,代碼來源:Random64.java

示例3: from

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/** Creates a `Box.Long` from a `LongSupplier` and a `LongConsumer`. */
public static Lng from(LongSupplier getter, LongConsumer setter) {
	return new Lng() {
		@Override
		public long getAsLong() {
			return getter.getAsLong();
		}

		@Override
		public void set(long value) {
			setter.accept(value);
		}

		@Override
		public String toString() {
			return "Box.Long.from[" + get() + "]";
		}
	};
}
 
開發者ID:diffplug,項目名稱:durian,代碼行數:20,代碼來源:Box.java

示例4: send2Queue

import java.util.function.LongSupplier; //導入方法依賴的package包/類
public void send2Queue(Path inputFile, int batchSize, LongSupplier sleep) throws IOException, InterruptedException {
    BlockingQueue<String> dataQueue = new ArrayBlockingQueue<>(10000);
    for (int i = 0; i < 3; i++) {
        new PushThread(dataQueue).start();
    }
    try (BufferedReader reader = Files.newBufferedReader(inputFile)) {
        String line;
        int batchCnt = 0;
        while ((line = reader.readLine()) != null) {
            dataQueue.put(processData(line));
            if (++batchCnt == batchSize) {
                batchCnt = 0;
                long ms = sleep.getAsLong();
                if (ms > 0) {
                    Utils.sleep(ms);
                }
            }
        }
    } finally {
        dataQueue.put(END);
    }
}
 
開發者ID:ADSC-Resa,項目名稱:resa,代碼行數:23,代碼來源:DataSender.java

示例5: send2Queue

import java.util.function.LongSupplier; //導入方法依賴的package包/類
public void send2Queue(Path inputFile, LongSupplier sleep) throws IOException {
    Jedis jedis = new Jedis(host, port);
    int counter = 0;
    try (BufferedReader reader = Files.newBufferedReader(inputFile)) {
        String line = null;
        while (line != null || (line = reader.readLine()) != null) {
            long ms = sleep.getAsLong();
            if (ms > 0) {
                Utils.sleep(ms);
            }
            if (jedis.llen(queueName) < maxPaddingSize) {
                String data = counter++ + "|" + System.currentTimeMillis() + "|" + line;
                jedis.rpush(queueName, data);
                line = null;
            }
        }
    } finally {
        jedis.quit();
    }
}
 
開發者ID:ADSC-Resa,項目名稱:resa,代碼行數:21,代碼來源:DataSenderWithTS.java

示例6: create

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/**
 * <p>Creates a binding using the passed supplier and list of dependencies.</p>
 *
 * <p>Note that this method requires manual implementation of the respective binding logic. For
 * most cases, however, the static methods provided by this interface do suffice however and
 * require far less manually programmed logic.</p>
 */
@Nonnull
static LongBinding create(@Nonnull LongSupplier supplier,
    ReadOnlyObservable<?>... observables) {
  return new AbstractLongBinding(new HashSet<>(Arrays.asList(observables))) {
    @Override
    protected Long compute() {
      return supplier.getAsLong();
    }
  };
}
 
開發者ID:Torchmind,項目名稱:Observables,代碼行數:18,代碼來源:LongBinding.java

示例7: waitFor

import java.util.function.LongSupplier; //導入方法依賴的package包/類
@SuppressWarnings("UnusedAssignment") //for availableSequence
@Override
public long waitFor(long sequence, LongSupplier cursorSequence, Runnable barrier)
        throws InterruptedException
{
    long availableSequence;
    if ((availableSequence = cursorSequence.getAsLong()) < sequence)
    {
        lock.lock();
        try
        {
            while ((availableSequence = cursorSequence.getAsLong()) < sequence)
            {
                barrier.run();
                processorNotifyCondition.await();
            }
        }
        finally
        {
            lock.unlock();
        }
    }

    while ((availableSequence = cursorSequence.getAsLong()) < sequence)
    {
        barrier.run();
    }

    return availableSequence;
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:31,代碼來源:WaitStrategy.java

示例8: waitRequestOrTerminalEvent

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/**
 * Spin CPU until the request {@link LongSupplier} is populated at least once by a
 * strict positive value. To relieve the spin loop, the read sequence itself will be
 * used against so it will wake up only when a signal is emitted upstream or other
 * stopping condition including terminal signals thrown by the {@link
 * RingBuffer.Reader} waiting barrier.
 *
 * @param pendingRequest the {@link LongSupplier} request to observe
 * @param barrier {@link RingBuffer.Reader} to wait on
 * @param isRunning {@link AtomicBoolean} calling loop running state
 * @param nextSequence {@link LongSupplier} ring buffer read cursor
 * @param waiter an optional extra spin observer for the wait strategy in {@link
 * RingBuffer.Reader}
 *
 * @return true if a request has been received, false in any other case.
 */
static boolean waitRequestOrTerminalEvent(LongSupplier pendingRequest,
		RingBuffer.Reader barrier,
		AtomicBoolean isRunning,
		LongSupplier nextSequence,
		Runnable waiter) {
	try {
		long waitedSequence;
		while (pendingRequest.getAsLong() <= 0L) {
			//pause until first request
			waitedSequence = nextSequence.getAsLong() + 1;
			waiter.run();
			barrier.waitFor(waitedSequence, waiter);

			if (!isRunning.get()) {
				WaitStrategy.alert();
			}
			LockSupport.parkNanos(1L);
		}
	}
	catch (InterruptedException ie) {
		Thread.currentThread()
		      .interrupt();
	}

	catch (Exception e) {
		if (!isRunning.get() || WaitStrategy.isAlert(e)) {
			return false;
		}
		throw e;
	}

	return true;
}
 
開發者ID:reactor,項目名稱:reactor-core,代碼行數:50,代碼來源:EventLoopProcessor.java

示例9: F

import java.util.function.LongSupplier; //導入方法依賴的package包/類
F(LongSupplier longSupplier) {
    this((Supplier<R>) new Supplier<Long>() {
        @Override
        public Long get() {
            return longSupplier.getAsLong();
        }
    });
}
 
開發者ID:codebulb,項目名稱:LambdaOmega,代碼行數:9,代碼來源:F.java

示例10: getOrCompute

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/**
 * This method will return the value for the specified key if it is cached,
 * and if not, will calculate the value using the supplied method. The
 * computed value may or may not be stored in the cache afterwards. This
 * method is guaranteed to be lock-free, and might calculate the value
 * instead of using the cached one to avoid blocking.
 *
 * @param key      the key to retrieve the value for
 * @param compute  method to use to compute the value if it is not cached
 * @return         the cached or computed value
 */
public long getOrCompute(K key, LongSupplier compute) {
    if (free.compareAndSet(true, false)) {
        try {
            return cache.computeIfAbsent(key, k -> compute.getAsLong());
        } finally {
            free.set(true);
        }
    } else {
        return compute.getAsLong();
    }
}
 
開發者ID:speedment,項目名稱:speedment,代碼行數:23,代碼來源:LongCache.java

示例11: countHelper

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/**
 * Optimizer for count operations.
 *
 * @param <ENTITY> the entity type
 * @param info about the stream optimizer
 * @param sqlStreamTerminator that called us
 * @param pipeline the pipeline
 * @param fallbackSupplier a fallback supplier should every item be size
 * retaining
 * @return the number of rows
 */
public static <ENTITY> long countHelper(
    final SqlStreamOptimizerInfo<ENTITY> info,
    final SqlStreamTerminator<ENTITY> sqlStreamTerminator,
    final Pipeline pipeline,
    final LongSupplier fallbackSupplier
) {
    requireNonNull(info);
    requireNonNull(sqlStreamTerminator);
    requireNonNull(pipeline);
    requireNonNull(fallbackSupplier);

    // Can we count it directly (with no sub-select query)?
    if (pipeline.stream().allMatch(PRESERVE_SIZE)) {
        return info.getCounter().applyAsLong(info.getSqlSelectCount(), emptyList());
    } else {

        final Pipeline optimizedPipeline = sqlStreamTerminator.optimize(pipeline);
        // Can we count using a sub-select query?
        if (optimizedPipeline.stream().allMatch(PRESERVE_SIZE)) {
            final AsynchronousQueryResult<ENTITY> asynchronousQueryResult = sqlStreamTerminator.getAsynchronousQueryResult();
            final StringBuilder sql = new StringBuilder()
                .append("SELECT COUNT(*) FROM (")
                .append(asynchronousQueryResult.getSql())
                .append(")");

            if (info.getDbmsType().getSubSelectAlias() == SubSelectAlias.REQUIRED) {
                sql.append(" AS A");
            }
            @SuppressWarnings("unchecked")
            final List<Object> values = (List<Object>) asynchronousQueryResult.getValues();
            return info.getCounter().applyAsLong(sql.toString(), values);
        } else {
            // Iterate over all materialized ENTITIES....
            return fallbackSupplier.getAsLong();
        }
    }
}
 
開發者ID:speedment,項目名稱:speedment,代碼行數:49,代碼來源:CountUtil.java

示例12: readLocked

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/**
 * Execute the provided callable in a read lock.
 *
 * @param aSupplier
 *        Callable to be executed. May not be <code>null</code>.
 * @return The return value of the callable. May be <code>null</code>.
 */
public long readLocked (@Nonnull final LongSupplier aSupplier)
{
  readLock ().lock ();
  try
  {
    return aSupplier.getAsLong ();
  }
  finally
  {
    readLock ().unlock ();
  }
}
 
開發者ID:phax,項目名稱:ph-commons,代碼行數:20,代碼來源:SimpleReadWriteLock.java

示例13: writeLocked

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/**
 * Execute the provided callable in a write lock.
 *
 * @param aSupplier
 *        Callable to be executed. May not be <code>null</code>.
 * @return The return value of the callable. May be <code>null</code>.
 */
public long writeLocked (@Nonnull final LongSupplier aSupplier)
{
  writeLock ().lock ();
  try
  {
    return aSupplier.getAsLong ();
  }
  finally
  {
    writeLock ().unlock ();
  }
}
 
開發者ID:phax,項目名稱:ph-commons,代碼行數:20,代碼來源:SimpleReadWriteLock.java

示例14: locked

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/**
 * Execute the provided callable in a read lock.
 *
 * @param aSupplier
 *        Callable to be executed. May not be <code>null</code>.
 * @return The return value of the callable. May be <code>null</code>.
 */
public long locked (@Nonnull final LongSupplier aSupplier)
{
  ValueEnforcer.notNull (aSupplier, "Supplier");

  lock ();
  try
  {
    return aSupplier.getAsLong ();
  }
  finally
  {
    unlock ();
  }
}
 
開發者ID:phax,項目名稱:ph-commons,代碼行數:22,代碼來源:SimpleLock.java

示例15: getLong

import java.util.function.LongSupplier; //導入方法依賴的package包/類
/**
 * Get the long value associated with the given key, using the given supplier to obtain a default value if there is no such
 * key-value pair.
 * 
 * @param key the key for the configuration property
 * @param defaultValueSupplier the supplier for the default value; may be null
 * @return the long value, or null if the key is null, there is no such key-value pair in the configuration, the
 *         {@code defaultValueSupplier} reference is null, or there is a key-value pair in the configuration but the value
 *         could not be parsed as a long
 */
default public Long getLong(String key, LongSupplier defaultValueSupplier) {
    String value = getString(key);
    if (value != null) {
        try {
            return Long.parseLong(value);
        } catch (NumberFormatException e) {
        }
    }
    return defaultValueSupplier != null ? defaultValueSupplier.getAsLong() : null;
}
 
開發者ID:rhauch,項目名稱:debezium-proto,代碼行數:21,代碼來源:Configuration.java


注:本文中的java.util.function.LongSupplier.getAsLong方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。