/** * Merges two CSS selector parts into one. * The current instance will be the left part of the merged selector. * * @param rightCSS The right part of the merged selector. * @return The two parts merged as a CSS selector. */ public CssFinder merge(CssFinder rightCSS) { if (!rightCSS.canFetchAllElementsOfTheQueryByItself()) { return CSS_NOT_NATIVELY_SUPPORTED; } if (selectorsHaveDifferentTags(this, rightCSS) && noneOfTheTagsIsTheUniversalSelector(this, rightCSS)) { // TODO throw custom exception here, catch somewhere above so we can warn the user about useless selectors (not fail silently like jQuery) throw new IllegalArgumentException("The attempted selector has two element (tag) selectors at the same level. " + "It is incorrect and would never fetch any elements (as no element has more than one tag)."); } if (this.hasUniversalSelector()) { return new CssFinder( this.getLeftPart(), rightCSS.getTag(), this.getRightPart() + rightCSS.getRightPart() ); } else { return new CssFinder( this.getLeftPart(), this.getTag(), this.getRightPart() + rightCSS.getRightPart() ); } }
/** * Merges two CSS selector parts into one. * The current instance will be the left part of the merged selector. * * @param rightCSS The right part of the merged selector. * @return The two parts merged as a CSS selector. */ public CssFinder merge(CssFinder rightCSS) { if (!rightCSS.canFetchAllElementsOfTheQueryByItself()) { return CSS_NOT_NATIVELY_SUPPORTED; } if (selectorsHaveDifferentTags(this, rightCSS) && noneOfTheTagsIsTheUniversalSelector(this, rightCSS)) { // TODO throw custom exception here, catch somewhere above so we can warn the user about useless selectors (not fail silently like jQuery) throw new IllegalArgumentException("The attempted selector has two element (tag) selectors at the same level. " + "It is incorrect and would never fetch any elements (as no element has more than one tag)."); } if (this.hasUniversalSelector()) { return new CssFinder( this.getLeftPart(), rightCSS.getTag(), this.getRightPart() + rightCSS.getRightPart() ); } else { return new CssFinder( this.getLeftPart(), this.getTag(), this.getRightPart() + rightCSS.getRightPart() ); } }