Source code: com/trapezium/chisel/IntegerConstraints.java
1 /*
2 * @(#)IntegerConstraints.java
3 *
4 * Copyright (c) 1998 by Trapezium Development LLC. All Rights Reserved.
5 *
6 * The information in this file is the property of Trapezium Development LLC
7 * and may be used only in accordance with the terms of the license granted
8 * by Trapezium.
9 *
10 */
11 package com.trapezium.chisel;
12
13 /**
14 * Constraints for an integer option value.
15 *
16 * Used by objects implementing the OptionHolder interface to deal with
17 * options that take integer values with minimum and maximum values.
18 *
19 * @author Michael St. Hippolyte
20 * @version 1.0, 18 Mar 1998
21 *
22 * @since 1.0
23 */
24 public final class IntegerConstraints {
25 int min;
26 int max;
27 int incr;
28
29 public IntegerConstraints( int min, int max, int incr ) {
30 this.min = min;
31 this.max = max;
32 this.incr = incr;
33 }
34
35 public int getMinimum() {
36 return min;
37 }
38
39 public int getMaximum() {
40 return max;
41 }
42
43 public int getIncrement() {
44 return incr;
45 }
46
47 public int legalize(int n) {
48 return (n < min ? min : (n > max ? max : n));
49 }
50
51 public int increment(int n) {
52 return legalize(n + incr);
53 }
54
55 public int decrement(int n) {
56 return legalize(n - incr);
57 }
58 }