Skip to content

Commit cd64464

Browse files
committed
Code Cleanup (warnings)
Automatically fixed - "'size() == 0' can be replaced with 'isEmpty()'
1 parent ecbb2b9 commit cd64464

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+130
-130
lines changed

use-core/src/main/java/org/tzi/use/gen/tool/GGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public void printResultStatistics() throws GNoResultException {
304304
PrintWriter pw = new PrintWriter(System.out);
305305
lastResult().checker().printStatistics(pw, lastResult().collector().numberOfCheckedStates());
306306

307-
if (lastResult().collector().getBarriers().size() > 0) {
307+
if (!lastResult().collector().getBarriers().isEmpty()) {
308308
pw.println();
309309
pw.println("Barrier statistics (barriers marked with * were calculated):");
310310
pw.println(" checks valid invalid mul. viol. time (ms) Barrier");

use-core/src/main/java/org/tzi/use/parser/ocl/ASTExpression.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ protected Expression genNavigation(Context ctx, Token rolenameToken,
187187
}
188188

189189
if (navigationNeedsExplicitRolename(srcClass, dst)) {
190-
if (explicitRolenameOrQualifiers.size() == 0) {
190+
if (explicitRolenameOrQualifiers.isEmpty()) {
191191
// an explicit rolename is needed, but not provided
192192
throw new SemanticException(
193193
rolenameToken,

use-core/src/main/java/org/tzi/use/parser/ocl/ASTOperationExpression.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ else if (srcType.isKindOfTupleType(VoidHandling.EXCLUDE_VOID) )
283283

284284
opcase += fFollowsArrow ? ARROW : DOT;
285285
opcase += fHasParentheses ? PARENTHESES : NO_PARENTHESES;
286-
opcase += fExplicitRolenameOrQualifiers.size() > 0 ? EXPLICIT_ROLENAME : NO_EXPLICIT_ROLENAME;
286+
opcase += !fExplicitRolenameOrQualifiers.isEmpty() ? EXPLICIT_ROLENAME : NO_EXPLICIT_ROLENAME;
287287

288288
switch ( opcase ) {
289289
case SRC_SIMPLE_TYPE + DOT + NO_PARENTHESES:

use-core/src/main/java/org/tzi/use/parser/use/ASTAssociation.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void generate() throws SemanticException {
188188
*/
189189
private void genRedefinesConstraints(ASTAssociationEnd aEnd)
190190
throws SemanticException {
191-
if (aEnd.getRedefinesRolenames().size() > 0) {
191+
if (!aEnd.getRedefinesRolenames().isEmpty()) {
192192
// Get the MAssociationEnd from the name
193193
MClass cls = model.getClass(aEnd.getClassName());
194194
MAssociationEnd redefiningEnd = association.getAssociationEnd(cls, aEnd.getRolename(ctx));
@@ -202,7 +202,7 @@ private void genRedefinesConstraints(ASTAssociationEnd aEnd)
202202
String redefinesRolename = redefinesRolenameToken.getText();
203203
List<MAssociationEnd> possibleRedefinedEnds = cls.getAssociationEnd(redefinesRolename);
204204

205-
if (possibleRedefinedEnds.size() == 0) {
205+
if (possibleRedefinedEnds.isEmpty()) {
206206
throw new SemanticException(redefinesRolenameToken, "No association end with name '" + redefinesRolename + "' to redefine.");
207207
}
208208

@@ -259,7 +259,7 @@ private void genSubsetsConstraints(ASTAssociationEnd aEnd) throws SemanticExcept
259259
String subsetsRolename = subsetsRolenameToken.getText();
260260
List<MAssociationEnd> possibleSubsettedEnds = cls.getAssociationEnd(subsetsRolename);
261261

262-
if (possibleSubsettedEnds.size() == 0) {
262+
if (possibleSubsettedEnds.isEmpty()) {
263263
throw new SemanticException(subsetsRolenameToken, "No association end with name '" + subsetsRolename + "' to subset.");
264264
}
265265

use-core/src/main/java/org/tzi/use/parser/use/ASTAssociationEnd.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public boolean isUnion() {
162162
*/
163163
public void addSubsetsRolename(Token name) {
164164
// Lazy initialization of the list.
165-
if (subsetsRolename.size() == 0)
165+
if (subsetsRolename.isEmpty())
166166
subsetsRolename = new ArrayList<Token>();
167167

168168
subsetsRolename.add(name);
@@ -182,7 +182,7 @@ public List<Token> getSubsetsRolenames() {
182182
*/
183183
public void addRedefinesRolename(Token rolename) {
184184
// Lazy initialization of the list.
185-
if (redefinesRolenames.size() == 0)
185+
if (redefinesRolenames.isEmpty())
186186
redefinesRolenames = new ArrayList<Token>();
187187

188188
redefinesRolenames.add(rolename);
@@ -248,7 +248,7 @@ public MAssociationEnd gen(Context ctx, int kind) throws SemanticException {
248248
}
249249

250250
List<VarDecl> generatedQualifiers;
251-
if (qualifiers.size() == 0) {
251+
if (qualifiers.isEmpty()) {
252252
generatedQualifiers = Collections.emptyList();
253253
} else {
254254
generatedQualifiers = new ArrayList<VarDecl>(qualifiers.size());

use-core/src/main/java/org/tzi/use/parser/use/ASTInvariantClause.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ MClassInvariant gen(Context ctx, List<Token> varTokens, MClassifier cf, boolean
6262
MClassInvariant inv = null;
6363

6464
try {
65-
if (varTokens != null && varTokens.size() > 0) {
65+
if (varTokens != null && !varTokens.isEmpty()) {
6666
for (Token var : varTokens) {
6767
vars.add(var, cf);
6868
ctx.exprContext().push(var.getText(), cf);

use-core/src/main/java/org/tzi/use/uml/mm/MAssociationEnd.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public boolean equals(Object obj) {
248248
public Type getType( Type sourceObjectType, MNavigableElement src, boolean qualifiedAccess ) {
249249
Type t;
250250

251-
if (this.getRedefiningEnds().size() > 0) {
251+
if (!this.getRedefiningEnds().isEmpty()) {
252252
t = getRedefinedType((MClass)sourceObjectType);
253253
} else {
254254
t = cls();
@@ -480,7 +480,7 @@ public List<VarDecl> getQualifiers() {
480480

481481
@Override
482482
public boolean hasQualifiers() {
483-
return getQualifiers().size() > 0;
483+
return !getQualifiers().isEmpty();
484484
}
485485

486486
/* (non-Javadoc)

use-core/src/main/java/org/tzi/use/uml/mm/MClassInvariant.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public final class MClassInvariant extends MModelElementImpl implements UseFileL
100100
fIsExistential = isExistential;
101101

102102
// parse variables
103-
if (vars == null || vars.size() == 0)
103+
if (vars == null || vars.isEmpty())
104104
{
105105
fHasVars = false;
106106
VarDecl decl = new VarDecl("self", fClassifier);

use-core/src/main/java/org/tzi/use/uml/mm/MMPrintVisitor.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void visitAssociationEnd(MAssociationEnd e) {
233233
result.append(')');
234234
}
235235

236-
if (e.getSubsettedEnds().size() > 0) {
236+
if (!e.getSubsettedEnds().isEmpty()) {
237237
for (MAssociationEnd end : e.getSubsettedEnds()) {
238238
result.append(ws());
239239
result.append(keyword("subsets"));
@@ -242,7 +242,7 @@ public void visitAssociationEnd(MAssociationEnd e) {
242242
}
243243
}
244244

245-
if (e.getRedefinedEnds().size() > 0) {
245+
if (!e.getRedefinedEnds().isEmpty()) {
246246
for (MAssociationEnd end : e.getRedefinedEnds()) {
247247
result.append(ws());
248248
result.append(keyword("redefines"));
@@ -299,7 +299,7 @@ else if(e.isDerived()){
299299

300300
private void visitAttributesAndOperations( MClassifier e ) {
301301
// visit attributes
302-
if (e.attributes().size() > 0 ) {
302+
if (!e.attributes().isEmpty()) {
303303
indent();
304304
println(keyword("attributes"));
305305
incIndent();
@@ -315,7 +315,7 @@ private void visitAttributesAndOperations( MClassifier e ) {
315315
}
316316

317317
// visit operations
318-
if (e.operations().size() > 0 ) {
318+
if (!e.operations().isEmpty()) {
319319
indent();
320320
println(keyword("operations"));
321321
incIndent();

use-core/src/main/java/org/tzi/use/uml/mm/MModelElementImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static class MutableInteger {
5858
}
5959

6060
protected MModelElementImpl(String name) {
61-
if (name == null || name.length() == 0 )
61+
if (name == null || name.isEmpty())
6262
throw new IllegalArgumentException("Modelelement without name");
6363
fName = name;
6464
hashCode = fName.hashCode();
@@ -71,7 +71,7 @@ protected MModelElementImpl(String name) {
7171
* they may still clash with some user defined name.
7272
*/
7373
protected MModelElementImpl(String name, String prefix) {
74-
if (name == null || name.trim().length() == 0 ) {
74+
if (name == null || name.trim().isEmpty()) {
7575
MutableInteger i = fNameMap.get(prefix);
7676
if (i == null ) {
7777
i = new MutableInteger();

use-core/src/main/java/org/tzi/use/uml/ocl/expr/operations/StandardOperationsString.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ public Value eval(EvalContext ctx, Value[] args, Type resultType) {
435435
String self = ((StringValue)args[0]).value();
436436
String s = ((StringValue)args[1]).value();
437437

438-
if (self.length() == 0) return IntegerValue.valueOf(0);
439-
if (s.length()== 0 && self.length() > 0) return IntegerValue.valueOf(1);
438+
if (self.isEmpty()) return IntegerValue.valueOf(0);
439+
if (s.isEmpty() && !self.isEmpty()) return IntegerValue.valueOf(1);
440440

441441
return IntegerValue.valueOf(self.indexOf(s) + 1);
442442
}

use-core/src/main/java/org/tzi/use/uml/sys/MLinkImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected MLinkImpl(MAssociation assoc, List<MObject> objects, List<List<Value>>
8282
this.qualifierValues = qualifierValues;
8383
Iterator<MAssociationEnd> it1 = assoc.associationEnds().iterator();
8484
Iterator<MObject> it2 = objects.iterator();
85-
boolean hasQualifiers = (qualifierValues != null && qualifierValues.size() > 0);
85+
boolean hasQualifiers = (qualifierValues != null && !qualifierValues.isEmpty());
8686
Iterator<List<Value>> it3 = (hasQualifiers ? qualifierValues.iterator() : null);
8787

8888
int newHashCode = fAssociation.hashCode();

use-core/src/main/java/org/tzi/use/uml/sys/MLinkSet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public CacheEntry(MAssociationEnd end, MObject object, List<Value> qualifiers) {
6767
this.object = object;
6868
// We set qualifier to null, if no elements are given
6969
// This makes comparison easier.
70-
this.qualifiers = (qualifiers != null && qualifiers.size() == 0) ? null : qualifiers;
70+
this.qualifiers = (qualifiers != null && qualifiers.isEmpty()) ? null : qualifiers;
7171
hashCode = end.hashCode() + 19 * object.hashCode() + (this.qualifiers == null ? 0 : 23 * this.qualifiers.hashCode());
7272
}
7373

use-core/src/main/java/org/tzi/use/uml/sys/MOperationCall.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ public Map<MProtocolStateMachineInstance, Set<MTransition>> getExecutedTransitio
621621
* @return
622622
*/
623623
public boolean hasExecutedTransitions() {
624-
return executedTransitions != null && executedTransitions.size() > 0;
624+
return executedTransitions != null && !executedTransitions.isEmpty();
625625
}
626626

627627
/**

use-core/src/main/java/org/tzi/use/uml/sys/MSystemState.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ protected ArrayList<MObject> getNavigableObjectsFromDerivedAssociation(MObject o
14531453
} else if (dst.isDerived()) {
14541454
res.addAll(linkedObjects);
14551455
} else {
1456-
if (linkedObjects.size() > 0)
1456+
if (!linkedObjects.isEmpty())
14571457
res.add(sourceObjects[dstIndex]);
14581458
}
14591459
}
@@ -1942,7 +1942,7 @@ private boolean validateBinaryAssociations(PrintWriter out, MAssociation assoc,
19421942
for (MObject obj : objects) {
19431943
Map<List<Value>,Set<MObject>> linkedObjects = getLinkedObjects(obj, aend1, aend2);
19441944

1945-
if (linkedObjects.size() == 0 && !aend2.multiplicity().contains(0)) {
1945+
if (linkedObjects.isEmpty() && !aend2.multiplicity().contains(0)) {
19461946
reportMultiplicityViolation(out, assoc, aend1, aend2, obj, null);
19471947
if (!reportAllErrors) {
19481948
return false;

use-core/src/main/java/org/tzi/use/uml/sys/soil/MBlockStatement.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Value execute(SoilEvaluationContext context,
8484
protected String shellCommand() {
8585
StringBuilder sb = new StringBuilder();
8686

87-
if(fVariableDeclarations.size() > 0){
87+
if(!fVariableDeclarations.isEmpty()){
8888
sb.append("declare ");
8989
boolean first = true;
9090
for(VarDecl var : fVariableDeclarations){
@@ -109,7 +109,7 @@ protected void toConcreteSyntax(
109109
String indentIncrease,
110110
StringBuilder target) {
111111

112-
if(fVariableDeclarations.size() > 0){
112+
if(!fVariableDeclarations.isEmpty()){
113113
target.append(indent);
114114
target.append("declare ");
115115
boolean first = true;

use-core/src/main/java/org/tzi/use/uml/sys/soil/MLinkDeletionStatement.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected String shellCommand() {
189189
public String format(MRValue element) {
190190
String qualifierValues = "";
191191

192-
if (!qualifier.isEmpty() && qualifier.get(index) != null && qualifier.get(index).size() > 0) {
192+
if (!qualifier.isEmpty() && qualifier.get(index) != null && !qualifier.get(index).isEmpty()) {
193193
qualifierValues = "{";
194194
qualifierValues += StringUtil.fmtSeq(qualifier.get(index), ",");
195195
qualifierValues += "}";

use-core/src/main/java/org/tzi/use/util/Report.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Report(int columns, String fmt) {
9393
Arrays.fill(fColumnFormat, FMT_LEFT);
9494

9595
// parse format string
96-
if (fmt != null && fmt.length() > 0 ) {
96+
if (fmt != null && !fmt.isEmpty()) {
9797
char[] f = fmt.toCharArray();
9898
int col = 0;
9999
int fillIndex = 0;

use-core/src/main/java/org/tzi/use/util/collections/CollectionUtil.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static <T> List<List<Pair<T>>> combinationsOne( List<T> firstList, List<T
122122

123123
private static <T> void combinationsOneAux(List<List<Pair<T>>> result, List<Pair<T>> head, List<List<Pair<T>>> tail) {
124124

125-
if (tail.size() == 0) return;
125+
if (tail.isEmpty()) return;
126126

127127
List<Pair<T>> myCombinations = tail.get(0);
128128

@@ -196,7 +196,7 @@ public static <T> Set<T> emptySetIfNull(final Set<T> theSet) {
196196
* @return The same list if <code>theList.size() > 0</code> or a new <code>ArrayList</code>
197197
*/
198198
public static <T> List<T> initAsArrayList(final List<T> theList) {
199-
if (theList.size() == 0)
199+
if (theList.isEmpty())
200200
return new ArrayList<T>();
201201
else
202202
return theList;
@@ -218,7 +218,7 @@ public static <T> List<T> initAsArrayList(final List<T> theList) {
218218
* @return The same <code>Map</code> if <code>theMap.size() > 0</code> or a new <code>HashMap</code>
219219
*/
220220
public static <TK, TV> Map<TK,TV> initAsHashMap(final Map<TK,TV> theMap) {
221-
if (theMap.size() == 0)
221+
if (theMap.isEmpty())
222222
return new HashMap<TK,TV>();
223223
else
224224
return theMap;
@@ -239,7 +239,7 @@ public static <TK, TV> Map<TK,TV> initAsHashMap(final Map<TK,TV> theMap) {
239239
* @return The same set if <code>theSet.size() > 0</code> or a new <code>HashSet</code>
240240
*/
241241
public static <T> Set<T> initAsHashSet(final Set<T> theSet) {
242-
if (theSet.size() == 0)
242+
if (theSet.isEmpty())
243243
return new HashSet<T>();
244244
else
245245
return theSet;

use-core/src/main/java/org/tzi/use/util/collections/MinCombinationsIterator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private void buildPartitions() {
102102
partition.add(entry);
103103
}
104104

105-
if (partition.size() > 0)
105+
if (!partition.isEmpty())
106106
partitionedCombinations.add(partition);
107107
}
108108
}

use-core/src/test/java/org/tzi/use/parser/USECompilerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void testExpression() throws IOException {
179179
}
180180
continue;
181181
}
182-
if (line.length() == 0 || line.startsWith("#")) {
182+
if (line.isEmpty() || line.startsWith("#")) {
183183
continue;
184184
}
185185

0 commit comments

Comments
 (0)