All Downloads are FREE. Search and download functionalities are using the official Maven repository.

reader-pdd-1.1.src.main.java.com.rempl.readers.pdd.Puzzle Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
/**
 * Copyright (c) 2011, REMPL.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1) Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 2) Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution.
 * 3) Neither the name of the REMPL.com nor the names of its
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.rempl.readers.pdd;

// string manipulations
import org.apache.commons.lang.StringUtils;

/**
 * One puzzle convertable to UML.
 *
 * @author Yegor Bugayenko ([email protected])
 * @version $Id: Puzzle.java 795 2011-03-19 10:17:23Z [email protected] $
 */
public final class Puzzle {

    /**
     * The name of the ticket.
     * @see #Puzzle(String)
     */
    private String ticket;

    /**
     * The prefix of the puzzle.
     */
    private String prefix = "";

    /**
     * The body of the puzzle.
     * @see #setBody(String)
     */
    @SuppressWarnings("PMD.AvoidStringBufferField")
    private final StringBuffer body = new StringBuffer();

    /**
     * The estimate in minutes.
     * @see #setEstimate(Integer)
     */
    private Integer estimate = 0;

    /**
     * Lines interval where the puzzle was found.
     * @see #setLines(String)
     */
    private String lines;

    /**
     * Possible wwner of the puzzle.
     */
    public enum Owner {
        /**
         * Uplink of the ticket.
         */
        UPLINK,
        /**
         * Who is currently working with it.
         */
        AUTHOR,
        /**
         * Someone else, who we're waiting for.
         */
        SOMEONE
    };

    /**
     * Owner of the puzzle.
     * @see #setOwner(Puzzle.Owner)
     */
    private Puzzle.Owner owner = Puzzle.Owner.SOMEONE;

    /**
     * Public ctor.
     * @param tkt The ticket number
     */
    public Puzzle(final String tkt) {
        this.ticket = tkt;
    }

    /**
     * Set prefix used in the source file.
     * @param pfx The prefix
     */
    public void setPrefix(final String pfx) {
        this.prefix = pfx;
    }

    /**
     * Append string to the body.
     * @param appendix What to append to the body
     */
    public void appendBody(final String appendix) {
        this.body.append(StringUtils.strip(appendix) + " ");
    }

    /**
     * Set estimate of the puzzle, in minutes.
     * @param min Minutes
     */
    public void setEstimate(final Integer min) {
        this.estimate = min;
    }

    /**
     * Set lines interval.
     * @param first The first line of the puzzle
     * @param last The last line of the puzzle
     */
    public void setLines(final Integer first, final Integer last) {
        this.lines = first + "-" + last;
    }

    /**
     * Set owner of the puzzle.
     * @param owr The owner
     */
    public void setOwner(final Puzzle.Owner owr) {
        this.owner = owr;
    }

    /**
     * Get ticket name.
     * @return The name of the ticket
     */
    public String getTicket() {
        return this.ticket;
    }

    /**
     * Get prefix.
     * @return The prefix
     */
    public String getPrefix() {
        return this.prefix;
    }

    /**
     * Get body of the puzzle.
     * @return The body
     */
    public String getBody() {
        final String txt = this.body.toString();
        if (txt.length() == 0) {
            return "empty";
        }
        return StringUtils.strip(txt);
    }

    /**
     * Get estimate in minutes.
     * @return Minutes
     */
    public Integer getEstimate() {
        return this.estimate;
    }

    /**
     * Get lines interval where the puzzle was found.
     * @return The lines interval, like "15-18"
     */
    public String getLines() {
        return this.lines;
    }

    /**
     * Get owner of the puzzle, as a text.
     * @return The title of the owner
     */
    public String getOwnerTitle() {
        String txt;
        switch (this.owner) {
            case UPLINK:
                txt = "uplink";
                break;
            case AUTHOR:
                txt = "author";
                break;
            case SOMEONE:
                txt = "someone";
                break;
            default:
                txt = "unknown";
                break;
        }
        return txt;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy