if (certs.size() == 1)
if (certs.size() < 2)
    private List sortCerts(        List certs)    {        if (certs.size() == 1)        {            return certs;        }                X500Principal   issuer = ((X509Certificate)certs.get(0)).getIssuerX500Principal();        boolean         okay = true;                for (int i = 1; i != certs.size(); i++)         {            X509Certificate cert = (X509Certificate)certs.get(i);                        if (issuer.equals(cert.getSubjectX500Principal()))            {                issuer = ((X509Certificate)certs.get(i)).getIssuerX500Principal();            }            else            {                okay = false;                break;            }        }                if (okay)        {            return certs;        }                // find end-entity cert        List       retList = new ArrayList(certs.size());                for (int i = 0; i < certs.size(); i++)        {            X509Certificate cert = (X509Certificate)certs.get(i);            boolean         found = false;                        X500Principal   subject = cert.getSubjectX500Principal();                        for (int j = 0; j != certs.size(); j++)            {                X509Certificate c = (X509Certificate)certs.get(j);                if (c.getIssuerX500Principal().equals(subject))                {                    found = true;                    break;                }            }                        if (!found)            {                retList.add(cert);                certs.remove(i);            }        }                // can only have one end entity cert - something's wrong, give up.        if (retList.size() > 1)        {            for (int i = 0; i != certs.size(); i++)            {                retList.add(certs.get(i));            }                        return retList;        }        for (int i = 0; i != retList.size(); i++)        {            issuer = ((X509Certificate)retList.get(i)).getIssuerX500Principal();                        for (int j = 0; j < certs.size(); j++)            {                X509Certificate c = (X509Certificate)certs.get(j);                if (issuer.equals(c.getSubjectX500Principal()))                {                    retList.add(c);                    certs.remove(j);                    break;                }            }        }                // make sure all certificates are accounted for.        for (int i = 0; i != certs.size(); i++)        {            retList.add(certs.get(i));        }                return retList;    }