Subversion Repository Public Repository

playgrnd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * LocationBean.java Jan 22, 2012
 * 
 * Copyright 2012 Uralian, LLC. All rights reserved.
 */
package com.uralian.sample;

import java.io.Serializable;
import java.util.*;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 * @author Vlad Orzhekhovskiy
 */
@ManagedBean
@SessionScoped
public class LocationBean implements Serializable
{
  private static final long serialVersionUID = 1L;

  private static SortedMap<String, SortedMap<String, Integer>> dataMap;
  static
  {
    SortedMap<String, Integer> gaCities = new TreeMap<String, Integer>();
    gaCities.put("Atlanta", 1234566);
    gaCities.put("Roswell", 23435);
    gaCities.put("Duluth", 45235);
    gaCities.put("Marietta", 3503);
    gaCities.put("", null);

    SortedMap<String, Integer> flCities = new TreeMap<String, Integer>();
    flCities.put("Miami", 9834234);
    flCities.put("Tampa", 34234);
    flCities.put("Naples", 23145);
    flCities.put("", null);

    SortedMap<String, Integer> alCities = new TreeMap<String, Integer>();
    alCities.put("Montgomery", 342354);
    alCities.put("Mobile", 125608);
    alCities.put("", null);

    dataMap = new TreeMap<String, SortedMap<String, Integer>>();
    dataMap.put("Georgia", gaCities);
    dataMap.put("Alabama", alCities);
    dataMap.put("Florida", flCities);
    dataMap.put("", null);
  }

  private String state = null;
  private String city = null;

  /**
   * @return the state.
   */
  public String getState()
  {
    return state;
  }

  /**
   * @param state the state to set.
   */
  public void setState(String state)
  {
    this.state = state;
    this.city = null;
  }

  /**
   * @return the city.
   */
  public String getCity()
  {
    return city;
  }

  /**
   * @param city the city to set.
   */
  public void setCity(String city)
  {
    this.city = city;
  }
  
  /**
   * @return the population.
   */
  public int getPopulation()
  {
    if (city == null || state.trim().equals(""))
      return 0;

    SortedMap<String, Integer> cityMap = dataMap.get(state);
    return cityMap.get(city);
  }

  public List<String> getStates()
  {
    return new ArrayList<String>(dataMap.keySet());
  }

  public List<String> getCities()
  {
    if (state == null || state.trim().equals(""))
      return Collections.emptyList();

    SortedMap<String, Integer> cityMap = dataMap.get(state);
    return new ArrayList<String>(cityMap.keySet());
  }
}

Commits for playgrnd/jsf-sample/src/main/java/com/uralian/sample/LocationBean.java

Diff revisions: vs.
Revision Author Commited Message
35 snark picture snark Thu 17 Aug, 2017 23:28:40 +0000

add jsf-sample project