public ServiceReference getServiceReference() { ServiceReference[] references = getServiceReferences();  int length = (references == null) ? 0 : references.length;  if (length > 0)          { int index = 0;  if (length > 1)      { int rankings[] = new int[length]; int count = 0; int maxRanking = Integer.MIN_VALUE;  for (int i = 0 ; i < length; i++) { Object property = references[i].getProperty(Constants.SERVICE_RANKING);  int ranking = (property instanceof Integer) ? ((Integer)property).intValue() : 0;  rankings[i] = ranking;  if (ranking > maxRanking) { index = i; maxRanking = ranking; count = 1; } else { if (ranking == maxRanking) { count++; } } }  if (count > 1)   { long minId = Long.MAX_VALUE;  for (int i = 0 ; i < length; i++) { if (rankings[i] == maxRanking) { long id = ((Long)(references[i].getProperty(Constants.SERVICE_ID))).longValue();  if (id < minId) { index = i; minId = id; } } } } }  return references[index]; }  return null; }
    public Object[] getServices()    {        Tracked tracked = this.tracked;     /* use local var since we are not synchronized */        if (tracked == null)    /* if ServiceTracker is not open */        {            return null;        }        synchronized (tracked)        {            int size = tracked.size();            if (size == 0)            {                return null;            }            Object objects[] = new Object[size];            Enumeration enum = tracked.elements();            for (int i = 0; i < size; i++)            {                objects[i] = enum.nextElement();            }            return objects;        }    }    /**	 * Returns a <tt>ServiceReference</tt> object for one of the services	 * being tracked by this <tt>ServiceTracker</tt> object.	 *	 * <p>If multiple services are being tracked, the service	 * with the highest ranking (as specified in its <tt>service.ranking</tt> property) is	 * returned.	 *	 * <p>If there is a tie in ranking, the service with the lowest	 * service ID (as specified in its <tt>service.id</tt> property); that is,	 * the service that was registered first is returned.	 * <p>This is the same algorithm used by <tt>BundleContext.getServiceReference</tt>.	 *	 * @return <tt>ServiceReference</tt> object or <tt>null</tt> if no service is being tracked.	 * @since 1.1	 */    public ServiceReference getServiceReference()    {        ServiceReference[] references = getServiceReferences();        int length = (references == null) ? 0 : references.length;        if (length > 0)         /* if a service is being tracked */        {            int index = 0;            if (length > 1)     /* if more than one service, select highest ranking */            {                int rankings[] = new int[length];                int count = 0;                int maxRanking = Integer.MIN_VALUE;                for (int i = 0 ; i < length; i++)                {                    Object property = references[i].getProperty(Constants.SERVICE_RANKING);                    int ranking = (property instanceof Integer)                                    ? ((Integer)property).intValue() : 0;                    rankings[i] = ranking;                    if (ranking > maxRanking)                    {                        index = i;                        maxRanking = ranking;                        count = 1;                    }                    else                    {                        if (ranking == maxRanking)                        {                            count++;                        }                    }                }                if (count > 1)  /* if still more than one service, select lowest id */                {                    long minId = Long.MAX_VALUE;                    for (int i = 0 ; i < length; i++)                    {                        if (rankings[i] == maxRanking)                        {                            long id = ((Long)(references[i].getProperty(Constants.SERVICE_ID))).longValue();                            if (id < minId)                            {                                index = i;                                minId = id;                            }                        }                    }                }            }            return references[index];        }        return null;    }