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

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

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

Debug.assertTrue介绍

[英]If the condition is NOT true, 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.
[中]如果condition为非真,并且已启用调试功能,则此方法将抛出AssertionFailure,以发出内部程序后置条件或前置条件失败的信号。
只要必须确保源代码中的有效状态才能安全地继续程序,就使用此方法。
例如,该方法可用于确保传递给私有和受保护方法的有效参数。

代码示例

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

/**
 * Constructs a new data item info from the supplied parameters.
 *
 * @param itemName     the item name, must not be null or empty
 * @param dataType     the internal data type. Must be one of the multiple <code>org.esa.beam.framework.datamodel.ProductData.TYPE_</code>X
 *                     constants
 * @param physicalUnit the item's physical unit (optional, can be null)
 * @param description  the item's description (optional, can be null)
 *
 * @see org.esa.beam.framework.datamodel.ProductData
 */
protected DataItemInfo(String itemName,
            int dataType,
            String physicalUnit,
            String description) {
  super(itemName, description);
  Debug.assertTrue(dataType != ProductData.TYPE_UNDEFINED,
           "undefined field data type"); /*I18N*/
  _dataType = dataType;
  _physicalUnit = physicalUnit;
}

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

/**
 * Constructs a new field-info from the supplied parameters.
 *
 * @param fieldName    the field name, must not be null or empty
 * @param dataType     the internal data type. Must be one of the multiple <code>TYPE_</code>XXX constants defined
 *                     in the <code>org.esa.beam.framework.datamodel.ProductData</code> interface.
 * @param numDataElems the number of data elements contained in this field (field-width), must be <code>&gt;=
 *                     1</code>.
 * @param physicalUnit the field's unit (optional, can be null)
 * @param description  the field's description (optional, can be null)
 *
 * @see org.esa.beam.framework.datamodel.ProductData
 */
FieldInfo(String fieldName,
     int dataType,
     int numDataElems,
     String physicalUnit,
     String description) {
  super(fieldName, dataType, physicalUnit, description);
  Debug.assertTrue(numDataElems >= 1,
           "number of data elements must be greater zero"); /*I18N*/
  _numDataElems = numDataElems;
}

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

/**
 * Constructs a new DSD from the given SPH parameters.
 *
 * @param index         the zero-based index of this DSD within the SPH.
 * @param datasetName   the name of the dataset.
 * @param datasetType   the type of the dataset.
 * @param fileName      the file name of an external dataset types (type 'R').
 * @param datasetOffset the dataset offset in bytes within the data product file.
 * @param datasetSize   the dataset size in bytes.
 * @param numRecords    the number of records contained in the dataset.
 * @param recordSize    the size in bytes of each record contained in the dataset.
 */
public DSD(int index,
      String datasetName,
      char datasetType,
      String fileName,
      long datasetOffset,
      long datasetSize,
      int numRecords,
      int recordSize) {
  Debug.assertTrue(datasetName != null);
  this.index = index;
  this.datasetName = datasetName;
  this.datasetType = datasetType;
  this.fileName = fileName;
  this.datasetOffset = datasetOffset;
  this.datasetSize = datasetSize;
  this.numRecords = numRecords;
  this.recordSize = recordSize;
}

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

private MetadataElement createDatasetTable(String name, RecordReader recordReader) throws IOException {
  Debug.assertTrue(productFile != null);
  Debug.assertTrue(name != null);
  Debug.assertTrue(recordReader != null);
  Record record = recordReader.readRecord();
  return createMetadataGroup(name, record);
}

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

public Object parse(Parameter parameter, String text) throws ParamParseException {
  Debug.assertTrue(text != null);
  if (isAllowedNullText(parameter, text)) {
    return null;
  }
  return text;
}

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

public Object parse(Parameter parameter, String text) throws ParamParseException {
  Debug.assertTrue(text != null);
  String trimedText = text.trim();
  if (isAllowedNullText(parameter, trimedText)) {
    return null;
  }
  return new File(trimedText);
}

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

public Object parse(Parameter parameter, String text) throws ParamParseException {
  Debug.assertTrue(text != null);
  String trimedText = text.trim();
  if (isAllowedNullText(parameter, trimedText)) {
    return null;
  }
  if (trimedText.equalsIgnoreCase(TRUE_STRING)) {
    return Boolean.TRUE;
  } else if (trimedText.equalsIgnoreCase(FALSE_STRING)) {
    return Boolean.FALSE;
  } else {
    throw new ParamParseException(parameter, ParamConstants.ERR_MSG_INVALID_BOOLEAN); /*I18N*/
  }
}

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

