Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Once again, as previouslypreviously coveredcovered in your earlier question, using a String-based placeholder is not recommended, especially now that you have more values to cover. A typo from <remove after incl> to <remove atfer incl will potentially make debugging painfully hard at 3 am.

Just to elabroate slightly on @MattPutnam@MattPutnam's answer, you should consider making a Shortener instance per-mappingFile, instead of making the field public static. This makes the usage of each instance clearer, as they are tied to one mapping file. What can remain static is your importMap() method, though I think it should be taking in an argument to the file's location, and returning the desired Map.

Once again, as previously covered in your earlier question, using a String-based placeholder is not recommended, especially now that you have more values to cover. A typo from <remove after incl> to <remove atfer incl will potentially make debugging painfully hard at 3 am.

Just to elabroate slightly on @MattPutnam's answer, you should consider making a Shortener instance per-mappingFile, instead of making the field public static. This makes the usage of each instance clearer, as they are tied to one mapping file. What can remain static is your importMap() method, though I think it should be taking in an argument to the file's location, and returning the desired Map.

Once again, as previously covered in your earlier question, using a String-based placeholder is not recommended, especially now that you have more values to cover. A typo from <remove after incl> to <remove atfer incl will potentially make debugging painfully hard at 3 am.

Just to elabroate slightly on @MattPutnam's answer, you should consider making a Shortener instance per-mappingFile, instead of making the field public static. This makes the usage of each instance clearer, as they are tied to one mapping file. What can remain static is your importMap() method, though I think it should be taking in an argument to the file's location, and returning the desired Map.

deleted 2 characters in body
Source Link
h.j.k.
  • 19.4k
  • 3
  • 37
  • 93

Now that you have different Pattern expressions and handling to cater, you may want to consider putting them into classes that encapsulatesencapsulates these states and behaviors for each target/replacement pair.

Now that you have different Pattern expressions and handling to cater, you may want to consider putting them into classes that encapsulates these states and behaviors for each target/replacement pair.

Now that you have different Pattern expressions and handling to cater, you may want to consider putting them into classes that encapsulates these states and behaviors for each target/replacement pair.

added link to Pattern.quote().
Source Link
h.j.k.
  • 19.4k
  • 3
  • 37
  • 93

it'sIt's me again. :)

Your code is broken because you forgot to quote "."quote("."), which carries special meaning in regex. Without quoting:

private static final Set<Processor> MAPPER = getMapper(); private static Set<Processor> getMapper() { // PROCESSOR_COMPARATOR will compare Processor instances // in a similar way to how the 'keys' aka targets are sorted Set<Processor> mapper = new TreeSet<>TreeSet<Processor>(PROCESSOR_COMPARATOR); mapper.add(Processor.remove("THE")); mapper.add(Processor.replace("AUTOMATIC GAIN CONTROL", "AGC")); mapper.add(Processor.replace("CONTROL", "CTRL")); mapper.add(Processor.replace("IDENTIFIER", "ID")); mapper.add(Processor.removeBefore("TH")); mapper.add(Processor.removeAfterIncluding(".")); mapper.add(Processor.removeAfter(":")); return mapper; } 

it's me again. :)

Your code is broken because you forgot to quote ".", which carries special meaning in regex. Without quoting:

private static final Set<Processor> MAPPER = getMapper(); private static Set<Processor> getMapper() { // PROCESSOR_COMPARATOR will compare Processor instances // in a similar way to how the 'keys' aka targets are sorted Set<Processor> mapper = new TreeSet<>(PROCESSOR_COMPARATOR); mapper.add(Processor.remove("THE")); mapper.add(Processor.replace("AUTOMATIC GAIN CONTROL", "AGC")); mapper.add(Processor.replace("CONTROL", "CTRL")); mapper.add(Processor.replace("IDENTIFIER", "ID")); mapper.add(Processor.removeBefore("TH")); mapper.add(Processor.removeAfterIncluding(".")); mapper.add(Processor.removeAfter(":")); return mapper; } 

It's me again. :)

Your code is broken because you forgot to quote("."), which carries special meaning in regex. Without quoting:

private static final Set<Processor> MAPPER = getMapper(); private static Set<Processor> getMapper() { // PROCESSOR_COMPARATOR will compare Processor instances // in a similar way to how the 'keys' aka targets are sorted Set<Processor> mapper = new TreeSet<Processor>(PROCESSOR_COMPARATOR); mapper.add(Processor.remove("THE")); mapper.add(Processor.replace("AUTOMATIC GAIN CONTROL", "AGC")); mapper.add(Processor.replace("CONTROL", "CTRL")); mapper.add(Processor.replace("IDENTIFIER", "ID")); mapper.add(Processor.removeBefore("TH")); mapper.add(Processor.removeAfterIncluding(".")); mapper.add(Processor.removeAfter(":")); return mapper; } 
Source Link
h.j.k.
  • 19.4k
  • 3
  • 37
  • 93
Loading