下面列出了怎么用java.lang.Long的API类实例代码及写法,或者点击链接到github查看源代码。
public void testCompoundOperators() {
int i = Integer.MAX_VALUE;
i += 1.0;
assertEquals(Integer.MAX_VALUE, i);
i *= 1.5;
assertEquals(Integer.MAX_VALUE, i);
i -= -1.0;
assertEquals(Integer.MAX_VALUE, i);
i /= 0.5;
assertEquals(Integer.MAX_VALUE, i);
long l = Long.MAX_VALUE;
l += 1.0;
assertEquals(Long.MAX_VALUE, l);
l *= 1.5;
assertEquals(Long.MAX_VALUE, l);
l -= -1.0;
assertEquals(Long.MAX_VALUE, l);
l /= 0.5;
assertEquals(Long.MAX_VALUE, l);
}
public void testFloatNarrowing() {
if (System.getProperty("os.arch").equals("armv7")) {
return;
}
float fmin = Float.NEGATIVE_INFINITY;
float fmax = Float.POSITIVE_INFINITY;
assertEquals("fmin as long failed", Long.MIN_VALUE, (long) fmin);
assertEquals("fmax as long failed", Long.MAX_VALUE, (long) fmax);
assertEquals("fmin as int failed", Integer.MIN_VALUE, (int) fmin);
assertEquals("fmax as int failed", Integer.MAX_VALUE, (int) fmax);
assertEquals("fmin as char failed", Character.MIN_VALUE, (char) fmin);
assertEquals("fmax as char failed", Character.MAX_VALUE, (char) fmax);
// Surprising values for shorts and bytes, but that's what's specified.
assertEquals("fmin as short failed", 0, (short) fmin);
assertEquals("fmax as short failed", -1, (short) fmax);
assertEquals("fmin as byte failed", 0, (byte) fmin);
assertEquals("fmax as byte failed", -1, (byte) fmax);
}
/**
* 判断缓存的byte数据是否到期
*
* @param data
* @return true:到期了 false:还没有到期
*/
private static boolean isDue(byte[] data) {
String[] strs = getDateInfoFromDate(data);
if (strs != null && strs.length == 2) {
String saveTimeStr = strs[0];
while (saveTimeStr.startsWith("0")) {
saveTimeStr = saveTimeStr.substring(1, saveTimeStr.length());
}
long saveTime = Long.parseLong(saveTimeStr);
long deleteAfter = Long.parseLong(strs[1]);
if (System.currentTimeMillis() > saveTime + deleteAfter * 1000) {
return true;
}
}
return false;
}
public BgReadingMessage(Long timestamp, Double time_since_sensor_started, Double raw_data, Double filtered_data, Double age_adjusted_raw_value, Boolean calibration_flag, Double calculated_value, Double filtered_calculated_value, Double calculated_value_slope, Double a, Double b, Double c, Double ra, Double rb, Double rc, String uuid, String calibration_uuid, String sensor_uuid, Boolean ignoreforstats, Double raw_calculated, Boolean hide_slope, String noise, ByteString unknownFields) {
super(ADAPTER, unknownFields);
this.timestamp = timestamp;
this.time_since_sensor_started = time_since_sensor_started;
this.raw_data = raw_data;
this.filtered_data = filtered_data;
this.age_adjusted_raw_value = age_adjusted_raw_value;
this.calibration_flag = calibration_flag;
this.calculated_value = calculated_value;
this.filtered_calculated_value = filtered_calculated_value;
this.calculated_value_slope = calculated_value_slope;
this.a = a;
this.b = b;
this.c = c;
this.ra = ra;
this.rb = rb;
this.rc = rc;
this.uuid = uuid;
this.calibration_uuid = calibration_uuid;
this.sensor_uuid = sensor_uuid;
this.ignoreforstats = ignoreforstats;
this.raw_calculated = raw_calculated;
this.hide_slope = hide_slope;
this.noise = noise;
}
public BgReadingMessage(Long timestamp, Double time_since_sensor_started, Double raw_data, Double filtered_data, Double age_adjusted_raw_value, Boolean calibration_flag, Double calculated_value, Double filtered_calculated_value, Double calculated_value_slope, Double a, Double b, Double c, Double ra, Double rb, Double rc, String uuid, String calibration_uuid, String sensor_uuid, Boolean ignoreforstats, Double raw_calculated, Boolean hide_slope, String noise, ByteString unknownFields) {
super(ADAPTER, unknownFields);
this.timestamp = timestamp;
this.time_since_sensor_started = time_since_sensor_started;
this.raw_data = raw_data;
this.filtered_data = filtered_data;
this.age_adjusted_raw_value = age_adjusted_raw_value;
this.calibration_flag = calibration_flag;
this.calculated_value = calculated_value;
this.filtered_calculated_value = filtered_calculated_value;
this.calculated_value_slope = calculated_value_slope;
this.a = a;
this.b = b;
this.c = c;
this.ra = ra;
this.rb = rb;
this.rc = rc;
this.uuid = uuid;
this.calibration_uuid = calibration_uuid;
this.sensor_uuid = sensor_uuid;
this.ignoreforstats = ignoreforstats;
this.raw_calculated = raw_calculated;
this.hide_slope = hide_slope;
this.noise = noise;
}
@Test
public void should_test_observable_interval() {
TestScheduler scheduler = new TestScheduler();
final List<Long> result = new ArrayList<>();
Observable.interval(1, TimeUnit.SECONDS, scheduler)
.take(5)
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
result.add(aLong);
}
});
assertTrue(result.isEmpty());
scheduler.advanceTimeBy(2, TimeUnit.SECONDS);
assertEquals(2, result.size());
scheduler.advanceTimeBy(10, TimeUnit.SECONDS);
assertEquals(5, result.size());
}
/**
* Fetch values for a list of {@link com.rackspacecloud.blueflood.types.Locator}
* from the specified column family and range.
*
* This is a base behavior for most rollup types. IO subclasses can override
* this behavior as they see fit.
*
* @param locators
* @param columnFamily
* @param range
* @return
*/
protected <T extends Object> Table<Locator, Long, T> getValuesForLocators( final List<Locator> locators,
String columnFamily,
Range range ) {
Table<Locator, Long, T> locatorTimestampRollup = HashBasedTable.create();
Map<Locator, List<ResultSetFuture>> resultSetFuturesMap = selectForLocatorListAndRange(columnFamily, locators, range);
for (Map.Entry<Locator, List<ResultSetFuture>> entry : resultSetFuturesMap.entrySet() ) {
Locator locator = entry.getKey();
List<ResultSetFuture> futures = entry.getValue();
Table<Locator, Long, T> result = toLocatorTimestampValue(futures, locator,
columnFamily,
range);
locatorTimestampRollup.putAll(result);
}
return locatorTimestampRollup;
}
public void testDoubleNarrowing() {
if (System.getProperty("os.arch").equals("armv7")) {
return;
}
double dmin = Double.NEGATIVE_INFINITY;
double dmax = Double.POSITIVE_INFINITY;
assertEquals("dmin as long failed", Long.MIN_VALUE, (long) dmin);
assertEquals("dmax as long failed", Long.MAX_VALUE, (long) dmax);
assertEquals("dmin as int failed", Integer.MIN_VALUE, (int) dmin);
assertEquals("dmax as int failed", Integer.MAX_VALUE, (int) dmax);
assertEquals("dmin as char failed", Character.MIN_VALUE, (char) dmin);
assertEquals("dmax as char failed", Character.MAX_VALUE, (char) dmax);
assertEquals("dmin as short failed", 0, (short) dmin);
assertEquals("dmax as short failed", -1, (short) dmax);
assertEquals("dmin as byte failed", 0, (byte) dmin);
assertEquals("dmax as byte failed", -1, (byte) dmax);
}
/**
* {@inheritDoc}
*/
@Override
@NonNull
public BoxedTypesMethodsConstructorIgnoreNull mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
Boolean field1 = null;
if (!cursor.isNull(cursor.getColumnIndex("field1"))) {
field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1;
}
Short field2 = null;
if (!cursor.isNull(cursor.getColumnIndex("field2"))) {
field2 = cursor.getShort(cursor.getColumnIndex("field2"));
}
Integer field3 = null;
if (!cursor.isNull(cursor.getColumnIndex("field3"))) {
field3 = cursor.getInt(cursor.getColumnIndex("field3"));
}
Long field4 = null;
if (!cursor.isNull(cursor.getColumnIndex("field4"))) {
field4 = cursor.getLong(cursor.getColumnIndex("field4"));
}
Float field5 = null;
if (!cursor.isNull(cursor.getColumnIndex("field5"))) {
field5 = cursor.getFloat(cursor.getColumnIndex("field5"));
}
Double field6 = null;
if (!cursor.isNull(cursor.getColumnIndex("field6"))) {
field6 = cursor.getDouble(cursor.getColumnIndex("field6"));
}
BoxedTypesMethodsConstructorIgnoreNull object = new BoxedTypesMethodsConstructorIgnoreNull(field1, field2, field3, field4, field5, field6);
return object;
}
private AqEscTelemetry(long timeBootMs, int seq, int numMotors, int numInSeq, byte[] escid,
List<Integer> statusAge, byte[] dataVersion, List<Long> data0, List<Long> data1) {
this.timeBootMs = timeBootMs;
this.seq = seq;
this.numMotors = numMotors;
this.numInSeq = numInSeq;
this.escid = escid;
this.statusAge = statusAge;
this.dataVersion = dataVersion;
this.data0 = data0;
this.data1 = data1;
}
/**
* Data bits 1-32 for each ESC.
*/
@MavlinkFieldInfo(
position = 8,
unitSize = 4,
arraySize = 4,
description = "Data bits 1-32 for each ESC."
)
public final List<Long> data0() {
return this.data0;
}
/**
* {@inheritDoc}
*/
@Override
@NonNull
public BoxedTypesPrivateFieldsIgnoreNull mapFromCursor(@NonNull StorIOContentResolver storIOContentResolver, @NonNull Cursor cursor) {
Boolean field1 = null;
if (!cursor.isNull(cursor.getColumnIndex("field1"))) {
field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1;
}
Short field2 = null;
if (!cursor.isNull(cursor.getColumnIndex("field2"))) {
field2 = cursor.getShort(cursor.getColumnIndex("field2"));
}
Integer field3 = null;
if (!cursor.isNull(cursor.getColumnIndex("field3"))) {
field3 = cursor.getInt(cursor.getColumnIndex("field3"));
}
Long field4 = null;
if (!cursor.isNull(cursor.getColumnIndex("field4"))) {
field4 = cursor.getLong(cursor.getColumnIndex("field4"));
}
Float field5 = null;
if (!cursor.isNull(cursor.getColumnIndex("field5"))) {
field5 = cursor.getFloat(cursor.getColumnIndex("field5"));
}
Double field6 = null;
if (!cursor.isNull(cursor.getColumnIndex("field6"))) {
field6 = cursor.getDouble(cursor.getColumnIndex("field6"));
}
BoxedTypesPrivateFieldsIgnoreNull object = new BoxedTypesPrivateFieldsIgnoreNull(field1, field2, field3, field4, field5, field6);
return object;
}
private OnboardComputerStatus(BigInteger timeUsec, long uptime, int type, byte[] cpuCores,
byte[] cpuCombined, byte[] gpuCores, byte[] gpuCombined, int temperatureBoard,
List<Integer> temperatureCore, List<Integer> fanSpeed, long ramUsage, long ramTotal,
List<Long> storageType, List<Long> storageUsage, List<Long> storageTotal,
List<Long> linkType, List<Long> linkTxRate, List<Long> linkRxRate, List<Long> linkTxMax,
List<Long> linkRxMax) {
this.timeUsec = timeUsec;
this.uptime = uptime;
this.type = type;
this.cpuCores = cpuCores;
this.cpuCombined = cpuCombined;
this.gpuCores = gpuCores;
this.gpuCombined = gpuCombined;
this.temperatureBoard = temperatureBoard;
this.temperatureCore = temperatureCore;
this.fanSpeed = fanSpeed;
this.ramUsage = ramUsage;
this.ramTotal = ramTotal;
this.storageType = storageType;
this.storageUsage = storageUsage;
this.storageTotal = storageTotal;
this.linkType = linkType;
this.linkTxRate = linkTxRate;
this.linkRxRate = linkRxRate;
this.linkTxMax = linkTxMax;
this.linkRxMax = linkRxMax;
}
/**
* Storage type: 0: HDD, 1: SSD, 2: EMMC, 3: SD card (non-removable), 4: SD card (removable). A
* value of UINT32_MAX implies the field is unused.
*/
@MavlinkFieldInfo(
position = 14,
unitSize = 4,
arraySize = 4,
description = "Storage type: 0: HDD, 1: SSD, 2: EMMC, 3: SD card (non-removable), 4: SD card (removable). A value of UINT32_MAX implies the field is unused."
)
public final List<Long> storageType() {
return this.storageType;
}
/**
* Total amount of storage space on the component system. A value of UINT32_MAX implies the field
* is unused.
*/
@MavlinkFieldInfo(
position = 16,
unitSize = 4,
arraySize = 4,
description = "Total amount of storage space on the component system. A value of UINT32_MAX implies the field is unused."
)
public final List<Long> storageTotal() {
return this.storageTotal;
}
/**
* Link type: 0-9: UART, 10-19: Wired network, 20-29: Wifi, 30-39: Point-to-point proprietary,
* 40-49: Mesh proprietary
*/
@MavlinkFieldInfo(
position = 17,
unitSize = 4,
arraySize = 6,
description = "Link type: 0-9: UART, 10-19: Wired network, 20-29: Wifi, 30-39: Point-to-point proprietary, 40-49: Mesh proprietary"
)
public final List<Long> linkType() {
return this.linkType;
}
/**
* Network traffic from the component system. A value of UINT32_MAX implies the field is unused.
*/
@MavlinkFieldInfo(
position = 18,
unitSize = 4,
arraySize = 6,
description = "Network traffic from the component system. A value of UINT32_MAX implies the field is unused."
)
public final List<Long> linkTxRate() {
return this.linkTxRate;
}
/**
* Network capacity from the component system. A value of UINT32_MAX implies the field is unused.
*/
@MavlinkFieldInfo(
position = 20,
unitSize = 4,
arraySize = 6,
description = "Network capacity from the component system. A value of UINT32_MAX implies the field is unused."
)
public final List<Long> linkTxMax() {
return this.linkTxMax;
}
/**
* Network capacity to the component system. A value of UINT32_MAX implies the field is unused.
*/
@MavlinkFieldInfo(
position = 21,
unitSize = 4,
arraySize = 6,
description = "Network capacity to the component system. A value of UINT32_MAX implies the field is unused."
)
public final List<Long> linkRxMax() {
return this.linkRxMax;
}
public void testFloatConversions() {
if (System.getProperty("os.arch").equals("armv7")) {
return;
}
Float maxFloat = Float.MAX_VALUE;
assertEquals(Integer.MAX_VALUE, maxFloat.intValue());
assertEquals(Long.MAX_VALUE, maxFloat.longValue());
}
/**
* {@inheritDoc}
*/
@Override
@NonNull
public BoxedTypesPrivateFields mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
Boolean field1 = null;
if (!cursor.isNull(cursor.getColumnIndex("field1"))) {
field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1;
}
Short field2 = null;
if (!cursor.isNull(cursor.getColumnIndex("field2"))) {
field2 = cursor.getShort(cursor.getColumnIndex("field2"));
}
Integer field3 = null;
if (!cursor.isNull(cursor.getColumnIndex("field3"))) {
field3 = cursor.getInt(cursor.getColumnIndex("field3"));
}
Long field4 = null;
if (!cursor.isNull(cursor.getColumnIndex("field4"))) {
field4 = cursor.getLong(cursor.getColumnIndex("field4"));
}
Float field5 = null;
if (!cursor.isNull(cursor.getColumnIndex("field5"))) {
field5 = cursor.getFloat(cursor.getColumnIndex("field5"));
}
Double field6 = null;
if (!cursor.isNull(cursor.getColumnIndex("field6"))) {
field6 = cursor.getDouble(cursor.getColumnIndex("field6"));
}
BoxedTypesPrivateFields object = new BoxedTypesPrivateFields(field1, field2, field3, field4, field5, field6);
return object;
}
private static String createDateInfo(int second) {
String currentTime = Long.toString(System.currentTimeMillis());
while (currentTime.length() < 13) {
currentTime = "0" + currentTime;
}
return currentTime + "-" + second + mSeparator;
}
/** PUT /game/SESSION/GAME/endtime/ENDTIME **/
@RequestMapping(value="/{gameId}/endtime/{endTime}",method=RequestMethod.PUT)
public void setEndTime(@PathVariable String sessionId, @PathVariable String gameId, @PathVariable String endTime) throws SessionNotFoundException, GameNotFoundException, NumberFormatException {
Game game = gameFactory.getGame(sessionId, gameId);
Long seconds = Long.parseLong(endTime);
Date date = new Date(seconds);
game.setEndTime(date);
model.saveGame(game);
}
public BloodTestMessage(Long timestamp, Double mgdl, Long created_timestamp, Long state, String source, String uuid, ByteString unknownFields) {
super(ADAPTER, unknownFields);
this.timestamp = timestamp;
this.mgdl = mgdl;
this.created_timestamp = created_timestamp;
this.state = state;
this.source = source;
this.uuid = uuid;
}
/**
* {@inheritDoc}
*/
@Override
@NonNull
public BoxedTypesPrivateFieldsIgnoreNull mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
Boolean field1 = null;
if (!cursor.isNull(cursor.getColumnIndex("field1"))) {
field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1;
}
Short field2 = null;
if (!cursor.isNull(cursor.getColumnIndex("field2"))) {
field2 = cursor.getShort(cursor.getColumnIndex("field2"));
}
Integer field3 = null;
if (!cursor.isNull(cursor.getColumnIndex("field3"))) {
field3 = cursor.getInt(cursor.getColumnIndex("field3"));
}
Long field4 = null;
if (!cursor.isNull(cursor.getColumnIndex("field4"))) {
field4 = cursor.getLong(cursor.getColumnIndex("field4"));
}
Float field5 = null;
if (!cursor.isNull(cursor.getColumnIndex("field5"))) {
field5 = cursor.getFloat(cursor.getColumnIndex("field5"));
}
Double field6 = null;
if (!cursor.isNull(cursor.getColumnIndex("field6"))) {
field6 = cursor.getDouble(cursor.getColumnIndex("field6"));
}
BoxedTypesPrivateFieldsIgnoreNull object = new BoxedTypesPrivateFieldsIgnoreNull(field1, field2, field3, field4, field5, field6);
return object;
}
public BloodTestMessage(Long timestamp, Double mgdl, Long created_timestamp, Long state, String source, String uuid, ByteString unknownFields) {
super(ADAPTER, unknownFields);
this.timestamp = timestamp;
this.mgdl = mgdl;
this.created_timestamp = created_timestamp;
this.state = state;
this.source = source;
this.uuid = uuid;
}
/**
* {@inheritDoc}
*/
@Override
@NonNull
public BoxedTypesMethodsFactoryMethod mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
Boolean field1 = null;
if (!cursor.isNull(cursor.getColumnIndex("field1"))) {
field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1;
}
Short field2 = null;
if (!cursor.isNull(cursor.getColumnIndex("field2"))) {
field2 = cursor.getShort(cursor.getColumnIndex("field2"));
}
Integer field3 = null;
if (!cursor.isNull(cursor.getColumnIndex("field3"))) {
field3 = cursor.getInt(cursor.getColumnIndex("field3"));
}
Long field4 = null;
if (!cursor.isNull(cursor.getColumnIndex("field4"))) {
field4 = cursor.getLong(cursor.getColumnIndex("field4"));
}
Float field5 = null;
if (!cursor.isNull(cursor.getColumnIndex("field5"))) {
field5 = cursor.getFloat(cursor.getColumnIndex("field5"));
}
Double field6 = null;
if (!cursor.isNull(cursor.getColumnIndex("field6"))) {
field6 = cursor.getDouble(cursor.getColumnIndex("field6"));
}
BoxedTypesMethodsFactoryMethod object = BoxedTypesMethodsFactoryMethod.create(field1, field2, field3, field4, field5, field6);
return object;
}
/**
* {@inheritDoc}
*/
@Override
@NonNull
public BoxedTypesMethodsFactoryMethod mapFromCursor(@NonNull StorIOContentResolver storIOContentResolver, @NonNull Cursor cursor) {
Boolean field1 = null;
if (!cursor.isNull(cursor.getColumnIndex("field1"))) {
field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1;
}
Short field2 = null;
if (!cursor.isNull(cursor.getColumnIndex("field2"))) {
field2 = cursor.getShort(cursor.getColumnIndex("field2"));
}
Integer field3 = null;
if (!cursor.isNull(cursor.getColumnIndex("field3"))) {
field3 = cursor.getInt(cursor.getColumnIndex("field3"));
}
Long field4 = null;
if (!cursor.isNull(cursor.getColumnIndex("field4"))) {
field4 = cursor.getLong(cursor.getColumnIndex("field4"));
}
Float field5 = null;
if (!cursor.isNull(cursor.getColumnIndex("field5"))) {
field5 = cursor.getFloat(cursor.getColumnIndex("field5"));
}
Double field6 = null;
if (!cursor.isNull(cursor.getColumnIndex("field6"))) {
field6 = cursor.getDouble(cursor.getColumnIndex("field6"));
}
BoxedTypesMethodsFactoryMethod object = BoxedTypesMethodsFactoryMethod.create(field1, field2, field3, field4, field5, field6);
return object;
}
private void checkRows(List<Row> actual, long expected[][])
{
List<List<Long>> actualList = new ArrayList<>();
for (Row row : actual)
actualList.add(Arrays.asList(getLong(row, ID1),
getLong(row, ID2)));
List<List<Long>> expectedList = new ArrayList<>();
for (long idPair[] : expected)
expectedList.add(Arrays.asList(idPair[0], idPair[1]));
assertEquals(expectedList, actualList);
}
@Query("select executionPlanZipped from RunningExecutionPlan r where r.id = :exeId")
byte[] getZippedExecutionPlan(@Param("exeId") Long exeId);