private MetadataElement createMetadataTableGroup(String name, RecordReader recordReader) throws IOException {
  Debug.assertTrue(productFile != null);
  Debug.assertTrue(name != null);
  Debug.assertTrue(recordReader != null);
  MetadataElement metadataTableGroup = new MetadataElement(name);
  StringBuilder sb = new StringBuilder(16);
  for (int i = 0; i < recordReader.getNumRecords(); i++) {
    Record record = recordReader.readRecord(i);
    sb.setLength(0);
    sb.append(name);
    sb.append('.');
    sb.append(i + 1);
    metadataTableGroup.addElement(createMetadataGroup(sb.toString(), record));
  }
  return metadataTableGroup;
}

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

/**
 * Gets product specific information from the database.
 *
 * @param productType the product type id
 *
 * @return a new product info instance, never <code>null</code>
 *
 * @throws java.lang.IllegalArgumentException
 *          if <code>productType</code> is null
 * @throws org.esa.beam.dataio.envisat.DDDBException
 *          if a database I/O error occurs
 */
private ProductInfo getProductInfo(String productType) throws DDDBException {
  Guardian.assertNotNull("productType", productType);
  ProductInfo productInfo = (ProductInfo) _productInfoCache.get(productType);
  if (productInfo != null) {
    return productInfo;
  }
  productInfo = readProductInfo(productType);
  Debug.assertTrue(productInfo != null);
  _productInfoCache.put(productType, productInfo);
  return productInfo;
}

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

public Object parse(Parameter parameter, String text) throws ParamParseException {
  Debug.assertTrue(text != null);
  if (isAllowedNullText(parameter, text.trim())) {
    return null;
  }
  Color c = StringUtils.parseColor(text);
  if (c == null) {
    throw new ParamParseException(parameter, ParamConstants.ERR_MSG_INVALID_COLOR); /*I18N*/
  }
  return c;
}

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

/**
 * Constructs a <code>ProductFile</code> for the given seekable data input stream.
 *
 * @param file            the abstract file path representation.
 * @param dataInputStream the seekable data input stream which will be used to read data from the product file.
 * @param lineInterleaved if true the Envisat file is expected to be in line interleaved storage format
 *
 * @throws java.io.IOException if an I/O error occurs
 */
protected ProductFile(File file, ImageInputStream dataInputStream, boolean lineInterleaved) throws IOException {
  Debug.assertTrue(dataInputStream != null);
  this.file = file;
  this.dataInputStream = dataInputStream;
  this.lineInterleaved = lineInterleaved;
  this.logger = BeamLogManager.getSystemLogger();
  init();
}

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

private void setSelectedIndices(Parameter parameter) {
    if (parameter.getValue() != null) {
      Debug.assertTrue(parameter.getValue() instanceof String[]);
      Debug.assertTrue(parameter.getValidator() instanceof StringArrayValidator);
      int[] indexes = ((StringArrayValidator) parameter.getValidator()).getValueSetIndices(parameter);
      _list.setSelectedIndices(indexes);
    }
  }
}

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

/**
 * Constructs a new record for the given record info. The record info tells the constructor which and how many
 * fields to be internally created.
 *
 * @param info the record info, must not be null
 */
private Record(RecordInfo info) {
  Debug.assertTrue(info != null);
  _info = info;
  _fields = new Field[info.getNumFieldInfos()];
  for (int i = 0; i < _fields.length; i++) {
    _fields[i] = info.getFieldInfoAt(i).createField();
  }
}

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

public Object parse(Parameter parameter, String text) throws ParamParseException {
  Debug.assertTrue(text != null);
  if (isAllowedNullText(parameter, text)) {
    // return null, since null values are allowed
    return null;
  }
  final ParamProperties props = parameter.getProperties();
  final char[] separators = new char[]{props.getValueSetDelim()};
  return StringUtils.split(text, separators, true);
}

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

/**
 * Returns the flag mask value for the specified flag name.
 *
 * @param name the flag name
 * @return flagMask the flag's bit mask as a 32 bit integer
 * @throws IllegalArgumentException if <code>name</code> is null, or a flag with the name does not exist
 */
