### Question:
ArraysConvert { public static ucar.ma2.Array convertFromArray(Array<?> from) { Preconditions.checkArgument(!(from instanceof ArrayVlen), "Cant convert Vlen"); Preconditions.checkArgument(from.dataType != DataType.OPAQUE, "Cant convert Opaque"); Preconditions.checkArgument(from.dataType != DataType.SEQUENCE, "Cant convert Sequence"); if (from.dataType == DataType.STRUCTURE) { return convertStructureDataArray(from); } ucar.ma2.Array values = ucar.ma2.Array.factory(from.getDataType(), from.getShape()); int count = 0; for (Object val : from) { values.setObject(count++, val); } return values; }  static Array<?> convertToArray(ucar.ma2.Array from); static ucar.ma2.Array convertFromArray(Array<?> from);  }### Answer:
@Test public void testConvert() { ucar.ma2.Array ma2 = ArraysConvert.convertFromArray(array); assertThat(ma2.getDataType()).isEqualTo(array.getDataType()); assertThat(ma2.getShape()).isEqualTo(array.getShape()); assertThat(ma2.getSize()).isEqualTo(array.length()); Iterator<Double> iter = array.iterator(); IndexIterator indexIter = ma2.getIndexIterator(); while (indexIter.hasNext() && iter.hasNext()) { assertThat(indexIter.getDoubleNext()).isEqualTo(iter.next()); } }
@Test public void testConvertStructureDataToMa2() throws IOException { ucar.ma2.Array ma2 = ArraysConvert.convertFromArray(structureDataArray); assertThat(ma2.getDataType()).isEqualTo(structureDataArray.getDataType()); assertThat(ma2.getShape()).isEqualTo(structureDataArray.getShape()); assertThat(ma2.getSize()).isEqualTo(structureDataArray.length()); Formatter f = new Formatter(); boolean ok = CompareArrayToMa2.compareData(f, "testConvertStructureDataToMa2", ma2, structureDataArray, false, true); if (!ok) { System.out.printf("%s%n", f); } assertThat(ok).isTrue(); }