当前位置: 首页>>代码示例>>Java>>正文


Java RangeMap类代码示例

本文整理汇总了Java中com.google.common.collect.RangeMap的典型用法代码示例。如果您正苦于以下问题:Java RangeMap类的具体用法?Java RangeMap怎么用?Java RangeMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RangeMap类属于com.google.common.collect包,在下文中一共展示了RangeMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRecipes

import com.google.common.collect.RangeMap; //导入依赖的package包/类
protected List<Recipe> getRecipes(FeatureWrapper feature, Collection<Pickle> pickles) {
	int pickleCount = pickles.size();
	ArrayList<Recipe> recipes = Lists.newArrayListWithExpectedSize(pickleCount);
	Set<Integer> pickleLines = Sets.newHashSetWithExpectedSize(pickleCount);

	RangeMap<Integer, ScenarioDefinition> rangeMap = getRangeMap(feature);
	for (Pickle pickle : pickles) {
		List<PickleLocation> locations = pickle.getLocations();
		for (PickleLocation location : locations) {
			int line = location.getLine();
			if (!pickleLines.contains(line)) {
				pickleLines.add(line);
				Range<Integer> range = Range.singleton(line);
				RangeMap<Integer, ScenarioDefinition> subRangeMap = rangeMap.subRangeMap(range);
				Map<Range<Integer>, ScenarioDefinition> asMap = subRangeMap.asMapOfRanges();
				checkState(1 == asMap.size(), "no single range found encompassing PickleLocation %s", location);
				ScenarioDefinition definition = Iterables.getOnlyElement(asMap.values());
				Recipe recipe = new Recipe(feature, pickle, location, definition);
				recipes.add(recipe);
			}
		}
	}
	return recipes;
}
 
开发者ID:qas-guru,项目名称:martini-core,代码行数:25,代码来源:DefaultMixology.java

示例2: getRangeMap

import com.google.common.collect.RangeMap; //导入依赖的package包/类
protected RangeMap<Integer, ScenarioDefinition> getRangeMap(FeatureWrapper feature) {
	List<ScenarioDefinition> children = Lists.newArrayList(feature.getChildren());

	ImmutableRangeMap.Builder<Integer, ScenarioDefinition> builder = ImmutableRangeMap.builder();
	while (!children.isEmpty()) {
		ScenarioDefinition child = children.remove(0);
		Location location = child.getLocation();
		Integer childStart = location.getLine();

		ScenarioDefinition sibling = children.isEmpty() ? null : children.get(0);
		Location siblingLocation = null == sibling ? null : sibling.getLocation();
		Integer siblingStart = null == siblingLocation ? null : siblingLocation.getLine();

		Range<Integer> range = null == siblingStart ? Range.atLeast(childStart) : Range.closedOpen(childStart, siblingStart);
		builder.put(range, child);
	}
	return builder.build();
}
 
开发者ID:qas-guru,项目名称:martini-core,代码行数:19,代码来源:DefaultMixology.java

示例3: update

