org.axonframework.common.Assert类的使用及代码示例

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

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

Assert介绍

[英]Utility class (inspired by Springs Assert class) for doing assertions on parameters and object state. To remove the need for explicit dependencies on Spring, the functionality of that class is migrated to this class.
[中]实用程序类(受Springs Assert类启发),用于对参数和对象状态进行断言。为了消除对Spring的显式依赖关系的需要,该类的功能被迁移到此类。

代码示例

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

/**
 * Initializes the strategy using given {@code unresolvedRoutingKeyPolicy} prescribing what happens when a
 * routing key cannot be resolved.
 *
 * @param unresolvedRoutingKeyPolicy The policy for unresolved routing keys.
 */
public AbstractRoutingStrategy(UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy) {
  Assert.notNull(unresolvedRoutingKeyPolicy, () -> "unresolvedRoutingKeyPolicy may not be null");
  this.unresolvedRoutingKeyPolicy = unresolvedRoutingKeyPolicy;
}

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

@Override
public TrackingToken upperBound(TrackingToken other) {
  Assert.isTrue(other instanceof GlobalSequenceTrackingToken, () -> "Incompatible token type provided.");
  if (((GlobalSequenceTrackingToken) other).globalIndex > this.globalIndex) {
    return other;
  }
  return this;
}

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

public Aggregate<T> getAggregate() {
  Assert.state(!rolledBack, () -> "The state of this aggregate cannot be retrieved because it " +
      "has been modified in a Unit of Work that was rolled back");
  return aggregate;
}

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

/**
 * Returns the boxed wrapper type for the given {@code primitiveType}.
 *
 * @param primitiveType The primitive type to return boxed wrapper type for
 * @return the boxed wrapper type for the given {@code primitiveType}
 * @throws IllegalArgumentException will be thrown instead of returning null if no wrapper class was found.
 */
public static Class<?> resolvePrimitiveWrapperType(Class<?> primitiveType) {
  Assert.notNull(primitiveType, () -> "primitiveType may not be null");
  Assert.isTrue(primitiveType.isPrimitive(), () -> "primitiveType is not actually primitive: " + primitiveType);
  Class<?> primitiveWrapperType = primitiveWrapperTypeMap.get(primitiveType);
  Assert.notNull(primitiveWrapperType, () -> "no wrapper found for primitiveType: " + primitiveType);
  return primitiveWrapperType;
}

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

private void assertNotBuilt() {
    Assert.isFalse(built, () -> "this builder has already been built");
  }
}

代码示例来源:origin: vvgomes/event-driven-restaurant

@CommandHandler
public void handle(ModifyMenuItemCommand command) {
  Assert.state(active, () -> "Item is inactive.");
  Assert.isFalse(command.getDescription().isEmpty(), () -> "Description must be present.");
  apply(new MenuItemModifiedEvent(id, command.getDescription(), command.getPrice()));
}

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

/**
 * Instantiate a lazy {@link ScopeAwareProvider} with the given {@code configuration} parameter.
 *
 * @param configuration a {@link Configuration} used to retrieve {@link ScopeAware} components from
 * @throws IllegalArgumentException when {@code configuration} is {@code null}
 */
public ConfigurationScopeAwareProvider(Configuration configuration) {
  this.configuration = Assert.nonNull(configuration, () -> "configuration may not be null");
}

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

/**
 * Initializes a BatchingUnitOfWork for processing the given list of {@code messages}.
 *
 * @param messages batch of messages to process
 */
public BatchingUnitOfWork(List<T> messages) {
  Assert.isFalse(messages.isEmpty(), () -> "The list of Messages to process is empty");
  processingContexts = messages.stream().map(MessageProcessingContext::new).collect(Collectors.toList());
  processingContext = processingContexts.get(0);
}

代码示例来源:origin: org.axonframework/axon-core

/**
 * Instantiate a lazy {@link ScopeAwareProvider} with the given {@code configuration} parameter.
 *
 * @param configuration a {@link Configuration} used to retrieve {@link ScopeAware} components from
 * @throws IllegalArgumentException when {@code configuration} is {@code null}
 */
public ConfigurationScopeAwareProvider(Configuration configuration) {
  this.configuration = Assert.nonNull(configuration, () -> "configuration may not be null");
}

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

/**
 * Initializes an instance that always returns the given {@code entityManager}. This class can be used for
 * testing, or when using a ContainerManaged EntityManager.
 *
 * @param entityManager the EntityManager to return on {@link #getEntityManager()}
 */