public int getIndexValue(String name) {
  Guardian.assertNotNull("name", name);
  MetadataAttribute attribute = getAttribute(name);
  if (attribute == null) {
    throw new IllegalArgumentException("index '" + name + "' not found");
  }
  Debug.assertTrue(attribute.getData().isInt());
  Debug.assertTrue(attribute.getData().isScalar());
  return attribute.getData().getElemInt();
}

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

/**
 * Creates an appropriate validator for this parameter info.
 *
 * @return a validator, never <code>null</code>
 */
public ParamValidator createValidator() {
  ParamValidator validator = null;
  Class validatorClass = getValidatorClass();
  if (validatorClass != null) {
    try {
      validator = (ParamValidator) validatorClass.newInstance();
    } catch (Exception e) {
      // @todo 1 nf/nf - throw exception ??? I think so!
      Debug.trace(e);
    }
  }
  if (validator == null) {
    validator = ParamValidatorRegistry.getValidator(getValueType());
  }
  Debug.assertTrue(validator != null);
  return validator;
}

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

/**
 * Returns the flag mask value for the specified flag name.
 *
 * @param name the flag name
 * @return flagMask the flag's bit mask as a 32 bit integer
 * @throws IllegalArgumentException if <code>name</code> is null, or a flag with the name does not exist
 */
public int getFlagMask(String name) {
  Guardian.assertNotNull("name", name);
  MetadataAttribute attribute = getAttribute(name);
  if (attribute == null) {
    throw new IllegalArgumentException("flag '" + name + "' not found");
  }
  Debug.assertTrue(attribute.getData().isInt());
  Debug.assertTrue(attribute.getData().isScalar());
  return attribute.getData().getElemInt();
}

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

/**
 * Parses a boolean expression.
 * @param parameter the expression parameter
 * @param text the expression text to be parsed
 * @return the validated text
 * @throws org.esa.beam.framework.param.ParamParseException
 */
@Override
public Object parse(Parameter parameter, String text) throws ParamParseException {
  Debug.assertTrue(text != null);
  if (isAllowedNullText(parameter, text)) {
    return null;
  }
  Parser parser = getParser(parameter);
  try {
    parser.parse(text);
  } catch (ParseException e) {
    throw new ParamParseException(parameter, e.getMessage());
  }
  // Just return text.
  return text;
}

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

private RasterDataNode getRaster(int varIndex) {
  final Product product = getProduct();
  if (product == null) {
    return null;
  }
  final String rasterName;// = rasterNameParams[varIndex].getValue().toString();
  if (varIndex == X_VAR) {
    rasterName = dataSourceConfig.xBand.getName();
  } else {
    rasterName = dataSourceConfig.yBand.getName();
  }
  RasterDataNode raster = product.getRasterDataNode(rasterName);
  if (raster == null) {
    if (getRaster() != null && rasterName.equalsIgnoreCase(getRaster().getName())) {
      raster = getRaster();
    }
  }
  Debug.assertTrue(raster != null);
  return raster;
}

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

/**
 * Reads the record with the given zero-based index from from the product file.
 * <p/>
 * <p> In order to reduce memory allocation, the method accepts an optional record argument. If this record is not
 * null, it will be used to read in the data. If it is null, a new record will be created.
 *
 * @param index  the record index, must be <code>&gt;=0</code> and <code>&lt;getDSD().getDatasetOffset()</code>
 * @param record record to be recycled, can be <code>null</code>
 * @throws java.io.IOException if an I/O error occurs
 * @throws java.lang.IndexOutOfBoundsException if the index is out of bounds
 */
@Override
public Record readRecord(int index, Record record) throws IOException {
  if (record == null) {
    record = createCompatibleRecord();
  }
  Debug.assertTrue(record.getInfo() == getRecordInfo());
  final ProductFile productFile = getProductFile();
  if (getDSD().getDatasetType() == 'M') {
    index = productFile.getMappedMDSRIndex(index);
  }
  long pos = headerSize + index * recordLength + recordOffset;
  final ImageInputStream istream = productFile.getDataInputStream();
  synchronized (istream) {
    istream.seek(pos);
    record.readFrom(istream);
  }
  return record;
}

相关文章