• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Range类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getContent

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Override
public Optional<InputStream> getContent(final IRI identifier, final List<Range<Integer>> ranges) {
    requireNonNull(ranges, "Byte ranges may not be null");
    return getFileFromIdentifier(identifier).map(file -> {
        try {
            if (ranges.isEmpty()) {
                return new FileInputStream(file);
            } else {
                final List<InputStream> iss = new ArrayList<>();
                for (final Range<Integer> r : ranges) {
                    final InputStream input = new FileInputStream(file);
                    final long skipped = input.skip(r.getMinimum());
                    LOGGER.debug("Skipped {} bytes", skipped);
                    iss.add(new BoundedInputStream(input, r.getMaximum() - r.getMinimum()));
                }
                return new SequenceInputStream(asEnumeration(iss.iterator()));
            }
        } catch (final IOException ex) {
            throw new UncheckedIOException(ex);
        }
    });
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:23,代码来源:FileBasedBinaryService.java


示例2: getContent

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Override
public Optional<InputStream> getContent(final IRI identifier, final List<Range<Integer>> ranges) {
    requireNonNull(identifier,  NON_NULL_IDENTIFIER);
    requireNonNull(ranges, "Byte ranges may not be null");
    final Response res;
    if (ranges.isEmpty()) {
        res = httpClient.target(identifier.getIRIString()).request().get();
    } else {
        final StringBuilder builder = new StringBuilder();
        ranges.forEach(r -> builder.append(r.getMinimum() + "-" + r.getMaximum()));
        res = httpClient.target(identifier.getIRIString()).request().header("Range", "bytes=" + builder).get();
    }
    LOGGER.info("HTTP GET request to {} returned status {}", identifier, res.getStatus());
    if (res.hasEntity()) {
        return of(res.getEntity()).map(x -> (InputStream) x);
    }
    return empty();
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:19,代码来源:HttpBasedBinaryService.java


示例3: getItemLootInfo

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Override
public Collection<ItemLootInfo> getItemLootInfo()
{
	Collection<ItemLootInfo> itemLoot = new LinkedList<>();
	itemLoot.add(new ItemLootInfo.Builder()
			.itemIdentifier(ItemIdentifiers.SMALL_HP_POTION)
			.chancesOfDropping(1.0f)
			.itemNumberRange(Range.between(1, 2))
			.build());
	itemLoot.add(new ItemLootInfo.Builder()
			.itemIdentifier(ItemIdentifiers.SMALL_MP_POTION)
			.chancesOfDropping(1.0f)
			.itemNumberRange(Range.between(2, 3))
			.build());
	itemLoot.add(new ItemLootInfo.Builder()
			.itemIdentifier(ItemIdentifiers.BLUE_BERRY)
			.chancesOfDropping(1.0f)
			.itemNumberRange(Range.between(2, 3))
			.build());
	return itemLoot;
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:22,代码来源:GreenDragonLootGenerator.java


示例4: getItemLootInfo

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Override
public Collection<ItemLootInfo> getItemLootInfo()
{
	Collection<ItemLootInfo> itemLoot = new LinkedList<>();
	itemLoot.add(new ItemLootInfo.Builder()
			.itemIdentifier(ItemIdentifiers.SMALL_HP_POTION)
			.chancesOfDropping(0.5f)
			.itemNumberRange(Range.between(1, 2))
			.build());
	itemLoot.add(new ItemLootInfo.Builder()
			.itemIdentifier(ItemIdentifiers.SMALL_MP_POTION)
			.chancesOfDropping(0.5f)
			.itemNumberRange(Range.between(2, 3))
			.build());
	itemLoot.add(new ItemLootInfo.Builder()
			.itemIdentifier(ItemIdentifiers.FISH)
			.chancesOfDropping(1.0f)
			.itemNumberRange(Range.between(2, 3))
			.build());
	return itemLoot;
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:22,代码来源:SkeletonLootGenerator.java


示例5: getItemLootInfo

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Override
public Collection<ItemLootInfo> getItemLootInfo()
{
	Collection<ItemLootInfo> itemLoot = new LinkedList<>();
	itemLoot.add(new ItemLootInfo.Builder()
			.itemIdentifier(ItemIdentifiers.SMALL_HP_POTION)
			.chancesOfDropping(0.2f)
			.itemNumberRange(Range.between(1, 2))
			.build());
	itemLoot.add(new ItemLootInfo.Builder()
			.itemIdentifier(ItemIdentifiers.SMALL_MP_POTION)
			.chancesOfDropping(0.2f)
			.itemNumberRange(Range.between(1, 2))
			.build());
	itemLoot.add(new ItemLootInfo.Builder()
			.itemIdentifier(ItemIdentifiers.FISH)
			.chancesOfDropping(0.8f)
			.itemNumberRange(Range.between(2, 3))
			.build());
	return itemLoot;
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:22,代码来源:SnakeLootGenerator.java


示例6: main

import org.apache.commons.lang3.Range; //导入依赖的package包/类
public static void main(String[] args) {
   PayPeriodCalculator wedThruTue = new PayPeriodCalculator(DayOfWeek.WEDNESDAY, DayOfWeek.TUESDAY);

   System.out.println("Wednesday through Tuesday");
   System.out.println(StringUtils.center("-", 75, '-'));
   Range<LocalDateTime> calculation = wedThruTue.calculatePayPeriod(new LocalDateTime(2017, 8, 17, 0, 0, 0));
   System.out.printf("Aug 17 2017 -> %s %s\n", calculation.getMinimum(), calculation.getMaximum());
   calculation = wedThruTue.calculatePayPeriod(new LocalDateTime(2017, 8, 22, 0, 0, 0));
   System.out.printf("Aug 22 2017 -> %s %s\n", calculation.getMinimum(), calculation.getMaximum());
   calculation = wedThruTue.calculatePayPeriod(new LocalDateTime(2017, 7, 4, 0, 0, 0));
   System.out.printf("July 4 2017 -> %s %s\n", calculation.getMinimum(), calculation.getMaximum());

   System.out.println("\nSunday through Saturday");
   System.out.println(StringUtils.center("-", 75, '-'));
   PayPeriodCalculator sunThruSat = new PayPeriodCalculator(DayOfWeek.SUNDAY, DayOfWeek.SATURDAY);
   calculation = sunThruSat.calculatePayPeriod(new LocalDateTime(2017, 8, 17, 0, 0, 0));
   System.out.printf("Aug 17 2017 -> %s %s\n", calculation.getMinimum(), calculation.getMaximum());
   calculation = sunThruSat.calculatePayPeriod(new LocalDateTime(2017, 8, 22, 0, 0, 0));
   System.out.printf("Aug 22 2017 -> %s %s\n", calculation.getMinimum(), calculation.getMaximum());
   calculation = sunThruSat.calculatePayPeriod(new LocalDateTime(2017, 7, 4, 0, 0, 0));
   System.out.printf("July 4 2017 -> %s %s\n", calculation.getMinimum(), calculation.getMaximum());
}
 
开发者ID:developerSid,项目名称:AwesomeJavaLibraryExamples,代码行数:23,代码来源:CalculateOperationalPeriodBasedOnConfigurableDaysOfTheWeek.java


示例7: BuiltContainer

import org.apache.commons.lang3.Range; //导入依赖的package包/类
BuiltContainer(final String name, final EntityPlayer player, final List<IInventory> inventories,
                      final Predicate<EntityPlayer> canInteract, final List<Range<Integer>> playerSlotRange,
                      final List<Range<Integer>> tileSlotRange)
{
    this.player = player;
    this.name = name;

    this.canInteract = canInteract;

    this.playerSlotRanges = playerSlotRange;
    this.tileSlotRanges = tileSlotRange;

    this.inventories = inventories;

    this.inventories.forEach(inventory -> inventory.openInventory(player));
}
 
开发者ID:OPMCorp,项目名称:Qbar,代码行数:17,代码来源:BuiltContainer.java


示例8: getFunctionRange

import org.apache.commons.lang3.Range; //导入依赖的package包/类
private Range<Double> getFunctionRange(String functionName) {
if (functionName.equals(Spherical.FUNCTION_NAME)) {
    return Spherical.range;
} else if (functionName.equals(Schwefel.FUNCTION_NAME)) {
    return Schwefel.range;
} else if (functionName.equals(Ackley.FUNCTION_NAME)) {
    return Ackley.range;
} else if (functionName.equals(Griewangk.FUNCTION_NAME)) {
    return Griewangk.range;
} else if (functionName.equals(Rastrigin.FUNCTION_NAME)) {
    return Rastrigin.range;
} else if (functionName.equals(Rosenbrock.FUNCTION_NAME)) {
    return Rosenbrock.range;
} else {
    return null;
}
   }
 
开发者ID:snjv180,项目名称:CS572,代码行数:18,代码来源:Individual.java


示例9: test

import org.apache.commons.lang3.Range; //导入依赖的package包/类
public State test(String windowSelector, Date now, Optional<Map<String, Object>> config, Assertions... assertions) {

    List<Range<Long>> windowIntervals = WindowProcessor.process(windowSelector).toIntervals(now.getTime());
    String stellarStatement = "PROFILE_WINDOW('" + windowSelector + "', now"
                            + (config.isPresent()?", config":"")
                            + ")";
    Map<String, Object> variables = new HashMap<>();
    variables.put("now", now.getTime());
    if(config.isPresent()) {
      variables.put("config", config.get());
    }
    StellarProcessor stellar = new StellarProcessor();
    List<ProfilePeriod> periods = (List<ProfilePeriod>)stellar.parse( stellarStatement
                                                                    , new DefaultVariableResolver(k -> variables.get(k),k -> variables.containsKey(k))
                                                                    , resolver
                                                                    , context
                                                                    );
    State state = new State(windowIntervals, periods);
    for(Assertions assertion : assertions) {
      Assert.assertTrue(assertion.name(), assertion.test(state));
    }
    return state;
  }
 
开发者ID:apache,项目名称:metron,代码行数:24,代码来源:WindowLookbackTest.java


示例10: testWithOverlap

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Test
public void testWithOverlap() {
  List<Range<Long>> intervals = new ArrayList<Range<Long>>() {{
    add(Range.between(0L, 10L));
    add(Range.between(5L, 30L));
    add(Range.between(40L, 50L));
  }};
  IntervalPredicate<Long> predicate = new IntervalPredicate.Identity(intervals);
  Assert.assertTrue(predicate.test(0L));
  Assert.assertTrue(predicate.test(5L));
  Assert.assertTrue(predicate.test(30L));
  Assert.assertTrue(predicate.test(10L));
  Assert.assertFalse(predicate.test(51L));
  Assert.assertTrue(predicate.test(15L));
  Assert.assertFalse(predicate.test(31L));
  Assert.assertTrue(predicate.test(45L));
}
 
开发者ID:apache,项目名称:metron,代码行数:18,代码来源:IntervalPredicateTest.java


示例11: testDenseWindow

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Test
public void testDenseWindow() {
  for (String text : new String[] {
          "from 2 hours ago to 30 minutes ago"
          ,"starting from 2 hours until 30 minutes"
          ,"starting from 2 hours ago until 30 minutes ago"
          ,"starting from 30 minutes ago until 2 hours ago"
          ,"from 30 minutes ago to 2 hours ago "
  }) {
    Window w = WindowProcessor.process(text);
  /*
  A dense window starting 2 hour ago and continuing until 30 minutes ago
   */
    Date now = new Date();
    List<Range<Long>> intervals = w.toIntervals(now.getTime());
    Assert.assertEquals(1, intervals.size());
    assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(0).getMinimum());
    assertEquals(now.getTime() - TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
  }
}
 
开发者ID:apache,项目名称:metron,代码行数:21,代码来源:WindowProcessorTest.java


示例12: testSparse

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Test
public void testSparse() {
  for(String text : new String[] {
    "30 minute window every 1 hour from 2 hours ago to 30 minutes ago",
    "30 minute window every 1 hour starting from 2 hours ago to 30 minutes ago",
    "30 minute window every 1 hour starting from 2 hours ago until 30 minutes ago",
    "30 minute window for every 1 hour starting from 2 hours ago until 30 minutes ago",
  })
  {
    Window w = WindowProcessor.process(text);
  /*
  A window size of 30 minutes
  Starting 2 hour ago and continuing until 30 minutes ago
  window 1: ( now - 2 hour, now - 2 hour + 30 minutes)
  window 2: (now - 1 hour, now - 1 hour + 30 minutes)
   */
    Date now = new Date();
    List<Range<Long>> intervals = w.toIntervals(now.getTime());
    Assert.assertEquals(2, intervals.size());
    assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(0).getMinimum());
    assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2) + TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
    assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1), intervals.get(1).getMinimum());
    assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1) + TimeUnit.MINUTES.toMillis(30), intervals.get(1).getMaximum());
  }
}
 
