Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Jan 13, 2016
1 parent ea3bd83 commit 8dd25e0
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 73 deletions.
Expand Up @@ -26,8 +26,8 @@
/**
* This class is a pluggable factory that produces
* {@link DbmsHandler DbmsHandlers} for a given Dbms. The DbmsHandler is
* obtained via the {@link #get(com.speedment.config.Dbms) } method and if an
* existing DbmsHandler can not be found, the {@link #make(com.speedment.config.Dbms)
* obtained via the {@link #get(com.speedment.config.db.Dbms) } method and if an
* existing DbmsHandler can not be found, the {@link #make(com.speedment.config.db.Dbms)
* } method is called to provide a new instance.
*
* @author pemi
Expand All @@ -38,10 +38,10 @@ public interface DbmsHandlerComponent extends Component {

/**
* Installs a new {@link DbmsType} so that handlers can be created using the
* {@link #make(com.speedment.config.Dbms) } method.
* {@link #make(com.speedment.config.db.Dbms) } method.
* <p>
* The type will be indexed by its name as returned by
* {@link DbmsType#getName()}. If multiple {@code DbmsTypes} share name,
* {@link DbmsType#getName() }. If multiple {@code DbmsTypes} share name,
* only the most recently installed will be saved.
*
* @param dbmsType the type to install
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/com/speedment/config/Document.java
Expand Up @@ -20,6 +20,8 @@
import com.speedment.annotation.Api;
import com.speedment.util.OptionalBoolean;
import com.speedment.stream.MapStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -40,7 +42,7 @@ public interface Document {
* Returns the parent of this Document or {@link Optional#empty()} if the
* Document does not have a parent.
*
* @return
* @return the parent
*/
Optional<? extends Document> getParent();

Expand Down Expand Up @@ -74,21 +76,22 @@ default <P extends Document, T extends Document> Stream<T> children(
if (list == null) {
return Stream.empty();
} else {
return list.stream().map(map -> constructor.apply((P) this, map));
@SuppressWarnings("unchecked")
final P thizz = (P)this;
return list.stream().map(map -> constructor.apply(thizz, map));
}
}

Stream<? extends Document> children();

default Stream<Document> ancestors() {
final Stream.Builder<Document> stream = Stream.builder();
final List<Document> ancestors = new ArrayList<>();
Document parent = this;

while ((parent = parent.getParent().orElse(null)) != null) {
stream.add(parent);
ancestors.add(parent);
}

return stream.build();
Collections.reverse(ancestors);
return ancestors.stream();
}

@SuppressWarnings("unchecked")
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/speedment/config/db/ForeignKeyColumn.java
Expand Up @@ -73,8 +73,9 @@ default String getForeignColumnName() {
* @return the foreign {@link Table} referenced by this
*/
default Table findForeignTable() throws SpeedmentException {
final Schema schema = (Schema) ancestors()
.filter(doc -> Schema.class.isAssignableFrom(doc.getClass()))
final Schema schema = ancestors()
.filter(Schema.class::isInstance)
.map(Schema.class::cast)
.findFirst()
.orElseThrow(() -> new SpeedmentException(
"A foreign key in the config tree references a table that "
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/com/speedment/config/db/trait/HasColumn.java
Expand Up @@ -27,21 +27,22 @@
*/
@Api(version = "2.3")
public interface HasColumn extends Document, HasName {

default Column findColumn() {
final Table table = (Table) ancestors()
.filter(doc -> Table.class.isAssignableFrom(doc.getClass()))
.findFirst()
.orElseThrow(() -> new IllegalStateException(
"A node in the config tree that references a column is" +
"not located inside a table node."
));

final Table table = ancestors()
.filter(Table.class::isInstance)
.map(Table.class::cast)
.findFirst()
.orElseThrow(() -> new IllegalStateException(
"A node in the config tree that references a column is"
+ "not located inside a table node."
));

return table.columns()
.filter(col -> col.getName().equals(getName()))
.findAny()
.orElseThrow(() -> new IllegalStateException(
"A non-existing column '" + getName() + "' was referenced."
));
.filter(col -> col.getName().equals(getName()))
.findAny()
.orElseThrow(() -> new IllegalStateException(
"A non-existing column '" + getName() + "' was referenced."
));
}
}
}
18 changes: 17 additions & 1 deletion src/main/java/com/speedment/internal/core/code/Translator.java
Expand Up @@ -46,6 +46,22 @@
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;

/**
* A component that can translate a {@link Node} into something else. This
Expand Down Expand Up @@ -184,7 +200,7 @@ default <E extends Document> E getGenericConfigEntity(Class<E> clazz) {
return getNode()
//.ancestor(clazz)
.ancestors()
.filter(d -> clazz.isAssignableFrom(d.getClass()))
.filter(clazz::isInstance)
.map(clazz::cast)
.findAny()
.orElseThrow(() -> new IllegalStateException(
Expand Down
Expand Up @@ -32,6 +32,7 @@ public AbstractChildDocument(PARENT parent, Map<String, Object> data) {
super(parent, data);
}

@SuppressWarnings("unchecked")
@Override
public Optional<PARENT> getParent() {
return (Optional<PARENT>) super.getParent();
Expand Down
Expand Up @@ -29,7 +29,7 @@
*/
public final class SchemaImpl extends AbstractChildDocument<Dbms> implements Schema {

public SchemaImpl(Dbms parent, Map data) {
public SchemaImpl(Dbms parent, Map<String, Object> data) {
super(parent, data);
}

Expand Down
Expand Up @@ -27,20 +27,21 @@
import java.util.function.BiFunction;
import static java.util.stream.Collectors.toList;
import java.util.stream.Stream;
import java.util.function.Function;

/**
*
* @author Emil Forslund
*/
public class ImmutableDocument extends BaseDocument {

private final transient Map<String, List<Document>> children;

protected ImmutableDocument(Map<String, Object> data) {
super(Collections.unmodifiableMap(data));
children = new ConcurrentHashMap<>();
}

protected ImmutableDocument(ImmutableDocument parent, Map<String, Object> data) {
super(parent, Collections.unmodifiableMap(data));
children = new ConcurrentHashMap<>();
Expand All @@ -58,23 +59,28 @@ public final void put(String key, Object value) {

@Override
public <P extends Document, T extends Document> Stream<T> children(String key, BiFunction<P, Map<String, Object>, T> constructor) {

@SuppressWarnings("unchecked")
final Function<Document, T> typeMapper = d -> (T) d;

return children.computeIfAbsent(key, k -> {
final List<Map<String, Object>> list =
(List<Map<String, Object>>) get(k).orElse(null);
final List<Map<String, Object>> list = get(k).map(DOCUMENT_LIST_TYPE::cast).orElse(null);

if (list == null) {
return new ArrayList<>();
} else {
@SuppressWarnings("unchecked")
final P thizz = (P) this;
return list.stream()
.map(Collections::unmodifiableMap)
.map(data -> constructor.apply((P) this, data))
.map(Document.class::cast)
.collect(toList());
.map(Collections::unmodifiableMap)
.map(data -> constructor.apply(thizz, data))
.map(Document.class::cast)
.collect(toList());
}
}).stream().map(c -> (T) c);
}).stream().map(typeMapper);
}

public static ImmutableDocument wrap(Document document) {
return new ImmutableDocument(document.getData());
}
}
}
Expand Up @@ -42,7 +42,7 @@ public void setAutoIncrement(Boolean autoIncrement) {
put(AUTO_INCREMENT, autoIncrement);
}

public void setTypeMapper(TypeMapper typeMapper) {
public void setTypeMapper(TypeMapper<?, ?> typeMapper) {
put(TYPE_MAPPER, typeMapper.getClass().getName());
}

Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.speedment.config.Document;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;

/**
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/speedment/internal/ui/UISession.java
Expand Up @@ -237,7 +237,7 @@ public <T extends Event, E extends EventHandler<T>> E reload() {

if (schemaName.isPresent()) {
project.dbmses()
.map(dbms -> (DbmsProperty) dbms)
.map(DbmsProperty.class::cast)
.forEach(dbms -> loadFromDatabase(dbms, schemaName.get()));
} else {
showError(
Expand Down
Expand Up @@ -19,7 +19,6 @@
import com.speedment.config.Document;
import com.speedment.exception.SpeedmentException;
import com.speedment.internal.ui.config.trait.HasExpandedProperty;
import com.speedment.stream.MapStream;
import com.speedment.util.OptionalBoolean;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -52,12 +51,12 @@
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue;
import static javafx.collections.FXCollections.observableList;
import static javafx.collections.FXCollections.observableMap;
import javafx.collections.ListChangeListener;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import static javafx.collections.FXCollections.observableList;

/**
*
Expand All @@ -77,7 +76,7 @@ public abstract class AbstractDocumentProperty implements DocumentProperty, HasE
/**
* An internal map of the properties that have been created by this class.
* Two different properties must never be returned for the same key. A
* property in this map must be configered to listen for changes in the
* property in this map must be configured to listen for changes in the
* raw map before being inserted into the map.
*/
private final transient Map<String, Property<?>> properties;
Expand Down Expand Up @@ -136,7 +135,7 @@ protected AbstractDocumentProperty(Map<String, Object> data) {
if (l == null) {
final List<DocumentProperty> children = addedList.stream()
.filter(Map.class::isInstance)
.map(obj -> (Map<String, Object>) obj)
.map(DOCUMENT_TYPE::cast)
.map(obj -> createDocument(change.getKey(), obj))
.collect(toList());

Expand All @@ -153,7 +152,7 @@ protected AbstractDocumentProperty(Map<String, Object> data) {
} else {
addedList.stream()
.filter(Map.class::isInstance)
.map(obj -> (Map<String, Object>) obj)
.map(DOCUMENT_TYPE::cast)
.map(obj -> createDocument(change.getKey(), obj))
.forEachOrdered(l::add);
}
Expand Down Expand Up @@ -186,7 +185,7 @@ protected AbstractDocumentProperty(Map<String, Object> data) {
} else if (added instanceof Double) {
newProperty = new SimpleDoubleProperty((Double) added);
} else {
newProperty = new SimpleObjectProperty(added);
newProperty = new SimpleObjectProperty<>(added);
}

properties.put(change.getKey(), newProperty);
Expand Down Expand Up @@ -266,6 +265,7 @@ public final BooleanProperty booleanPropertyOf(String key, BooleanSupplier ifEmp
return (BooleanProperty) properties.computeIfAbsent(key, k -> prepare(k, new SimpleBooleanProperty(getAsBoolean(k).orElse(ifEmpty.getAsBoolean()))));
}

@SuppressWarnings("unchecked")
@Override
public final <T> ObjectProperty<T> objectPropertyOf(String key, Class<T> type, Supplier<T> ifEmpty) {
return (ObjectProperty<T>) properties.computeIfAbsent(key, k -> prepare(k, new SimpleObjectProperty<>(type.cast(get(k).orElseGet(ifEmpty)))));
Expand Down Expand Up @@ -295,7 +295,7 @@ public final <P extends DocumentProperty, T extends DocumentProperty> Observable
return monitor.runWithoutGeneratingEvents(() -> {
try {
@SuppressWarnings("unchecked")
final List<T> existing = ((List<Map<String, Object>>) config.computeIfAbsent(key, k -> new CopyOnWriteArrayList<>()))
final List<T> existing = DOCUMENT_LIST_TYPE.cast(config.computeIfAbsent(key, k -> new CopyOnWriteArrayList<>()))
.stream().map(child -> constructor.apply((P) this, child))
.collect(toList());

Expand Down Expand Up @@ -325,11 +325,11 @@ protected DocumentProperty createDocument(String key, Map<String, Object> data)
@Override
public final Stream<DocumentProperty> children() {
return stream()
.filterValue(obj -> obj instanceof List<?>)
.filterValue(List.class::isInstance)
.mapValue(list -> (List<Object>) list)
.flatMapValue(list -> list.stream())
.filterValue(obj -> obj instanceof Map<?, ?>)
.mapValue(map -> (Map<String, Object>) map)
.mapValue(DOCUMENT_TYPE::cast)
.mapValue((key, value) -> createDocument(key, value))
.values();
}
Expand All @@ -351,8 +351,7 @@ private <T extends DocumentProperty> ObservableList<T> prepareListOnKey(String k
list.addListener((ListChangeListener.Change<? extends T> change) -> {
monitor.runWithoutGeneratingEvents(() -> {
@SuppressWarnings("unchecked")
final List<Map<String, Object>> rawList =
(List<Map<String, Object>>) config.get(key);
final List<Map<String, Object>> rawList = DOCUMENT_LIST_TYPE.cast(config.get(key));

while (change.next()) {
if (change.wasAdded()) {
Expand Down
Expand Up @@ -38,7 +38,7 @@
public final class SchemaProperty extends AbstractChildDocumentProperty<Dbms>
implements Schema, HasEnabledProperty, HasNameProperty, HasAliasProperty {

public SchemaProperty(Dbms parent, Map data) {
public SchemaProperty(Dbms parent, Map<String, Object> data) {
super(parent, data);
}

Expand Down
Expand Up @@ -37,7 +37,7 @@ public interface HasOrderTypeProperty extends DocumentProperty, HasOrderType {
default ObjectProperty<OrderType> orderTypeProperty() {
final String defaultValue = HasOrderType.super.getOrderType().name();
final StringProperty strProperty = stringPropertyOf(HasOrderType.ORDER_TYPE, () -> defaultValue);
final ObjectProperty<OrderType> objProperty = new SimpleObjectProperty(OrderType.valueOf(defaultValue));
final ObjectProperty<OrderType> objProperty = new SimpleObjectProperty<>(OrderType.valueOf(defaultValue));

strProperty.bindBidirectional(objProperty, new StringConverter<OrderType>() {
@Override
Expand Down
Expand Up @@ -108,11 +108,11 @@ private <P extends DocumentProperty & HasExpandedProperty> TreeItem<DocumentProp

final TreeItem<DocumentProperty> branch = new TreeItem<>(doc);
branch.expandedProperty().bindBidirectional(doc.expandedProperty());

doc.children()
.filter(d -> d instanceof DocumentProperty)
.filter(d -> d instanceof HasExpandedProperty)
.map(d -> (P) d)
.filter(DocumentProperty.class::isInstance)
.filter(HasExpandedProperty.class::isInstance)
.map(d -> (DocumentProperty & HasExpandedProperty) d)
.map(this::branch)
.forEachOrdered(branch.getChildren()::add);

Expand Down

0 comments on commit 8dd25e0

Please sign in to comment.