/** * Returns the taxAmount for the passed in state or * null if no match is found. * * First checks the abbreviation (uppercase) followed by the name (uppercase). * * @param stateTaxRateMap, state * @return */ public Double lookupStateRate(Map<String,Double> stateTaxRateMap, State state) { if (stateTaxRateMap != null && state != null && state.getAbbreviation() != null) { String stateAbbr = state.getAbbreviation().toUpperCase(); Double rate = stateTaxRateMap.get(stateAbbr); if (rate == null && state.getName() != null) { String stateName = state.getName().toUpperCase(); return stateTaxRateMap.get(stateName); } else { return rate; } } return null; }
@Entity @Table(name = "Businesses") public class Business{ //define id and other fields @ManyToOne @JoinColumn(name = "state_code") private State state; public String getStateName(){ return state.getName(); } } @Entity @Table(name="StateCodes") public class State{ //define id and other fields. @Column(name = "state_name") private String stateName; public String getStateName(){ return stateName; } }
spinner1.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { State state = (State) spinner1.getSelectedItem(); String stateId = state.getId(); String stateName = state.getName(); //you are very assured that the id matches the name selected and you can proceed from there } });
final JSONObject jsonObject = ... // ... final Iterable<Void> voids = Iterables.transform(Arrays.asList(states), new Function<State, Void>() { @Override public Void apply(State currentState) { jsonObject.put(String.valueOf(currentState.getId()), currentState.getName()); return null; } }); for ( final Void v : voids ) { // do nothing }
public class MyCustomAdapter extends ArrayAdapter<States> { public ArrayList<States> stateList; public MyCustomAdapter(Context context, int textViewResourceId, ArrayList<States> stateList) { super(context, textViewResourceId, stateList); this.stateList = new ArrayList<States>(); this.stateList.addAll(stateList); this.getSelectedList(); } private void getSelectedList() { pref = context.getSharedPreferences("MYPref", Context.MODE_PRIVATE); String text = pref.getString("key",""); List<String> selectedList = Arrays.asList(text.split(",")); for (State state: this.stateList) { if (selectedList.contains(state.getName())) { state.setSelected(true); } } } ... }