/*
 * Copyright 2015 Wesley Ameling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.ameling.base;

public class BaseNumber {

	private final Base base;
	private final int value;
	private String representation;

	protected BaseNumber (final Base base, final int value, final String representation) {
		this.base = base;
		this.value = value;
		this.representation = representation;
	}

	public int value() {
		return value;
	}

	public Base getBase() {
		return base;
	}

	public BaseNumber subtract(final BaseNumber baseNumber) {
		return subtract(baseNumber, getBase());
	}

	public BaseNumber subtract(final BaseNumber baseNumber, final Base base) {
		return base.encode(value() - baseNumber.value());
	}

	public BaseNumber add(final BaseNumber baseNumber) {
		return add(baseNumber,  getBase());
	}

	public BaseNumber add(final BaseNumber baseNumber, final Base base) {
		return base.encode(value() + baseNumber.value());
	}

	public BaseNumber divide(final BaseNumber baseNumber) {
		return divide(baseNumber,  getBase());
	}

	public BaseNumber divide(final BaseNumber baseNumber, final Base base) {
		return base.encode(value() / baseNumber.value());
	}

	public BaseNumber multiply(final BaseNumber baseNumber) {
		return multiply(baseNumber,  getBase());
	}

	public BaseNumber multiply(final BaseNumber baseNumber, final Base base) {
		return base.encode(value() * baseNumber.value());
	}


	@Override
	public String toString () {
		return base.getPrefix() + representation;
	}

	@Override
	public int hashCode () {
		int result = 17;
		result = 53 * result + value;
		result += base.hashCode();
		return result;
	}

	@Override
	public boolean equals (final Object obj) {
		if (obj.getClass() == getClass()) {
			final BaseNumber baseNumber = (BaseNumber) obj;
			return baseNumber.base.base == base.base && baseNumber.value == value;
		}
		return false;
	}
}

@@ -623,119 +623,910 @@
 e;%0A%0A
-public class BaseNumber %7B%0A%0A%09private final Base base;%0A%09private final int value;%0A%09private String representation;%0A
+/**%0A * This class represents a value from the given %7B@link Base%7D. This class does not convert the number itself, it simply stores the %7B@link #base%7D, %7B@link #value%7D and the%0A * %7B@link #representation%7D of the number. It can also divide, multiply, add and subtract the number by calculating the values and then converting it with the given base %0A * or the base it is in.%0A */%0Apublic class BaseNumber %7B%0A%0A%09/**%0A%09 * The base this number represents%0A%09 */%0A%09private final Base base;%0A%09%0A%09/**%0A%09 * The value of this number%0A%09 */%0A%09private final int value;%0A%09%0A%09/**%0A%09 * The representation of the value without the prefix of the base.%0A%09 */%0A%09private String representation;%0A%0A%09/**%0A%09 * Creates a new number of the given variables.%0A%09 * @param base The %7B@link Base%7D this number represents%0A%09 * @param value The value of this number object%0A%09 * @param representation The representation of the value, converted by the %7B@link Base%7D%0A%09 */
 %0A%09pr
@@ -1701,48 +1701,153 @@
 %7D%0A%0A%09
-public int value() %7B%0A%09%09return value;%0A%09%7D%0A
+/**%0A%09 * Retrieves the value of this number%0A%09 */%0A%09public int value() %7B%0A%09%09return value;%0A%09%7D%0A%0A%09/**%0A%09 * Retrieves the %7B@link Base%7D of this number%0A%09 */
 %0A%09pu

Add documentation