org.apache.sling.commons.osgi

## Class ServiceUtil

- java.lang.Object
- - org.apache.sling.commons.osgi.ServiceUtil

    public class ServiceUtil
    extends Object

The `ServiceUtil` is a utility class providing some useful utility methods for service handling.

Since:
  2.1

### Constructor Summary

Constructors
Constructor and Description
`ServiceUtil()`

### Method Summary

All Methods Static Methods Concrete Methods Deprecated Methods
`static Comparable<Object>` `getComparableForServiceRanking(Map<String,Object> props)` Deprecated. Use `getComparableForServiceRanking(Map, Order)` instead.
`static Comparable<Object>` `getComparableForServiceRanking(Map<String,Object> props, Order order)` Create a comparable object out of the service properties.

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ServiceUtil

    public ServiceUtil()

### Method Detail

#### getComparableForServiceRanking

    @Deprecated
    public static Comparable<Object> getComparableForServiceRanking(Map<String,Object> props)

Deprecated. Use `getComparableForServiceRanking(Map, Order)` instead.

Parameters:
  `props` - The service properties.
Returns:
  the same comparable as returned by `getComparableForServiceRanking(Map, Order.ASCENDING)`
See Also:
  `getComparableForServiceRanking(Map, Order)`

#### getComparableForServiceRanking

    public static Comparable<Object> getComparableForServiceRanking(Map<String,Object> props,
                                                                    Order order)

Create a comparable object out of the service properties. With the result it is possible to compare service properties based on the service ranking of a service. This object acts like `ServiceReference.compareTo(Object)`. The comparator will return the services in the given order. In ascending order the service with the lowest ranking comes first, in descending order the service with the highest ranking comes first. The latter is useful if you want to have the service returned first which is also chosen by `BundleContext.getServiceReference(String)`.

Parameters:
  `props` - The service properties.
  `order` - The order (either ascending or descending).
Returns:
  A comparable for the ranking of the service
Since:
  2.4