4
4
* Copyright (C) 2011 to 2012 Tim Marston <tim@ed.am>
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
10
10
* This program is free software: you can redistribute it and/or modify
37
37
public static class CacheIdentifier
40
NONE, NAME, ORGANISATION, PRIMARY_NUMBER, PRIMARY_EMAIL }
39
public enum Type { NAME, ORGANISATION, PRIMARY_NUMBER, PRIMARY_EMAIL }
42
41
private Type _type;
43
42
private String _detail;
45
protected CacheIdentifier()
51
45
* Obtain a cache identifier. This routine is designed to be as robust
52
46
* as possible (in terms of bad or null detail values), and to return
53
47
* null when a cache identifier can not be created.
54
49
* @param type the detail type
55
50
* @param detail the detail
56
51
* @return the cache identifier, or null
73
68
* Obtain a cache identifier from contact data. This routine is
74
69
* designed to be as robust as possible and may return null when a cache
75
70
* identifier can not be created.
76
72
* @param contact the contact data
77
73
* @return the cache identifier, or null
79
75
public static CacheIdentifier factory( Importer.ContactData contact )
81
CacheIdentifier ret = null;
77
CacheIdentifier identifier = null;
83
79
if( contact.hasName() )
84
ret = factory( CacheIdentifier.Type.NAME,
80
identifier = factory( CacheIdentifier.Type.NAME,
85
81
contact.getName() );
86
if( ret == null && contact.hasPrimaryOrganisation() )
87
ret = factory( CacheIdentifier.Type.ORGANISATION,
82
if( identifier != null ) return identifier;
84
if( contact.hasPrimaryOrganisation() )
85
identifier = factory( CacheIdentifier.Type.ORGANISATION,
88
86
contact.getPrimaryOrganisation() );
89
if( ret == null && contact.hasPrimaryNumber() )
90
ret = factory( CacheIdentifier.Type.PRIMARY_NUMBER,
87
if( identifier != null ) return identifier;
89
if( contact.hasPrimaryNumber() )
90
identifier = factory( CacheIdentifier.Type.PRIMARY_NUMBER,
91
91
contact.getPrimaryNumber() );
92
if( ret == null && contact.hasPrimaryEmail() )
93
ret = factory( CacheIdentifier.Type.PRIMARY_EMAIL,
92
if( identifier != null ) return identifier;
94
if( contact.hasPrimaryEmail() )
95
identifier = factory( CacheIdentifier.Type.PRIMARY_EMAIL,
94
96
contact.getPrimaryEmail() );
97
if( identifier != null ) return identifier;
99
102
protected CacheIdentifier( Type type, String detail )
144
147
* Retrieve the contact id of a contact identified by the specified cache
145
148
* identifier, if it exists.
146
150
* @param identifier the cache identifier
147
151
* @return a contact id, or null