本文整理汇总了Java中com.google.common.collect.RangeMap.get方法的典型用法代码示例。如果您正苦于以下问题:Java RangeMap.get方法的具体用法?Java RangeMap.get怎么用?Java RangeMap.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.RangeMap
的用法示例。
在下文中一共展示了RangeMap.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
public static void main(String[] args) {
// define rages for checks
RangeMap<Integer, Double> checkFee = TreeRangeMap.create();
checkFee.put(Range.closed(0, 19), .1);
checkFee.put(Range.closed(20, 39), .8);
checkFee.put(Range.closed(40, 59), .6);
checkFee.put(Range.closed(60, Integer.MAX_VALUE), .4);
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get the number of checks written.
System.out.print("Enter the number of checks written " + "this month: ");
int numChecks = keyboard.nextInt();
//close scanner
keyboard.close();
// calculate total fee
double total = BASE_FEE + (checkFee.get(numChecks) * numChecks);
// Display the total bank fees.
System.out.printf("The total fees are $%.2f\n", total);
}
示例2: chooseShuffledMaterial
import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
MaterialData chooseShuffledMaterial() {
ImmutableRangeMap.Builder<Double, MaterialData> weightsBuilder = ImmutableRangeMap.builder();
double sum = 0d;
for(MaterialData material : shuffleableMaterialDeficit.materials()) {
double weight = shuffleableMaterialDeficit.get(material);
if(weight > 0) {
weightsBuilder.put(Range.closedOpen(sum, sum + weight), material);
sum += weight;
}
}
RangeMap<Double, MaterialData> weights = weightsBuilder.build();
return weights.get(match.getRandom().nextDouble() * sum);
}
示例3: get
import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
public V get(int index) { //indent:2 exp:2
K key = null; //indent:4 exp:4
int len = 0; //indent:4 exp:4
checkElementIndex(index, len); //indent:4 exp:4
int off; //indent:4 exp:4
RangeMap<K, V> ranges = null; //indent:4 exp:4
if (index == 0 || index == len - 1) { //indent:4 exp:4
Object range; //indent:6 exp:6
return ranges.get(key); //indent:6 exp:6
} else { //indent:4 exp:4
return ranges.get(key); //indent:6 exp:6
} //indent:4 exp:4
}
示例4: Opcodes
import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
private Opcodes(int api, int artVersion, boolean experimental) {
this.api = api;
this.artVersion = artVersion;
opcodeValues = new EnumMap<Opcode, Short>(Opcode.class);
opcodesByName = Maps.newHashMap();
int version;
if (isArt()) {
version = artVersion;
} else {
version = api;
}
for (Opcode opcode: Opcode.values()) {
RangeMap<Integer, Short> versionToValueMap;
if (isArt()) {
versionToValueMap = opcode.artVersionToValueMap;
} else {
versionToValueMap = opcode.apiToValueMap;
}
Short opcodeValue = versionToValueMap.get(version);
if (opcodeValue != null && (!opcode.isExperimental() || experimental)) {
if (!opcode.format.isPayloadFormat) {
opcodesByValue[opcodeValue] = opcode;
}
opcodeValues.put(opcode, opcodeValue);
opcodesByName.put(opcode.name.toLowerCase(), opcode);
}
}
}
示例5: google_guava_range_map_example
import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
@Test
public void google_guava_range_map_example () {
RangeMap<Integer, String> gradeScale = TreeRangeMap.create();
gradeScale.put(Range.closed(0, 60), "F");
gradeScale.put(Range.closed(61, 70), "D");
gradeScale.put(Range.closed(71, 80), "C");
gradeScale.put(Range.closed(81, 90), "B");
gradeScale.put(Range.closed(91, 100), "A");
String grade = gradeScale.get(77);
assertEquals("C", grade);
}
示例6: Opcodes
import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
private Opcodes(int api, int artVersion) {
if (api >= 21) {
this.api = api;
this.artVersion = mapApiToArtVersion(api);
} else if (artVersion >= 0 && artVersion < 39) {
this.api = mapArtVersionToApi(artVersion);
this.artVersion = artVersion;
} else {
this.api = api;
this.artVersion = artVersion;
}
opcodeValues = new EnumMap<Opcode, Short>(Opcode.class);
opcodesByName = Maps.newHashMap();
int version;
if (isArt()) {
version = this.artVersion;
} else {
version = this.api;
}
for (Opcode opcode: Opcode.values()) {
RangeMap<Integer, Short> versionToValueMap;
if (isArt()) {
versionToValueMap = opcode.artVersionToValueMap;
} else {
versionToValueMap = opcode.apiToValueMap;
}
Short opcodeValue = versionToValueMap.get(version);
if (opcodeValue != null) {
if (!opcode.format.isPayloadFormat) {
opcodesByValue[opcodeValue] = opcode;
}
opcodeValues.put(opcode, opcodeValue);
opcodesByName.put(opcode.name.toLowerCase(), opcode);
}
}
}
示例7: getSpeedLimit
import com.google.common.collect.RangeMap; //导入方法依赖的package包/类
private Double getSpeedLimit(RangeMap<Long, Double> rangeMap) {
return rangeMap.get(timeProvider.getSimTimeInDayRange());
}