-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Extended modifiers and added options for: CamelN Camel ShortTitleFormatter VeryShortTitleFormatter * Extended modifiers and added options for: CamelN Camel ShortTitleFormatter VeryShortTitleFormatter * Merge remote-tracking branch 'origin/main' # Conflicts: # src/main/java/org/jabref/logic/formatter/casechanger/CamelFormatter.java # src/main/java/org/jabref/logic/formatter/casechanger/CamelNFormatter.java # src/main/java/org/jabref/logic/formatter/casechanger/ShortTitleFormatter.java # src/main/java/org/jabref/logic/formatter/casechanger/VeryShortTitleFormatter.java * Small fix for get key and get name in camel formatters * Changed tests to have only one location inside BracketedPatternTest.java
- Loading branch information
Showing
7 changed files
with
279 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/org/jabref/logic/formatter/casechanger/CamelFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.jabref.logic.formatter.casechanger; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.logic.cleanup.Formatter; | ||
import org.jabref.logic.l10n.Localization; | ||
|
||
public class CamelFormatter extends Formatter { | ||
|
||
@Override | ||
public String getName() { | ||
return Localization.lang("Camel case"); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return "camel_case"; | ||
} | ||
|
||
@Override | ||
public String format(String input) { | ||
Title title = new Title(input); | ||
|
||
return title.getWords().stream() | ||
.map(Word -> { | ||
Word.toUpperFirst(); | ||
return Word.toString(); | ||
}) | ||
.collect(Collectors.joining("")); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Localization.lang( | ||
"Returns capitalized and concatenated title."); | ||
} | ||
|
||
@Override | ||
public String getExampleInput() { | ||
return "this is example input"; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/jabref/logic/formatter/casechanger/CamelNFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.jabref.logic.formatter.casechanger; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.logic.cleanup.Formatter; | ||
import org.jabref.logic.l10n.Localization; | ||
|
||
public class CamelNFormatter extends Formatter { | ||
private final int length; | ||
|
||
public CamelNFormatter(int length) { | ||
this.length = length; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return Localization.lang("Camel case - n letters max"); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return "camel_case_n"; | ||
} | ||
|
||
@Override | ||
public String format(String input) { | ||
Title title = new Title(input); | ||
|
||
return title.getWords().stream() | ||
.map(Word -> { | ||
Word.toUpperFirst(); | ||
return Word.toString(); | ||
}) | ||
.limit(length) | ||
.collect(Collectors.joining("")); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Localization.lang( | ||
"Returns capitalized and concatenated title to N length."); | ||
} | ||
|
||
@Override | ||
public String getExampleInput() { | ||
return "this is camel formatter"; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/jabref/logic/formatter/casechanger/ShortTitleFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.jabref.logic.formatter.casechanger; | ||
|
||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.logic.cleanup.Formatter; | ||
import org.jabref.logic.l10n.Localization; | ||
|
||
public class ShortTitleFormatter extends Formatter { | ||
|
||
@Override | ||
public String getName() { | ||
return Localization.lang("Short title"); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return "short_title"; | ||
} | ||
|
||
@Override | ||
public String format(String input) { | ||
Title title = new Title(input); | ||
|
||
return title.getWords().stream() | ||
.filter(Predicate.not( | ||
Word::isSmallerWord)) | ||
.map(Word::toString) | ||
.limit(3) | ||
.collect(Collectors.joining(" ")); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Localization.lang( | ||
"Returns first 3 words of the title ignoring any function words."); | ||
} | ||
|
||
@Override | ||
public String getExampleInput() { | ||
return "This is a short title"; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/jabref/logic/formatter/casechanger/VeryShortTitleFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.jabref.logic.formatter.casechanger; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
|
||
import org.jabref.logic.cleanup.Formatter; | ||
import org.jabref.logic.l10n.Localization; | ||
|
||
public class VeryShortTitleFormatter extends Formatter { | ||
|
||
@Override | ||
public String getName() { | ||
return Localization.lang("Very short title"); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return "very_short_title"; | ||
} | ||
|
||
@Override | ||
public String format(String input) { | ||
Title title = new Title(input); | ||
|
||
Optional<Word> resultTitle = title.getWords().stream() | ||
.filter(Predicate.not( | ||
Word::isSmallerWord)) | ||
.findFirst(); | ||
|
||
return resultTitle.map(Word::toString).orElse(""); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Localization.lang( | ||
"Returns first word of the title ignoring any function words."); | ||
} | ||
|
||
@Override | ||
public String getExampleInput() { | ||
return "A very short title"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters