Package com.betfair.platform.virtualheap

Source Code of com.betfair.platform.virtualheap.ScalarNode

/*
Copyright 2013, The Sporting Exchange Limited

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.betfair.platform.virtualheap;

import com.betfair.platform.virtualheap.updates.SetScalar;
import com.betfair.platform.virtualheap.projection.ScalarProjection;

public class ScalarNode<T> extends Node implements ScalarProjection<T> {

    T value;

    ScalarNode(int id, MutableHeap heap) {
        super(id, heap);
    }

    public void set(T newValue) {
        set(false, newValue);
    }

    void set(boolean fromListener, T newValue) {
        if (!fromListener) {
            beforeMutation();
        }
        if (value == null && newValue == null) {
            return;
        }
        if (value != null && newValue != null && value.equals(newValue)) {
            return;
        }

        value = newValue;
        heap.emit(new SetScalar(this.id, value));
    }

    public T get() {
        return value;
    }

    @Override
    public String prettyPrint(int depth, boolean collapse) {
        return toString();
    }

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

    public NodeType getType() {
        return NodeType.SCALAR;
    }

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

        ScalarNode that = (ScalarNode) o;

        if (value != null ? !value.equals(that.value) : that.value != null) {
            return false;
        }

        return true;
    }

}
TOP

Related Classes of com.betfair.platform.virtualheap.ScalarNode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.