/*
 * Copyright 2016 Hurence
 *
 * 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.hurence.logisland.event;

import java.io.Serializable;

/**
 * Encapulstaion of a field
 */
public class EventField implements Serializable{

    public EventField() {

    }

    // TODO match the scala/Java type here
    public EventField(String name, String type, Object value) {
        this.name = name;
        this.type = type.toLowerCase();
        this.value = value;
    }

    @Override
    public String toString() {
        return value.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EventField field = (EventField) o;

        if (!type.equals(field.type)) return false;
        if (!name.equals(field.name)) return false;
        return value.equals(field.value);

    }

    @Override
    public int hashCode() {
        int result = type.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + value.hashCode();
        return result;
    }

    private String name = "Field";
    private String type = "String";
    private Object value = null;


    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }
}

/*
 * Copyright 2016 Hurence
 *
 * 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.hurence.logisland.event;

import java.io.Serializable;

/**
 * Encapulstaion of a field
 */
public class EventField implements Serializable {

    public EventField() {

    }

    // TODO match the scala/Java type here
    public EventField(String name, String type, Object value) {
        this.name = name;
        this.type = type.toLowerCase();
        this.value = value;
    }

    @Override
    public String toString() {
        if (value != null)
            return value.toString();
        else
            return "null";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EventField field = (EventField) o;

        if (!type.equals(field.type)) return false;
        if (!name.equals(field.name)) return false;
        return value.equals(field.value);

    }

    @Override
    public int hashCode() {
        int result = type.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + value.hashCode();
        return result;
    }

    private String name = "Field";
    private String type = "String";
    private Object value = null;


    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }
}

fix Event toString nullpointer exception