org.esa.beam.util.Debug类的使用及代码示例

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

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

Debug介绍

[英]The Debug as it name says is a utility class for debugging. It contains exculisvely static methods and cannot be instantiated.

This class provides methods for program assertions as well as tracing capabilities. The tracing output can be redirected to any java.io.XMLCoder. The debbuging capabilities of this class can be disabled at runtime by calling Debug.setEnabled(false).

The methods defined in this class are guaranteed not to throw any exceptions caused by illegal argument passed to them.
[中]顾名思义,Debug是一个用于调试的实用程序类。它包含非常静态的方法,无法实例化。
此类提供程序断言的方法以及跟踪功能。跟踪输出可以重定向到任何java.io.XMLCoder。可以在运行时通过调用Debug.setEnabled(false)禁用该类的去bug功能。
此类中定义的方法保证不会抛出由传递给它们的非法参数引起的任何异常。

代码示例

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

@Override
public void dockableFrameFloating(DockableFrameEvent dockableFrameEvent) {
  Debug.trace("dockableFrameEvent = " + dockableFrameEvent);
  ensurePageComponentControlCreated();
}

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

@Override
protected void setUp() {
  //_oldDebugState = Debug.setEnabled(true);
  _oldDebugState = Debug.setEnabled(false);
}

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

private static void closeCsvReader(CsvReader csvReader, URL url) {
  Debug.assertNotNull(csvReader);
  Debug.assertNotNull(url);
  try {
    csvReader.close();
  } catch (IOException e) {
    Debug.trace("DDDB: I/O warning: failed to close DDDB file: " /*I18N*/
          + url
          + ": "
          + e.getMessage());
  }
}

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

/**
 * Gets the current writer that will used for debugging output. If no writer was explicitely set by the user, the
 * default writer is returned.
 *
 * @return the current writer, or <code>null</code> if debugging is disabled
 */
public static PrintWriter getWriter() {
  if (isEnabled() && _writer == null) {
    _writer = getDefaultWriter();
  }
  return _writer;
}

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

/**
 * Sets the current writer for the given stream that will be used for debugging output.
 *
 * @param stream the stream that will be used for debugging output
 */
public static void setWriter(OutputStream stream) {
  if (isEnabled() && stream != null) {
    _writer = createPrintWriter(stream);
  }
}

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

/**
 * If the given object is null, and the debugging functionality is enabled, this method throws an
 * <code>AssertionFailure</code> in order to signal that an internal program post- or pre-condition failed.
 * <p/>
 * <p> Use this method whenever a valid state must be ensured within your sourcecode in order to safely continue the
 * program.
 * <p/>
 * <p> For example, the method can be used to ensure valid arguments passed to private and protected methods.
 *
 * @param object the object to test for non-null condition
 *
 * @throws AssertionFailure if <code>object</code> is null and the debugging functionality is enabled
 */
public static void assertNotNull(Object object) throws AssertionFailure {
  if (isEnabled()) {
    if (object == null) {
      handleAssertionFailed(UtilConstants.MSG_OBJECT_NULL);
    }
  }
}

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

public void trace(String label) {
    if (Debug.isEnabled()) {
      Debug.trace(label + ": " + getTimeDiffString());
    }
  }
}

代码示例来源: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

/**
 * Constructs a new dataset reader for ENVISAT products.
 *
 * @param productFile the product file which is creating this reader
 * @param dsd         the DSD which describes the dataset to be read
 * @param recordInfo  the description of the record structure of which the dataset is composed of
 */
RecordReader(ProductFile productFile, DSD dsd, RecordInfo recordInfo) {
  Debug.assertNotNull(productFile);
  Debug.assertNotNull(dsd);
  Debug.assertNotNull(recordInfo);
  _productFile = productFile;
  _dsd = dsd;
  _recordInfo = recordInfo;
}

代码示例来源: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

public void testAssertWidthoutMessage() {
  Debug.setEnabled(false);
  try {
    Debug.assertTrue(true);
  } catch (AssertionFailure e) {
    fail("no AssertionFailure expected");
  }
  try {
    Debug.assertTrue(false);
  } catch (AssertionFailure e) {
    fail("no AssertionFailure expected");
  }
  Debug.setEnabled(true);
  java.io.StringWriter sw = new java.io.StringWriter();
  Debug.setWriter(sw);
  try {
    Debug.assertTrue(true);
  } catch (AssertionFailure e) {
    fail("no AssertionFailure expected");
  }
  try {
    Debug.assertTrue(false);
    fail("AssertionFailure expected");
  } catch (AssertionFailure e) {
  }
  String assertionFailureMsg = sw.getBuffer().toString();
  String expectedContent = Debug.class.getName();
  assertEquals(true, assertionFailureMsg.indexOf(expectedContent) >= 0);
}

代码示例来源: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

public void testAssertNotNull() {
  Debug.setEnabled(false);
  try {
    Debug.assertNotNull(new Object());
  } catch (AssertionFailure e) {
    fail("no AssertionFailure expected");
  }
  try {
    Debug.assertNotNull(null);
  } catch (AssertionFailure e) {
    fail("no AssertionFailure expected");
  }
  Debug.setEnabled(true);
  Debug.setWriter(new java.io.StringWriter());
  try {
    Debug.assertNotNull(new Object());
  } catch (AssertionFailure e) {
    fail("no AssertionFailure expected");
  }
  try {
    Debug.assertNotNull(null);
    fail("AssertionFailure expected");
  } catch (AssertionFailure e) {
  }
}

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

private static boolean isDebugClassTestable() {
  boolean oldDebugState = Debug.isEnabled();
  Debug.setEnabled(true);
  boolean newDebugState = Debug.isEnabled();
  Debug.setEnabled(oldDebugState);
  return newDebugState;
}

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

public void testAssertNotNullOrEmpty() {
  Debug.setEnabled(false);
  try {
    Debug.assertNotNullOrEmpty(null);
  } catch (AssertionFailure e) {
    fail("no AssertionFailure expected");
    Debug.assertNotNullOrEmpty("");
  } catch (AssertionFailure e) {
    fail("no AssertionFailure expected");
  Debug.setEnabled(true);
  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

/**
 * Prints the given message string to the current writer if and only if the debugging class functionality is
 * enabled.
 */
public static void trace(String message) {
  if (isEnabled() && message != null) {
    PrintWriter w = getWriter();
    w.print(_tracePrefix);
    w.println(message);
    log(message);
  }
}

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

/**
 * Prints the ammount of free memory using the given label string to the current writer if and only if the debugging
 * class functionality is enabled.
 *
 * @param label an optional label, can be null
 */
public static void traceMemoryUsage(String label) {
  if (isEnabled()) {
    String message = createMemoryUsageMessage(label);
    PrintWriter w = getWriter();
    w.print(_tracePrefix);
    w.println(message);
    log(message);
  }
}

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

/**
 * Delegates <code>Debug.trace()</code> calls to the system logger.
 *
 * @param exception the exception to be logged.
 */
protected static void log(Throwable exception) {
  if (isEnabled()) {
    if (isLogging()) {
      final StringWriter stringWriter = new StringWriter();
      final PrintWriter printWriter = new PrintWriter(stringWriter);
      exception.printStackTrace(printWriter);
      log(stringWriter.getBuffer().toString());
    }
  }
}

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

/**
 * Prints the given property change event to the current writer if and only if the debugging class functionality is
 * enabled.
 */
public static void trace(PropertyChangeEvent event) {
  if (isEnabled() && event != null) {
    PrintWriter w = getWriter();
    w.print("property ");
    w.print(event.getPropertyName());
    w.print(" changed from ");
    w.print(event.getOldValue());
    w.print(" to ");
    w.print(event.getNewValue());
    w.println();
  }
}

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

/**
 * Delegates <code>Debug.trace()</code> calls to the system logger.
 *
 * @param message the message to be logged.
 */
protected static void log(String message) {
  if (isEnabled()) {
    if (isLogging()) {
      if (_logger == null) {
        _logger = BeamLogManager.getSystemLogger();
      }
      _logger.finest(message);
    }
  }
}

相关文章