FeatureAssembly.java revision 7b5b77b038b846e8e2d3aaf0d94c206723a83ccf
1/* 2 * Copyright (C) 2012 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 17package android.bordeaux.services; 18 19import android.os.IBinder; 20import android.util.Log; 21import java.util.HashMap; 22import java.util.Map; 23import java.util.List; 24import java.util.Arrays; 25import java.util.HashSet; 26import java.util.Set; 27import java.util.Iterator; 28import android.bordeaux.services.AggregatorManager; 29import android.bordeaux.services.Aggregator; 30import java.io.Serializable; 31 32public class FeatureAssembly { 33 private static final String TAG = "FeatureAssembly"; 34 private List<String> mPossibleFeatures; 35 private HashSet<String> mUseFeatures; 36 private AggregatorManager mAggregatorManager; 37 38 public FeatureAssembly() { 39 mAggregatorManager = AggregatorManager.getInstance(); 40 mPossibleFeatures = Arrays.asList(mAggregatorManager.getListOfFeatures()); 41 mUseFeatures = new HashSet<String>(); 42 } 43 44 public boolean registerFeature(String s) { 45 boolean res = mPossibleFeatures.contains(s); 46 if (res){ 47 if (!mUseFeatures.contains(s)) 48 mUseFeatures.add(s); 49 } 50 return res; 51 } 52 53 public Set<String> getUsedFeatures() { 54 return (Set) mUseFeatures; 55 } 56 57 public String augmentFeatureInputString(String s) { 58 String fs = s; 59 Iterator itr = mUseFeatures.iterator(); 60 while(itr.hasNext()) { 61 String f = (String) itr.next(); 62 fs = fs + "+" + mAggregatorManager.getDataMap(f).get(f); 63 } 64 return fs; 65 } 66} 67