Skip to content

Commit

Permalink
Remove deprecated uses of CompareNetcdfFile2.
Browse files Browse the repository at this point in the history
Deprecate CompareNetcdfFile, remove uses of it.
  • Loading branch information
JohnLCaron committed Jun 3, 2020
1 parent b889409 commit aed5334
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ucar.nc2.dt.GridDatatype;
import ucar.nc2.dt.grid.GridDataset;
import ucar.nc2.ft2.coverage.*;
import ucar.nc2.util.CompareNetcdf2;
import ucar.unidata.util.test.CompareNetcdf;
import ucar.unidata.util.test.category.NeedsCdmUnitTest;
import ucar.unidata.util.test.TestDir;
Expand Down Expand Up @@ -144,7 +145,7 @@ public void testWriteCoverage() throws IOException, InvalidRangeException {
logger.debug("{}", geotiff2.showInfo());

Formatter out = new Formatter();
geotiff.compare(geotiff2, out);
CompareNetcdf2.compareLists(geotiff.getTags(), geotiff2.getTags(), out);
logger.debug("{}", out.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private boolean doCompare(String location, boolean showCompare, boolean showEach

Formatter f = new Formatter();
CompareNetcdf2 tc = new CompareNetcdf2(f, showCompare, showEach, compareData);
boolean ok = tc.compare(ncfile, jni, new CompareNetcdf2.Netcdf4ObjectFilter(), showCompare, showEach, compareData);
boolean ok = tc.compare(ncfile, jni, new CompareNetcdf2.Netcdf4ObjectFilter());
System.out.printf(" %s compare %s ok = %s%n", ok ? "" : "***", location, ok);
if (!ok || (showCompare && showCompareResults))
System.out.printf("%s%n=====================================%n", f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private boolean compare(NetcdfFile nc1, NetcdfFile nc2, boolean showCompare, boo
throws IOException {
Formatter f = new Formatter();
CompareNetcdf2 tc = new CompareNetcdf2(f, showCompare, showEach, compareData);
boolean ok = tc.compare(nc1, nc2, new CompareNetcdf2.Netcdf4ObjectFilter(), showCompare, showEach, compareData);
boolean ok = tc.compare(nc1, nc2, new CompareNetcdf2.Netcdf4ObjectFilter());
System.out.printf(" %s compare %s to %s ok = %s%n", ok ? "" : "***", nc1.getLocation(), nc2.getLocation(), ok);
if (!ok)
System.out.printf(" %s%n", f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void compareDatasets() throws IOException {

Formatter f = new Formatter();
CompareNetcdf2 mind = new CompareNetcdf2(f, true, true, false);
boolean ok = mind.compare(ncfile, jni, new CompareNetcdf2.Netcdf4ObjectFilter(), true, true, false);
boolean ok = mind.compare(ncfile, jni, new CompareNetcdf2.Netcdf4ObjectFilter());
if (!ok) {
fail++;
System.out.printf("--Compare %s%n", filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void compareNcML(boolean useRecords, boolean explicit, boolean openDatas
try {
Formatter f = new Formatter();
CompareNetcdf2 mind = new CompareNetcdf2(f, false, false, compareData);
boolean ok = mind.compare(org, copy, new CompareNetcdf2.Netcdf4ObjectFilter(), false, false, compareData);
boolean ok = mind.compare(org, copy, new CompareNetcdf2.Netcdf4ObjectFilter());
if (!ok) {
fail++;
System.out.printf("--Compare %s, useRecords=%s explicit=%s openDataset=%s compareData=%s %n", location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void compareNcML(DatasetUrl durl, boolean useRecords, boolean explicit,
try {
Formatter f = new Formatter();
CompareNetcdf2 mind = new CompareNetcdf2(f, false, false, compareData);
boolean ok = mind.compare(org, copy, new CompareNetcdf2.Netcdf4ObjectFilter(), false, false, compareData);
boolean ok = mind.compare(org, copy, new CompareNetcdf2.Netcdf4ObjectFilter());
if (!ok) {
System.out.printf("--Compare %s, useRecords=%s explicit=%s openDataset=%s compareData=%s %n", durl.trueurl,
useRecords, explicit, openDataset, compareData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void compareNcML(boolean useRecords, boolean explicit, boolean openDatas
try {
Formatter f = new Formatter();
CompareNetcdf2 mind = new CompareNetcdf2(f, false, false, compareData);
boolean ok = mind.compare(org, copy, new CompareNetcdf2.Netcdf4ObjectFilter(), false, false, compareData);
boolean ok = mind.compare(org, copy, new CompareNetcdf2.Netcdf4ObjectFilter());
if (!ok) {
fail++;
System.out.printf("--Compare %s, useRecords=%s explicit=%s openDataset=%s compareData=%s %n", durl.trueurl,
Expand Down Expand Up @@ -249,7 +249,7 @@ public void compareNcMLold(boolean useRecords, boolean explicit, boolean openDat
try {
Formatter f = new Formatter();
CompareNetcdf2 mind = new CompareNetcdf2(f, false, false, compareData);
boolean ok = mind.compare(org, copy, new CompareNetcdf2.Netcdf4ObjectFilter(), false, false, compareData);
boolean ok = mind.compare(org, copy, new CompareNetcdf2.Netcdf4ObjectFilter());
if (!ok) {
fail++;
System.out.printf("--Compare %s, useRecords=%s explicit=%s openDataset=%s compareData=%s %n", durl.trueurl,
Expand Down
36 changes: 11 additions & 25 deletions cdm/core/src/main/java/ucar/nc2/util/CompareNetcdf2.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package ucar.nc2.util;

import javax.annotation.Nullable;
import ucar.nc2.constants.CDM;
import ucar.nc2.dataset.*;
import ucar.nc2.*;
Expand All @@ -20,16 +21,13 @@

/**
* Compare two NetcdfFile.
* Dont use assert, place results in Formatter.
* Doesnt fail (eg doesnt use assert), places results in Formatter.
*
* @deprecated will move in ver6
* TODO will move to test classes in ver6.
*/
@Deprecated
public class CompareNetcdf2 {
public static final ObjFilter IDENTITY_FILTER = new ObjFilter() {};

/** @deprecated will move in ver6. */
@Deprecated
public interface ObjFilter {
// if true, compare attribute, else skip comparision
default boolean attCheckOk(Variable v, Attribute att) {
Expand Down Expand Up @@ -57,9 +55,8 @@ default boolean compareCoordinateTransform(CoordinateTransform ct1, CoordinateTr
}
}

/** @deprecated will move in ver6. */
public static class Netcdf4ObjectFilter implements ObjFilter {
@Override

public boolean attCheckOk(Variable v, Attribute att) {
// if (v != null && v.isMemberOfStructure()) return false;
String name = att.getShortName();
Expand Down Expand Up @@ -159,18 +156,20 @@ public boolean compare(NetcdfFile org, NetcdfFile copy) {
return compare(org, copy, showCompare, showEach, compareData);
}

public boolean compare(NetcdfFile org, NetcdfFile copy, ObjFilter filter) {
public boolean compare(NetcdfFile org, NetcdfFile copy, @Nullable ObjFilter filter) {
return compare(org, copy, filter, showCompare, showEach, compareData);
}

/** @deprecated use constructor to set options, then compare(NetcdfFile org, NetcdfFile copy) */
@Deprecated
public boolean compare(NetcdfFile org, NetcdfFile copy, boolean showCompare, boolean showEach, boolean compareData) {
return compare(org, copy, null, showCompare, showEach, compareData);
}

/** @deprecated use constructor to set options, then compare(NetcdfFile org, NetcdfFile copy, ObjFilter filter) */
@Deprecated
public boolean compare(NetcdfFile org, NetcdfFile copy, ObjFilter objFilter, boolean showCompare, boolean showEach,
boolean compareData) {
public boolean compare(NetcdfFile org, NetcdfFile copy, @Nullable ObjFilter objFilter, boolean showCompare,
boolean showEach, boolean compareData) {
if (objFilter == null)
objFilter = IDENTITY_FILTER;
this.compareData = compareData;
Expand Down Expand Up @@ -239,19 +238,6 @@ public boolean compareVariables(NetcdfFile org, NetcdfFile copy) {
return ok;
}

/*
* private boolean compare(List<Dimension> dims1, List<Dimension> dims2) {
* if (dims1.size() != dims2.size()) return false;
* for (int i = 0; i < dims1.size(); i++) {
* Dimension dim1 = dims1.get(i);
* Dimension dim2 = dims2.get(i);
* //if (!dim1.getName().equals(dim2.getName())) return false;
* if (dim1.getLength() != dim2.getLength()) return false;
* }
* return true;
* }
*/

private boolean compareGroups(Group org, Group copy, ObjFilter objFilter) {
if (showCompare)
f.format("compare Group '%s' to '%s' %n", org.getShortName(), copy.getShortName());
Expand Down Expand Up @@ -884,8 +870,8 @@ public static void main(String[] arg) throws IOException {
compareData = true;
}

NetcdfFile ncfile1 = NetcdfDataset.open(file1);
NetcdfFile ncfile2 = NetcdfDataset.open(file2);
NetcdfFile ncfile1 = NetcdfDatasets.openFile(file1, null);
NetcdfFile ncfile2 = NetcdfDatasets.openFile(file2, null);
compareFiles(ncfile1, ncfile2, new Formatter(System.out), true, compareData, showEach);
ncfile1.close();
ncfile2.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void compare(String fileLocation) throws IOException {
try (NetcdfDataset withBuilder = NetcdfDatasets.openDataset(fileLocation)) {
Formatter f = new Formatter();
CompareNetcdf2 compare = new CompareNetcdf2(f, false, false, true);
boolean ok = compare.compare(org, withBuilder, new TestCoordSysCompare.CoordsObjFilter(), false, false, true);
boolean ok = compare.compare(org, withBuilder, new TestCoordSysCompare.CoordsObjFilter());
System.out.printf("%s %s%n", ok ? "OK" : "NOT OK", f);
assertThat(ok).isTrue();
}
Expand Down
3 changes: 2 additions & 1 deletion cdm/misc/src/main/java/ucar/nc2/geotiff/GeoTiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,12 @@ public String showInfo() {
return sw.toString();
}

/** @deprecated do not use */
@Deprecated
public void compare(GeoTiff other, Formatter f) {
CompareNetcdf2.compareLists(tags, other.getTags(), f);
}


//////////////////////////////////////////////////////////////////////////

// testing only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
/**
* Compare two NetcdfFile. Uses assert.
* Test classes only.
*
* @author john
*
* @deprecated use CompareNetcdf2
*/
@Deprecated
public class CompareNetcdf {

public static boolean compareFiles(NetcdfFile org, NetcdfFile copy) {
Expand Down
4 changes: 2 additions & 2 deletions uicdm/src/main/java/ucar/nc2/ui/op/DatasetViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private void compareBuilder() {
try (NetcdfFile withBuilder = NetcdfFiles.open(fileLocation)) {
Formatter f = new Formatter();
CompareNetcdf2 compare = new CompareNetcdf2(f, false, false, true);
boolean ok = compare.compare(org, withBuilder, new CoordsObjFilter(), false, false, true);
boolean ok = compare.compare(org, withBuilder, new CoordsObjFilter());
infoTA.setText(f.toString());
infoTA.gotoTop();
infoWindow.setTitle("Compare Old (file1) with Builder (file 2)");
Expand All @@ -275,7 +275,7 @@ private void compareBuilderDS() {
try (NetcdfDataset withBuilder = NetcdfDatasets.openDataset(fileLocation)) {
Formatter f = new Formatter();
CompareNetcdf2 compare = new CompareNetcdf2(f, false, false, true);
boolean ok = compare.compare(org, withBuilder, new CoordsObjFilter(), false, false, true);
compare.compare(org, withBuilder, new CoordsObjFilter());
infoTA.setText(f.toString());
infoTA.gotoTop();
infoWindow.setTitle("Compare Old (file1) with Builder (file 2)");
Expand Down

0 comments on commit aed5334

Please sign in to comment.