本文整理汇总了Java中org.apache.commons.lang3.Range.getMinimum方法的典型用法代码示例。如果您正苦于以下问题:Java Range.getMinimum方法的具体用法?Java Range.getMinimum怎么用?Java Range.getMinimum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.Range
的用法示例。
在下文中一共展示了Range.getMinimum方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: randomValueIn
import org.apache.commons.lang3.Range; //导入方法依赖的package包/类
private int randomValueIn(Range<Integer> range)
{
int result = random.nextInt(range.getMaximum() - range.getMinimum() + 1) + range.getMinimum();
return result;
}
示例3: 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();
}
示例4: 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;
}
示例5: 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);
}
示例6: 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();
}
示例7: getRangeClause
import org.apache.commons.lang3.Range; //导入方法依赖的package包/类
/**
* range condition
*
* @param r range
* @return
*/
default String getRangeClause(Range<Long> r) {
return "LIMIT " + (r.getMaximum() - r.getMinimum()) + " OFFSET " + r.getMinimum();
}