1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 cr.define('print_preview', function() {
9 * An immutable ordered set of page numbers.
10 * @param {!Array<number>} pageNumberList A list of page numbers to include
14 function PageNumberSet(pageNumberList) {
16 * Internal data store for the page number set.
17 * @type {!Array<number>}
20 this.pageNumberSet_ = pageListToPageSet(pageNumberList);
23 PageNumberSet.prototype = {
24 /** @return {number} The number of page numbers in the set. */
26 return this.pageNumberSet_.length;
30 * @param {number} index 0-based index of the page number to get.
31 * @return {number} Page number at the given index.
33 getPageNumberAt: function(index) {
34 return this.pageNumberSet_[index];
38 * @param {number} pageNumber 1-based page number to check for.
39 * @return {boolean} Whether the given page number is in the page range.
41 hasPageNumber: function(pageNumber) {
42 return arrayContains(this.pageNumberSet_, pageNumber);
46 * @param {number} pageNumber 1-based number of the page to get index of.
47 * @return {number} 0-based index of the given page number with respect to
48 * all of the pages in the page range.
50 getPageNumberIndex: function(pageNumber) {
51 return this.pageNumberSet_.indexOf(pageNumber);
54 /** @return {!Array<number>} Array representation of the set. */
56 return this.pageNumberSet_.slice(0);
62 PageNumberSet: PageNumberSet