Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no @DoubleRange annotation in Android Studio Support Annotations like @IntRange and @FloatRange

I read this article on Android Studio Support Annotations today and started using these annotations in my code, here is an example:

public final static class GoogleMapsZoomLevel {

    public static final int MIN_ZOOM_LEVEL = 0;
    public static final int MAX_ZOOM_LEVEL = 21;

    ..

    public GoogleMapsZoomLevel(@IntRange(from=MIN_ZOOM_LEVEL, to=MAX_ZOOM_LEVEL) int zoomLevel) {
        if (zoomLevel < MIN_ZOOM_LEVEL || zoomLevel > MAX_ZOOM_LEVEL) {
            throw new IllegalArgumentException(ERROR_ZOOM_LEVEL_OUT_OF_BOUNDS);
        }
        this.zoomLevel = zoomLevel;
    }
    ..
}

Further down in my code I have a class that accepts double values in it's constructor, but there is no @DoubleRange annotation. Do I use @FloatRange or nothing at all? Same question for long values

like image 889
Kaloyan Roussev Avatar asked Oct 10 '15 09:10

Kaloyan Roussev


People also ask

How do I add annotations to Android support?

To enable annotations in your project, add the support-annotations dependency to your library or app. Any annotations you add then get checked when you run a code inspection or lint task.

What is androidx annotation annotation?

annotation:annotation. Official Description: The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs.

What is IntDef?

@Retention(value = AnnotationRetention.SOURCE) @Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS]) public annotation IntDef. Denotes that the annotated element of integer type, represents a logical type and that its value should be one of the explicitly named constants.


1 Answers

Actually, @FloatRange 's documentation states:

Denotes that the annotated element should be a float or double in the given range

And similar situation for @IntRange

Denotes that the annotated element should be an int or long in the given range
like image 114
Kaloyan Roussev Avatar answered Oct 12 '22 02:10

Kaloyan Roussev