d3scomp / JDEECo-old

JDEECo is a Java implementation of the DEECo domponent system
0 stars 0 forks source link

Holder classes for InOut and Out process parameters #6

Closed keznikl closed 12 years ago

keznikl commented 12 years ago

It is necessary to provide a holder class for InOut and Out process parameters. It is not necessary to provide a "blank" instance to be filled in the process body, because the associated class does not have to have a non-parameterized constructor (enforcing this would be too restrictive). Imagine a class for a response which requires a request object in its constructor.

I have developed a helper class for that in the parking lot booking scenario (at the end), it is necessary to introduce a support for it in the runtime.

package cz.cuni.mff.d3s.deeco.demo.parkinglotbooking;

import java.io.Serializable;

public class ProcessOutHolder<ItemType> implements Serializable {

    private static final long serialVersionUID = 3526860113119876016L;

    private ItemType item;

    public ProcessOutHolder(ItemType item) {
        this.item = item;
    }

    public ItemType get() {
        return item;
    }

    public void set(ItemType newItem) {
        item = newItem;
    }

    @Override
    public boolean equals(Object obj) {
         if ( this == obj ) 
             return true;
         if (obj == null)
            return false;
        if ( !(obj instanceof ProcessOutHolder<?>) ) 
            return false;
        ProcessOutHolder<?> other = (ProcessOutHolder<?>) obj;
        return item == null ? other.item == null : item.equals(other.item);
    }

    @Override
    public int hashCode() {
        return item == null ? 0 : item.hashCode();
    }
}
bures commented 12 years ago

Seems nice, only I would make the item field public. Maybe we can then discard the get/set methods.

mkit commented 12 years ago

Done in the last commit. The class name is cz.cuni.mff.d3s.deeco.knowledge.OutWrapper.