From d98c043f247d1c03e8ca4dea472e08552d84ff97 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Wed, 6 Jul 2016 15:00:49 +0200 Subject: [PATCH] Fixed javac/ejc generics issues --- .../jooq/impl/DefaultConverterProvider.java | 202 +----------------- .../src/main/java/org/jooq/tools/Convert.java | 10 +- 2 files changed, 9 insertions(+), 203 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultConverterProvider.java b/jOOQ/src/main/java/org/jooq/impl/DefaultConverterProvider.java index 1ebfd7d789..38a7a7bb2c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultConverterProvider.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultConverterProvider.java @@ -40,24 +40,8 @@ */ package org.jooq.impl; -import static org.jooq.Converters.inverse; -import static org.jooq.impl.Tools.EMPTY_CLASS; -import static org.jooq.tools.StringUtils.rightPad; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - import org.jooq.Converter; import org.jooq.ConverterProvider; -import org.jooq.Converters; /** * @author Lukas Eder @@ -65,192 +49,8 @@ import org.jooq.Converters; */ @Deprecated public class DefaultConverterProvider implements ConverterProvider { - - final Graph graph = new Graph(); - - @SuppressWarnings("unchecked") @Override public Converter provide(Class tType, Class uType) { - if (tType == uType) - return (Converter) Converters.identity(tType); - else - return graph.get(new Endpoints(tType, uType)); - } - - public void add(Converter converter) { - graph.add(converter); - } - - @Override - public String toString() { - return graph.toString(); - } - - /** - * A graph modelling all the possible conversion paths. - */ - static class Graph { - - final Set> vertices; - final Map, Set>> adjacency; - final Map, Converter> paths; - - Graph() { - vertices = new HashSet>(); - adjacency = new HashMap, Set>>(); - paths = new ConcurrentHashMap, Converter>(); - } - - /** - * Get a converter for a pair of classes. - */ - @SuppressWarnings("unchecked") - Converter get(Endpoints classes) { - build(); - return (Converter) paths.get(classes); - } - - /** - * Add a Converter to the graph. - */ - void add(Converter converter) { - synchronized (paths) { - paths.clear(); - - Class t = converter.fromType(); - Class u = converter.toType(); - - vertices.add(t); - vertices.add(u); - - Set> tSet = adjacency.get(t); - if (tSet == null) { - tSet = new HashSet>(); - adjacency.put(t, tSet); - } - tSet.add(converter); - - Set> uSet = adjacency.get(u); - if (uSet == null) { - uSet = new HashSet>(); - adjacency.put(u, uSet); - } - uSet.add(inverse(converter)); - } - } - - /** - * Build the graph. - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - private void build() { - if (paths.isEmpty()) { - synchronized (paths) { - for (Entry, Set>> entry : adjacency.entrySet()) { - for (Converter converter : entry.getValue()) { - path(new Endpoints(converter.fromType(), converter.toType()), converter); - } - } - - int size; - do { - size = paths.size(); - - List> keys = new ArrayList>(paths.keySet()); - for (Endpoints key : keys) { - for (Converter converter : adjacency.get(key.toType)) { - path(new Endpoints(key.fromType, converter.toType()), Converters.of((Converter) paths.get(key), converter)); - } - } - } - while (size < paths.size()); - } - } - } - - /** - * Add a path configuration if there isn't already one for the given - * endpoints. - */ - private void path(Endpoints key, Converter converter) { - if (key.fromType != key.toType) - if (!paths.containsKey(key)) - paths.put(key, converter); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public String toString() { - build(); - - synchronized (paths) { - StringBuilder sb = new StringBuilder(); - - Class[] classes = vertices.toArray(EMPTY_CLASS); - Arrays.sort(classes, new Comparator>() { - @Override - public int compare(Class o1, Class o2) { - return o1.getName().compareTo(o2.getName()); - } - }); - - int maxLength = Integer.MIN_VALUE; - for (Class c : classes) - maxLength = Math.max(maxLength, c.getName().length()); - - String sep1 = ""; - for (Class c1 : classes) { - sb.append(sep1); - sb.append(rightPad(c1.getName(), maxLength)); - - for (Class c2 : classes) { - if (paths.containsKey(new Endpoints(c1, c2))) { - sb.append("\n -> ") - .append(c2.getName()); - } - } - - sep1 = "\n\n"; - } - - return sb.toString(); - } - } - } - - /** - * A type modelling two end points inside of a graph. - */ - static class Endpoints { - final Class fromType; - final Class toType; - - Endpoints(Class t, Class u) { - this.fromType = t; - this.toType = u; - } - - @Override - public int hashCode() { - return 17 * fromType.hashCode() + toType.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - - if (obj instanceof Endpoints) { - Endpoints that = (Endpoints) obj; - return fromType == that.fromType && toType == that.toType; - } - - return false; - } - - @Override - public String toString() { - return "(" + fromType.getName() + ", " + toType.getName() + ")"; - } + throw new UnsupportedOperationException(); } } diff --git a/jOOQ/src/main/java/org/jooq/tools/Convert.java b/jOOQ/src/main/java/org/jooq/tools/Convert.java index e5ef81e232..94c7f76548 100644 --- a/jOOQ/src/main/java/org/jooq/tools/Convert.java +++ b/jOOQ/src/main/java/org/jooq/tools/Convert.java @@ -304,8 +304,11 @@ public final class Convert { * @return The target type object * @throws DataTypeException - When the conversion is not possible */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public static final U convert(Object from, Converter converter) throws DataTypeException { - return convert0(from, converter); + + // Raw type cast necessary because of javac compiler bug in 1.8.0_74 (still used by travis) + return (U) convert0(from, (Converter) converter); } /** @@ -405,8 +408,11 @@ public final class Convert { * @throws DataTypeException - When the conversion is not possible * @see #convert(Object, Converter) */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public static final List convert(Collection collection, Converter converter) throws DataTypeException { - return convert0(collection, converter); + + // Raw type cast necessary because of javac compiler bug in 1.8.0_74 (still used by travis) + return convert0(collection, (Converter) converter); } /**