]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/test/java/org/rocksdb/PlatformRandomHelper.java
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
8 import java
.util
.Random
;
11 * Helper class to get the appropriate Random class instance dependent
12 * on the current platform architecture (32bit vs 64bit)
14 public class PlatformRandomHelper
{
16 * Determine if OS is 32-Bit/64-Bit
18 * @return boolean value indicating if operating system is 64 Bit.
20 public static boolean isOs64Bit(){
21 final boolean is64Bit
;
22 if (System
.getProperty("os.name").contains("Windows")) {
23 is64Bit
= (System
.getenv("ProgramFiles(x86)") != null);
25 is64Bit
= (System
.getProperty("os.arch").contains("64"));
31 * Factory to get a platform specific Random instance
33 * @return {@link java.util.Random} instance.
35 public static Random
getPlatformSpecificRandomFactory(){
39 return new Random32Bit();
43 * Random32Bit is a class which overrides {@code nextLong} to
44 * provide random numbers which fit in size_t. This workaround
45 * is necessary because there is no unsigned_int < Java 8
47 private static class Random32Bit
extends Random
{
49 public long nextLong(){
50 return this.nextInt(Integer
.MAX_VALUE
);
55 * Utility class constructor
57 private PlatformRandomHelper() { }