开发者ID:apache,项目名称:metron,代码行数:26,代码来源:WindowProcessorTest.java


示例13: testRepeatTilNow

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Test
public void testRepeatTilNow() {
  Window w = WindowProcessor.process("30 minute window every 1 hour from 3 hours ago");
  /*
  A window size of 30 minutes
  Starting 3 hours ago and continuing until now
  window 1: ( now - 3 hour, now - 3 hour + 30 minutes)
  window 2: ( now - 2 hour, now - 2 hour + 30 minutes)
  window 3: ( now - 1 hour, now - 1 hour + 30 minutes)
   */
  Date now = new Date();
  List<Range<Long>> intervals = w.toIntervals(now.getTime());
  Assert.assertEquals(3, intervals.size());

  assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(3), intervals.get(0).getMinimum());
  assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(3) + TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());

  assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(1).getMinimum());
  assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2) + TimeUnit.MINUTES.toMillis(30), intervals.get(1).getMaximum());

  assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1), intervals.get(2).getMinimum());
  assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(1) + TimeUnit.MINUTES.toMillis(30), intervals.get(2).getMaximum());
}
 
开发者ID:apache,项目名称:metron,代码行数:24,代码来源:WindowProcessorTest.java


示例14: UpnpIgdPortMapper

