本文整理汇总了Java中com.google.common.primitives.UnsignedInts类的典型用法代码示例。如果您正苦于以下问题:Java UnsignedInts类的具体用法?Java UnsignedInts怎么用?Java UnsignedInts使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnsignedInts类属于com.google.common.primitives包,在下文中一共展示了UnsignedInts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: of
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
/**
* get an OFGroup object corresponding to a raw 32-bit integer group number.
* NOTE: The group object may either be newly allocated or cached. Do not
* rely on either behavior.
*
* @param groupNumber the raw 32-bit group number
* @return a corresponding OFPort
*/
public static OFGroup of(final int groupNumber) {
switch(groupNumber) {
case ZERO_VAL:
return MAX;
case MAX_VAL:
return MAX;
case ALL_VAL:
return ALL;
case ANY_VAL:
return ANY;
default:
if(UnsignedInts.compare(groupNumber, MAX_VAL) > 0) {
// greater than max_val, but not one of the reserved values
throw new IllegalArgumentException("Unknown special group number: "
+ groupNumber);
}
return new OFGroup(groupNumber);
}
}
示例2: getDefaultInstance
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
public static BgpSetMedType getDefaultInstance(final java.lang.String defaultValue) {
final Matcher ipv4Matcher = MED_TYPE_STRING_PATTERN.matcher(defaultValue);
if (ipv4Matcher.matches()) {
return new BgpSetMedType(defaultValue);
} else {
try {
final long parseUnsignedInt = UnsignedInts.parseUnsignedInt(defaultValue);
return new BgpSetMedType(parseUnsignedInt);
} catch (final NumberFormatException e) {
try {
final Enumeration medTypeEnum = BgpSetMedType.Enumeration.valueOf(defaultValue.toUpperCase());
return new BgpSetMedType(medTypeEnum);
} catch(final IllegalArgumentException e1) {
throw new IllegalArgumentException("Cannot create BgpSetMedType from " + defaultValue);
}
}
}
}
示例3: handleValidStoreMsg
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
@Override
protected void handleValidStoreMsg(PB.DHTTopLevelMsg.Builder topLevelResponseMsg, PB.DHTStoreValueMsg storeValueMsg) throws Exception {
if(storeValueMsg.hasSignature()==false){
throw new Exception("The store message "+storeValueMsg+" does not have a signature");
}
if(storeValueMsg.hasKey()==false){
throw new Exception("The store message "+storeValueMsg+" does not have a key");
}
if(storeValueMsg.hasValue()==false){
throw new Exception("The store message "+storeValueMsg+" does not have a value");
}
final byte[] key=storeValueMsg.getKey().toByteArray();
final byte[] value=storeValueMsg.getValue().toByteArray();
if(key.length!=32){
throw new Exception("The store message "+storeValueMsg+" does not have a key of proper length");
}
if(storeValueMsg.hasNonce()==false){
throw new Exception("Nonce is missing "+storeValueMsg);
}
final long nonceInMessage=UnsignedInts.toLong(storeValueMsg.getNonce());
if(isTransactionValid(storeValueMsg)){
storeKeyValue(key, value, nonceInMessage);
}
//TODO Add status message?
}
示例4: of
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
/**
* get an OFGroup object corresponding to a raw 32-bit integer group number.
* NOTE: The group object may either be newly allocated or cached. Do not
* rely on either behavior.
*
* @param groupNumber the raw 32-bit group number
* @return a corresponding OFPort
*/
public static OFGroup of(final int groupNumber) {
switch(groupNumber) {
case ZERO_VAL:
return ZERO;
case MAX_VAL:
return MAX;
case ALL_VAL:
return ALL;
case ANY_VAL:
return ANY;
default:
if(UnsignedInts.compare(groupNumber, MAX_VAL) > 0) {
// greater than max_val, but not one of the reserved values
throw new IllegalArgumentException("Unknown special group number: "
+ groupNumber);
}
return new OFGroup(groupNumber);
}
}
示例5: createTriggerByGlassTrigger
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
private void createTriggerByGlassTrigger(Class<?> clazz, GlassTrigger glassTrigger) throws Exception {
GlassTriggerFactoryBean factoryBean = new GlassTriggerFactoryBean();
if (StringUtils.isBlank(glassTrigger.name())) {
factoryBean.setName("[email protected]" + UnsignedInts.toString(UUID.randomUUID().hashCode()));
} else {
factoryBean.setName(glassTrigger.name());
}
factoryBean.setGroup(glassTrigger.group());
factoryBean.setJobClass(clazz);
factoryBean.setTriggerDataMap(glassTrigger.triggerDataMap());
factoryBean.setScheduler(glassTrigger.scheduler());
factoryBean.setStartDelay(glassTrigger.startDelay());
beanFactory.autowireBean(factoryBean);
factoryBean.afterPropertiesSet();
}
示例6: parseRecord
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
protected UserEventRecord parseRecord(byte[] recordBytes, DatabasePageHeader header,
long recordNumber) throws IOException {
DataInput input = this.dataInputFactory.create(new ByteArrayInputStream(recordBytes));
LOGGER.debug(format("Parsing user event record from bytes [%s]...", toHexString(recordBytes)));
long systemSeconds = UnsignedInts.toLong(input.readInt());
long displaySeconds = UnsignedInts.toLong(input.readInt());
UserEventRecord.UserEventType eventType = UserEventRecord.UserEventType.fromId(input.readByte());
byte eventSubType = input.readByte();
long eventLocalTimeInSeconds = UnsignedInts.toLong(input.readInt());
long eventValue = UnsignedInts.toLong(input.readInt());
int actualReceiverCrc = input.readUnsignedShort();
validateCrc(actualReceiverCrc, recordBytes);
UserEventRecord userEventRecord = new UserEventRecord(systemSeconds, displaySeconds,
eventLocalTimeInSeconds, eventType, eventSubType, eventValue);
LOGGER.debug(format("Parsed UserEventRecord: [%s]", userEventRecord));
return userEventRecord;
}
示例7: getManufacturingParameters
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
public List<ManufacturingParameters> getManufacturingParameters() {
List<ManufacturingParameters> manufacturingParameters = newArrayList();
try {
for (DatabasePage page : getPages()) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(page.getPageData());
DataInput input = this.dataInputFactory.create(inputStream);
// TODO: something better than ignoring the data?
long systemSeconds = UnsignedInts.toLong(input.readInt());
long displaySeconds = UnsignedInts.toLong(input.readInt());
byte[] xmlBytes = new byte[inputStream.available() - 2];
input.readFully(xmlBytes);
validateCrc(input.readUnsignedShort(), page.getPageData());
XmlMapper xmlMapper = new XmlMapper();
ManufacturingParameters parameterPage = xmlMapper.readValue(new String(xmlBytes, "UTF-8"),
ManufacturingParameters.class);
manufacturingParameters.add(parameterPage);
}
return manufacturingParameters;
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
开发者ID:alexandre-normand,项目名称:blood-shepherd,代码行数:26,代码来源:ManufacturingDataDatabasePagesResponse.java
示例8: parseRecord
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
protected GlucoseReadRecord parseRecord(byte[] recordBytes, DatabasePageHeader header,
long recordNumber) throws IOException {
DataInput input = this.dataInputFactory.create(new ByteArrayInputStream(recordBytes));
LOGGER.debug(format("Parsing glucose record from bytes [%s]", toHexString(recordBytes)));
long systemSeconds = UnsignedInts.toLong(input.readInt());
long displaySeconds = UnsignedInts.toLong(input.readInt());
int glucoseValueWithFlags = input.readUnsignedShort();
byte trendAndArrowNoise = input.readByte();
int actualReceiverCrc = input.readUnsignedShort();
validateCrc(actualReceiverCrc, recordBytes);
GlucoseReadRecord glucoseReadRecord = new GlucoseReadRecord(systemSeconds, displaySeconds,
glucoseValueWithFlags, trendAndArrowNoise, recordNumber, header.getPageNumber());
LOGGER.debug(format("Parsed GlucoseRead: [%s]", glucoseReadRecord));
return glucoseReadRecord;
}
示例9: checkChecksum
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
public static boolean checkChecksum(byte[] bytes) {
if ((bytes == null) || (bytes.length < 4)) return false;
final CRC32 crc = new CRC32();
crc.update(bytes, 0, bytes.length - 4);
final long buffer_crc = UnsignedInts.toLong(ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getInt(bytes.length - 4));
return buffer_crc == crc.getValue();
}
示例10: data
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
/** The entry data. */
public byte[] data() {
// Read the offset and variable lengths from the central directory and then try to map in the
// data section in one shot.
long offset = UnsignedInts.toLong(cd.getInt(cdindex + CENOFF));
int nameLength = cd.getChar(cdindex + CENNAM);
int extLength = cd.getChar(cdindex + CENEXT);
int compression = cd.getChar(cdindex + CENHOW);
switch (compression) {
case 0x8:
return getBytes(
offset,
nameLength,
extLength,
UnsignedInts.toLong(cd.getInt(cdindex + CENSIZ)),
/*deflate=*/ true);
case 0x0:
return getBytes(
offset,
nameLength,
extLength,
UnsignedInts.toLong(cd.getInt(cdindex + CENLEN)),
/*deflate=*/ false);
default:
throw new AssertionError(
String.format("unsupported compression mode: 0x%x", compression));
}
}
示例11: extract
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
@Override
public <C> SpanContext extract(C carrier, Getter<C> getter) throws SpanContextParseException {
checkNotNull(carrier, "carrier");
checkNotNull(getter, "getter");
try {
String headerStr = getter.get(carrier, HEADER_NAME);
if (headerStr == null || headerStr.length() < MIN_HEADER_SIZE) {
throw new SpanContextParseException("Missing or too short header: " + HEADER_NAME);
}
checkArgument(headerStr.charAt(TRACE_ID_SIZE) == SPAN_ID_DELIMITER, "Invalid TRACE_ID size");
TraceId traceId = TraceId.fromLowerBase16(headerStr.subSequence(0, TRACE_ID_SIZE));
int traceOptionsPos = headerStr.indexOf(TRACE_OPTION_DELIMITER, SPAN_ID_DELIMITER);
CharSequence spanIdStr =
headerStr.subSequence(
SPAN_ID_START_POS, traceOptionsPos < 0 ? headerStr.length() : traceOptionsPos);
SpanId spanId = longToSpanId(UnsignedLongs.parseUnsignedLong(spanIdStr.toString(), 10));
TraceOptions traceOptions = OPTIONS_NOT_SAMPLED;
if (traceOptionsPos > 0) {
String traceOptionsStr = headerStr.substring(traceOptionsPos + TRACE_OPTION_DELIMITER_SIZE);
if ((UnsignedInts.parseUnsignedInt(traceOptionsStr, 10) & CLOUD_TRACE_IS_SAMPLED) != 0) {
traceOptions = OPTIONS_SAMPLED;
}
}
return SpanContext.create(traceId, spanId, traceOptions);
} catch (IllegalArgumentException e) {
throw new SpanContextParseException("Invalid input", e);
}
}
示例12: apply
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
@Override
public Optional<String> apply(String sql) {
checkNotNull(sql);
final String lowerCasedSql = sql.toLowerCase();
Collection<Pair<String, Integer>> keywordPositions =
Collections2.transform(
SQL_STATEMENT_KEYWORDS,
new Function<String, Pair<String, Integer>>() {
@Override
public Pair<String, Integer> apply(String input) {
checkNotNull(input);
return new Pair(input, lowerCasedSql.indexOf(input));
}
});
Pair<String, Integer> firstKeyword =
Collections.min(
keywordPositions,
new Comparator<Pair<String, Integer>>() {
@Override
public int compare(Pair<String, Integer> o1, Pair<String, Integer> o2) {
return UnsignedInts.compare(o1.second, o2.second);
}
});
if (firstKeyword.second >= 0) {
return Optional.of(firstKeyword.first + " <...>");
} else {
return Optional.of("<...>");
}
}
示例13: createValidatorSignature
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
public static String createValidatorSignature(Method method) {
String sig = sig(method.getReturnType(), method.getParameterTypes());
String methodValidatorSignature =
method.getDeclaringClass().getName()
+ StringUtils.capitalize(method.getName())
+ UnsignedInts.toString(sig.hashCode());
return methodValidatorSignature;
}
示例14: findReplicationSetSizes
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
private static Set<Integer> findReplicationSetSizes(LookupTable lut) {
Set<Integer> sizes = new TreeSet<Integer>();
for (Map.Entry<ByteBuffer, ImmutableMap<String, String>> e : lut.schemas().metaData.entrySet()) {
ByteBuffer id = e.getKey();
ImmutableMap<String, String> meta = e.getValue();
String rfS = J6.orDefault(meta.get("rfactor"), "3");
Integer rf = Integer.parseInt(rfS);
String forceMasterS = J6.orDefault(meta.get("forceMaster"), "false");
boolean forceMaster = Boolean.parseBoolean(forceMasterS);
if (forceMaster) { // they better all have the same rfactor or weird things are going to happen^^
lut.setMasterRepSize(rf);
}
sizes.add(rf);
if (UnsignedInts.remainder(rf, 2) == 0) {
BootstrapServer.LOG.warn("Schema {} uses a replication factor of {}. "
+ "It is recommended to use uneven factors.",
lut.schemas().schemaNames.get(id), rf);
}
if (rf < 3) {
throw new RuntimeException("Replication factor for any schema must be >=3!");
}
if (rf > lut.hosts().size()) {
throw new RuntimeException("Replication factor for any schema can't be larger than the initial number of hosts!"
+ "If you think you have enough hosts for rf=" + rf + " consider incrementing the value of caraca.bootThreshold.");
}
}
if (lut.getMasterRepSize() < 0) { // in case there are no forceMaster schemata
lut.setMasterRepSize(3);
}
return sizes;
}
示例15: writeShortest
import com.google.common.primitives.UnsignedInts; //导入依赖的package包/类
/**
* Given the integer values, this method instead of writing the value
* in 4B field, compresses the value to lowest required byte field
* depending on the value.
*
* @param value integer to be written
* @param buffer ByteBuf where the value will be written
*/
public static void writeShortest(final int value, final ByteBuf buffer) {
if (value <= Values.UNSIGNED_BYTE_MAX_VALUE) {
buffer.writeByte(UnsignedBytes.checkedCast(value));
} else if (value <= Values.UNSIGNED_SHORT_MAX_VALUE) {
ByteBufWriteUtil.writeUnsignedShort(value, buffer);
} else if (value <= Values.UNSIGNED_INT_MAX_VALUE) {
ByteBufWriteUtil.writeUnsignedInt(UnsignedInts.toLong(value), buffer);
} else {
buffer.writeLong(value);
}
}