class Persons {
final String name;
final String age;
Persons(
this.name,
this.age,
);
void printName() {
print(name);
}
}
class Players extends Persons {}
enter image description here
Edit the class Players
class Players extends Persons {
Players(name, age): super(name, age);
}
Related
How to change this constructor so that the link would be _host + link ?
class Profile {
static final String _host = 'http://github.com';
Profile(this.link, this.id, this.photo);
final link;
final id;
final photo;
#override
String toString() {
return '$link, $id, $photo';
}
}
You can't since writting this.link is equivalent to writing the following class:
class Profile {
static final String _host = 'http://github.com';
Profile(String link, this.id, this.photo) :
this.link = link;
final link;
final id;
final photo;
#override
String toString() {
return '$link, $id, $photo';
}
}
And link being final, you can't assign it to any other value. Your best option here you be to do somthing like this:
class Profile {
static final String _host = 'http://github.com';
Profile(String path, this.id, this.photo) :
link = _host + path;
final link;
final id;
final photo;
#override
String toString() {
return '$link, $id, $photo';
}
}
I saw exmaple code something like:
class ModelBinding extends StatefulWidget {
ModelBinding({
Key key,
this.initialModel = const GalleryOptions(),
this.child,
}) : assert(initialModel != null),
super(key: key);
...
so I wrote something:
class Person {
String firstName;
Person({name}){
print(name);
}
}
class Employee extends Person {
Employee(String name) : assert(false), super(name: name);
}
main() {
var emp = new Employee('Jason');
}
No matter if it is assert(false) or assert(true), the result is same.
So what is the meaning of assert?
assert is used for debugging and it simply means the condition should be true to proceed. Let me explain:
class MyClass {
final int age;
MyClass({this.age});
void someMethod() {
// using `age` here
}
}
You might face issues in someMethod if age passed is null, so to make sure it isn't null, you use assert like:
class MyClass {
final int age;
MyClass({this.age}) : assert(age != null, "Make sure age isn't null");
void someMethod() {
// using `age` here
}
}
I'm trying to export an Excel corresponding to a FilterTable using Vaadin TableExport. That Filtertable has some columns storing Dates and other class type elements, so I'm using setConverter function to print them as specific Strings:
filerTable.setConverter("dateColumn", dateConverter);
filerTable.setConverter("myClassColumn", myClassConverter);
dateConverter and myClassConverter are instances of some classes to print that column values as Strings.
The problem comes when I want to export the table as an Excel: That setConverter conversions are not being applied to the output file. For example, date cells are being exported as string ('42741,0080787037' instead of '06/01/17 0:11'). The code section to export the Excel file is:
ExcelExport exp = new ExcelExport(new CustomTableHolder(filerTable), "excel.xls");
exp.setRowHeaders(true);
exp.export();
Is there any way to export the table exactly as shown, having applied setConverter function?
Looking at the add-on sources, it seems that this feature is supported but 2 things have to happen in order for it to work:
you have to use a PropertyFormatTable (nothing fancy, just a wrapper over table for this custom purpose)
set the setUseTableFormatPropertyValue(true) on the ExcelExport
Code:
public class ExcelExportTableComponent extends VerticalLayout {
public ExcelExportTableComponent() {
// basic table configuration
Table table = new PropertyFormatTable();
BeanItemContainer<Person> itemContainer = new BeanItemContainer<>(Person.class);
table.setContainerDataSource(itemContainer);
table.setConverter("age", new AgeConverter());
// add some dummy data to the table
Random random = new Random();
for (int i = 0; i < 10; i++) {
itemContainer.addItem(new Person("Name " + i, "Surname " + i, random.nextInt(99) + 1));
}
// add components to the layout
addComponent(table);
addComponent(new Button("Export to excel", event -> {
ExcelExport excelExport = new ExcelExport(table);
excelExport.setUseTableFormatPropertyValue(true);
excelExport.excludeCollapsedColumns();
excelExport.setReportTitle("Demo Report");
excelExport.export();
}));
}
// basic bean for data binding
public static class Person {
private String name;
private String surname;
private int age;
public Person(String name, String surname, int age) {
this.name = name;
this.surname = surname;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
// custom converter
private static class AgeConverter implements Converter<String, Integer> {
#Override
public Integer convertToModel(String value, Class<? extends Integer> targetType, Locale locale) throws ConversionException {
return Integer.valueOf(value.substring(0, value.indexOf(" years")));
}
#Override
public String convertToPresentation(Integer value, Class<? extends String> targetType, Locale locale) throws ConversionException {
return String.valueOf(value) + " years";
}
#Override
public Class<Integer> getModelType() {
return Integer.class;
}
#Override
public Class<String> getPresentationType() {
return String.class;
}
}
}
Output:
I am running into an issue wherein some of my Neo4J queries like the one below ends up in an OGM AmbiguousBaseClassException while others don't. For example findByTitle for the movie "The Score" throws an exception but "The Matrix" does not. My graph is populated by the Movie Database found at https://neo4j.com/developer/example-data/
I am unable to find an explanation to the above observation and I hope someone can help.
curl http://localhost:8080/movies/search/findByTitle?title=The%20Score
Neo4j Server: 3.1.0
Spring-data-neo4j:4.1.1
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.neo4j.ogm.exception.MappingException: Error mapping GraphModel to instance of com.knowledgeGraph.kgClient.domain.Movie
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
Caused by: org.neo4j.ogm.exception.AmbiguousBaseClassException: Multiple classes found in type hierarchy that map to: [Person, Actor, Director]
at org.neo4j.ogm.MetaData.resolve(MetaData.java:174) ~[neo4j-ogm-core-2.0.1.jar:na]
at org.neo4j.ogm.annotations.EntityFactory.resolve(EntityFactory.java:121) ~[neo4j-ogm-core-2.0.1.jar:na]
at org.neo4j.ogm.annotations.EntityFactory.instantiateObjectFromTaxa(EntityFactory.java:105) ~[neo4j-ogm-core-2.0.1.jar:na]
at org.neo4j.ogm.annotations.EntityFactory.newObject(EntityFactory.java:61) ~[neo4j-ogm-core-2.0.1.jar:na]
Domain Objects:
Movie Class:
import static org.neo4j.graphdb.Direction.INCOMING;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
#JsonIdentityInfo(generator=JSOGGenerator.class)
#NodeEntity
#JsonIgnoreProperties(ignoreUnknown = true)
public class Movie {
#GraphId Long nodeId;
String id;
String title;
String description;
#Relationship(type="DIRECTED", direction = Relationship.INCOMING)
List<Person> directors;
#Relationship(type="ACTS_IN", direction = Relationship.INCOMING)
List<Person> actors;
private String language;
private String imdbId;
private String tagline;
private String releaseDate;
private Integer runtime;
private String homepage;
private String trailer;
private String genre;
private String studio;
private Integer version;
private String lastModified;
private String imageUrl;
public Movie() { }
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/*Remaining Set's and Get's*/
}
Person Class:
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import com.fasterxml.jackson.annotation.JsonSubTypes;
#NodeEntity
#JsonSubTypes({
#JsonSubTypes.Type(value = Actor.class, name = "actor"),
#JsonSubTypes.Type(value = Director.class, name = "director")
})
public class Person {
#GraphId Long nodeId;
String id;
String name;
private String birthday;
private String birthplace;
private String biography;
private Integer version;
private String lastModified;
private String profileImageUrl;
public Person () {}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/*Remaining Set's and Get's*/
}
Director Class:
#NodeEntity
public class Director extends Person{
#GraphId
Long id;
public Director() {
}
#Relationship(type="DIRECTED", direction = Relationship.OUTGOING)
private List<Movie> directedMovies = new ArrayList<Movie>();
public List<Movie> getDirectedMovies() {
return directedMovies;
}
public void setDirectedMovies(List<Movie> directedMovies) {
this.directedMovies = directedMovies;
}
}
Actor Class:
#NodeEntity
public class Actor extends Person {
#GraphId
Long id;
public Actor() {
}
#Relationship(type="ACTS_IN", direction = Relationship.OUTGOING)
private List<Movie> actedMovies = new ArrayList<Movie>();
public List<Movie> getMovies() {
return actedMovies;
}
public void setMovies(List<Movie> movies) {
this.actedMovies = movies;
}
}
Repositories:
public interface ActorRepository extends GraphRepository<Actor>{
#Query("MATCH (a:Actor) -[:ACTS_IN]-> (m:Movie {`title`:{title}}) return a")
Collection<Actor> findActorsOfMovie(#Param("title") String title);
}
public interface DirectorRepository extends GraphRepository<Director>{
#Query("MATCH (d:Director) -[:DIRECTED]-> (m:Movie {`title`:{title}}) return d")
Collection<Director> findDirectorOfMovie(#Param("title") String title);
}
public interface MovieRepository extends GraphRepository<Movie>{
Movie findByTitle(#Param("title") String title);
#Query("MATCH (m:Movie) WHERE m.title =~ ('(?i).*'+{title}+'.*') RETURN m")
Collection<Movie> findByTitleContaining(#Param("title") String title);
}
public interface PersonRepository extends GraphRepository<Person>{
#Query("MATCH (a:Person) -[:ACTS_IN]-> (m:Movie {`title`:{title}}) return a")
Set<Person> findActorsOfMovie(#Param("title") String title);
#Query("MATCH (d:Person) -[:DIRECTED]-> (m:Movie {`title`:{title}}) return d")
Set<Person> findDirectorOfMovie(#Param("title") String title);
}
Resolved this problem by removing Actor and Director domain classes and used Person class with Actor list and director list.
I'm programming an application Web (Semantic Web) and for storing the triples, using sesame, and for mapping of data alibaba. My question is, that way I have to implement the classes,to that at the base of triplets is store an object as a subclass of another , try interfaces but I got no results , below I present the "entities":
the parent class:
import java.math.BigInteger;
import org.openrdf.annotations.Iri;
#Iri(Parent.NS + "Parent")
public interface Parent {
public static final String NS = "http://www.spelta.ec/ontology/example#";
#Iri(Parent.NS +"code")
BigInteger getCode();
#Iri(Parent.NS +"code")
void setCode(BigInteger code);
#Iri(Parent.NS+"description")
String getDescription();
#Iri(Parent.NS+"description")
void setDescription(String description);
}
The child class:
import java.math.BigInteger;
public class Child implements Parent {
private BigInteger code;
private String description;
#Override
public BigInteger getCode() {
return code;
}
#Override
public void setCode(BigInteger code) {
this.code = code;
}
#Override
public String getDescription() {
return description;
}
#Override
public void setDescription(String description) {
this.description = description;
}
}
to consult the store of triples, should define an instance of the Children class is a subclass of Parent
many thanks