34
34
*/
35
35
public class VariableDS extends Variable implements VariableEnhanced , EnhanceScaleMissingUnsigned {
36
36
37
+
38
+
37
39
/**
38
40
* Constructor when there's no underlying variable.
39
41
* You must also set the values by doing one of:
@@ -269,8 +271,10 @@ Array convert(Array data, Set<NetcdfDataset.Enhance> enhancements) {
269
271
// datatype of the result depends on what enhancements were applied
270
272
DataType convertedType = data .getDataType ();
271
273
274
+
272
275
// TODO: change to a provider for extensible Enhancements
273
276
List <Enhancement > toApply = new ArrayList <>();
277
+
274
278
if (enhancements .contains (Enhance .ConvertUnsigned ) && unsignedConversion != null ) {
275
279
toApply .add (unsignedConversion );
276
280
convertedType = unsignedConversion .getOutType ();
@@ -283,15 +287,9 @@ Array convert(Array data, Set<NetcdfDataset.Enhance> enhancements) {
283
287
toApply .add (scaleOffset );
284
288
convertedType = scaleOffset .getScaledOffsetType ();
285
289
}
286
- if (enhancements .contains (Enhance .ApplyStandardizer ) && standardizer != null ) {
287
- toApply .add (standardizer );
288
- }
289
- if (enhancements .contains (Enhance .ApplyNormalizer ) && normalizer != null ) {
290
- toApply .add (normalizer );
291
- }
292
- if (enhancements .contains (Enhance .ApplyClassifier ) && classifier != null ) {
293
- toApply .add (classifier );
294
- }
290
+
291
+ toApply .addAll (loadedEnhancements );
292
+
295
293
296
294
double [] dataArray = (double []) data .get1DJavaArray (DataType .DOUBLE );
297
295
@@ -866,9 +864,8 @@ public Array convert(Array in, boolean convertUnsigned, boolean applyScaleOffset
866
864
// TODO make immutable in version 6
867
865
private UnsignedConversion unsignedConversion ;
868
866
private ScaleOffset scaleOffset ;
869
- private Standardizer standardizer ;
870
- private Normalizer normalizer ;
871
- private Classifier classifier ;
867
+ private List <Enhancement > loadedEnhancements = new ArrayList <>();
868
+
872
869
private ConvertMissing convertMissing ;
873
870
private Set <Enhance > enhanceMode = EnumSet .noneOf (Enhance .class ); // The set of enhancements that were made.
874
871
@@ -935,18 +932,14 @@ private void createEnhancements() {
935
932
}
936
933
this .dataType = scaleOffset != null ? scaleOffset .getScaledOffsetType () : this .dataType ;
937
934
}
938
- Attribute standardizerAtt = findAttribute (CDM .STANDARDIZE );
939
- if (standardizerAtt != null && this .enhanceMode .contains (Enhance .ApplyStandardizer ) && dataType .isFloatingPoint ()) {
940
- this .standardizer = Standardizer .createFromVariable (this );
941
- }
942
- Attribute normalizerAtt = findAttribute (CDM .NORMALIZE );
943
- if (normalizerAtt != null && this .enhanceMode .contains (Enhance .ApplyNormalizer ) && dataType .isFloatingPoint ()) {
944
- this .normalizer = Normalizer .createFromVariable (this );
945
- }
946
- Attribute classifierAtt = findAttribute (CDM .CLASSIFY );
947
- if (classifierAtt != null && this .enhanceMode .contains (Enhance .ApplyClassifier ) && dataType .isNumeric ()) {
948
- this .classifier = Classifier .createFromVariable (this );
935
+ for (Enhance enhance : this .enhanceMode ) {
936
+ for (EnhancementProvider service : ServiceLoader .load (EnhancementProvider .class )) {
937
+ if (service .appliesTo (enhance , this .attributes (), dataType )) {
938
+ loadedEnhancements .add (service .create (this ));
939
+ }
940
+ }
949
941
}
942
+
950
943
}
951
944
952
945
public Builder <?> toBuilder () {
0 commit comments