org.wildfly.common.Assert.checkMaximumParameter()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.wildfly.common.Assert.checkMaximumParameter()方法的一些代码示例,展示了Assert.checkMaximumParameter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.checkMaximumParameter()方法的具体详情如下:
包路径:org.wildfly.common.Assert
类名称:Assert
方法名:checkMaximumParameter

Assert.checkMaximumParameter介绍

[英]Check that the named parameter is less than or equal to max.
[中]检查命名参数是否小于或等于max。

代码示例

代码示例来源:origin: wildfly/wildfly

/**
 * Set the maximum queue size.
 *
 * @param maxQueueSize the maximum queue size (must be ≥ 0)
 * @see EnhancedQueueExecutor#setMaximumQueueSize(int)
 */
public Builder setMaximumQueueSize(final int maxQueueSize) {
  Assert.checkMinimumParameter("maxQueueSize", 0, maxQueueSize);
  Assert.checkMaximumParameter("maxQueueSize", Integer.MAX_VALUE, maxQueueSize);
  this.maxQueueSize = maxQueueSize;
  return this;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Set the growth resistance factor.
 *
 * @param growthResistance the thread pool growth resistance (must be in the range {@code 0.0f ≤ n ≤ 1.0f})
 * @see Builder#setGrowthResistance(float) Builder.setGrowthResistance()
 */
public void setGrowthResistance(final float growthResistance) {
  Assert.checkMinimumParameter("growthResistance", 0.0f, growthResistance);
  Assert.checkMaximumParameter("growthResistance", 1.0f, growthResistance);
  this.growthResistance = growthResistance;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Set the certificate version.
 *
 * @param version the certificate version (must be between 1 and 3, inclusive)
 * @return this builder instance
 */
public X509CertificateBuilder setVersion(final int version) {
  Assert.checkMinimumParameter("version", 1, version);
  Assert.checkMaximumParameter("version", 3, version);
  this.version = version;
  return this;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Set the thread pool growth resistance.
 *
 * @param growthResistance the thread pool growth resistance (must be in the range {@code 0.0f ≤ n ≤ 1.0f})
 * @return this builder
 * @see #getGrowthResistance()
 * @see EnhancedQueueExecutor#setGrowthResistance(float)
 */
public Builder setGrowthResistance(final float growthResistance) {
  Assert.checkMinimumParameter("growthResistance", 0.0f, growthResistance);
  Assert.checkMaximumParameter("growthResistance", 1.0f, growthResistance);
  this.growthResistance = growthResistance;
  return this;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Set the core pool size.  If the configured maximum pool size is less than the configured core size, the
 * core size will be reduced to match the maximum size when the thread pool is constructed.
 *
 * @param coreSize the core pool size (must be greater than or equal to 0, and less than 2^20)
 * @return this builder
 * @see EnhancedQueueExecutor#setCorePoolSize(int)
 */
public Builder setCorePoolSize(final int coreSize) {
  Assert.checkMinimumParameter("coreSize", 0, coreSize);
  Assert.checkMaximumParameter("coreSize", TS_THREAD_CNT_MASK, coreSize);
  this.coreSize = coreSize;
  return this;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Set the maximum pool size.  If the configured maximum pool size is less than the configured core size, the
 * core size will be reduced to match the maximum size when the thread pool is constructed.
 *
 * @param maxSize the maximum pool size (must be greater than or equal to 0, and less than 2^20)
 * @return this builder
 * @see EnhancedQueueExecutor#setMaximumPoolSize(int)
 */
public Builder setMaximumPoolSize(final int maxSize) {
  Assert.checkMinimumParameter("maxSize", 0, maxSize);
  Assert.checkMaximumParameter("maxSize", TS_THREAD_CNT_MASK, maxSize);
  this.maxSize = maxSize;
  return this;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get an IPv4 address from four integer segments.  Each segment must be between 0 and 255.
 *
 * @param s1 the first segment
 * @param s2 the second segment
 * @param s3 the third segment
 * @param s4 the fourth segment
 * @return the address (not {@code null})
 */
public static Inet4Address getInet4Address(int s1, int s2, int s3, int s4) {
  byte[] bytes = new byte[4];
  Assert.checkMinimumParameter("s1", 0, s1);
  Assert.checkMaximumParameter("s1", 255, s1);
  Assert.checkMinimumParameter("s2", 0, s2);
  Assert.checkMaximumParameter("s2", 255, s2);
  Assert.checkMinimumParameter("s3", 0, s3);
  Assert.checkMaximumParameter("s3", 255, s3);
  Assert.checkMinimumParameter("s4", 0, s4);
  Assert.checkMaximumParameter("s4", 255, s4);
  bytes[0] = (byte) s1;
  bytes[1] = (byte) s2;
  bytes[2] = (byte) s3;
  bytes[3] = (byte) s4;
  try {
    return (Inet4Address) InetAddress.getByAddress(s1 + "." + s2 + "." + s3 + "." + s4, bytes);
  } catch (UnknownHostException e) {
    // not possible
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get an item from this mapping by ID.
 *
 * @param index the index to look up
 * @return the mapped item for the given ID
 * @throws IllegalArgumentException if the given index is out of range
 */
public T getItemById(int index) throws IllegalArgumentException {
  Assert.checkMinimumParameter("index", 0, index);
  Assert.checkMaximumParameter("index", stringEnumeration.size() - 1, index);
  return items[index];
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get the canonical name for an index.  If the index is out of range, an exception is thrown.
 *
 * @param index the index to seek
 * @return the canonical name (not {@code null})
 */
public String nameOf(int index) {
  final Data[] byId = this.byId;
  Assert.checkMinimumParameter("index", 0, index);
  Assert.checkMaximumParameter("index", size() - 1, index);
  return byId[index].canonicalName;
}

代码示例来源:origin: wildfly/wildfly

private void loadSecretKey(ObjectInputStream ois) throws IOException, GeneralSecurityException {
  byte[] encryptedData = readBytes(ois);
  byte[] iv = readBytes(ois);
  decrypt.init(Cipher.DECRYPT_MODE, storageSecretKey, new IvParameterSpec(iv));
  Assert.checkMaximumParameter("cipher block size", 256, decrypt.getBlockSize());
  byte[] unPadded = pkcs7UnPad(decrypt.doFinal(encryptedData));
  ObjectInputStream entryOis = new ObjectInputStream(new ByteArrayInputStream(unPadded));
  String ksAlias = entryOis.readUTF();
  byte[] encodedSecretKey = readBytes(entryOis);
  KeyStore.Entry entry = new KeyStore.SecretKeyEntry(new SecretKeySpec(encodedSecretKey, DATA_OID));
  dataKeyStore.setEntry(ksAlias, entry, convertParameter(protectionParameter));
}

代码示例来源:origin: wildfly/wildfly

/**
 * Construct a new instance.
 *
 * @param elements the elements to iterate over
 * @param descending {@code true} to iterate in descending order, {@code false} otherwise
 * @param startIdx the starting index (must be within the bounds of {@code elements})
 */
public ArrayIterator(final E[] elements, final boolean descending, final int startIdx) {
  Assert.checkNotNullParam("elements", elements);
  Assert.checkMinimumParameter("startIdx", 0, startIdx);
  Assert.checkMaximumParameter("startIdx", elements.length, startIdx);
  this.elements = elements;
  this.descending = descending;
  this.idx = startIdx;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Construct a new instance.
 *
 * @param elements the elements to iterate over
 * @param descending {@code true} to iterate in descending order, {@code false} otherwise
 * @param startIdx the starting index (must be within the bounds of {@code elements})
 */
public ArrayIterator(final E[] elements, final boolean descending, final int startIdx) {
  Assert.checkNotNullParam("elements", elements);
  Assert.checkMinimumParameter("startIdx", 0, startIdx);
  Assert.checkMaximumParameter("startIdx", elements.length, startIdx);
  this.elements = elements;
  this.descending = descending;
  this.idx = startIdx;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get a resolved socket address from the given URI.
 *
 * @param uri the URI (must not be {@code null})
 * @param defaultPort the default port to use if none is given (must be in the range {@code 1 ≤ n ≤ 65535}
 * @param addressType the class of the {@code InetAddress} to search for (must not be {@code null})
 * @return the socket address, or {@code null} if the URI does not have a host component
 * @throws UnknownHostException if address resolution failed
 */
public static InetSocketAddress getResolved(URI uri, int defaultPort, Class<? extends InetAddress> addressType) throws UnknownHostException {
  Assert.checkNotNullParam("uri", uri);
  Assert.checkMinimumParameter("defaultPort", 1, defaultPort);
  Assert.checkMaximumParameter("defaultPort", 65535, defaultPort);
  Assert.checkNotNullParam("addressType", addressType);
  final String uriHost = uri.getHost();
  if (uriHost == null) {
    return null;
  }
  final InetAddress resolved = getAddressByNameAndType(uriHost, addressType);
  final int uriPort = uri.getPort();
  return uriPort != - 1 ? new InetSocketAddress(resolved, uriPort) : new InetSocketAddress(resolved, defaultPort);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Set the maximum queue size.  If the new maximum queue size is smaller than the current queue size, there is no
 * effect other than preventing tasks from being enqueued until the size decreases below the maximum again.
 *
 * @param maxQueueSize the maximum queue size (must be ≥ 0)
 * @see Builder#setMaximumQueueSize(int) Builder.setMaximumQueueSize()
 */
public void setMaximumQueueSize(final int maxQueueSize) {
  Assert.checkMinimumParameter("maxQueueSize", 0, maxQueueSize);
  Assert.checkMaximumParameter("maxQueueSize", Integer.MAX_VALUE, maxQueueSize);
  if (NO_QUEUE_LIMIT) return;
  long oldVal;
  do {
    oldVal = queueSize;
  } while (! compareAndSetQueueSize(oldVal, withMaxQueueSize(oldVal, maxQueueSize)));
}

代码示例来源:origin: wildfly/wildfly

private void saveSecretKey(String ksAlias, ObjectOutputStream oos, KeyStore.SecretKeyEntry entry) throws IOException, GeneralSecurityException {
  ByteArrayOutputStream entryData = new ByteArrayOutputStream(1024);
  ObjectOutputStream entryOos = new ObjectOutputStream(entryData);
  entryOos.writeUTF(ksAlias);
  writeBytes(entry.getSecretKey().getEncoded(), entryOos);
  entryOos.flush();
  encrypt.init(Cipher.ENCRYPT_MODE, storageSecretKey, (AlgorithmParameterSpec) null); // ELY-1308: third param need to workaround BouncyCastle bug
  int blockSize = encrypt.getBlockSize();
  if (blockSize == 0) throw log.algorithmNotBlockBased(encrypt.getAlgorithm());
  Assert.checkMaximumParameter("cipher block size", 256, blockSize);
  byte[] padded = pkcs7Pad(entryData.toByteArray(), blockSize);
  byte[] encrypted = encrypt.doFinal(padded);
  byte[] iv = encrypt.getIV();
  if (iv == null) throw log.algorithmNotIV(encrypt.getAlgorithm());
  oos.writeInt(SECRET_KEY_ENTRY_TYPE);
  writeBytes(encrypted, oos);
  writeBytes(iv, oos);
}

代码示例来源:origin: wildfly/wildfly

static CidrAddress create(byte[] addressBytes, int netmaskBits, boolean clone) {
  Assert.checkNotNullParam("networkAddress", addressBytes);
  Assert.checkMinimumParameter("netmaskBits", 0, netmaskBits);
  final int length = addressBytes.length;
  if (length == 4) {
    Assert.checkMaximumParameter("netmaskBits", 32, netmaskBits);
    if (netmaskBits == 0) {
      return INET4_ANY_CIDR;
    }
  } else if (length == 16) {
    Assert.checkMaximumParameter("netmaskBits", 128, netmaskBits);
    if (netmaskBits == 0) {
      return INET6_ANY_CIDR;
    }
  } else {
    throw CommonMessages.msg.invalidAddressBytes(length);
  }
  final byte[] bytes = clone ? addressBytes.clone() : addressBytes;
  maskBits0(bytes, netmaskBits);
  String name = Inet.toOptimalString(bytes);
  try {
    return new CidrAddress(InetAddress.getByAddress(name, bytes), netmaskBits);
  } catch (UnknownHostException e) {
    throw Assert.unreachableCode();
  }
}

代码示例来源:origin: wildfly/wildfly

int scopeId = Inet.getScopeId(networkAddress);
if (networkAddress instanceof Inet4Address) {
  Assert.checkMaximumParameter("netmaskBits", 32, netmaskBits);
  if (netmaskBits == 0) {
    return INET4_ANY_CIDR;
  Assert.checkMaximumParameter("netmaskBits", 128, netmaskBits);
  if (netmaskBits == 0 && scopeId == 0) {
    return INET6_ANY_CIDR;

代码示例来源:origin: wildfly/wildfly

@Override
protected void engineUpdate(byte[] input, int offset, int len) {
  Assert.checkMinimumParameter("offset", 0, offset);
  Assert.checkMinimumParameter("len", 0, len);
  Assert.checkMaximumParameter("offset + len", input.length, offset + len);
  if (len == 0) return;
  messageLength += len;
  while (len > 0) {
    int loadingBytes = Math.min(len, BLOCK_SIZE - bytesLoaded); // amount of bytes from input into current block
    System.arraycopy(input, offset, block, bytesLoaded, loadingBytes);
    bytesLoaded += loadingBytes;
    offset += loadingBytes;
    len -= loadingBytes;
    if (bytesLoaded == BLOCK_SIZE) {
      ByteIterator bi = ByteIterator.ofBytes(block);
      // prepare the message schedule
      for (int i = 0; i < 16; i++) {
        W[i] = bi.getBE64();
      }
      for(int i = 16; i < 80; i++) {
        long s0 = rotr(W[i - 15], 1) ^ rotr(W[i - 15], 8) ^ (W[i - 15] >>> 7);
        long s1 = rotr(W[i - 2], 19) ^ rotr(W[i - 2], 61) ^ (W[i - 2] >>> 6);
        W[i] = W[i - 16] + s0 + W[i - 7] + s1;
      }
      processBlock();
      bytesLoaded = 0;
    }
  }
}

代码示例来源:origin: wildfly/wildfly

/**
 * Set the maximum pool size.  If the configured maximum pool size is less than the configured core size, the
 * core size will be reduced to match the maximum size when the thread pool is constructed.
 *
 * @param maxPoolSize the maximum pool size (must be greater than or equal to 0, and less than 2^20)
 * @see Builder#setMaximumPoolSize(int) Builder.setMaximumPoolSize()
 */
public void setMaximumPoolSize(final int maxPoolSize) {
  Assert.checkMinimumParameter("maxPoolSize", 0, maxPoolSize);
  Assert.checkMaximumParameter("maxPoolSize", TS_THREAD_CNT_MASK, maxPoolSize);
  long oldVal, newVal;
  do {
    oldVal = threadStatus;
    if (maxPoolSize < coreSizeOf(oldVal)) {
      // automatically bump down core size to match
      newVal = withCoreSize(withMaxSize(oldVal, maxPoolSize), maxPoolSize);
    } else {
      newVal = withMaxSize(oldVal, maxPoolSize);
    }
  } while (! compareAndSetThreadStatus(oldVal, newVal));
  if (maxSizeOf(newVal) < maxSizeOf(oldVal) || coreSizeOf(newVal) < coreSizeOf(oldVal)) {
    // poke all the threads to try to terminate any excess eagerly
    for (Thread activeThread : runningThreads) {
      unpark(activeThread);
    }
  }
}

代码示例来源:origin: wildfly/wildfly

/**
 * Set the core pool size.  If the configured maximum pool size is less than the configured core size, the
 * core size will be reduced to match the maximum size when the thread pool is constructed.
 *
 * @param corePoolSize the core pool size (must be greater than or equal to 0, and less than 2^20)
 * @see Builder#setCorePoolSize(int) Builder.setCorePoolSize()
 */
public void setCorePoolSize(final int corePoolSize) {
  Assert.checkMinimumParameter("corePoolSize", 0, corePoolSize);
  Assert.checkMaximumParameter("corePoolSize", TS_THREAD_CNT_MASK, corePoolSize);
  long oldVal, newVal;
  do {
    oldVal = threadStatus;
    if (corePoolSize > maxSizeOf(oldVal)) {
      // automatically bump up max size to match
      newVal = withCoreSize(withMaxSize(oldVal, corePoolSize), corePoolSize);
    } else {
      newVal = withCoreSize(oldVal, corePoolSize);
    }
  } while (! compareAndSetThreadStatus(oldVal, newVal));
  if (maxSizeOf(newVal) < maxSizeOf(oldVal) || coreSizeOf(newVal) < coreSizeOf(oldVal)) {
    // poke all the threads to try to terminate any excess eagerly
    for (Thread activeThread : runningThreads) {
      unpark(activeThread);
    }
  }
}

相关文章