org.esa.beam.util.Debug.assertNotNullOrEmpty()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(98)

本文整理了Java中org.esa.beam.util.Debug.assertNotNullOrEmpty()方法的一些代码示例,展示了Debug.assertNotNullOrEmpty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Debug.assertNotNullOrEmpty()方法的具体详情如下:
包路径:org.esa.beam.util.Debug
类名称:Debug
方法名:assertNotNullOrEmpty

Debug.assertNotNullOrEmpty介绍

[英]If the given String is null or empty, and the debugging functionality is enabled, this method throws an AssertionFailure in order to signal that an internal program post- or pre-condition failed.

Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the program.

For example, the method can be used to ensure valid arguments passed to private and protected methods.
[中]如果给定的字符串为null或空,并且调试功能已启用,则此方法将抛出AssertionFailure,以发出内部程序post或pre条件失败的信号。
只要必须确保源代码中的有效状态才能安全地继续程序,就使用此方法。
例如,该方法可用于确保传递给私有和受保护方法的有效参数。

代码示例

代码示例来源:origin: bcdev/beam

public static String[] createTags(int indent, String name, String[][] attributes) {
  Debug.assertNotNullOrEmpty(name);
  Debug.assertNotNull(attributes);
  final StringBuffer tag = new StringBuffer();
  final String indentWs = getIndentWhiteSpace(indent);
  tag.append(indentWs);
  tag.append("<");
  tag.append(name);
  for (int i = 0; i < attributes.length; i++) {
    final String[] att_val = attributes[i];
    if (att_val.length > 1) {
      final String attribute = att_val[0];
      final String value = att_val[1];
      if (attribute != null && attribute.length() > 0) {
        tag.append(" " + attribute + "=\"");
        if (value != null) {
          tag.append(encode(value));
        }
        tag.append("\"");
      }
    }
  }
  tag.append(">");
  final String[] tags = new String[2];
  tags[0] = tag.toString();
  tags[1] = indentWs + "</" + name + ">";
  return tags;
}

代码示例来源:origin: bcdev/beam

private static float resolveGadsValueFloat(String gadsRef, String gadsName, Record gadsRecord)
    throws DDDBException {
  Debug.assertNotNullOrEmpty(gadsRef);
  try {
    if (gadsName != null && gadsRef.startsWith(gadsName + ".")) {
      Debug.assertNotNull(gadsRecord);
      FieldRef fieldRef = FieldRef.parse(gadsRef);
      return gadsRecord.getFieldAt(fieldRef.getFieldIndex()).getElemFloat(fieldRef.getElemIndex());
    } else {
      return Float.parseFloat(gadsRef);
    }
  } catch (Exception e) {
    throw new DDDBException("failed to resolve GADS reference '" + gadsRef + "': " + e.getMessage()); /*I18N*/
  }
}

代码示例来源:origin: bcdev/beam

Debug.assertNotNullOrEmpty(null);
} catch (AssertionFailure e) {
  fail("no AssertionFailure expected");
  Debug.assertNotNullOrEmpty("");
} catch (AssertionFailure e) {
  fail("no AssertionFailure expected");
Debug.setWriter(new java.io.StringWriter());
try {
  Debug.assertNotNullOrEmpty("a");
} catch (AssertionFailure e) {
  fail("no AssertionFailure expected");
  Debug.assertNotNullOrEmpty(null);
  fail("AssertionFailure expected");
} catch (AssertionFailure e) {
  Debug.assertNotNullOrEmpty("");
  fail("AssertionFailure expected");
} catch (AssertionFailure e) {

代码示例来源:origin: bcdev/beam

static MetadataElement createMetadataGroup(String name, Record record) {
  Debug.assertNotNullOrEmpty(name);
  Debug.assertNotNull(record);
  MetadataElement metadataGroup = new MetadataElement(name);
  for (int i = 0; i < record.getNumFields(); i++) {
    Field field = record.getFieldAt(i);
    String description = field.getInfo().getDescription();
    if (description != null) {
      if ("Spare".equalsIgnoreCase(description)) {
        continue;
      }
    }
    MetadataAttribute attribute = new MetadataAttribute(field.getName(), field.getData(), true);
    if (field.getInfo().getPhysicalUnit() != null) {
      attribute.setUnit(field.getInfo().getPhysicalUnit());
    }
    if (description != null) {
      attribute.setDescription(field.getInfo().getDescription());
    }
    metadataGroup.addAttribute(attribute);
  }
  return metadataGroup;
}

相关文章