1 /* 2 * Copyright 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 17 package foo.bar; 18 import androidx.room.*; 19 20 @Entity 21 public class Song { 22 @PrimaryKey 23 public final int mSongId; 24 public final String mTitle; 25 public final String mArtist; 26 public final String mAlbum; 27 public final int mLength; // in seconds 28 public final int mReleasedYear; 29 30 Song(int songId, String title, String artist, String album, int length, int releasedYear)31 public Song(int songId, String title, String artist, String album, int length, 32 int releasedYear) { 33 mSongId = songId; 34 mTitle = title; 35 mArtist = artist; 36 mAlbum = album; 37 mLength = length; 38 mReleasedYear = releasedYear; 39 } 40 41 @Override equals(Object o)42 public boolean equals(Object o) { 43 if (this == o) return true; 44 if (o == null || getClass() != o.getClass()) return false; 45 46 Song song = (Song) o; 47 48 if (mSongId != song.mSongId) return false; 49 if (mLength != song.mLength) return false; 50 if (mReleasedYear != song.mReleasedYear) return false; 51 if (mTitle != null ? !mTitle.equals(song.mTitle) : song.mTitle != null) return false; 52 if (mArtist != null ? !mArtist.equals(song.mArtist) : song.mArtist != null) return false; 53 return mAlbum != null ? mAlbum.equals(song.mAlbum) : song.mAlbum == null; 54 } 55 56 @Override hashCode()57 public int hashCode() { 58 int result = mSongId; 59 result = 31 * result + (mTitle != null ? mTitle.hashCode() : 0); 60 result = 31 * result + (mArtist != null ? mArtist.hashCode() : 0); 61 result = 31 * result + (mAlbum != null ? mAlbum.hashCode() : 0); 62 result = 31 * result + mLength; 63 result = 31 * result + mReleasedYear; 64 return result; 65 } 66 }