Skip to content

Commit

Permalink
(#130) Unify Object and Page interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciofx committed Jan 24, 2024
1 parent 450c9d3 commit 1599950
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 67 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/github/fabriciofx/cactoos/pdf/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ public interface Object {
/**
* Object indirect.
*
* @param parent Parent number, if there is one
* @return An object indirect
* @throws Exception if fails
*/
Indirect indirect() throws Exception;
Indirect indirect(int... parent) throws Exception;

/**
* Print object.
*
* @param output Output to print
* @param parent Parent number, if there is one
* @throws Exception if fails
*/
void print(OutputStream output) throws Exception;
void print(OutputStream output, int... parent) throws Exception;
}
21 changes: 1 addition & 20 deletions src/main/java/com/github/fabriciofx/cactoos/pdf/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@

import com.github.fabriciofx.cactoos.pdf.content.Contents;
import com.github.fabriciofx.cactoos.pdf.resource.Resources;
import java.io.OutputStream;

/**
* PageDefault.
*
* @since 0.0.1
*/
@SuppressWarnings("PMD.ExtendsObject")
public interface Page {
public interface Page extends Object {
/**
* Page Resources.
*
Expand All @@ -47,22 +46,4 @@ public interface Page {
* @return Contents
*/
Contents contents();

/**
* Build an Indirect.
*
* @param parent Page's parent
* @return An indirect
* @throws Exception if fails
*/
Indirect indirect(int parent) throws Exception;

/**
* Print object.
*
* @param output Output to print
* @param parent Parent number
* @throws Exception if fails
*/
void print(OutputStream output, int parent) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ public Contents(final List<Content> list) {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
throw new UnsupportedOperationException(
"there is no indirect to contents"
);
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
for (final Content content : this) {
content.print(output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public List<Resource> resource() {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final byte[] stream = this.asStream();
final Dictionary dictionary = new Dictionary()
.add("Length", new Int(stream.length))
Expand All @@ -102,7 +102,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public List<Resource> resource() {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final byte[] stream = this.asStream();
final Dictionary dictionary = new Dictionary()
.add("Length", new Int(stream.length))
Expand All @@ -168,7 +168,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
this.fmt.print(output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public List<Resource> resource() {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final Indirect indirect = this.origin.indirect();
final byte[] stream = this.asStream();
return new DefaultIndirect(
Expand All @@ -143,7 +143,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public List<Resource> resource() {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final byte[] stream = this.asStream();
final Dictionary dictionary = new Dictionary()
.add("Length", new Int(stream.length))
Expand All @@ -252,7 +252,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public int height() throws Exception {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final Header header = this.raw.header();
final byte[] stream = this.asStream();
final Dictionary dictionary = new Dictionary()
Expand All @@ -130,7 +130,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public int height() throws Exception {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final Header header = this.raw.header();
final Palette palette = this.raw.palette();
final Indirect pal = palette.indirect();
Expand Down Expand Up @@ -161,7 +161,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
this.raw.palette().print(output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ public List<Resource> resource() {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
throw new UnsupportedOperationException(
"there is not indirect in jpeg body"
);
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
// Empty of purpose.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,17 @@ public List<Resource> resource() {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
throw new UnsupportedOperationException(
"There is no indirect into PNG body"
);
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
// Empty of purpose.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public List<Resource> resource() {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final byte[] stream = this.asStream();
final Dictionary dictionary = new Dictionary()
.add("Length", new Int(stream.length))
Expand All @@ -136,7 +136,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Catalog(final int number, final int generation, final Pages pages) {
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final Indirect indirect = this.pages.indirect();
final Dictionary dictionary = new Dictionary()
.add("Type", new Name("Catalog"))
Expand All @@ -91,7 +91,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
this.pages.print(output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,15 @@ public Information(
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
return new DefaultIndirect(this.number, this.generation, this.metadata);
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public Contents contents() {
}

@Override
public Indirect indirect(final int parent) throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final Indirect resrcs = this.resources().indirect();
Array refs = new Array();
for (final Content content : this.contents) {
Expand All @@ -137,7 +137,7 @@ public Indirect indirect(final int parent) throws Exception {
.add("Type", new Name("Page"))
.add("Resources", new Text(resrcs.reference().asString()))
.add("Contents", refs)
.add("Parent", new Text(new Reference(parent, 0).asString()));
.add("Parent", new Text(new Reference(parent[0], 0).asString()));
return new DefaultIndirect(
this.number,
this.generation,
Expand All @@ -148,7 +148,7 @@ public Indirect indirect(final int parent) throws Exception {
@Override
public void print(
final OutputStream output,
final int parent
final int... parent
) throws Exception {
output.write(this.indirect(parent).asBytes());
this.resources().print(output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public Contents contents() {
}

@Override
public Indirect indirect(final int parent) throws Exception {
final Indirect indirect = this.origin.indirect(parent);
public Indirect indirect(final int... parent) throws Exception {
final Indirect indirect = this.origin.indirect(parent[0]);
final Dictionary dictionary = indirect.dictionary().add(
"Rotate",
new Int(this.angle)
Expand All @@ -87,9 +87,9 @@ public Indirect indirect(final int parent) throws Exception {
@Override
public void print(
final OutputStream output,
final int parent
final int... parent
) throws Exception {
output.write(this.indirect(parent).asBytes());
output.write(this.indirect(parent[0]).asBytes());
this.resources().print(output);
this.contents().print(output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public DefaultPages(
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
Array kds = new Array();
for (final Page page : this) {
final Indirect indirect = page.indirect(this.number);
Expand All @@ -136,7 +136,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
for (final Page page : this) {
page.print(output, this.number);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Margins(
}

@Override
public Indirect indirect() throws Exception {
public Indirect indirect(final int... parent) throws Exception {
final Indirect indirect = this.origin.indirect();
final Pattern pattern = Pattern.compile("BT.*TL");
final Matcher matcher = pattern.matcher(
Expand Down Expand Up @@ -154,7 +154,10 @@ public Indirect indirect() throws Exception {
}

@Override
public void print(final OutputStream output) throws Exception {
public void print(
final OutputStream output,
final int... parent
) throws Exception {
output.write(this.indirect().asBytes());
this.origin.print(output);
}
Expand Down
Loading

0 comments on commit 1599950

Please sign in to comment.