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

org.mattressframework.test.model.SimpleModel Maven / Gradle / Ivy

/*
 * Copyright 2007-2008, Josh Devins.
 *
 * 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 org.mattressframework.test.model;

import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * A basic, mock model to be used for various testing purposes.
 * 
 * @author Josh Devins ([email protected])
 */
@XmlRootElement
public class SimpleModel {

    public static final String FIELD1_NAME = "field1";

    public static final String TEST_FIELD1_1 = "TEST_FIELD1_1";

    public static final int TEST_FIELD2_1 = 1;

    public static final String FIELD2_NAME = "field2";

    public static final String TEST_FIELD1_2 = "TEST_FIELD2_1";

    public static final int TEST_FIELD2_2 = 2;

    public static final SimpleModel TEST_INSTANCE1 =
            new SimpleModel(TEST_FIELD1_1, TEST_FIELD2_1);

    public static final SimpleModel TEST_INSTANCE2 =
            new SimpleModel(TEST_FIELD1_2, TEST_FIELD2_2);

    public static final SimpleModel[] TEST_INSTANCE_ARRAY =
            { TEST_INSTANCE1, TEST_INSTANCE2 };

    private String field1;

    private int field2;

    public SimpleModel() {
        this.field1 = null;
        this.field2 = -1;
    }

    public SimpleModel(final String field1, final int field2) {
        this.field1 = field1;
        this.field2 = field2;
    }

    @Override
    public boolean equals(final Object object) {

        if (object == this) {
            return true;
        }

        if (!(object instanceof SimpleModel)) {
            return false;
        }

        SimpleModel rhs = (SimpleModel) object;
        return field1.equals(rhs.field1) && field2 == rhs.field2;
    }

    public String getField1() {
        return field1;
    }

    public int getField2() {
        return field2;
    }

    public void setField1(final String field1) {
        this.field1 = field1;
    }

    public void setField2(final int field2) {
        this.field2 = field2;
    }

    @Override
    public String toString() {
        ToStringBuilder tsb =
                new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
        tsb.append("field1", field1);
        tsb.append("field2", field2);

        return tsb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy