< prev index next >

src/jdk.naming.dns/share/classes/com/sun/jndi/dns/DnsContext.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()
Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad


 520 
 521         // Each of prefix and name is now either a DnsName or a CompositeName.
 522 
 523         // If we have two DnsNames, simply join them together.
 524         if ((prefix instanceof DnsName) && (name instanceof DnsName)) {
 525             result = (DnsName) (prefix.clone());
 526             result.addAll(name);
 527             return new CompositeName().add(result.toString());
 528         }
 529 
 530         // Wrap compound names in composite names.
 531         Name prefixC = (prefix instanceof CompositeName)
 532             ? prefix
 533             : new CompositeName().add(prefix.toString());
 534         Name nameC = (name instanceof CompositeName)
 535             ? name
 536             : new CompositeName().add(name.toString());
 537         int prefixLast = prefixC.size() - 1;
 538 
 539         // Let toolkit do the work at namespace boundaries.
 540         if (nameC.isEmpty() || nameC.get(0).equals("") ||
 541                 prefixC.isEmpty() || prefixC.get(prefixLast).equals("")) {
 542             return super.composeName(nameC, prefixC);
 543         }
 544 
 545         result = (prefix == prefixC)
 546             ? (CompositeName) prefixC.clone()
 547             : prefixC;                  // prefixC is already a clone
 548         result.addAll(nameC);
 549 
 550         if (parentIsDns) {
 551             DnsName dnsComp = (prefix instanceof DnsName)
 552                            ? (DnsName) prefix.clone()
 553                            : new DnsName(prefixC.get(prefixLast));
 554             dnsComp.addAll((name instanceof DnsName)
 555                            ? name
 556                            : new DnsName(nameC.get(0)));
 557             result.remove(prefixLast + 1);
 558             result.remove(prefixLast);
 559             result.add(prefixLast, dnsComp.toString());
 560         }
 561         return result;


 670      */
 671     private static String toAttrId(int rrclass, int rrtype) {
 672         String attrId = ResourceRecord.getTypeName(rrtype);
 673         if (rrclass != ResourceRecord.CLASS_INTERNET) {
 674             attrId = ResourceRecord.getRrclassName(rrclass) + " " + attrId;
 675         }
 676         return attrId;
 677     }
 678 
 679     /*
 680      * Returns the class and type values corresponding to an attribute
 681      * ID.  An indeterminate class or type is represented by ANY.  See
 682      * toAttrId() for the format of attribute IDs.
 683      *
 684      * @throws InvalidAttributeIdentifierException
 685      *          if class or type is unknown
 686      */
 687     private static CT fromAttrId(String attrId)
 688             throws InvalidAttributeIdentifierException {
 689 
 690         if (attrId.equals("")) {
 691             throw new InvalidAttributeIdentifierException(
 692                     "Attribute ID cannot be empty");
 693         }
 694         int rrclass;
 695         int rrtype;
 696         int space = attrId.indexOf(' ');
 697 
 698         // class
 699         if (space < 0) {
 700             rrclass = ResourceRecord.CLASS_INTERNET;
 701         } else {
 702             String className = attrId.substring(0, space);
 703             rrclass = ResourceRecord.getRrclass(className);
 704             if (rrclass < 0) {
 705                 throw new InvalidAttributeIdentifierException(
 706                         "Unknown resource record class '" + className + '\'');
 707             }
 708         }
 709 
 710         // type




 520 
 521         // Each of prefix and name is now either a DnsName or a CompositeName.
 522 
 523         // If we have two DnsNames, simply join them together.
 524         if ((prefix instanceof DnsName) && (name instanceof DnsName)) {
 525             result = (DnsName) (prefix.clone());
 526             result.addAll(name);
 527             return new CompositeName().add(result.toString());
 528         }
 529 
 530         // Wrap compound names in composite names.
 531         Name prefixC = (prefix instanceof CompositeName)
 532             ? prefix
 533             : new CompositeName().add(prefix.toString());
 534         Name nameC = (name instanceof CompositeName)
 535             ? name
 536             : new CompositeName().add(name.toString());
 537         int prefixLast = prefixC.size() - 1;
 538 
 539         // Let toolkit do the work at namespace boundaries.
 540         if (nameC.isEmpty() || nameC.get(0).isEmpty() ||
 541                 prefixC.isEmpty() || prefixC.get(prefixLast).isEmpty()) {
 542             return super.composeName(nameC, prefixC);
 543         }
 544 
 545         result = (prefix == prefixC)
 546             ? (CompositeName) prefixC.clone()
 547             : prefixC;                  // prefixC is already a clone
 548         result.addAll(nameC);
 549 
 550         if (parentIsDns) {
 551             DnsName dnsComp = (prefix instanceof DnsName)
 552                            ? (DnsName) prefix.clone()
 553                            : new DnsName(prefixC.get(prefixLast));
 554             dnsComp.addAll((name instanceof DnsName)
 555                            ? name
 556                            : new DnsName(nameC.get(0)));
 557             result.remove(prefixLast + 1);
 558             result.remove(prefixLast);
 559             result.add(prefixLast, dnsComp.toString());
 560         }
 561         return result;


 670      */
 671     private static String toAttrId(int rrclass, int rrtype) {
 672         String attrId = ResourceRecord.getTypeName(rrtype);
 673         if (rrclass != ResourceRecord.CLASS_INTERNET) {
 674             attrId = ResourceRecord.getRrclassName(rrclass) + " " + attrId;
 675         }
 676         return attrId;
 677     }
 678 
 679     /*
 680      * Returns the class and type values corresponding to an attribute
 681      * ID.  An indeterminate class or type is represented by ANY.  See
 682      * toAttrId() for the format of attribute IDs.
 683      *
 684      * @throws InvalidAttributeIdentifierException
 685      *          if class or type is unknown
 686      */
 687     private static CT fromAttrId(String attrId)
 688             throws InvalidAttributeIdentifierException {
 689 
 690         if (attrId.isEmpty()) {
 691             throw new InvalidAttributeIdentifierException(
 692                     "Attribute ID cannot be empty");
 693         }
 694         int rrclass;
 695         int rrtype;
 696         int space = attrId.indexOf(' ');
 697 
 698         // class
 699         if (space < 0) {
 700             rrclass = ResourceRecord.CLASS_INTERNET;
 701         } else {
 702             String className = attrId.substring(0, space);
 703             rrclass = ResourceRecord.getRrclass(className);
 704             if (rrclass < 0) {
 705                 throw new InvalidAttributeIdentifierException(
 706                         "Unknown resource record class '" + className + '\'');
 707             }
 708         }
 709 
 710         // type


< prev index next >