Skip to content

Commit

Permalink
Sonar QUBE checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rportela committed Jan 4, 2019
1 parent ab19036 commit 263139d
Show file tree
Hide file tree
Showing 26 changed files with 192 additions and 103 deletions.
2 changes: 1 addition & 1 deletion jetfuel-core/src/main/java/com/eixox/StreamCopy.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final void execute() {
for (int r = input.read(buffer); r >= 0; r = input.read(buffer))
output.write(buffer, 0, r);
} catch (Exception ex) {
throw new RuntimeException(ex);
throw new JetfuelException(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ public class Base64Adapter extends ByteArrayAdapter {
*/
@Override
public String format(byte[] source) {
if (source == null)
if (source == null || source.length == 0)
return null;
else if (source.length == 0)
return "";
else {
byte[] data = new byte[source.length + 2];
System.arraycopy(source, 0, data, 0, source.length);
Expand Down
12 changes: 7 additions & 5 deletions jetfuel-core/src/main/java/com/eixox/adapters/NumberAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.text.ParseException;
import java.util.Date;

import com.eixox.JetfuelException;

/**
* An adapter for Number objects;
*
Expand All @@ -18,7 +20,7 @@ public class NumberAdapter extends Adapter<Number> {
/**
* Gets the number format used by this adapter;
*/
public final NumberFormat format;
public final NumberFormat formatter;

/**
* Creates a new number adapter;
Expand All @@ -27,7 +29,7 @@ public class NumberAdapter extends Adapter<Number> {
*/
public NumberAdapter(NumberFormat format) {
super(Number.class);
this.format = format;
this.formatter = format;
}

/**
Expand Down Expand Up @@ -56,9 +58,9 @@ public Number parse(String source) {
try {
return source == null || source.isEmpty()
? whenNull()
: this.format.parse(source);
: this.formatter.parse(source);
} catch (ParseException e) {
throw new RuntimeException(e);
throw new JetfuelException(e);
}
}

Expand All @@ -69,7 +71,7 @@ public Number parse(String source) {
public String format(Number source) {
return source == null
? ""
: this.format.format(source);
: this.formatter.format(source);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import java.util.UUID;

import com.eixox.JetfuelException;

public class UUIDBase36Adapter extends UUIDAdapter {

@Override
public UUID parse(String source) {
if (source == null || source.isEmpty())
return null;

throw new RuntimeException("Not implemented");
throw new JetfuelException("Not implemented");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.w3c.dom.Node;
import org.xml.sax.InputSource;

import com.eixox.JetfuelException;

/**
* A generic adapter for xml documents;
*
Expand Down Expand Up @@ -84,7 +86,7 @@ public Document convertInputStream(InputStream is) {
try {
return builderFactory.newDocumentBuilder().parse(is);
} catch (Exception e) {
throw new RuntimeException(e);
throw new JetfuelException(e);
}
}

Expand All @@ -98,7 +100,7 @@ public Document convertFile(File file) {
try {
return builderFactory.newDocumentBuilder().parse(file);
} catch (Exception e) {
throw new RuntimeException(e);
throw new JetfuelException(e);
}
}

Expand All @@ -112,7 +114,7 @@ public Document convertURI(String uri) {
try {
return builderFactory.newDocumentBuilder().parse(uri);
} catch (Exception e) {
throw new RuntimeException(e);
throw new JetfuelException(e);
}
}

Expand All @@ -126,7 +128,7 @@ public Document convertInputSource(InputSource is) {
try {
return builderFactory.newDocumentBuilder().parse(is);
} catch (Exception e) {
throw new RuntimeException(e);
throw new JetfuelException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class TableColumn implements Column {
public final String columnName;
public final int columnOrdinal;
public final Class<?> dataType;
public boolean isIdentity;
public boolean isUnique;
public boolean isCompositeKey;
public boolean isReadOnly;
private boolean isIdentity;
private boolean isUnique;
private boolean isCompositeKey;
private boolean isReadOnly;

protected TableColumn(Table table, String name, Class<?> dataType, int ordinal) {
this.table = table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ public int indexOf(String name) {

public TableColumn getIdentity() {
for (TableColumn col : this)
if (col.isIdentity)
if (col.isIdentity())
return col;
return null;
}

public List<TableColumn> getUniqueColumns() {
List<TableColumn> uniques = new LinkedList<>();
for (TableColumn col : this)
if (col.isUnique)
if (col.isUnique())
uniques.add(col);
return uniques;
}

public List<TableColumn> getCompositeKeys() {
List<TableColumn> composites = new LinkedList<>();
for (TableColumn col : this)
if (col.isCompositeKey)
if (col.isCompositeKey())
composites.add(col);
return composites;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.eixox.data.common;

import java.util.Iterator;
import java.util.NoSuchElementException;

public class TableRow implements Iterable<Object> {

Expand All @@ -17,6 +18,8 @@ public final Iterator<Object> iterator() {
public int ordinal = 0;

public Object next() {
if (ordinal >= cells.length)
throw new NoSuchElementException();
Object o = cells[ordinal];
ordinal++;
return o;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.eixox.data.common;

import java.util.Iterator;
import java.util.NoSuchElementException;

import com.eixox.data.Filter;

Expand All @@ -10,8 +11,8 @@ public class TableRowIterator implements Iterator<TableRow> {
public final Filter filter;
public final int start_position;
public final int end_position;
private int current_position;
private TableRow current_row;
private int currentPosition;
private TableRow currentRow;

public TableRowIterator(Table source, Filter filter, int offset, int limit) {
this.source = source;
Expand All @@ -20,28 +21,31 @@ public TableRowIterator(Table source, Filter filter, int offset, int limit) {
this.end_position = limit > 0
? offset + limit
: source.rows.size();
this.current_position = offset;
this.currentPosition = offset;

}

public boolean hasNext() {
this.current_row = null;
if (current_position >= end_position || current_position >= source.rows.size())
this.currentRow = null;
if (currentPosition >= end_position || currentPosition >= source.rows.size())
return false;

TableRow r = source.rows.get(current_position);
current_position++;
TableRow r = source.rows.get(currentPosition);
currentPosition++;

if (filter != null && !filter.testRow(r.cells))
return hasNext();

current_row = r;
currentRow = r;
return true;

}

public TableRow next() {
return current_row;
if (currentRow == null)
throw new NoSuchElementException();
else
return currentRow;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.eixox.data.entities;

import java.util.Iterator;
import java.util.NoSuchElementException;

import com.eixox.data.Filter;

Expand Down Expand Up @@ -41,7 +42,10 @@ public boolean hasNext() {
}

public T next() {
return this.currentValue;
if (this.currentValue == null)
throw new NoSuchElementException();
else
return this.currentValue;
}

}
12 changes: 10 additions & 2 deletions jetfuel-core/src/main/java/com/eixox/data/schema/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ public class Schema extends ArrayList<SchemaItem> {
*/
private static final long serialVersionUID = -7031068396058238241L;
public String name;



@Override
public boolean equals(Object o) {
return super.equals(o);
}

@Override
public int hashCode() {
return super.hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@ public final DatabaseCommand appendValue(Object value) {
return appendString(value.toString());
if (value instanceof Character)
return appendString(value.toString());

throw new JetfuelException("Can't serialize to SQL: " + value.getClass());
else
throw new JetfuelException("Can't serialize to SQL: " + value.getClass());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public synchronized String format(T entity) {
FixedLengthAspectField field = get(i);
String val = field.getFormattedValue(entity);
int l = Math.min(val.length(), field.end - field.start);
for (int j = 0; i < l; i++)
for (int j = 0; j < l; j++)
line_buffer[field.start + j] = val.charAt(j);
}

Expand Down
23 changes: 22 additions & 1 deletion jetfuel-core/src/main/java/com/eixox/data/text/TextReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.NoSuchElementException;

import com.eixox.data.Filter;

Expand Down Expand Up @@ -128,14 +129,34 @@ else if (filter != null && !filter.testEntity(current))
/**
* Returns this guy as an iterator;
*/
@SuppressWarnings("resource")
public Iterator<T> iterator() {
return this;

TextReader<T> i = this;

return new Iterator<T>() {
final TextReader<T> instance = i;

@Override
public boolean hasNext() {
return instance.hasNext();
}

@Override
public T next() {
return instance.next();
}
};
}

/**
* Gets the next value from this iterator;
*/
public T next() {

if (this.line_number > -1 && this.current == null) {
throw new NoSuchElementException("This iterator has no more elements");
}
return this.current;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ else if (input instanceof String) {
else
return isValid(Long.parseLong(is))
? new RestrictionResult(true, "")
: new RestrictionResult(false, "N�o � um CPF ou CNPJ v�lido.");
: new RestrictionResult(false, "Não é um CPF ou CNPJ válido.");
} else if (input instanceof Number) {
return isValid(((Number) input).longValue())
? new RestrictionResult(true, "")
: new RestrictionResult(false, "N�o � um CPF ou CNPJ v�lido.");
: new RestrictionResult(false, "Não é um CPF ou CNPJ válido.");
} else {
return new RestrictionResult(false, "N�o foi poss�vel converter para um CPF ou CNPJ.");
return new RestrictionResult(false, "Não foi possível converter para um CPF ou CNPJ.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ public RestrictionResult validate(Object input) {
return Array.getLength(input) <= value
? new RestrictionResult(true, "")
: new RestrictionResult(false, "O número máximo de elementos é " + this.value);
} else
} else {
return new RestrictionResult(false, "Não foi possível determinar a contagem de " + input.getClass());
}

}

@Override
public String toString() {
return "MaxCount(" + this.value + ")";
Expand Down
Loading

0 comments on commit 263139d

Please sign in to comment.