All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jclouds.compute.domain.internal.HardwareImpl Maven / Gradle / Ivy

/**
 * Licensed to jclouds, Inc. (jclouds) under one or more
 * contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  jclouds licenses this file
 * to you 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 org.jclouds.compute.domain.internal;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed;
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;

import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.domain.Location;
import org.jclouds.domain.ResourceMetadata;
import org.jclouds.javax.annotation.Nullable;

import com.google.common.base.Predicate;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableList;

/**
 * @author Adrian Cole
 */
public class HardwareImpl extends ComputeMetadataImpl implements Hardware {

   /** The serialVersionUID */
   private static final long serialVersionUID = 8994255275911717567L;
   private final List processors;
   private final int ram;
   private final List volumes;
   private final Predicate supportsImage;
   private final String hypervisor;

   public HardwareImpl(String providerId, String name, String id, @Nullable Location location, URI uri,
         Map userMetadata, Set tags, Iterable processors, int ram,
         Iterable volumes, Predicate supportsImage, @Nullable String hypervisor) {
      super(ComputeType.HARDWARE, providerId, name, id, location, uri, userMetadata, tags);
      this.processors = ImmutableList.copyOf(checkNotNull(processors, "processors"));
      this.ram = ram;
      this.volumes = ImmutableList.copyOf(checkNotNull(volumes, "volumes"));
      this.supportsImage = supportsImage;
      this.hypervisor = hypervisor;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public List getProcessors() {
      return processors;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public int getRam() {
      return ram;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public List getVolumes() {
      return volumes;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   @Nullable
   public String getHypervisor() {
      return hypervisor;
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public int compareTo(ResourceMetadata that) {
      if (that instanceof Hardware) {
         Hardware thatHardware = Hardware.class.cast(that);
         return ComparisonChain.start().compare(getCoresAndSpeed(this), getCoresAndSpeed(thatHardware)).compare(
                  this.getRam(), thatHardware.getRam()).compare(getSpace(this), getSpace(thatHardware)).compare(
                  getHypervisor(), thatHardware.getHypervisor()).result();
      } else {
         return super.compareTo(that);
      }
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public String toString() {
      return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() + ", processors="
               + processors + ", ram=" + ram + ", volumes=" + volumes + ", hypervisor=" + hypervisor
               + ", supportsImage=" + supportsImage + ", tags=" + tags + "]";
   }

   /**
    * {@inheritDoc}
    */
   @Override
   public Predicate supportsImage() {
      return supportsImage;
   }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy