本文整理汇总了Java中org.apache.commons.lang3.Range.isBefore方法的典型用法代码示例。如果您正苦于以下问题:Java Range.isBefore方法的具体用法?Java Range.isBefore怎么用?Java Range.isBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.Range
的用法示例。
在下文中一共展示了Range.isBefore方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bizYearByDate
import org.apache.commons.lang3.Range; //导入方法依赖的package包/类
private Pair<Integer, Range<LocalDate>> bizYearByDate(int year, LocalDate dt) {
Range<LocalDate> range = bizYearStrategy.rangeOfBizYear(year);
if (range.isAfter(dt)) {
return bizYearByDate(year - 1, dt);
}
if (range.isBefore(dt)) {
return bizYearByDate(year + 1, dt);
}
return Pair.of(year, range);
}
示例2: mapPort
import org.apache.commons.lang3.Range; //导入方法依赖的package包/类
@Override
public MappedPort mapPort(PortType portType, int internalPort, int externalPort, long lifetime) throws InterruptedException {
LOG.info("Attempting to map {} Internal:{} External:{} Lifetime:{}", portType, internalPort, externalPort, lifetime);
Validate.notNull(portType);
Validate.inclusiveBetween(1, 65535, internalPort);
Validate.inclusiveBetween(1L, Long.MAX_VALUE, lifetime);
Bus networkBus = getNetworkBus();
URL controlUrl = getControlUrl();
String serviceType = getServiceType();
InetAddress internalAddress = getInternalAddress();
// attempt to map 5 times -- first attempt should be 3 tries to map the externalPort passed in... anything after that is 1 attempt
// to map a randomized externalPort
long[] retryDurations = new long[] {5000L, 5000L, 5000L};
for (int i = 0; i < 5; i++) {
Range<Long> externalPortRange = getExternalPortRange();
Range<Long> leaseDurationRange = getLeaseDurationRange();
long leaseDuration;
if (leaseDurationRange.isBefore(lifetime)) {
leaseDuration = leaseDurationRange.getMaximum();
} else if (leaseDurationRange.isAfter(lifetime)) {
leaseDuration = leaseDurationRange.getMinimum();
} else {
leaseDuration = lifetime;
}
Validate.validState(externalPortRange.contains((long) externalPort),
"Router reports external port mappings as %s", externalPortRange);
TcpRequest mapHttpRequest = new TcpRequest(
internalAddress,
controlUrlAddress,
new AddPinholeUpnpIgdRequest(
controlUrl.getAuthority(),
controlUrl.getFile(),
serviceType,
null,
externalPort,
internalAddress,
internalPort,
portType,
leaseDuration),
new BasicRequestTransformer(),
new BytesToResponseTransformer() {
@Override
public Object create(byte[] buffer) {
return new AddPinholeUpnpIgdResponse(buffer);
}
});
performTcpRequests(
networkBus,
Collections.singleton(mapHttpRequest),
retryDurations);
if (mapHttpRequest.getResponse() != null) {
// server responded, so we're good to go
String key = ((AddPinholeUpnpIgdResponse) mapHttpRequest.getResponse()).getUniqueId();
MappedPort mappedPort = new FirewallMappedPort(key, internalPort, externalPort, portType, leaseDuration);
LOG.debug("Map successful {}", mappedPort);
return mappedPort;
}
// choose another external port for next try -- next try only make 1 attempt
retryDurations = new long[] {5000L};
externalPort = RandomUtils.nextInt(
externalPortRange.getMinimum().intValue(), // should never be < 1
externalPortRange.getMaximum().intValue() + 1); // should never be > 65535
}
throw new IllegalStateException();
}
示例3: refreshPort
import org.apache.commons.lang3.Range; //导入方法依赖的package包/类
@Override
public MappedPort refreshPort(MappedPort mappedPort, long lifetime) throws InterruptedException {
LOG.info("Attempting to refresh mapping {} for {}", mappedPort, lifetime);
Validate.notNull(mappedPort);
Validate.isTrue(mappedPort instanceof FirewallMappedPort);
Bus networkBus = getNetworkBus();
URL controlUrl = getControlUrl();
String serviceType = getServiceType();
Range<Long> leaseDurationRange = getLeaseDurationRange();
long leaseDuration;
if (leaseDurationRange.isBefore(lifetime)) {
leaseDuration = leaseDurationRange.getMaximum();
} else if (leaseDurationRange.isAfter(lifetime)) {
leaseDuration = leaseDurationRange.getMinimum();
} else {
leaseDuration = lifetime;
}
String key = ((FirewallMappedPort) mappedPort).getKey();
InetAddress internalAddress = getInternalAddress();
TcpRequest httpRequest = new TcpRequest(
internalAddress,
controlUrlAddress,
new UpdatePinholeUpnpIgdRequest(
controlUrl.getAuthority(),
controlUrl.getFile(),
serviceType,
key,
leaseDuration),
new BasicRequestTransformer(),
new BytesToResponseTransformer() {
@Override
public Object create(byte[] buffer) {
return new UpdatePinholeUpnpIgdResponse(buffer);
}
});
performTcpRequests(
networkBus,
Collections.singleton(httpRequest),
5000L, 5000L, 5000L);
if (httpRequest.getResponse() == null) {
throw new IllegalStateException("No response/invalid response to refresh");
}
FirewallMappedPort newMappedPort = new FirewallMappedPort(key, mappedPort.getInternalPort(), mappedPort.getExternalPort(),
mappedPort.getPortType(), leaseDuration);
LOG.warn("Mapping refreshed {}: ", mappedPort, newMappedPort);
return newMappedPort;
}
示例4: newMapPort
import org.apache.commons.lang3.Range; //导入方法依赖的package包/类
private MappedPort newMapPort(PortType portType, int internalPort, int externalPort, long lifetime, InetAddress externalAddress)
throws InterruptedException {
Bus networkBus = getNetworkBus();
URL controlUrl = getControlUrl();
String serviceType = getServiceType();
InetAddress internalAddress = getInternalAddress();
Range<Long> externalPortRange = getExternalPortRange();
Range<Long> leaseDurationRange = getLeaseDurationRange();
long leaseDuration;
if (leaseDurationRange.isBefore(lifetime)) {
leaseDuration = leaseDurationRange.getMaximum();
} else if (leaseDurationRange.isAfter(lifetime)) {
leaseDuration = leaseDurationRange.getMinimum();
} else {
leaseDuration = lifetime;
}
Validate.validState(externalPortRange.contains((long) externalPort),
"Router reports external port mappings as %s", externalPortRange);
TcpRequest mapHttpRequest = new TcpRequest(
internalAddress,
controlUrlAddress,
new AddAnyPortMappingUpnpIgdRequest(
controlUrl.getAuthority(),
controlUrl.getFile(),
serviceType,
null,
externalPort,
portType,
internalPort,
internalAddress,
true,
"",
leaseDuration),
new BasicRequestTransformer(),
new BytesToResponseTransformer() {
@Override
public Object create(byte[] buffer) {
return new AddAnyPortMappingUpnpIgdResponse(buffer);
}
});
performTcpRequests(
networkBus,
Collections.singleton(mapHttpRequest),
5000L, 5000L, 5000L);
if (mapHttpRequest.getResponse() == null) {
throw new IllegalStateException("No response/invalid response to mapping");
}
int reservedExternalPort = ((AddAnyPortMappingUpnpIgdResponse) mapHttpRequest.getResponse()).getReservedPort();
return new PortMapperMappedPort(
internalPort,
reservedExternalPort,
externalAddress,
portType,
leaseDuration);
}
示例5: oldMapPort
import org.apache.commons.lang3.Range; //导入方法依赖的package包/类
private MappedPort oldMapPort(PortType portType, int internalPort, int externalPort, long lifetime, InetAddress externalAddress)
throws InterruptedException {
Bus networkBus = getNetworkBus();
URL controlUrl = getControlUrl();
String serviceType = getServiceType();
InetAddress internalAddress = getInternalAddress();
// attempt to map 5 times -- first attempt should be 3 tries to map the externalPort passed in... anything after that is 1 attempt
// to map a randomized externalPort
long[] retryDurations = new long[] {5000L, 5000L, 5000L};
for (int i = 0; i < 5; i++) {
Range<Long> externalPortRange = getExternalPortRange();
Range<Long> leaseDurationRange = getLeaseDurationRange();
long leaseDuration;
if (leaseDurationRange.isBefore(lifetime)) {
leaseDuration = leaseDurationRange.getMaximum();
} else if (leaseDurationRange.isAfter(lifetime)) {
leaseDuration = leaseDurationRange.getMinimum();
} else {
leaseDuration = lifetime;
}
Validate.validState(externalPortRange.contains((long) externalPort),
"Router reports external port mappings as %s", externalPortRange);
TcpRequest mapHttpRequest = new TcpRequest(
internalAddress,
controlUrlAddress,
new AddPortMappingUpnpIgdRequest(
controlUrl.getAuthority(),
controlUrl.getFile(),
serviceType,
null,
externalPort,
portType,
internalPort,
internalAddress,
true,
"",
leaseDuration),
new BasicRequestTransformer(),
new BytesToResponseTransformer() {
@Override
public Object create(byte[] buffer) {
return new AddPortMappingUpnpIgdResponse(buffer);
}
});
performTcpRequests(
networkBus,
Collections.singleton(mapHttpRequest),
retryDurations);
if (mapHttpRequest.getResponse() != null) {
// server responded, so we're good to go
return new PortMapperMappedPort(
internalPort,
externalPort,
externalAddress,
portType,
leaseDuration);
}
// choose another external port for next try -- next try only make 1 attempt
retryDurations = new long[] {5000L};
externalPort = RandomUtils.nextInt(
externalPortRange.getMinimum().intValue(), // should never be < 1
externalPortRange.getMaximum().intValue() + 1); // should never be > 65535
}
throw new IllegalStateException();
}