1 /*
2 * Prometheus: Application Framework
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.prometheus.service.sheet;
18
19 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20 import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
21
22 import java.io.OutputStream;
23
24 /**
25 * Sheet Service interface.
26 */
27 public interface PrometheusSheetWorkBook {
28 /**
29 * Is the WorkBook readOnly?
30 *
31 * @return true/false
32 */
33 boolean isReadOnly();
34
35 /**
36 * Save the workBook to output stream.
37 *
38 * @param pOutput the output stream
39 * @throws OceanusException on error
40 */
41 void saveToStream(OutputStream pOutput) throws OceanusException;
42
43 /**
44 * Create a new Sheet with the given name.
45 *
46 * @param pName the name of the new sheet
47 * @return the new sheet
48 * @throws OceanusException on error
49 */
50 PrometheusSheetSheet newSheet(String pName) throws OceanusException;
51
52 /**
53 * Create a new Sheet with the given name.
54 *
55 * @param pName the name of the new sheet
56 * @param pNumRows the number of rows to allocate
57 * @param pNumCols the number of columns to allocate
58 * @return the new sheet
59 * @throws OceanusException on error
60 */
61 PrometheusSheetSheet newSheet(String pName,
62 int pNumRows,
63 int pNumCols) throws OceanusException;
64
65 /**
66 * Access an existing Sheet with the given name.
67 *
68 * @param pName the name of the sheet
69 * @return the sheet (or null if no such sheet)
70 * @throws OceanusException on error
71 */
72 PrometheusSheetSheet getSheet(String pName) throws OceanusException;
73
74 /**
75 * Obtain a view of the named range.
76 *
77 * @param pName the name of the range
78 * @return the view of the range
79 * @throws OceanusException on error
80 */
81 PrometheusSheetView getRangeView(String pName) throws OceanusException;
82
83 /**
84 * Create data formatter.
85 *
86 * @return the new formatter
87 */
88 default OceanusDataFormatter createFormatter() {
89 /* Allocate the formatter and set date format */
90 final OceanusDataFormatter myFormatter = new OceanusDataFormatter();
91 myFormatter.setFormat(PrometheusSheetFormats.OASIS_DATE);
92 myFormatter.setAccountingWidth(PrometheusSheetFormats.ACCOUNTING_WIDTH);
93
94 /* return the formatter */
95 return myFormatter;
96 }
97 }