import org.apache.commons.lang3.Range; //导入依赖的package包/类
/**
     * Constructs a {@link UpnpIgdPortMapper} object.
     * @param networkBus network bus
     * @param internalAddress source address (address to communicate with gateway from)
     * @param controlUrl control URL
     * @param serverName sever name (may be {@code null})
     * @param serviceType service type
     * @param externalPortRange external port range
     * @param leaseDurationRange lease duration range
     * @throws NullPointerException if any argument other than {@code serverName} is {@code null}
     * @throws IllegalArgumentException if {@code 0L > externalPortRange > 65535L || 0L > leaseDurationRange > 0xFFFFFFFFL}, or if
     * {@code controlUrl} scheme is not {@code "http"}
     * 
     */
    protected UpnpIgdPortMapper(Bus networkBus, InetAddress internalAddress, URL controlUrl, String serverName, String serviceType,
            Range<Long> externalPortRange, Range<Long> leaseDurationRange) {
        Validate.notNull(networkBus);
        Validate.notNull(internalAddress);
        Validate.notNull(controlUrl);
//        Validate.notNull(serverName); // can be null
        Validate.notNull(serviceType);
        Validate.notNull(externalPortRange);
        Validate.notNull(leaseDurationRange);
        Validate.isTrue(leaseDurationRange.getMinimum() >= 0L);
        Validate.isTrue(leaseDurationRange.getMaximum() <= 0xFFFFFFFFL);
        Validate.isTrue(externalPortRange.getMinimum() >= 0L);
        Validate.isTrue(externalPortRange.getMaximum() <= 0xFFFFL);
        Validate.isTrue("http".equalsIgnoreCase(controlUrl.getProtocol()));
        this.networkBus = networkBus;
        this.internalAddress = internalAddress;
        this.controlUrl = controlUrl;
        this.serverName = serverName;
        this.serviceType = serviceType;
        this.externalPortRange = externalPortRange;
        this.leaseDurationRange = leaseDurationRange;
    }
 
