Skip to content

Commit

Permalink
Merge pull request #1082 from jlerbsc/master
Browse files Browse the repository at this point in the history
fix: issue #1081 Sonar S1132 Strings literals should be placed on the left side when checking for equality
  • Loading branch information
josemduarte committed Mar 4, 2024
2 parents 1b5fa3c + ac75f31 commit a9542ca
Show file tree
Hide file tree
Showing 93 changed files with 462 additions and 462 deletions.
Expand Up @@ -116,8 +116,8 @@ public static void run(String[] args) throws Exception{
case 'o': outputLocation = args[++i]; break;
case 'f':
i++;
if(args[i].equalsIgnoreCase("csv")) delimiter = ",";
else if(args[i].equalsIgnoreCase("tsv")) delimiter = "\t";
if("csv".equalsIgnoreCase(args[i])) delimiter = ",";
else if("tsv".equalsIgnoreCase(args[i])) delimiter = "\t";
else throw new Error("Invalid value for -f: " + args[i] + ". Please choose either csv or tsv only.");
break;
case 'x': aminoAcidCompositionLocation = args[++i]; break;
Expand Down
Expand Up @@ -471,7 +471,7 @@ StockholmStructure parse(Scanner scanner) throws IOException {
this.stockholmStructure = new StockholmStructure();
this.stockholmStructure.getFileAnnotation().setFormat(header[1]);
this.stockholmStructure.getFileAnnotation().setVersion(header[2]);
} else if (line.trim().equals("//")) {
} else if ("//".equals(line.trim())) {
// status = STATUS_OUTSIDE_FILE;
break;// should we just break immediately or jump next empty lines?
} else /* if (!line.startsWith("#")) */{
Expand Down
Expand Up @@ -256,8 +256,8 @@ else if (forcedSequenceType.equals(PFAM))
}
String[] seqDetails = splitSeqName(sequencename);
seq.setDescription(seqDetails[0]);
seq.setBioBegin((seqDetails[1] == null || seqDetails[1].trim().equals("") ? null : Integer.valueOf(seqDetails[1])));
seq.setBioEnd((seqDetails[2] == null || seqDetails[2].trim().equals("") ? null : Integer.valueOf(seqDetails[2])));
seq.setBioBegin((seqDetails[1] == null || "".equals(seqDetails[1].trim()) ? null : Integer.valueOf(seqDetails[1])));
seq.setBioEnd((seqDetails[2] == null || "".equals(seqDetails[2].trim()) ? null : Integer.valueOf(seqDetails[2])));

seqs.add(seq);
}
Expand Down
Expand Up @@ -107,7 +107,7 @@ private void processScores(String line) {
}

// special case: MEHP950101
if (values[i].equals("-")) {
if ("-".equals(values[i])) {
values[i] = "0";
}
if ( scale == -1 ) {
Expand Down
Expand Up @@ -191,13 +191,13 @@ public AbstractSequence<NucleotideCompound> getSequence() throws CompoundNotFoun
* @throws CompoundNotFoundException if the base is not valid
*/
public int[] getTrace (String base) throws CompoundNotFoundException {
if (base.equals("A")) {
if ("A".equals(base)) {
return A;
} else if (base.equals("C")) {
} else if ("C".equals(base)) {
return C;
} else if (base.equals("G")) {
} else if ("G".equals(base)) {
return G;
} else if (base.equals("T")) {
} else if ("T".equals(base)) {
return T;
} else {
throw new CompoundNotFoundException("Don't know base: " + base);
Expand Down Expand Up @@ -492,9 +492,9 @@ private void setIndex() {
for (int record = 0; record <= NumRecords - 1; record++) {
getSubArray(RecNameArray, (indexBase + (record * 28)));
RecName = new String(RecNameArray);
if (RecName.equals("FWO_"))
if ("FWO_".equals(RecName))
FWO = indexBase + (record * 28) + 20;
if (RecName.equals("DATA")) {
if ("DATA".equals(RecName)) {
++DataCounter;
if (DataCounter == 9)
DATA9 = indexBase + (record * 28) + 20;
Expand All @@ -505,17 +505,17 @@ private void setIndex() {
if (DataCounter == 12)
DATA12 = indexBase + (record * 28) + 20;
}
if (RecName.equals("PBAS")) {
if ("PBAS".equals(RecName)) {
++PBASCounter;
if (PBASCounter == 2)
PBAS2 = indexBase + (record * 28) + 20;
}
if (RecName.equals("PLOC")) {
if ("PLOC".equals(RecName)) {
++PLOCCounter;
if (PLOCCounter == 2)
PLOC = indexBase + (record * 28) + 20;
}
if (RecName.equals("PCON")) {
if ("PCON".equals(RecName)) {
++PCONCounter;
if (PCONCounter == 2)
PCON = indexBase + (record * 28) + 20;
Expand Down
Expand Up @@ -145,7 +145,7 @@ private String parse(BufferedReader bufferedReader) {
sectionKey = section.get(0)[0];
if (sectionKey == null) {
//if we reach the end of the file, section contains empty strings
if(section.get(0)[1]==null || section.get(0)[1].equals("") ||
if(section.get(0)[1]==null || "".equals(section.get(0)[1]) ||
section.get(0)[1].length()==0) {
throw new ParserException(Messages.ENDOFFILE);
}
Expand Down Expand Up @@ -208,7 +208,7 @@ private void parseFeatureTag(List<String[]> section) {
needsQuotes = true; // as the value has quotes then set that it needs quotes when written back out
}
// parameter on old feature
if (key.equals("db_xref")) {
if ("db_xref".equals(key)) {
Matcher m = dbxp.matcher(val);
if (m.matches()) {
String dbname = m.group(1);
Expand All @@ -223,12 +223,12 @@ private void parseFeatureTag(List<String[]> section) {
} else {
throw new ParserException("Bad dbxref");
}
} else if (key.equalsIgnoreCase("organism")) {
} else if ("organism".equalsIgnoreCase(key)) {
Qualifier q = new Qualifier(key, val.replace('\n', ' '), needsQuotes);
gbFeature.addQualifier(key, q);
} else {
if (key.equalsIgnoreCase("translation") || key.equals("anticodon")
|| key.equals("transl_except")) {
if ("translation".equalsIgnoreCase(key) || "anticodon".equals(key)
|| "transl_except".equals(key)) {
// strip spaces from sequence
val = val.replaceAll("\\s+", "");
Qualifier q = new Qualifier(key, val, needsQuotes);
Expand Down Expand Up @@ -319,9 +319,9 @@ private void parseLocusTag(List<String[]> section) {
String lengthUnits = m.group(3);
String type = m.group(6);

if (lengthUnits.equalsIgnoreCase("aa")) {
if ("aa".equalsIgnoreCase(lengthUnits)) {
compoundType = AminoAcidCompoundSet.getAminoAcidCompoundSet();
} else if (lengthUnits.equalsIgnoreCase("bp")) {
} else if ("bp".equalsIgnoreCase(lengthUnits)) {
if (type != null) {
if (type.contains("RNA")) {
compoundType = RNACompoundSet.getRNACompoundSet();
Expand All @@ -333,7 +333,7 @@ private void parseLocusTag(List<String[]> section) {
}
}

if (m.group(7) != null) isCircularSequence = m.group(7).equalsIgnoreCase("circular");
if (m.group(7) != null) isCircularSequence = "circular".equalsIgnoreCase(m.group(7));

// configure location parser with needed information
locationParser.setSequenceLength(sequenceLength);
Expand All @@ -349,9 +349,9 @@ private void parseLocusTag(List<String[]> section) {
String lengthUnits = m2.group(2);
String type = m2.group(5);

if (lengthUnits.equalsIgnoreCase("aa")) {
if ("aa".equalsIgnoreCase(lengthUnits)) {
compoundType = AminoAcidCompoundSet.getAminoAcidCompoundSet();
} else if (lengthUnits.equalsIgnoreCase("bp")) {
} else if ("bp".equalsIgnoreCase(lengthUnits)) {
if (type != null) {
if (type.contains("RNA")) {
compoundType = RNACompoundSet.getRNACompoundSet();
Expand All @@ -363,7 +363,7 @@ private void parseLocusTag(List<String[]> section) {
}
}

if (m2.group(6) != null) isCircularSequence = m2.group(6).equalsIgnoreCase("circular");
if (m2.group(6) != null) isCircularSequence = "circular".equalsIgnoreCase(m2.group(6));

// configure location parser with needed information
locationParser.setSequenceLength(sequenceLength);
Expand Down
Expand Up @@ -116,8 +116,8 @@ public void parseHeader(String header, S sequence) {

if (data.length == 1) {
sequence.setAccession(new AccessionID(data[0]));
} else if (data[0].equalsIgnoreCase("sp") || data[0].equalsIgnoreCase("tr")) {
if (data[0].equalsIgnoreCase("sp")) {
} else if ("sp".equalsIgnoreCase(data[0]) || "tr".equalsIgnoreCase(data[0])) {
if ("sp".equalsIgnoreCase(data[0])) {
sequence.setAnnotationType(AnnotationType.CURATED);
} else {
sequence.setAnnotationType(AnnotationType.PREDICTED);
Expand All @@ -128,41 +128,41 @@ public void parseHeader(String header, S sequence) {
sequence.setDescription(data[2]);
}

} else if (data[0].equalsIgnoreCase("gi")) {
} else if ("gi".equalsIgnoreCase(data[0])) {
DataSource giSource = DataSource.UNKNOWN;
if (data.length >= 3) {
if (data[2].equalsIgnoreCase("gb")) {
if ("gb".equalsIgnoreCase(data[2])) {
giSource = DataSource.GENBANK;
} else if (data[2].equalsIgnoreCase("emb")) {
} else if ("emb".equalsIgnoreCase(data[2])) {
giSource = DataSource.ENA;
} else if (data[2].equalsIgnoreCase("dbj")) {
} else if ("dbj".equalsIgnoreCase(data[2])) {
giSource = DataSource.DDBJ;
}
sequence.setAccession(new AccessionID(data[3], giSource));
} else {
sequence.setAccession(new AccessionID(header, giSource));
}
} else if (data[0].equalsIgnoreCase("pir")) {
} else if ("pir".equalsIgnoreCase(data[0])) {
sequence.setAccession(new AccessionID(data[2], DataSource.NBRF));
} else if (data[0].equalsIgnoreCase("prf")) {
} else if ("prf".equalsIgnoreCase(data[0])) {
sequence.setAccession(new AccessionID(data[2], DataSource.PRF));
} else if (data[0].equalsIgnoreCase("pdb")) {
} else if ("pdb".equalsIgnoreCase(data[0])) {
sequence.setAccession(new AccessionID(data[1] + ":" + data[2], DataSource.PDB1));
} else if (data[0].startsWith("PDB")) {
String[] pdbe = data[0].split(" ");
String[] pdbaccession = pdbe[0].split(":");
sequence.setAccession(new AccessionID(pdbaccession[1], DataSource.PDBe));
} else if (data[0].indexOf(":") != -1 && data.length > 1 && data[1].equals("PDBID")) {
} else if (data[0].indexOf(":") != -1 && data.length > 1 && "PDBID".equals(data[1])) {
sequence.setAccession(new AccessionID(data[0], DataSource.PDB2));
} else if (data[0].equalsIgnoreCase("pat")) {
} else if ("pat".equalsIgnoreCase(data[0])) {
sequence.setAccession(new AccessionID(data[2], DataSource.PATENTS));
} else if (data[0].equalsIgnoreCase("bbs")) {
} else if ("bbs".equalsIgnoreCase(data[0])) {
sequence.setAccession(new AccessionID(data[1], DataSource.GENINFO));
} else if (data[0].equalsIgnoreCase("gnl")) {
} else if ("gnl".equalsIgnoreCase(data[0])) {
sequence.setAccession(new AccessionID(data[2], DataSource.GENERAL));
} else if (data[0].equalsIgnoreCase("ref")) {
} else if ("ref".equalsIgnoreCase(data[0])) {
sequence.setAccession(new AccessionID(data[1], DataSource.NCBI));
} else if (data[0].equalsIgnoreCase("lcl")) {
} else if ("lcl".equalsIgnoreCase(data[0])) {
sequence.setAccession(new AccessionID(data[1], DataSource.LOCAL));
} else {
sequence.setAccession(new AccessionID(data[0])); // avoid the common problem of picking up all the comments original header in getOriginalHeader
Expand Down
Expand Up @@ -150,27 +150,27 @@ private List<IUPACTable> parseTables() {
String name, aa, starts, baseone, basetwo, basethree;
name = aa = starts = baseone = basetwo = basethree = null;
for (String line : lines) {
if (line.equalsIgnoreCase("//")) {
if ("//".equalsIgnoreCase(line)) {
localTables.add(new IUPACTable(name, id, aa, starts, baseone, basetwo,
basethree));
name = aa = starts = baseone = basetwo = basethree = null;
id = null;
}
else {
String[] keyValue = line.split("\\s*=\\s*");
if (keyValue[0].equals("AAs")) {
if ("AAs".equals(keyValue[0])) {
aa = keyValue[1];
}
else if (keyValue[0].equals("Starts")) {
else if ("Starts".equals(keyValue[0])) {
starts = keyValue[1];
}
else if (keyValue[0].equals("Base1")) {
else if ("Base1".equals(keyValue[0])) {
baseone = keyValue[1];
}
else if (keyValue[0].equals("Base2")) {
else if ("Base2".equals(keyValue[0])) {
basetwo = keyValue[1];
}
else if (keyValue[0].equals("Base3")) {
else if ("Base3".equals(keyValue[0])) {
basethree = keyValue[1];
}
else {
Expand Down
Expand Up @@ -67,46 +67,46 @@ public static EmblRecord process(File file) throws IOException {
if (line.length() > 1) {
lineInfo = line.substring(2, line.length()).trim();
lineIdentifier = line.substring(0, 2);
if (lineIdentifier.equals("ID"))
if ("ID".equals(lineIdentifier))
emblRecord.setEmblId(populateID(lineInfo));
else if (lineIdentifier.equals("AC"))
else if ("AC".equals(lineIdentifier))
populateAccessionNumber(line, accessionNumber);
else if (lineIdentifier.equals("DT") && line.contains("Created"))
else if ("DT".equals(lineIdentifier) && line.contains("Created"))
emblRecord.setCreatedDate(lineInfo);
else if (lineIdentifier.equals("DT") && line.contains("updated"))
else if ("DT".equals(lineIdentifier) && line.contains("updated"))
emblRecord.setLastUpdatedDate(lineInfo);
else if (lineIdentifier.equals("DE"))
else if ("DE".equals(lineIdentifier))
emblRecord.setSequenceDescription(lineInfo);
else if (lineIdentifier.equals("KW"))
else if ("KW".equals(lineIdentifier))
keyword.add(lineInfo);
else if (lineIdentifier.equals("OS"))
else if ("OS".equals(lineIdentifier))
emblRecord.setOrganismSpecies(lineInfo);
else if (lineIdentifier.equals("OC"))
else if ("OC".equals(lineIdentifier))
emblRecord.setOrganismClassification(lineInfo);
else if (lineIdentifier.equals("OG"))
else if ("OG".equals(lineIdentifier))
emblRecord.setOrGanelle(lineInfo);
else if (lineIdentifier.equals("RN") || lineIdentifier.equals("RP")
|| lineIdentifier.equals("RX") || lineIdentifier.equals("RG")
|| lineIdentifier.equals("RA") || lineIdentifier.equals("RT")
|| lineIdentifier.equals("RL"))
else if ("RN".equals(lineIdentifier) || "RP".equals(lineIdentifier)
|| "RX".equals(lineIdentifier) || "RG".equals(lineIdentifier)
|| "RA".equals(lineIdentifier) || "RT".equals(lineIdentifier)
|| "RL".equals(lineIdentifier))
populateEmblReferences(lineIdentifier, lineInfo, emblReference, emblReferences);
else if (lineIdentifier.equals("DR"))
else if ("DR".equals(lineIdentifier))
emblRecord.setDatabaseCrossReference(lineInfo);
else if (lineIdentifier.equals("AH"))
else if ("AH".equals(lineIdentifier))
emblRecord.setAssemblyHeader(lineInfo);
else if (lineIdentifier.equals("AS"))
else if ("AS".equals(lineIdentifier))
emblRecord.setAssemblyInformation(lineInfo);
else if (lineIdentifier.equals("CO"))
else if ("CO".equals(lineIdentifier))
emblRecord.setConstructedSequence(lineInfo);
else if (lineIdentifier.equals("FH"))
else if ("FH".equals(lineIdentifier))
emblRecord.setFeatureHeader(lineInfo);
else if (lineIdentifier.equals("FT"))
else if ("FT".equals(lineIdentifier))
emblRecord.setFeatureTable(lineInfo);
else if (lineIdentifier.equals("SQ"))
else if ("SQ".equals(lineIdentifier))
emblRecord.setSequenceHeader(lineInfo);
else if (lineIdentifier.equals(" ") && !lineIdentifier.equals("//"))
else if (" ".equals(lineIdentifier) && !"//".equals(lineIdentifier))
populateSequence(line, sequence);
else if (lineIdentifier.equals("//")) {
else if ("//".equals(lineIdentifier)) {
emblRecord.setKeyword(keyword);
emblRecord.setEmblReference(emblReferences);
emblRecord.setAccessionNumber(accessionNumber);
Expand All @@ -129,19 +129,19 @@ private static void populateSequence(String line, StringBuilder sequence) {

private static void populateEmblReferences(String lineIdentifier, String lineInfo, EmblReference emblReference
, LinkedList<EmblReference> emblReferences) {
if (lineIdentifier.equals("RN"))
if ("RN".equals(lineIdentifier))
emblReference.setReferenceNumber(lineInfo);
else if (lineIdentifier.equals("RP"))
else if ("RP".equals(lineIdentifier))
emblReference.setReferencePosition(lineInfo);
else if (lineIdentifier.equals("RX"))
else if ("RX".equals(lineIdentifier))
emblReference.setReferenceCrossReference(lineInfo);
else if (lineIdentifier.equals("RG"))
else if ("RG".equals(lineIdentifier))
emblReference.setReferenceGroup(lineInfo);
else if (lineIdentifier.equals("RA"))
else if ("RA".equals(lineIdentifier))
emblReference.setReferenceAuthor(lineInfo);
else if (lineIdentifier.equals("RT"))
else if ("RT".equals(lineIdentifier))
emblReference.setReferenceTitle(lineInfo);
else if (lineIdentifier.equals("RL")) {
else if ("RL".equals(lineIdentifier)) {
emblReference.setReferenceLocation(lineInfo);
emblReferences.add(emblReference.copyEmblReference(emblReference));
}
Expand Down

0 comments on commit a9542ca

Please sign in to comment.