test_class.declarator: smiles = new SmilesParser(SilentChemObjectBuilder.getInstance())
test_class.modifier: static
test_class.original_string: static SmilesParser smiles = new SmilesParser(SilentChemObjectBuilder.getInstance());
test_class.type: SmilesParser
test_class.var_name: smiles
test_class.file: descriptor/cip/src/test/java/org/openscience/cdk/geometry/cip/rules/CIPLigandRuleTest.java
test_class.identifier: CIPLigandRuleTest
test_class.superclass: extends CDKTestCase
test_case.body: @Test
      public void testCBrIFCl() throws Exception {
          IAtomContainer molecule = smiles.parseSmiles("FC(Br)(Cl)I");
          ILigand ligandF = new Ligand(molecule, new VisitedAtoms(), molecule.getAtom(1), molecule.getAtom(0));
          ILigand ligandBr = new Ligand(molecule, new VisitedAtoms(), molecule.getAtom(1), molecule.getAtom(2));
          ILigand ligandCl = new Ligand(molecule, new VisitedAtoms(), molecule.getAtom(1), molecule.getAtom(3));
          ILigand ligandI = new Ligand(molecule, new VisitedAtoms(), molecule.getAtom(1), molecule.getAtom(4));
          ISequenceSubRule<ILigand> rule = new CIPLigandRule();
          Assert.assertEquals(-1, rule.compare(ligandF, ligandI));
          Assert.assertEquals(-1, rule.compare(ligandF, ligandBr));
          Assert.assertEquals(-1, rule.compare(ligandF, ligandCl));
          Assert.assertEquals(-1, rule.compare(ligandCl, ligandI));
          Assert.assertEquals(-1, rule.compare(ligandCl, ligandBr));
          Assert.assertEquals(-1, rule.compare(ligandBr, ligandI));
  
          List<ILigand> ligands = new ArrayList<ILigand>();
          ligands.add(ligandI);
          ligands.add(ligandBr);
          ligands.add(ligandF);
          ligands.add(ligandCl);
          Collections.sort(ligands, new CIPLigandRule());
  
          Assert.assertEquals("F", ligands.get(0).getLigandAtom().getSymbol());
          Assert.assertEquals("Cl", ligands.get(1).getLigandAtom().getSymbol());
          Assert.assertEquals("Br", ligands.get(2).getLigandAtom().getSymbol());
          Assert.assertEquals("I", ligands.get(3).getLigandAtom().getSymbol());
      }
test_case.class_method_signature: CIPLigandRuleTest.testCBrIFCl()
test_case.full_signature: @Test public void testCBrIFCl()
test_case.identifier: testCBrIFCl
test_case.invocations: parseSmiles getAtom getAtom getAtom getAtom getAtom getAtom getAtom getAtom assertEquals compare assertEquals compare assertEquals compare assertEquals compare assertEquals compare assertEquals compare add add add add sort assertEquals getSymbol getLigandAtom get assertEquals getSymbol getLigandAtom get assertEquals getSymbol getLigandAtom get assertEquals getSymbol getLigandAtom get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testCBrIFCl()
focal_class.declarator: numberRule = new CombinedAtomicMassNumberRule()
focal_class.original_string: CombinedAtomicMassNumberRule numberRule = new CombinedAtomicMassNumberRule();
focal_class.type: CombinedAtomicMassNumberRule
focal_class.var_name: numberRule
focal_class.file: descriptor/cip/src/main/java/org/openscience/cdk/geometry/cip/rules/CIPLigandRule.java
focal_class.identifier: CIPLigandRule
focal_class.interfaces: implements ISequenceSubRule<ILigand>
focal_class.class_method_signature: CIPLigandRule.compare(ILigand ligand1, ILigand ligand2)
focal_class.full_signature: @Override public int compare(ILigand ligand1, ILigand ligand2)
focal_class.identifier: compare
focal_class.modifiers: @Override public
focal_class.parameters: (ILigand ligand1, ILigand ligand2)
focal_class.return: int
focal_class.signature: int compare(ILigand ligand1, ILigand ligand2)
focal_class.class_method_signature: CIPLigandRule.order(ILigand[] ligands)
focal_class.full_signature: private ILigand[] order(ILigand[] ligands)
focal_class.identifier: order
focal_class.modifiers: private
focal_class.parameters: (ILigand[] ligands)
focal_class.return: ILigand[]
focal_class.signature: ILigand[] order(ILigand[] ligands)
focal_method.body: @Override
      public int compare(ILigand ligand1, ILigand ligand2) {
          int numberComp = numberRule.compare(ligand1, ligand2);
          if (numberComp != 0) return numberComp;
  
          // OK, now I need to recurse...
          ILigand[] ligand1Ligands = CIPTool.getLigandLigands(ligand1);
          ILigand[] ligand2Ligands = CIPTool.getLigandLigands(ligand2);
          // if neither have ligands:
          if (ligand1Ligands.length == 0 && ligand2Ligands.length == 0) return 0;
          // else if one has no ligands
          if (ligand1Ligands.length == 0) return -1;
          if (ligand2Ligands.length == 0) return 1;
          // ok, both have at least one ligand
          int minLigandCount = Math.min(ligand1Ligands.length, ligand2Ligands.length);
          if (ligand1Ligands.length > 1) ligand1Ligands = order(ligand1Ligands);
          if (ligand2Ligands.length > 1) ligand2Ligands = order(ligand2Ligands);
          // first do a basic number rule
          for (int i = 0; i < minLigandCount; i++) {
              int comparison = numberRule.compare(ligand1Ligands[i], ligand2Ligands[i]);
              if (comparison != 0) return comparison;
          }
          if (ligand1Ligands.length == ligand2Ligands.length) {
              // it that does not resolve it, do a full, recursive compare
              for (int i = 0; i < minLigandCount; i++) {
                  int comparison = compare(ligand1Ligands[i], ligand2Ligands[i]);
                  if (comparison != 0) return comparison;
              }
          }
          // OK, if we reached this point, then the ligands they 'share' are all equals, so the one
          // with more ligands wins
          if (ligand1Ligands.length > ligand2Ligands.length)
              return 1;
          else if (ligand1Ligands.length < ligand2Ligands.length)
              return -1;
          else
              return 0;
      }
focal_method.class_method_signature: CIPLigandRule.compare(ILigand ligand1, ILigand ligand2)
focal_method.full_signature: @Override public int compare(ILigand ligand1, ILigand ligand2)
focal_method.identifier: compare
focal_method.invocations: compare getLigandLigands getLigandLigands min order order compare compare
focal_method.modifiers: @Override public
focal_method.parameters: (ILigand ligand1, ILigand ligand2)
focal_method.return: int
focal_method.signature: int compare(ILigand ligand1, ILigand ligand2)