1af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann/* 2af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * Copyright (C) 2010 The Android Open Source Project 3af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * 4af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License"); 5af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * you may not use this file except in compliance with the License. 6af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * You may obtain a copy of the License at 7af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * 8af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * http://www.apache.org/licenses/LICENSE-2.0 9af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * 10af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * Unless required by applicable law or agreed to in writing, software 11af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS, 12af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * See the License for the specific language governing permissions and 14af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * limitations under the License. 15af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann */ 16af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 17af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannpackage com.android.contacts.quickcontact; 18af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 19af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport java.util.ArrayList; 20af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannimport java.util.HashMap; 21af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann 22af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann/** 23af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * Provide a simple way of collecting one or more {@link Action} objects 24af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann * under a MIME-type key. 25af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann */ 26af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmannpublic class ActionMultiMap extends HashMap<String, ArrayList<Action>> { 27af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann public void put(String mimeType, Action info) { 288a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu put(mimeType, info, false); 298a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu } 308a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu 318a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu /** 328a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu * Puts the (mimeType,Action) tuple into the multimap at the front if 338a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu * the 'front' flag is set to true 348a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu */ 358a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu public void put(String mimeType, Action info, boolean front) { 368a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu // Put the info first 37af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann ArrayList<Action> collectList = get(mimeType); 388a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu 398a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu // Create list for this MIME-type if needed 40af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann if (collectList == null) { 41af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann collectList = new ArrayList<Action>(); 42af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann put(mimeType, collectList); 43af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 448a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu if (front) { 458a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu collectList.add(0, info); 468a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu } else { 478a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu collectList.add(info); 488a0dd0f08ab11e9c6dad386e4411aeeb4c0cd73fMaurice Chu } 49af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann } 50af8e3864a2d0131f72337165c846fe909a099e52Daniel Lehmann} 51