• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 com.android.deskclock.data;
18 
19 import android.text.TextUtils;
20 
21 /**
22  * A read-only domain object representing the timezones from which to choose a "home" timezone.
23  */
24 public final class TimeZones {
25 
26     private final CharSequence[] mTimeZoneIds;
27     private final CharSequence[] mTimeZoneNames;
28 
TimeZones(CharSequence[] timeZoneIds, CharSequence[] timeZoneNames)29     TimeZones(CharSequence[] timeZoneIds, CharSequence[] timeZoneNames) {
30         mTimeZoneIds = timeZoneIds;
31         mTimeZoneNames = timeZoneNames;
32     }
33 
getTimeZoneIds()34     public CharSequence[] getTimeZoneIds() {
35         return mTimeZoneIds;
36     }
37 
getTimeZoneNames()38     public CharSequence[] getTimeZoneNames() {
39         return mTimeZoneNames;
40     }
41 
42     /**
43      * @param timeZoneId identifies the timezone to locate
44      * @return the timezone name with the {@code timeZoneId}; {@code null} if it does not exist
45      */
getTimeZoneName(CharSequence timeZoneId)46     CharSequence getTimeZoneName(CharSequence timeZoneId) {
47         for (int i = 0; i < mTimeZoneIds.length; i++) {
48             if (TextUtils.equals(timeZoneId, mTimeZoneIds[i])) {
49                 return mTimeZoneNames[i];
50             }
51         }
52 
53         return null;
54     }
55 
56     /**
57      * @param timeZoneId identifies the timezone to locate
58      * @return {@code true} iff the timezone with the given id is present
59      */
contains(String timeZoneId)60     boolean contains(String timeZoneId) {
61         return getTimeZoneName(timeZoneId) != null;
62     }
63 }