本文整理汇总了Java中com.google.common.primitives.Shorts.checkedCast方法的典型用法代码示例。如果您正苦于以下问题:Java Shorts.checkedCast方法的具体用法?Java Shorts.checkedCast怎么用?Java Shorts.checkedCast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.Shorts
的用法示例。
在下文中一共展示了Shorts.checkedCast方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculatePercentCompletion
import com.google.common.primitives.Shorts; //导入方法依赖的package包/类
/**
* Given a low watermark (starting point) and a high watermark (target), returns the percentage
* of events pulled.
*
* @return a percentage value between 0 and 100.
*/
@Override
public short calculatePercentCompletion(Watermark lowWatermark, Watermark highWatermark) {
Preconditions.checkArgument(
lowWatermark instanceof MultiLongWatermark && highWatermark instanceof MultiLongWatermark,
String.format("Arguments of %s.%s must be of type %s", MultiLongWatermark.class.getSimpleName(),
Thread.currentThread().getStackTrace()[1].getMethodName(), MultiLongWatermark.class.getSimpleName()));
long pulled = ((MultiLongWatermark) lowWatermark).getGap(this);
long all = ((MultiLongWatermark) lowWatermark).getGap((MultiLongWatermark) highWatermark);
Preconditions.checkState(all > 0);
long percent = LongMath.divide(pulled * 100, all, RoundingMode.HALF_UP);
return Shorts.checkedCast(percent);
}
示例2: intToShort
import com.google.common.primitives.Shorts; //导入方法依赖的package包/类
private static Short intToShort(Integer input)
{
if (input == null) {
return null;
}
return Shorts.checkedCast(input);
}
示例3: parseLabelValue
import com.google.common.primitives.Shorts; //导入方法依赖的package包/类
private static LabelValue parseLabelValue(String src) {
List<String> parts =
ImmutableList.copyOf(
Splitter.on(CharMatcher.whitespace()).omitEmptyStrings().limit(2).split(src));
if (parts.isEmpty()) {
throw new IllegalArgumentException("empty value");
}
String valueText = parts.size() > 1 ? parts.get(1) : "";
return new LabelValue(Shorts.checkedCast(PermissionRule.parseInt(parts.get(0))), valueText);
}
示例4: newApproval
import com.google.common.primitives.Shorts; //导入方法依赖的package包/类
public static PatchSetApproval newApproval(
PatchSet.Id psId, CurrentUser user, LabelId labelId, int value, Date when) {
PatchSetApproval psa =
new PatchSetApproval(
new PatchSetApproval.Key(psId, user.getAccountId(), labelId),
Shorts.checkedCast(value),
when);
user.updateRealAccountId(psa::setRealAccountId);
return psa;
}
示例5: Type
import com.google.common.primitives.Shorts; //导入方法依赖的package包/类
Type(int code) {
this.code = Shorts.checkedCast(code);
}
示例6: Type
import com.google.common.primitives.Shorts; //导入方法依赖的package包/类
Type(int code) {
this.code = Shorts.checkedCast(code);
}
示例7: ResChunk
import com.google.common.primitives.Shorts; //导入方法依赖的package包/类
ResChunk(int chunkType, int headerSize, int chunkSize) {
this.type = Shorts.checkedCast(chunkType);
this.headerSize = Shorts.checkedCast(headerSize);
this.chunkSize = chunkSize;
Preconditions.checkState((chunkSize % 4) == 0);
}