Not able to pass:
I was trying a whole bunch of different ways to return the string for the getQuery() method to see if any of them passed. I even tried removing 'abstract' from getQuery and typing in:
return "SELECT * FROM " + ((Class) ((ParameterizedType) this.getClass().
getGenericSuperclass()).getActualTypeArguments()[0]).getSimpleName().toUpperCase();
No matter what I do I can't pass the last 5 requirements, they all say the same thing (for the specific class) Each element of the list returned by the getUsers method must contain the string "Received from executing 'SELECT * FROM USER'" in the description field.
My output:
Id=1, name='User-1', description=Received from executing 'SELECT * FROM USER'
Id=2, name='User-2', description=Received from executing 'SELECT * FROM USER'
Id=3, name='User-3', description=Received from executing 'SELECT * FROM USER'
Id=4, name='User-4', description=Received from executing 'SELECT * FROM USER'
Id=5, name='User-5', description=Received from executing 'SELECT * FROM USER'
Id=1, name='Location-1', description=Received from executing 'SELECT * FROM LOCATION'
Id=2, name='Location-2', description=Received from executing 'SELECT * FROM LOCATION'
Id=3, name='Location-3', description=Received from executing 'SELECT * FROM LOCATION'
Id=4, name='Location-4', description=Received from executing 'SELECT * FROM LOCATION'
Id=5, name='Location-5', description=Received from executing 'SELECT * FROM LOCATION'
package com.codegym.task.task23.task2309;
import com.codegym.task.task23.task2309.vo.*;
import java.lang.reflect.ParameterizedType;
import java.util.AbstractList;
import java.util.List;
/*
Sometimes anonymity is so nice!
*/
public class Solution {
public static void main(String[] args) {
Solution solution = new Solution();
print(solution.getUsers());
print(solution.getLocations());
}
public static List<User> getUsers(){
return new AbstractDbSelectExecutor<User>(){
@Override
public String getQuery() {
return "SELECT * FROM USER";
}
}.execute();
}
public static List<Location> getLocations(){
return new AbstractDbSelectExecutor<Location>(){
@Override
public String getQuery() {
return "SELECT * FROM " + ((Class) ((ParameterizedType) this.getClass().
getGenericSuperclass()).getActualTypeArguments()[0]).getSimpleName().toUpperCase();
}
}.execute();
}
public static List<Server> getServers(){
return new AbstractDbSelectExecutor<Server>(){
@Override
public String getQuery() {
return "SELECT * FROM " + ((Class) ((ParameterizedType) this.getClass().
getGenericSuperclass()).getActualTypeArguments()[0]).getSimpleName().toUpperCase();
}
}.execute();
}
public static List<Subscription> getSubscriptions(){
return new AbstractDbSelectExecutor<Subscription>(){
@Override
public String getQuery() {
return "SELECT * FROM " + ((Class) ((ParameterizedType) this.getClass().
getGenericSuperclass()).getActualTypeArguments()[0]).getSimpleName().toUpperCase();
}
}.execute();
}
public static List<Subject> getSubjects(){
return new AbstractDbSelectExecutor<Subject>(){
@Override
public String getQuery() {
return "SELECT * FROM " + ((Class) ((ParameterizedType) this.getClass().
getGenericSuperclass()).getActualTypeArguments()[0]).getSimpleName().toUpperCase();
}
}.execute();
}
public static void print(List list) {
String format = "Id=%d, name='%s', description=%s";
for (Object obj : list) {
NamedItem item = (NamedItem) obj;
System.out.println(String.format(format, item.getId(), item.getName(), item.getDescription()));
}
}
}