
org.btrplace.model.AbstractMapping Maven / Gradle / Ivy
/*
* Copyright (c) 2016 University Nice Sophia Antipolis
*
* This file is part of btrplace.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
package org.btrplace.model;
import java.util.Objects;
/**
* An helper abstract class for standards equals() and hashcode() methods
* as it is not possible to make them as default in Mapping.
*
* @author Fabien Hermenier
*/
public abstract class AbstractMapping implements Mapping {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Mapping)) {
return false;
}
Mapping that = (Mapping) o;
if (!getOnlineNodes().equals(that.getOnlineNodes())
|| !getOfflineNodes().equals(that.getOfflineNodes())
|| !getReadyVMs().equals(that.getReadyVMs())) {
return false;
}
for (Node n : getOnlineNodes()) {
if (!getRunningVMs(n).equals(that.getRunningVMs(n))
|| !getSleepingVMs(n).equals(that.getSleepingVMs(n))) {
return false;
}
}
return true;
}
@Override
public int hashCode() {
int result = Objects.hash(getOfflineNodes(), getReadyVMs(), getOnlineNodes());
for (Node n : getOnlineNodes()) {
result += Objects.hash(n, getRunningVMs(n), getSleepingVMs(n));
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy