Menu

#185 Additional util methods

None
open
nobody
util (1)
1
2012-10-31
2012-10-31
John May
No

The 'isEmpty' feature request got me thinking of some other useful utilities that would be simple to implement and in my opinion improve usability and readability.

- `.clear()` remove all atoms/bonds from the AtomContainer/ContainerSets etc. - simply invokes the `removesAllAtomsAndBonds`
- `addAtom()` and `addBond` could return true/false as to whether the container was modified - this is useful as there is currently no indication when duplicates are added.

~~~~~:::java
public void addAtom(IAtom atom)
{
if (contains(atom))
{
return; // false
}

    if (atomCount + 1 >= atoms.length)
    {
        growAtomArray();
    }
    atoms[atomCount] = atom;
    atomCount++;
            // return true
}

~~~~~

Discussion

  • John May

    John May - 2012-10-31

    Oh and we can also do this...

        public void add(IAtomContainer atomContainer);
    
        public void add(IAtom atom);
    
        public void add(IBond bond);
    

    currently code reads as follows:

    container.addAtom(atom) - container add atom atom

    this could easily be reduced to

    container.add(atom) - container add atom

    The existing methods could stay but the util methods would make implementing code look a lot cleaner.

     
  • John May

    John May - 2012-10-31
    • milestone: -->
     

Log in to post a comment.

MongoDB Logo MongoDB