import com.google.common.collect.RangeMap; //导入依赖的package包/类
@Override
public synchronized void update(Fragment fragment) {
  RangeMap<RangeValue, String> ranges = getRanges(fragment.getSegmentId());
  Map.Entry<Range<RangeValue>, String> entry = ranges.getEntry(RangeValue.of(fragment.getStartVersion()));
  if (entry != null) {
      Preconditions.checkArgument(entry.getValue().equals(fragment.getBlock().getBlockId()),
      "New range overlaps an existing by block Id");
    Preconditions.checkArgument(fragment.getStartVersion() == entry.getKey().lowerEndpoint().get(),
      "New range overlaps an existing by start version");
    entry.getKey().upperEndpoint().set(fragment.isLast() ? Long.MAX_VALUE : fragment.getLastModifiedVersion());
  } else {
    ranges.put(Range.closed(RangeValue.of(fragment.getStartVersion()),
      RangeValue.of(fragment.isLast() ? Long.MAX_VALUE : fragment.getLastModifiedVersion())),
      fragment.getBlock().getBlockId());
  }
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:17,代码来源:BlockIndexImpl.java

示例4: getRanges

import com.google.common.collect.RangeMap; //导入依赖的package包/类
private RangeMap<RangeValue, String> getRanges(SegmentId segmentId) {
  RangeMap<RangeValue, String> ranges = rangeMap.getIfPresent(segmentId);
  if (ranges == null) {
    try {
      ranges = rangeMap.get(segmentId);
      if (serialized != null) {
        int index = serialized.getSegmentIdList().indexOf(segmentId.serialize());
        if (index != -1) {
          SegmentRanges serializedRanges = serialized.getSegmentRanges(index);
          for (ByteString serializedFragment : serializedRanges.getRawFragmentRangesList()) {
            ProtoBlockIndex.BlockIndex.FragmentRange fragment =
                ProtoBlockIndex.BlockIndex.FragmentRange.parseFrom(serializedFragment);
            ranges.put(Range.closed(RangeValue.of(fragment.getSourceVersion()),
                RangeValue.of(fragment.getTargetVersion())), fragment.getBlockId());
          }
        }
      }
    } catch (ExecutionException | InvalidProtocolBufferException ex) {
      throw new RuntimeException(ex);
    }
  }
  return ranges;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:24,代码来源:BlockIndexImpl.java

示例5: addHeadersToSheet

import com.google.common.collect.RangeMap; //导入依赖的package包/类
/**
 * Ajoute les en-têtes dans la feuille de calcul et cache les colonnes qui doivent l'être.
 * 
 * @param sheet feuille de calcul
 * @param rowIndex numéro de la ligne
 * @param columnInfos RangeMap contenant les informations de colonnes (valeurs) et les index sur auxquelles s'appliquent ces colonnes (clés).
 *                    Les "colonnes" s'étendant sur plus d'un index seront automatiquement fusionnées.
 */
protected void addHeadersToSheet(Sheet sheet, int rowIndex, RangeMap<Integer, ColumnInformation> columnInfos) {
	Row rowHeader = sheet.createRow(rowIndex);
	for (Map.Entry<Range<Integer>, ColumnInformation> entry : columnInfos.asMapOfRanges().entrySet()) {
		Range<Integer> range = entry.getKey();
		ColumnInformation columnInformation = entry.getValue();
		
		addHeaderCell(rowHeader, range.lowerEndpoint(), getColumnLabel(columnInformation.getHeaderKey()));
		
		for (Integer columnIndex : ContiguousSet.create(range, DiscreteDomain.integers())) {
			sheet.setColumnHidden(columnIndex, columnInformation.isHidden());
		}
		
		int beginIndex = range.lowerEndpoint();
		int endIndex = range.upperEndpoint();
		if (beginIndex != endIndex) {
			sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, beginIndex, endIndex));
		}
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:28,代码来源:AbstractExcelTableExport.java

示例6: computeBmp

import com.google.common.collect.RangeMap; //导入依赖的package包/类
private void computeBmp(RangeMap<Integer, Short> fullMap) {
    for (Map.Entry<Range<Integer>, Short> me : fullMap.asMapOfRanges().entrySet()) {
        Range<Integer> range = me.getKey();
        int min = range.lowerEndpoint();
        if (range.lowerBoundType() == BoundType.OPEN) {
            min++;
        }
        if (min < Character.MAX_VALUE) {
            int rmax = range.upperEndpoint();
            if (range.upperBoundType() == BoundType.OPEN) {
                rmax--;
            }
            int max = Math.min(Character.MAX_VALUE, rmax);
            for (int x = min; x <= max; x++) {
                this.bmpMap[x] = me.getValue();
            }
        }
    }
}
 
开发者ID:basis-technology-corp,项目名称:tcl-regex-java,代码行数:20,代码来源:RuntimeColorMap.java

示例7: parseDiscretize

import com.google.common.collect.RangeMap; //导入依赖的package包/类
static
private RangeMap<Double, String> parseDiscretize(Discretize discretize){
	RangeMap<Double, String> result = TreeRangeMap.create();

	List<DiscretizeBin> discretizeBins = discretize.getDiscretizeBins();
	for(DiscretizeBin discretizeBin : discretizeBins){
		Interval interval = discretizeBin.getInterval();
		if(interval == null){
			throw new MissingAttributeException(discretizeBin, PMMLAttributes.DISCRETIZEBIN_INTERVAL);
		}

		Range<Double> range = toRange(interval);

		String binValue = discretizeBin.getBinValue();
		if(binValue == null){
			throw new MissingAttributeException(discretizeBin, PMMLAttributes.DISCRETIZEBIN_BINVALUE);
		}

		result.put(range, binValue);
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:24,代码来源:DiscretizationUtil.java

示例8: 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);
	}
 
开发者ID:leveluplunch,项目名称:levelup-java-exercises,代码行数:26,代码来源:BankCharges.java

示例9: 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);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:14,代码来源:Renewable.java

示例10: 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
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:14,代码来源:InputIndentationFromGuava2.java

示例11: serialize

import com.google.common.collect.RangeMap; //导入依赖的package包/类
@Override
public synchronized ProtoBlockIndex.BlockIndex serialize() {
  ProtoBlockIndex.BlockIndex.Builder builder = ProtoBlockIndex.BlockIndex.newBuilder();
  builder.setFormatVersion(FORMAT_VERSION);
  if (serialized != null) {
    for (int i=0; i < serialized.getSegmentIdCount(); i++) {
      SegmentId segmentId = SegmentId.of(serialized.getSegmentId(i));
      if (rangeMap.getIfPresent(segmentId) == null) {
        builder.addSegmentId(serialized.getSegmentId(i));
        builder.addSegmentRanges(serialized.getSegmentRanges(i));
      }
    }
  }
  for (Map.Entry<SegmentId, RangeMap<RangeValue, String>> segmentEntry : rangeMap.asMap().entrySet()) {
    builder.addSegmentId(segmentEntry.getKey().toString());
    SegmentRanges.Builder rangesBuilder = builder.addSegmentRangesBuilder();
    Map<Range<RangeValue>, String> mapOfRanges = segmentEntry.getValue().asMapOfRanges();
    for (Map.Entry<Range<RangeValue>, String> range : mapOfRanges.entrySet()) {
      ProtoBlockIndex.BlockIndex.FragmentRange.Builder fragmentBuilder = ProtoBlockIndex.BlockIndex.FragmentRange.newBuilder();
      fragmentBuilder.setSourceVersion(range.getKey().lowerEndpoint().get());
      fragmentBuilder.setTargetVersion(range.getKey().upperEndpoint().get());
      fragmentBuilder.setBlockId(range.getValue());
      rangesBuilder.addRawFragmentRanges(fragmentBuilder.build().toByteString());
    }
  }
  Preconditions.checkArgument(lastModifiedVersion.getVersion() != 0 || rangeMap.asMap().isEmpty(),
      "Last modified version is 0 but range map is not empty");
  builder.setLastModifiedVersion(OperationSerializer.serialize(lastModifiedVersion));
  builder.setLastModifiedTime(lastModifiedTime);
  builder.setConsistent(consistent);
  return builder.build();
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:33,代码来源:BlockIndexImpl.java

示例12: 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);
        }
    }
}
 
