-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStandardAttribute.java
More file actions
124 lines (112 loc) · 5.42 KB
/
StandardAttribute.java
File metadata and controls
124 lines (112 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (C) 2025 Tony Luken <tonyluken62+gerberfilereader.gmail.com>
*
* This file is part of GerberFileReader.
*
* GerberFileReader is free software: you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* GerberFileReader is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with GerberFileReader. If
* not, see <http://www.gnu.org/licenses/>.
*/
package standardAttributes;
import gerberFileReader.Attribute;
import gerberFileReader.GerberLayerFormatException;
/**
* An abstract class to represent Gerber Standard Attributes
*/
public abstract class StandardAttribute extends Attribute {
/**
* The string used in Gerber files as the Standard Attribute's name. All subclasses of
* StandardAttribute must override this with the proper value. Failure to do so will result in
* an IllegalStateException to be thrown when the constructor is called.
*/
public static final String GERBER_STANDARD_ATTRIBUTE_NAME = "";
/**
* Constructs a Gerber Standard Attribute from a Gerber command
* @param cmd the Gerber command
* @throws GerberLayerFormatException if the command doesn't properly represent a Gerber
* Attribute
*/
protected StandardAttribute(String cmd) throws GerberLayerFormatException {
super(cmd);
if (getGerberStandardAttributeName().equals(StandardAttribute.GERBER_STANDARD_ATTRIBUTE_NAME)) {
throw new IllegalStateException("Subclasses of StandardAttribute must provide a unique value for GERBER_STANDARD_ATTRIBUTE_NAME");
}
initialize(this);
}
/**
* Constructs and empty Gerber Standard Attribute. Call {@link #initialize(Attribute)} to
* initialize the contents with another Attribute.
*/
protected StandardAttribute() {
super();
if (getGerberStandardAttributeName().equals(StandardAttribute.GERBER_STANDARD_ATTRIBUTE_NAME)) {
throw new IllegalStateException("Subclasses of StandardAttribute must provide a unique value for GERBER_STANDARD_ATTRIBUTE_NAME");
}
}
/**
* Initializes and validates the standard attribute using the contents of the specified
* attribute.
*
* @param attribute the attribute whose contents are used to initialize the standard attribute
* @throws UnsupportedOperationException if the name of the specified attribute does not match
* the name of the standard attribute.
* @throws GerberLayerFormatException if the contents of the specified attribute are not valid
* per the Gerber Layer Format Specification.
*/
public void initialize(Attribute attribute) throws GerberLayerFormatException {
if (!getGerberStandardAttributeName().equals(attribute.getName())) {
throw new UnsupportedOperationException("Can not initialize standard attribute \"" +
getGerberStandardAttributeName() + "\" with contents of " + attribute.toString());
}
name = attribute.getName();
type = attribute.getType();
values = attribute.getValues();
validate();
}
/**
* Gets the standard attribute's name as specified in the Gerber Layer Format Specification,
* should always return a string beginning with a "." character.
*
* @return the standard attribute's name
*/
public abstract String getGerberStandardAttributeName();
/**
* Validates the Standard Attribute to ensure all values are of proper type and range.
* @throws GerberLayerFormatException if the contents of the specified attribute are not valid
* per the Gerber Layer Format Specification.
*/
public abstract void validate() throws GerberLayerFormatException;
/**
* Verifies the number of values this attribute has is exactly the expected count
* @param expectedCount the expected number of values
* @throws GerberLayerFormatException if the number of values is not correct
*/
protected void verifyValueCount(int expectedCount) throws GerberLayerFormatException {
int count = getValues().size();
if (count != expectedCount) {
throw new GerberLayerFormatException("Invalid number of values for Standard Attribute, "
+ "expected " + expectedCount + ", but found " + count + ": " + toString());
}
}
/**
* Verifies the number of values this attribute has is within the expected range
* @param minCount the minimum number of expected values
* @param maxCount the maximum number of expected values
* @throws GerberLayerFormatException if the number of values is not correct
*/
protected void verifyValueCount(int minCount, int maxCount) throws GerberLayerFormatException {
int count = getValues().size();
if (count < minCount || count > maxCount) {
throw new GerberLayerFormatException("Invalid number of values for Standard Attribute, "
+ "expected " + minCount + " to " + maxCount + ", but found " + count + ": "
+ toString());
}
}
}