org.teiid.core.util.Assertion类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(117)

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

Assertion介绍

[英]This class contains a set of static utility methods for assertion checking. Assertions are used to document the assumptions a programmer is making about the code they are writing. Assertions should not be used in cases where the user of a class can affect whether the assertion is true or false, such as argument checking. Rather, assertions should be considered a much stronger statement by the programmer that such a condition is NEVER true. In fact, this statement is so strong that assertions should be considered optional as they should never occur. However, these assertions may be violated during development and that is primarily where these assertions are useful.

In JDK 1.4, Sun introduces the "assert" keyword and builds assertion support directly into the language. When MetaMatrix begins using JDK 1.4 across the board, this class should no longer be needed and all usage of assertions should be replaced with use of the built-in JDK assertion facility.
[中]此类包含一组用于断言检查的静态实用程序方法。断言用于记录程序员对他们正在编写的代码所做的假设。在类的用户可以影响断言是真是假的情况下,不应使用断言,例如参数检查。相反,程序员应该将断言视为一种更强有力的声明,即这样的条件永远不会成立。事实上,该语句非常强大,因此断言应该被视为可选的,因为它们永远不会出现。然而,在开发过程中可能会违反这些断言,而这正是这些断言最有用的地方。
在JDK1.4中,Sun引入了“assert”关键字,并将断言支持直接构建到语言中。当MetaMatrix开始全面使用JDK1.4时,应该不再需要这个类,所有断言的使用都应该被内置的JDK断言工具所取代。

代码示例

代码示例来源:origin: org.teiid/teiid-common-core

public void reset(int newIndex) {
  Assertion.assertTrue(newIndex < bufs[0].length);
  while (bufferIndex > 0) {
    bufs[bufferIndex--] = null;
  }
  count = index = newIndex;
}

代码示例来源:origin: org.teiid/teiid-engine

/**
 * <p> This constructor initialises this object by setting the symbolMap and
 * passing in the command object that is being visited.</p>
 * @param symbolMap A map of virtual elements/groups to their physical counterparts
 */
public StaticSymbolMappingVisitor(Map symbolMap) {                
  super();
  
  Assertion.isNotNull(symbolMap);
  this.symbolMap = symbolMap;		
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

void setComment(String comment){
  if (this.elementStarted) {
    Assertion.failed("Comment must not be added to Element after Element is started."); //$NON-NLS-1$
  }
  this.comment = comment;
}

代码示例来源:origin: org.teiid/teiid-common-core

/**
 * This method transforms a value of the source type into a value
 * of the target type.
 * @param value Incoming value - Integer
 * @return Outgoing value - String
 * @throws TransformationException if value is an incorrect input type or
 * the transformation fails
 */
public Object transformDirect(Object value) throws TransformationException {
  Assertion.isNull(value);
  return null;
}

代码示例来源:origin: org.teiid/teiid-engine

private void setExecution(Command command,
    org.teiid.language.Command translatedCommand, final Execution exec) {
  if (translatedCommand instanceof Call) {
    this.execution = Assertion.isInstanceOf(exec, ProcedureExecution.class, "Call Executions are expected to be ProcedureExecutions"); //$NON-NLS-1$
    StoredProcedure proc = (StoredProcedure)command;
    if (proc.returnParameters()) 			{
    this.execution = Assertion.isInstanceOf(exec, ResultSetExecution.class, "QueryExpression Executions are expected to be ResultSetExecutions"); //$NON-NLS-1$
  } else {
    final boolean singleUpdateCount = connector.returnsSingleUpdateCount() 
        && (translatedCommand instanceof BatchedUpdates || (translatedCommand instanceof BulkCommand && ((BulkCommand)translatedCommand).getParameterValues() != null));
    Assertion.isInstanceOf(exec, UpdateExecution.class, "Update Executions are expected to be UpdateExecutions"); //$NON-NLS-1$
    this.execution = new ResultSetExecution() {
      private int[] results;

代码示例来源:origin: teiid/teiid

/**
 * This method transforms a value of the source type into a value
 * of the target type.
 * @param value Incoming value - Integer
 * @return Outgoing value - String
 * @throws TransformationException if value is an incorrect input type or
 * the transformation fails
 */
public Object transformDirect(Object value) throws TransformationException {
  Assertion.isNull(value);
  return null;
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

private void setExecution(Command command,
    org.teiid.language.Command translatedCommand, final Execution exec) {
  if (translatedCommand instanceof Call) {
    this.execution = Assertion.isInstanceOf(exec, ProcedureExecution.class, "Call Executions are expected to be ProcedureExecutions"); //$NON-NLS-1$
    StoredProcedure proc = (StoredProcedure)command;
    if (proc.returnParameters()) 			{
    this.execution = Assertion.isInstanceOf(exec, ResultSetExecution.class, "QueryExpression Executions are expected to be ResultSetExecutions"); //$NON-NLS-1$
  } else {
    final boolean singleUpdateCount = connector.returnsSingleUpdateCount() 
        && (translatedCommand instanceof BatchedUpdates || (translatedCommand instanceof BatchedCommand && ((BatchedCommand)translatedCommand).getParameterValues() != null));
    Assertion.isInstanceOf(exec, UpdateExecution.class, "Update Executions are expected to be UpdateExecutions"); //$NON-NLS-1$
    this.execution = new ResultSetExecution() {
      private int[] results;

代码示例来源:origin: teiid/teiid

public void reset(int newIndex) {
  Assertion.assertTrue(newIndex < bufs[0].length);
  while (bufferIndex > 0) {
    bufs[bufferIndex--] = null;
  }
  count = index = newIndex;
}

代码示例来源:origin: org.teiid/teiid-admin

public Message(Severity severity, String msg) {
  this.severity = severity;
  Assertion.isNotNull(msg);
  this.value = msg;
}

代码示例来源:origin: teiid/teiid

public static final void assertTrue(boolean condition, String msgKey) {
  if(! condition) {
    final String msg = msgKey != null ?
              msgKey :
              CorePlugin.Util.getString("Assertion.Assertion_failed"); //$NON-NLS-1$ 
    failed(msg);
  }   
}

代码示例来源:origin: org.teiid/teiid-common-core

public static final void isNull(Object value) {
  isNull(value,null);
}

代码示例来源:origin: teiid/teiid

private void setExecution(Command command,
    org.teiid.language.Command translatedCommand, final Execution exec) {
  if (translatedCommand instanceof Call) {
    this.execution = Assertion.isInstanceOf(exec, ProcedureExecution.class, "Call Executions are expected to be ProcedureExecutions"); //$NON-NLS-1$
    StoredProcedure proc = (StoredProcedure)command;
    if (proc.returnParameters()) 			{
    this.execution = Assertion.isInstanceOf(exec, ResultSetExecution.class, "QueryExpression Executions are expected to be ResultSetExecutions"); //$NON-NLS-1$
  } else {
    final boolean singleUpdateCount = connector.returnsSingleUpdateCount() 
        && (translatedCommand instanceof BatchedUpdates || (translatedCommand instanceof BulkCommand && ((BulkCommand)translatedCommand).getParameterValues() != null));
    Assertion.isInstanceOf(exec, UpdateExecution.class, "Update Executions are expected to be UpdateExecutions"); //$NON-NLS-1$
    this.execution = new ResultSetExecution() {
      private int[] results;

代码示例来源:origin: org.jboss.teiid/teiid-engine

public void setProcessingSortRight(boolean processingSortRight) {
  if (processingSortRight && this.processingSortRight == SortOption.ALREADY_SORTED) {
    //it is possible that a delayed open will be called after the parent open
    //for now we'll just throw an assertion
    Assertion.assertTrue(!this.rightSource.open);
    this.processingSortRight = SortOption.SORT;
  }
}

代码示例来源:origin: teiid/teiid

public Message(Severity severity, String msg) {
  this.severity = severity;
  Assertion.isNotNull(msg);
  this.value = msg;
}

代码示例来源:origin: org.teiid/teiid-common-core

public static final void isNull(Object value, String message) {
  if ( value != null ) {
    final String msg = message != null ?
              message :
              CorePlugin.Util.getString("Assertion.isNull"); //$NON-NLS-1$
    failed(msg);
  }
}

代码示例来源:origin: org.teiid/teiid-engine

synchronized void setResultsReceiver(ResultsReceiver<LobChunk> resultsReceiver) {
  Assertion.isNull(this.resultsReceiver, "Cannot request results with a pending request"); //$NON-NLS-1$
  this.resultsReceiver = resultsReceiver;
}

代码示例来源:origin: teiid/teiid

public void testIsInstanceOf() {
  Assertion.isInstanceOf(new Integer(1),Integer.class,"name"); //$NON-NLS-1$
  Assertion.isInstanceOf("asdfasdf",String.class,"name2"); //$NON-NLS-1$ //$NON-NLS-2$
  try {
    Assertion.isInstanceOf(new Integer(1),Long.class,"name3"); //$NON-NLS-1$
    fail();
  } catch ( ClassCastException e ) {
    // expected, but check the message
    final Object[] params = new Object[]{"name3", Long.class, Integer.class.getName()}; //$NON-NLS-1$
    final String msg = CorePlugin.Util.getString("Assertion.invalidClassMessage",params); //$NON-NLS-1$
    assertEquals(msg, e.getMessage());
  }
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

public void setProcessingSortLeft(boolean processingSortLeft) {
  if (processingSortLeft && this.processingSortLeft == SortOption.ALREADY_SORTED) {
    //it is possible that a delayed open will be called after the parent open
    //for now we'll just throw an assertion
    Assertion.assertTrue(!this.leftSource.open);
    this.processingSortLeft = SortOption.SORT;
  }
}

代码示例来源:origin: org.teiid/teiid-common-core

public BinaryType(byte[] bytes) {
  Assertion.isNotNull(bytes);
  //to be truly immutable we should clone here
  this.bytes = bytes;
}

代码示例来源:origin: org.teiid/teiid-common-core

public static final void assertTrue(boolean condition, String msgKey) {
  if(! condition) {
    final String msg = msgKey != null ?
              msgKey :
              CorePlugin.Util.getString("Assertion.Assertion_failed"); //$NON-NLS-1$ 
    failed(msg);
  }   
}

相关文章