Debian Codegraph @

src/uk/me/parabola/tdbfmt/CopyrightBlock.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Steve Ratcliffe
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 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: 23-Sep-2007
16 */
17 package uk.me.parabola.tdbfmt;
18
19 import uk.me.parabola.io.FileBlock;
20 import uk.me.parabola.io.StructuredOutputStream;
21 import uk.me.parabola.log.Logger;
22 import uk.me.parabola.io.StructuredInputStream;
23
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Set;
28 import java.util.HashSet;
29
30 /**
31 * A copyright block consists of a number of copyright segments.
32 *
33 * @author Steve Ratcliffe
34 */
35 class CopyrightBlock extends FileBlock {
36 public static final int BLOCK_ID = 0x44;
37
38 private static final Logger log = Logger.getLogger(CopyrightBlock.class);
39
40 private final List<CopyrightSegment> segments = new ArrayList<>();
41 private final Set<CopyrightSegment> copySet = new HashSet<>();
42
43 CopyrightBlock() {
44 super(BLOCK_ID);
45 }
46
47 CopyrightBlock(StructuredInputStream ds) throws IOException {
48 super(BLOCK_ID);
49
50 while (!ds.testEof()) {
51 CopyrightSegment segment = new CopyrightSegment(ds);
52
53 log.info("segment: " + segment);
54 segments.add(segment);
55 }
56 }
57
58 /**
59 * This is to overridden in a subclass.
60 */
61 protected void writeBody(StructuredOutputStream ds) throws IOException {
62 for (CopyrightSegment seg : segments) {
63 seg.write(ds);
64 }
65 }
66
67 /**
68 * Add a copyright segment. We only add unique ones.
69 * @param seg The copyright segment to add.
70 */
71 public void addSegment(CopyrightSegment seg) {
72 if (copySet.add(seg))
73 segments.add(seg);
74 }
75 }