1 package com
.android
.hotspot2
;
3 import java
.io
.IOException
;
5 public class IMSIParameter
{
6 private final String mImsi
;
7 private final boolean mPrefix
;
9 public IMSIParameter(String imsi
, boolean prefix
) {
14 public IMSIParameter(String imsi
) throws IOException
{
15 if (imsi
== null || imsi
.length() == 0) {
16 throw new IOException("Bad IMSI: '" + imsi
+ "'");
21 for (nonDigit
= 0; nonDigit
< imsi
.length(); nonDigit
++) {
22 stopChar
= imsi
.charAt(nonDigit
);
23 if (stopChar
< '0' || stopChar
> '9') {
28 if (nonDigit
== imsi
.length()) {
31 } else if (nonDigit
== imsi
.length() - 1 && stopChar
== '*') {
32 mImsi
= imsi
.substring(0, nonDigit
);
35 throw new IOException("Bad IMSI: '" + imsi
+ "'");
39 public boolean matches(String fullIMSI
) {
41 return mImsi
.regionMatches(false, 0, fullIMSI
, 0, mImsi
.length());
43 return mImsi
.equals(fullIMSI
);
47 public boolean matchesMccMnc(String mccMnc
) {
49 // For a prefix match, the entire prefix must match the mcc+mnc
50 return mImsi
.regionMatches(false, 0, mccMnc
, 0, mImsi
.length());
52 // For regular match, the entire length of mcc+mnc must match this IMSI
53 return mImsi
.regionMatches(false, 0, mccMnc
, 0, mccMnc
.length());
57 public boolean isPrefix() {
61 public String
getImsi() {
65 public int prefixLength() {
66 return mImsi
.length();
70 public boolean equals(Object thatObject
) {
71 if (this == thatObject
) {
73 } else if (thatObject
== null || getClass() != thatObject
.getClass()) {
77 IMSIParameter that
= (IMSIParameter
) thatObject
;
78 return mPrefix
== that
.mPrefix
&& mImsi
.equals(that
.mImsi
);
82 public int hashCode() {
83 int result
= mImsi
!= null ? mImsi
.hashCode() : 0;
84 result
= 31 * result
+ (mPrefix ?
1 : 0);
89 public String
toString() {