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


Java Longs類代碼示例

本文整理匯總了Java中com.google.common.primitives.Longs的典型用法代碼示例。如果您正苦於以下問題:Java Longs類的具體用法?Java Longs怎麽用?Java Longs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: rename

import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
        fileLength) {
    long blockSize = 0;
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        Pipeline pipelined = jedis.pipelined();
        //add new file length
        pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
        //add new file content
        blockSize = getBlockSize(fileLength);
        for (int i = 0; i < blockSize; i++) {
            pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
        }
        values.clear();
        pipelined.sync();
    } finally {
        jedis.close();
        deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
    }
}
 
開發者ID:shijiebei2009,項目名稱:RedisDirectory,代碼行數:23,代碼來源:JedisPoolStream.java

示例2: updateCommitted

import com.google.common.primitives.Longs; //導入依賴的package包/類
/**
 * Find the median value of the list of matchIndex, this value is the committedIndex since, by definition, half of the
 * matchIndex values are greater and half are less than this value. So, at least half of the replicas have stored the
 * median value, this is the definition of committed.
 */
private void updateCommitted() {

    List<ReplicaManager> sorted = newArrayList(managers.values());
    Collections.sort(sorted, new Comparator<ReplicaManager>() {
        @Override
        public int compare(ReplicaManager o, ReplicaManager o2) {
            return Longs.compare(o.getMatchIndex(), o2.getMatchIndex());
        }
    });

    final int middle = (int) Math.ceil(sorted.size() / 2.0);
    final long committed = sorted.get(middle).getMatchIndex();
    log.updateCommitIndex(committed);

    SortedMap<Long, SettableFuture<Boolean>> entries = requests.headMap(committed + 1);
    for (SettableFuture<Boolean> f : entries.values()) {
        f.set(true);
    }

    entries.clear();

}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:28,代碼來源:Leader.java

示例3: renameFile

import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void renameFile(String source, String dest) throws IOException {
    List<byte[]> values = new ArrayList<>();
    //在get的時候不需要加事務
    //在刪除和添加的時候使用事務
    //Get the file length with old file name
    byte[] hget = inputOutputStream.hget(Constants.DIR_METADATA_BYTES, source.getBytes(), FILE_LENGTH);
    long length = Longs.fromByteArray(hget);
    long blockSize = getBlockSize(length);
    for (int i = 0; i < blockSize; i++) {
        //Get the contents with old file name
        byte[] res = inputOutputStream.hget(Constants.FILE_METADATA_BYTES, getBlockName(source, i), FILE_DATA);
        values.add(res);
    }
    inputOutputStream.rename(Constants.DIRECTORY_METADATA, Constants.FILE_METADATA, source, dest, values, length);
    log.debug("Rename file success from {} to {}", source, dest);
}
 
開發者ID:shijiebei2009,項目名稱:RedisDirectory,代碼行數:18,代碼來源:RedisDirectory.java

示例4: saveFile

import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        Pipeline pipelined = jedis.pipelined();
        pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
        Long blockSize = getBlockSize(fileLength);
        for (int i = 0; i < blockSize; i++) {
            pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
            if (i % Constants.SYNC_COUNT == 0) {
                pipelined.sync();
                pipelined = jedis.pipelined();
            }
        }
        values.clear();
        pipelined.sync();
    } finally {
        jedis.close();
    }
}
 
開發者ID:shijiebei2009,項目名稱:RedisDirectory,代碼行數:22,代碼來源:JedisPoolStream.java

示例5: rename

import com.google.common.primitives.Longs; //導入依賴的package包/類
/**
 * Use transactions to add index file and then delete the old one
 *
 * @param fileLengthKey the key using for hash file length
 * @param fileDataKey   the key using for hash file data
 * @param oldField      the old hash field
 * @param newField      the new hash field
 * @param values        the data values of the old hash field
 * @param fileLength    the data length of the old hash field
 */
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
        fileLength) {
    ShardedJedis shardedJedis = getShardedJedis();
    ShardedJedisPipeline pipelined = shardedJedis.pipelined();
    //add new file length
    pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
    //add new file content
    Long blockSize = getBlockSize(fileLength);
    for (int i = 0; i < blockSize; i++) {
        pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
    }
    pipelined.sync();
    shardedJedis.close();
    values.clear();
    deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
 
開發者ID:shijiebei2009,項目名稱:RedisDirectory,代碼行數:28,代碼來源:ShardedJedisPoolStream.java

示例6: saveFile

import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
    ShardedJedis shardedJedis = getShardedJedis();
    ShardedJedisPipeline pipelined = shardedJedis.pipelined();
    pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
    Long blockSize = getBlockSize(fileLength);
    for (int i = 0; i < blockSize; i++) {
        pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
        if (i % Constants.SYNC_COUNT == 0) {
            pipelined.sync();
            pipelined = shardedJedis.pipelined();
        }
    }
    pipelined.sync();
    shardedJedis.close();
    values.clear();
}
 
開發者ID:shijiebei2009,項目名稱:RedisDirectory,代碼行數:18,代碼來源:ShardedJedisPoolStream.java

示例7: rename

import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
        fileLength) {
    Jedis jedis = openJedis();
    Pipeline pipelined = jedis.pipelined();
    //add new file length
    pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
    //add new file content
    Long blockSize = getBlockSize(fileLength);
    for (int i = 0; i < blockSize; i++) {
        pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
    }
    pipelined.sync();
    jedis.close();
    values.clear();
    deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
 
開發者ID:shijiebei2009,項目名稱:RedisDirectory,代碼行數:18,代碼來源:JedisStream.java

示例8: saveFile

import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
    Jedis jedis = openJedis();
    Pipeline pipelined = jedis.pipelined();
    pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
    Long blockSize = getBlockSize(fileLength);
    for (int i = 0; i < blockSize; i++) {
        pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
        if (i % Constants.SYNC_COUNT == 0) {
            pipelined.sync();
            pipelined = jedis.pipelined();
        }
    }
    pipelined.sync();
    jedis.close();
    values.clear();
}
 
開發者ID:shijiebei2009,項目名稱:RedisDirectory,代碼行數:18,代碼來源:JedisStream.java

示例9: ThreadsIterator

import com.google.common.primitives.Longs; //導入依賴的package包/類
public ThreadsIterator(final SabotContext dbContext, final OperatorContext context) {
  this.dbContext = dbContext;
  threadMXBean = ManagementFactory.getThreadMXBean();
  final long[] ids = threadMXBean.getAllThreadIds();

  final Iterator<Long> threadIdIterator = Longs.asList(ids).iterator();

  this.threadInfoIterator = Iterators.filter(
    Iterators.transform(threadIdIterator, new Function<Long, ThreadInfo>() {

      @Override
      public ThreadInfo apply(Long input) {
        return threadMXBean.getThreadInfo(input, 100);
      }
    }),
    Predicates.notNull());

  logger.debug("number of threads = {}, number of cores = {}", ids.length, NUMBER_OF_CORES);

  this.stats = dbContext.getWorkStatsProvider().get();
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:22,代碼來源:ThreadsIterator.java

示例10: compare

import com.google.common.primitives.Longs; //導入依賴的package包/類
/**
 * Compare cells.
 * TODO: Replace with dynamic rather than static comparator so can change comparator
 * implementation.
 * @param a
 * @param b
 * @param ignoreSequenceid True if we are to compare the key portion only and ignore
 * the sequenceid. Set to false to compare key and consider sequenceid.
 * @return 0 if equal, -1 if a &lt; b, and +1 if a &gt; b.
 */
public static int compare(final Cell a, final Cell b, boolean ignoreSequenceid) {
  // row
  int c = compareRows(a, b);
  if (c != 0) return c;

  c = compareWithoutRow(a, b);
  if(c != 0) return c;

  if (!ignoreSequenceid) {
    // Negate following comparisons so later edits show up first
    // mvccVersion: later sorts first
    return Longs.compare(b.getMvccVersion(), a.getMvccVersion());
  } else {
    return c;
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:27,代碼來源:CellComparator.java

示例11: testOneEvent

import com.google.common.primitives.Longs; //導入依賴的package包/類
@Test
public void testOneEvent() throws Exception {
  initContextForSimpleHbaseEventSerializer();
  HBaseSink sink = new HBaseSink(conf);
  Configurables.configure(sink, ctx);
  Channel channel = new MemoryChannel();
  Configurables.configure(channel, new Context());
  sink.setChannel(channel);
  sink.start();
  Transaction tx = channel.getTransaction();
  tx.begin();
  Event e = EventBuilder.withBody(
      Bytes.toBytes(valBase));
  channel.put(e);
  tx.commit();
  tx.close();

  sink.process();
  sink.stop();
  HTable table = new HTable(conf, tableName);
  byte[][] results = getResults(table, 1);
  byte[] out = results[0];
  Assert.assertArrayEquals(e.getBody(), out);
  out = results[1];
  Assert.assertArrayEquals(Longs.toByteArray(1), out);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:27,代碼來源:TestHBaseSink.java

示例12: GabrielGatewayClient

import com.google.common.primitives.Longs; //導入依賴的package包/類
public GabrielGatewayClient(int shardId, Channel channel) throws IOException {
    super(shardId, channel, true);
    channel.queueDeclare("shard-" + shardId + "-getping", false, false, false, null);
    channel.queueDeclare("shard-" + shardId + "-getping-response", false, false, false, null);
    channel.basicConsume("shard-" + shardId + "-getping-response", true, new DefaultConsumer(channel) {
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            long now = System.currentTimeMillis();
            ping = now - Longs.fromByteArray(body);
        }
    });
    calculatePing();
    PING_CALCULATOR.scheduleAtFixedRate(this::calculatePing, 30, 30, TimeUnit.SECONDS);
}
 
開發者ID:natanbc,項目名稱:GabrielBot,代碼行數:15,代碼來源:GabrielGatewayClient.java

示例13: assertErrorsOnLines

import com.google.common.primitives.Longs; //導入依賴的package包/類
/**
 * Asserts that the given diagnostics contain errors with a message containing "[CheckerName]"
 * on the given lines of the given file. If there should be multiple errors on a line, the line
 * number must appear multiple times. There may not be any errors in any other file.
 */
public void assertErrorsOnLines(String file,
    List<Diagnostic<? extends JavaFileObject>> diagnostics, long... lines) {
  ListMultimap<String, Long> actualErrors = ArrayListMultimap.create();
  for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
    String message = diagnostic.getMessage(Locale.US);

    // The source may be null, e.g. for diagnostics about command-line flags
    assertNotNull(message, diagnostic.getSource());
    String sourceName = diagnostic.getSource().getName();

    assertEquals(
        "unexpected error in source file " + sourceName + ": " + message,
        file, sourceName);

    actualErrors.put(diagnostic.getSource().getName(), diagnostic.getLineNumber());

    // any errors from the compiler that are not related to this checker should fail
    assertThat(message).contains("[" + checker.getAnnotation(BugPattern.class).name() + "]");
  }

  assertEquals(
      ImmutableMultiset.copyOf(Longs.asList(lines)),
      ImmutableMultiset.copyOf(actualErrors.get(file)));
}
 
開發者ID:google,項目名稱:guava-beta-checker,代碼行數:30,代碼來源:TestCompiler.java

示例14: toArray

import com.google.common.primitives.Longs; //導入依賴的package包/類
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
    if (componentType == boolean.class) {
        return Booleans.toArray((Collection) values);
    } else if (componentType == byte.class) {
        return Bytes.toArray((Collection) values);
    } else if (componentType == short.class) {
        return Shorts.toArray((Collection) values);
    } else if (componentType == int.class) {
        return Ints.toArray((Collection) values);
    } else if (componentType == long.class) {
        return Longs.toArray((Collection) values);
    } else if (componentType == float.class) {
        return Floats.toArray((Collection) values);
    } else if (componentType == double.class) {
        return Doubles.toArray((Collection) values);
    } else if (componentType == char.class) {
        return Chars.toArray((Collection) values);
    }
    return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
 
開發者ID:TNG,項目名稱:ArchUnit,代碼行數:22,代碼來源:JavaClassProcessor.java

示例15: getValues

import com.google.common.primitives.Longs; //導入依賴的package包/類
static
public List<?> getValues(Tensor tensor){
	DataType dataType = tensor.dataType();

	switch(dataType){
		case FLOAT:
			return Floats.asList(TensorUtil.toFloatArray(tensor));
		case DOUBLE:
			return Doubles.asList(TensorUtil.toDoubleArray(tensor));
		case INT32:
			return Ints.asList(TensorUtil.toIntArray(tensor));
		case INT64:
			return Longs.asList(TensorUtil.toLongArray(tensor));
		case STRING:
			return Arrays.asList(TensorUtil.toStringArray(tensor));
		case BOOL:
			return Booleans.asList(TensorUtil.toBooleanArray(tensor));
		default:
			throw new IllegalArgumentException();
	}
}
 
開發者ID:jpmml,項目名稱:jpmml-tensorflow,代碼行數:22,代碼來源:TensorUtil.java


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