Package org.apache.sling.junit.jupiter.osgi

# Enum ServiceCardinality

java.lang.Object
java.lang.Enum<ServiceCardinality>
org.apache.sling.junit.jupiter.osgi.ServiceCardinality

All Implemented Interfaces:
  `Serializable`, `Comparable<ServiceCardinality>`

public enum ServiceCardinality extends Enum<ServiceCardinality>
The cardinality of a service being injected is controlled via the type of the injected parameter and additionally via the `@Service` annotation's `cardinality` attribute.
The cardinality can be either `OPTIONAL` or `MANDATORY`. `OPTIONAL` does not require the presence of a service, whereas `MANDATORY` requires at least one service to be present, otherwise an exception is thrown.
The other aspect of cardinality, namely whether a single service or multiple services should be injected, is controlled via the type of the annotated field. For single service injection, the field's type is expected to be the type of the injected service. For multiple service injection, the field's type is expected to be a `Collection` or `List` with the type of the injected service as its generic type-argument.
Any further constraints, i.e. checking for an exact number or a range of services must be done via assertions.

See Also:
  - `Service.cardinality()`

## Enum Constant Summary

Enum Constants
Enum Constant
Description
`AUTO`
For unary service injection, `AUTO` defaults to `MANDATORY`.
`MANDATORY`
At least one service must be present, otherwise a `ParameterResolutionException` is thrown.
`OPTIONAL`
If no service is present, `null` is injected for unary service injection, and an empty `List` is injected for multiple service injection.

## Method Summary

Modifier and Type
Method
Description
`static ServiceCardinality`
`valueOf(String name)`
Returns the enum constant of this type with the specified name.
`static ServiceCardinality[]`
`values()`
Returns an array containing the constants of this enum type, in the order they are declared.

### Methods inherited from class java.lang.Enum

`clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`

## Enum Constant Details

### AUTO

public static final ServiceCardinality AUTO
For unary service injection, `AUTO` defaults to `MANDATORY`. Whereas for multiple service injection, `AUTO` defaults to `OPTIONAL`.

### OPTIONAL

public static final ServiceCardinality OPTIONAL
If no service is present, `null` is injected for unary service injection, and an empty `List` is injected for multiple service injection.

### MANDATORY

public static final ServiceCardinality MANDATORY
At least one service must be present, otherwise a `ParameterResolutionException` is thrown.

## Method Details

### values

public static ServiceCardinality[] values()
Returns an array containing the constants of this enum type, in the order they are declared.

Returns:
  an array containing the constants of this enum type, in the order they are declared

### valueOf

public static ServiceCardinality valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
  `name` - the name of the enum constant to be returned.
Returns:
  the enum constant with the specified name
Throws:
  `IllegalArgumentException` - if this enum type has no constant with the specified name
  `NullPointerException` - if the argument is null