Commit a97c59c6 authored by Daniel Le Berre's avatar Daniel Le Berre
Browse files

fixed most sonarqube violations in org.sat4j and org.sat4j.core

parent 56e95163
Pipeline #20055 passed with stages
in 54 minutes and 36 seconds
......@@ -181,7 +181,7 @@ public class MUSLauncher extends AbstractLauncher {
System.out.println(solver.getLogPrefix()
+ "found mus number " + ++muscount);
out.print(OutputPrefix.SOLUTION_PREFIX);
int[] localMus = new int[solution.size()];
var localMus = new int[solution.size()];
solution.copyTo(localMus);
reader.decode(localMus, out);
out.println();
......@@ -219,7 +219,7 @@ public class MUSLauncher extends AbstractLauncher {
private int muscount = 0;
public static void main(final String[] args) {
MUSLauncher lanceur = new MUSLauncher();
var lanceur = new MUSLauncher();
if (args.length < 1 || args.length > 2) {
lanceur.usage();
return;
......
......@@ -33,7 +33,7 @@ import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* That class is intented to manage internationalisation within the application.
* That class is intended to manage internationalization within the application.
*
* @author leberre
*
......@@ -54,7 +54,6 @@ public final class Messages {
}
public static String getString(String key) {
// TODO Auto-generated method stub
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
......
......@@ -105,9 +105,9 @@ public final class OptimizationMode implements ILauncherMode {
if (!optproblem.hasNoObjectiveFunction()) {
String objvalue;
if (optproblem instanceof LexicoDecorator<?>) {
IVec<Number> values = new Vec<Number>();
IVec<Number> values = new Vec<>();
LexicoDecorator<?> lexico = (LexicoDecorator<?>) optproblem;
for (int i = 0; i < lexico.numberOfCriteria(); i++) {
for (var i = 0; i < lexico.numberOfCriteria(); i++) {
values.push(lexico.getObjectiveValue(i));
}
objvalue = values.toString();
......@@ -126,7 +126,7 @@ public final class OptimizationMode implements ILauncherMode {
public void solve(IProblem problem, Reader reader, ILogAble logger,
PrintWriter out, long beginTime) {
boolean isSatisfiable = false;
var isSatisfiable = false;
this.nbSolutions = 0;
IOptimizationProblem optproblem = (IOptimizationProblem) problem;
exitCode = ExitCode.UNKNOWN;
......@@ -177,7 +177,6 @@ public final class OptimizationMode implements ILauncherMode {
public void onSolutionFound(int[] solution) {
this.nbSolutions++;
// this.exitCode = ExitCode.SATISFIABLE;
this.out.printf("c Found solution #%d (%.2f)s%n", nbSolutions,
(System.currentTimeMillis() - beginTime) / 1000.0);
this.out.println("c Value of objective function : "
......
......@@ -69,7 +69,7 @@ public abstract class ASolverFactory<T extends ISolver>
}
}
Collections.sort(l);
String[] names = new String[l.size()];
var names = new String[l.size()];
l.toArray(names);
return names;
}
......@@ -87,7 +87,7 @@ public abstract class ASolverFactory<T extends ISolver>
public T createSolverByName(String solvername) {
try {
Class<?>[] paramtypes = {};
Method m = this.getClass().getMethod("new" + solvername, //$NON-NLS-1$
var m = this.getClass().getMethod("new" + solvername, //$NON-NLS-1$
paramtypes);
return (T) m.invoke(null, (Object[]) null);
} catch (SecurityException | IllegalArgumentException
......
......@@ -46,7 +46,7 @@ import org.sat4j.specs.VarMapper;
@Feature("constraint")
public class ConstrGroup implements IConstr {
private final IVec<IConstr> constrs = new Vec<IConstr>();
private final IVec<IConstr> constrs = new Vec<>();
private final boolean disallowNullConstraints;
/**
......@@ -123,8 +123,8 @@ public class ConstrGroup implements IConstr {
@Override
public String dump() {
StringBuilder stb = new StringBuilder();
for (int i = 0; i < constrs.size(); i++) {
var stb = new StringBuilder();
for (var i = 0; i < constrs.size(); i++) {
stb.append(constrs.get(i).dump());
if (i < constrs.size() - 1) {
stb.append(System.lineSeparator());
......
......@@ -36,8 +36,8 @@ import org.sat4j.specs.IteratorInt;
final class EmptyVecInt implements IVecInt {
/**
*
*/
*
*/
private static final long serialVersionUID = 1L;
public int size() {
......@@ -45,9 +45,11 @@ final class EmptyVecInt implements IVecInt {
}
public void shrink(int nofelems) {
// do nothing when IVecInt is empty
}
public void shrinkTo(int newsize) {
// do nothing when IVecInt is empty
}
public IVecInt pop() {
......@@ -55,9 +57,11 @@ final class EmptyVecInt implements IVecInt {
}
public void growTo(int newsize, int pad) {
// do nothing when IVecInt is empty
}
public void ensure(int nsize) {
// do nothing when IVecInt is empty
}
public IVecInt push(int elem) {
......@@ -69,6 +73,7 @@ final class EmptyVecInt implements IVecInt {
}
public void clear() {
// do nothing when IVecInt is empty
}
public int last() {
......@@ -88,18 +93,23 @@ final class EmptyVecInt implements IVecInt {
}
public void copyTo(IVecInt copy) {
// do nothing when IVecInt is empty
}
public void copyTo(int[] is) {
// do nothing when IVecInt is empty
}
public void moveTo(IVecInt dest) {
// do nothing when IVecInt is empty
}
public void moveTo2(IVecInt dest) {
// do nothing when IVecInt is empty
}
public void moveTo(int[] dest) {
// do nothing when IVecInt is empty
}
public void insertFirst(int elem) {
......@@ -115,9 +125,11 @@ final class EmptyVecInt implements IVecInt {
}
public void sort() {
// do nothing when IVecInt is empty
}
public void sortUnique() {
// do nothing when IVecInt is empty
}
public int unsafeGet(int eleem) {
......@@ -188,6 +200,7 @@ final class EmptyVecInt implements IVecInt {
}
public void sort(Comparator<Integer> comparator) {
// do nothing when IVecInt is empty
}
@Override
......
......@@ -82,25 +82,25 @@ public final class LiteralsUtils {
/**
* Returns the positive literal associated with a variable.
*
* @param var
* @param variable
* a variable in Dimacs format
* @return the positive literal associated with this variable in internal
* representation
*/
public static int posLit(int var) {
return var << 1;
public static int posLit(int variable) {
return variable << 1;
}
/**
* Returns the negative literal associated with a variable.
*
* @param var
* @param variable
* a variable in Dimacs format
* @return the negative literal associated with this variable in internal
* representation
*/
public static int negLit(int var) {
return var << 1 ^ 1;
public static int negLit(int variable) {
return variable << 1 ^ 1;
}
/**
......
......@@ -194,8 +194,8 @@ public final class ReadOnlyVec<T> implements IVec<T> {
@Override
public IVec<T> clone() {
IVec<T> cloned = new Vec<T>(this.size());
IVec<T> cloned = new Vec<>(this.size());
this.copyTo(cloned);
return new ReadOnlyVec<T>(cloned);
return new ReadOnlyVec<>(cloned);
}
}
......@@ -43,8 +43,8 @@ import org.sat4j.specs.IteratorInt;
public final class ReadOnlyVecInt implements IVecInt {
/**
*
*/
*
*/
private static final long serialVersionUID = 1L;
private final IVecInt vec;
......@@ -173,7 +173,7 @@ public final class ReadOnlyVecInt implements IVecInt {
* @since 2.1
*/
public int[] toArray() {
int[] copy = new int[this.vec.size()];
var copy = new int[this.vec.size()];
this.vec.copyTo(copy);
return copy;
}
......@@ -200,7 +200,7 @@ public final class ReadOnlyVecInt implements IVecInt {
* @since 2.3.1
*/
public VecInt[] subset(int cardinal) {
return null;
throw new UnsupportedOperationException();
}
@Override
......
......@@ -113,7 +113,7 @@ public final class Vec<T> implements IVec<T> {
@SuppressWarnings("unchecked")
public Vec(int size, T pad) {
this.myarray = (T[]) new Object[size];
for (int i = 0; i < size; i++) {
for (var i = 0; i < size; i++) {
this.myarray[i] = pad;
}
this.nbelem = size;
......@@ -132,7 +132,6 @@ public final class Vec<T> implements IVec<T> {
* the number of elements to remove.
*/
public void shrink(int nofelems) {
// assert nofelems <= nbelem;
while (nofelems-- > 0) {
this.myarray[--this.nbelem] = null;
}
......@@ -145,12 +144,10 @@ public final class Vec<T> implements IVec<T> {
* the new size of the vector.
*/
public void shrinkTo(final int newsize) {
// assert newsize <= size();
for (int i = this.nbelem; i > newsize; i--) {
this.myarray[i - 1] = null;
}
this.nbelem = newsize;
// assert size() == newsize;
}
/**
......@@ -158,12 +155,10 @@ public final class Vec<T> implements IVec<T> {
* empty!
*/
public void pop() {
// assert size() > 0;
this.myarray[--this.nbelem] = null;
}
public void growTo(final int newsize, final T pad) {
// assert newsize >= size();
ensure(newsize);
for (int i = this.nbelem; i < newsize; i++) {
this.myarray[i] = pad;
......@@ -232,7 +227,6 @@ public final class Vec<T> implements IVec<T> {
* @return the last element on the stack (the one on the top)
*/
public T last() {
// assert size() != 0;
return this.myarray[this.nbelem - 1];
}
......@@ -251,8 +245,7 @@ public final class Vec<T> implements IVec<T> {
* an element from the vector.
*/
public void remove(T elem) {
// assert size() > 0;
int j = 0;
var j = 0;
for (; this.myarray[j] != elem; j++) {
if (j == size())
throw new NoSuchElementException();
......@@ -292,8 +285,7 @@ public final class Vec<T> implements IVec<T> {
* vector
*/
public T delete(int index) {
// assert index >= 0 && index < nbelem;
T ith = this.myarray[index];
var ith = this.myarray[index];
this.myarray[index] = this.myarray[--this.nbelem];
this.myarray[this.nbelem] = null;
return ith;
......@@ -327,7 +319,6 @@ public final class Vec<T> implements IVec<T> {
* <code>dest.length &gt;= this.size()</code>.
*/
public <E> void copyTo(E[] dest) {
// assert dest.length >= nbelem;
System.arraycopy(this.myarray, 0, dest, 0, this.nbelem);
}
......@@ -362,8 +353,8 @@ public final class Vec<T> implements IVec<T> {
*/
@Override
public String toString() {
StringBuilder stb = new StringBuilder();
for (int i = 0; i < this.nbelem - 1; i++) {
var stb = new StringBuilder();
for (var i = 0; i < this.nbelem - 1; i++) {
stb.append(this.myarray[i]);
stb.append(","); //$NON-NLS-1$
}
......@@ -395,7 +386,7 @@ public final class Vec<T> implements IVec<T> {
if (width <= 15) {
selectionSort(from, to, cmp);
} else {
T pivot = this.myarray[width / 2 + from];
var pivot = this.myarray[width / 2 + from];
T tmp;
int i = from - 1;
int j = to;
......@@ -466,7 +457,7 @@ public final class Vec<T> implements IVec<T> {
if (v.size() != size()) {
return false;
}
for (int i = 0; i < size(); i++) {
for (var i = 0; i < size(); i++) {
if (!v.get(i).equals(get(i))) {
return false;
}
......@@ -483,8 +474,8 @@ public final class Vec<T> implements IVec<T> {
*/
@Override
public int hashCode() {
int sum = 0;
for (int i = 0; i < this.nbelem; i++) {
var sum = 0;
for (var i = 0; i < this.nbelem; i++) {
sum += this.myarray[i].hashCode() / this.nbelem;
}
return sum;
......@@ -504,10 +495,6 @@ public final class Vec<T> implements IVec<T> {
}
return Vec.this.myarray[this.i++];
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
......@@ -519,7 +506,7 @@ public final class Vec<T> implements IVec<T> {
* @since 2.1
*/
public boolean contains(T e) {
for (int i = 0; i < this.nbelem; i++) {
for (var i = 0; i < this.nbelem; i++) {
if (this.myarray[i].equals(e)) {
return true;
}
......@@ -531,7 +518,7 @@ public final class Vec<T> implements IVec<T> {
* @since 2.2
*/
public int indexOf(T element) {
for (int i = 0; i < this.nbelem; i++) {
for (var i = 0; i < this.nbelem; i++) {
if (this.myarray[i].equals(element)) {
return i;
}
......@@ -541,7 +528,7 @@ public final class Vec<T> implements IVec<T> {
@Override
public IVec<T> clone() {
IVec<T> cloned = new Vec<T>(this.size());
IVec<T> cloned = new Vec<>(this.size());
this.copyTo(cloned);
return cloned;
}
......
......@@ -108,7 +108,7 @@ public final class VecInt implements IVecInt {
*/
public VecInt(int size, int pad) {
this.myarray = new int[size];
for (int i = 0; i < size; i++) {
for (var i = 0; i < size; i++) {
this.myarray[i] = pad;
}
this.nbelem = size;
......@@ -125,14 +125,10 @@ public final class VecInt implements IVecInt {
* the number of elements to remove
*/
public void shrink(int nofelems) {
// assert nofelems >= 0;
// assert nofelems <= size();
this.nbelem -= nofelems;
}
public void shrinkTo(int newsize) {
// assert newsize >= 0;
// assert newsize < nbelem;
this.nbelem = newsize;
}
......@@ -141,13 +137,11 @@ public final class VecInt implements IVecInt {
* rien.
*/
public IVecInt pop() {
// assert size() != 0;
--this.nbelem;
return this;
}
public void growTo(int newsize, final int pad) {
// assert newsize > size();
ensure(newsize);
while (--newsize >= 0) {
this.myarray[this.nbelem++] = pad;
......@@ -156,7 +150,7 @@ public final class VecInt implements IVecInt {
public void ensure(int nsize) {
if (nsize >= this.myarray.length) {
int[] narray = new int[Math.max(nsize, this.nbelem * 2)];
var narray = new int[Math.max(nsize, this.nbelem * 2)];
System.arraycopy(this.myarray, 0, narray, 0, this.nbelem);
this.myarray = narray;
}
......@@ -177,12 +171,10 @@ public final class VecInt implements IVecInt {
}
public int last() {
// assert nbelem > 0;
return this.myarray[this.nbelem - 1];
}
public int get(int i) {
// assert i >= 0 && i < nbelem;
return this.myarray[i];
}
......@@ -197,7 +189,7 @@ public final class VecInt implements IVecInt {
public boolean contains(int e) {
final int[] workArray = this.myarray; // dvh, faster access
for (int i = 0; i < this.nbelem; i++) {
for (var i = 0; i < this.nbelem; i++) {
if (workArray[i] == e) {
return true;
}
......@@ -210,7 +202,7 @@ public final class VecInt implements IVecInt {
*/
public int indexOf(int e) {
final int[] workArray = this.myarray; // dvh, faster access
for (int i = 0; i < this.nbelem; i++) {
for (var i = 0; i < this.nbelem; i++) {
if (workArray[i] == e) {
return i;
}
......@@ -256,7 +248,6 @@ public final class VecInt implements IVecInt {
* the target array.
*/
public void copyTo(int[] is) {
// assert is.length >= nbelem;
System.arraycopy(this.myarray, 0, is, 0, this.nbelem);
}
......@@ -267,7 +258,7 @@ public final class VecInt implements IVecInt {
public void moveTo2(IVecInt dest) {
VecInt ndest = (VecInt) dest;
int tmp[] = ndest.myarray;
int[] tmp = ndest.myarray;
ndest.myarray = this.myarray;
ndest.nbelem = this.nbelem;
this.myarray = tmp;
......@@ -314,8 +305,7 @@ public final class VecInt implements IVecInt {
* an element from that VecInt
*/
public void remove(int elem) {
// assert size() > 0;
int j = 0;
var j = 0;
for (; this.myarray[j] != elem; j++) {
if (j == size())
throw new NoSuchElementException();
......@@ -334,7 +324,6 @@ public final class VecInt implements IVecInt {
* vector
*/
public int delete(int i) {
// assert i >= 0 && i < nbelem;
int ith = this.myarray[i];
this.myarray[i] = this.myarray[--this.nbelem];
return ith;
......@@ -457,7 +446,7 @@ public final class VecInt implements IVecInt {
if (v.size() != this.nbelem) {
return false;
}
for (int i = 0; i < this.nbelem; i++) {
for (var i = 0; i < this.nbelem; i++) {
if (v.get(i) != this.myarray[i]) {
return false;
}
......@@ -475,7 +464,7 @@ public final class VecInt implements IVecInt {
@Override
public int hashCode() {
long sum = 0;
for (int i = 0; i < this.nbelem; i++) {
for (var i = 0; i < this.nbelem; i++) {
sum += this.myarray[i];
}
return (int) sum / this.nbelem;
......@@ -504,8 +493,8 @@ public final class VecInt implements IVecInt {
* @return true iff the current vector is a subset of vec
*/
public boolean isSubsetOf(VecInt vec) {
int i = 0;
int j = 0;
var i = 0;
var j = 0;
while (i < this.nbelem && j < vec.nbelem) {
while (j < vec.nbelem && vec.myarray[j] < this.myarray[i]) {
j++;
......@@ -551,13 +540,13 @@ public final class VecInt implements IVecInt {
* @author sroussel
*/
public IVecInt[] subset(int cardinal) {
List<IVecInt> liste = new ArrayList<IVecInt>();
List<IVecInt> liste = new ArrayList<>();
IVecInt[] result;
if (cardinal == 1) {
result = new VecInt[this.size()];
for (int i = 0; i < this.size(); i++) {
for (var i = 0; i < this.size(); i++) {
result[i] = new VecInt(new int[] { this.get(i) });
}
return result;
......@@ -568,7 +557,7 @@ public final class VecInt implements IVecInt {
return result;
}
VecInt subVec = new VecInt();
var subVec = new VecInt();
VecInt newVec;
this.copyTo(subVec);
subVec.remove(this.get(0));
......@@ -585,7 +574,7 @@ public final class VecInt implements IVecInt {
}
result = new VecInt[liste.size()];
for (int i = 0; i < liste.size(); i++) {
for (var i = 0; i < liste.size(); i++) {
result[i] = liste.get(i);
}
return result;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment