View | Details | Raw Unified | Return to bug 58740
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java (-23 / +31 lines)
Lines 276-281 Link Here
276
        return numberFormats.get(fmtId);
276
        return numberFormats.get(fmtId);
277
    }
277
    }
278
    
278
    
279
    /**
280
     * Case sensitive search.
281
     * Runs in O(n) time. Consider using a bidirectional map for faster reverse lookups.
282
     */
279
    private short getNumberFormatId(String fmt) {
283
    private short getNumberFormatId(String fmt) {
280
     // Find the key, and return that
284
     // Find the key, and return that
281
        for (Entry<Short,String> numFmt : numberFormats.entrySet()) {
285
        for (Entry<Short,String> numFmt : numberFormats.entrySet()) {
Lines 383-389 Link Here
383
    }
387
    }
384
388
385
    public XSSFFont getFontAt(int idx) {
389
    public XSSFFont getFontAt(int idx) {
386
        return fonts.get(idx);
390
        return fonts.get(idx); // 0-based index
387
    }
391
    }
388
392
389
    /**
393
    /**
Lines 403-417 Link Here
403
        }
407
        }
404
408
405
        if (idx != -1) {
409
        if (idx != -1) {
406
            return idx;
410
            return idx; // 0-based index
407
        }
411
        }
408
412
409
        idx = fonts.size();
413
        idx = fonts.size();
410
        fonts.add(font);
414
        fonts.add(font);
411
        return idx;
415
        return idx; // 0-based index
412
    }
416
    }
413
    public int putFont(XSSFFont font) {
417
    public int putFont(XSSFFont font) {
414
        return putFont(font, false);
418
        return putFont(font, false); // 0-based index
415
    }
419
    }
416
420
417
    public XSSFCellStyle getStyleAt(int idx) {
421
    public XSSFCellStyle getStyleAt(int idx) {
Lines 418-424 Link Here
418
        int styleXfId = 0;
422
        int styleXfId = 0;
419
423
420
        // 0 is the empty default
424
        // 0 is the empty default
421
        if(xfs.get(idx).getXfId() > 0) {
425
        if(xfs.get(idx).getXfId() > 0) { // 0-based index
422
            styleXfId = (int) xfs.get(idx).getXfId();
426
            styleXfId = (int) xfs.get(idx).getXfId();
423
        }
427
        }
424
428
Lines 426-440 Link Here
426
    }
430
    }
427
    public int putStyle(XSSFCellStyle style) {
431
    public int putStyle(XSSFCellStyle style) {
428
        CTXf mainXF = style.getCoreXf();
432
        CTXf mainXF = style.getCoreXf();
433
        int idx = xfs.indexOf(mainXF);
429
434
430
        if(! xfs.contains(mainXF)) {
435
        if (idx != -1) {
431
            xfs.add(mainXF);
436
            return idx; // 0-based index
432
        }
437
        }
433
        return xfs.indexOf(mainXF);
438
439
        idx = xfs.size();
440
        xfs.add(mainXF);
441
        return idx; // 0-based index
434
    }
442
    }
435
443
436
    public XSSFCellBorder getBorderAt(int idx) {
444
    public XSSFCellBorder getBorderAt(int idx) {
437
        return borders.get(idx);
445
        return borders.get(idx); // 0-based index
438
    }
446
    }
439
447
440
    /**
448
    /**
Lines 447-461 Link Here
447
    public int putBorder(XSSFCellBorder border) {
455
    public int putBorder(XSSFCellBorder border) {
448
        int idx = borders.indexOf(border);
456
        int idx = borders.indexOf(border);
449
        if (idx != -1) {
457
        if (idx != -1) {
450
            return idx;
458
            return idx; // 0-based index
451
        }
459
        }
452
        borders.add(border);
460
        borders.add(border);
453
        border.setThemesTable(theme);
461
        border.setThemesTable(theme);
454
        return borders.size() - 1;
462
        return borders.size() - 1; // 0-based index
455
    }
463
    }
456
464
457
    public XSSFCellFill getFillAt(int idx) {
465
    public XSSFCellFill getFillAt(int idx) {
458
        return fills.get(idx);
466
        return fills.get(idx); // 0-based index
459
    }
467
    }
460
468
461
    public List<XSSFCellBorder> getBorders(){
469
    public List<XSSFCellBorder> getBorders(){
Lines 484-498 Link Here
484
    public int putFill(XSSFCellFill fill) {
492
    public int putFill(XSSFCellFill fill) {
485
        int idx = fills.indexOf(fill);
493
        int idx = fills.indexOf(fill);
486
        if (idx != -1) {
494
        if (idx != -1) {
487
            return idx;
495
            return idx; // 0-based index
488
        }
496
        }
489
        fills.add(fill);
497
        fills.add(fill);
490
        return fills.size() - 1;
498
        return fills.size() - 1; // 0-based index
491
    }
499
    }
492
500
493
    @Internal
501
    @Internal
494
    public CTXf getCellXfAt(int idx) {
502
    public CTXf getCellXfAt(int idx) {
495
        return xfs.get(idx);
503
        return xfs.get(idx); // 0-based index
496
    }
504
    }
497
    
505
    
498
    /**
506
    /**
Lines 505-522 Link Here
505
    @Internal
513
    @Internal
506
    public int putCellXf(CTXf cellXf) {
514
    public int putCellXf(CTXf cellXf) {
507
        xfs.add(cellXf);
515
        xfs.add(cellXf);
508
        return xfs.size();
516
        return xfs.size(); // 1-based index
509
    }
517
    }
510
    
518
    
511
    @Internal
519
    @Internal
512
    public void replaceCellXfAt(int idx, CTXf cellXf) {
520
    public void replaceCellXfAt(int idx, CTXf cellXf) {
513
        xfs.set(idx, cellXf);
521
        xfs.set(idx, cellXf); // 0-based index
514
    }
522
    }
515
523
516
    @Internal
524
    @Internal
517
    public CTXf getCellStyleXfAt(int idx) {
525
    public CTXf getCellStyleXfAt(int idx) {
518
        try {
526
        try {
519
            return styleXfs.get(idx);
527
            return styleXfs.get(idx); // 0-based index
520
        }
528
        }
521
        catch (final IndexOutOfBoundsException e) {
529
        catch (final IndexOutOfBoundsException e) {
522
            return null;
530
            return null;
Lines 534-545 Link Here
534
    public int putCellStyleXf(CTXf cellStyleXf) {
542
    public int putCellStyleXf(CTXf cellStyleXf) {
535
        styleXfs.add(cellStyleXf);
543
        styleXfs.add(cellStyleXf);
536
        // TODO: check for duplicate
544
        // TODO: check for duplicate
537
        return styleXfs.size();
545
        return styleXfs.size(); // 1-based index
538
    }
546
    }
539
    
547
    
540
    @Internal
548
    @Internal
541
    protected void replaceCellStyleXfAt(int idx, CTXf cellStyleXf) {
549
    protected void replaceCellStyleXfAt(int idx, CTXf cellStyleXf) {
542
        styleXfs.set(idx, cellStyleXf);
550
        styleXfs.set(idx, cellStyleXf); // 0-based index
543
    }
551
    }
544
552
545
    /**
553
    /**
Lines 762-768 Link Here
762
770
763
    @Internal
771
    @Internal
764
    public CTDxf getDxfAt(int idx) {
772
    public CTDxf getDxfAt(int idx) {
765
        return dxfs.get(idx);
773
        return dxfs.get(idx); //0-based index
766
    }
774
    }
767
775
768
    /**
776
    /**
Lines 775-781 Link Here
775
    @Internal
783
    @Internal
776
    public int putDxf(CTDxf dxf) {
784
    public int putDxf(CTDxf dxf) {
777
        this.dxfs.add(dxf);
785
        this.dxfs.add(dxf);
778
        return this.dxfs.size();
786
        return this.dxfs.size(); //1-based index
779
    }
787
    }
780
788
781
    /**
789
    /**
Lines 798-804 Link Here
798
        xf.setBorderId(0);
806
        xf.setBorderId(0);
799
        xf.setXfId(0);
807
        xf.setXfId(0);
800
        int indexXf = putCellXf(xf);
808
        int indexXf = putCellXf(xf);
801
        return new XSSFCellStyle(indexXf - 1, xfSize - 1, this, theme);
809
        return new XSSFCellStyle(indexXf - 1, xfSize - 1, this, theme); //0-based index
802
    }
810
    }
803
811
804
    /**
812
    /**

Return to bug 58740