/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: edam
  • Date: 2012-12-20 16:55:00 UTC
  • Revision ID: tim@ed.am-20121220165500-y9p9klxqk5wqos2t
removed redundant CacheIdentifier constructor and NONE type

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * ContactsCache.java
3
3
 *
4
 
 * Copyright (C) 2011 to 2013 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2011 to 2012 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
 
                 *
49
48
                 * @param type the detail type
50
49
                 * @param detail the detail
51
50
                 * @return the cache identifier, or null
68
67
                 * Obtain a cache identifier from contact data.  This routine is
69
68
                 * designed to be as robust as possible and may return null when a cache
70
69
                 * identifier can not be created.
71
 
                 *
72
70
                 * @param contact the contact data
73
71
                 * @return the cache identifier, or null
74
72
                 */
75
73
                public static CacheIdentifier factory( Importer.ContactData contact )
76
74
                {
77
 
                        CacheIdentifier identifier = null;
 
75
                        CacheIdentifier ret = null;
78
76
 
79
77
                        if( contact.hasName() )
80
 
                                identifier = factory( CacheIdentifier.Type.NAME,
 
78
                                ret = factory( CacheIdentifier.Type.NAME,
81
79
                                        contact.getName() );
82
 
                        if( identifier != null ) return identifier;
83
 
 
84
 
                        if( contact.hasPrimaryOrganisation() )
85
 
                                identifier = factory( CacheIdentifier.Type.ORGANISATION,
 
80
                        if( ret == null && contact.hasPrimaryOrganisation() )
 
81
                                ret = factory( CacheIdentifier.Type.ORGANISATION,
86
82
                                        contact.getPrimaryOrganisation() );
87
 
                        if( identifier != null ) return identifier;
88
 
 
89
 
                        if( contact.hasPrimaryNumber() )
90
 
                                identifier = factory( CacheIdentifier.Type.PRIMARY_NUMBER,
 
83
                        if( ret == null && contact.hasPrimaryNumber() )
 
84
                                ret = factory( CacheIdentifier.Type.PRIMARY_NUMBER,
91
85
                                        contact.getPrimaryNumber() );
92
 
                        if( identifier != null ) return identifier;
93
 
 
94
 
                        if( contact.hasPrimaryEmail() )
95
 
                                identifier = factory( CacheIdentifier.Type.PRIMARY_EMAIL,
 
86
                        if( ret == null && contact.hasPrimaryEmail() )
 
87
                                ret = factory( CacheIdentifier.Type.PRIMARY_EMAIL,
96
88
                                        contact.getPrimaryEmail() );
97
 
                        if( identifier != null ) return identifier;
98
89
 
99
 
                        return null;
 
90
                        return ret;
100
91
                }
101
92
 
102
93
                protected CacheIdentifier( Type type, String detail )
137
128
                = new HashMap< Long, HashSet< String > >();
138
129
        private HashMap< Long, HashSet< String > > _contactNotes
139
130
                = new HashMap< Long, HashSet< String > >();
140
 
        private HashMap< Long, String > _contactBirthdays
141
 
                = new HashMap< Long, String >();
142
131
 
143
132
        public boolean canLookup( CacheIdentifier identifier )
144
133
        {
148
137
        /**
149
138
         * Retrieve the contact id of a contact identified by the specified cache
150
139
         * identifier, if it exists.
151
 
         *
152
140
         * @param identifier the cache identifier
153
141
         * @return a contact id, or null
154
142
         */
170
158
 
171
159
        /**
172
160
         * Remove any cache entry that is identified by the cache identifier.
173
 
         *
174
161
         * @param identifier the cache identifier
175
162
         * @return the contact id of the contact that was removed, or null
176
163
         */
192
179
 
193
180
        /**
194
181
         * Add a lookup from a contact identifier to a contact id to the cache.
195
 
         *
196
182
         * @param identifier the cache identifier
197
183
         * @param id teh contact id
198
184
         */
217
203
 
218
204
        /**
219
205
         * Remove any data that is associated with an contact id.
220
 
         *
221
206
         * @param id
222
207
         */
223
208
        public void removeAssociatedData( Long id )
339
324
                set.add( note );
340
325
        }
341
326
 
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
 
 
359
327
        static public String normaliseName( String name )
360
328
        {
361
329
                if( name == null ) return null;
397
365
                note = note.trim();
398
366
                return note.length() > 0? note : null;
399
367
        }
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
 
        }
407
368
}