Skip to content

Commit

Permalink
Improves javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Håkansson committed Dec 7, 2016
1 parent 8980432 commit 392debf
Show file tree
Hide file tree
Showing 36 changed files with 448 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public BrailleNotationConverter(String separator) {
this.separator = separator;
}

/**
* Parses a string for braille notation and converts it to Unicode braille patterns
* @param p the string to parse
* @return returns the parsed string
*/
public String parseBrailleNotation(String p) {
String[] s = p.split(separator);
if (s.length == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/org/daisy/dotify/common/collection/ArrayStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Provides an unsynchronized stack based on ArrayList instead of Vector.
*
* @author Joel Håkansson
* @param <E> the type of array
*/
public class ArrayStack<E> extends ArrayList<E> {

Expand Down
4 changes: 4 additions & 0 deletions src/org/daisy/dotify/common/collection/CompoundIterable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
public class CompoundIterable<T> implements Iterable<T> {
private final Iterable<? extends Iterable<T>> iterables;

/**
* Creates a new compound iterable
* @param iterables the iterables to use
*/
public CompoundIterable(Iterable<? extends Iterable<T>> iterables) {
this.iterables = iterables;
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/daisy/dotify/common/collection/CompoundIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
public class CompoundIterator<T> implements Iterator<T> {
ArrayList<Iterator<T>> iterators;

/**
* Creates a new compound iterator
* @param iterables the iterables to use in this iterator
*/
public CompoundIterator(Iterable<? extends Iterable<T>> iterables) {
iterators = new ArrayList<>();
for (Iterable<T> e : iterables) {
Expand Down
5 changes: 5 additions & 0 deletions src/org/daisy/dotify/common/collection/SplitList.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
public class SplitList<T> {
private final List<T> first, second;

/**
* Creates a new split list
* @param first the first part of the list
* @param second the second part of the list
*/
public SplitList(List<T> first, List<T> second) {
this.first = first;
this.second = second;
Expand Down
10 changes: 10 additions & 0 deletions src/org/daisy/dotify/common/io/AbstractResourceLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@
public abstract class AbstractResourceLocator implements ResourceLocator {
private final String basePath;

/**
* Creates a new abstract resource locator. Resources are resolved relative
* to the location of the concrete implementation.
*/
public AbstractResourceLocator() {
this(null);
}

/**
* Creates a new abstract resource locator with the specified sub-path prefix, in other
* words a sub-path from where all resources are resolved. Resources are resolved relative
* to the location of the concrete implementation.
* @param basePath the sub-path prefix
*/
public AbstractResourceLocator(String basePath) {
if (basePath==null || basePath.equals("")) {
this.basePath = "";
Expand Down
9 changes: 9 additions & 0 deletions src/org/daisy/dotify/common/io/ByteArrayInputStreamMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
import java.io.IOException;
import java.io.InputStream;

/**
* Provides a in-memory input stream maker.
* @author Joel Håkansson
*
*/
public class ByteArrayInputStreamMaker implements InputStreamMaker {
private final byte[] buf;

/**
* Creates a new byte array input stream maker with the specified data.
* @param buf the data
*/
public ByteArrayInputStreamMaker(byte[] buf) {
this.buf = buf;
}
Expand Down
5 changes: 5 additions & 0 deletions src/org/daisy/dotify/common/io/ByteArrayStreamJuggler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import java.io.IOException;
import java.io.OutputStream;

/**
* Provides an in-memory stream juggler.
*
* @author Joel Håkansson
*/
public class ByteArrayStreamJuggler implements StreamJuggler {
private final int BUF_SIZE = 65536;
private InputStreamMaker ci;
Expand Down
36 changes: 36 additions & 0 deletions src/org/daisy/dotify/common/io/FileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import java.nio.channels.FileChannel;
import java.util.logging.Logger;

/**
* Provides file IO tools.
* @author Joel Håkansson
*
*/
public class FileIO {

/**
Expand All @@ -35,10 +40,22 @@ public static void copy(InputStream is, OutputStream os) throws IOException {
bis.close();
}

/**
* Copies an input file to an output file
* @param input the input file
* @param output the output file
* @throws IOException if IO fails
*/
public static void copy(File input, File output) throws IOException {
copy(new FileInputStream(input), new FileOutputStream(output));
}

/**
* Copies an input file to an output file
* @param sourceFile the source file
* @param destFile the destination file
* @throws IOException if IO fails
*/
public static void copyFile(File sourceFile, File destFile) throws IOException {
if (!destFile.exists()) {
destFile.createNewFile();
Expand All @@ -60,12 +77,22 @@ public static void copyFile(File sourceFile, File destFile) throws IOException {
}
}

/**
* Creates a temp file
* @return returns a the created file
* @throws IOException if IO fails
*/
public static File createTempFile() throws IOException {
File ret = File.createTempFile("temp", null, null);
ret.deleteOnExit();
return ret;
}

/**
* Creates a temp folder
* @return returns the created folder
* @throws IOException if IO fails
*/
public static File createTempDir() throws IOException {
File temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
if (!temp.delete()) {
Expand All @@ -87,6 +114,11 @@ public static File createTempDir() throws IOException {
return f;
}

/**
* Copies a folder recursively
* @param f the source folder
* @param out the destination folder
*/
public static void copyRecursive(File f, File out) {
if (f.isDirectory()) {
out.mkdirs();
Expand All @@ -102,6 +134,10 @@ public static void copyRecursive(File f, File out) {
}
}

/**
* Deletes a folder recursively
* @param f the folder to delete
*/
public static void deleteRecursive(File f) {
if (f.isDirectory()) {
for (File f1 : f.listFiles()) {
Expand Down
9 changes: 9 additions & 0 deletions src/org/daisy/dotify/common/io/FileInputStreamMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
import java.io.IOException;
import java.io.InputStream;

/**
* Provides a file based input stream maker
* @author Joel Håkansson
*
*/
public class FileInputStreamMaker implements InputStreamMaker {
private final File f;

/**
* Creates a new input stream maker with the specified file as source
* @param f the file containing the stream source
*/
public FileInputStreamMaker(File f) {
this.f = f;
}
Expand Down
9 changes: 9 additions & 0 deletions src/org/daisy/dotify/common/io/StreamJuggler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
import java.io.IOException;
import java.io.OutputStream;

/**
* <p>Provides a juggler for streams.</p>
* <p>This interface can be used to limit the code needed to handle temporary streams
* in a sequence of read/write operations. After each step (stream written)
* the juggler can be reset by calling reset() and the streams are ready to be used
* again. Very convenient together with optional steps.</p>
*
* @author Joel Håkansson
*/
public interface StreamJuggler extends Closeable {

/**
Expand Down
3 changes: 2 additions & 1 deletion src/org/daisy/dotify/common/layout/SplitPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.util.List;

/**
* Provides a data object to keep the information about a split point result.
* Provides a data object to keep the information about a split point result.
* @param <T> the type of split point units
* @author Joel Håkansson
*/
public class SplitPoint<T extends SplitPointUnit> {
Expand Down
1 change: 1 addition & 0 deletions src/org/daisy/dotify/common/layout/SplitPointCost.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
*
* @author Joel Håkansson
* @param <T> the type of split point unit
*
*/
// @FunctionalInterface
Expand Down
27 changes: 27 additions & 0 deletions src/org/daisy/dotify/common/layout/SplitPointData.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,38 @@
import java.util.Arrays;
import java.util.List;

/**
* Provides split point data
* @author Joel Håkansson
*
* @param <T> the type of split point units
*/
public final class SplitPointData<T extends SplitPointUnit> {
private final List<T> units;
private final Supplements<T> supplements;

/**
* Creates a new instance with the specified units
* @param units the units
*/
@SafeVarargs
public SplitPointData(T ... units) {
this(Arrays.asList(units));
}

/**
* Creates a new instance with the specified units
* @param units the units
*/
public SplitPointData(List<T> units) {
this(units, null);
}

/**
* Creates a new instance with the specified units and supplements
* @param units the units
* @param supplements the supplements
*/
public SplitPointData(List<T> units, Supplements<T> supplements) {
this.units = units;
if (supplements==null) {
Expand All @@ -29,10 +48,18 @@ public T get(String id) {
}
}

/**
* Gets the split point data units
* @return returns the units
*/
public List<T> getUnits() {
return units;
}

/**
* Gets the split point data supplements
* @return the supplements
*/
public Supplements<T> getSupplements() {
return supplements;
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/daisy/dotify/common/layout/SplitPointHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* @author Joel Håkansson
*
* @param <T> the type of split point units
*/
public class SplitPointHandler<T extends SplitPointUnit> {
private final List<T> EMPTY_LIST = Collections.emptyList();
Expand All @@ -34,7 +35,6 @@ public double getCost(List<T> units, int breakpoint) {
};
}

@SafeVarargs
/**
* Splits the data at, or before, the supplied breakPoint according to the rules
* in the data. If force is used, rules may be broken to achieve a result.
Expand All @@ -43,6 +43,7 @@ public double getCost(List<T> units, int breakpoint) {
* @param units the data
* @return returns a split point result
*/
@SafeVarargs
public final SplitPoint<T> split(float breakPoint, boolean force, T ... units) {
return split(breakPoint, force, new SplitPointData<>(units));
}
Expand Down
27 changes: 21 additions & 6 deletions src/org/daisy/dotify/common/text/BreakPointHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* Breaks a paragraph of text into rows. It is assumed that all
* preferred break points are supplied with the input String.
* preferred break points are supplied with the input string.
*
* Soft hyphen (0x00ad) and zero width space (0x200b) characters
* can also be used for non-standard hyphenation.
Expand All @@ -29,10 +29,21 @@ public class BreakPointHandler {
private int offset;
private TreeMap<Integer, NonStandardHyphenationInfo> meta;

/**
* Provides a builder for break point handlers
* @author Joel Håkansson
*
*/
public static class Builder {
private final String str;
private final TreeMap<Integer, NonStandardHyphenationInfo> meta;

/**
* Creates a new builder with the string to break.
* All regular break points must be in supplied with the input string,
* represented by hyphen 0x2d, soft hyphen 0xad or space 0x20.
* @param str the string
*/
public Builder(String str) {
this.str = str;
this.meta = new TreeMap<>();
Expand Down Expand Up @@ -82,11 +93,7 @@ public BreakPointHandler build() {
public BreakPointHandler(String str) {
this(str, null, 0);
}
/*
public BreakPointHandler(String str, TreeMap<Integer, NonStandardHyphenationInfo> meta) {
this(str, meta, 0);
}*/


@SuppressWarnings("unchecked")
private BreakPointHandler(String str, TreeMap<Integer, NonStandardHyphenationInfo> meta, int offset) {
if (str==null) {
Expand Down Expand Up @@ -216,13 +223,21 @@ private BreakPoint finalizeBreakpointTrimTail(String head, String tail, boolean
return new BreakPoint(head, tail, hard);
}

/**
* Counts the remaining characters, excluding unused breakpoints.
* @return returns the number of remaining characters
*/
public int countRemaining() {
if (charsStr==null) {
return 0;
}
return getRemaining().length();
}

/**
* Gets the remaining characters, removing unused breakpoint characters.
* @return returns the remaining characters
*/
public String getRemaining() {
return finalizeResult(charsStr);
}
Expand Down
Loading

0 comments on commit 392debf

Please sign in to comment.