Debian Codegraph @

src/uk/me/parabola/imgfmt/app/mdr/Mdr9.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2009.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13
14 package uk.me.parabola.imgfmt.app.mdr;
15
16 import java.util.LinkedHashMap;
17 import java.util.Map;
18
19 import uk.me.parabola.imgfmt.app.ImgFileWriter;
20
21 /**
22 * An index into mdr10. There is a single byte group number followed by
23 * the first record in mdr10 that belongs to that group.
24 *
25 * @author Steve Ratcliffe
26 */
27 public class Mdr9 extends MdrSection implements HasHeaderFlags {
28 private final Map<Integer, Integer> index = new LinkedHashMap<>();
29
30 public Mdr9(MdrConfig config) {
31 setConfig(config);
32 }
33
34 public void writeSectData(ImgFileWriter writer) {
35 int poiSize = getSizes().getPoiSize();
36 for (Map.Entry<Integer, Integer> ent : index.entrySet()) {
37 int group = ent.getKey();
38 writer.put1u(group);
39 writer.putNu(poiSize, ent.getValue());
40 }
41 }
42
43 /**
44 * The item size is one byte for the group and then enough bytes for the
45 * index into mdr10.
46 * @return Just return 4 for now.
47 */
48 public int getItemSize() {
49 return 1 + getSizes().getPoiSize();
50 }
51
52 /**
53 * The number of records in this section.
54 *
55 * @return The number of items in the section.
56 */
57 protected int numberOfItems() {
58 return index.size();
59 }
60
61 public void setGroups(Map<Integer, Integer> groupSizes) {
62 int offset = 1;
63 for (Map.Entry<Integer, Integer> ent : groupSizes.entrySet()) {
64 index.put(ent.getKey(), offset);
65 offset += ent.getValue();
66 }
67 }
68
69 public int getExtraValue() {
70 return 0x00;
71 }
72 }