Created
December 15, 2015 23:42
-
-
Save romartin/d84cb8136db9b0f38ae5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright 2015 JBoss, by Red Hat, Inc | |
| * | |
| * 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.uberfire.ext.wirez.core.api.impl.property; | |
| import org.uberfire.commons.validation.PortablePreconditions; | |
| import org.uberfire.ext.wirez.core.api.model.property.Property; | |
| import org.uberfire.ext.wirez.core.api.model.property.PropertyType; | |
| public abstract class BaseProperty<C> implements Property<C> { | |
| protected String id; | |
| protected String caption; | |
| protected String description; | |
| protected boolean isReadOnly; | |
| protected boolean isOptional; | |
| protected C defaultValue; | |
| public BaseProperty(final String id, | |
| final String caption, | |
| final String description, | |
| final boolean isReadOnly, | |
| final boolean isOptional, | |
| final C defaultValue) { | |
| this.id = PortablePreconditions.checkNotNull( "id", | |
| id ); | |
| this.caption = PortablePreconditions.checkNotNull( "caption", | |
| caption ); | |
| this.description = PortablePreconditions.checkNotNull( "description", | |
| description ); | |
| this.isReadOnly = isReadOnly; | |
| this.isOptional = isOptional; | |
| this.defaultValue = PortablePreconditions.checkNotNull( "defaultValue", | |
| defaultValue ); | |
| } | |
| @Override | |
| public String getId() { | |
| return id; | |
| } | |
| @Override | |
| public String getCaption() { | |
| return caption; | |
| } | |
| @Override | |
| public String getDescription() { | |
| return description; | |
| } | |
| @Override | |
| public boolean isReadOnly() { | |
| return isReadOnly; | |
| } | |
| @Override | |
| public boolean isOptional() { | |
| return isOptional; | |
| } | |
| @Override | |
| public C getDefaultValue() { | |
| return defaultValue; | |
| } | |
| public BaseProperty<C> setCaption(String caption) { | |
| this.caption = caption; | |
| return this; | |
| } | |
| public BaseProperty<C> setDescription(String description) { | |
| this.description = description; | |
| return this; | |
| } | |
| public BaseProperty<C> setReadOnly(boolean readOnly) { | |
| isReadOnly = readOnly; | |
| return this; | |
| } | |
| public BaseProperty<C> setOptional(boolean optional) { | |
| isOptional = optional; | |
| return this; | |
| } | |
| public BaseProperty<C> setDefaultValue(C defaultValue) { | |
| this.defaultValue = defaultValue; | |
| return this; | |
| } | |
| @Override | |
| public boolean equals( Object o ) { | |
| if ( this == o ) { | |
| return true; | |
| } | |
| if ( !( o instanceof BaseProperty) ) { | |
| return false; | |
| } | |
| BaseProperty that = (BaseProperty) o; | |
| if ( isOptional != that.isOptional ) { | |
| return false; | |
| } | |
| if ( isReadOnly != that.isReadOnly ) { | |
| return false; | |
| } | |
| if ( !caption.equals( that.caption ) ) { | |
| return false; | |
| } | |
| if ( !description.equals( that.description ) ) { | |
| return false; | |
| } | |
| if ( !id.equals( that.id ) ) { | |
| return false; | |
| } | |
| if ( !getType().equals( that.getType() ) ) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| @Override | |
| public int hashCode() { | |
| int result = id.hashCode(); | |
| result = ~~result; | |
| result = 31 * result + getType().hashCode(); | |
| result = ~~result; | |
| result = 31 * result + caption.hashCode(); | |
| result = ~~result; | |
| result = 31 * result + description.hashCode(); | |
| result = ~~result; | |
| result = 31 * result + ( isReadOnly ? 1 : 0 ); | |
| result = ~~result; | |
| result = 31 * result + ( isOptional ? 1 : 0 ); | |
| result = ~~result; | |
| return result; | |
| } | |
| @Override | |
| public String toString() { | |
| return "DefaultPropertyImpl{" + | |
| "id='" + id + '\'' + | |
| ", type=" + getType() + | |
| ", caption='" + caption + '\'' + | |
| ", description='" + description + '\'' + | |
| ", isReadOnly=" + isReadOnly + | |
| ", isOptional=" + isOptional + | |
| '}'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment