Java Code Examples for org.apache.commons.lang3.Validate#inclusiveBetween()

The following examples show how to use org.apache.commons.lang3.Validate#inclusiveBetween() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfluenceMarkupBuilder.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder sectionTitleWithAnchorLevel(int level, String title, String anchor) {
    Validate.notBlank(title, "title must not be blank");
    Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);

    documentBuilder.append(newLine);
    documentBuilder.append(String.format(TITLE_FORMAT, level + 1, replaceNewLinesWithWhiteSpace(title)));
    if (isBlank(anchor))
        anchor = title;
    documentBuilder.append(" ");
    anchor(replaceNewLinesWithWhiteSpace(anchor));
    
    documentBuilder.append(newLine);

    return this;
}
 
Example 2
Source File: LitematicaBitArray.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
public LitematicaBitArray(int bitsPerEntryIn, long arraySizeIn, @Nullable long[] longArrayIn)
{
    Validate.inclusiveBetween(1L, 32L, (long) bitsPerEntryIn);
    this.arraySize = arraySizeIn;
    this.bitsPerEntry = bitsPerEntryIn;
    this.maxEntryValue = (1L << bitsPerEntryIn) - 1L;

    if (longArrayIn != null)
    {
        this.longArray = longArrayIn;
    }
    else
    {
        this.longArray = new long[(int) (MathUtils.roundUp((long) arraySizeIn * (long) bitsPerEntryIn, 64L) / 64L)];
    }
}
 
Example 3
Source File: EBMLUtils.java    From amazon-kinesis-video-streams-parser-library with Apache License 2.0 6 votes vote down vote up
/**
 * A specialized method used to read a variable length unsigned integer of size 7 bytes or less.
 * @param byteBuffer The byteBuffer to read from.
 * @param size The size of bytes.
 * @return The long containing the integer value.
 */
public static long readUnsignedIntegerSevenBytesOrLess(final ByteBuffer byteBuffer, long size) {
    Validate.inclusiveBetween(0L,
            (long) EBML_SIZE_MAX_BYTES - 1,
            size,
            "Asked for a numeric value of invalid size " + size);

    Validate.isTrue(byteBuffer.remaining() >= size);
    long value = 0;
    for (int i = 0; i < size; i++) {
        final int result = byteBuffer.get() & 0xFF;
        value = (value << Byte.SIZE) | result;
    }

    return value;
}
 
Example 4
Source File: DefinitionsDocumentExtension.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * @param position       the current position
 * @param docBuilder     the MarkupDocBuilder
 * @param definitionName the name of the current definition
 * @param model          the current Model of the definition
 */
public Context(Position position, MarkupDocBuilder docBuilder, String definitionName, Model model) {
    super(docBuilder);
    Validate.inclusiveBetween(Position.DEFINITION_BEFORE, Position.DEFINITION_AFTER, position);
    Validate.notNull(definitionName);
    Validate.notNull(model);
    this.position = position;
    this.definitionName = definitionName;
    this.model = model;
}
 
Example 5
Source File: MapPartitionsOperator.java    From rheem with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<org.qcri.rheem.core.optimizer.cardinality.CardinalityEstimator> createCardinalityEstimator(
        final int outputIndex,
        final Configuration configuration) {
    Validate.inclusiveBetween(0, this.getNumOutputs() - 1, outputIndex);
    return Optional.of(new MapPartitionsOperator.CardinalityEstimator(configuration));
}
 
Example 6
Source File: PathsDocumentExtension.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Context for all other positions
 *
 * @param position   the current position
 * @param document   document object
 * @param operation  the current path operation
 */
public Context(Position position, Document document, PathOperation operation) {
    super(document);
    Validate.inclusiveBetween(Position.OPERATION_BEFORE, Position.OPERATION_SECURITY_AFTER, position);
    Validate.notNull(operation);
    this.position = position;
    this.operation = operation;
}
 
Example 7
Source File: SecurityDocumentExtension.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * @param position           the current position
 * @param docBuilder         the MarkupDocBuilder
 * @param securitySchemeName the name of the current securityScheme
 * @param securityScheme     the current security scheme securityScheme
 */
public Context(Position position, MarkupDocBuilder docBuilder, String securitySchemeName, SecuritySchemeDefinition securityScheme) {
    super(docBuilder);
    Validate.inclusiveBetween(Position.SECURITY_SCHEME_BEFORE, Position.SECURITY_SCHEME_AFTER, position);
    Validate.notNull(securitySchemeName);
    Validate.notNull(securityScheme);
    this.position = position;
    this.securitySchemeName = securitySchemeName;
    this.securityScheme = securityScheme;
}
 
Example 8
Source File: LocalCallbackSink.java    From rheem with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CardinalityEstimator> createCardinalityEstimator(
        final int outputIndex,
        final Configuration configuration) {
    Validate.inclusiveBetween(0, this.getNumOutputs() - 1, outputIndex);
    return super.createCardinalityEstimator(outputIndex, configuration);
}
 
Example 9
Source File: SampleOperator.java    From rheem with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CardinalityEstimator> createCardinalityEstimator(
        final int outputIndex,
        final Configuration configuration) {
    Validate.inclusiveBetween(0, this.getNumOutputs() - 1, outputIndex);
    // TODO: Incorporate OperatoContext would allow for precise estimation.
    return Optional.of(new FixedSizeCardinalityEstimator(this.sampleSizeFunction.applyAsInt(0)));
}
 
Example 10
Source File: CountOperator.java    From rheem with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CardinalityEstimator> createCardinalityEstimator(
        final int outputIndex,
        final Configuration configuration) {
    Validate.inclusiveBetween(0, this.getNumOutputs() - 1, outputIndex);
    return Optional.of(new FixedSizeCardinalityEstimator(1));
}
 
Example 11
Source File: MaterializedGroupByOperator.java    From rheem with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CardinalityEstimator> createCardinalityEstimator(
        final int outputIndex,
        final Configuration configuration) {
    Validate.inclusiveBetween(0, this.getNumOutputs() - 1, outputIndex);
    // TODO: Come up with a decent way to estimate the "distinctness" of reduction keys.
    return Optional.of(new DefaultCardinalityEstimator(0.5d, 1, this.isSupportingBroadcastInputs(),
            inputCards -> (long) (inputCards[0] * 0.1)));
}
 
Example 12
Source File: CardinalityBreakpoint.java    From rheem with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param minConfidence the minimum confidence of the {@link CardinalityEstimate}s
 * @param maxSpread     the minimum accuracy of the {@link CardinalityEstimate}s
 */
public CardinalityBreakpoint(double minConfidence, double maxSpread, double spreadSmoothing) {
    Validate.inclusiveBetween(0, 1, minConfidence);
    Validate.isTrue(maxSpread >= 1);
    this.minConfidence = minConfidence;
    this.maxSpread = maxSpread;
    this.spreadSmoothing = spreadSmoothing;
}
 
Example 13
Source File: DistinctOperator.java    From rheem with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<CardinalityEstimator> createCardinalityEstimator(
        final int outputIndex,
        final Configuration configuration) {
    Validate.inclusiveBetween(0, this.getNumOutputs() - 1, outputIndex);
    // TODO: Come up with a dynamic estimator.
    // Assume with a confidence of 0.7 that 70% of the data quanta are pairwise distinct.
    return Optional.of(new DefaultCardinalityEstimator(0.7d, 1, this.isSupportingBroadcastInputs(),
            inputCards -> (long) (inputCards[0] * 0.7d)));
}
 
Example 14
Source File: AlexaApiEndpoint.java    From alexa-skills-kit-tester-java with Apache License 2.0 5 votes vote down vote up
public void refreshToken() {
    final String url = "https://api.amazon.com/auth/o2/token";

    final HttpPost httpPost = new HttpPost(url);
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE,"application/x-www-form-urlencoded;charset=UTF-8");

    httpPost.setHeader(HttpHeaders.ACCEPT,"application/json");
    httpPost.setHeader(HttpHeaders.ACCEPT_ENCODING,"application/json");

    final List<NameValuePair> nameValuePairs = new ArrayList<>();
    nameValuePairs.add(new BasicNameValuePair("grant_type", "refresh_token"));
    nameValuePairs.add(new BasicNameValuePair("refresh_token", lwaRefreshToken));
    nameValuePairs.add(new BasicNameValuePair("client_id", lwaClientId));
    nameValuePairs.add(new BasicNameValuePair("client_secret", lwaClientSecret));

    final HttpResponse httpResponse;
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        httpResponse = HttpClientBuilder.create().build().execute(httpPost);
        Validate.inclusiveBetween(200, 399, httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase());
        final HttpEntity responseEntity = httpResponse.getEntity();
        final String responsePayload = IOUtils.toString(responseEntity.getContent(), "UTF-8");
        cacheAccessToken(om.readTree(responsePayload));
    } catch (final IOException e) {
        throw new RuntimeException("[ERROR] Error received from Login with Amazon on refreshing an access token. " + e.getMessage(), e);
    }
}
 
Example 15
Source File: AbstractMarkupDocBuilder.java    From markup-document-builder with Apache License 2.0 5 votes vote down vote up
protected void sectionTitleWithAnchorLevel(Markup markup, int level, String title, String anchor) {
    Validate.notBlank(title, "title must not be blank");
    Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
    documentBuilder.append(newLine);
    if (anchor == null)
        anchor = title;
    anchor(replaceNewLinesWithWhiteSpace(anchor)).newLine();
    documentBuilder.append(StringUtils.repeat(markup.toString(), level + 1)).append(" ").append(replaceNewLinesWithWhiteSpace(title)).append(newLine);
}
 
Example 16
Source File: AlexaResponse.java    From alexa-skills-kit-tester-java with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the execution time of the request call to the skill. It
 * throws an IllegalArgumentException in case the execution time exceeded the
 * milliseconds given
 * @param millis milliseconds (inclusive) that should not be exceeded by the skill call
 * @return this response
 */
public AlexaResponse assertExecutionTimeLessThan(final long millis) {
    final String assertionText = String.format("Execution is not longer than %s ms.", millis);
    final long executionMillis = request.getSession().getClient().getLastExecutionMillis();
    Validate.inclusiveBetween(0L, millis, executionMillis, "[FAILED] Assertion '%1Ss' is FALSE. Was %2Ss ms.", assertionText, executionMillis);
    log.info(String.format("->[TRUE] %s", assertionText));
    return this;
}
 
Example 17
Source File: IncrementalSplitter.java    From inception with Apache License 2.0 5 votes vote down vote up
public IncrementalSplitter(double aTrainPercentage, int aIncrement, int aLowSampleThreshold)
{
    Validate.inclusiveBetween(0, 1, aTrainPercentage, "Percentage has to be in (0,1)");

    trainBatchSize = (int) Math.round(10 * aTrainPercentage);
    testBatchSize = 10 - trainBatchSize;
    increment = aIncrement;
    lowSampleThreshold = aLowSampleThreshold;
}
 
Example 18
Source File: SecurityDocumentExtension.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
/**
 * @param position   the current position
 * @param document the MarkupDocBuilder
 */
public Context(Position position, Document document) {
    super(document);
    Validate.inclusiveBetween(Position.DOCUMENT_BEFORE, Position.DOCUMENT_AFTER, position);
    this.position = position;
}
 
Example 19
Source File: DefinitionsDocumentExtension.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
/**
 * @param position   the current position
 * @param docBuilder the MarkupDocBuilder
 */
public Context(Position position, MarkupDocBuilder docBuilder) {
    super(docBuilder);
    Validate.inclusiveBetween(Position.DOCUMENT_BEFORE, Position.DOCUMENT_AFTER, position);
    this.position = position;
}
 
Example 20
Source File: ElementaryOperator.java    From rheem with Apache License 2.0 3 votes vote down vote up
/**
 * Provide a {@link CardinalityEstimator} for the {@link OutputSlot} at {@code outputIndex}.
 *
 * @param outputIndex   index of the {@link OutputSlot} for that the {@link CardinalityEstimator} is requested
 * @param configuration if the {@link CardinalityEstimator} depends on further ones, use this to obtain the latter
 * @return an {@link Optional} that might provide the requested instance
 */
default Optional<CardinalityEstimator> createCardinalityEstimator(
        final int outputIndex,
        final Configuration configuration) {
    Validate.inclusiveBetween(0, this.getNumOutputs() - 1, outputIndex);
    return Optional.empty();
}