Skip to content

Commit

Permalink
Create new class ParsingOptions
Browse files Browse the repository at this point in the history
There is a new class called PrasingOptions. With it we can replace old parsing methodes such as keepRawInput or defaultRegion.
  • Loading branch information
KarolJakubKrawiec committed Nov 28, 2024
1 parent 1eea8ec commit b557d11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ public class ParsingOptions {
public boolean hasDefaultRegion() { return hasDefaultRegion; }
public String getDefaultRegion() { return defaultRegion_; }
public ParsingOptions setDefaultRegion(String value) {
if (value == null) {
throw new NullPointerException();
}
hasDefaultRegion = true;
hasDefaultRegion = (value != null);
defaultRegion_ = value;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,10 @@ private boolean checkRegionForParsing(CharSequence numberToParse, String default
public PhoneNumber parse(CharSequence numberToParse, String defaultRegion)
throws NumberParseException {
PhoneNumber phoneNumber = new PhoneNumber();
parseWithOptions(
numberToParse,
new ParsingOptions().setDefaultRegion(defaultRegion),
phoneNumber);
parseWithOptions(
numberToParse,
new ParsingOptions().setDefaultRegion(defaultRegion),
Expand All @@ -3169,6 +3173,10 @@ public void parse(CharSequence numberToParse, String defaultRegion, PhoneNumber
numberToParse,
new ParsingOptions().setDefaultRegion(defaultRegion),
phoneNumber);
parseWithOptions(
numberToParse,
new ParsingOptions().setDefaultRegion(defaultRegion),
phoneNumber);
}

/**
Expand All @@ -3190,6 +3198,10 @@ public void parse(CharSequence numberToParse, String defaultRegion, PhoneNumber
public PhoneNumber parseAndKeepRawInput(CharSequence numberToParse, String defaultRegion)
throws NumberParseException {
PhoneNumber phoneNumber = new PhoneNumber();
parseWithOptions(
numberToParse,
new ParsingOptions().setKeepRawInput(true).setDefaultRegion(defaultRegion),
phoneNumber);
parseWithOptions(
numberToParse,
new ParsingOptions().setKeepRawInput(true).setDefaultRegion(defaultRegion),
Expand Down Expand Up @@ -3257,18 +3269,6 @@ public void parseWithOptions(CharSequence numberToParse, ParsingOptions options,
parseHelper(numberToParse, options.getDefaultRegion(), options.isKeepRawInput(), true, phoneNumber);
}

public PhoneNumber parseWithOptions(CharSequence numberToParse, ParsingOptions options)
throws NumberParseException {
PhoneNumber phoneNumber = new PhoneNumber();
parseHelper(numberToParse, options.getDefaultRegion(), options.hasKeepRawInput(), options.hasDefaultRegion(), phoneNumber);
return phoneNumber;
}

public void parseWithOptions(CharSequence numberToParse, ParsingOptions options, PhoneNumber phoneNumber)
throws NumberParseException {
parseHelper(numberToParse, options.getDefaultRegion(), options.hasKeepRawInput(), options.hasDefaultRegion(), phoneNumber);
}

/**
* Returns an iterable over all {@link PhoneNumberMatch PhoneNumberMatches} in {@code text}. This
* is a shortcut for {@link #findNumbers(CharSequence, String, Leniency, long)
Expand Down

0 comments on commit b557d11

Please sign in to comment.