开发者ID:offbynull,项目名称:portmapper,代码行数:37,代码来源:UpnpIgdPortMapper.java


示例15: mustProperlyParseFaulyHybrid

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Test
public void mustProperlyParseFaulyHybrid() throws Exception {
    byte[] buffer = HYBRID_IP_CONNECTION_AND_IPV6_FIREWALL_CONTROL_WITH_FAULTY_XML.getBytes("US-ASCII");
    ServiceDescriptionUpnpIgdResponse resp = new ServiceDescriptionUpnpIgdResponse(buffer);

    Map<ServiceType, IdentifiedService> services = resp.getIdentifiedServices();
    assertEquals(2, services.size());
    assertTrue(services.containsKey(ServiceType.OLD_PORT_MAPPER));
    assertTrue(services.containsKey(ServiceType.FIREWALL));

    IdentifiedService service;
    
    service = services.get(ServiceType.OLD_PORT_MAPPER);
    // these are negative and overlapping in XML, so they should be defaults
    assertEquals(Range.between(0L, 65535L), service.getExternalPortRange());
    assertEquals(Range.between(1L, 604800L), service.getLeaseDurationRange());
    
    
    service = services.get(ServiceType.FIREWALL);
    // these are valid
    assertEquals(Range.between(123L, 500L), service.getExternalPortRange());
    assertEquals(Range.between(1L, 11111L), service.getLeaseDurationRange());
}
 
