com.tc.util.Assert.failure()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(147)

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

Assert.failure介绍

[英]This returns an exception, instead of throwing one, so that you can do (e.g.): public Object foo() { throw Assert.failure("doesn't work"); } or whatever. If this just threw the exception itself, the compiler would complain (above) that there's no value being returned.
[中]这将返回一个异常,而不是抛出一个异常,以便您可以执行(例如:public Object foo() { throw Assert.failure("doesn't work"); }或其他操作。如果这只是抛出异常本身,编译器会抱怨(上面)没有返回值。

代码示例

代码示例来源:origin: org.terracotta/terracotta-l1

@Override
public void ensureBeanIsOfClass(Class theClass) {
 if (!theClass.isAssignableFrom(this.requiredClass)) {
  // formatting
  throw Assert.failure("You're making sure this repository requires at least " + theClass + ", but it requires "
             + this.requiredClass + ", which isn't that class or a subclass thereof.");
 }
}

代码示例来源:origin: org.terracotta/terracotta-ee

@Override
public void ensureBeanIsOfClass(Class theClass) {
 if (!theClass.isAssignableFrom(this.requiredClass)) {
  // formatting
  throw Assert.failure("You're making sure this repository requires at least " + theClass + ", but it requires "
             + this.requiredClass + ", which isn't that class or a subclass thereof.");
 }
}

代码示例来源:origin: org.terracotta/terracotta-ee

private static Class getBeanInterface(Object value) {
 Class[] interfaces = value.getClass().getInterfaces();
 if (interfaces.length != 1) {
  // formatting
  throw Assert.failure("Class " + value.getClass() + ", the class of object " + value + ", implements "
             + interfaces.length + " interfaces, not 1. We don't support this yet.");
 }
 return interfaces[0];
}

代码示例来源:origin: org.terracotta/terracotta-l1

private static Class getBeanInterface(Object value) {
 Class[] interfaces = value.getClass().getInterfaces();
 if (interfaces.length != 1) {
  // formatting
  throw Assert.failure("Class " + value.getClass() + ", the class of object " + value + ", implements "
             + interfaces.length + " interfaces, not 1. We don't support this yet.");
 }
 return interfaces[0];
}

代码示例来源:origin: org.terracotta/terracotta-l1-ee

private TCByteBuffer getBuffer(int index) {
 int buffersSize = buffers.size();
 if (index < buffersSize) {
  return (TCByteBuffer) buffers.get(index);
 } else if (index == buffersSize) {
  return current;
 } else {
  throw Assert.failure("index=" + index + ", buffers.size()=" + buffers.size());
 }
}

代码示例来源:origin: org.terracotta/terracotta-l1-ee

private static Class getBeanInterface(Object value) {
 Class[] interfaces = value.getClass().getInterfaces();
 if (interfaces.length != 1) {
  // formatting
  throw Assert.failure("Class " + value.getClass() + ", the class of object " + value + ", implements "
             + interfaces.length + " interfaces, not 1. We don't support this yet.");
 }
 return interfaces[0];
}

代码示例来源:origin: org.terracotta/terracotta-ee

@Override
public boolean next() throws IOException {
 try {
  return next(DNA_STORAGE_ENCODING);
 } catch (final ClassNotFoundException e) {
  // This shouldn't happen when expand is "false"
  throw Assert.failure("Internal error");
 }
}

代码示例来源:origin: org.terracotta/terracotta-ee

/**
 * Evaluate the boolean exception and throw an assertion error if false
 *
 * @param expr Expression
 */
public static void eval(boolean expr) {
 if ((!expr) && isEnabled()) { throw failure("Assertion failed"); }
 return;
}

代码示例来源:origin: org.terracotta/terracotta-ee

/**
 * Throw assertion error with generic message
 */
public static void fail() {
 if (isEnabled()) {
  throw failure("generic failure");
 }
}

代码示例来源:origin: org.terracotta/terracotta-l1-ee

@Override
public boolean next() throws IOException {
 try {
  return next(DNA_STORAGE_ENCODING);
 } catch (final ClassNotFoundException e) {
  // This shouldn't happen when expand is "false"
  throw Assert.failure("Internal error");
 }
}

代码示例来源:origin: org.terracotta/terracotta-l1-ee

/**
 * Throw assertion error with specified message
 *
 * @param message Message
 */
public static void fail(String message) {
 if (isEnabled()) {
  throw failure(message);
 }
}

代码示例来源:origin: org.terracotta/terracotta-l1-ee

/**
 * Evaluate the boolean exception and throw an assertion error if false
 *
 * @param expr Expression
 */
public static void eval(boolean expr) {
 if ((!expr) && isEnabled()) { throw failure("Assertion failed"); }
 return;
}

代码示例来源:origin: org.terracotta/terracotta-l1

@Override
public InputStream rawConfigFile() {
 String text = configurationCreator().rawConfigText();
 try {
  return new ByteArrayInputStream(text.getBytes("UTF-8"));
 } catch (UnsupportedEncodingException uee) {
  throw Assert.failure("This shouldn't be possible", uee);
 }
}

代码示例来源:origin: org.terracotta/terracotta-ee

@Override
public InputStream rawConfigFile() {
 String text = configurationCreator().rawConfigText();
 try {
  return new ByteArrayInputStream(text.getBytes("UTF-8"));
 } catch (UnsupportedEncodingException uee) {
  throw Assert.failure("This shouldn't be possible", uee);
 }
}

代码示例来源:origin: org.terracotta/terracotta-l1-ee

/**
 * Evaluate the boolean exception and throw an assertion error if false
 *
 * @param expr Expression
 * @param message Message for assertion error if false
 */
public static void eval(Object message, boolean expr) {
 if ((!expr) && isEnabled()) { throw failure("Assertion failed: " + StringUtil.safeToString(message)); }
 return;
}

代码示例来源:origin: org.terracotta/terracotta-ee

public static void assertDoesNotContainsElement(Object[] objectArray, Object element) {
 assertNotNull(objectArray);
 for (int pos = 0; pos < objectArray.length; pos++) {
  if (objectArray[pos] == element) {
   failure("Element<" + element + "> was found in array " + StringUtil.toString(objectArray, ",", "<", ">"));
  }
 }
}

代码示例来源:origin: org.terracotta/terracotta-l1

@Override
public void messageReceived(NodeID fromNode, GroupMessage msg) {
 if (!(msg instanceof EventContext)) {
  Assert.failure(this.toString());
 }
 sink.add((EventContext) msg);
}

代码示例来源:origin: org.terracotta/terracotta-ee

@Override
public void messageReceived(NodeID fromNode, GroupMessage msg) {
 if (!(msg instanceof EventContext)) {
  Assert.failure(this.toString());
 }
 sink.add((EventContext) msg);
}

代码示例来源:origin: org.terracotta/terracotta-ee

/**
 * Evaluate the boolean exception and throw an assertion error if false
 *
 * @param expr Expression
 * @param message Message for assertion error if false
 */
public static void eval(Object message, boolean expr) {
 if ((!expr) && isEnabled()) { throw failure("Assertion failed: " + StringUtil.safeToString(message)); }
 return;
}

代码示例来源:origin: org.terracotta/terracotta-ee

/**
 * If o is non-null, throw assertion error
 *
 * @param o Object
 * @param what Message for error
 */
public static void assertNull(Object what, Object o) {
 if ((o != null) && isEnabled()) { throw failure(StringUtil.safeToString(what) + " was not null"); }
}

相关文章