public SimpleEntityManagerProvider(EntityManager entityManager) {
  Assert.notNull(entityManager, () -> "entityManager should not be null");
  this.entityManager = entityManager;
}

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

/**
 * Assert that the given {@code value} is not {@code null}. If not, an IllegalArgumentException is
 * thrown.
 *
 * @param value           the value not to be {@code null}
 * @param messageSupplier Supplier of the exception message if the assertion fails
 * @return the provided {@code value}
 */
public static <T> T nonNull(T value, Supplier<String> messageSupplier) {
  isTrue(value != null, messageSupplier);
  return value;
}

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

private void ensureInitialized() {
    Assert.state(config != null, () -> "Configuration is not initialized yet");
  }
}

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

/**
 * Initialize the AggregateFactory for creating instances of the given {@code aggregateType}.
 *
 * @param aggregateType The type of aggregate this factory creates instances of.
 * @throws IncompatibleAggregateException if the aggregate constructor throws an exception, or if the JVM security
 *                                        settings prevent the GenericAggregateFactory from calling the
 *                                        constructor.
 */
public GenericAggregateFactory(Class<T> aggregateType) {
  super(aggregateType);
  Assert.isFalse(Modifier.isAbstract(aggregateType.getModifiers()), () -> "Given aggregateType may not be abstract");
  try {
    this.constructor = ensureAccessible(aggregateType.getDeclaredConstructor());
  } catch (NoSuchMethodException e) {
    throw new IncompatibleAggregateException(format("The aggregate [%s] doesn't provide a no-arg constructor.",
                            aggregateType.getSimpleName()), e);
  }
}

代码示例来源:origin: org.axonframework/axon-configuration

/**
 * Instantiate a lazy {@link ScopeAwareProvider} with the given {@code configuration} parameter.
 *
 * @param configuration a {@link Configuration} used to retrieve {@link ScopeAware} components from
 * @throws IllegalArgumentException when {@code configuration} is {@code null}
 */
public ConfigurationScopeAwareProvider(Configuration configuration) {
  this.configuration = Assert.nonNull(configuration, () -> "configuration may not be null");
}

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

/**
 * Initialize a ParameterResolverFactory instance that resolves parameters of type
 * {@code declaredParameterType} annotated with the given {@code annotationType}.
 *
 * @param annotationType        the type of annotation that a prospective parameter should declare
 * @param declaredParameterType the type that the parameter value should be assignable to
 */
protected AbstractAnnotatedParameterResolverFactory(Class<A> annotationType, Class<P> declaredParameterType) {
  Assert.notNull(annotationType, () -> "annotationType may not be null");
  Assert.notNull(declaredParameterType, () -> "declaredParameterType may not be null");
  this.annotationType = annotationType;
  this.declaredParameterType = declaredParameterType;
}

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

@Override
public TrackingToken lowerBound(TrackingToken other) {
  Assert.isTrue(other instanceof GlobalSequenceTrackingToken, () -> "Incompatible token type provided.");
  GlobalSequenceTrackingToken otherToken = (GlobalSequenceTrackingToken) other;
  if (otherToken.globalIndex < this.globalIndex) {
    return otherToken;
  } else {
    return this;
  }
}

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

/**
   * Updates the builder function for this component.
   *
   * @param builderFunction The new builder function for the component
   * @throws IllegalStateException when the component has already been retrieved using {@link #get()}.
   */
  public void update(Function<Configuration, ? extends B> builderFunction) {
    Assert.state(instance == null, () -> "Cannot change " + name + ": it is already in use");
    this.builderFunction = builderFunction;
  }
}

代码示例来源:origin: org.axonframework/axon-core

private void assertNotBuilt() {
    Assert.isFalse(built, () -> "this builder has already been built");
  }
}

代码示例来源:origin: org.axonframework/axon-core

/**
 * Initializes a repository that stores aggregate of the given {@code aggregateType}. All aggregates in this
 * repository must be {@code instanceOf} this aggregate type.
 *
 * @param aggregateType The type of aggregate stored in this repository
 */
protected AbstractRepository(Class<T> aggregateType) {
  this(AnnotatedAggregateMetaModelFactory.inspectAggregate(
      nonNull(aggregateType, () -> "aggregateType may not be null")
  ));
}

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

/**
 * Initialize with given {@code objectType} and {@code revisionNumber}
 *
 * @param objectType     The description of the serialized object's type
 * @param revisionNumber The revision of the serialized object's type
 */
public SimpleSerializedType(String objectType, String revisionNumber) {
  Assert.notNull(objectType, () -> "objectType cannot be null");
  this.type = objectType;
  this.revisionId = revisionNumber;
}

相关文章