开发者ID:johnlee175,项目名称:dex,代码行数:34,代码来源:Opcodes.java

示例13: finalizeSheet

import com.google.common.collect.RangeMap; //导入依赖的package包/类
/**
 * Finalise la création de la feuille de calcul, notamment en demandant le
 * redimensionnement automatique des colonnes.
 * 
 * @param sheet feuilles de calcul
 * @param columnInfos collection contenant les informations de colonnes
 * @param landscapePrintSetup définit si la feuille est imprimée en paysage ou non
 */
protected void finalizeSheet(Sheet sheet, Collection<ColumnInformation> columnInfos, boolean landscapePrintSetup) {
	RangeMap<Integer, ColumnInformation> map = TreeRangeMap.create();
	int index = 0;
	for (ColumnInformation column : columnInfos) {
		map.put(Range.singleton(index), column);
		++index;
	}
	finalizeSheet(sheet, map, landscapePrintSetup);
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:18,代码来源:AbstractExcelTableExport.java

示例14: setDynamismLevels

import com.google.common.collect.RangeMap; //导入依赖的package包/类
/**
 * Sets the dynamism levels.
 * @param levels At least one level must be given. The default level is
 *          <code>.5</code>.
 * @return This, as per the builder pattern.
 */
public Builder setDynamismLevels(Iterable<Double> levels) {
  checkArgument(Iterables.size(levels) > 0);
  final RangeSet<Double> rangeSet = TreeRangeSet.create();
  final Set<Range<Double>> dynamismLevelsB = new LinkedHashSet<>();
  final RangeMap<Double, Double> map = TreeRangeMap.create();
  for (final Double d : levels) {
    checkArgument(d >= 0d && d <= 1d);
    final Range<Double> newRange = createDynRange(d);
    checkArgument(
      rangeSet.subRangeSet(newRange).isEmpty(),
      "Can not add dynamism level %s, it is too close to another level.",
      d);
    rangeSet.add(newRange);
    dynamismLevelsB.add(newRange);
    map.put(newRange, d);
  }

  final SetMultimap<TimeSeriesType, Range<Double>> timeSeriesTypes =
    LinkedHashMultimap
      .<TimeSeriesType, Range<Double>>create();

  for (final Range<Double> r : dynamismLevelsB) {
    checkArgument(DYNAMISM_MAP.get(r.lowerEndpoint()) != null);
    checkArgument(DYNAMISM_MAP.get(r.lowerEndpoint()) == DYNAMISM_MAP.get(r
      .upperEndpoint()));

    timeSeriesTypes.put(DYNAMISM_MAP.get(r.lowerEndpoint()), r);
  }
  dynamismLevels = ImmutableSetMultimap.copyOf(timeSeriesTypes);
  dynamismRangeMap = ImmutableRangeMap.copyOf(map);
  return this;
}
 
开发者ID:rinde,项目名称:pdptw-dataset-generator,代码行数:39,代码来源:DatasetGenerator.java

示例15: addReplacement

import com.google.common.collect.RangeMap; //导入依赖的package包/类
private void addReplacement(Replacement replacement) {
  checkNotNull(replacement);
  Range<Integer> range = Range.closedOpen(replacement.startPosition, replacement.endPosition);

  RangeMap<Integer, Replacement> overlaps = replacements.subRangeMap(range);
  checkArgument(overlaps.asMapOfRanges().isEmpty(), "Replacement %s overlaps with %s",
      replacement, overlaps);

  replacements.put(range, replacement);
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:11,代码来源:DescriptionBasedDiff.java


注:本文中的com.google.common.collect.RangeMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。