开发者ID:offbynull,项目名称:portmapper,代码行数:24,代码来源:ServiceDescriptionUpnpIgdResponseTest.java


示例16: findTree

import org.apache.commons.lang3.Range; //导入依赖的package包/类
/**
 * Find the Lowest Common Ancestor of [from, to] in the tree t
 * 
 * @param t
 * @param e
 * @return null if nothing found
 */
public static Pair<Tree, Tree> findTree(Tree t, Range<Integer> range) {
  Tree tnF = null;
  Tree tnT = null;
  for (Tree leaf : t.getLeaves()) {
    OffsetLabel label = (OffsetLabel) leaf.label();
    if (range.getMinimum() == label.beginPosition()) {
      tnF = leaf.parent(t);
    }
    if (range.getMaximum() == label.endPosition()) {
      tnT = leaf.parent(t);
    }
  }
  if (tnF == null || tnT == null) {
    return null;
  }
  return new Pair<Tree, Tree>(tnF, tnT);
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:25,代码来源:Utils.java


示例17: containmentTest

import org.apache.commons.lang3.Range; //导入依赖的package包/类
private ContainsTest containmentTest(final double doubleStarts, final double doubleEnds) {
	ContainsTest containsTest = null;
	if(start<end){
		
		containsTest = new ContainsTest(){
			
			final Range<Double> range = Range.between(doubleStarts, doubleEnds);
			@Override
			public boolean contains(Double dateAsDouble) {
				return range.contains(dateAsDouble);
			}
			
		};
	}else{
		containsTest = new ContainsTest(){
			
			final Range<Double> range = Range.between(doubleStarts, doubleEnds);
			@Override
			public boolean contains(Double dateAsDouble) {
				return !range.contains(dateAsDouble);
			}
			
		};			
	}
	return containsTest;
}
 
开发者ID:danidemi,项目名称:jlubricant,代码行数:27,代码来源:TimelyRangedTrigger.java


示例18: testFileContentSegment

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Test
public void testFileContentSegment() {
    final BinaryService resolver = new FileBasedBinaryService(directory, idService.getSupplier("file:"));
    final List<Range<Integer>> range = singletonList(between(1, 5));
    assertTrue(resolver.getContent(file, range).isPresent());
    assertEquals(" tes", resolver.getContent(file, range).map(this::uncheckedToString).get());
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:8,代码来源:FileBasedBinaryServiceTest.java


示例19: testFileContentSegments

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Test
public void testFileContentSegments() {
    final BinaryService resolver = new FileBasedBinaryService(directory, idService.getSupplier("file:"));
    final List<Range<Integer>> ranges = new ArrayList<>();
    ranges.add(between(1, 5));
    ranges.add(between(8, 10));

    assertTrue(resolver.getContent(file, ranges).isPresent());
    assertEquals(" tesoc", resolver.getContent(file, ranges).map(this::uncheckedToString).get());
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:11,代码来源:FileBasedBinaryServiceTest.java


示例20: testFileContentSegmentBeyond

import org.apache.commons.lang3.Range; //导入依赖的package包/类
@Test
public void testFileContentSegmentBeyond() {
    final BinaryService resolver = new FileBasedBinaryService(directory, idService.getSupplier("file:"));
    final List<Range<Integer>> range = singletonList(between(1000, 1005));
    assertTrue(resolver.getContent(file, range).isPresent());
    assertEquals("", resolver.getContent(file, range).map(this::uncheckedToString).get());
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:8,代码来源:FileBasedBinaryServiceTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CollectionUtils类代码示例发布时间:2022-05-21
下一篇:
Java ContextBindings类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap