Class KnuthPenalty

  • Direct Known Subclasses:
    ActiveCell.FillerPenalty, WhitespaceManagementPenalty

    public class KnuthPenalty
    extends KnuthElement
    An instance of this class represents information about a feasible breaking point; it does not represent any piece of content. A KnuthPenalty is a feasible breaking point unless its value is infinity; a KnuthPenalty whose value is -infinity represents a forced break. A KnuthPenalty is suppressed, and its width is ignored, if it is not a chosen breaking point; for example, a KnuthPenalty representing a hyphenation point has a width (the "-" width), which must be ignored if that point is not chosen as a breaking point. Besides the inherited methods and attributes, this class has two more attributes and the methods used to get them: the penalty value, which is a kind of "aesthetic cost" (the higher the value, the more unsightly the breaking point), and a boolean that marks KnuthPenalties which should not be chosen as breaking points for consecutive lines.
    • Field Detail

      • FLAGGED_PENALTY

        public static final int FLAGGED_PENALTY
        Used for flagged penalties. See Knuth algorithm.
        See Also:
        Constant Field Values
      • DUMMY_ZERO_PENALTY

        public static final KnuthPenalty DUMMY_ZERO_PENALTY
        Dummy, zero-width penalty
      • penalty

        private int penalty
      • penaltyFlagged

        private boolean penaltyFlagged
      • breakClass

        private int breakClass
    • Constructor Detail

      • KnuthPenalty

        public KnuthPenalty​(int width,
                            int penalty,
                            boolean penaltyFlagged,
                            Position pos,
                            boolean auxiliary)
        Create a new KnuthPenalty.
        Parameters:
        width - the width of this penalty
        penalty - the penalty value of this penalty
        penaltyFlagged - is this penalty flagged?
        pos - the Position stored in this penalty
        auxiliary - is this penalty auxiliary?
      • KnuthPenalty

        public KnuthPenalty​(int width,
                            int penalty,
                            boolean penaltyFlagged,
                            int breakClass,
                            Position pos,
                            boolean isAuxiliary)
        Create a new KnuthPenalty.
        Parameters:
        width - the width of this penalty
        penalty - the penalty value of this penalty
        penaltyFlagged - is this penalty flagged?
        breakClass - the break class of this penalty (one of Constants.EN_AUTO, Constants.EN_COLUMN, Constants.EN_PAGE, Constants.EN_EVEN_PAGE, Constants.EN_ODD_PAGE).
        pos - the Position stored in this penalty
        isAuxiliary - is this penalty auxiliary?
    • Method Detail

      • getBreakClassName

        private static java.lang.String getBreakClassName​(int breakClass)
      • valueOf

        protected static java.lang.String valueOf​(int penaltyValue)
        Get the penalty's value as a String. (Mainly used in toString() methods, to improve readability of the trace logs.) TODO: shouldn't be penalty a class of its own?
        Parameters:
        penaltyValue - the penalty value
        Returns:
        the penalty value as a String
      • isPenalty

        public boolean isPenalty()
        Overrides:
        isPenalty in class ListElement
        Returns:
        true if this element is a KnuthPenalty.
      • getPenalty

        public int getPenalty()
        Overrides:
        getPenalty in class KnuthElement
        Returns:
        the penalty value of this penalty.
      • setPenalty

        public void setPenalty​(int penalty)
        Sets a new penalty value.
        Parameters:
        penalty - the new penalty value
      • isPenaltyFlagged

        public boolean isPenaltyFlagged()
        Returns:
        true is this penalty is a flagged one.
      • isForcedBreak

        public boolean isForcedBreak()
        Overrides:
        isForcedBreak in class ListElement
        Returns:
        true if the element is a penalty and represents a forced break.
      • getBreakClass

        public int getBreakClass()
        Returns:
        the break class of this penalty (EN_AUTO, EN_COLUMN, EN_PAGE, EN_EVEN_PAGE, EN_ODD_PAGE)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object