Computer Science, asked by rinayashasvi1, 8 months ago

write a VDC for a program in java

the program could be any by your choice

if you gave the correct answer then I would mark you brainlist​

Answers

Answered by benerjeeariyan
2

Answer:

there you go

Explanation:

package com.emc.rest.smart.ecs;

import com.emc.rest.smart.Host;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

public class Vdc implements Iterable<VdcHost> {

private String name;

private List<VdcHost> hosts;

public Vdc(String... hostNames) {

this.name = hostNames[0];

hosts = new ArrayList<VdcHost>();

for (String hostName : hostNames) {

hosts.add(new VdcHost(this, hostName));

}

}

public Vdc(List<? extends Host> hosts) {

this(hosts.get(0).getName(), hosts);

}

public Vdc(String name, List<? extends Host> hosts) {

this.name = name;

this.hosts = createVdcHosts(hosts);

}

@Override

public Iterator<VdcHost> iterator() {

return hosts.iterator();

}

public boolean isHealthy() {

for (Host host : hosts) {

if (!host.isHealthy()) return false;

}

return true;

}

protected List<VdcHost> createVdcHosts(List<? extends Host> hosts) {

List<VdcHost> vdcHosts = new ArrayList<VdcHost>();

for (Host host : hosts) {

vdcHosts.add(new VdcHost(this, host.getName()));

}

return vdcHosts;

}

@Override

public boolean equals(Object o) {

if (this == o) return true;

if (!(o instanceof Vdc)) return false;

Vdc vdc = (Vdc) o;

return getName().equals(vdc.getName());

}

@Override

public int hashCode() {

return getName().hashCode();

}

@Override

public String toString() {

String hostsString = "";

if (hosts != null) {

for (Host host : hosts) {

if (hostsString.length() > 0) hostsString += ",";

hostsString += host.getName();

}

}

return name + '(' + hostsString + ')';

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public List<VdcHost> getHosts() {

return hosts;

}

public Vdc withName(String name) {

setName(name);

return this;

}

}

Similar questions