Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions bufr/src/main/java/ucar/nc2/iosp/bufr/BufrIospBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BufrIospBuilder {
private static final boolean warnUnits = false;

private final Group.Builder rootGroup;
private Sequence.Builder recordStructure;
private Sequence.Builder<?> recordStructure;
private final Formatter coordinates = new Formatter();

private int tempNo = 1; // fishy
Expand Down Expand Up @@ -69,7 +69,7 @@ class BufrIospBuilder {

for (BufrConfig bufrConfig : bufrConfigs) {
String varName = proto.getLookup().getCategoryName(bufrConfig.getMessage().ids.getCategory());
Sequence.Builder rs = Sequence.builder().setName(varName);
Sequence.Builder<?> rs = Sequence.builder().setName(varName);
this.rootGroup.addVariable(rs);
makeObsRecord(bufrConfig, rs);
String coordS = coordinates.toString();
Expand Down Expand Up @@ -103,7 +103,7 @@ private void addCommonGlobalAttributes(AttributeContainerMutable atts, Message p
}
}

Sequence.Builder getObsStructure() {
Sequence.Builder<?> getObsStructure() {
return recordStructure;
}

Expand All @@ -129,7 +129,7 @@ private void makeObsRecord(BufrConfig bufrConfig) {
addDpiStructure(recordStructure, fld, subFld);

} else if (subDds.replication == 1) { // one member not a replication
Variable.Builder v = addVariable(rootGroup, recordStructure, subFld, dkey.replication);
Variable.Builder<?> v = addVariable(rootGroup, recordStructure, subFld, dkey.replication);
v.setSPobject(fld); // set the replicating field as SPI object

} else { // one member is a replication (two replications in a row)
Expand All @@ -145,7 +145,7 @@ private void makeObsRecord(BufrConfig bufrConfig) {
}
}

private void makeObsRecord(BufrConfig bufrConfig, Sequence.Builder rs) {
private void makeObsRecord(BufrConfig bufrConfig, Sequence.Builder<?> rs) {
BufrConfig.FieldConverter root = bufrConfig.getRootConverter();
for (BufrConfig.FieldConverter fld : root.flds) {
DataDescriptor dkey = fld.dds;
Expand All @@ -167,7 +167,7 @@ private void makeObsRecord(BufrConfig bufrConfig, Sequence.Builder rs) {
addDpiStructure(rs, fld, subFld);

} else if (subDds.replication == 1) { // one member not a replication
Variable.Builder v = addVariable(rootGroup, rs, subFld, dkey.replication);
Variable.Builder<?> v = addVariable(rootGroup, rs, subFld, dkey.replication);
v.setSPobject(fld); // set the replicating field as SPI object

} else { // one member is a replication (two replications in a row)
Expand All @@ -183,12 +183,13 @@ private void makeObsRecord(BufrConfig bufrConfig, Sequence.Builder rs) {
}
}

private void addStructure(Group.Builder group, Structure.Builder parent, BufrConfig.FieldConverter fld, int count) {
private void addStructure(Group.Builder group, Structure.Builder<?> parent, BufrConfig.FieldConverter fld,
int count) {
DataDescriptor dkey = fld.dds;
String uname = findUniqueName(parent, fld.getName(), "struct");
dkey.name = uname; // name may need to be changed for uniqueness

Structure.Builder struct = Structure.builder().setName(uname);
Structure.Builder<?> struct = Structure.builder().setName(uname);
struct.setDimensionsAnonymous(new int[] {count}); // anon vector
for (BufrConfig.FieldConverter subKey : fld.flds) {
addMember(group, struct, subKey);
Expand All @@ -198,12 +199,12 @@ private void addStructure(Group.Builder group, Structure.Builder parent, BufrCon
struct.setSPobject(fld);
}

private void addSequence(Group.Builder group, Structure.Builder parent, BufrConfig.FieldConverter fld) {
private void addSequence(Group.Builder group, Structure.Builder<?> parent, BufrConfig.FieldConverter fld) {
DataDescriptor dkey = fld.dds;
String uname = findUniqueName(parent, fld.getName(), "seq");
dkey.name = uname; // name may need to be changed for uniqueness

Sequence.Builder seq = Sequence.builder().setName(uname);
Sequence.Builder<?> seq = Sequence.builder().setName(uname);
for (BufrConfig.FieldConverter subKey : fld.flds) {
addMember(group, seq, subKey);
}
Expand All @@ -212,7 +213,7 @@ private void addSequence(Group.Builder group, Structure.Builder parent, BufrConf
seq.setSPobject(fld);
}

private void addMember(Group.Builder group, Structure.Builder parent, BufrConfig.FieldConverter fld) {
private void addMember(Group.Builder group, Structure.Builder<?> parent, BufrConfig.FieldConverter fld) {
DataDescriptor dkey = fld.dds;

if (dkey.replication == 0) {
Expand All @@ -221,7 +222,7 @@ private void addMember(Group.Builder group, Structure.Builder parent, BufrConfig
List<DataDescriptor> subKeys = dkey.subKeys;
if (subKeys.size() == 1) {
BufrConfig.FieldConverter subFld = fld.flds.get(0);
Variable.Builder v = addVariable(group, parent, subFld, dkey.replication);
Variable.Builder<?> v = addVariable(group, parent, subFld, dkey.replication);
v.setSPobject(fld); // set the replicating field as SPI object

} else {
Expand All @@ -233,18 +234,18 @@ private void addMember(Group.Builder group, Structure.Builder parent, BufrConfig
}
}

private void addDpiStructure(Structure.Builder parent, BufrConfig.FieldConverter parentFld,
private void addDpiStructure(Structure.Builder<?> parent, BufrConfig.FieldConverter parentFld,
BufrConfig.FieldConverter dpiField) {
DataDescriptor dpiKey = dpiField.dds;
String uname = findUniqueName(parent, dpiField.getName(), "struct");
dpiKey.name = uname; // name may need to be changed for uniqueness

Structure.Builder struct = Structure.builder().setName(uname);
Structure.Builder<?> struct = Structure.builder().setName(uname);
parent.addMemberVariable(struct);
int n = parentFld.dds.replication;
struct.setDimensionsAnonymous(new int[] {n}); // anon vector

Variable.Builder v = Variable.builder().setName("name");
Variable.Builder<?> v = Variable.builder().setName("name");
v.setDataType(DataType.STRING); // scalar
struct.addMemberVariable(v);

Expand All @@ -255,11 +256,11 @@ private void addDpiStructure(Structure.Builder parent, BufrConfig.FieldConverter
struct.setSPobject(dpiField); // ??
}

private void addDpiSequence(Structure.Builder parent, BufrConfig.FieldConverter fld) {
Structure.Builder struct = Structure.builder().setName("statistics");
private void addDpiSequence(Structure.Builder<?> parent, BufrConfig.FieldConverter fld) {
Structure.Builder<?> struct = Structure.builder().setName("statistics");
struct.setDimensionsAnonymous(new int[] {fld.dds.replication}); // scalar

Variable.Builder v = Variable.builder().setName("name");
Variable.Builder<?> v = Variable.builder().setName("name");
v.setDataType(DataType.STRING); // scalar
struct.addMemberVariable(v);

Expand All @@ -270,13 +271,13 @@ private void addDpiSequence(Structure.Builder parent, BufrConfig.FieldConverter
parent.addMemberVariable(struct);
}

private Variable.Builder addVariable(Group.Builder group, Structure.Builder struct, BufrConfig.FieldConverter fld,
int count) {
private Variable.Builder<?> addVariable(Group.Builder group, Structure.Builder<?> struct,
BufrConfig.FieldConverter fld, int count) {
DataDescriptor dkey = fld.dds;
String uname = findGloballyUniqueName(fld.getName(), "unknown");
dkey.name = uname; // name may need to be changed for uniqueness

Variable.Builder v = Variable.builder().setName(uname);
Variable.Builder<?> v = Variable.builder().setName(uname);
if (count > 1) {
v.setDimensionsAnonymous(new int[] {count}); // anon vector
}
Expand All @@ -287,7 +288,7 @@ private Variable.Builder addVariable(Group.Builder group, Structure.Builder stru

if (fld.getUnits() == null) {
if (warnUnits) {
log.warn("dataDesc.units == null for " + uname);
log.warn("dataDesc.units == null for {}", uname);
}
} else {
String units = fld.getUnits();
Expand Down Expand Up @@ -432,7 +433,7 @@ private String findGloballyUniqueName(String want, String def) {
}


private void annotate(Variable.Builder v, BufrConfig.FieldConverter fld) {
private void annotate(Variable.Builder<?> v, BufrConfig.FieldConverter fld) {
if (fld.type == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ private boolean compareGroups(Group org, Group copy, Formatter f) {
}

// nested groups
List groups = new ArrayList();
List<Group> groups = new ArrayList<>();
ok &= checkAll(org.getGroups(), copy.getGroups(), groups, f);
for (int i = 0; i < groups.size(); i += 2) {
Group orgGroup = (Group) groups.get(i);
Group ncmlGroup = (Group) groups.get(i + 1);
Group orgGroup = groups.get(i);
Group ncmlGroup = groups.get(i + 1);
ok &= compareGroups(orgGroup, ncmlGroup, f);
}

Expand Down Expand Up @@ -211,11 +211,11 @@ private boolean compareVariables(Variable org, Variable copy, boolean compareDat
Structure orgS = (Structure) org;
Structure ncmlS = (Structure) copy;

List vars = new ArrayList();
List<Variable> vars = new ArrayList<>();
ok &= checkAll(orgS.getVariables(), ncmlS.getVariables(), vars, f);
for (int i = 0; i < vars.size(); i += 2) {
Variable orgV = (Variable) vars.get(i);
Variable ncmlV = (Variable) vars.get(i + 1);
Variable orgV = vars.get(i);
Variable ncmlV = vars.get(i + 1);
ok &= compareVariables(orgV, ncmlV, false, f);
}
}
Expand All @@ -224,7 +224,7 @@ private boolean compareVariables(Variable org, Variable copy, boolean compareDat
}

// make sure each object in wantList is contained in container, using equals().
public static boolean checkContains(List container, List wantList, Formatter f) {
public static boolean checkContains(List<?> container, List<?> wantList, Formatter f) {
boolean ok = true;

for (Object want1 : wantList) {
Expand All @@ -241,22 +241,21 @@ public static boolean checkContains(List container, List wantList, Formatter f)

// make sure each object in each list are in the other list, using equals().
// return an arrayList of paired objects.
private boolean checkAll(List list1, List list2, List result, Formatter f) {
private <T> boolean checkAll(List<T> list1, List<T> list2, List<T> result, Formatter f) {
boolean ok = true;

for (Object aList1 : list1) {
for (T aList1 : list1) {
ok &= checkEach(aList1, "file1", list1, "file2", list2, result, f);
}

for (Object aList2 : list2) {
for (T aList2 : list2) {
ok &= checkEach(aList2, "file2", list2, "file1", list1, result, f);
}

return ok;
}

// check that want is in both list1 and list2, using object.equals()
private boolean checkEach(Object want1, String name1, List list1, String name2, List list2, List result,
private <T> boolean checkEach(T want1, String name1, List<T> list1, String name2, List<T> list2, List<T> result,
Formatter f) {
boolean ok = true;
try {
Expand All @@ -265,14 +264,13 @@ private boolean checkEach(Object want1, String name1, List list1, String name2,
f.format(" ** %s %s (%s) not in %s %n", want1.getClass().getName(), want1, name1, name2);
ok = false;
} else { // found it in second list
Object want2 = list2.get(index2);
T want2 = list2.get(index2);
int index1 = list1.indexOf(want2);
if (index1 < 0) { // can this happen ??
f.format(" ** %s %s (%s) not in %s %n", want2.getClass().getName(), want2, name2, name1);
ok = false;

} else { // found it in both lists
Object want = list1.get(index1);
T want = list1.get(index1);
if (want != want1) {
f.format(" ** %s %s (%s) not equal to %s (%s) %n", want1.getClass().getName(), want1, name1, want2, name2);
ok = false;
Expand All @@ -286,11 +284,9 @@ private boolean checkEach(Object want1, String name1, List list1, String name2,
}
}
}

} catch (Throwable t) {
f.format(" *** Throwable= %s %n", t.getMessage());
}

return ok;
}

Expand Down
5 changes: 4 additions & 1 deletion cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static ucar.nc2.constants.CDM.ARRAYDIMENSIONS;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

import ucar.ma2.ArrayObject;
Expand Down Expand Up @@ -38,6 +39,8 @@ public class ZarrHeader {
private final String rootLocation;

private static final ObjectMapper objectMapper = new ObjectMapper();
private static final JavaType ATTR_MAP_TYPE =
objectMapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);

public ZarrHeader(RandomAccessDirectory raf, Group.Builder rootGroup) {
this.rootRaf = raf;
Expand Down Expand Up @@ -340,7 +343,7 @@ private List<Attribute> makeAttributes(RandomAccessDirectoryItem item) {
RandomAccessFile raf = item.getOrOpenRaf();
// read attributes from file
raf.seek(0);
Map<String, Object> attrMap = objectMapper.readValue(raf, HashMap.class);
Map<String, Object> attrMap = objectMapper.readValue(raf, ATTR_MAP_TYPE);

// create Attribute objects
List<Attribute> attrs = new ArrayList<>();
Expand Down
5 changes: 3 additions & 2 deletions grib/src/main/java/ucar/nc2/grib/coord/CoordinateND.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void addRecord(T gr) {
}

public CoordinateND<T> finish(List<T> records, Formatter info) {
for (CoordinateBuilder builder : builders) {
for (CoordinateBuilder<T> builder : builders) {
Coordinate coord = builder.finish();
if (coord.getType() == Coordinate.Type.time2D)
coordb.add(((CoordinateTime2D) coord).getRuntimeCoordinate());
Expand All @@ -103,7 +103,8 @@ SparseArray<T> buildSparseArray(List<T> records, Formatter info) {
int count = 0;
for (CoordinateBuilder<T> builder : builders) {
if (builder instanceof CoordinateBuilder.TwoD) {
CoordinateBuilder.TwoD<T> builder2D = (CoordinateBuilder.TwoD) builder;
@SuppressWarnings("unchecked")
CoordinateBuilder.TwoD<T> builder2D = (CoordinateBuilder.TwoD<T>) builder;
int[] coordsIdx = builder2D.getCoordIndices(gr);
index[count++] = coordsIdx[0];
index[count++] = coordsIdx[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ public class TestCoordinateUniquify {
@Test
public void testCoordinateUnionizer() {

List<CoordinateND> coordNDs = new ArrayList<>();
List<CoordinateND<Short>> coordNDs = new ArrayList<>();
for (int i = 5; i < 15; i += 2) {
coordNDs.add(TestCoordinateND.makeCoordinateND(i));
}

CoordinateSharerBest unionizer = new CoordinateSharerBest();
for (CoordinateND coordND : coordNDs) {
for (CoordinateND<Short> coordND : coordNDs) {
unionizer.addCoordinates(coordND.getCoordinates());
}
List<Coordinate> shared = unionizer.finish();

Formatter f = new Formatter();
f.format("Original%n");
for (CoordinateND coordND : coordNDs) {
for (CoordinateND<Short> coordND : coordNDs) {
coordND.showInfo(f, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import javax.annotation.concurrent.ThreadSafe;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Centralized management of the connections used by HTTPSession/HTTPMethod.
Expand Down Expand Up @@ -87,7 +85,7 @@ public void setClientManager(HttpClientBuilder cb, HTTPMethod method) {

protected Registry<ConnectionSocketFactory> getRegistry() {
if (this.protocolregistry == null) {
RegistryBuilder rb = RegistryBuilder.<ConnectionSocketFactory>create();
RegistryBuilder<ConnectionSocketFactory> rb = RegistryBuilder.create();
for (HashMap.Entry<String, ConnectionSocketFactory> entry : protocols.entrySet()) {
rb.register(entry.getKey(), entry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class HTTPFactory {
// HTTPMethod, provide a static global
// than can be set by a test program.

public static java.lang.Class MOCKMETHODCLASS = null;
public static Class<? extends HTTPMethod> MOCKMETHODCLASS = null;

//////////////////////////////////////////////////////////////////////////
// Static factory methods for creating HTTPSession instances
Expand Down Expand Up @@ -116,9 +116,9 @@ protected static HTTPMethod makemethod(HTTPSession.Methods m, HTTPSession sessio
HTTPMethod meth = null;
if (MOCKMETHODCLASS == null) { // do the normal case
meth = new HTTPMethod(m, session, url);
} else {// (MOCKMETHODCLASS != null)
java.lang.Class methodcl = MOCKMETHODCLASS;
Constructor<HTTPMethod> cons = null;
} else { // (MOCKMETHODCLASS != null)
Class<? extends HTTPMethod> methodcl = MOCKMETHODCLASS;
Constructor<? extends HTTPMethod> cons;
try {
cons = methodcl.getConstructor(HTTPSession.Methods.class, HTTPSession.class, String.class);
} catch (Exception e) {
Expand Down
Loading
Loading