• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / JavaSpiNNaker / 6233274834

19 Sep 2023 08:46AM UTC coverage: 36.409% (-0.6%) from 36.982%
6233274834

Pull #658

github

dkfellows
Merge branch 'master' into java-17
Pull Request #658: Update Java version to 17

1656 of 1656 new or added lines in 260 files covered. (100.0%)

8373 of 22997 relevant lines covered (36.41%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/compat/SaneParameter.java
1
/*
2
 * Copyright (c) 2021 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.alloc.compat;
17

18
import static java.lang.annotation.ElementType.FIELD;
19
import static java.lang.annotation.ElementType.METHOD;
20
import static java.lang.annotation.ElementType.PARAMETER;
21
import static java.lang.annotation.ElementType.TYPE_USE;
22
import static java.lang.annotation.RetentionPolicy.RUNTIME;
23

24
import java.lang.annotation.Documented;
25
import java.lang.annotation.Retention;
26
import java.lang.annotation.Target;
27

28
import javax.validation.Constraint;
29
import javax.validation.ConstraintValidator;
30
import javax.validation.ConstraintValidatorContext;
31
import javax.validation.Payload;
32

33
/**
34
 * Validates that an argument is a sane value to pass in a classic spalloc API
35
 * call. That means "is it a string, a boolean or a number"? Null is not
36
 * permitted.
37
 *
38
 * @author Donal Fellows
39
 */
40
@Documented
41
@Retention(RUNTIME)
42
@Target({ METHOD, FIELD, PARAMETER, TYPE_USE })
43
@Constraint(validatedBy = { IsSaneValidator.class })
44
public @interface SaneParameter {
45
        /**
46
         * Message on constraint violated.
47
         *
48
         * @return Message
49
         */
50
        String message() default "${validatedValue} is a bad spalloc parameter";
51

52
        /**
53
         * Group of constraints. Required by validation spec.
54
         *
55
         * @return Constraint groups, if any
56
         * @hidden
57
         */
58
        Class<?>[] groups() default {};
59

60
        /**
61
         * Payload info. Required by validation spec.
62
         *
63
         * @return Payloads, if any.
64
         * @hidden
65
         */
66
        Class<? extends Payload>[] payload() default {};
67
}
68

69
class IsSaneValidator implements ConstraintValidator<SaneParameter, Object> {
×
70
        @Override
71
        public boolean isValid(Object value, ConstraintValidatorContext context) {
72
                if (value instanceof String s) {
×
73
                        return !s.isBlank();
×
74
                } else {
75
                        return (value instanceof Boolean) || (value instanceof Number);
×
76
                }
77
        }
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc