• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.tradefed.device;
17 
18 /**
19  * Representation of device foldable state as returned by "cmd device_state print-states".
20  */
21 public class DeviceFoldableState implements Comparable<DeviceFoldableState> {
22 
23     private final long mIdentifier;
24     private final String mName;
25 
DeviceFoldableState(long identifier, String name)26     public DeviceFoldableState(long identifier, String name) {
27         mIdentifier = identifier;
28         mName = name;
29     }
30 
getIdentifier()31     public long getIdentifier() {
32         return mIdentifier;
33     }
34 
35     @Override
toString()36     public String toString() {
37         return "foldable:" + mIdentifier + ":" + mName;
38     }
39 
40     @Override
hashCode()41     public int hashCode() {
42         final int prime = 31;
43         int result = 1;
44         result = prime * result + (int) (mIdentifier ^ (mIdentifier >>> 32));
45         result = prime * result + ((mName == null) ? 0 : mName.hashCode());
46         return result;
47     }
48 
49     @Override
equals(Object obj)50     public boolean equals(Object obj) {
51         if (this == obj) {
52             return true;
53         }
54         if (obj == null) {
55             return false;
56         }
57         if (getClass() != obj.getClass()) {
58             return false;
59         }
60         DeviceFoldableState other = (DeviceFoldableState) obj;
61         if (mIdentifier != other.mIdentifier) {
62             return false;
63         }
64         if (mName == null) {
65             if (other.mName != null) {
66                 return false;
67             }
68         } else if (!mName.equals(other.mName)) {
69             return false;
70         }
71         return true;
72     }
73 
74     @Override
compareTo(DeviceFoldableState o)75     public int compareTo(DeviceFoldableState o) {
76         if (this.mIdentifier == o.mIdentifier) {
77             return 0;
78         } else if (this.mIdentifier > o.mIdentifier) {
79             return 1;
80         }
81         return -1;
82     }
83 }
84