/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts

« back to all changes in this revision

Viewing changes to src/am/ed/importcontacts/ContactsCache.java

  • Committer: Tim Marston
  • Date: 2013-09-16 20:15:38 UTC
  • Revision ID: tim@ed.am-20130916201538-w2s54x86ml6kvjft
prevent NPE

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * ContactsCache.java
3
3
 *
4
 
 * Copyright (C) 2011 to 2012 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2011 to 2013 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Import Contacts program (hereafter referred
7
 
 * to as "this program"). For more information, see
 
7
 * to as "this program").  For more information, see
8
8
 * http://ed.am/dev/android/import-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
45
45
                 * Obtain a cache identifier.  This routine is designed to be as robust
46
46
                 * as possible (in terms of bad or null detail values), and to return
47
47
                 * null when a cache identifier can not be created.
 
48
                 *
48
49
                 * @param type the detail type
49
50
                 * @param detail the detail
50
51
                 * @return the cache identifier, or null
67
68
                 * Obtain a cache identifier from contact data.  This routine is
68
69
                 * designed to be as robust as possible and may return null when a cache
69
70
                 * identifier can not be created.
 
71
                 *
70
72
                 * @param contact the contact data
71
73
                 * @return the cache identifier, or null
72
74
                 */
135
137
                = new HashMap< Long, HashSet< String > >();
136
138
        private HashMap< Long, HashSet< String > > _contactNotes
137
139
                = new HashMap< Long, HashSet< String > >();
 
140
        private HashMap< Long, String > _contactBirthdays
 
141
                = new HashMap< Long, String >();
138
142
 
139
143
        public boolean canLookup( CacheIdentifier identifier )
140
144
        {
144
148
        /**
145
149
         * Retrieve the contact id of a contact identified by the specified cache
146
150
         * identifier, if it exists.
 
151
         *
147
152
         * @param identifier the cache identifier
148
153
         * @return a contact id, or null
149
154
         */
165
170
 
166
171
        /**
167
172
         * Remove any cache entry that is identified by the cache identifier.
 
173
         *
168
174
         * @param identifier the cache identifier
169
175
         * @return the contact id of the contact that was removed, or null
170
176
         */
186
192
 
187
193
        /**
188
194
         * Add a lookup from a contact identifier to a contact id to the cache.
 
195
         *
189
196
         * @param identifier the cache identifier
190
197
         * @param id teh contact id
191
198
         */
210
217
 
211
218
        /**
212
219
         * Remove any data that is associated with an contact id.
 
220
         *
213
221
         * @param id
214
222
         */
215
223
        public void removeAssociatedData( Long id )
331
339
                set.add( note );
332
340
        }
333
341
 
 
342
        public boolean hasAssociatedBirthday( Long id, String birthday )
 
343
        {
 
344
                birthday = normaliseBirthday( birthday );
 
345
                if( birthday == null ) return false;
 
346
 
 
347
                String found = _contactBirthdays.get( id );
 
348
                return found != null && found.equalsIgnoreCase( birthday );
 
349
        }
 
350
 
 
351
        public void addAssociatedBirthday( Long id, String birthday )
 
352
        {
 
353
                birthday = normaliseBirthday( birthday );
 
354
                if( birthday == null ) return;
 
355
 
 
356
                _contactBirthdays.put( id, birthday );
 
357
        }
 
358
 
334
359
        static public String normaliseName( String name )
335
360
        {
336
361
                if( name == null ) return null;
372
397
                note = note.trim();
373
398
                return note.length() > 0? note : null;
374
399
        }
 
400
 
 
401
        static public String normaliseBirthday( String birthday )
 
402
        {
 
403
                if( birthday == null ) return null;
 
404
                birthday = birthday.trim();
 
405
                return birthday.length() > 0? birthday : null;
 
406
        }
375
407
}