001package com.changenode;
002
003import java.util.EventListener;
004import java.util.StringTokenizer;
005
006/**
007 * Simple Calculator for demonstration purposes.
008 */
009public class Calculator {
010
011    private double state;
012
013    /**
014     *
015     * @param value to add to register
016     * @return the original Calculator object
017     */
018    public Calculator add(double value) {
019        state += value;
020        return this;
021    }
022
023    /**
024     *
025     * @param value to subtract from the register
026     * @return the original Calculator object
027     */
028    public Calculator subtract(double value) {
029        state -= value;
030        return this;
031    }
032
033    /**
034     *
035     * @param value to multiply the register by
036     * @return the original Calculator object
037     */
038    public Calculator multiply(double value) {
039        state = state * value;
040        return this;
041    }
042
043    /**
044     *
045     * @param value to divide the register by
046     * @return the original Calculator object
047     */
048    public Calculator divide(double value) {
049        state = state / value;
050        return this;
051    }
052
053    /**
054     *
055     * @return current value of the register
056     */
057    public double value() {
058        return state;
059    }
060
061    /**
062     *
063     * @param value to apply transwarp value
064     * @return the original Calculator object
065     */
066    public Calculator transwarp(double value) {
067
068        // TODO figure out the transwarp requirements.
069        throw new UnsupportedOperationException("No transwarp defined.");
070    }
071
072    /**
073     *
074     * Method intended to trip the PMD violations error. Hopefully you find this method as horrifying as I do even without PMD.
075     *
076     * @param foo random string
077     * @param bar random string
078     * @param spam untyped Object FTW
079     * @param eventListener some kind of events...?
080     * @param stringTokenizer because why not?
081     * @return some number
082     */
083    public int arbitrarilyComplexMethod(String foo, int bar, Object spam, EventListener eventListener, StringTokenizer stringTokenizer) {
084
085        try {
086            System.out.println(foo);
087        } catch (Exception e) {
088
089        }
090
091        try {
092            System.out.println(foo);
093        } catch (Exception e) {
094
095        }
096
097
098        if (foo == "bar")
099            return 0;
100
101        if (bar++ == -100)
102            return Long.BYTES;
103
104        return Integer.valueOf(foo + bar + spam.toString() + eventListener.toString() + stringTokenizer.toString());
105    }
106
107    /**
108     * Method intended to trip the CPM violations error
109     *
110     * @param foo random string
111     * @param bar random string
112     * @param spam untyped Object FTW
113     * @param eventListener some kind of events...?
114     * @param stringTokenizer because why not?
115     * @return some number
116     */
117    public int arbitrarilyComplexMethodPart2(String foo, int bar, Object spam, EventListener eventListener, StringTokenizer stringTokenizer) {
118        try {
119            System.out.println(foo);
120        } catch (Exception e) {
121
122        }
123
124        try {
125            System.out.println(foo);
126        } catch (Exception e) {
127
128        }
129
130        if (foo == "bar")
131            return 0;
132
133        if (bar++ == -100)
134            return Long.BYTES;
135
136        return Integer.valueOf(foo + bar + spam.toString() + eventListener.toString() + stringTokenizer.toString());
137    }
138
139}