| 1 | /** | 
| 2 |  * | 
| 3 |  * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> | 
| 4 |  * | 
| 5 |  * ==================================================================== | 
| 6 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
| 7 |  * you may not use this file except in compliance with the License. | 
| 8 |  * You may obtain a copy of the License at | 
| 9 |  * | 
| 10 |  * http://www.apache.org/licenses/LICENSE-2.0 | 
| 11 |  * | 
| 12 |  * Unless required by applicable law or agreed to in writing, software | 
| 13 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
| 14 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 15 |  * See the License for the specific language governing permissions and | 
| 16 |  * limitations under the License. | 
| 17 |  * ==================================================================== | 
| 18 |  */ | 
| 19 | package org.jclouds.compute.domain; | 
| 20 |   | 
| 21 | import com.google.common.collect.ComparisonChain; | 
| 22 |   | 
| 23 | /** | 
| 24 |  * Processor (or CPU) as a part of {@link Hardware} of a {@link NodeMetadata} | 
| 25 |  *  | 
| 26 |  * @author Adrian Cole | 
| 27 |  */ | 
| 28 | public class Processor implements Comparable<Processor> { | 
| 29 |    private final double cores; | 
| 30 |    private final double speed; | 
| 31 |   | 
| 32 |    public Processor(double cores, double speed) { | 
| 33 |       this.cores = cores; | 
| 34 |       this.speed = speed; | 
| 35 |    } | 
| 36 |   | 
| 37 |    /** | 
| 38 |     * {@inheritDoc} | 
| 39 |     */ | 
| 40 |    @Override | 
| 41 |    public int compareTo(Processor that) { | 
| 42 |       if (that instanceof Processor) { | 
| 43 |          Processor thatProcessor = Processor.class.cast(that); | 
| 44 |          return ComparisonChain.start().compare(this.getCores(), thatProcessor.getCores()) | 
| 45 |                .compare(this.getSpeed(), thatProcessor.getSpeed()).result(); | 
| 46 |       } else { | 
| 47 |          return -1; | 
| 48 |       } | 
| 49 |    } | 
| 50 |   | 
| 51 |    /** | 
| 52 |     * Amount of virtual or physical cores provided | 
| 53 |     */ | 
| 54 |    public double getCores() { | 
| 55 |       return cores; | 
| 56 |    } | 
| 57 |   | 
| 58 |    /** | 
| 59 |     * Speed, not necessarily in ghz, but certainly relevant to other processors | 
| 60 |     * in the same provider. | 
| 61 |     */ | 
| 62 |    public double getSpeed() { | 
| 63 |       return speed; | 
| 64 |    } | 
| 65 |   | 
| 66 |    @Override | 
| 67 |    public String toString() { | 
| 68 |       return "[cores=" + cores + ", speed=" + speed + "]"; | 
| 69 |    } | 
| 70 |   | 
| 71 |    @Override | 
| 72 |    public int hashCode() { | 
| 73 |       final int prime = 31; | 
| 74 |       int result = 1; | 
| 75 |       long temp; | 
| 76 |       temp = Double.doubleToLongBits(cores); | 
| 77 |       result = prime * result + (int) (temp ^ (temp >>> 32)); | 
| 78 |       temp = Double.doubleToLongBits(speed); | 
| 79 |       result = prime * result + (int) (temp ^ (temp >>> 32)); | 
| 80 |       return result; | 
| 81 |    } | 
| 82 |   | 
| 83 |    @Override | 
| 84 |    public boolean equals(Object obj) { | 
| 85 |       if (this == obj) | 
| 86 |          return true; | 
| 87 |       if (obj == null) | 
| 88 |          return false; | 
| 89 |       if (getClass() != obj.getClass()) | 
| 90 |          return false; | 
| 91 |       Processor other = (Processor) obj; | 
| 92 |       if (Double.doubleToLongBits(cores) != Double.doubleToLongBits(other.cores)) | 
| 93 |          return false; | 
| 94 |       if (Double.doubleToLongBits(speed) != Double.doubleToLongBits(other.speed)) | 
| 95 |          return false; | 
| 96 |       return true; | 
| 97 |    } | 
| 98 |   | 
| 99 | } |