repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
sudheerj/primefaces-blueprints | chapter07/src/test/java/com/pocketpub/pfbp/test/HibernateUtilTest.java | // Path: chapter09/src/main/java/com/packtpub/pf/blueprint/persistence/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter07/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Movie.java
// @Entity
// @Table
// @Data
// public class Movie {
//
// @Id
// @GeneratedValue
// private Long id;
//
// private String title;
//
// private String description;
//
// @Temporal(TemporalType.DATE)
// private Date releaseDate;
//
// private int rating;
//
// private boolean favorite;
//
// private String image;
//
// private boolean isImageUrl;
//
// private String movieUrl;
//
// private MovieType movieType;
//
// private boolean isPublic;
//
// @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
// @JoinTable(name = "MOVIE_TAGS",
// joinColumns = {@JoinColumn(name = "MOVIE_ID")},
// inverseJoinColumns = {@JoinColumn(name = "TAG_ID")})
// private Set<Tags> tags = new HashSet<>();
//
// @OneToMany(mappedBy = "movie", fetch = FetchType.LAZY)
// private Set<Comment> comments = new HashSet<>();
//
// @ManyToOne
// private User user;
//
//
// public void addToTags(Tags t){
// this.tags.add(t);
// }
//
//
// }
| import com.packtpub.pf.blueprint.persistence.HibernateUtil;
import com.packtpub.pf.blueprint.persistence.entity.Movie;
import org.hibernate.Session;
import java.util.List; | package com.pocketpub.pfbp.test;
/**
* Created with IntelliJ IDEA.
* User: psramkumar
* Date: 2/6/14
* Time: 7:44 PM
* To change this template use File | Settings | File Templates.
*/
public class HibernateUtilTest {
public static void main(String[] args) {
System.out.println("Testing Hibernate Utility Class");
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction(); | // Path: chapter09/src/main/java/com/packtpub/pf/blueprint/persistence/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter07/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Movie.java
// @Entity
// @Table
// @Data
// public class Movie {
//
// @Id
// @GeneratedValue
// private Long id;
//
// private String title;
//
// private String description;
//
// @Temporal(TemporalType.DATE)
// private Date releaseDate;
//
// private int rating;
//
// private boolean favorite;
//
// private String image;
//
// private boolean isImageUrl;
//
// private String movieUrl;
//
// private MovieType movieType;
//
// private boolean isPublic;
//
// @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
// @JoinTable(name = "MOVIE_TAGS",
// joinColumns = {@JoinColumn(name = "MOVIE_ID")},
// inverseJoinColumns = {@JoinColumn(name = "TAG_ID")})
// private Set<Tags> tags = new HashSet<>();
//
// @OneToMany(mappedBy = "movie", fetch = FetchType.LAZY)
// private Set<Comment> comments = new HashSet<>();
//
// @ManyToOne
// private User user;
//
//
// public void addToTags(Tags t){
// this.tags.add(t);
// }
//
//
// }
// Path: chapter07/src/test/java/com/pocketpub/pfbp/test/HibernateUtilTest.java
import com.packtpub.pf.blueprint.persistence.HibernateUtil;
import com.packtpub.pf.blueprint.persistence.entity.Movie;
import org.hibernate.Session;
import java.util.List;
package com.pocketpub.pfbp.test;
/**
* Created with IntelliJ IDEA.
* User: psramkumar
* Date: 2/6/14
* Time: 7:44 PM
* To change this template use File | Settings | File Templates.
*/
public class HibernateUtilTest {
public static void main(String[] args) {
System.out.println("Testing Hibernate Utility Class");
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction(); | Movie cat = new Movie(); |
sudheerj/primefaces-blueprints | chapter10/src/main/java/com/packt/pfblueprints/dao/ProductsDAO.java | // Path: chapter10/src/main/java/com/packt/pfblueprints/dao/util/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter10/src/main/java/com/packt/pfblueprints/model/Product.java
// @Entity
// @Table
// public class Product implements Serializable{
//
// private static final long serialVersionUID = 1L;
// @Id
// @GeneratedValue
// private Long id;
//
// private String prodname;
// private String prodimage;
// private String prodcat;
// private int rating;
// private String discount;
// private String price;
//
//
// public Product() {
// super();
// // TODO Auto-generated constructor stub
// }
//
// public Product(String prodname,String prodimage,String prodcat,int rating, String discount,String price) {
// super();
// this.prodname = prodname;
// this.prodimage = prodimage;
// this.prodcat = prodcat;
// this.rating = rating;
// this.discount = discount;
// this.price = price;
// }
//
// public String getProdname() {
// return prodname;
// }
//
// public void setProdname(String prodname) {
// this.prodname = prodname;
// }
//
// public String getProdimage() {
// return prodimage;
// }
//
// public void setProdimage(String prodimage) {
// this.prodimage = prodimage;
// }
//
// public String getProdcat() {
// return prodcat;
// }
//
// public void setProdcat(String prodcat) {
// this.prodcat = prodcat;
// }
//
// public String getPrice() {
// return price;
// }
//
// public void setPrice(String price) {
// this.price = price;
// }
//
// public String getDiscount() {
// return discount;
// }
//
// public void setDiscount(String discount) {
// this.discount = discount;
// }
//
// public void setRating(int rating) {
// this.rating = rating;
// }
//
// public int getRating() {
// return rating;
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import com.packt.pfblueprints.dao.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.packt.pfblueprints.model.Product;
| package com.packt.pfblueprints.dao;
public class ProductsDAO {
private String productCategory;
public ProductsDAO() {
super();
}
| // Path: chapter10/src/main/java/com/packt/pfblueprints/dao/util/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter10/src/main/java/com/packt/pfblueprints/model/Product.java
// @Entity
// @Table
// public class Product implements Serializable{
//
// private static final long serialVersionUID = 1L;
// @Id
// @GeneratedValue
// private Long id;
//
// private String prodname;
// private String prodimage;
// private String prodcat;
// private int rating;
// private String discount;
// private String price;
//
//
// public Product() {
// super();
// // TODO Auto-generated constructor stub
// }
//
// public Product(String prodname,String prodimage,String prodcat,int rating, String discount,String price) {
// super();
// this.prodname = prodname;
// this.prodimage = prodimage;
// this.prodcat = prodcat;
// this.rating = rating;
// this.discount = discount;
// this.price = price;
// }
//
// public String getProdname() {
// return prodname;
// }
//
// public void setProdname(String prodname) {
// this.prodname = prodname;
// }
//
// public String getProdimage() {
// return prodimage;
// }
//
// public void setProdimage(String prodimage) {
// this.prodimage = prodimage;
// }
//
// public String getProdcat() {
// return prodcat;
// }
//
// public void setProdcat(String prodcat) {
// this.prodcat = prodcat;
// }
//
// public String getPrice() {
// return price;
// }
//
// public void setPrice(String price) {
// this.price = price;
// }
//
// public String getDiscount() {
// return discount;
// }
//
// public void setDiscount(String discount) {
// this.discount = discount;
// }
//
// public void setRating(int rating) {
// this.rating = rating;
// }
//
// public int getRating() {
// return rating;
// }
// }
// Path: chapter10/src/main/java/com/packt/pfblueprints/dao/ProductsDAO.java
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import com.packt.pfblueprints.dao.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.packt.pfblueprints.model.Product;
package com.packt.pfblueprints.dao;
public class ProductsDAO {
private String productCategory;
public ProductsDAO() {
super();
}
| public List<Product> getAllProducts(int first, int pageSize,
|
sudheerj/primefaces-blueprints | chapter10/src/main/java/com/packt/pfblueprints/dao/ProductsDAO.java | // Path: chapter10/src/main/java/com/packt/pfblueprints/dao/util/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter10/src/main/java/com/packt/pfblueprints/model/Product.java
// @Entity
// @Table
// public class Product implements Serializable{
//
// private static final long serialVersionUID = 1L;
// @Id
// @GeneratedValue
// private Long id;
//
// private String prodname;
// private String prodimage;
// private String prodcat;
// private int rating;
// private String discount;
// private String price;
//
//
// public Product() {
// super();
// // TODO Auto-generated constructor stub
// }
//
// public Product(String prodname,String prodimage,String prodcat,int rating, String discount,String price) {
// super();
// this.prodname = prodname;
// this.prodimage = prodimage;
// this.prodcat = prodcat;
// this.rating = rating;
// this.discount = discount;
// this.price = price;
// }
//
// public String getProdname() {
// return prodname;
// }
//
// public void setProdname(String prodname) {
// this.prodname = prodname;
// }
//
// public String getProdimage() {
// return prodimage;
// }
//
// public void setProdimage(String prodimage) {
// this.prodimage = prodimage;
// }
//
// public String getProdcat() {
// return prodcat;
// }
//
// public void setProdcat(String prodcat) {
// this.prodcat = prodcat;
// }
//
// public String getPrice() {
// return price;
// }
//
// public void setPrice(String price) {
// this.price = price;
// }
//
// public String getDiscount() {
// return discount;
// }
//
// public void setDiscount(String discount) {
// this.discount = discount;
// }
//
// public void setRating(int rating) {
// this.rating = rating;
// }
//
// public int getRating() {
// return rating;
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import com.packt.pfblueprints.dao.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.packt.pfblueprints.model.Product;
| package com.packt.pfblueprints.dao;
public class ProductsDAO {
private String productCategory;
public ProductsDAO() {
super();
}
public List<Product> getAllProducts(int first, int pageSize,
String sortField, String sortOrderValue, Map<String, Object> filters) {
Session session = getSession();// sessionFactory.openSession();
session.beginTransaction();
ExternalContext externalContext = FacesContext.getCurrentInstance()
.getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
productCategory = (String) sessionMap.get("productCategory");
String query = null;
Query queryResult=null;
if (productCategory != "") {
query = "from Product where prodcat = :productCategory ORDER BY "+sortField+" "+sortOrderValue;
queryResult = session.createQuery(query);
queryResult.setParameter("productCategory", productCategory);
} else {
query = "from Product ORDER BY "+sortField+" "+sortOrderValue;
queryResult = session.createQuery(query);
}
List<Product> allProducts = queryResult.list();
session.getTransaction().commit();
return allProducts;
}
private Session getSession() {
| // Path: chapter10/src/main/java/com/packt/pfblueprints/dao/util/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter10/src/main/java/com/packt/pfblueprints/model/Product.java
// @Entity
// @Table
// public class Product implements Serializable{
//
// private static final long serialVersionUID = 1L;
// @Id
// @GeneratedValue
// private Long id;
//
// private String prodname;
// private String prodimage;
// private String prodcat;
// private int rating;
// private String discount;
// private String price;
//
//
// public Product() {
// super();
// // TODO Auto-generated constructor stub
// }
//
// public Product(String prodname,String prodimage,String prodcat,int rating, String discount,String price) {
// super();
// this.prodname = prodname;
// this.prodimage = prodimage;
// this.prodcat = prodcat;
// this.rating = rating;
// this.discount = discount;
// this.price = price;
// }
//
// public String getProdname() {
// return prodname;
// }
//
// public void setProdname(String prodname) {
// this.prodname = prodname;
// }
//
// public String getProdimage() {
// return prodimage;
// }
//
// public void setProdimage(String prodimage) {
// this.prodimage = prodimage;
// }
//
// public String getProdcat() {
// return prodcat;
// }
//
// public void setProdcat(String prodcat) {
// this.prodcat = prodcat;
// }
//
// public String getPrice() {
// return price;
// }
//
// public void setPrice(String price) {
// this.price = price;
// }
//
// public String getDiscount() {
// return discount;
// }
//
// public void setDiscount(String discount) {
// this.discount = discount;
// }
//
// public void setRating(int rating) {
// this.rating = rating;
// }
//
// public int getRating() {
// return rating;
// }
// }
// Path: chapter10/src/main/java/com/packt/pfblueprints/dao/ProductsDAO.java
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import com.packt.pfblueprints.dao.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.packt.pfblueprints.model.Product;
package com.packt.pfblueprints.dao;
public class ProductsDAO {
private String productCategory;
public ProductsDAO() {
super();
}
public List<Product> getAllProducts(int first, int pageSize,
String sortField, String sortOrderValue, Map<String, Object> filters) {
Session session = getSession();// sessionFactory.openSession();
session.beginTransaction();
ExternalContext externalContext = FacesContext.getCurrentInstance()
.getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
productCategory = (String) sessionMap.get("productCategory");
String query = null;
Query queryResult=null;
if (productCategory != "") {
query = "from Product where prodcat = :productCategory ORDER BY "+sortField+" "+sortOrderValue;
queryResult = session.createQuery(query);
queryResult.setParameter("productCategory", productCategory);
} else {
query = "from Product ORDER BY "+sortField+" "+sortOrderValue;
queryResult = session.createQuery(query);
}
List<Product> allProducts = queryResult.list();
session.getTransaction().commit();
return allProducts;
}
private Session getSession() {
| SessionFactory sf = HibernateUtil.getSessionFactory();
|
sudheerj/primefaces-blueprints | chapter04/src/main/java/com/packt/pfblueprints/dao/ServiceCenterDAO.java | // Path: chapter04/src/main/java/com/packt/pfblueprints/model/Dealer.java
// public class Dealer implements Serializable{
//
// private static final long serialVersionUID = 1L;
// private int id;
// private String dealerfirstname;
// private String dealerlastname;
// private String dealertinnumber;
// private String branchname;
// private String dor;
// private String noofadvisors;
// private String pan;
// private String status;
// private String address1;
// private String address2;
// private String country;
// private String city;
// private String contactnumber;
// private String postalcode;
//
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
// public String getDealerfirstname() {
// return dealerfirstname;
// }
// public void setDealerfirstname(String dealerfirstname) {
// this.dealerfirstname = dealerfirstname;
// }
// public String getDealerlastname() {
// return dealerlastname;
// }
// public void setDealerlastname(String dealerlastname) {
// this.dealerlastname = dealerlastname;
// }
// public String getDealertinnumber() {
// return dealertinnumber;
// }
// public void setDealertinnumber(String dealertinnumber) {
// this.dealertinnumber = dealertinnumber;
// }
// public String getBranchname() {
// return branchname;
// }
// public void setBranchname(String branchname) {
// this.branchname = branchname;
// }
// public String getDor() {
// return dor;
// }
// public void setDor(String dor) {
// this.dor = dor;
// }
// public String getNoofadvisors() {
// return noofadvisors;
// }
// public void setNoofadvisors(String noofadvisors) {
// this.noofadvisors = noofadvisors;
// }
// public String getPan() {
// return pan;
// }
// public void setPan(String pan) {
// this.pan = pan;
// }
// public String getStatus() {
// return status;
// }
// public void setStatus(String status) {
// this.status = status;
// }
// public String getAddress1() {
// return address1;
// }
// public void setAddress1(String address1) {
// this.address1 = address1;
// }
// public String getAddress2() {
// return address2;
// }
// public void setAddress2(String address2) {
// this.address2 = address2;
// }
// public String getCountry() {
// return country;
// }
// public void setCountry(String country) {
// this.country = country;
// }
// public String getCity() {
// return city;
// }
// public void setCity(String city) {
// this.city = city;
// }
// public String getContactnumber() {
// return contactnumber;
// }
// public void setContactnumber(String contactnumber) {
// this.contactnumber = contactnumber;
// }
// public String getPostalcode() {
// return postalcode;
// }
// public void setPostalcode(String postalcode) {
// this.postalcode = postalcode;
// }
//
// }
| import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.packt.pfblueprints.model.Dealer;
| package com.packt.pfblueprints.dao;
public class ServiceCenterDAO {
private SessionFactory sessionFactory;
private SessionFactory configureSessionFactory()
throws HibernateException {
Configuration configuration = new Configuration();
configuration.configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties());
SessionFactory sessionfactory = configuration
.buildSessionFactory(builder.build());
return sessionfactory;
}
public ServiceCenterDAO() {
super();
// TODO Auto-generated constructor stub
}
| // Path: chapter04/src/main/java/com/packt/pfblueprints/model/Dealer.java
// public class Dealer implements Serializable{
//
// private static final long serialVersionUID = 1L;
// private int id;
// private String dealerfirstname;
// private String dealerlastname;
// private String dealertinnumber;
// private String branchname;
// private String dor;
// private String noofadvisors;
// private String pan;
// private String status;
// private String address1;
// private String address2;
// private String country;
// private String city;
// private String contactnumber;
// private String postalcode;
//
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
// public String getDealerfirstname() {
// return dealerfirstname;
// }
// public void setDealerfirstname(String dealerfirstname) {
// this.dealerfirstname = dealerfirstname;
// }
// public String getDealerlastname() {
// return dealerlastname;
// }
// public void setDealerlastname(String dealerlastname) {
// this.dealerlastname = dealerlastname;
// }
// public String getDealertinnumber() {
// return dealertinnumber;
// }
// public void setDealertinnumber(String dealertinnumber) {
// this.dealertinnumber = dealertinnumber;
// }
// public String getBranchname() {
// return branchname;
// }
// public void setBranchname(String branchname) {
// this.branchname = branchname;
// }
// public String getDor() {
// return dor;
// }
// public void setDor(String dor) {
// this.dor = dor;
// }
// public String getNoofadvisors() {
// return noofadvisors;
// }
// public void setNoofadvisors(String noofadvisors) {
// this.noofadvisors = noofadvisors;
// }
// public String getPan() {
// return pan;
// }
// public void setPan(String pan) {
// this.pan = pan;
// }
// public String getStatus() {
// return status;
// }
// public void setStatus(String status) {
// this.status = status;
// }
// public String getAddress1() {
// return address1;
// }
// public void setAddress1(String address1) {
// this.address1 = address1;
// }
// public String getAddress2() {
// return address2;
// }
// public void setAddress2(String address2) {
// this.address2 = address2;
// }
// public String getCountry() {
// return country;
// }
// public void setCountry(String country) {
// this.country = country;
// }
// public String getCity() {
// return city;
// }
// public void setCity(String city) {
// this.city = city;
// }
// public String getContactnumber() {
// return contactnumber;
// }
// public void setContactnumber(String contactnumber) {
// this.contactnumber = contactnumber;
// }
// public String getPostalcode() {
// return postalcode;
// }
// public void setPostalcode(String postalcode) {
// this.postalcode = postalcode;
// }
//
// }
// Path: chapter04/src/main/java/com/packt/pfblueprints/dao/ServiceCenterDAO.java
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.packt.pfblueprints.model.Dealer;
package com.packt.pfblueprints.dao;
public class ServiceCenterDAO {
private SessionFactory sessionFactory;
private SessionFactory configureSessionFactory()
throws HibernateException {
Configuration configuration = new Configuration();
configuration.configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties());
SessionFactory sessionfactory = configuration
.buildSessionFactory(builder.build());
return sessionfactory;
}
public ServiceCenterDAO() {
super();
// TODO Auto-generated constructor stub
}
| public List<Dealer> getAllDealers() {
|
sudheerj/primefaces-blueprints | chapter07/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Movie.java | // Path: chapter07/src/main/java/com/packtpub/pf/blueprint/MovieType.java
// public enum MovieType {
// YOUTUBE, QUICKTIME
// }
| import com.packtpub.pf.blueprint.MovieType;
import lombok.Data;
import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set; | package com.packtpub.pf.blueprint.persistence.entity;
/**
* Created with IntelliJ IDEA.
* User: Ramkumar Pillai <psramkumar@gmail.com>
* Date: 3/6/14
* Time: 11:06 AM
* To change this template use File | Settings | File Templates.
*/
@Entity
@Table
@Data
public class Movie {
@Id
@GeneratedValue
private Long id;
private String title;
private String description;
@Temporal(TemporalType.DATE)
private Date releaseDate;
private int rating;
private boolean favorite;
private String image;
private boolean isImageUrl;
private String movieUrl;
| // Path: chapter07/src/main/java/com/packtpub/pf/blueprint/MovieType.java
// public enum MovieType {
// YOUTUBE, QUICKTIME
// }
// Path: chapter07/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Movie.java
import com.packtpub.pf.blueprint.MovieType;
import lombok.Data;
import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
package com.packtpub.pf.blueprint.persistence.entity;
/**
* Created with IntelliJ IDEA.
* User: Ramkumar Pillai <psramkumar@gmail.com>
* Date: 3/6/14
* Time: 11:06 AM
* To change this template use File | Settings | File Templates.
*/
@Entity
@Table
@Data
public class Movie {
@Id
@GeneratedValue
private Long id;
private String title;
private String description;
@Temporal(TemporalType.DATE)
private Date releaseDate;
private int rating;
private boolean favorite;
private String image;
private boolean isImageUrl;
private String movieUrl;
| private MovieType movieType; |
sudheerj/primefaces-blueprints | chapter06/src/test/java/com/pocketpub/pfbp/test/HibernateUtilTest.java | // Path: chapter09/src/main/java/com/packtpub/pf/blueprint/persistence/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter06/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Category.java
// @Entity
// @Table
// public class Category implements java.io.Serializable {
//
// @Id
// @GeneratedValue
// private Long id;
//
// private String name;
//
// private Long parentId;
//
// @OneToMany(mappedBy = "category")
// private Set<Product> products = new HashSet<>();
//
// public Category() {
// this.parentId = 0L;
// }
//
// public Category(String name) {
// this.name = name;
// this.parentId = 0L;
// }
//
// public Category(String name, Long parentId) {
// this.name = name;
// this.parentId = parentId;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Long getParentId() {
// return parentId;
// }
//
// public void setParentId(Long parentId) {
// this.parentId = parentId;
// }
//
// public Set<Product> getProducts() {
// return products;
// }
//
// public void setProducts(Set<Product> product) {
// this.products = product;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", parentId=" + parentId +
// '}';
// }
// }
| import com.packtpub.pf.blueprint.persistence.HibernateUtil;
import com.packtpub.pf.blueprint.persistence.entity.Category;
import org.hibernate.Session;
import java.util.List; | package com.pocketpub.pfbp.test;
/**
* Created with IntelliJ IDEA.
* User: psramkumar
* Date: 2/6/14
* Time: 7:44 PM
* To change this template use File | Settings | File Templates.
*/
public class HibernateUtilTest {
public static void main(String[] args) {
System.out.println("Testing Hibernate Utility Class"); | // Path: chapter09/src/main/java/com/packtpub/pf/blueprint/persistence/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter06/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Category.java
// @Entity
// @Table
// public class Category implements java.io.Serializable {
//
// @Id
// @GeneratedValue
// private Long id;
//
// private String name;
//
// private Long parentId;
//
// @OneToMany(mappedBy = "category")
// private Set<Product> products = new HashSet<>();
//
// public Category() {
// this.parentId = 0L;
// }
//
// public Category(String name) {
// this.name = name;
// this.parentId = 0L;
// }
//
// public Category(String name, Long parentId) {
// this.name = name;
// this.parentId = parentId;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Long getParentId() {
// return parentId;
// }
//
// public void setParentId(Long parentId) {
// this.parentId = parentId;
// }
//
// public Set<Product> getProducts() {
// return products;
// }
//
// public void setProducts(Set<Product> product) {
// this.products = product;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", parentId=" + parentId +
// '}';
// }
// }
// Path: chapter06/src/test/java/com/pocketpub/pfbp/test/HibernateUtilTest.java
import com.packtpub.pf.blueprint.persistence.HibernateUtil;
import com.packtpub.pf.blueprint.persistence.entity.Category;
import org.hibernate.Session;
import java.util.List;
package com.pocketpub.pfbp.test;
/**
* Created with IntelliJ IDEA.
* User: psramkumar
* Date: 2/6/14
* Time: 7:44 PM
* To change this template use File | Settings | File Templates.
*/
public class HibernateUtilTest {
public static void main(String[] args) {
System.out.println("Testing Hibernate Utility Class"); | Session session = HibernateUtil.getSessionFactory().openSession(); |
sudheerj/primefaces-blueprints | chapter06/src/test/java/com/pocketpub/pfbp/test/HibernateUtilTest.java | // Path: chapter09/src/main/java/com/packtpub/pf/blueprint/persistence/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter06/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Category.java
// @Entity
// @Table
// public class Category implements java.io.Serializable {
//
// @Id
// @GeneratedValue
// private Long id;
//
// private String name;
//
// private Long parentId;
//
// @OneToMany(mappedBy = "category")
// private Set<Product> products = new HashSet<>();
//
// public Category() {
// this.parentId = 0L;
// }
//
// public Category(String name) {
// this.name = name;
// this.parentId = 0L;
// }
//
// public Category(String name, Long parentId) {
// this.name = name;
// this.parentId = parentId;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Long getParentId() {
// return parentId;
// }
//
// public void setParentId(Long parentId) {
// this.parentId = parentId;
// }
//
// public Set<Product> getProducts() {
// return products;
// }
//
// public void setProducts(Set<Product> product) {
// this.products = product;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", parentId=" + parentId +
// '}';
// }
// }
| import com.packtpub.pf.blueprint.persistence.HibernateUtil;
import com.packtpub.pf.blueprint.persistence.entity.Category;
import org.hibernate.Session;
import java.util.List; | package com.pocketpub.pfbp.test;
/**
* Created with IntelliJ IDEA.
* User: psramkumar
* Date: 2/6/14
* Time: 7:44 PM
* To change this template use File | Settings | File Templates.
*/
public class HibernateUtilTest {
public static void main(String[] args) {
System.out.println("Testing Hibernate Utility Class");
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction(); | // Path: chapter09/src/main/java/com/packtpub/pf/blueprint/persistence/HibernateUtil.java
// public class HibernateUtil {
//
// private static final SessionFactory sessionFactory = buildSessionFactory();
//
// private static SessionFactory buildSessionFactory() throws HibernateException {
// Configuration configuration = new Configuration().configure();
// // configures settings from hibernate.cfg.xml
//
// StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
//
// // If you miss the below line then it will complain about a missing dialect setting
// serviceRegistryBuilder.applySettings(configuration.getProperties());
//
// ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
// return configuration.buildSessionFactory(serviceRegistry);
// }
//
// public static SessionFactory getSessionFactory() {
// return sessionFactory;
// }
//
// public static void shutdown() {
// // Close caches and connection pools
// getSessionFactory().close();
// }
//
// }
//
// Path: chapter06/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Category.java
// @Entity
// @Table
// public class Category implements java.io.Serializable {
//
// @Id
// @GeneratedValue
// private Long id;
//
// private String name;
//
// private Long parentId;
//
// @OneToMany(mappedBy = "category")
// private Set<Product> products = new HashSet<>();
//
// public Category() {
// this.parentId = 0L;
// }
//
// public Category(String name) {
// this.name = name;
// this.parentId = 0L;
// }
//
// public Category(String name, Long parentId) {
// this.name = name;
// this.parentId = parentId;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public Long getParentId() {
// return parentId;
// }
//
// public void setParentId(Long parentId) {
// this.parentId = parentId;
// }
//
// public Set<Product> getProducts() {
// return products;
// }
//
// public void setProducts(Set<Product> product) {
// this.products = product;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", parentId=" + parentId +
// '}';
// }
// }
// Path: chapter06/src/test/java/com/pocketpub/pfbp/test/HibernateUtilTest.java
import com.packtpub.pf.blueprint.persistence.HibernateUtil;
import com.packtpub.pf.blueprint.persistence.entity.Category;
import org.hibernate.Session;
import java.util.List;
package com.pocketpub.pfbp.test;
/**
* Created with IntelliJ IDEA.
* User: psramkumar
* Date: 2/6/14
* Time: 7:44 PM
* To change this template use File | Settings | File Templates.
*/
public class HibernateUtilTest {
public static void main(String[] args) {
System.out.println("Testing Hibernate Utility Class");
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction(); | Category cat = new Category(); |
sudheerj/primefaces-blueprints | chapter05/src/main/java/com/packt/pfblueprints/dao/TransactionSummaryDAO.java | // Path: chapter05/src/main/java/com/packt/pfblueprints/model/TransactionSummary.java
// public class TransactionSummary implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
// private int id;
// private String investmentNumber;
// private String transactionid;
// private String transactiontype;
// private String transactiondate;
// private String paymenttype;
// private String status;
// private String transactionunitprice;
// private String transactionunits;
// private String grossamount;
// private String deductions;
// private String netamount;
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
// public String getInvestmentNumber() {
// return investmentNumber;
// }
// public void setInvestmentNumber(String investmentNumber) {
// this.investmentNumber = investmentNumber;
// }
// public String getTransactionid() {
// return transactionid;
// }
// public void setTransactionid(String transactionid) {
// this.transactionid = transactionid;
// }
// public String getTransactiontype() {
// return transactiontype;
// }
// public void setTransactiontype(String transactiontype) {
// this.transactiontype = transactiontype;
// }
//
// public String getTransactiondate() {
// return transactiondate;
// }
// public void setTransactiondate(String transactiondate) {
// this.transactiondate = transactiondate;
// }
// public String getStatus() {
// return status;
// }
// public void setStatus(String status) {
// this.status = status;
// }
//
// public String getTransactionunitprice() {
// return transactionunitprice;
// }
// public void setTransactionunitprice(String transactionunitprice) {
// this.transactionunitprice = transactionunitprice;
// }
// public String getTransactionunits() {
// return transactionunits;
// }
// public void setTransactionunits(String transactionunits) {
// this.transactionunits = transactionunits;
// }
// public String getGrossamount() {
// return grossamount;
// }
// public void setGrossamount(String grossamount) {
// this.grossamount = grossamount;
// }
// public String getDeductions() {
// return deductions;
// }
// public void setDeductions(String deductions) {
// this.deductions = deductions;
// }
// public String getNetamount() {
// return netamount;
// }
// public void setNetamount(String netamount) {
// this.netamount = netamount;
// }
// public String getPaymenttype() {
// return paymenttype;
// }
// public void setPaymenttype(String paymenttype) {
// this.paymenttype = paymenttype;
// }
//
//
// }
| import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.packt.pfblueprints.model.TransactionSummary;
| package com.packt.pfblueprints.dao;
public class TransactionSummaryDAO {
private SessionFactory sessionFactory;
private String investmentNumber;
private SessionFactory configureSessionFactory()
throws HibernateException {
Configuration configuration = new Configuration();
configuration.configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties());
SessionFactory sessionfactory = configuration
.buildSessionFactory(builder.build());
return sessionfactory;
}
public TransactionSummaryDAO() {
super();
// TODO Auto-generated constructor stub
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
investmentNumber=(String) sessionMap.get("investmentNumber");
}
| // Path: chapter05/src/main/java/com/packt/pfblueprints/model/TransactionSummary.java
// public class TransactionSummary implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
// private int id;
// private String investmentNumber;
// private String transactionid;
// private String transactiontype;
// private String transactiondate;
// private String paymenttype;
// private String status;
// private String transactionunitprice;
// private String transactionunits;
// private String grossamount;
// private String deductions;
// private String netamount;
//
// public int getId() {
// return id;
// }
// public void setId(int id) {
// this.id = id;
// }
// public String getInvestmentNumber() {
// return investmentNumber;
// }
// public void setInvestmentNumber(String investmentNumber) {
// this.investmentNumber = investmentNumber;
// }
// public String getTransactionid() {
// return transactionid;
// }
// public void setTransactionid(String transactionid) {
// this.transactionid = transactionid;
// }
// public String getTransactiontype() {
// return transactiontype;
// }
// public void setTransactiontype(String transactiontype) {
// this.transactiontype = transactiontype;
// }
//
// public String getTransactiondate() {
// return transactiondate;
// }
// public void setTransactiondate(String transactiondate) {
// this.transactiondate = transactiondate;
// }
// public String getStatus() {
// return status;
// }
// public void setStatus(String status) {
// this.status = status;
// }
//
// public String getTransactionunitprice() {
// return transactionunitprice;
// }
// public void setTransactionunitprice(String transactionunitprice) {
// this.transactionunitprice = transactionunitprice;
// }
// public String getTransactionunits() {
// return transactionunits;
// }
// public void setTransactionunits(String transactionunits) {
// this.transactionunits = transactionunits;
// }
// public String getGrossamount() {
// return grossamount;
// }
// public void setGrossamount(String grossamount) {
// this.grossamount = grossamount;
// }
// public String getDeductions() {
// return deductions;
// }
// public void setDeductions(String deductions) {
// this.deductions = deductions;
// }
// public String getNetamount() {
// return netamount;
// }
// public void setNetamount(String netamount) {
// this.netamount = netamount;
// }
// public String getPaymenttype() {
// return paymenttype;
// }
// public void setPaymenttype(String paymenttype) {
// this.paymenttype = paymenttype;
// }
//
//
// }
// Path: chapter05/src/main/java/com/packt/pfblueprints/dao/TransactionSummaryDAO.java
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.packt.pfblueprints.model.TransactionSummary;
package com.packt.pfblueprints.dao;
public class TransactionSummaryDAO {
private SessionFactory sessionFactory;
private String investmentNumber;
private SessionFactory configureSessionFactory()
throws HibernateException {
Configuration configuration = new Configuration();
configuration.configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties());
SessionFactory sessionfactory = configuration
.buildSessionFactory(builder.build());
return sessionfactory;
}
public TransactionSummaryDAO() {
super();
// TODO Auto-generated constructor stub
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
investmentNumber=(String) sessionMap.get("investmentNumber");
}
| public List<TransactionSummary> getAllTransactions() {
|
sudheerj/primefaces-blueprints | chapter05/src/main/java/com/packt/pfblueprints/controller/LoginController.java | // Path: chapter02/src/main/java/com/packt/pfblueprints/dao/LoginDAO.java
// public class LoginDAO {
//
// private DataSource ds;
// Connection con;
//
// public LoginDAO() throws SQLException {
// try {
// Context ctx = new InitialContext();
// ds = (DataSource) ctx.lookup("java:comp/env/jdbc/blueprintsdb");
// if (ds == null) {
// throw new SQLException("Can't get data source");
// }
// // get database connection
// con = ds.getConnection();
// if (con == null) {
// throw new SQLException("Can't get database connection");
// }
//
// } catch (NamingException e) {
// e.printStackTrace();
// }
//
// }
//
// public boolean changepassword(String userid, String oldpassword,
// String newpassword) {
// try {
// // Persist employee
// PreparedStatement ps = con
// .prepareStatement("UPDATE blueprintsdb.employee SET password='"
// + newpassword
// + "' WHERE userid='"
// + userid + "' and password='" + oldpassword + "'");
// int count = ps.executeUpdate();
// return (count > 0);
// } catch (SQLException e) {
// e.printStackTrace();
//
// } catch (Exception e) {
// e.printStackTrace();
//
// }
// return false;
//
// }
//
// public boolean validateUser(String userid, String password) {
// try {
// // Check the logged jobseeker is valid user or not
// PreparedStatement ps = con
// .prepareStatement("select * FROM blueprintsdb.employee WHERE userid='"
// + userid + "' and password='" + password + "'");
// ResultSet resultSet = ps.executeQuery();
// if (resultSet.next()) {
// return true;
// } else {
// return false;
// }
//
// } catch (SQLException e) {
// e.printStackTrace();
//
// } catch (Exception e) {
// e.printStackTrace();
//
// }
// return false;
// }
// }
| import java.io.Serializable;
import java.sql.SQLException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.bean.ViewScoped;
import javax.faces.bean.ManagedBean;
import com.packt.pfblueprints.dao.LoginDAO;
| package com.packt.pfblueprints.controller;
@ManagedBean
@ViewScoped
public class LoginController implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String username;
private String password;
public LoginController() {
super();
}
public String validateUser() throws SQLException {
FacesMessage msg = null;
boolean isValidUser = false;
| // Path: chapter02/src/main/java/com/packt/pfblueprints/dao/LoginDAO.java
// public class LoginDAO {
//
// private DataSource ds;
// Connection con;
//
// public LoginDAO() throws SQLException {
// try {
// Context ctx = new InitialContext();
// ds = (DataSource) ctx.lookup("java:comp/env/jdbc/blueprintsdb");
// if (ds == null) {
// throw new SQLException("Can't get data source");
// }
// // get database connection
// con = ds.getConnection();
// if (con == null) {
// throw new SQLException("Can't get database connection");
// }
//
// } catch (NamingException e) {
// e.printStackTrace();
// }
//
// }
//
// public boolean changepassword(String userid, String oldpassword,
// String newpassword) {
// try {
// // Persist employee
// PreparedStatement ps = con
// .prepareStatement("UPDATE blueprintsdb.employee SET password='"
// + newpassword
// + "' WHERE userid='"
// + userid + "' and password='" + oldpassword + "'");
// int count = ps.executeUpdate();
// return (count > 0);
// } catch (SQLException e) {
// e.printStackTrace();
//
// } catch (Exception e) {
// e.printStackTrace();
//
// }
// return false;
//
// }
//
// public boolean validateUser(String userid, String password) {
// try {
// // Check the logged jobseeker is valid user or not
// PreparedStatement ps = con
// .prepareStatement("select * FROM blueprintsdb.employee WHERE userid='"
// + userid + "' and password='" + password + "'");
// ResultSet resultSet = ps.executeQuery();
// if (resultSet.next()) {
// return true;
// } else {
// return false;
// }
//
// } catch (SQLException e) {
// e.printStackTrace();
//
// } catch (Exception e) {
// e.printStackTrace();
//
// }
// return false;
// }
// }
// Path: chapter05/src/main/java/com/packt/pfblueprints/controller/LoginController.java
import java.io.Serializable;
import java.sql.SQLException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.bean.ViewScoped;
import javax.faces.bean.ManagedBean;
import com.packt.pfblueprints.dao.LoginDAO;
package com.packt.pfblueprints.controller;
@ManagedBean
@ViewScoped
public class LoginController implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String username;
private String password;
public LoginController() {
super();
}
public String validateUser() throws SQLException {
FacesMessage msg = null;
boolean isValidUser = false;
| LoginDAO dao = new LoginDAO();
|
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlStreamHandler.java | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
//
// Path: provider/src/main/java/com/raygun/raygun4android/utils/RaygunReflectionUtils.java
// public class RaygunReflectionUtils {
// public static Method findMethod(Class<?> clazz, String methodName, Class<?>[] args) throws NoSuchMethodException {
// Method methodMatched = null;
//
// for (Method m : getAllMethods(clazz)) {
//
// if (m.getName().equals(methodName)) {
// Class<?>[] paramClasses = m.getParameterTypes();
//
// if (paramClasses.length == args.length) {
// boolean paramsMatch = true;
//
// for (int i = 0; i < paramClasses.length; ++i) {
// Class<?> paramType = paramClasses[i];
// paramType = convertPrimitiveClass(paramType);
//
// if (paramType != args[i]) {
// paramsMatch = false;
// break;
// }
// }
//
// if (paramsMatch) {
// methodMatched = m;
// break;
// }
// }
// }
// }
//
// if (methodMatched != null) {
// return methodMatched;
// } else {
// throw new NoSuchMethodException("Cannot find method: " + methodName);
// }
// }
//
// private static Collection<Method> getAllMethods(Class<?> clazz) {
// HashSet<Method> methods = new HashSet<Method>();
//
// methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
//
// for (Class<?> s : getAllSuperClasses(clazz)) {
// methods.addAll(Arrays.asList(s.getDeclaredMethods()));
// }
//
// return methods;
// }
//
// private static Collection<Class<?>> getAllSuperClasses(Class<?> clazz) {
// HashSet<Class<?>> classes = new HashSet<Class<?>>();
//
// if ((clazz != null) && (!clazz.equals(Object.class))) {
// classes.add(clazz);
// classes.addAll(getAllSuperClasses(clazz.getSuperclass()));
//
// for (Class<?> i : clazz.getInterfaces()) {
// classes.addAll(getAllSuperClasses(i));
// }
// }
// return classes;
// }
//
// private static Class<?> convertPrimitiveClass(Class<?> primitive) {
// if (primitive.isPrimitive()) {
// if (primitive == Integer.TYPE) {
// return Integer.class;
// }
// if (primitive == Boolean.TYPE) {
// return Boolean.class;
// }
// if (primitive == Float.TYPE) {
// return Float.class;
// }
// if (primitive == Long.TYPE) {
// return Long.class;
// }
// if (primitive == Double.TYPE) {
// return Double.class;
// }
// if (primitive == Short.TYPE) {
// return Short.class;
// }
// if (primitive == Byte.TYPE) {
// return Byte.class;
// }
// if (primitive == Character.TYPE) {
// return Character.class;
// }
// }
// return primitive;
// }
// }
| import com.raygun.raygun4android.logging.RaygunLogger;
import com.raygun.raygun4android.utils.RaygunReflectionUtils;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler; | package com.raygun.raygun4android.network.http;
final class RaygunHttpsUrlStreamHandler extends URLStreamHandler {
private static final int PORT = 443;
private static final String PROTOCOL = "https";
private final URLStreamHandler originalHandler;
RaygunHttpsUrlStreamHandler(URLStreamHandler handler) {
originalHandler = handler;
}
protected URLConnection openConnection(URL url) throws IOException {
try { | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
//
// Path: provider/src/main/java/com/raygun/raygun4android/utils/RaygunReflectionUtils.java
// public class RaygunReflectionUtils {
// public static Method findMethod(Class<?> clazz, String methodName, Class<?>[] args) throws NoSuchMethodException {
// Method methodMatched = null;
//
// for (Method m : getAllMethods(clazz)) {
//
// if (m.getName().equals(methodName)) {
// Class<?>[] paramClasses = m.getParameterTypes();
//
// if (paramClasses.length == args.length) {
// boolean paramsMatch = true;
//
// for (int i = 0; i < paramClasses.length; ++i) {
// Class<?> paramType = paramClasses[i];
// paramType = convertPrimitiveClass(paramType);
//
// if (paramType != args[i]) {
// paramsMatch = false;
// break;
// }
// }
//
// if (paramsMatch) {
// methodMatched = m;
// break;
// }
// }
// }
// }
//
// if (methodMatched != null) {
// return methodMatched;
// } else {
// throw new NoSuchMethodException("Cannot find method: " + methodName);
// }
// }
//
// private static Collection<Method> getAllMethods(Class<?> clazz) {
// HashSet<Method> methods = new HashSet<Method>();
//
// methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
//
// for (Class<?> s : getAllSuperClasses(clazz)) {
// methods.addAll(Arrays.asList(s.getDeclaredMethods()));
// }
//
// return methods;
// }
//
// private static Collection<Class<?>> getAllSuperClasses(Class<?> clazz) {
// HashSet<Class<?>> classes = new HashSet<Class<?>>();
//
// if ((clazz != null) && (!clazz.equals(Object.class))) {
// classes.add(clazz);
// classes.addAll(getAllSuperClasses(clazz.getSuperclass()));
//
// for (Class<?> i : clazz.getInterfaces()) {
// classes.addAll(getAllSuperClasses(i));
// }
// }
// return classes;
// }
//
// private static Class<?> convertPrimitiveClass(Class<?> primitive) {
// if (primitive.isPrimitive()) {
// if (primitive == Integer.TYPE) {
// return Integer.class;
// }
// if (primitive == Boolean.TYPE) {
// return Boolean.class;
// }
// if (primitive == Float.TYPE) {
// return Float.class;
// }
// if (primitive == Long.TYPE) {
// return Long.class;
// }
// if (primitive == Double.TYPE) {
// return Double.class;
// }
// if (primitive == Short.TYPE) {
// return Short.class;
// }
// if (primitive == Byte.TYPE) {
// return Byte.class;
// }
// if (primitive == Character.TYPE) {
// return Character.class;
// }
// }
// return primitive;
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpsUrlStreamHandler.java
import com.raygun.raygun4android.logging.RaygunLogger;
import com.raygun.raygun4android.utils.RaygunReflectionUtils;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
package com.raygun.raygun4android.network.http;
final class RaygunHttpsUrlStreamHandler extends URLStreamHandler {
private static final int PORT = 443;
private static final String PROTOCOL = "https";
private final URLStreamHandler originalHandler;
RaygunHttpsUrlStreamHandler(URLStreamHandler handler) {
originalHandler = handler;
}
protected URLConnection openConnection(URL url) throws IOException {
try { | Method method = RaygunReflectionUtils.findMethod(originalHandler.getClass(), "openConnection", new Class<?>[]{URL.class}); |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunEnvironmentMessage.java | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
| import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import com.raygun.raygun4android.logging.RaygunLogger;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern; | currentOrientation = "Undefined";
}
DisplayMetrics metrics = new DisplayMetrics();
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
windowsBoundWidth = metrics.widthPixels;
windowsBoundHeight = metrics.heightPixels;
TimeZone tz = TimeZone.getDefault();
Date now = new Date();
utcOffset = TimeUnit.SECONDS.convert(tz.getOffset(now.getTime()), TimeUnit.MILLISECONDS) / 3600;
locale = context.getResources().getConfiguration().locale.toString();
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
am.getMemoryInfo(mi);
availablePhysicalMemory = mi.availMem / 0x100000;
Pattern p = Pattern.compile("^\\D*(\\d*).*$");
Matcher m = p.matcher(getTotalRam());
m.find();
String match = m.group(1);
totalPhysicalMemory = Long.parseLong(match) / 0x400;
StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
long availableBlocks = (long) stat.getAvailableBlocks();
long blockSize = (long) stat.getBlockSize();
diskSpaceFree = (availableBlocks * blockSize) / 0x100000;
} catch (Exception e) { | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
// Path: provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunEnvironmentMessage.java
import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import com.raygun.raygun4android.logging.RaygunLogger;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
currentOrientation = "Undefined";
}
DisplayMetrics metrics = new DisplayMetrics();
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
windowsBoundWidth = metrics.widthPixels;
windowsBoundHeight = metrics.heightPixels;
TimeZone tz = TimeZone.getDefault();
Date now = new Date();
utcOffset = TimeUnit.SECONDS.convert(tz.getOffset(now.getTime()), TimeUnit.MILLISECONDS) / 3600;
locale = context.getResources().getConfiguration().locale.toString();
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
am.getMemoryInfo(mi);
availablePhysicalMemory = mi.availMem / 0x100000;
Pattern p = Pattern.compile("^\\D*(\\d*).*$");
Matcher m = p.matcher(getTotalRam());
m.find();
String match = m.group(1);
totalPhysicalMemory = Long.parseLong(match) / 0x400;
StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
long availableBlocks = (long) stat.getAvailableBlocks();
long blockSize = (long) stat.getBlockSize();
diskSpaceFree = (availableBlocks * blockSize) / 0x100000;
} catch (Exception e) { | RaygunLogger.w("Couldn't get all env data: " + e); |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/network/http/RaygunUrlStreamHandlerFactory.java | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
| import android.os.Build;
import com.raygun.raygun4android.logging.RaygunLogger;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
import java.util.HashMap; | streamHandler = (URLStreamHandler) c.newInstance();
return streamHandler;
} catch (IllegalAccessException ignore) {
} catch (InstantiationException ignore) {
} catch (ClassNotFoundException ignore) {
}
}
}
if (Build.VERSION.SDK_INT >= 19) {
if (protocol.equals("http")) {
streamHandler = createStreamHandler("com.android.okhttp.HttpHandler");
} else if (protocol.equals("https")) {
streamHandler = createStreamHandler("com.android.okhttp.HttpsHandler");
}
} else {
if (protocol.equals("http")) {
streamHandler = createStreamHandler("libcore.net.http.HttpHandler");
} else if (protocol.equals("https")) {
streamHandler = createStreamHandler("libcore.net.http.HttpsHandler");
}
}
return streamHandler;
}
private URLStreamHandler createStreamHandler(String className) {
try {
return (URLStreamHandler) Class.forName(className).newInstance();
} catch (Exception e) { | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
// Path: provider/src/main/java/com/raygun/raygun4android/network/http/RaygunUrlStreamHandlerFactory.java
import android.os.Build;
import com.raygun.raygun4android.logging.RaygunLogger;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
import java.util.HashMap;
streamHandler = (URLStreamHandler) c.newInstance();
return streamHandler;
} catch (IllegalAccessException ignore) {
} catch (InstantiationException ignore) {
} catch (ClassNotFoundException ignore) {
}
}
}
if (Build.VERSION.SDK_INT >= 19) {
if (protocol.equals("http")) {
streamHandler = createStreamHandler("com.android.okhttp.HttpHandler");
} else if (protocol.equals("https")) {
streamHandler = createStreamHandler("com.android.okhttp.HttpsHandler");
}
} else {
if (protocol.equals("http")) {
streamHandler = createStreamHandler("libcore.net.http.HttpHandler");
} else if (protocol.equals("https")) {
streamHandler = createStreamHandler("libcore.net.http.HttpsHandler");
}
}
return streamHandler;
}
private URLStreamHandler createStreamHandler(String className) {
try {
return (URLStreamHandler) Class.forName(className).newInstance();
} catch (Exception e) { | RaygunLogger.e("Exception occurred in createStreamHandler: " + e.getMessage()); |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/IRaygunMessageBuilder.java | // Path: provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunBreadcrumbMessage.java
// public class RaygunBreadcrumbMessage {
// private String message;
// private String category;
// private int level;
// private String type = "Manual";
// private Map<String, Object> customData;
// private Long timestamp = System.currentTimeMillis();
// private String className;
// private String methodName;
// private Integer lineNumber;
//
// public static class Builder {
// private String message;
// private String category;
// private int level = RaygunBreadcrumbLevel.INFO.ordinal();
// private Map<String, Object> customData = new WeakHashMap<>();
// private String className;
// private String methodName;
// private Integer lineNumber;
//
// public Builder(String message) {
// this.message = message;
// }
//
// public Builder category(String category) {
// this.category = category;
// return this;
// }
//
// public Builder level(RaygunBreadcrumbLevel level) {
// this.level = level.ordinal();
// return this;
// }
//
// public Builder customData(Map<String, Object> customData) {
// this.customData = customData;
// return this;
// }
//
// public Builder className(String className) {
// this.className = className;
// return this;
// }
//
// public Builder methodName(String methodName) {
// this.methodName = methodName;
// return this;
// }
//
// public Builder lineNumber(Integer lineNumber) {
// this.lineNumber = lineNumber;
// return this;
// }
//
// public RaygunBreadcrumbMessage build() {
// return new RaygunBreadcrumbMessage(this);
// }
// }
//
// public String getMessage() {
// return message;
// }
//
// public String getCategory() {
// return category;
// }
//
// public RaygunBreadcrumbLevel getLevel() {
// return RaygunBreadcrumbLevel.values()[level];
// }
//
// public Map<String, Object> getCustomData() {
// return customData;
// }
//
// public String getClassName() {
// return className;
// }
//
// public String getMethodName() {
// return methodName;
// }
//
// public Integer getLineNumber() {
// return lineNumber;
// }
//
// private RaygunBreadcrumbMessage(Builder builder) {
// message = builder.message;
// category = builder.category;
// level = builder.level;
// customData = builder.customData;
// className = builder.className;
// methodName = builder.methodName;
// lineNumber = builder.lineNumber;
// }
// }
//
// Path: provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessage.java
// public class RaygunMessage {
// private String occurredOn;
// private RaygunMessageDetails details;
//
// public RaygunMessage() {
// details = new RaygunMessageDetails();
//
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// LocalDateTime utcDateTime = LocalDateTime.now(ZoneId.of("UTC"));
// occurredOn = utcDateTime.toString();
// } else {
// @SuppressLint("SimpleDateFormat") SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
// df.setTimeZone(TimeZone.getTimeZone("UTC"));
// occurredOn = df.format(Calendar.getInstance().getTime());
// }
// }
//
// public RaygunMessageDetails getDetails() {
// return details;
// }
//
// public void setDetails(RaygunMessageDetails details) {
// this.details = details;
// }
//
// public String getOccurredOn() {
// return occurredOn;
// }
//
// public void setOccurredOn(String occurredOn) {
// this.occurredOn = occurredOn;
// }
// }
| import android.content.Context;
import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbMessage;
import com.raygun.raygun4android.messages.crashreporting.RaygunMessage;
import java.util.List;
import java.util.Map; | package com.raygun.raygun4android;
public interface IRaygunMessageBuilder {
RaygunMessage build();
IRaygunMessageBuilder setMachineName(String machineName);
IRaygunMessageBuilder setExceptionDetails(Throwable throwable);
IRaygunMessageBuilder setClientDetails();
IRaygunMessageBuilder setEnvironmentDetails(Context context);
IRaygunMessageBuilder setVersion(String version);
IRaygunMessageBuilder setTags(List tags);
IRaygunMessageBuilder setCustomData(Map customData);
IRaygunMessageBuilder setAppContext(String identifier);
IRaygunMessageBuilder setUserInfo();
IRaygunMessageBuilder setNetworkInfo(Context context);
IRaygunMessageBuilder setGroupingKey(String groupingKey);
| // Path: provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunBreadcrumbMessage.java
// public class RaygunBreadcrumbMessage {
// private String message;
// private String category;
// private int level;
// private String type = "Manual";
// private Map<String, Object> customData;
// private Long timestamp = System.currentTimeMillis();
// private String className;
// private String methodName;
// private Integer lineNumber;
//
// public static class Builder {
// private String message;
// private String category;
// private int level = RaygunBreadcrumbLevel.INFO.ordinal();
// private Map<String, Object> customData = new WeakHashMap<>();
// private String className;
// private String methodName;
// private Integer lineNumber;
//
// public Builder(String message) {
// this.message = message;
// }
//
// public Builder category(String category) {
// this.category = category;
// return this;
// }
//
// public Builder level(RaygunBreadcrumbLevel level) {
// this.level = level.ordinal();
// return this;
// }
//
// public Builder customData(Map<String, Object> customData) {
// this.customData = customData;
// return this;
// }
//
// public Builder className(String className) {
// this.className = className;
// return this;
// }
//
// public Builder methodName(String methodName) {
// this.methodName = methodName;
// return this;
// }
//
// public Builder lineNumber(Integer lineNumber) {
// this.lineNumber = lineNumber;
// return this;
// }
//
// public RaygunBreadcrumbMessage build() {
// return new RaygunBreadcrumbMessage(this);
// }
// }
//
// public String getMessage() {
// return message;
// }
//
// public String getCategory() {
// return category;
// }
//
// public RaygunBreadcrumbLevel getLevel() {
// return RaygunBreadcrumbLevel.values()[level];
// }
//
// public Map<String, Object> getCustomData() {
// return customData;
// }
//
// public String getClassName() {
// return className;
// }
//
// public String getMethodName() {
// return methodName;
// }
//
// public Integer getLineNumber() {
// return lineNumber;
// }
//
// private RaygunBreadcrumbMessage(Builder builder) {
// message = builder.message;
// category = builder.category;
// level = builder.level;
// customData = builder.customData;
// className = builder.className;
// methodName = builder.methodName;
// lineNumber = builder.lineNumber;
// }
// }
//
// Path: provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessage.java
// public class RaygunMessage {
// private String occurredOn;
// private RaygunMessageDetails details;
//
// public RaygunMessage() {
// details = new RaygunMessageDetails();
//
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// LocalDateTime utcDateTime = LocalDateTime.now(ZoneId.of("UTC"));
// occurredOn = utcDateTime.toString();
// } else {
// @SuppressLint("SimpleDateFormat") SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
// df.setTimeZone(TimeZone.getTimeZone("UTC"));
// occurredOn = df.format(Calendar.getInstance().getTime());
// }
// }
//
// public RaygunMessageDetails getDetails() {
// return details;
// }
//
// public void setDetails(RaygunMessageDetails details) {
// this.details = details;
// }
//
// public String getOccurredOn() {
// return occurredOn;
// }
//
// public void setOccurredOn(String occurredOn) {
// this.occurredOn = occurredOn;
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/IRaygunMessageBuilder.java
import android.content.Context;
import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbMessage;
import com.raygun.raygun4android.messages.crashreporting.RaygunMessage;
import java.util.List;
import java.util.Map;
package com.raygun.raygun4android;
public interface IRaygunMessageBuilder {
RaygunMessage build();
IRaygunMessageBuilder setMachineName(String machineName);
IRaygunMessageBuilder setExceptionDetails(Throwable throwable);
IRaygunMessageBuilder setClientDetails();
IRaygunMessageBuilder setEnvironmentDetails(Context context);
IRaygunMessageBuilder setVersion(String version);
IRaygunMessageBuilder setTags(List tags);
IRaygunMessageBuilder setCustomData(Map customData);
IRaygunMessageBuilder setAppContext(String identifier);
IRaygunMessageBuilder setUserInfo();
IRaygunMessageBuilder setNetworkInfo(Context context);
IRaygunMessageBuilder setGroupingKey(String groupingKey);
| IRaygunMessageBuilder setBreadcrumbs(List<RaygunBreadcrumbMessage> breadcrumbs); |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileFilter.java | // Path: provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java
// public class RaygunSettings {
//
// // General
// public static final String APIKEY_MANIFEST_FIELD = "com.raygun.raygun4android.apikey";
// public static final String RAYGUN_CLIENT_VERSION = BuildConfig.VERSION_NAME;
// public static final String LOGGING_TAG = "Raygun4Android";
//
// // HTTP error response codes
// public static final int RESPONSE_CODE_ACCEPTED = 202;
// public static final int RESPONSE_CODE_BAD_MESSAGE = 400;
// public static final int RESPONSE_CODE_INVALID_API_KEY = 403;
// public static final int RESPONSE_CODE_LARGE_PAYLOAD = 413;
// public static final int RESPONSE_CODE_RATE_LIMITED = 429;
//
// // Crash Reporting
// public static final String DEFAULT_CRASHREPORTING_ENDPOINT = "https://api.raygun.io/entries";
// public static final String DEFAULT_FILE_EXTENSION = "raygun4";
// public static final int DEFAULT_MAX_REPORTS_STORED_ON_DEVICE = 64;
// public static final String CRASH_REPORTING_UNHANDLED_EXCEPTION_TAG = "UnhandledException";
//
// // RUM
// public static final String RUM_EVENT_SESSION_START = "session_start";
// public static final String RUM_EVENT_SESSION_END = "session_end";
// public static final String RUM_EVENT_TIMING = "mobile_event_timing";
// public static final String DEFAULT_RUM_ENDPOINT = "https://api.raygun.io/events";
// // 30 minutes in milliseconds
// public static final int RUM_SESSION_EXPIRY = 30 * 60 * 1000;
//
// private static IgnoredURLs ignoredURLs = new IgnoredURLs("api.raygun.io");
// private static HashSet<String> ignoredViews = new HashSet<>();
// private static int maxReportsStoredOnDevice = DEFAULT_MAX_REPORTS_STORED_ON_DEVICE;
// private static String crashReportingEndpoint = DEFAULT_CRASHREPORTING_ENDPOINT;
// private static String rumEndpoint = DEFAULT_RUM_ENDPOINT;
//
// private RaygunSettings() {
// }
//
// public static String getCrashReportingEndpoint() {
// return crashReportingEndpoint;
// }
//
// static void setCrashReportingEndpoint(String crashReportingEndpoint) {
// RaygunSettings.crashReportingEndpoint = crashReportingEndpoint;
// }
//
// public static String getRUMEndpoint() {
// return rumEndpoint;
// }
//
// static void setRUMEndpoint(String rumEndpoint) {
// RaygunSettings.rumEndpoint = rumEndpoint;
// }
//
// public static HashSet<String> getIgnoredURLs() {
// return ignoredURLs;
// }
//
// static HashSet<String> getIgnoredViews() {
// return ignoredViews;
// }
//
// public static int getMaxReportsStoredOnDevice() {
// return maxReportsStoredOnDevice;
// }
//
// static void setMaxReportsStoredOnDevice(int maxReportsStoredOnDevice) {
// if (maxReportsStoredOnDevice <= DEFAULT_MAX_REPORTS_STORED_ON_DEVICE) {
// RaygunSettings.maxReportsStoredOnDevice = maxReportsStoredOnDevice;
// } else {
// RaygunLogger.w("It's not possible to exceed the value " + DEFAULT_MAX_REPORTS_STORED_ON_DEVICE + " for the number of reports stored on the device. The setting has not been applied.");
// }
// }
//
// public static class IgnoredURLs extends HashSet<String> {
// IgnoredURLs(String... defaultIgnoredUrls) {
// this.addAll(Arrays.asList(defaultIgnoredUrls));
// }
// }
//
// static void ignoreURLs(String[] urls) {
// if (urls != null) {
// for (String url : urls) {
// if (url != null) {
// RaygunSettings.ignoredURLs.add(url);
// }
// }
// }
// }
//
// static void ignoreViews(String[] views) {
// if (views != null) {
// for (String view : views) {
// if (view != null) {
// RaygunSettings.ignoredViews.add(view);
// }
// }
// }
// }
// }
| import com.raygun.raygun4android.RaygunSettings;
import java.io.File;
import java.io.FileFilter; | package com.raygun.raygun4android.utils;
public class RaygunFileFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
| // Path: provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java
// public class RaygunSettings {
//
// // General
// public static final String APIKEY_MANIFEST_FIELD = "com.raygun.raygun4android.apikey";
// public static final String RAYGUN_CLIENT_VERSION = BuildConfig.VERSION_NAME;
// public static final String LOGGING_TAG = "Raygun4Android";
//
// // HTTP error response codes
// public static final int RESPONSE_CODE_ACCEPTED = 202;
// public static final int RESPONSE_CODE_BAD_MESSAGE = 400;
// public static final int RESPONSE_CODE_INVALID_API_KEY = 403;
// public static final int RESPONSE_CODE_LARGE_PAYLOAD = 413;
// public static final int RESPONSE_CODE_RATE_LIMITED = 429;
//
// // Crash Reporting
// public static final String DEFAULT_CRASHREPORTING_ENDPOINT = "https://api.raygun.io/entries";
// public static final String DEFAULT_FILE_EXTENSION = "raygun4";
// public static final int DEFAULT_MAX_REPORTS_STORED_ON_DEVICE = 64;
// public static final String CRASH_REPORTING_UNHANDLED_EXCEPTION_TAG = "UnhandledException";
//
// // RUM
// public static final String RUM_EVENT_SESSION_START = "session_start";
// public static final String RUM_EVENT_SESSION_END = "session_end";
// public static final String RUM_EVENT_TIMING = "mobile_event_timing";
// public static final String DEFAULT_RUM_ENDPOINT = "https://api.raygun.io/events";
// // 30 minutes in milliseconds
// public static final int RUM_SESSION_EXPIRY = 30 * 60 * 1000;
//
// private static IgnoredURLs ignoredURLs = new IgnoredURLs("api.raygun.io");
// private static HashSet<String> ignoredViews = new HashSet<>();
// private static int maxReportsStoredOnDevice = DEFAULT_MAX_REPORTS_STORED_ON_DEVICE;
// private static String crashReportingEndpoint = DEFAULT_CRASHREPORTING_ENDPOINT;
// private static String rumEndpoint = DEFAULT_RUM_ENDPOINT;
//
// private RaygunSettings() {
// }
//
// public static String getCrashReportingEndpoint() {
// return crashReportingEndpoint;
// }
//
// static void setCrashReportingEndpoint(String crashReportingEndpoint) {
// RaygunSettings.crashReportingEndpoint = crashReportingEndpoint;
// }
//
// public static String getRUMEndpoint() {
// return rumEndpoint;
// }
//
// static void setRUMEndpoint(String rumEndpoint) {
// RaygunSettings.rumEndpoint = rumEndpoint;
// }
//
// public static HashSet<String> getIgnoredURLs() {
// return ignoredURLs;
// }
//
// static HashSet<String> getIgnoredViews() {
// return ignoredViews;
// }
//
// public static int getMaxReportsStoredOnDevice() {
// return maxReportsStoredOnDevice;
// }
//
// static void setMaxReportsStoredOnDevice(int maxReportsStoredOnDevice) {
// if (maxReportsStoredOnDevice <= DEFAULT_MAX_REPORTS_STORED_ON_DEVICE) {
// RaygunSettings.maxReportsStoredOnDevice = maxReportsStoredOnDevice;
// } else {
// RaygunLogger.w("It's not possible to exceed the value " + DEFAULT_MAX_REPORTS_STORED_ON_DEVICE + " for the number of reports stored on the device. The setting has not been applied.");
// }
// }
//
// public static class IgnoredURLs extends HashSet<String> {
// IgnoredURLs(String... defaultIgnoredUrls) {
// this.addAll(Arrays.asList(defaultIgnoredUrls));
// }
// }
//
// static void ignoreURLs(String[] urls) {
// if (urls != null) {
// for (String url : urls) {
// if (url != null) {
// RaygunSettings.ignoredURLs.add(url);
// }
// }
// }
// }
//
// static void ignoreViews(String[] views) {
// if (views != null) {
// for (String view : views) {
// if (view != null) {
// RaygunSettings.ignoredViews.add(view);
// }
// }
// }
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/utils/RaygunFileFilter.java
import com.raygun.raygun4android.RaygunSettings;
import java.io.File;
import java.io.FileFilter;
package com.raygun.raygun4android.utils;
public class RaygunFileFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
| String extension = "." + RaygunSettings.DEFAULT_FILE_EXTENSION; |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/services/RaygunPostService.java | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
//
// Path: provider/src/debug/java/com/raygun/raygun4android/logging/TimberRaygunLoggerImplementation.java
// public class TimberRaygunLoggerImplementation implements TimberRaygunLogger {
//
// public static void init() {
// if (Timber.treeCount() == 0) {
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
| import android.support.v4.app.JobIntentService;
import com.raygun.raygun4android.logging.RaygunLogger;
import com.raygun.raygun4android.logging.TimberRaygunLoggerImplementation; | package com.raygun.raygun4android.services;
/**
* A JobIntentService that can validate Raygun API keys
*/
public abstract class RaygunPostService extends JobIntentService {
/**
* Validation to check if an API key has been supplied to the service
*
* @param apiKey The API key of the app to deliver to
* @return true or false
*/
static Boolean validateApiKey(String apiKey) {
if (apiKey.length() == 0) { | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
//
// Path: provider/src/debug/java/com/raygun/raygun4android/logging/TimberRaygunLoggerImplementation.java
// public class TimberRaygunLoggerImplementation implements TimberRaygunLogger {
//
// public static void init() {
// if (Timber.treeCount() == 0) {
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/services/RaygunPostService.java
import android.support.v4.app.JobIntentService;
import com.raygun.raygun4android.logging.RaygunLogger;
import com.raygun.raygun4android.logging.TimberRaygunLoggerImplementation;
package com.raygun.raygun4android.services;
/**
* A JobIntentService that can validate Raygun API keys
*/
public abstract class RaygunPostService extends JobIntentService {
/**
* Validation to check if an API key has been supplied to the service
*
* @param apiKey The API key of the app to deliver to
* @return true or false
*/
static Boolean validateApiKey(String apiKey) {
if (apiKey.length() == 0) { | RaygunLogger.e("API key is empty, nothing will be logged or reported"); |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/services/RaygunPostService.java | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
//
// Path: provider/src/debug/java/com/raygun/raygun4android/logging/TimberRaygunLoggerImplementation.java
// public class TimberRaygunLoggerImplementation implements TimberRaygunLogger {
//
// public static void init() {
// if (Timber.treeCount() == 0) {
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
| import android.support.v4.app.JobIntentService;
import com.raygun.raygun4android.logging.RaygunLogger;
import com.raygun.raygun4android.logging.TimberRaygunLoggerImplementation; | package com.raygun.raygun4android.services;
/**
* A JobIntentService that can validate Raygun API keys
*/
public abstract class RaygunPostService extends JobIntentService {
/**
* Validation to check if an API key has been supplied to the service
*
* @param apiKey The API key of the app to deliver to
* @return true or false
*/
static Boolean validateApiKey(String apiKey) {
if (apiKey.length() == 0) {
RaygunLogger.e("API key is empty, nothing will be logged or reported");
return false;
} else {
return true;
}
}
@Override
public void onCreate() {
super.onCreate();
| // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
//
// Path: provider/src/debug/java/com/raygun/raygun4android/logging/TimberRaygunLoggerImplementation.java
// public class TimberRaygunLoggerImplementation implements TimberRaygunLogger {
//
// public static void init() {
// if (Timber.treeCount() == 0) {
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/services/RaygunPostService.java
import android.support.v4.app.JobIntentService;
import com.raygun.raygun4android.logging.RaygunLogger;
import com.raygun.raygun4android.logging.TimberRaygunLoggerImplementation;
package com.raygun.raygun4android.services;
/**
* A JobIntentService that can validate Raygun API keys
*/
public abstract class RaygunPostService extends JobIntentService {
/**
* Validation to check if an API key has been supplied to the service
*
* @param apiKey The API key of the app to deliver to
* @return true or false
*/
static Boolean validateApiKey(String apiKey) {
if (apiKey.length() == 0) {
RaygunLogger.e("API key is empty, nothing will be logged or reported");
return false;
} else {
return true;
}
}
@Override
public void onCreate() {
super.onCreate();
| TimberRaygunLoggerImplementation.init(); |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessageDetails.java | // Path: provider/src/main/java/com/raygun/raygun4android/messages/shared/RaygunUserInfo.java
// public class RaygunUserInfo {
//
// private Boolean isAnonymous;
// private String email;
// private String fullName;
// private String firstName;
// private String identifier;
//
// /**
// * Set the current user's info to be transmitted - any parameter can be null if the data is not available or you do not wish to send it.
// *
// * @param firstName The user's first name
// * @param fullName The user's full name - if setting the first name you should set this too
// * @param email User's email address
// * @param identifier Unique identifier for this user. Set this to the internal identifier you use to look up users,
// * or a correlation ID for anonymous users if you have one. It doesn't have to be unique, but we will treat
// * any duplicated values as the same user. If you use their email address here, pass it in as the 'emailAddress' parameter too.
// * If identifier is not set and/or null, a uuid will be assigned to this field.
// */
// public RaygunUserInfo(String identifier, String firstName, String fullName, String email) {
// if (isValidUser(identifier)) {
// this.firstName = firstName;
// this.fullName = fullName;
// this.email = email;
// } else {
// RaygunLogger.i("Ignored firstName, fullName and email because created user was deemed anonymous");
// }
// }
//
// /**
// * Convenience constructor to be used if you only want to supply an identifier string for the user.
// *
// * @param identifier Unique identifier for this user. Set this to the internal identifier you use to look up users,
// * or a correlation ID for anonymous users if you have one. It doesn't have to be unique, but we will treat
// * any duplicated values as the same user. If you use their email address here, please use the full constructor and pass it
// * in as the 'emailAddress' parameter too.
// * If identifier is not set and/or null, a uuid will be assigned to this field.
// */
// public RaygunUserInfo(String identifier) {
// isValidUser(identifier);
// }
//
// public RaygunUserInfo() {
// this.identifier = RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext());
// this.isAnonymous = true;
// }
//
// public Boolean getIsAnonymous() {
// return this.isAnonymous;
// }
//
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// if (!getIsAnonymous()) {
// this.email = email;
// } else {
// RaygunLogger.i("Ignored email because current user was deemed anonymous");
// }
// }
//
// public String getFullName() {
// return this.fullName;
// }
//
// public void setFullName(String fullName) {
// if (!getIsAnonymous()) {
// this.fullName = fullName;
// } else {
// RaygunLogger.i("Ignored fullName because current user was deemed anonymous");
// }
// }
//
// public String getFirstName() {
// return this.firstName;
// }
//
// public void setFirstName(String firstName) {
// if (!getIsAnonymous()) {
// this.firstName = firstName;
// } else {
// RaygunLogger.i("Ignored firstName because current user was deemed anonymous");
// }
// }
//
// public String getIdentifier() {
// return this.identifier;
// }
//
// private Boolean isValidUser(String identifier) {
// if (identifier == null || identifier.isEmpty()) {
// this.identifier = RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext());
// this.isAnonymous = true;
// RaygunLogger.i("Created anonymous user");
// return false;
// } else {
// this.identifier = identifier;
// this.isAnonymous = false;
// return true;
// }
// }
// }
| import android.content.Context;
import com.google.gson.annotations.SerializedName;
import com.raygun.raygun4android.messages.shared.RaygunUserInfo;
import java.util.List;
import java.util.Map; | package com.raygun.raygun4android.messages.crashreporting;
public class RaygunMessageDetails {
private String groupingKey;
private String machineName;
private String version = "Not supplied";
private RaygunErrorMessage error;
private RaygunEnvironmentMessage environment;
private RaygunClientMessage client;
private List tags;
@SerializedName("userCustomData")
private Map customData;
private RaygunAppContext context; | // Path: provider/src/main/java/com/raygun/raygun4android/messages/shared/RaygunUserInfo.java
// public class RaygunUserInfo {
//
// private Boolean isAnonymous;
// private String email;
// private String fullName;
// private String firstName;
// private String identifier;
//
// /**
// * Set the current user's info to be transmitted - any parameter can be null if the data is not available or you do not wish to send it.
// *
// * @param firstName The user's first name
// * @param fullName The user's full name - if setting the first name you should set this too
// * @param email User's email address
// * @param identifier Unique identifier for this user. Set this to the internal identifier you use to look up users,
// * or a correlation ID for anonymous users if you have one. It doesn't have to be unique, but we will treat
// * any duplicated values as the same user. If you use their email address here, pass it in as the 'emailAddress' parameter too.
// * If identifier is not set and/or null, a uuid will be assigned to this field.
// */
// public RaygunUserInfo(String identifier, String firstName, String fullName, String email) {
// if (isValidUser(identifier)) {
// this.firstName = firstName;
// this.fullName = fullName;
// this.email = email;
// } else {
// RaygunLogger.i("Ignored firstName, fullName and email because created user was deemed anonymous");
// }
// }
//
// /**
// * Convenience constructor to be used if you only want to supply an identifier string for the user.
// *
// * @param identifier Unique identifier for this user. Set this to the internal identifier you use to look up users,
// * or a correlation ID for anonymous users if you have one. It doesn't have to be unique, but we will treat
// * any duplicated values as the same user. If you use their email address here, please use the full constructor and pass it
// * in as the 'emailAddress' parameter too.
// * If identifier is not set and/or null, a uuid will be assigned to this field.
// */
// public RaygunUserInfo(String identifier) {
// isValidUser(identifier);
// }
//
// public RaygunUserInfo() {
// this.identifier = RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext());
// this.isAnonymous = true;
// }
//
// public Boolean getIsAnonymous() {
// return this.isAnonymous;
// }
//
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// if (!getIsAnonymous()) {
// this.email = email;
// } else {
// RaygunLogger.i("Ignored email because current user was deemed anonymous");
// }
// }
//
// public String getFullName() {
// return this.fullName;
// }
//
// public void setFullName(String fullName) {
// if (!getIsAnonymous()) {
// this.fullName = fullName;
// } else {
// RaygunLogger.i("Ignored fullName because current user was deemed anonymous");
// }
// }
//
// public String getFirstName() {
// return this.firstName;
// }
//
// public void setFirstName(String firstName) {
// if (!getIsAnonymous()) {
// this.firstName = firstName;
// } else {
// RaygunLogger.i("Ignored firstName because current user was deemed anonymous");
// }
// }
//
// public String getIdentifier() {
// return this.identifier;
// }
//
// private Boolean isValidUser(String identifier) {
// if (identifier == null || identifier.isEmpty()) {
// this.identifier = RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext());
// this.isAnonymous = true;
// RaygunLogger.i("Created anonymous user");
// return false;
// } else {
// this.identifier = identifier;
// this.isAnonymous = false;
// return true;
// }
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunMessageDetails.java
import android.content.Context;
import com.google.gson.annotations.SerializedName;
import com.raygun.raygun4android.messages.shared.RaygunUserInfo;
import java.util.List;
import java.util.Map;
package com.raygun.raygun4android.messages.crashreporting;
public class RaygunMessageDetails {
private String groupingKey;
private String machineName;
private String version = "Not supplied";
private RaygunErrorMessage error;
private RaygunEnvironmentMessage environment;
private RaygunClientMessage client;
private List tags;
@SerializedName("userCustomData")
private Map customData;
private RaygunAppContext context; | private RaygunUserInfo user; |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
| import com.raygun.raygun4android.logging.RaygunLogger;
import java.util.Arrays;
import java.util.HashSet; | }
static void setCrashReportingEndpoint(String crashReportingEndpoint) {
RaygunSettings.crashReportingEndpoint = crashReportingEndpoint;
}
public static String getRUMEndpoint() {
return rumEndpoint;
}
static void setRUMEndpoint(String rumEndpoint) {
RaygunSettings.rumEndpoint = rumEndpoint;
}
public static HashSet<String> getIgnoredURLs() {
return ignoredURLs;
}
static HashSet<String> getIgnoredViews() {
return ignoredViews;
}
public static int getMaxReportsStoredOnDevice() {
return maxReportsStoredOnDevice;
}
static void setMaxReportsStoredOnDevice(int maxReportsStoredOnDevice) {
if (maxReportsStoredOnDevice <= DEFAULT_MAX_REPORTS_STORED_ON_DEVICE) {
RaygunSettings.maxReportsStoredOnDevice = maxReportsStoredOnDevice;
} else { | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
// Path: provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java
import com.raygun.raygun4android.logging.RaygunLogger;
import java.util.Arrays;
import java.util.HashSet;
}
static void setCrashReportingEndpoint(String crashReportingEndpoint) {
RaygunSettings.crashReportingEndpoint = crashReportingEndpoint;
}
public static String getRUMEndpoint() {
return rumEndpoint;
}
static void setRUMEndpoint(String rumEndpoint) {
RaygunSettings.rumEndpoint = rumEndpoint;
}
public static HashSet<String> getIgnoredURLs() {
return ignoredURLs;
}
static HashSet<String> getIgnoredViews() {
return ignoredViews;
}
public static int getMaxReportsStoredOnDevice() {
return maxReportsStoredOnDevice;
}
static void setMaxReportsStoredOnDevice(int maxReportsStoredOnDevice) {
if (maxReportsStoredOnDevice <= DEFAULT_MAX_REPORTS_STORED_ON_DEVICE) {
RaygunSettings.maxReportsStoredOnDevice = maxReportsStoredOnDevice;
} else { | RaygunLogger.w("It's not possible to exceed the value " + DEFAULT_MAX_REPORTS_STORED_ON_DEVICE + " for the number of reports stored on the device. The setting has not been applied."); |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlStreamHandler.java | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
//
// Path: provider/src/main/java/com/raygun/raygun4android/utils/RaygunReflectionUtils.java
// public class RaygunReflectionUtils {
// public static Method findMethod(Class<?> clazz, String methodName, Class<?>[] args) throws NoSuchMethodException {
// Method methodMatched = null;
//
// for (Method m : getAllMethods(clazz)) {
//
// if (m.getName().equals(methodName)) {
// Class<?>[] paramClasses = m.getParameterTypes();
//
// if (paramClasses.length == args.length) {
// boolean paramsMatch = true;
//
// for (int i = 0; i < paramClasses.length; ++i) {
// Class<?> paramType = paramClasses[i];
// paramType = convertPrimitiveClass(paramType);
//
// if (paramType != args[i]) {
// paramsMatch = false;
// break;
// }
// }
//
// if (paramsMatch) {
// methodMatched = m;
// break;
// }
// }
// }
// }
//
// if (methodMatched != null) {
// return methodMatched;
// } else {
// throw new NoSuchMethodException("Cannot find method: " + methodName);
// }
// }
//
// private static Collection<Method> getAllMethods(Class<?> clazz) {
// HashSet<Method> methods = new HashSet<Method>();
//
// methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
//
// for (Class<?> s : getAllSuperClasses(clazz)) {
// methods.addAll(Arrays.asList(s.getDeclaredMethods()));
// }
//
// return methods;
// }
//
// private static Collection<Class<?>> getAllSuperClasses(Class<?> clazz) {
// HashSet<Class<?>> classes = new HashSet<Class<?>>();
//
// if ((clazz != null) && (!clazz.equals(Object.class))) {
// classes.add(clazz);
// classes.addAll(getAllSuperClasses(clazz.getSuperclass()));
//
// for (Class<?> i : clazz.getInterfaces()) {
// classes.addAll(getAllSuperClasses(i));
// }
// }
// return classes;
// }
//
// private static Class<?> convertPrimitiveClass(Class<?> primitive) {
// if (primitive.isPrimitive()) {
// if (primitive == Integer.TYPE) {
// return Integer.class;
// }
// if (primitive == Boolean.TYPE) {
// return Boolean.class;
// }
// if (primitive == Float.TYPE) {
// return Float.class;
// }
// if (primitive == Long.TYPE) {
// return Long.class;
// }
// if (primitive == Double.TYPE) {
// return Double.class;
// }
// if (primitive == Short.TYPE) {
// return Short.class;
// }
// if (primitive == Byte.TYPE) {
// return Byte.class;
// }
// if (primitive == Character.TYPE) {
// return Character.class;
// }
// }
// return primitive;
// }
// }
| import com.raygun.raygun4android.logging.RaygunLogger;
import com.raygun.raygun4android.utils.RaygunReflectionUtils;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler; | package com.raygun.raygun4android.network.http;
final class RaygunHttpUrlStreamHandler extends URLStreamHandler {
private static final int PORT = 80;
private static final String PROTOCOL = "http";
private URLStreamHandler originalHandler;
RaygunHttpUrlStreamHandler(URLStreamHandler handler) {
originalHandler = handler;
}
protected URLConnection openConnection(URL url) throws IOException {
try { | // Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
// public class RaygunLogger {
//
// public static void d(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).d(string);
// }
// }
//
// public static void i(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).i(string);
// }
// }
//
// public static void w(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).w(string);
// }
// }
//
// public static void e(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).e(string);
// }
// }
//
// public static void v(String string) {
// if (string != null) {
// Timber.tag(RaygunSettings.LOGGING_TAG).v(string);
// }
// }
//
// public static void responseCode(int responseCode) {
// switch (responseCode) {
// case RaygunSettings.RESPONSE_CODE_ACCEPTED:
// RaygunLogger.d("Request succeeded");
// break;
// case RaygunSettings.RESPONSE_CODE_BAD_MESSAGE:
// RaygunLogger.e("Bad message - could not parse the provided JSON. Check all fields are present, especially both occurredOn (ISO 8601 DateTime) and details { } at the top level");
// break;
// case RaygunSettings.RESPONSE_CODE_INVALID_API_KEY:
// RaygunLogger.e("Invalid API Key - The value specified in the header X-ApiKey did not match with an application in Raygun");
// break;
// case RaygunSettings.RESPONSE_CODE_LARGE_PAYLOAD:
// RaygunLogger.e("Request entity too large - The maximum size of a JSON payload is 128KB");
// break;
// case RaygunSettings.RESPONSE_CODE_RATE_LIMITED:
// RaygunLogger.e("Too Many Requests - Plan limit exceeded for month or plan expired");
// break;
// default:
// RaygunLogger.d("Response status code: " + responseCode);
//
// }
// }
//
// }
//
// Path: provider/src/main/java/com/raygun/raygun4android/utils/RaygunReflectionUtils.java
// public class RaygunReflectionUtils {
// public static Method findMethod(Class<?> clazz, String methodName, Class<?>[] args) throws NoSuchMethodException {
// Method methodMatched = null;
//
// for (Method m : getAllMethods(clazz)) {
//
// if (m.getName().equals(methodName)) {
// Class<?>[] paramClasses = m.getParameterTypes();
//
// if (paramClasses.length == args.length) {
// boolean paramsMatch = true;
//
// for (int i = 0; i < paramClasses.length; ++i) {
// Class<?> paramType = paramClasses[i];
// paramType = convertPrimitiveClass(paramType);
//
// if (paramType != args[i]) {
// paramsMatch = false;
// break;
// }
// }
//
// if (paramsMatch) {
// methodMatched = m;
// break;
// }
// }
// }
// }
//
// if (methodMatched != null) {
// return methodMatched;
// } else {
// throw new NoSuchMethodException("Cannot find method: " + methodName);
// }
// }
//
// private static Collection<Method> getAllMethods(Class<?> clazz) {
// HashSet<Method> methods = new HashSet<Method>();
//
// methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
//
// for (Class<?> s : getAllSuperClasses(clazz)) {
// methods.addAll(Arrays.asList(s.getDeclaredMethods()));
// }
//
// return methods;
// }
//
// private static Collection<Class<?>> getAllSuperClasses(Class<?> clazz) {
// HashSet<Class<?>> classes = new HashSet<Class<?>>();
//
// if ((clazz != null) && (!clazz.equals(Object.class))) {
// classes.add(clazz);
// classes.addAll(getAllSuperClasses(clazz.getSuperclass()));
//
// for (Class<?> i : clazz.getInterfaces()) {
// classes.addAll(getAllSuperClasses(i));
// }
// }
// return classes;
// }
//
// private static Class<?> convertPrimitiveClass(Class<?> primitive) {
// if (primitive.isPrimitive()) {
// if (primitive == Integer.TYPE) {
// return Integer.class;
// }
// if (primitive == Boolean.TYPE) {
// return Boolean.class;
// }
// if (primitive == Float.TYPE) {
// return Float.class;
// }
// if (primitive == Long.TYPE) {
// return Long.class;
// }
// if (primitive == Double.TYPE) {
// return Double.class;
// }
// if (primitive == Short.TYPE) {
// return Short.class;
// }
// if (primitive == Byte.TYPE) {
// return Byte.class;
// }
// if (primitive == Character.TYPE) {
// return Character.class;
// }
// }
// return primitive;
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/network/http/RaygunHttpUrlStreamHandler.java
import com.raygun.raygun4android.logging.RaygunLogger;
import com.raygun.raygun4android.utils.RaygunReflectionUtils;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
package com.raygun.raygun4android.network.http;
final class RaygunHttpUrlStreamHandler extends URLStreamHandler {
private static final int PORT = 80;
private static final String PROTOCOL = "http";
private URLStreamHandler originalHandler;
RaygunHttpUrlStreamHandler(URLStreamHandler handler) {
originalHandler = handler;
}
protected URLConnection openConnection(URL url) throws IOException {
try { | Method method = RaygunReflectionUtils.findMethod(originalHandler.getClass(), "openConnection", new Class<?>[]{URL.class}); |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java | // Path: provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java
// public class RaygunSettings {
//
// // General
// public static final String APIKEY_MANIFEST_FIELD = "com.raygun.raygun4android.apikey";
// public static final String RAYGUN_CLIENT_VERSION = BuildConfig.VERSION_NAME;
// public static final String LOGGING_TAG = "Raygun4Android";
//
// // HTTP error response codes
// public static final int RESPONSE_CODE_ACCEPTED = 202;
// public static final int RESPONSE_CODE_BAD_MESSAGE = 400;
// public static final int RESPONSE_CODE_INVALID_API_KEY = 403;
// public static final int RESPONSE_CODE_LARGE_PAYLOAD = 413;
// public static final int RESPONSE_CODE_RATE_LIMITED = 429;
//
// // Crash Reporting
// public static final String DEFAULT_CRASHREPORTING_ENDPOINT = "https://api.raygun.io/entries";
// public static final String DEFAULT_FILE_EXTENSION = "raygun4";
// public static final int DEFAULT_MAX_REPORTS_STORED_ON_DEVICE = 64;
// public static final String CRASH_REPORTING_UNHANDLED_EXCEPTION_TAG = "UnhandledException";
//
// // RUM
// public static final String RUM_EVENT_SESSION_START = "session_start";
// public static final String RUM_EVENT_SESSION_END = "session_end";
// public static final String RUM_EVENT_TIMING = "mobile_event_timing";
// public static final String DEFAULT_RUM_ENDPOINT = "https://api.raygun.io/events";
// // 30 minutes in milliseconds
// public static final int RUM_SESSION_EXPIRY = 30 * 60 * 1000;
//
// private static IgnoredURLs ignoredURLs = new IgnoredURLs("api.raygun.io");
// private static HashSet<String> ignoredViews = new HashSet<>();
// private static int maxReportsStoredOnDevice = DEFAULT_MAX_REPORTS_STORED_ON_DEVICE;
// private static String crashReportingEndpoint = DEFAULT_CRASHREPORTING_ENDPOINT;
// private static String rumEndpoint = DEFAULT_RUM_ENDPOINT;
//
// private RaygunSettings() {
// }
//
// public static String getCrashReportingEndpoint() {
// return crashReportingEndpoint;
// }
//
// static void setCrashReportingEndpoint(String crashReportingEndpoint) {
// RaygunSettings.crashReportingEndpoint = crashReportingEndpoint;
// }
//
// public static String getRUMEndpoint() {
// return rumEndpoint;
// }
//
// static void setRUMEndpoint(String rumEndpoint) {
// RaygunSettings.rumEndpoint = rumEndpoint;
// }
//
// public static HashSet<String> getIgnoredURLs() {
// return ignoredURLs;
// }
//
// static HashSet<String> getIgnoredViews() {
// return ignoredViews;
// }
//
// public static int getMaxReportsStoredOnDevice() {
// return maxReportsStoredOnDevice;
// }
//
// static void setMaxReportsStoredOnDevice(int maxReportsStoredOnDevice) {
// if (maxReportsStoredOnDevice <= DEFAULT_MAX_REPORTS_STORED_ON_DEVICE) {
// RaygunSettings.maxReportsStoredOnDevice = maxReportsStoredOnDevice;
// } else {
// RaygunLogger.w("It's not possible to exceed the value " + DEFAULT_MAX_REPORTS_STORED_ON_DEVICE + " for the number of reports stored on the device. The setting has not been applied.");
// }
// }
//
// public static class IgnoredURLs extends HashSet<String> {
// IgnoredURLs(String... defaultIgnoredUrls) {
// this.addAll(Arrays.asList(defaultIgnoredUrls));
// }
// }
//
// static void ignoreURLs(String[] urls) {
// if (urls != null) {
// for (String url : urls) {
// if (url != null) {
// RaygunSettings.ignoredURLs.add(url);
// }
// }
// }
// }
//
// static void ignoreViews(String[] views) {
// if (views != null) {
// for (String view : views) {
// if (view != null) {
// RaygunSettings.ignoredViews.add(view);
// }
// }
// }
// }
// }
| import com.raygun.raygun4android.RaygunSettings;
import timber.log.Timber; | package com.raygun.raygun4android.logging;
public class RaygunLogger {
public static void d(String string) {
if (string != null) { | // Path: provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java
// public class RaygunSettings {
//
// // General
// public static final String APIKEY_MANIFEST_FIELD = "com.raygun.raygun4android.apikey";
// public static final String RAYGUN_CLIENT_VERSION = BuildConfig.VERSION_NAME;
// public static final String LOGGING_TAG = "Raygun4Android";
//
// // HTTP error response codes
// public static final int RESPONSE_CODE_ACCEPTED = 202;
// public static final int RESPONSE_CODE_BAD_MESSAGE = 400;
// public static final int RESPONSE_CODE_INVALID_API_KEY = 403;
// public static final int RESPONSE_CODE_LARGE_PAYLOAD = 413;
// public static final int RESPONSE_CODE_RATE_LIMITED = 429;
//
// // Crash Reporting
// public static final String DEFAULT_CRASHREPORTING_ENDPOINT = "https://api.raygun.io/entries";
// public static final String DEFAULT_FILE_EXTENSION = "raygun4";
// public static final int DEFAULT_MAX_REPORTS_STORED_ON_DEVICE = 64;
// public static final String CRASH_REPORTING_UNHANDLED_EXCEPTION_TAG = "UnhandledException";
//
// // RUM
// public static final String RUM_EVENT_SESSION_START = "session_start";
// public static final String RUM_EVENT_SESSION_END = "session_end";
// public static final String RUM_EVENT_TIMING = "mobile_event_timing";
// public static final String DEFAULT_RUM_ENDPOINT = "https://api.raygun.io/events";
// // 30 minutes in milliseconds
// public static final int RUM_SESSION_EXPIRY = 30 * 60 * 1000;
//
// private static IgnoredURLs ignoredURLs = new IgnoredURLs("api.raygun.io");
// private static HashSet<String> ignoredViews = new HashSet<>();
// private static int maxReportsStoredOnDevice = DEFAULT_MAX_REPORTS_STORED_ON_DEVICE;
// private static String crashReportingEndpoint = DEFAULT_CRASHREPORTING_ENDPOINT;
// private static String rumEndpoint = DEFAULT_RUM_ENDPOINT;
//
// private RaygunSettings() {
// }
//
// public static String getCrashReportingEndpoint() {
// return crashReportingEndpoint;
// }
//
// static void setCrashReportingEndpoint(String crashReportingEndpoint) {
// RaygunSettings.crashReportingEndpoint = crashReportingEndpoint;
// }
//
// public static String getRUMEndpoint() {
// return rumEndpoint;
// }
//
// static void setRUMEndpoint(String rumEndpoint) {
// RaygunSettings.rumEndpoint = rumEndpoint;
// }
//
// public static HashSet<String> getIgnoredURLs() {
// return ignoredURLs;
// }
//
// static HashSet<String> getIgnoredViews() {
// return ignoredViews;
// }
//
// public static int getMaxReportsStoredOnDevice() {
// return maxReportsStoredOnDevice;
// }
//
// static void setMaxReportsStoredOnDevice(int maxReportsStoredOnDevice) {
// if (maxReportsStoredOnDevice <= DEFAULT_MAX_REPORTS_STORED_ON_DEVICE) {
// RaygunSettings.maxReportsStoredOnDevice = maxReportsStoredOnDevice;
// } else {
// RaygunLogger.w("It's not possible to exceed the value " + DEFAULT_MAX_REPORTS_STORED_ON_DEVICE + " for the number of reports stored on the device. The setting has not been applied.");
// }
// }
//
// public static class IgnoredURLs extends HashSet<String> {
// IgnoredURLs(String... defaultIgnoredUrls) {
// this.addAll(Arrays.asList(defaultIgnoredUrls));
// }
// }
//
// static void ignoreURLs(String[] urls) {
// if (urls != null) {
// for (String url : urls) {
// if (url != null) {
// RaygunSettings.ignoredURLs.add(url);
// }
// }
// }
// }
//
// static void ignoreViews(String[] views) {
// if (views != null) {
// for (String view : views) {
// if (view != null) {
// RaygunSettings.ignoredViews.add(view);
// }
// }
// }
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/logging/RaygunLogger.java
import com.raygun.raygun4android.RaygunSettings;
import timber.log.Timber;
package com.raygun.raygun4android.logging;
public class RaygunLogger {
public static void d(String string) {
if (string != null) { | Timber.tag(RaygunSettings.LOGGING_TAG).d(string); |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/messages/rum/RaygunRUMDataMessage.java | // Path: provider/src/main/java/com/raygun/raygun4android/messages/shared/RaygunUserInfo.java
// public class RaygunUserInfo {
//
// private Boolean isAnonymous;
// private String email;
// private String fullName;
// private String firstName;
// private String identifier;
//
// /**
// * Set the current user's info to be transmitted - any parameter can be null if the data is not available or you do not wish to send it.
// *
// * @param firstName The user's first name
// * @param fullName The user's full name - if setting the first name you should set this too
// * @param email User's email address
// * @param identifier Unique identifier for this user. Set this to the internal identifier you use to look up users,
// * or a correlation ID for anonymous users if you have one. It doesn't have to be unique, but we will treat
// * any duplicated values as the same user. If you use their email address here, pass it in as the 'emailAddress' parameter too.
// * If identifier is not set and/or null, a uuid will be assigned to this field.
// */
// public RaygunUserInfo(String identifier, String firstName, String fullName, String email) {
// if (isValidUser(identifier)) {
// this.firstName = firstName;
// this.fullName = fullName;
// this.email = email;
// } else {
// RaygunLogger.i("Ignored firstName, fullName and email because created user was deemed anonymous");
// }
// }
//
// /**
// * Convenience constructor to be used if you only want to supply an identifier string for the user.
// *
// * @param identifier Unique identifier for this user. Set this to the internal identifier you use to look up users,
// * or a correlation ID for anonymous users if you have one. It doesn't have to be unique, but we will treat
// * any duplicated values as the same user. If you use their email address here, please use the full constructor and pass it
// * in as the 'emailAddress' parameter too.
// * If identifier is not set and/or null, a uuid will be assigned to this field.
// */
// public RaygunUserInfo(String identifier) {
// isValidUser(identifier);
// }
//
// public RaygunUserInfo() {
// this.identifier = RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext());
// this.isAnonymous = true;
// }
//
// public Boolean getIsAnonymous() {
// return this.isAnonymous;
// }
//
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// if (!getIsAnonymous()) {
// this.email = email;
// } else {
// RaygunLogger.i("Ignored email because current user was deemed anonymous");
// }
// }
//
// public String getFullName() {
// return this.fullName;
// }
//
// public void setFullName(String fullName) {
// if (!getIsAnonymous()) {
// this.fullName = fullName;
// } else {
// RaygunLogger.i("Ignored fullName because current user was deemed anonymous");
// }
// }
//
// public String getFirstName() {
// return this.firstName;
// }
//
// public void setFirstName(String firstName) {
// if (!getIsAnonymous()) {
// this.firstName = firstName;
// } else {
// RaygunLogger.i("Ignored firstName because current user was deemed anonymous");
// }
// }
//
// public String getIdentifier() {
// return this.identifier;
// }
//
// private Boolean isValidUser(String identifier) {
// if (identifier == null || identifier.isEmpty()) {
// this.identifier = RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext());
// this.isAnonymous = true;
// RaygunLogger.i("Created anonymous user");
// return false;
// } else {
// this.identifier = identifier;
// this.isAnonymous = false;
// return true;
// }
// }
// }
| import com.raygun.raygun4android.messages.shared.RaygunUserInfo; | package com.raygun.raygun4android.messages.rum;
@SuppressWarnings("FieldCanBeLocal")
public class RaygunRUMDataMessage {
private String sessionId;
private String timestamp;
private String type; | // Path: provider/src/main/java/com/raygun/raygun4android/messages/shared/RaygunUserInfo.java
// public class RaygunUserInfo {
//
// private Boolean isAnonymous;
// private String email;
// private String fullName;
// private String firstName;
// private String identifier;
//
// /**
// * Set the current user's info to be transmitted - any parameter can be null if the data is not available or you do not wish to send it.
// *
// * @param firstName The user's first name
// * @param fullName The user's full name - if setting the first name you should set this too
// * @param email User's email address
// * @param identifier Unique identifier for this user. Set this to the internal identifier you use to look up users,
// * or a correlation ID for anonymous users if you have one. It doesn't have to be unique, but we will treat
// * any duplicated values as the same user. If you use their email address here, pass it in as the 'emailAddress' parameter too.
// * If identifier is not set and/or null, a uuid will be assigned to this field.
// */
// public RaygunUserInfo(String identifier, String firstName, String fullName, String email) {
// if (isValidUser(identifier)) {
// this.firstName = firstName;
// this.fullName = fullName;
// this.email = email;
// } else {
// RaygunLogger.i("Ignored firstName, fullName and email because created user was deemed anonymous");
// }
// }
//
// /**
// * Convenience constructor to be used if you only want to supply an identifier string for the user.
// *
// * @param identifier Unique identifier for this user. Set this to the internal identifier you use to look up users,
// * or a correlation ID for anonymous users if you have one. It doesn't have to be unique, but we will treat
// * any duplicated values as the same user. If you use their email address here, please use the full constructor and pass it
// * in as the 'emailAddress' parameter too.
// * If identifier is not set and/or null, a uuid will be assigned to this field.
// */
// public RaygunUserInfo(String identifier) {
// isValidUser(identifier);
// }
//
// public RaygunUserInfo() {
// this.identifier = RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext());
// this.isAnonymous = true;
// }
//
// public Boolean getIsAnonymous() {
// return this.isAnonymous;
// }
//
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// if (!getIsAnonymous()) {
// this.email = email;
// } else {
// RaygunLogger.i("Ignored email because current user was deemed anonymous");
// }
// }
//
// public String getFullName() {
// return this.fullName;
// }
//
// public void setFullName(String fullName) {
// if (!getIsAnonymous()) {
// this.fullName = fullName;
// } else {
// RaygunLogger.i("Ignored fullName because current user was deemed anonymous");
// }
// }
//
// public String getFirstName() {
// return this.firstName;
// }
//
// public void setFirstName(String firstName) {
// if (!getIsAnonymous()) {
// this.firstName = firstName;
// } else {
// RaygunLogger.i("Ignored firstName because current user was deemed anonymous");
// }
// }
//
// public String getIdentifier() {
// return this.identifier;
// }
//
// private Boolean isValidUser(String identifier) {
// if (identifier == null || identifier.isEmpty()) {
// this.identifier = RaygunNetworkUtils.getDeviceUuid(RaygunClient.getApplicationContext());
// this.isAnonymous = true;
// RaygunLogger.i("Created anonymous user");
// return false;
// } else {
// this.identifier = identifier;
// this.isAnonymous = false;
// return true;
// }
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/messages/rum/RaygunRUMDataMessage.java
import com.raygun.raygun4android.messages.shared.RaygunUserInfo;
package com.raygun.raygun4android.messages.rum;
@SuppressWarnings("FieldCanBeLocal")
public class RaygunRUMDataMessage {
private String sessionId;
private String timestamp;
private String type; | private RaygunUserInfo user; |
MindscapeHQ/raygun4android | provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunClientMessage.java | // Path: provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java
// public class RaygunSettings {
//
// // General
// public static final String APIKEY_MANIFEST_FIELD = "com.raygun.raygun4android.apikey";
// public static final String RAYGUN_CLIENT_VERSION = BuildConfig.VERSION_NAME;
// public static final String LOGGING_TAG = "Raygun4Android";
//
// // HTTP error response codes
// public static final int RESPONSE_CODE_ACCEPTED = 202;
// public static final int RESPONSE_CODE_BAD_MESSAGE = 400;
// public static final int RESPONSE_CODE_INVALID_API_KEY = 403;
// public static final int RESPONSE_CODE_LARGE_PAYLOAD = 413;
// public static final int RESPONSE_CODE_RATE_LIMITED = 429;
//
// // Crash Reporting
// public static final String DEFAULT_CRASHREPORTING_ENDPOINT = "https://api.raygun.io/entries";
// public static final String DEFAULT_FILE_EXTENSION = "raygun4";
// public static final int DEFAULT_MAX_REPORTS_STORED_ON_DEVICE = 64;
// public static final String CRASH_REPORTING_UNHANDLED_EXCEPTION_TAG = "UnhandledException";
//
// // RUM
// public static final String RUM_EVENT_SESSION_START = "session_start";
// public static final String RUM_EVENT_SESSION_END = "session_end";
// public static final String RUM_EVENT_TIMING = "mobile_event_timing";
// public static final String DEFAULT_RUM_ENDPOINT = "https://api.raygun.io/events";
// // 30 minutes in milliseconds
// public static final int RUM_SESSION_EXPIRY = 30 * 60 * 1000;
//
// private static IgnoredURLs ignoredURLs = new IgnoredURLs("api.raygun.io");
// private static HashSet<String> ignoredViews = new HashSet<>();
// private static int maxReportsStoredOnDevice = DEFAULT_MAX_REPORTS_STORED_ON_DEVICE;
// private static String crashReportingEndpoint = DEFAULT_CRASHREPORTING_ENDPOINT;
// private static String rumEndpoint = DEFAULT_RUM_ENDPOINT;
//
// private RaygunSettings() {
// }
//
// public static String getCrashReportingEndpoint() {
// return crashReportingEndpoint;
// }
//
// static void setCrashReportingEndpoint(String crashReportingEndpoint) {
// RaygunSettings.crashReportingEndpoint = crashReportingEndpoint;
// }
//
// public static String getRUMEndpoint() {
// return rumEndpoint;
// }
//
// static void setRUMEndpoint(String rumEndpoint) {
// RaygunSettings.rumEndpoint = rumEndpoint;
// }
//
// public static HashSet<String> getIgnoredURLs() {
// return ignoredURLs;
// }
//
// static HashSet<String> getIgnoredViews() {
// return ignoredViews;
// }
//
// public static int getMaxReportsStoredOnDevice() {
// return maxReportsStoredOnDevice;
// }
//
// static void setMaxReportsStoredOnDevice(int maxReportsStoredOnDevice) {
// if (maxReportsStoredOnDevice <= DEFAULT_MAX_REPORTS_STORED_ON_DEVICE) {
// RaygunSettings.maxReportsStoredOnDevice = maxReportsStoredOnDevice;
// } else {
// RaygunLogger.w("It's not possible to exceed the value " + DEFAULT_MAX_REPORTS_STORED_ON_DEVICE + " for the number of reports stored on the device. The setting has not been applied.");
// }
// }
//
// public static class IgnoredURLs extends HashSet<String> {
// IgnoredURLs(String... defaultIgnoredUrls) {
// this.addAll(Arrays.asList(defaultIgnoredUrls));
// }
// }
//
// static void ignoreURLs(String[] urls) {
// if (urls != null) {
// for (String url : urls) {
// if (url != null) {
// RaygunSettings.ignoredURLs.add(url);
// }
// }
// }
// }
//
// static void ignoreViews(String[] views) {
// if (views != null) {
// for (String view : views) {
// if (view != null) {
// RaygunSettings.ignoredViews.add(view);
// }
// }
// }
// }
// }
| import com.raygun.raygun4android.RaygunSettings; | package com.raygun.raygun4android.messages.crashreporting;
public class RaygunClientMessage {
private String version;
private String clientUrl;
private String name;
public RaygunClientMessage() {
setName("Raygun4Android"); | // Path: provider/src/main/java/com/raygun/raygun4android/RaygunSettings.java
// public class RaygunSettings {
//
// // General
// public static final String APIKEY_MANIFEST_FIELD = "com.raygun.raygun4android.apikey";
// public static final String RAYGUN_CLIENT_VERSION = BuildConfig.VERSION_NAME;
// public static final String LOGGING_TAG = "Raygun4Android";
//
// // HTTP error response codes
// public static final int RESPONSE_CODE_ACCEPTED = 202;
// public static final int RESPONSE_CODE_BAD_MESSAGE = 400;
// public static final int RESPONSE_CODE_INVALID_API_KEY = 403;
// public static final int RESPONSE_CODE_LARGE_PAYLOAD = 413;
// public static final int RESPONSE_CODE_RATE_LIMITED = 429;
//
// // Crash Reporting
// public static final String DEFAULT_CRASHREPORTING_ENDPOINT = "https://api.raygun.io/entries";
// public static final String DEFAULT_FILE_EXTENSION = "raygun4";
// public static final int DEFAULT_MAX_REPORTS_STORED_ON_DEVICE = 64;
// public static final String CRASH_REPORTING_UNHANDLED_EXCEPTION_TAG = "UnhandledException";
//
// // RUM
// public static final String RUM_EVENT_SESSION_START = "session_start";
// public static final String RUM_EVENT_SESSION_END = "session_end";
// public static final String RUM_EVENT_TIMING = "mobile_event_timing";
// public static final String DEFAULT_RUM_ENDPOINT = "https://api.raygun.io/events";
// // 30 minutes in milliseconds
// public static final int RUM_SESSION_EXPIRY = 30 * 60 * 1000;
//
// private static IgnoredURLs ignoredURLs = new IgnoredURLs("api.raygun.io");
// private static HashSet<String> ignoredViews = new HashSet<>();
// private static int maxReportsStoredOnDevice = DEFAULT_MAX_REPORTS_STORED_ON_DEVICE;
// private static String crashReportingEndpoint = DEFAULT_CRASHREPORTING_ENDPOINT;
// private static String rumEndpoint = DEFAULT_RUM_ENDPOINT;
//
// private RaygunSettings() {
// }
//
// public static String getCrashReportingEndpoint() {
// return crashReportingEndpoint;
// }
//
// static void setCrashReportingEndpoint(String crashReportingEndpoint) {
// RaygunSettings.crashReportingEndpoint = crashReportingEndpoint;
// }
//
// public static String getRUMEndpoint() {
// return rumEndpoint;
// }
//
// static void setRUMEndpoint(String rumEndpoint) {
// RaygunSettings.rumEndpoint = rumEndpoint;
// }
//
// public static HashSet<String> getIgnoredURLs() {
// return ignoredURLs;
// }
//
// static HashSet<String> getIgnoredViews() {
// return ignoredViews;
// }
//
// public static int getMaxReportsStoredOnDevice() {
// return maxReportsStoredOnDevice;
// }
//
// static void setMaxReportsStoredOnDevice(int maxReportsStoredOnDevice) {
// if (maxReportsStoredOnDevice <= DEFAULT_MAX_REPORTS_STORED_ON_DEVICE) {
// RaygunSettings.maxReportsStoredOnDevice = maxReportsStoredOnDevice;
// } else {
// RaygunLogger.w("It's not possible to exceed the value " + DEFAULT_MAX_REPORTS_STORED_ON_DEVICE + " for the number of reports stored on the device. The setting has not been applied.");
// }
// }
//
// public static class IgnoredURLs extends HashSet<String> {
// IgnoredURLs(String... defaultIgnoredUrls) {
// this.addAll(Arrays.asList(defaultIgnoredUrls));
// }
// }
//
// static void ignoreURLs(String[] urls) {
// if (urls != null) {
// for (String url : urls) {
// if (url != null) {
// RaygunSettings.ignoredURLs.add(url);
// }
// }
// }
// }
//
// static void ignoreViews(String[] views) {
// if (views != null) {
// for (String view : views) {
// if (view != null) {
// RaygunSettings.ignoredViews.add(view);
// }
// }
// }
// }
// }
// Path: provider/src/main/java/com/raygun/raygun4android/messages/crashreporting/RaygunClientMessage.java
import com.raygun.raygun4android.RaygunSettings;
package com.raygun.raygun4android.messages.crashreporting;
public class RaygunClientMessage {
private String version;
private String clientUrl;
private String name;
public RaygunClientMessage() {
setName("Raygun4Android"); | setVersion(RaygunSettings.RAYGUN_CLIENT_VERSION); |
anthonyu/Sizzle | src/java/sizzle/aggregators/MrcounterAggregator.java | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
| import java.io.IOException;
import sizzle.io.EmitKey; | package sizzle.aggregators;
/**
* A Sizzle aggregator to increment named mapreduce counters by weight.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "mrcounter", type = "int")
public class MrcounterAggregator extends Aggregator {
private String group;
private String name;
@Override | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
// Path: src/java/sizzle/aggregators/MrcounterAggregator.java
import java.io.IOException;
import sizzle.io.EmitKey;
package sizzle.aggregators;
/**
* A Sizzle aggregator to increment named mapreduce counters by weight.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "mrcounter", type = "int")
public class MrcounterAggregator extends Aggregator {
private String group;
private String name;
@Override | public void setKey(final EmitKey key) { |
anthonyu/Sizzle | src/java/sizzle/aggregators/MaximumAggregator.java | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
| import sizzle.io.EmitKey; | package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate the top <i>n</i> values in a dataset by
* weight.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "maximum", formalParameters = { "int" }, weightType = "float")
public class MaximumAggregator extends MinOrMaxAggregator {
/**
* Construct a MaximumAggregator.
*
* @param n
* A long representing the number of values to return
*/
public MaximumAggregator(final long n) {
super(n);
}
/** {@inheritDoc} */
@Override | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
// Path: src/java/sizzle/aggregators/MaximumAggregator.java
import sizzle.io.EmitKey;
package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate the top <i>n</i> values in a dataset by
* weight.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "maximum", formalParameters = { "int" }, weightType = "float")
public class MaximumAggregator extends MinOrMaxAggregator {
/**
* Construct a MaximumAggregator.
*
* @param n
* A long representing the number of values to return
*/
public MaximumAggregator(final long n) {
super(n);
}
/** {@inheritDoc} */
@Override | public void start(final EmitKey key) { |
anthonyu/Sizzle | src/java/sizzle/aggregators/MinimumAggregator.java | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
| import sizzle.io.EmitKey; | package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate the top <i>n</i> values in a dataset by
* weight.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "minimum", formalParameters = { "int" }, weightType = "float")
public class MinimumAggregator extends MinOrMaxAggregator {
/**
* Construct a MinimumAggregator.
*
* @param n
* A long representing the number of values to return
*/
public MinimumAggregator(final long n) {
super(n);
}
/** {@inheritDoc} */
@Override | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
// Path: src/java/sizzle/aggregators/MinimumAggregator.java
import sizzle.io.EmitKey;
package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate the top <i>n</i> values in a dataset by
* weight.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "minimum", formalParameters = { "int" }, weightType = "float")
public class MinimumAggregator extends MinOrMaxAggregator {
/**
* Construct a MinimumAggregator.
*
* @param n
* A long representing the number of values to return
*/
public MinimumAggregator(final long n) {
super(n);
}
/** {@inheritDoc} */
@Override | public void start(final EmitKey key) { |
anthonyu/Sizzle | src/test/sizzle/aggregators/TestSortedCountingSet.java | // Path: src/java/sizzle/aggregators/SortedCountingSet.java
// public class SortedCountingSet<T> implements Iterable<T> {
// private final TreeMap<T, Long> map;
//
// /**
// * Construct a SortedCountingSet.
// */
// public SortedCountingSet() {
// this.map = new TreeMap<T, Long>();
// }
//
// /**
// * Add a value to the set.
// *
// * @param t
// * The value to be added
// */
// public void add(final T t) {
// // add it with cardinality 1
// this.add(t, 1);
// }
//
// /**
// * Add a value and its cardinality to the set.
// *
// * @param t
// * The value to be added
// * @param n
// * The cardinality of the value
// */
// public void add(final T t, final long n) {
// // if the map already has this key, add n to the current cardiality and
// // reinsert
// if (this.map.containsKey(t))
// this.map.put(t, Long.valueOf(this.map.get(t).longValue() + n));
// else
// this.map.put(t, Long.valueOf(n));
// }
//
// /** {@inheritDoc} */
// @Override
// public Iterator<T> iterator() {
// return new Iterator<T>() {
// private Entry<T, Long> lastEntry;
// private Entry<T, Long> thisEntry;
//
// private long cursor;
//
// {
// this.thisEntry = SortedCountingSet.this.map.firstEntry();
// this.lastEntry = SortedCountingSet.this.map.lastEntry();
// this.cursor = 0;
// }
//
// @Override
// public boolean hasNext() {
// if (this.lastEntry == null)
// return false;
//
// if (!this.thisEntry.getKey().equals(this.lastEntry.getKey()))
// return true;
//
// return this.cursor != this.lastEntry.getValue().longValue();
// }
//
// @Override
// public T next() {
// if (this.cursor == this.thisEntry.getValue().longValue()) {
// this.thisEntry = SortedCountingSet.this.map.higherEntry(this.thisEntry.getKey());
// this.cursor = 0;
// }
//
// this.cursor++;
//
// return this.thisEntry.getKey();
// }
//
// @Override
// public void remove() {
// throw new UnsupportedOperationException();
// }
// };
// }
//
// /**
// * Copy this set into a {@link List}.
// *
// * @return A {@link List} containing the values in this set
// */
// public List<T> toList() {
// final List<T> l = new ArrayList<T>();
//
// for (final T t : this)
// l.add(t);
//
// return l;
// }
//
// /**
// * Get the entries in this set.
// *
// * @return A {@link Set} of Map.Entry containing the entries in this set
// */
// public Set<java.util.Map.Entry<T, Long>> getEntries() {
// return this.map.entrySet();
// }
// }
| import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import sizzle.aggregators.SortedCountingSet; | package sizzle.aggregators;
public class TestSortedCountingSet {
@Test
public void testSortedCountingSetEmpty() { | // Path: src/java/sizzle/aggregators/SortedCountingSet.java
// public class SortedCountingSet<T> implements Iterable<T> {
// private final TreeMap<T, Long> map;
//
// /**
// * Construct a SortedCountingSet.
// */
// public SortedCountingSet() {
// this.map = new TreeMap<T, Long>();
// }
//
// /**
// * Add a value to the set.
// *
// * @param t
// * The value to be added
// */
// public void add(final T t) {
// // add it with cardinality 1
// this.add(t, 1);
// }
//
// /**
// * Add a value and its cardinality to the set.
// *
// * @param t
// * The value to be added
// * @param n
// * The cardinality of the value
// */
// public void add(final T t, final long n) {
// // if the map already has this key, add n to the current cardiality and
// // reinsert
// if (this.map.containsKey(t))
// this.map.put(t, Long.valueOf(this.map.get(t).longValue() + n));
// else
// this.map.put(t, Long.valueOf(n));
// }
//
// /** {@inheritDoc} */
// @Override
// public Iterator<T> iterator() {
// return new Iterator<T>() {
// private Entry<T, Long> lastEntry;
// private Entry<T, Long> thisEntry;
//
// private long cursor;
//
// {
// this.thisEntry = SortedCountingSet.this.map.firstEntry();
// this.lastEntry = SortedCountingSet.this.map.lastEntry();
// this.cursor = 0;
// }
//
// @Override
// public boolean hasNext() {
// if (this.lastEntry == null)
// return false;
//
// if (!this.thisEntry.getKey().equals(this.lastEntry.getKey()))
// return true;
//
// return this.cursor != this.lastEntry.getValue().longValue();
// }
//
// @Override
// public T next() {
// if (this.cursor == this.thisEntry.getValue().longValue()) {
// this.thisEntry = SortedCountingSet.this.map.higherEntry(this.thisEntry.getKey());
// this.cursor = 0;
// }
//
// this.cursor++;
//
// return this.thisEntry.getKey();
// }
//
// @Override
// public void remove() {
// throw new UnsupportedOperationException();
// }
// };
// }
//
// /**
// * Copy this set into a {@link List}.
// *
// * @return A {@link List} containing the values in this set
// */
// public List<T> toList() {
// final List<T> l = new ArrayList<T>();
//
// for (final T t : this)
// l.add(t);
//
// return l;
// }
//
// /**
// * Get the entries in this set.
// *
// * @return A {@link Set} of Map.Entry containing the entries in this set
// */
// public Set<java.util.Map.Entry<T, Long>> getEntries() {
// return this.map.entrySet();
// }
// }
// Path: src/test/sizzle/aggregators/TestSortedCountingSet.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import sizzle.aggregators.SortedCountingSet;
package sizzle.aggregators;
public class TestSortedCountingSet {
@Test
public void testSortedCountingSetEmpty() { | final SortedCountingSet<String> s = new SortedCountingSet<String>(); |
anthonyu/Sizzle | src/java/sizzle/types/SizzleType.java | // Path: src/java/sizzle/compiler/TypeException.java
// public class TypeException extends RuntimeException {
// private static final long serialVersionUID = -5838752670934187621L;
//
// /**
// * Construct a TypeException.
// *
// * @param text
// * A {@link String} containing the description of the error
// */
// public TypeException(final String text) {
// super(text);
// }
//
// /**
// * Construct a TypeException caused by another exception.
// *
// * @param text
// * A {@link String} containing the description of the error
// * @param e
// * A {@link Throwable} representing the cause of this type
// * exception
// */
// public TypeException(final String text, final Throwable e) {
// super(text, e);
// }
// }
| import sizzle.compiler.TypeException; | package sizzle.types;
/**
* Base class for the types in Sizzle.
*
* @author anthonyu
*
*/
public abstract class SizzleType {
/**
* Returns the type that results from an expression of this type and an
* expression of that type in an arithmetic expression. (e.g. an int plus a
* float results in an expression of type float).
*
* @param that
* A SizzleType representing the other expression's type
*
* @return A SizzleType representing the type of the resulting expression
*/
public SizzleScalar arithmetics(final SizzleType that) {
// by default, no types are allowed in arithmetic | // Path: src/java/sizzle/compiler/TypeException.java
// public class TypeException extends RuntimeException {
// private static final long serialVersionUID = -5838752670934187621L;
//
// /**
// * Construct a TypeException.
// *
// * @param text
// * A {@link String} containing the description of the error
// */
// public TypeException(final String text) {
// super(text);
// }
//
// /**
// * Construct a TypeException caused by another exception.
// *
// * @param text
// * A {@link String} containing the description of the error
// * @param e
// * A {@link Throwable} representing the cause of this type
// * exception
// */
// public TypeException(final String text, final Throwable e) {
// super(text, e);
// }
// }
// Path: src/java/sizzle/types/SizzleType.java
import sizzle.compiler.TypeException;
package sizzle.types;
/**
* Base class for the types in Sizzle.
*
* @author anthonyu
*
*/
public abstract class SizzleType {
/**
* Returns the type that results from an expression of this type and an
* expression of that type in an arithmetic expression. (e.g. an int plus a
* float results in an expression of type float).
*
* @param that
* A SizzleType representing the other expression's type
*
* @return A SizzleType representing the type of the resulting expression
*/
public SizzleScalar arithmetics(final SizzleType that) {
// by default, no types are allowed in arithmetic | throw new TypeException("incorrect type " + this + " for arithmetic with " + that); |
anthonyu/Sizzle | src/java/sizzle/aggregators/FloatMeanAggregator.java | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
| import java.io.IOException;
import sizzle.io.EmitKey; | package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate a mean of the values in a dataset.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "mean", type = "float")
public class FloatMeanAggregator extends MeanAggregator {
private double sum;
/** {@inheritDoc} */
@Override | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
// Path: src/java/sizzle/aggregators/FloatMeanAggregator.java
import java.io.IOException;
import sizzle.io.EmitKey;
package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate a mean of the values in a dataset.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "mean", type = "float")
public class FloatMeanAggregator extends MeanAggregator {
private double sum;
/** {@inheritDoc} */
@Override | public void start(EmitKey key) { |
anthonyu/Sizzle | src/java/sizzle/aggregators/MeanAggregator.java | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
| import sizzle.io.EmitKey; | package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate a mean of the values in a dataset.
*
* @author anthonyu
*
*/
abstract class MeanAggregator extends Aggregator {
private long count;
public void count(String metadata) {
if (metadata == null)
this.count++;
else
this.count += Long.parseLong(metadata);
}
/** {@inheritDoc} */
@Override | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
// Path: src/java/sizzle/aggregators/MeanAggregator.java
import sizzle.io.EmitKey;
package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate a mean of the values in a dataset.
*
* @author anthonyu
*
*/
abstract class MeanAggregator extends Aggregator {
private long count;
public void count(String metadata) {
if (metadata == null)
this.count++;
else
this.count += Long.parseLong(metadata);
}
/** {@inheritDoc} */
@Override | public void start(EmitKey key) { |
anthonyu/Sizzle | src/java/sizzle/aggregators/IntMeanAggregator.java | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
| import java.io.IOException;
import sizzle.io.EmitKey; | package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate a mean of the values in a dataset.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "mean", type = "int")
public class IntMeanAggregator extends MeanAggregator {
private long sum;
/** {@inheritDoc} */
@Override | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
// Path: src/java/sizzle/aggregators/IntMeanAggregator.java
import java.io.IOException;
import sizzle.io.EmitKey;
package sizzle.aggregators;
/**
* A Sizzle aggregator to calculate a mean of the values in a dataset.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "mean", type = "int")
public class IntMeanAggregator extends MeanAggregator {
private long sum;
/** {@inheritDoc} */
@Override | public void start(EmitKey key) { |
anthonyu/Sizzle | src/java/sizzle/aggregators/Table.java | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
| import java.io.IOException;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer.Context;
import sizzle.io.EmitKey; | package sizzle.aggregators;
/**
* A container for one or more Sizzle aggregators.
*
* @author anthonyu
*
*/
public class Table {
private final Aggregator[] aggregators;
@SuppressWarnings("rawtypes")
private Context context; | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
// Path: src/java/sizzle/aggregators/Table.java
import java.io.IOException;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer.Context;
import sizzle.io.EmitKey;
package sizzle.aggregators;
/**
* A container for one or more Sizzle aggregators.
*
* @author anthonyu
*
*/
public class Table {
private final Aggregator[] aggregators;
@SuppressWarnings("rawtypes")
private Context context; | private EmitKey key; |
anthonyu/Sizzle | src/java/sizzle/types/SizzleArray.java | // Path: src/java/sizzle/compiler/TypeException.java
// public class TypeException extends RuntimeException {
// private static final long serialVersionUID = -5838752670934187621L;
//
// /**
// * Construct a TypeException.
// *
// * @param text
// * A {@link String} containing the description of the error
// */
// public TypeException(final String text) {
// super(text);
// }
//
// /**
// * Construct a TypeException caused by another exception.
// *
// * @param text
// * A {@link String} containing the description of the error
// * @param e
// * A {@link Throwable} representing the cause of this type
// * exception
// */
// public TypeException(final String text, final Throwable e) {
// super(text, e);
// }
// }
| import sizzle.compiler.TypeException; | package sizzle.types;
/**
* A {@link SizzleType} representing an array of scalar values.
*
* @author anthonyu
*
*/
public class SizzleArray extends SizzleType {
private SizzleType type;
/**
* Construct a SizzleArray.
*/
public SizzleArray() {
}
/**
* Construct a SizzleArray.
*
* @param sizzleType
* A {@link SizzleType} representing the type of the elements in
* this array
*/
public SizzleArray(final SizzleType sizzleType) {
this.type = sizzleType;
}
/** {@inheritDoc} */
@Override
public boolean assigns(final SizzleType that) {
// if that is a function, check its return type
if (that instanceof SizzleFunction)
return this.assigns(((SizzleFunction) that).getType());
// otherwise, if it's not an array, forget it
if (!(that instanceof SizzleArray))
return false;
// if the element types are wrong, forget it
if (this.type.assigns(((SizzleArray) that).type))
return true;
return false;
}
/** {@inheritDoc} */
@Override
public boolean accepts(final SizzleType that) {
// if that is a function, check its return type
if (that instanceof SizzleFunction)
return this.assigns(((SizzleFunction) that).getType());
// otherwise, if it's not an array, forget it
if (!(that instanceof SizzleArray))
return false;
// if the element types are wrong, forget it
if (this.type.accepts(((SizzleArray) that).type))
return true;
return false;
}
/** {@inheritDoc} */
@Override
public boolean compares(final SizzleType that) {
// FIXME: is this needed?
// if that is an array..
if (that instanceof SizzleArray)
// check against the element types of these arrays
return this.type.compares(((SizzleArray) that).type);
// otherwise, forget it
return false;
}
/**
* Get the element type of this array.
*
* @return A {@link SizzleScalar} representing the element type of this
* array
*/
public SizzleScalar getType() {
if (this.type instanceof SizzleScalar)
return (SizzleScalar) this.type;
| // Path: src/java/sizzle/compiler/TypeException.java
// public class TypeException extends RuntimeException {
// private static final long serialVersionUID = -5838752670934187621L;
//
// /**
// * Construct a TypeException.
// *
// * @param text
// * A {@link String} containing the description of the error
// */
// public TypeException(final String text) {
// super(text);
// }
//
// /**
// * Construct a TypeException caused by another exception.
// *
// * @param text
// * A {@link String} containing the description of the error
// * @param e
// * A {@link Throwable} representing the cause of this type
// * exception
// */
// public TypeException(final String text, final Throwable e) {
// super(text, e);
// }
// }
// Path: src/java/sizzle/types/SizzleArray.java
import sizzle.compiler.TypeException;
package sizzle.types;
/**
* A {@link SizzleType} representing an array of scalar values.
*
* @author anthonyu
*
*/
public class SizzleArray extends SizzleType {
private SizzleType type;
/**
* Construct a SizzleArray.
*/
public SizzleArray() {
}
/**
* Construct a SizzleArray.
*
* @param sizzleType
* A {@link SizzleType} representing the type of the elements in
* this array
*/
public SizzleArray(final SizzleType sizzleType) {
this.type = sizzleType;
}
/** {@inheritDoc} */
@Override
public boolean assigns(final SizzleType that) {
// if that is a function, check its return type
if (that instanceof SizzleFunction)
return this.assigns(((SizzleFunction) that).getType());
// otherwise, if it's not an array, forget it
if (!(that instanceof SizzleArray))
return false;
// if the element types are wrong, forget it
if (this.type.assigns(((SizzleArray) that).type))
return true;
return false;
}
/** {@inheritDoc} */
@Override
public boolean accepts(final SizzleType that) {
// if that is a function, check its return type
if (that instanceof SizzleFunction)
return this.assigns(((SizzleFunction) that).getType());
// otherwise, if it's not an array, forget it
if (!(that instanceof SizzleArray))
return false;
// if the element types are wrong, forget it
if (this.type.accepts(((SizzleArray) that).type))
return true;
return false;
}
/** {@inheritDoc} */
@Override
public boolean compares(final SizzleType that) {
// FIXME: is this needed?
// if that is an array..
if (that instanceof SizzleArray)
// check against the element types of these arrays
return this.type.compares(((SizzleArray) that).type);
// otherwise, forget it
return false;
}
/**
* Get the element type of this array.
*
* @return A {@link SizzleScalar} representing the element type of this
* array
*/
public SizzleScalar getType() {
if (this.type instanceof SizzleScalar)
return (SizzleScalar) this.type;
| throw new TypeException("this shouldn't happen"); |
anthonyu/Sizzle | src/java/sizzle/aggregators/SetAggregator.java | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
| import java.io.IOException;
import java.util.HashSet;
import sizzle.io.EmitKey; | package sizzle.aggregators;
/**
* A Sizzle aggregator to filter the values in a dataset by maximum size.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "set")
public class SetAggregator extends Aggregator {
private HashSet<String> set;
private final long max;
/**
* Construct a SetAggregator.
*
* @param n
* A long representing the number of values to return
*/
public SetAggregator(final long n) {
super(n);
// the maximum size we will pass through
this.max = n;
}
@Override | // Path: src/java/sizzle/io/EmitKey.java
// public class EmitKey implements WritableComparable<EmitKey>, RawComparator<EmitKey>, Serializable {
// private static final long serialVersionUID = -6302400030199718829L;
//
// private String index;
// private String name;
//
// /**
// * Construct an EmitKey.
// *
// */
// public EmitKey() {
// // default constructor for Writable
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String name) {
// this("[]", name);
// }
//
// /**
// * Construct an EmitKey.
// *
// * @param index
// * A {@link String} containing the index into the table this was
// * emitted to
// *
// * @param name
// * A {@link String} containing the name of the table this was
// * emitted to
// *
// */
// public EmitKey(final String index, final String name) {
// if (index.equals(""))
// throw new RuntimeException();
//
// this.index = index;
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public void readFields(final DataInput in) throws IOException {
// this.index = Text.readString(in);
// this.name = Text.readString(in);
// }
//
// /** {@inheritDoc} */
// @Override
// public void write(final DataOutput out) throws IOException {
// Text.writeString(out, this.index);
// Text.writeString(out, this.name);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
// return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compare(final EmitKey k1, final EmitKey k2) {
// return k1.compareTo(k2);
// }
//
// /** {@inheritDoc} */
// @Override
// public int compareTo(final EmitKey that) {
// // compare the names
// final int c = this.name.compareTo(that.name);
//
// // if the names are different
// if (c != 0)
// // return that difference
// return c;
// else
// // otherwise compare the indices
// return this.index.compareTo(that.index);
// }
//
// /** {@inheritDoc} */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + (this.index == null ? 0 : this.index.hashCode());
// result = prime * result + (this.name == null ? 0 : this.name.hashCode());
// return result;
// }
//
// /** {@inheritDoc} */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (this.getClass() != obj.getClass())
// return false;
// final EmitKey other = (EmitKey) obj;
// if (this.index == null) {
// if (other.index != null)
// return false;
// } else if (!this.index.equals(other.index))
// return false;
// if (this.name == null) {
// if (other.name != null)
// return false;
// } else if (!this.name.equals(other.name))
// return false;
// return true;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @return A {@link String} containing the index into the table this key was
// * emitted to
// */
// public String getIndex() {
// return this.index;
// }
//
// /**
// * Get the index into the table this key was emitted to.
// *
// * @param index
// * A {@link String} containing the index into the table this key
// * was emitted to
// */
// public void setIndex(final String index) {
// this.index = index;
// }
//
// /**
// * Get the name of the table this key was emitted to.
// *
// * @return A {@link String} containing the name of the table this key was
// * emitted to
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * Set the name of the table this key was emitted to.
// *
// * @param name
// * A {@link String} containing the name of the table this key was
// * emitted to
// */
// public void setName(final String name) {
// this.name = name;
// }
//
// /** {@inheritDoc} */
// @Override
// public String toString() {
// return this.name + this.index;
// }
// }
// Path: src/java/sizzle/aggregators/SetAggregator.java
import java.io.IOException;
import java.util.HashSet;
import sizzle.io.EmitKey;
package sizzle.aggregators;
/**
* A Sizzle aggregator to filter the values in a dataset by maximum size.
*
* @author anthonyu
*
*/
@AggregatorSpec(name = "set")
public class SetAggregator extends Aggregator {
private HashSet<String> set;
private final long max;
/**
* Construct a SetAggregator.
*
* @param n
* A long representing the number of values to return
*/
public SetAggregator(final long n) {
super(n);
// the maximum size we will pass through
this.max = n;
}
@Override | public void start(final EmitKey key) { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Delete.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
| import com.github.kokorin.jdbunit.table.Table;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.ListIterator;
import java.util.Objects; | package com.github.kokorin.jdbunit.operation;
public class Delete implements Operation {
@Override | // Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Delete.java
import com.github.kokorin.jdbunit.table.Table;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.ListIterator;
import java.util.Objects;
package com.github.kokorin.jdbunit.operation;
public class Delete implements Operation {
@Override | public void execute(List<Table> tables, Connection connection) { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Insert.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects; | package com.github.kokorin.jdbunit.operation;
public class Insert implements Operation {
@Override | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Insert.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
package com.github.kokorin.jdbunit.operation;
public class Insert implements Operation {
@Override | public void execute(List<Table> tables, Connection connection) { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Insert.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects; | package com.github.kokorin.jdbunit.operation;
public class Insert implements Operation {
@Override
public void execute(List<Table> tables, Connection connection) {
Objects.requireNonNull(tables);
Objects.requireNonNull(connection);
try {
for (Table table : tables) {
insertTable(table, connection);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void insertTable(Table table, Connection connection) throws SQLException {
String query = buildInsertQuery(table);
try (PreparedStatement statement = connection.prepareStatement(query)) {
| // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Insert.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
package com.github.kokorin.jdbunit.operation;
public class Insert implements Operation {
@Override
public void execute(List<Table> tables, Connection connection) {
Objects.requireNonNull(tables);
Objects.requireNonNull(connection);
try {
for (Table table : tables) {
insertTable(table, connection);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void insertTable(Table table, Connection connection) throws SQLException {
String query = buildInsertQuery(table);
try (PreparedStatement statement = connection.prepareStatement(query)) {
| for (Row row : table.getRows()) { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Insert.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects; | package com.github.kokorin.jdbunit.operation;
public class Insert implements Operation {
@Override
public void execute(List<Table> tables, Connection connection) {
Objects.requireNonNull(tables);
Objects.requireNonNull(connection);
try {
for (Table table : tables) {
insertTable(table, connection);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void insertTable(Table table, Connection connection) throws SQLException {
String query = buildInsertQuery(table);
try (PreparedStatement statement = connection.prepareStatement(query)) {
for (Row row : table.getRows()) {
setParameters(statement, table.getColumns(), row);
statement.addBatch();
}
statement.executeBatch();
}
}
| // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Insert.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
package com.github.kokorin.jdbunit.operation;
public class Insert implements Operation {
@Override
public void execute(List<Table> tables, Connection connection) {
Objects.requireNonNull(tables);
Objects.requireNonNull(connection);
try {
for (Table table : tables) {
insertTable(table, connection);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void insertTable(Table table, Connection connection) throws SQLException {
String query = buildInsertQuery(table);
try (PreparedStatement statement = connection.prepareStatement(query)) {
for (Row row : table.getRows()) {
setParameters(statement, table.getColumns(), row);
statement.addBatch();
}
statement.executeBatch();
}
}
| void setParameters(PreparedStatement statement, List<Column> columns, Row row) throws SQLException { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Insert.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects; | package com.github.kokorin.jdbunit.operation;
public class Insert implements Operation {
@Override
public void execute(List<Table> tables, Connection connection) {
Objects.requireNonNull(tables);
Objects.requireNonNull(connection);
try {
for (Table table : tables) {
insertTable(table, connection);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void insertTable(Table table, Connection connection) throws SQLException {
String query = buildInsertQuery(table);
try (PreparedStatement statement = connection.prepareStatement(query)) {
for (Row row : table.getRows()) {
setParameters(statement, table.getColumns(), row);
statement.addBatch();
}
statement.executeBatch();
}
}
void setParameters(PreparedStatement statement, List<Column> columns, Row row) throws SQLException {
List<Object> values = row.getValues();
for (int i = 0; i < values.size(); ++i) {
Object value = values.get(i); | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Insert.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
package com.github.kokorin.jdbunit.operation;
public class Insert implements Operation {
@Override
public void execute(List<Table> tables, Connection connection) {
Objects.requireNonNull(tables);
Objects.requireNonNull(connection);
try {
for (Table table : tables) {
insertTable(table, connection);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void insertTable(Table table, Connection connection) throws SQLException {
String query = buildInsertQuery(table);
try (PreparedStatement statement = connection.prepareStatement(query)) {
for (Row row : table.getRows()) {
setParameters(statement, table.getColumns(), row);
statement.addBatch();
}
statement.executeBatch();
}
}
void setParameters(PreparedStatement statement, List<Column> columns, Row row) throws SQLException {
List<Object> values = row.getValues();
for (int i = 0; i < values.size(); ++i) {
Object value = values.get(i); | Type type = columns.get(i).getType(); |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Verify.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals; | package com.github.kokorin.jdbunit.operation;
public class Verify implements Operation {
@Override | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Verify.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals;
package com.github.kokorin.jdbunit.operation;
public class Verify implements Operation {
@Override | public void execute(List<Table> expectedTables, Connection connection) { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Verify.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals; | package com.github.kokorin.jdbunit.operation;
public class Verify implements Operation {
@Override
public void execute(List<Table> expectedTables, Connection connection) {
expectedTables = combineAll(expectedTables);
try {
List<Table> actualTables = new ArrayList<>(expectedTables.size());
for (Table expected : expectedTables) {
Table actual = readTable(connection, expected);
actualTables.add(actual);
}
| // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Verify.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals;
package com.github.kokorin.jdbunit.operation;
public class Verify implements Operation {
@Override
public void execute(List<Table> expectedTables, Connection connection) {
expectedTables = combineAll(expectedTables);
try {
List<Table> actualTables = new ArrayList<>(expectedTables.size());
for (Table expected : expectedTables) {
Table actual = readTable(connection, expected);
actualTables.add(actual);
}
| assertTableEquals(expectedTables, actualTables); |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Verify.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals; | package com.github.kokorin.jdbunit.operation;
public class Verify implements Operation {
@Override
public void execute(List<Table> expectedTables, Connection connection) {
expectedTables = combineAll(expectedTables);
try {
List<Table> actualTables = new ArrayList<>(expectedTables.size());
for (Table expected : expectedTables) {
Table actual = readTable(connection, expected);
actualTables.add(actual);
}
assertTableEquals(expectedTables, actualTables);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Table readTable(Connection connection, Table expected) throws SQLException {
try (Statement statement = connection.createStatement()) {
String query = createSelectQuery(expected);
try (ResultSet resultSet = statement.executeQuery(query)) { | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Verify.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals;
package com.github.kokorin.jdbunit.operation;
public class Verify implements Operation {
@Override
public void execute(List<Table> expectedTables, Connection connection) {
expectedTables = combineAll(expectedTables);
try {
List<Table> actualTables = new ArrayList<>(expectedTables.size());
for (Table expected : expectedTables) {
Table actual = readTable(connection, expected);
actualTables.add(actual);
}
assertTableEquals(expectedTables, actualTables);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Table readTable(Connection connection, Table expected) throws SQLException {
try (Statement statement = connection.createStatement()) {
String query = createSelectQuery(expected);
try (ResultSet resultSet = statement.executeQuery(query)) { | List<Column> columns = expected.getColumns(); |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Verify.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals; | package com.github.kokorin.jdbunit.operation;
public class Verify implements Operation {
@Override
public void execute(List<Table> expectedTables, Connection connection) {
expectedTables = combineAll(expectedTables);
try {
List<Table> actualTables = new ArrayList<>(expectedTables.size());
for (Table expected : expectedTables) {
Table actual = readTable(connection, expected);
actualTables.add(actual);
}
assertTableEquals(expectedTables, actualTables);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Table readTable(Connection connection, Table expected) throws SQLException {
try (Statement statement = connection.createStatement()) {
String query = createSelectQuery(expected);
try (ResultSet resultSet = statement.executeQuery(query)) {
List<Column> columns = expected.getColumns(); | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Verify.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals;
package com.github.kokorin.jdbunit.operation;
public class Verify implements Operation {
@Override
public void execute(List<Table> expectedTables, Connection connection) {
expectedTables = combineAll(expectedTables);
try {
List<Table> actualTables = new ArrayList<>(expectedTables.size());
for (Table expected : expectedTables) {
Table actual = readTable(connection, expected);
actualTables.add(actual);
}
assertTableEquals(expectedTables, actualTables);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Table readTable(Connection connection, Table expected) throws SQLException {
try (Statement statement = connection.createStatement()) {
String query = createSelectQuery(expected);
try (ResultSet resultSet = statement.executeQuery(query)) {
List<Column> columns = expected.getColumns(); | List<Row> rows = readRows(resultSet, columns); |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/operation/Verify.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals; | actualTables.add(actual);
}
assertTableEquals(expectedTables, actualTables);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Table readTable(Connection connection, Table expected) throws SQLException {
try (Statement statement = connection.createStatement()) {
String query = createSelectQuery(expected);
try (ResultSet resultSet = statement.executeQuery(query)) {
List<Column> columns = expected.getColumns();
List<Row> rows = readRows(resultSet, columns);
return new Table(expected.getName(), columns, rows);
}
}
}
List<Row> readRows(ResultSet set, List<Column> columns) throws SQLException {
List<Row> result = new ArrayList<>();
int count = columns.size();
while (set.next()) {
List<Object> values = new ArrayList<>(count);
for (int i = 0; i < count; ++i) { | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Type.java
// public interface Type {
// List<String> getAliases();
//
// Object parse(String string);
//
// void setParameter(PreparedStatement statement, int index, Object value) throws SQLException;
//
// Object getValue(ResultSet set, int index) throws SQLException;
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
// public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
// assertNotNull("No expected table", expectedTables);
// assertNotNull("No actual table", actualTables);
// assertEquals(expectedTables.size(), actualTables.size());
//
// Map<String, Table> actualMap = new HashMap<>();
// for (Table actual : actualTables) {
// actualMap.put(actual.getName(), actual);
// }
//
// Map<String, Object> variables = new HashMap<>();
// for (Table expected : expectedTables) {
// Table actual = actualMap.get(expected.getName());
// assertNotNull("No table among actual: " + expected.getName(), actual);
// assertColumnsEqual(expected.getColumns(), actual.getColumns());
// assertContentsEqual(expected.getRows(), actual.getRows(), variables);
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/operation/Verify.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import com.github.kokorin.jdbunit.table.Type;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import static com.github.kokorin.jdbunit.JdbUnitAssert.assertTableEquals;
actualTables.add(actual);
}
assertTableEquals(expectedTables, actualTables);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Table readTable(Connection connection, Table expected) throws SQLException {
try (Statement statement = connection.createStatement()) {
String query = createSelectQuery(expected);
try (ResultSet resultSet = statement.executeQuery(query)) {
List<Column> columns = expected.getColumns();
List<Row> rows = readRows(resultSet, columns);
return new Table(expected.getName(), columns, rows);
}
}
}
List<Row> readRows(ResultSet set, List<Column> columns) throws SQLException {
List<Row> result = new ArrayList<>();
int count = columns.size();
while (set.next()) {
List<Object> values = new ArrayList<>(count);
for (int i = 0; i < count; ++i) { | Type type = columns.get(i).getType(); |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.*;
import static org.junit.Assert.*; | package com.github.kokorin.jdbunit;
public class JdbUnitAssert {
private JdbUnitAssert() {}
| // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.*;
import static org.junit.Assert.*;
package com.github.kokorin.jdbunit;
public class JdbUnitAssert {
private JdbUnitAssert() {}
| public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.*;
import static org.junit.Assert.*; | package com.github.kokorin.jdbunit;
public class JdbUnitAssert {
private JdbUnitAssert() {}
public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
assertNotNull("No expected table", expectedTables);
assertNotNull("No actual table", actualTables);
assertEquals(expectedTables.size(), actualTables.size());
Map<String, Table> actualMap = new HashMap<>();
for (Table actual : actualTables) {
actualMap.put(actual.getName(), actual);
}
Map<String, Object> variables = new HashMap<>();
for (Table expected : expectedTables) {
Table actual = actualMap.get(expected.getName());
assertNotNull("No table among actual: " + expected.getName(), actual);
assertColumnsEqual(expected.getColumns(), actual.getColumns());
assertContentsEqual(expected.getRows(), actual.getRows(), variables);
}
}
| // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.*;
import static org.junit.Assert.*;
package com.github.kokorin.jdbunit;
public class JdbUnitAssert {
private JdbUnitAssert() {}
public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
assertNotNull("No expected table", expectedTables);
assertNotNull("No actual table", actualTables);
assertEquals(expectedTables.size(), actualTables.size());
Map<String, Table> actualMap = new HashMap<>();
for (Table actual : actualTables) {
actualMap.put(actual.getName(), actual);
}
Map<String, Object> variables = new HashMap<>();
for (Table expected : expectedTables) {
Table actual = actualMap.get(expected.getName());
assertNotNull("No table among actual: " + expected.getName(), actual);
assertColumnsEqual(expected.getColumns(), actual.getColumns());
assertContentsEqual(expected.getRows(), actual.getRows(), variables);
}
}
| public static void assertColumnsEqual(List<Column> expected, List<Column> actual) { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.*;
import static org.junit.Assert.*; | package com.github.kokorin.jdbunit;
public class JdbUnitAssert {
private JdbUnitAssert() {}
public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
assertNotNull("No expected table", expectedTables);
assertNotNull("No actual table", actualTables);
assertEquals(expectedTables.size(), actualTables.size());
Map<String, Table> actualMap = new HashMap<>();
for (Table actual : actualTables) {
actualMap.put(actual.getName(), actual);
}
Map<String, Object> variables = new HashMap<>();
for (Table expected : expectedTables) {
Table actual = actualMap.get(expected.getName());
assertNotNull("No table among actual: " + expected.getName(), actual);
assertColumnsEqual(expected.getColumns(), actual.getColumns());
assertContentsEqual(expected.getRows(), actual.getRows(), variables);
}
}
public static void assertColumnsEqual(List<Column> expected, List<Column> actual) {
assertEquals("Column counts must be equal", expected.size(), actual.size());
for (int i = 0; i < expected.size(); ++i) {
Column expColumn = expected.get(i);
Column actColumn = actual.get(i);
assertEquals("Column not found: " + expColumn.getName(), expColumn.getName(), actColumn.getName());
assertEquals("Column has wrong type: " + actColumn.getName(), expColumn.getType(), actColumn.getType());
}
}
| // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/JdbUnitAssert.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.*;
import static org.junit.Assert.*;
package com.github.kokorin.jdbunit;
public class JdbUnitAssert {
private JdbUnitAssert() {}
public static void assertTableEquals(List<Table> expectedTables, List<Table> actualTables) {
assertNotNull("No expected table", expectedTables);
assertNotNull("No actual table", actualTables);
assertEquals(expectedTables.size(), actualTables.size());
Map<String, Table> actualMap = new HashMap<>();
for (Table actual : actualTables) {
actualMap.put(actual.getName(), actual);
}
Map<String, Object> variables = new HashMap<>();
for (Table expected : expectedTables) {
Table actual = actualMap.get(expected.getName());
assertNotNull("No table among actual: " + expected.getName(), actual);
assertColumnsEqual(expected.getColumns(), actual.getColumns());
assertContentsEqual(expected.getRows(), actual.getRows(), variables);
}
}
public static void assertColumnsEqual(List<Column> expected, List<Column> actual) {
assertEquals("Column counts must be equal", expected.size(), actual.size());
for (int i = 0; i < expected.size(); ++i) {
Column expColumn = expected.get(i);
Column actColumn = actual.get(i);
assertEquals("Column not found: " + expColumn.getName(), expColumn.getName(), actColumn.getName());
assertEquals("Column has wrong type: " + actColumn.getName(), expColumn.getType(), actColumn.getType());
}
}
| public static void assertContentsEqual(List<Row> expected, List<Row> actual, Map<String, Object> variables) { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/TablePrinter.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.ArrayList;
import java.util.List; | package com.github.kokorin.jdbunit;
public class TablePrinter {
static String print(Table table) {
StringBuilder result = new StringBuilder();
List<Integer> widths = calcColumnWidths(table);
printName(result, table.getName());
printHeaderSeparator(result, widths);
printHeader(result, table.getColumns(), widths);
printContentSeparator(result, widths);
| // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/TablePrinter.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.ArrayList;
import java.util.List;
package com.github.kokorin.jdbunit;
public class TablePrinter {
static String print(Table table) {
StringBuilder result = new StringBuilder();
List<Integer> widths = calcColumnWidths(table);
printName(result, table.getName());
printHeaderSeparator(result, widths);
printHeader(result, table.getColumns(), widths);
printContentSeparator(result, widths);
| for (Row row : table.getRows()) { |
kokorin/jdbUnit | src/main/java/com/github/kokorin/jdbunit/TablePrinter.java | // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
| import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.ArrayList;
import java.util.List; | package com.github.kokorin.jdbunit;
public class TablePrinter {
static String print(Table table) {
StringBuilder result = new StringBuilder();
List<Integer> widths = calcColumnWidths(table);
printName(result, table.getName());
printHeaderSeparator(result, widths);
printHeader(result, table.getColumns(), widths);
printContentSeparator(result, widths);
for (Row row : table.getRows()) {
printRow(result, row, widths);
}
return result.toString();
}
static List<Integer> calcColumnWidths(Table table) {
return new ArrayList<>();
}
static void printName(StringBuilder builder, String name) {
}
static void printHeaderSeparator(StringBuilder builder, List<Integer> widths) {
}
| // Path: src/main/java/com/github/kokorin/jdbunit/table/Column.java
// public class Column {
// private final String name;
// private final Type type;
//
// public Column(String name, Type type) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(type);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Column name must be non empty");
// }
//
// this.name = name;
// this.type = type;
// }
//
// public String getName() {
// return name;
// }
//
// public Type getType() {
// return type;
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Row.java
// public class Row {
// private final List<Object> values;
//
// public static final Object ANY_VALUE = new Object(){
// @Override
// public String toString() {
// return "ANY_VALUE";
// }
// };
//
// public Row(List<Object> values) {
// Objects.requireNonNull(values);
// if (values.isEmpty()) {
// throw new IllegalArgumentException("At least one value in a row is required");
// }
//
// values = Collections.unmodifiableList(new ArrayList<>(values));
// this.values = values;
// }
//
// public List<Object> getValues() {
// return values;
// }
//
// public static class ValueCaptor {
// private final String name;
//
// public ValueCaptor(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Cap:" + name + ":";
// }
// }
//
// public static class ValueReference {
// private final String name;
//
// public ValueReference(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return "Ref=" + name + "=";
// }
// }
// }
//
// Path: src/main/java/com/github/kokorin/jdbunit/table/Table.java
// public class Table {
// private final String name;
// private final List<Column> columns;
// private final List<Row> rows;
//
// public Table(String name, List<Column> columns, List<Row> rows) {
// Objects.requireNonNull(name);
// Objects.requireNonNull(columns);
// Objects.requireNonNull(rows);
//
// if (name.isEmpty()) {
// throw new IllegalArgumentException("Table name must be non empty");
// }
// if (columns.isEmpty() && !rows.isEmpty()) {
// throw new IllegalArgumentException("At least one column is required for non-empty table");
// }
//
// for (Row row : rows) {
// if (row.getValues().size() != columns.size()) {
// throw new IllegalArgumentException("Every row must have value for every column.");
// }
// }
//
// this.name = name;
// this.columns = Collections.unmodifiableList(new ArrayList<>(columns));
// this.rows = Collections.unmodifiableList(new ArrayList<>(rows));
// }
//
// public String getName() {
// return name;
// }
//
// public List<Column> getColumns() {
// return columns;
// }
//
// public List<Row> getRows() {
// return rows;
// }
// }
// Path: src/main/java/com/github/kokorin/jdbunit/TablePrinter.java
import com.github.kokorin.jdbunit.table.Column;
import com.github.kokorin.jdbunit.table.Row;
import com.github.kokorin.jdbunit.table.Table;
import java.util.ArrayList;
import java.util.List;
package com.github.kokorin.jdbunit;
public class TablePrinter {
static String print(Table table) {
StringBuilder result = new StringBuilder();
List<Integer> widths = calcColumnWidths(table);
printName(result, table.getName());
printHeaderSeparator(result, widths);
printHeader(result, table.getColumns(), widths);
printContentSeparator(result, widths);
for (Row row : table.getRows()) {
printRow(result, row, widths);
}
return result.toString();
}
static List<Integer> calcColumnWidths(Table table) {
return new ArrayList<>();
}
static void printName(StringBuilder builder, String name) {
}
static void printHeaderSeparator(StringBuilder builder, List<Integer> widths) {
}
| static void printHeader(StringBuilder builder, List<Column> columns, List<Integer> widths) { |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/DefaultErrorResolver.java | // Path: src/main/java/com/googlecode/jsonrpc4j/ErrorResolver.java
// public static final JsonError ERROR_NOT_HANDLED = new JsonError(-32001, "error not handled", null);
| import com.fasterxml.jackson.databind.JsonNode;
import java.lang.reflect.Method;
import java.util.List;
import static com.googlecode.jsonrpc4j.ErrorResolver.JsonError.ERROR_NOT_HANDLED; | package com.googlecode.jsonrpc4j;
/**
* An {@link ErrorResolver} that puts type information into the
* data portion of the error. This {@link ErrorResolver} always
* returns a {@link com.googlecode.jsonrpc4j.ErrorResolver.JsonError JsonError}.
*/
@SuppressWarnings("WeakerAccess")
public enum DefaultErrorResolver implements ErrorResolver {
INSTANCE;
/**
* {@inheritDoc}
*/
public JsonError resolveError(Throwable t, Method method, List<JsonNode> arguments) { | // Path: src/main/java/com/googlecode/jsonrpc4j/ErrorResolver.java
// public static final JsonError ERROR_NOT_HANDLED = new JsonError(-32001, "error not handled", null);
// Path: src/main/java/com/googlecode/jsonrpc4j/DefaultErrorResolver.java
import com.fasterxml.jackson.databind.JsonNode;
import java.lang.reflect.Method;
import java.util.List;
import static com.googlecode.jsonrpc4j.ErrorResolver.JsonError.ERROR_NOT_HANDLED;
package com.googlecode.jsonrpc4j;
/**
* An {@link ErrorResolver} that puts type information into the
* data portion of the error. This {@link ErrorResolver} always
* returns a {@link com.googlecode.jsonrpc4j.ErrorResolver.JsonError JsonError}.
*/
@SuppressWarnings("WeakerAccess")
public enum DefaultErrorResolver implements ErrorResolver {
INSTANCE;
/**
* {@inheritDoc}
*/
public JsonError resolveError(Throwable t, Method method, List<JsonNode> arguments) { | return new JsonError(ERROR_NOT_HANDLED.code, t.getMessage(), new ErrorData(t.getClass().getName(), t.getMessage())); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData; | ObjectNode jsonObject = ObjectNode.class.cast(response);
if (id != null) {
while (isIdValueNotCorrect(id, jsonObject)) {
response = context.nextValue();
raiseExceptionIfNotValidResponseObject(response);
jsonObject = ObjectNode.class.cast(response);
}
}
return jsonObject;
}
private void notifyAnswerListener(ObjectNode jsonObject) {
if (this.requestListener != null) {
this.requestListener.onBeforeResponseProcessed(this, jsonObject);
}
}
protected void handleErrorResponse(ObjectNode jsonObject) throws Throwable {
if (hasError(jsonObject)) {
// resolve and throw the exception
if (exceptionResolver == null) {
throw DefaultExceptionResolver.INSTANCE.resolveException(jsonObject);
} else {
throw exceptionResolver.resolveException(jsonObject);
}
}
}
private boolean hasResult(ObjectNode jsonObject) { | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData;
ObjectNode jsonObject = ObjectNode.class.cast(response);
if (id != null) {
while (isIdValueNotCorrect(id, jsonObject)) {
response = context.nextValue();
raiseExceptionIfNotValidResponseObject(response);
jsonObject = ObjectNode.class.cast(response);
}
}
return jsonObject;
}
private void notifyAnswerListener(ObjectNode jsonObject) {
if (this.requestListener != null) {
this.requestListener.onBeforeResponseProcessed(this, jsonObject);
}
}
protected void handleErrorResponse(ObjectNode jsonObject) throws Throwable {
if (hasError(jsonObject)) {
// resolve and throw the exception
if (exceptionResolver == null) {
throw DefaultExceptionResolver.INSTANCE.resolveException(jsonObject);
} else {
throw exceptionResolver.resolveException(jsonObject);
}
}
}
private boolean hasResult(ObjectNode jsonObject) { | return hasNonNullData(jsonObject, RESULT); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData; |
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param output the stream
* @param id the optional id
* @throws IOException on error
*/
private void internalWriteRequest(String methodName, Object arguments, OutputStream output, String id) throws IOException {
final ObjectNode request = internalCreateRequest(methodName, arguments, id);
logger.debug("Request {}", request);
writeAndFlushValue(output, request);
}
private JsonNode readResponseNode(ReadContext context) throws IOException {
context.assertReadable();
JsonNode response = context.nextValue();
logger.debug("JSON-RPC Response: {}", response);
return response;
}
private void raiseExceptionIfNotValidResponseObject(JsonNode response) {
if (isInvalidResponse(response)) {
throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
}
}
private boolean isIdValueNotCorrect(String id, ObjectNode jsonObject) { | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData;
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param output the stream
* @param id the optional id
* @throws IOException on error
*/
private void internalWriteRequest(String methodName, Object arguments, OutputStream output, String id) throws IOException {
final ObjectNode request = internalCreateRequest(methodName, arguments, id);
logger.debug("Request {}", request);
writeAndFlushValue(output, request);
}
private JsonNode readResponseNode(ReadContext context) throws IOException {
context.assertReadable();
JsonNode response = context.nextValue();
logger.debug("JSON-RPC Response: {}", response);
return response;
}
private void raiseExceptionIfNotValidResponseObject(JsonNode response) {
if (isInvalidResponse(response)) {
throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
}
}
private boolean isIdValueNotCorrect(String id, ObjectNode jsonObject) { | return !jsonObject.has(ID) || jsonObject.get(ID) == null || !jsonObject.get(ID).asText().equals(id); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData; | * @param methodName the method name
* @param arguments the arguments
* @param output the stream
* @param id the optional id
* @throws IOException on error
*/
private void internalWriteRequest(String methodName, Object arguments, OutputStream output, String id) throws IOException {
final ObjectNode request = internalCreateRequest(methodName, arguments, id);
logger.debug("Request {}", request);
writeAndFlushValue(output, request);
}
private JsonNode readResponseNode(ReadContext context) throws IOException {
context.assertReadable();
JsonNode response = context.nextValue();
logger.debug("JSON-RPC Response: {}", response);
return response;
}
private void raiseExceptionIfNotValidResponseObject(JsonNode response) {
if (isInvalidResponse(response)) {
throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
}
}
private boolean isIdValueNotCorrect(String id, ObjectNode jsonObject) {
return !jsonObject.has(ID) || jsonObject.get(ID) == null || !jsonObject.get(ID).asText().equals(id);
}
protected boolean hasError(ObjectNode jsonObject) { | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData;
* @param methodName the method name
* @param arguments the arguments
* @param output the stream
* @param id the optional id
* @throws IOException on error
*/
private void internalWriteRequest(String methodName, Object arguments, OutputStream output, String id) throws IOException {
final ObjectNode request = internalCreateRequest(methodName, arguments, id);
logger.debug("Request {}", request);
writeAndFlushValue(output, request);
}
private JsonNode readResponseNode(ReadContext context) throws IOException {
context.assertReadable();
JsonNode response = context.nextValue();
logger.debug("JSON-RPC Response: {}", response);
return response;
}
private void raiseExceptionIfNotValidResponseObject(JsonNode response) {
if (isInvalidResponse(response)) {
throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
}
}
private boolean isIdValueNotCorrect(String id, ObjectNode jsonObject) {
return !jsonObject.has(ID) || jsonObject.get(ID) == null || !jsonObject.get(ID).asText().equals(id);
}
protected boolean hasError(ObjectNode jsonObject) { | return jsonObject.has(ERROR) && jsonObject.get(ERROR) != null && !jsonObject.get(ERROR).isNull() && !(jsonObject.get(ERROR).isInt() && jsonObject.intValue()==0) ; |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData; | addAdditionalHeaders(request);
notifyBeforeRequestListener(request);
addNoneArguments(request);
return request;
}
/**
* Writes and flushes a value to the given {@link OutputStream}
* and prevents Jackson from closing it.
*
* @param output the {@link OutputStream}
* @param value the value to write
* @throws IOException on error
*/
private void writeAndFlushValue(OutputStream output, Object value) throws IOException {
mapper.writeValue(new NoCloseOutputStream(output), value);
output.flush();
}
private boolean isInvalidResponse(JsonNode response) {
return !response.isObject();
}
private void addId(String id, ObjectNode request) {
if (id != null) {
request.put(ID, id);
}
}
private void addProtocolAndMethod(String methodName, ObjectNode request) { | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData;
addAdditionalHeaders(request);
notifyBeforeRequestListener(request);
addNoneArguments(request);
return request;
}
/**
* Writes and flushes a value to the given {@link OutputStream}
* and prevents Jackson from closing it.
*
* @param output the {@link OutputStream}
* @param value the value to write
* @throws IOException on error
*/
private void writeAndFlushValue(OutputStream output, Object value) throws IOException {
mapper.writeValue(new NoCloseOutputStream(output), value);
output.flush();
}
private boolean isInvalidResponse(JsonNode response) {
return !response.isObject();
}
private void addId(String id, ObjectNode request) {
if (id != null) {
request.put(ID, id);
}
}
private void addProtocolAndMethod(String methodName, ObjectNode request) { | request.put(JSONRPC, VERSION); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData; | addAdditionalHeaders(request);
notifyBeforeRequestListener(request);
addNoneArguments(request);
return request;
}
/**
* Writes and flushes a value to the given {@link OutputStream}
* and prevents Jackson from closing it.
*
* @param output the {@link OutputStream}
* @param value the value to write
* @throws IOException on error
*/
private void writeAndFlushValue(OutputStream output, Object value) throws IOException {
mapper.writeValue(new NoCloseOutputStream(output), value);
output.flush();
}
private boolean isInvalidResponse(JsonNode response) {
return !response.isObject();
}
private void addId(String id, ObjectNode request) {
if (id != null) {
request.put(ID, id);
}
}
private void addProtocolAndMethod(String methodName, ObjectNode request) { | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData;
addAdditionalHeaders(request);
notifyBeforeRequestListener(request);
addNoneArguments(request);
return request;
}
/**
* Writes and flushes a value to the given {@link OutputStream}
* and prevents Jackson from closing it.
*
* @param output the {@link OutputStream}
* @param value the value to write
* @throws IOException on error
*/
private void writeAndFlushValue(OutputStream output, Object value) throws IOException {
mapper.writeValue(new NoCloseOutputStream(output), value);
output.flush();
}
private boolean isInvalidResponse(JsonNode response) {
return !response.isObject();
}
private void addId(String id, ObjectNode request) {
if (id != null) {
request.put(ID, id);
}
}
private void addProtocolAndMethod(String methodName, ObjectNode request) { | request.put(JSONRPC, VERSION); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData; | notifyBeforeRequestListener(request);
addNoneArguments(request);
return request;
}
/**
* Writes and flushes a value to the given {@link OutputStream}
* and prevents Jackson from closing it.
*
* @param output the {@link OutputStream}
* @param value the value to write
* @throws IOException on error
*/
private void writeAndFlushValue(OutputStream output, Object value) throws IOException {
mapper.writeValue(new NoCloseOutputStream(output), value);
output.flush();
}
private boolean isInvalidResponse(JsonNode response) {
return !response.isObject();
}
private void addId(String id, ObjectNode request) {
if (id != null) {
request.put(ID, id);
}
}
private void addProtocolAndMethod(String methodName, ObjectNode request) {
request.put(JSONRPC, VERSION); | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData;
notifyBeforeRequestListener(request);
addNoneArguments(request);
return request;
}
/**
* Writes and flushes a value to the given {@link OutputStream}
* and prevents Jackson from closing it.
*
* @param output the {@link OutputStream}
* @param value the value to write
* @throws IOException on error
*/
private void writeAndFlushValue(OutputStream output, Object value) throws IOException {
mapper.writeValue(new NoCloseOutputStream(output), value);
output.flush();
}
private boolean isInvalidResponse(JsonNode response) {
return !response.isObject();
}
private void addId(String id, ObjectNode request) {
if (id != null) {
request.put(ID, id);
}
}
private void addProtocolAndMethod(String methodName, ObjectNode request) {
request.put(JSONRPC, VERSION); | request.put(METHOD, methodName); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData; | output.flush();
}
private boolean isInvalidResponse(JsonNode response) {
return !response.isObject();
}
private void addId(String id, ObjectNode request) {
if (id != null) {
request.put(ID, id);
}
}
private void addProtocolAndMethod(String methodName, ObjectNode request) {
request.put(JSONRPC, VERSION);
request.put(METHOD, methodName);
}
private void addParameters(Object arguments, ObjectNode request) {
// object array args
if (isArrayArguments(arguments)) {
addArrayArguments(arguments, request);
// collection args
} else if (isCollectionArguments(arguments)) {
addCollectionArguments(arguments, request);
// map args
} else if (isMapArguments(arguments)) {
addMapArguments(arguments, request);
// other args
} else if (arguments != null) { | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String VERSION = "2.0";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.VERSION;
import static com.googlecode.jsonrpc4j.Util.hasNonNullData;
output.flush();
}
private boolean isInvalidResponse(JsonNode response) {
return !response.isObject();
}
private void addId(String id, ObjectNode request) {
if (id != null) {
request.put(ID, id);
}
}
private void addProtocolAndMethod(String methodName, ObjectNode request) {
request.put(JSONRPC, VERSION);
request.put(METHOD, methodName);
}
private void addParameters(Object arguments, ObjectNode request) {
// object array args
if (isArrayArguments(arguments)) {
addArrayArguments(arguments, request);
// collection args
} else if (isCollectionArguments(arguments)) {
addCollectionArguments(arguments, request);
// map args
} else if (isMapArguments(arguments)) {
addMapArguments(arguments, request);
// other args
} else if (arguments != null) { | request.set(PARAMS, mapper.valueToTree(arguments)); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT; | RequestAsyncFuture<T> futureCallback = new RequestAsyncFuture<>(returnType, callback);
BasicHttpContext httpContext = new BasicHttpContext();
requester.execute(asyncRequestProducer, asyncResponseConsumer, pool, httpContext, futureCallback);
return (callback instanceof JsonRpcFuture ? (Future<T>) callback : null);
}
/**
* Set the request headers.
*
* @param request the request object
* @param headers to be used
*/
private void addHeaders(HttpRequest request, Map<String, String> headers) {
for (Map.Entry<String, String> key : headers.entrySet()) {
request.addHeader(key.getKey(), key.getValue());
}
}
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param httpRequest the stream on error
*/
private void writeRequest(String methodName, Object arguments, HttpRequest httpRequest) throws IOException {
ObjectNode request = mapper.createObjectNode(); | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
RequestAsyncFuture<T> futureCallback = new RequestAsyncFuture<>(returnType, callback);
BasicHttpContext httpContext = new BasicHttpContext();
requester.execute(asyncRequestProducer, asyncResponseConsumer, pool, httpContext, futureCallback);
return (callback instanceof JsonRpcFuture ? (Future<T>) callback : null);
}
/**
* Set the request headers.
*
* @param request the request object
* @param headers to be used
*/
private void addHeaders(HttpRequest request, Map<String, String> headers) {
for (Map.Entry<String, String> key : headers.entrySet()) {
request.addHeader(key.getKey(), key.getValue());
}
}
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param httpRequest the stream on error
*/
private void writeRequest(String methodName, Object arguments, HttpRequest httpRequest) throws IOException {
ObjectNode request = mapper.createObjectNode(); | request.put(ID, nextId.getAndIncrement()); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT; |
BasicHttpContext httpContext = new BasicHttpContext();
requester.execute(asyncRequestProducer, asyncResponseConsumer, pool, httpContext, futureCallback);
return (callback instanceof JsonRpcFuture ? (Future<T>) callback : null);
}
/**
* Set the request headers.
*
* @param request the request object
* @param headers to be used
*/
private void addHeaders(HttpRequest request, Map<String, String> headers) {
for (Map.Entry<String, String> key : headers.entrySet()) {
request.addHeader(key.getKey(), key.getValue());
}
}
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param httpRequest the stream on error
*/
private void writeRequest(String methodName, Object arguments, HttpRequest httpRequest) throws IOException {
ObjectNode request = mapper.createObjectNode();
request.put(ID, nextId.getAndIncrement()); | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
BasicHttpContext httpContext = new BasicHttpContext();
requester.execute(asyncRequestProducer, asyncResponseConsumer, pool, httpContext, futureCallback);
return (callback instanceof JsonRpcFuture ? (Future<T>) callback : null);
}
/**
* Set the request headers.
*
* @param request the request object
* @param headers to be used
*/
private void addHeaders(HttpRequest request, Map<String, String> headers) {
for (Map.Entry<String, String> key : headers.entrySet()) {
request.addHeader(key.getKey(), key.getValue());
}
}
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param httpRequest the stream on error
*/
private void writeRequest(String methodName, Object arguments, HttpRequest httpRequest) throws IOException {
ObjectNode request = mapper.createObjectNode();
request.put(ID, nextId.getAndIncrement()); | request.put(JSONRPC, JsonRpcBasicServer.VERSION); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT; | BasicHttpContext httpContext = new BasicHttpContext();
requester.execute(asyncRequestProducer, asyncResponseConsumer, pool, httpContext, futureCallback);
return (callback instanceof JsonRpcFuture ? (Future<T>) callback : null);
}
/**
* Set the request headers.
*
* @param request the request object
* @param headers to be used
*/
private void addHeaders(HttpRequest request, Map<String, String> headers) {
for (Map.Entry<String, String> key : headers.entrySet()) {
request.addHeader(key.getKey(), key.getValue());
}
}
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param httpRequest the stream on error
*/
private void writeRequest(String methodName, Object arguments, HttpRequest httpRequest) throws IOException {
ObjectNode request = mapper.createObjectNode();
request.put(ID, nextId.getAndIncrement());
request.put(JSONRPC, JsonRpcBasicServer.VERSION); | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
BasicHttpContext httpContext = new BasicHttpContext();
requester.execute(asyncRequestProducer, asyncResponseConsumer, pool, httpContext, futureCallback);
return (callback instanceof JsonRpcFuture ? (Future<T>) callback : null);
}
/**
* Set the request headers.
*
* @param request the request object
* @param headers to be used
*/
private void addHeaders(HttpRequest request, Map<String, String> headers) {
for (Map.Entry<String, String> key : headers.entrySet()) {
request.addHeader(key.getKey(), key.getValue());
}
}
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param httpRequest the stream on error
*/
private void writeRequest(String methodName, Object arguments, HttpRequest httpRequest) throws IOException {
ObjectNode request = mapper.createObjectNode();
request.put(ID, nextId.getAndIncrement());
request.put(JSONRPC, JsonRpcBasicServer.VERSION); | request.put(METHOD, methodName); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT; |
/**
* Set the request headers.
*
* @param request the request object
* @param headers to be used
*/
private void addHeaders(HttpRequest request, Map<String, String> headers) {
for (Map.Entry<String, String> key : headers.entrySet()) {
request.addHeader(key.getKey(), key.getValue());
}
}
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param httpRequest the stream on error
*/
private void writeRequest(String methodName, Object arguments, HttpRequest httpRequest) throws IOException {
ObjectNode request = mapper.createObjectNode();
request.put(ID, nextId.getAndIncrement());
request.put(JSONRPC, JsonRpcBasicServer.VERSION);
request.put(METHOD, methodName);
if (arguments != null && arguments.getClass().isArray()) {
Object[] args = Object[].class.cast(arguments);
if (args.length > 0) { | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
/**
* Set the request headers.
*
* @param request the request object
* @param headers to be used
*/
private void addHeaders(HttpRequest request, Map<String, String> headers) {
for (Map.Entry<String, String> key : headers.entrySet()) {
request.addHeader(key.getKey(), key.getValue());
}
}
/**
* Writes a request.
*
* @param methodName the method name
* @param arguments the arguments
* @param httpRequest the stream on error
*/
private void writeRequest(String methodName, Object arguments, HttpRequest httpRequest) throws IOException {
ObjectNode request = mapper.createObjectNode();
request.put(ID, nextId.getAndIncrement());
request.put(JSONRPC, JsonRpcBasicServer.VERSION);
request.put(METHOD, methodName);
if (arguments != null && arguments.getClass().isArray()) {
Object[] args = Object[].class.cast(arguments);
if (args.length > 0) { | request.set(PARAMS, mapper.valueToTree(Object[].class.cast(arguments))); |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT; | * {@code JsonRpcCallback} with the result cast to the given
* {@code returnType}, or null if void.
*
* @param methodName the name of the method to invoke
* @param argument the arguments to the method
* @param returnType the return type
* @param <T> the return type
* @param callback the {@code JsonRpcCallback}
*/
public <T> void invoke(String methodName, Object argument, Class<T> returnType, JsonRpcCallback<T> callback) {
invoke(methodName, argument, returnType, new HashMap<String, String>(), callback);
}
/**
* Reads a JSON-RPC response from the server. This blocks until a response
* is received.
*
* @param returnType the expected return type
* @param ips the {@link InputStream} to read from
* @return the object returned by the JSON-RPC response
* @throws Throwable on error
*/
private <T> T readResponse(Type returnType, InputStream ips) throws Throwable {
JsonNode response = mapper.readTree(new NoCloseInputStream(ips));
logger.debug("JSON-RPC Response: {}", response);
if (!response.isObject()) {
throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
}
ObjectNode jsonObject = ObjectNode.class.cast(response);
| // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
* {@code JsonRpcCallback} with the result cast to the given
* {@code returnType}, or null if void.
*
* @param methodName the name of the method to invoke
* @param argument the arguments to the method
* @param returnType the return type
* @param <T> the return type
* @param callback the {@code JsonRpcCallback}
*/
public <T> void invoke(String methodName, Object argument, Class<T> returnType, JsonRpcCallback<T> callback) {
invoke(methodName, argument, returnType, new HashMap<String, String>(), callback);
}
/**
* Reads a JSON-RPC response from the server. This blocks until a response
* is received.
*
* @param returnType the expected return type
* @param ips the {@link InputStream} to read from
* @return the object returned by the JSON-RPC response
* @throws Throwable on error
*/
private <T> T readResponse(Type returnType, InputStream ips) throws Throwable {
JsonNode response = mapper.readTree(new NoCloseInputStream(ips));
logger.debug("JSON-RPC Response: {}", response);
if (!response.isObject()) {
throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
}
ObjectNode jsonObject = ObjectNode.class.cast(response);
| if (jsonObject.has(ERROR) && jsonObject.get(ERROR) != null && !jsonObject.get(ERROR).isNull()) { |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
| import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT; | * @param methodName the name of the method to invoke
* @param argument the arguments to the method
* @param returnType the return type
* @param <T> the return type
* @param callback the {@code JsonRpcCallback}
*/
public <T> void invoke(String methodName, Object argument, Class<T> returnType, JsonRpcCallback<T> callback) {
invoke(methodName, argument, returnType, new HashMap<String, String>(), callback);
}
/**
* Reads a JSON-RPC response from the server. This blocks until a response
* is received.
*
* @param returnType the expected return type
* @param ips the {@link InputStream} to read from
* @return the object returned by the JSON-RPC response
* @throws Throwable on error
*/
private <T> T readResponse(Type returnType, InputStream ips) throws Throwable {
JsonNode response = mapper.readTree(new NoCloseInputStream(ips));
logger.debug("JSON-RPC Response: {}", response);
if (!response.isObject()) {
throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
}
ObjectNode jsonObject = ObjectNode.class.cast(response);
if (jsonObject.has(ERROR) && jsonObject.get(ERROR) != null && !jsonObject.get(ERROR).isNull()) {
throw exceptionResolver.resolveException(jsonObject);
} | // Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ERROR = "error";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String ID = "id";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String JSONRPC = "jsonrpc";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String METHOD = "method";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String PARAMS = "params";
//
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java
// public static final String RESULT = "result";
// Path: src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpAsyncClient.java
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
import org.apache.http.impl.nio.pool.BasicNIOConnPool;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequester;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOReactorException;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ERROR;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.ID;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.JSONRPC;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.METHOD;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.PARAMS;
import static com.googlecode.jsonrpc4j.JsonRpcBasicServer.RESULT;
* @param methodName the name of the method to invoke
* @param argument the arguments to the method
* @param returnType the return type
* @param <T> the return type
* @param callback the {@code JsonRpcCallback}
*/
public <T> void invoke(String methodName, Object argument, Class<T> returnType, JsonRpcCallback<T> callback) {
invoke(methodName, argument, returnType, new HashMap<String, String>(), callback);
}
/**
* Reads a JSON-RPC response from the server. This blocks until a response
* is received.
*
* @param returnType the expected return type
* @param ips the {@link InputStream} to read from
* @return the object returned by the JSON-RPC response
* @throws Throwable on error
*/
private <T> T readResponse(Type returnType, InputStream ips) throws Throwable {
JsonNode response = mapper.readTree(new NoCloseInputStream(ips));
logger.debug("JSON-RPC Response: {}", response);
if (!response.isObject()) {
throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response);
}
ObjectNode jsonObject = ObjectNode.class.cast(response);
if (jsonObject.has(ERROR) && jsonObject.get(ERROR) != null && !jsonObject.get(ERROR).isNull()) {
throw exceptionResolver.resolveException(jsonObject);
} | if (jsonObject.has(RESULT) && !jsonObject.get(RESULT).isNull() && jsonObject.get(RESULT) != null) { |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_12_R1/PandaWireInjector.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.BlockRedstoneWire;
import net.minecraft.server.v1_12_R1.Blocks;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.MinecraftKey; | package cn.jiongjionger.neverlag.module.pandawire.v1_12_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_12_R1/PandaWireInjector.java
import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.BlockRedstoneWire;
import net.minecraft.server.v1_12_R1.Blocks;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.MinecraftKey;
package cn.jiongjionger.neverlag.module.pandawire.v1_12_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | PandaWireReflectUtil.setStatic("REDSTONE_WIRE", Blocks.class, get("redstone_wire")); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/utils/PingUtils.java | // Path: src/main/java/cn/jiongjionger/neverlag/utils/Reflection.java
// public interface FieldAccessor<T> {
// /**
// * Retrieve the content of a field.
// *
// * @param target the target object, or NULL for a static field.
// * @return The value of the field.
// */
// T get(Object target);
//
// /**
// * Determine if the given object has this field.
// *
// * @param target the object to test.
// * @return TRUE if it does, FALSE otherwise.
// */
// boolean hasField(Object target);
//
// /**
// * Set the content of a field.
// *
// * @param target the target object, or NULL for a static field.
// * @param value the new value of the field.
// */
// void set(Object target, Object value);
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/utils/Reflection.java
// public interface MethodInvoker {
// /**
// * Invoke a method on a specific target object.
// *
// * @param target - the target object, or NULL for a static method.
// * @param arguments - the arguments to pass to the method.
// * @return The return value, or NULL if is void.
// */
// Object invoke(Object target, Object... arguments);
// }
| import cn.jiongjionger.neverlag.utils.Reflection.FieldAccessor;
import cn.jiongjionger.neverlag.utils.Reflection.MethodInvoker;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.LinkedHashMap; | package cn.jiongjionger.neverlag.utils;
public final class PingUtils {
private static final MethodInvoker method_getHandle; | // Path: src/main/java/cn/jiongjionger/neverlag/utils/Reflection.java
// public interface FieldAccessor<T> {
// /**
// * Retrieve the content of a field.
// *
// * @param target the target object, or NULL for a static field.
// * @return The value of the field.
// */
// T get(Object target);
//
// /**
// * Determine if the given object has this field.
// *
// * @param target the object to test.
// * @return TRUE if it does, FALSE otherwise.
// */
// boolean hasField(Object target);
//
// /**
// * Set the content of a field.
// *
// * @param target the target object, or NULL for a static field.
// * @param value the new value of the field.
// */
// void set(Object target, Object value);
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/utils/Reflection.java
// public interface MethodInvoker {
// /**
// * Invoke a method on a specific target object.
// *
// * @param target - the target object, or NULL for a static method.
// * @param arguments - the arguments to pass to the method.
// * @return The return value, or NULL if is void.
// */
// Object invoke(Object target, Object... arguments);
// }
// Path: src/main/java/cn/jiongjionger/neverlag/utils/PingUtils.java
import cn.jiongjionger.neverlag.utils.Reflection.FieldAccessor;
import cn.jiongjionger.neverlag.utils.Reflection.MethodInvoker;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.LinkedHashMap;
package cn.jiongjionger.neverlag.utils;
public final class PingUtils {
private static final MethodInvoker method_getHandle; | private static final FieldAccessor<Integer> field_ping; |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_11_R1/PandaWireInjector.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockRedstoneWire;
import net.minecraft.server.v1_11_R1.Blocks;
import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.MinecraftKey; | package cn.jiongjionger.neverlag.module.pandawire.v1_11_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_11_R1/PandaWireInjector.java
import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockRedstoneWire;
import net.minecraft.server.v1_11_R1.Blocks;
import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.MinecraftKey;
package cn.jiongjionger.neverlag.module.pandawire.v1_11_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | PandaWireReflectUtil.setStatic("REDSTONE_WIRE", Blocks.class, get("redstone_wire")); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_10_R1/PandaRedstoneWire.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_10_R1.BaseBlockPosition;
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_10_R1.BlockPiston;
import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_10_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_10_R1.BlockRedstoneWire;
import net.minecraft.server.v1_10_R1.EnumDirection;
import net.minecraft.server.v1_10_R1.IBlockAccess;
import net.minecraft.server.v1_10_R1.IBlockData;
import net.minecraft.server.v1_10_R1.SoundEffectType;
import net.minecraft.server.v1_10_R1.World; | package cn.jiongjionger.neverlag.module.pandawire.v1_10_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_10_R1/PandaRedstoneWire.java
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_10_R1.BaseBlockPosition;
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_10_R1.BlockPiston;
import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_10_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_10_R1.BlockRedstoneWire;
import net.minecraft.server.v1_10_R1.EnumDirection;
import net.minecraft.server.v1_10_R1.IBlockAccess;
import net.minecraft.server.v1_10_R1.IBlockData;
import net.minecraft.server.v1_10_R1.SoundEffectType;
import net.minecraft.server.v1_10_R1.World;
package cn.jiongjionger.neverlag.module.pandawire.v1_10_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | set.add(PandaWireReflectUtil.getOfT(facing, BaseBlockPosition.class)); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/I18n.java | // Path: src/main/java/cn/jiongjionger/neverlag/utils/NeverLagUtils.java
// public final class NeverLagUtils {
// public static int getMaxPermission(Player p, String node) {
// int maxLimit = 0;
// for (PermissionAttachmentInfo perm : p.getEffectivePermissions()) {
// String permission = perm.getPermission();
// if (!permission.toLowerCase().startsWith(node.toLowerCase())) {
// continue;
// }
// String[] split = permission.split("\\.");
// try {
// int number = Integer.parseInt(split[split.length - 1]);
// if (number > maxLimit) {
// maxLimit = number;
// }
// } catch (NumberFormatException ignore) { }
// }
// return maxLimit;
// }
//
// public static LinkedHashMap<String, Integer> sortMapByValues(HashMap<String, Integer> map) {
// if (map.isEmpty()) {
// return null;
// }
// Set<Map.Entry<String, Integer>> entries = map.entrySet();
// List<Map.Entry<String, Integer>> list = new LinkedList<>(entries);
// Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
// @Override
// public int compare(Map.Entry<String, Integer> entry1, Map.Entry<String, Integer> entry2) {
// return entry1.getValue().compareTo(entry2.getValue());
// }
// });
// LinkedHashMap<String, Integer> sortMap = new LinkedHashMap<>();
// for (Map.Entry<String, Integer> entry : list) {
// sortMap.put(entry.getKey(), entry.getValue());
// }
// return sortMap;
// }
//
// public static boolean checkCustomNpc(Entity entity) {
// return entity == null || entity.hasMetadata("NPC") || entity.hasMetadata("MyPet");
// }
//
// /*
// * 判断掉落物附近有没有玩家
// *
// * @param item 掉落物
// * @param distance 判断距离
// * @return 是否存在玩家
// */
// public static boolean hasPlayerNearby(Entity entity, int distance) {
// for (Entity e : entity.getNearbyEntities(distance, distance, distance)) {
// if (e instanceof Player && !checkCustomNpc(e)) {
// return true;
// }
// }
// return false;
// }
//
// public static Locale toLocale(String str) {
// String language;
// String country = "";
//
// int idx = str.indexOf('_');
// if (idx == -1) {
// idx = str.indexOf('-');
// }
// if (idx == -1) {
// language = str;
// } else {
// language = str.substring(0, idx);
// country = str.substring(idx + 1, str.length());
// }
//
// return new Locale(language, country);
// }
//
// public static void broadcastIfOnline(String message) {
// if (!Bukkit.getOnlinePlayers().isEmpty())
// Bukkit.broadcastMessage(message);
// }
//
// private NeverLagUtils() {}
// }
| import cn.jiongjionger.neverlag.utils.NeverLagUtils;
import org.bukkit.ChatColor;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.MessageFormat;
import java.util.*;
import java.util.logging.Level; | package cn.jiongjionger.neverlag;
public class I18n extends ResourceBundle {
public static String colorize(String str) {
return ChatColor.translateAlternateColorCodes('&', str);
}
public static I18n load(File directory, String locale) throws FileNotFoundException { | // Path: src/main/java/cn/jiongjionger/neverlag/utils/NeverLagUtils.java
// public final class NeverLagUtils {
// public static int getMaxPermission(Player p, String node) {
// int maxLimit = 0;
// for (PermissionAttachmentInfo perm : p.getEffectivePermissions()) {
// String permission = perm.getPermission();
// if (!permission.toLowerCase().startsWith(node.toLowerCase())) {
// continue;
// }
// String[] split = permission.split("\\.");
// try {
// int number = Integer.parseInt(split[split.length - 1]);
// if (number > maxLimit) {
// maxLimit = number;
// }
// } catch (NumberFormatException ignore) { }
// }
// return maxLimit;
// }
//
// public static LinkedHashMap<String, Integer> sortMapByValues(HashMap<String, Integer> map) {
// if (map.isEmpty()) {
// return null;
// }
// Set<Map.Entry<String, Integer>> entries = map.entrySet();
// List<Map.Entry<String, Integer>> list = new LinkedList<>(entries);
// Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
// @Override
// public int compare(Map.Entry<String, Integer> entry1, Map.Entry<String, Integer> entry2) {
// return entry1.getValue().compareTo(entry2.getValue());
// }
// });
// LinkedHashMap<String, Integer> sortMap = new LinkedHashMap<>();
// for (Map.Entry<String, Integer> entry : list) {
// sortMap.put(entry.getKey(), entry.getValue());
// }
// return sortMap;
// }
//
// public static boolean checkCustomNpc(Entity entity) {
// return entity == null || entity.hasMetadata("NPC") || entity.hasMetadata("MyPet");
// }
//
// /*
// * 判断掉落物附近有没有玩家
// *
// * @param item 掉落物
// * @param distance 判断距离
// * @return 是否存在玩家
// */
// public static boolean hasPlayerNearby(Entity entity, int distance) {
// for (Entity e : entity.getNearbyEntities(distance, distance, distance)) {
// if (e instanceof Player && !checkCustomNpc(e)) {
// return true;
// }
// }
// return false;
// }
//
// public static Locale toLocale(String str) {
// String language;
// String country = "";
//
// int idx = str.indexOf('_');
// if (idx == -1) {
// idx = str.indexOf('-');
// }
// if (idx == -1) {
// language = str;
// } else {
// language = str.substring(0, idx);
// country = str.substring(idx + 1, str.length());
// }
//
// return new Locale(language, country);
// }
//
// public static void broadcastIfOnline(String message) {
// if (!Bukkit.getOnlinePlayers().isEmpty())
// Bukkit.broadcastMessage(message);
// }
//
// private NeverLagUtils() {}
// }
// Path: src/main/java/cn/jiongjionger/neverlag/I18n.java
import cn.jiongjionger.neverlag.utils.NeverLagUtils;
import org.bukkit.ChatColor;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.MessageFormat;
import java.util.*;
import java.util.logging.Level;
package cn.jiongjionger.neverlag;
public class I18n extends ResourceBundle {
public static String colorize(String str) {
return ChatColor.translateAlternateColorCodes('&', str);
}
public static I18n load(File directory, String locale) throws FileNotFoundException { | Locale localeObj = NeverLagUtils.toLocale(locale); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_9_R1/PandaWireInjector.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_9_R1.Block;
import net.minecraft.server.v1_9_R1.BlockRedstoneWire;
import net.minecraft.server.v1_9_R1.Blocks;
import net.minecraft.server.v1_9_R1.IBlockData;
import net.minecraft.server.v1_9_R1.MinecraftKey; | package cn.jiongjionger.neverlag.module.pandawire.v1_9_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_9_R1/PandaWireInjector.java
import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_9_R1.Block;
import net.minecraft.server.v1_9_R1.BlockRedstoneWire;
import net.minecraft.server.v1_9_R1.Blocks;
import net.minecraft.server.v1_9_R1.IBlockData;
import net.minecraft.server.v1_9_R1.MinecraftKey;
package cn.jiongjionger.neverlag.module.pandawire.v1_9_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | PandaWireReflectUtil.setStatic("REDSTONE_WIRE", Blocks.class, get("redstone_wire")); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_9_R2/PandaWireInjector.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_9_R2.Block;
import net.minecraft.server.v1_9_R2.BlockRedstoneWire;
import net.minecraft.server.v1_9_R2.Blocks;
import net.minecraft.server.v1_9_R2.IBlockData;
import net.minecraft.server.v1_9_R2.MinecraftKey; | package cn.jiongjionger.neverlag.module.pandawire.v1_9_R2;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_9_R2/PandaWireInjector.java
import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_9_R2.Block;
import net.minecraft.server.v1_9_R2.BlockRedstoneWire;
import net.minecraft.server.v1_9_R2.Blocks;
import net.minecraft.server.v1_9_R2.IBlockData;
import net.minecraft.server.v1_9_R2.MinecraftKey;
package cn.jiongjionger.neverlag.module.pandawire.v1_9_R2;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | PandaWireReflectUtil.setStatic("REDSTONE_WIRE", Blocks.class, get("redstone_wire")); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_9_R2/PandaRedstoneWire.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_9_R2.BaseBlockPosition;
import net.minecraft.server.v1_9_R2.Block;
import net.minecraft.server.v1_9_R2.BlockDiodeAbstract;
import net.minecraft.server.v1_9_R2.BlockPiston;
import net.minecraft.server.v1_9_R2.BlockPosition;
import net.minecraft.server.v1_9_R2.BlockRedstoneComparator;
import net.minecraft.server.v1_9_R2.BlockRedstoneTorch;
import net.minecraft.server.v1_9_R2.BlockRedstoneWire;
import net.minecraft.server.v1_9_R2.EnumDirection;
import net.minecraft.server.v1_9_R2.IBlockAccess;
import net.minecraft.server.v1_9_R2.IBlockData;
import net.minecraft.server.v1_9_R2.SoundEffectType;
import net.minecraft.server.v1_9_R2.World; | package cn.jiongjionger.neverlag.module.pandawire.v1_9_R2;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_9_R2/PandaRedstoneWire.java
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_9_R2.BaseBlockPosition;
import net.minecraft.server.v1_9_R2.Block;
import net.minecraft.server.v1_9_R2.BlockDiodeAbstract;
import net.minecraft.server.v1_9_R2.BlockPiston;
import net.minecraft.server.v1_9_R2.BlockPosition;
import net.minecraft.server.v1_9_R2.BlockRedstoneComparator;
import net.minecraft.server.v1_9_R2.BlockRedstoneTorch;
import net.minecraft.server.v1_9_R2.BlockRedstoneWire;
import net.minecraft.server.v1_9_R2.EnumDirection;
import net.minecraft.server.v1_9_R2.IBlockAccess;
import net.minecraft.server.v1_9_R2.IBlockData;
import net.minecraft.server.v1_9_R2.SoundEffectType;
import net.minecraft.server.v1_9_R2.World;
package cn.jiongjionger.neverlag.module.pandawire.v1_9_R2;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | set.add(PandaWireReflectUtil.getOfT(facing, BaseBlockPosition.class)); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R1/PandaWireInjector.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import org.bukkit.Bukkit;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R1.Block;
import net.minecraft.server.v1_8_R1.BlockRedstoneWire;
import net.minecraft.server.v1_8_R1.Blocks;
import net.minecraft.server.v1_8_R1.IBlockData;
import net.minecraft.server.v1_8_R1.MinecraftKey; | package cn.jiongjionger.neverlag.module.pandawire.v1_8_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return (Block) Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R1/PandaWireInjector.java
import org.bukkit.Bukkit;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R1.Block;
import net.minecraft.server.v1_8_R1.BlockRedstoneWire;
import net.minecraft.server.v1_8_R1.Blocks;
import net.minecraft.server.v1_8_R1.IBlockData;
import net.minecraft.server.v1_8_R1.MinecraftKey;
package cn.jiongjionger.neverlag.module.pandawire.v1_8_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return (Block) Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | PandaWireReflectUtil.setStatic("REDSTONE_WIRE", Blocks.class, get("redstone_wire")); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R2/PandaWireInjector.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import org.bukkit.Bukkit;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R2.Block;
import net.minecraft.server.v1_8_R2.BlockRedstoneWire;
import net.minecraft.server.v1_8_R2.Blocks;
import net.minecraft.server.v1_8_R2.IBlockData;
import net.minecraft.server.v1_8_R2.MinecraftKey; | package cn.jiongjionger.neverlag.module.pandawire.v1_8_R2;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R2/PandaWireInjector.java
import org.bukkit.Bukkit;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R2.Block;
import net.minecraft.server.v1_8_R2.BlockRedstoneWire;
import net.minecraft.server.v1_8_R2.Blocks;
import net.minecraft.server.v1_8_R2.IBlockData;
import net.minecraft.server.v1_8_R2.MinecraftKey;
package cn.jiongjionger.neverlag.module.pandawire.v1_8_R2;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | PandaWireReflectUtil.setStatic("REDSTONE_WIRE", Blocks.class, get("redstone_wire")); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R2/PandaRedstoneWire.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R2.BaseBlockPosition;
import net.minecraft.server.v1_8_R2.Block;
import net.minecraft.server.v1_8_R2.BlockDiodeAbstract;
import net.minecraft.server.v1_8_R2.BlockDirectional;
import net.minecraft.server.v1_8_R2.BlockPiston;
import net.minecraft.server.v1_8_R2.BlockPosition;
import net.minecraft.server.v1_8_R2.BlockRedstoneComparator;
import net.minecraft.server.v1_8_R2.BlockRedstoneTorch;
import net.minecraft.server.v1_8_R2.BlockRedstoneWire;
import net.minecraft.server.v1_8_R2.BlockTorch;
import net.minecraft.server.v1_8_R2.EnumDirection;
import net.minecraft.server.v1_8_R2.IBlockAccess;
import net.minecraft.server.v1_8_R2.IBlockData;
import net.minecraft.server.v1_8_R2.World; | package cn.jiongjionger.neverlag.module.pandawire.v1_8_R2;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
// facing方向的枚举
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
// facing垂直的枚举
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
// 上述两者之和
private static final EnumDirection[] facings = ArrayUtils.addAll(facingsVertical, facingsHorizontal);
// facing的X、Y、Z的偏移量位置数组
private static final BaseBlockPosition[] surroundingBlocksOffset;
// 初始化surroundingBlocksOffset
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R2/PandaRedstoneWire.java
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R2.BaseBlockPosition;
import net.minecraft.server.v1_8_R2.Block;
import net.minecraft.server.v1_8_R2.BlockDiodeAbstract;
import net.minecraft.server.v1_8_R2.BlockDirectional;
import net.minecraft.server.v1_8_R2.BlockPiston;
import net.minecraft.server.v1_8_R2.BlockPosition;
import net.minecraft.server.v1_8_R2.BlockRedstoneComparator;
import net.minecraft.server.v1_8_R2.BlockRedstoneTorch;
import net.minecraft.server.v1_8_R2.BlockRedstoneWire;
import net.minecraft.server.v1_8_R2.BlockTorch;
import net.minecraft.server.v1_8_R2.EnumDirection;
import net.minecraft.server.v1_8_R2.IBlockAccess;
import net.minecraft.server.v1_8_R2.IBlockData;
import net.minecraft.server.v1_8_R2.World;
package cn.jiongjionger.neverlag.module.pandawire.v1_8_R2;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
// facing方向的枚举
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
// facing垂直的枚举
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
// 上述两者之和
private static final EnumDirection[] facings = ArrayUtils.addAll(facingsVertical, facingsHorizontal);
// facing的X、Y、Z的偏移量位置数组
private static final BaseBlockPosition[] surroundingBlocksOffset;
// 初始化surroundingBlocksOffset
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | set.add(PandaWireReflectUtil.getOfT(facing, BaseBlockPosition.class)); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_10_R1/PandaWireInjector.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockRedstoneWire;
import net.minecraft.server.v1_10_R1.Blocks;
import net.minecraft.server.v1_10_R1.IBlockData;
import net.minecraft.server.v1_10_R1.MinecraftKey; | package cn.jiongjionger.neverlag.module.pandawire.v1_10_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_10_R1/PandaWireInjector.java
import org.bukkit.Bukkit;
import com.google.common.collect.UnmodifiableIterator;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockRedstoneWire;
import net.minecraft.server.v1_10_R1.Blocks;
import net.minecraft.server.v1_10_R1.IBlockData;
import net.minecraft.server.v1_10_R1.MinecraftKey;
package cn.jiongjionger.neverlag.module.pandawire.v1_10_R1;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | PandaWireReflectUtil.setStatic("REDSTONE_WIRE", Blocks.class, get("redstone_wire")); |
jiongjionger/NeverLag | src/test/java/cn/jiongjionger/neverlag/utils/VersionUtilsTest.java | // Path: src/main/java/cn/jiongjionger/neverlag/utils/VersionUtils.java
// public static class Version implements Comparable<Version>, Serializable {
//
// private static final long serialVersionUID = 1L;
// private static final Pattern DEVELOPMENT_VERSION_PATTERN = Pattern.compile("-|(\\d{2}w\\d{2})([a-z])");
//
// private final int major;
// private final int minor;
// private final int build;
//
// public Version(int major, int minor, int build) {
// this.major = major;
// this.minor = minor;
// this.build = build;
// }
//
// public Version(String versionString) {
// Matcher matcher = DEVELOPMENT_VERSION_PATTERN.matcher(versionString);
// if (matcher.find()) { // 检查版本字符串里是否包含连字符(-)或类似 15w36a 形式的快照版本号
// throw new IllegalStateException("此插件不支持开发版/快照版服务端");
// }
//
// String[] sections = versionString.split("\\.");
// int[] versions = new int[3];
//
// if (sections.length < 1) {
// throw new IllegalStateException(versionString);
// }
//
// try {
// for (int i = 0; i < Math.min(sections.length, versions.length); i++) {
// versions[i] = Integer.parseInt(sections[i]);
// }
// } catch (NumberFormatException ex) {
// throw new IllegalStateException(versionString, ex);
// }
//
// this.major = versions[0];
// this.minor = versions[1];
// this.build = versions[2];
// }
//
// @Override
// public int compareTo(Version other) {
// int r;
// if ((r = Integer.compare(this.major, other.major)) != 0)
// return r;
// if ((r = Integer.compare(this.minor, other.minor)) != 0)
// return r;
// if ((r = Integer.compare(this.build, other.build)) != 0)
// return r;
// return 0;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || getClass() != obj.getClass()) {
// return false;
// }
// final Version other = (Version) obj;
// return this.major == other.major && this.minor == other.minor && this.build == other.build;
// }
//
// public int getBuild() {
// return build;
// }
//
// public int getMajor() {
// return major;
// }
//
// public int getMinor() {
// return minor;
// }
//
// @Override
// public int hashCode() {
// int hash = 7;
// hash = 67 * hash + this.major;
// hash = 67 * hash + this.minor;
// hash = 67 * hash + this.build;
// return hash;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder(6);
// builder.append(major).append('.').append(minor);
// if (build != 0)
// builder.append('.').append(build);
// return builder.toString();
// }
// }
| import cn.jiongjionger.neverlag.utils.VersionUtils.Version;
import org.junit.Test;
import static org.junit.Assert.*; | package cn.jiongjionger.neverlag.utils;
public class VersionUtilsTest {
@Test
public void testParsing() { | // Path: src/main/java/cn/jiongjionger/neverlag/utils/VersionUtils.java
// public static class Version implements Comparable<Version>, Serializable {
//
// private static final long serialVersionUID = 1L;
// private static final Pattern DEVELOPMENT_VERSION_PATTERN = Pattern.compile("-|(\\d{2}w\\d{2})([a-z])");
//
// private final int major;
// private final int minor;
// private final int build;
//
// public Version(int major, int minor, int build) {
// this.major = major;
// this.minor = minor;
// this.build = build;
// }
//
// public Version(String versionString) {
// Matcher matcher = DEVELOPMENT_VERSION_PATTERN.matcher(versionString);
// if (matcher.find()) { // 检查版本字符串里是否包含连字符(-)或类似 15w36a 形式的快照版本号
// throw new IllegalStateException("此插件不支持开发版/快照版服务端");
// }
//
// String[] sections = versionString.split("\\.");
// int[] versions = new int[3];
//
// if (sections.length < 1) {
// throw new IllegalStateException(versionString);
// }
//
// try {
// for (int i = 0; i < Math.min(sections.length, versions.length); i++) {
// versions[i] = Integer.parseInt(sections[i]);
// }
// } catch (NumberFormatException ex) {
// throw new IllegalStateException(versionString, ex);
// }
//
// this.major = versions[0];
// this.minor = versions[1];
// this.build = versions[2];
// }
//
// @Override
// public int compareTo(Version other) {
// int r;
// if ((r = Integer.compare(this.major, other.major)) != 0)
// return r;
// if ((r = Integer.compare(this.minor, other.minor)) != 0)
// return r;
// if ((r = Integer.compare(this.build, other.build)) != 0)
// return r;
// return 0;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || getClass() != obj.getClass()) {
// return false;
// }
// final Version other = (Version) obj;
// return this.major == other.major && this.minor == other.minor && this.build == other.build;
// }
//
// public int getBuild() {
// return build;
// }
//
// public int getMajor() {
// return major;
// }
//
// public int getMinor() {
// return minor;
// }
//
// @Override
// public int hashCode() {
// int hash = 7;
// hash = 67 * hash + this.major;
// hash = 67 * hash + this.minor;
// hash = 67 * hash + this.build;
// return hash;
// }
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder(6);
// builder.append(major).append('.').append(minor);
// if (build != 0)
// builder.append('.').append(build);
// return builder.toString();
// }
// }
// Path: src/test/java/cn/jiongjionger/neverlag/utils/VersionUtilsTest.java
import cn.jiongjionger.neverlag.utils.VersionUtils.Version;
import org.junit.Test;
import static org.junit.Assert.*;
package cn.jiongjionger.neverlag.utils;
public class VersionUtilsTest {
@Test
public void testParsing() { | assertEquals("1.6", new Version("1.6").toString()); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/utils/HardwareInfo.java | // Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixCPUInfo.java
// public class UnixCPUInfo {
//
// public String getProcessorData() {
// List<String> streamProcessorInfo = HardwareInfoUtils.readFile("/proc/cpuinfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamProcessorInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public Map<String, String> parseInfo() {
// HashMap<String, String> processorDataMap = new HashMap<>();
// String[] dataStringLines = getProcessorData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// processorDataMap.put(dataStringInfo[0].trim(),
// (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixMemoryInfo.java
// public class UnixMemoryInfo {
//
// private String getMemoryData() {
// List<String> streamMemoryInfo = HardwareInfoUtils.readFile("/proc/meminfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamMemoryInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public HashMap<String, String> parseInfo() {
// HashMap<String, String> memoryDataMap = new HashMap<>();
// String[] dataStringLines = getMemoryData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// memoryDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return memoryDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsCPUInfo.java
// public class WindowsCPUInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> processorDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PROCESSOR);
// String lineInfos = processorDataMap.get("Description");
// String[] infos = lineInfos.split("\\s+");
// processorDataMap.put("cpu family", infos[2]);
// processorDataMap.put("model", infos[4]);
// processorDataMap.put("stepping", infos[6]);
// processorDataMap.put("model name", processorDataMap.get("Name"));
// processorDataMap.put("cpu MHz", processorDataMap.get("MaxClockSpeed"));
// processorDataMap.put("vendor_id", processorDataMap.get("Manufacturer"));
// processorDataMap.put("cpu cores", processorDataMap.get("NumberOfCores"));
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsMemoryInfo.java
// public class WindowsMemoryInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> memoryDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PERFFORMATTEDDATA_PERFOS_MEMORY);
// memoryDataMap.putAll(WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PHYSICALMEMORY));
// memoryDataMap.put("MemAvailable", memoryDataMap.get("AvailableKBytes"));
// memoryDataMap.put("MemFree", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
// memoryDataMap.put("MemTotal", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("TotalPhysicalMemory"));
// return memoryDataMap;
// }
// }
| import cn.jiongjionger.neverlag.hardware.UnixCPUInfo;
import cn.jiongjionger.neverlag.hardware.UnixMemoryInfo;
import cn.jiongjionger.neverlag.hardware.WindowsCPUInfo;
import cn.jiongjionger.neverlag.hardware.WindowsMemoryInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap;
import java.util.Map; | package cn.jiongjionger.neverlag.utils;
public final class HardwareInfo {
private static final String OS = System.getProperty("os.name").toLowerCase();
private static final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
private static final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
private static Map<String, String> cpuInfoMap = new HashMap<>();
// 获取CPU信息(类似Intel(R) Xeon(R) CPU E5-2679V4 @ 3.2GHz 20 cores B0 stepping)
public static String getCPUInfo() {
try {
synchronized (cpuInfoMap) {
if (isWindows()) {
if (cpuInfoMap.isEmpty()) { | // Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixCPUInfo.java
// public class UnixCPUInfo {
//
// public String getProcessorData() {
// List<String> streamProcessorInfo = HardwareInfoUtils.readFile("/proc/cpuinfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamProcessorInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public Map<String, String> parseInfo() {
// HashMap<String, String> processorDataMap = new HashMap<>();
// String[] dataStringLines = getProcessorData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// processorDataMap.put(dataStringInfo[0].trim(),
// (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixMemoryInfo.java
// public class UnixMemoryInfo {
//
// private String getMemoryData() {
// List<String> streamMemoryInfo = HardwareInfoUtils.readFile("/proc/meminfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamMemoryInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public HashMap<String, String> parseInfo() {
// HashMap<String, String> memoryDataMap = new HashMap<>();
// String[] dataStringLines = getMemoryData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// memoryDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return memoryDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsCPUInfo.java
// public class WindowsCPUInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> processorDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PROCESSOR);
// String lineInfos = processorDataMap.get("Description");
// String[] infos = lineInfos.split("\\s+");
// processorDataMap.put("cpu family", infos[2]);
// processorDataMap.put("model", infos[4]);
// processorDataMap.put("stepping", infos[6]);
// processorDataMap.put("model name", processorDataMap.get("Name"));
// processorDataMap.put("cpu MHz", processorDataMap.get("MaxClockSpeed"));
// processorDataMap.put("vendor_id", processorDataMap.get("Manufacturer"));
// processorDataMap.put("cpu cores", processorDataMap.get("NumberOfCores"));
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsMemoryInfo.java
// public class WindowsMemoryInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> memoryDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PERFFORMATTEDDATA_PERFOS_MEMORY);
// memoryDataMap.putAll(WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PHYSICALMEMORY));
// memoryDataMap.put("MemAvailable", memoryDataMap.get("AvailableKBytes"));
// memoryDataMap.put("MemFree", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
// memoryDataMap.put("MemTotal", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("TotalPhysicalMemory"));
// return memoryDataMap;
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/utils/HardwareInfo.java
import cn.jiongjionger.neverlag.hardware.UnixCPUInfo;
import cn.jiongjionger.neverlag.hardware.UnixMemoryInfo;
import cn.jiongjionger.neverlag.hardware.WindowsCPUInfo;
import cn.jiongjionger.neverlag.hardware.WindowsMemoryInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap;
import java.util.Map;
package cn.jiongjionger.neverlag.utils;
public final class HardwareInfo {
private static final String OS = System.getProperty("os.name").toLowerCase();
private static final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
private static final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
private static Map<String, String> cpuInfoMap = new HashMap<>();
// 获取CPU信息(类似Intel(R) Xeon(R) CPU E5-2679V4 @ 3.2GHz 20 cores B0 stepping)
public static String getCPUInfo() {
try {
synchronized (cpuInfoMap) {
if (isWindows()) {
if (cpuInfoMap.isEmpty()) { | WindowsCPUInfo cpuInfo = new WindowsCPUInfo(); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/utils/HardwareInfo.java | // Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixCPUInfo.java
// public class UnixCPUInfo {
//
// public String getProcessorData() {
// List<String> streamProcessorInfo = HardwareInfoUtils.readFile("/proc/cpuinfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamProcessorInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public Map<String, String> parseInfo() {
// HashMap<String, String> processorDataMap = new HashMap<>();
// String[] dataStringLines = getProcessorData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// processorDataMap.put(dataStringInfo[0].trim(),
// (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixMemoryInfo.java
// public class UnixMemoryInfo {
//
// private String getMemoryData() {
// List<String> streamMemoryInfo = HardwareInfoUtils.readFile("/proc/meminfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamMemoryInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public HashMap<String, String> parseInfo() {
// HashMap<String, String> memoryDataMap = new HashMap<>();
// String[] dataStringLines = getMemoryData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// memoryDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return memoryDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsCPUInfo.java
// public class WindowsCPUInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> processorDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PROCESSOR);
// String lineInfos = processorDataMap.get("Description");
// String[] infos = lineInfos.split("\\s+");
// processorDataMap.put("cpu family", infos[2]);
// processorDataMap.put("model", infos[4]);
// processorDataMap.put("stepping", infos[6]);
// processorDataMap.put("model name", processorDataMap.get("Name"));
// processorDataMap.put("cpu MHz", processorDataMap.get("MaxClockSpeed"));
// processorDataMap.put("vendor_id", processorDataMap.get("Manufacturer"));
// processorDataMap.put("cpu cores", processorDataMap.get("NumberOfCores"));
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsMemoryInfo.java
// public class WindowsMemoryInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> memoryDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PERFFORMATTEDDATA_PERFOS_MEMORY);
// memoryDataMap.putAll(WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PHYSICALMEMORY));
// memoryDataMap.put("MemAvailable", memoryDataMap.get("AvailableKBytes"));
// memoryDataMap.put("MemFree", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
// memoryDataMap.put("MemTotal", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("TotalPhysicalMemory"));
// return memoryDataMap;
// }
// }
| import cn.jiongjionger.neverlag.hardware.UnixCPUInfo;
import cn.jiongjionger.neverlag.hardware.UnixMemoryInfo;
import cn.jiongjionger.neverlag.hardware.WindowsCPUInfo;
import cn.jiongjionger.neverlag.hardware.WindowsMemoryInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap;
import java.util.Map; | package cn.jiongjionger.neverlag.utils;
public final class HardwareInfo {
private static final String OS = System.getProperty("os.name").toLowerCase();
private static final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
private static final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
private static Map<String, String> cpuInfoMap = new HashMap<>();
// 获取CPU信息(类似Intel(R) Xeon(R) CPU E5-2679V4 @ 3.2GHz 20 cores B0 stepping)
public static String getCPUInfo() {
try {
synchronized (cpuInfoMap) {
if (isWindows()) {
if (cpuInfoMap.isEmpty()) {
WindowsCPUInfo cpuInfo = new WindowsCPUInfo();
cpuInfoMap = cpuInfo.parseInfo();
}
} else if (isUnix()) {
if (cpuInfoMap.isEmpty()) { | // Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixCPUInfo.java
// public class UnixCPUInfo {
//
// public String getProcessorData() {
// List<String> streamProcessorInfo = HardwareInfoUtils.readFile("/proc/cpuinfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamProcessorInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public Map<String, String> parseInfo() {
// HashMap<String, String> processorDataMap = new HashMap<>();
// String[] dataStringLines = getProcessorData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// processorDataMap.put(dataStringInfo[0].trim(),
// (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixMemoryInfo.java
// public class UnixMemoryInfo {
//
// private String getMemoryData() {
// List<String> streamMemoryInfo = HardwareInfoUtils.readFile("/proc/meminfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamMemoryInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public HashMap<String, String> parseInfo() {
// HashMap<String, String> memoryDataMap = new HashMap<>();
// String[] dataStringLines = getMemoryData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// memoryDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return memoryDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsCPUInfo.java
// public class WindowsCPUInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> processorDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PROCESSOR);
// String lineInfos = processorDataMap.get("Description");
// String[] infos = lineInfos.split("\\s+");
// processorDataMap.put("cpu family", infos[2]);
// processorDataMap.put("model", infos[4]);
// processorDataMap.put("stepping", infos[6]);
// processorDataMap.put("model name", processorDataMap.get("Name"));
// processorDataMap.put("cpu MHz", processorDataMap.get("MaxClockSpeed"));
// processorDataMap.put("vendor_id", processorDataMap.get("Manufacturer"));
// processorDataMap.put("cpu cores", processorDataMap.get("NumberOfCores"));
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsMemoryInfo.java
// public class WindowsMemoryInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> memoryDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PERFFORMATTEDDATA_PERFOS_MEMORY);
// memoryDataMap.putAll(WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PHYSICALMEMORY));
// memoryDataMap.put("MemAvailable", memoryDataMap.get("AvailableKBytes"));
// memoryDataMap.put("MemFree", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
// memoryDataMap.put("MemTotal", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("TotalPhysicalMemory"));
// return memoryDataMap;
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/utils/HardwareInfo.java
import cn.jiongjionger.neverlag.hardware.UnixCPUInfo;
import cn.jiongjionger.neverlag.hardware.UnixMemoryInfo;
import cn.jiongjionger.neverlag.hardware.WindowsCPUInfo;
import cn.jiongjionger.neverlag.hardware.WindowsMemoryInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap;
import java.util.Map;
package cn.jiongjionger.neverlag.utils;
public final class HardwareInfo {
private static final String OS = System.getProperty("os.name").toLowerCase();
private static final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
private static final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
private static Map<String, String> cpuInfoMap = new HashMap<>();
// 获取CPU信息(类似Intel(R) Xeon(R) CPU E5-2679V4 @ 3.2GHz 20 cores B0 stepping)
public static String getCPUInfo() {
try {
synchronized (cpuInfoMap) {
if (isWindows()) {
if (cpuInfoMap.isEmpty()) {
WindowsCPUInfo cpuInfo = new WindowsCPUInfo();
cpuInfoMap = cpuInfo.parseInfo();
}
} else if (isUnix()) {
if (cpuInfoMap.isEmpty()) { | UnixCPUInfo cpuInfo = new UnixCPUInfo(); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/utils/HardwareInfo.java | // Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixCPUInfo.java
// public class UnixCPUInfo {
//
// public String getProcessorData() {
// List<String> streamProcessorInfo = HardwareInfoUtils.readFile("/proc/cpuinfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamProcessorInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public Map<String, String> parseInfo() {
// HashMap<String, String> processorDataMap = new HashMap<>();
// String[] dataStringLines = getProcessorData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// processorDataMap.put(dataStringInfo[0].trim(),
// (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixMemoryInfo.java
// public class UnixMemoryInfo {
//
// private String getMemoryData() {
// List<String> streamMemoryInfo = HardwareInfoUtils.readFile("/proc/meminfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamMemoryInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public HashMap<String, String> parseInfo() {
// HashMap<String, String> memoryDataMap = new HashMap<>();
// String[] dataStringLines = getMemoryData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// memoryDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return memoryDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsCPUInfo.java
// public class WindowsCPUInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> processorDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PROCESSOR);
// String lineInfos = processorDataMap.get("Description");
// String[] infos = lineInfos.split("\\s+");
// processorDataMap.put("cpu family", infos[2]);
// processorDataMap.put("model", infos[4]);
// processorDataMap.put("stepping", infos[6]);
// processorDataMap.put("model name", processorDataMap.get("Name"));
// processorDataMap.put("cpu MHz", processorDataMap.get("MaxClockSpeed"));
// processorDataMap.put("vendor_id", processorDataMap.get("Manufacturer"));
// processorDataMap.put("cpu cores", processorDataMap.get("NumberOfCores"));
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsMemoryInfo.java
// public class WindowsMemoryInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> memoryDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PERFFORMATTEDDATA_PERFOS_MEMORY);
// memoryDataMap.putAll(WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PHYSICALMEMORY));
// memoryDataMap.put("MemAvailable", memoryDataMap.get("AvailableKBytes"));
// memoryDataMap.put("MemFree", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
// memoryDataMap.put("MemTotal", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("TotalPhysicalMemory"));
// return memoryDataMap;
// }
// }
| import cn.jiongjionger.neverlag.hardware.UnixCPUInfo;
import cn.jiongjionger.neverlag.hardware.UnixMemoryInfo;
import cn.jiongjionger.neverlag.hardware.WindowsCPUInfo;
import cn.jiongjionger.neverlag.hardware.WindowsMemoryInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap;
import java.util.Map; | }
return String.format("%s %s cores %s stepping",
cpuInfoMap.get("model name"),
cpuInfoMap.get("cpu cores"),
cpuInfoMap.get("stepping"));
}
} catch (Exception e) {
return null;
}
}
// 获取JVM参数
public static String getJVMArg() {
StringBuilder sb = new StringBuilder();
for (String arg : runtimeMXBean.getInputArguments()) {
sb.append(arg).append(" ");
}
return sb.toString();
}
// 获取JVM名称和版本号
public static String getJVMInfo() {
return runtimeMXBean.getVmName() + " (" + runtimeMXBean.getVmVersion() + ")";
}
// 获取物理内存使用情况(使用量 / 总量)类似 109621MB / 262144MB
public static String getMemoryInfo() {
try {
Map<String, String> memoryInfoMap = new HashMap<>();
if (isWindows()) { | // Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixCPUInfo.java
// public class UnixCPUInfo {
//
// public String getProcessorData() {
// List<String> streamProcessorInfo = HardwareInfoUtils.readFile("/proc/cpuinfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamProcessorInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public Map<String, String> parseInfo() {
// HashMap<String, String> processorDataMap = new HashMap<>();
// String[] dataStringLines = getProcessorData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// processorDataMap.put(dataStringInfo[0].trim(),
// (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixMemoryInfo.java
// public class UnixMemoryInfo {
//
// private String getMemoryData() {
// List<String> streamMemoryInfo = HardwareInfoUtils.readFile("/proc/meminfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamMemoryInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public HashMap<String, String> parseInfo() {
// HashMap<String, String> memoryDataMap = new HashMap<>();
// String[] dataStringLines = getMemoryData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// memoryDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return memoryDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsCPUInfo.java
// public class WindowsCPUInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> processorDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PROCESSOR);
// String lineInfos = processorDataMap.get("Description");
// String[] infos = lineInfos.split("\\s+");
// processorDataMap.put("cpu family", infos[2]);
// processorDataMap.put("model", infos[4]);
// processorDataMap.put("stepping", infos[6]);
// processorDataMap.put("model name", processorDataMap.get("Name"));
// processorDataMap.put("cpu MHz", processorDataMap.get("MaxClockSpeed"));
// processorDataMap.put("vendor_id", processorDataMap.get("Manufacturer"));
// processorDataMap.put("cpu cores", processorDataMap.get("NumberOfCores"));
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsMemoryInfo.java
// public class WindowsMemoryInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> memoryDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PERFFORMATTEDDATA_PERFOS_MEMORY);
// memoryDataMap.putAll(WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PHYSICALMEMORY));
// memoryDataMap.put("MemAvailable", memoryDataMap.get("AvailableKBytes"));
// memoryDataMap.put("MemFree", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
// memoryDataMap.put("MemTotal", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("TotalPhysicalMemory"));
// return memoryDataMap;
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/utils/HardwareInfo.java
import cn.jiongjionger.neverlag.hardware.UnixCPUInfo;
import cn.jiongjionger.neverlag.hardware.UnixMemoryInfo;
import cn.jiongjionger.neverlag.hardware.WindowsCPUInfo;
import cn.jiongjionger.neverlag.hardware.WindowsMemoryInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap;
import java.util.Map;
}
return String.format("%s %s cores %s stepping",
cpuInfoMap.get("model name"),
cpuInfoMap.get("cpu cores"),
cpuInfoMap.get("stepping"));
}
} catch (Exception e) {
return null;
}
}
// 获取JVM参数
public static String getJVMArg() {
StringBuilder sb = new StringBuilder();
for (String arg : runtimeMXBean.getInputArguments()) {
sb.append(arg).append(" ");
}
return sb.toString();
}
// 获取JVM名称和版本号
public static String getJVMInfo() {
return runtimeMXBean.getVmName() + " (" + runtimeMXBean.getVmVersion() + ")";
}
// 获取物理内存使用情况(使用量 / 总量)类似 109621MB / 262144MB
public static String getMemoryInfo() {
try {
Map<String, String> memoryInfoMap = new HashMap<>();
if (isWindows()) { | WindowsMemoryInfo memoryInfo = new WindowsMemoryInfo(); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/utils/HardwareInfo.java | // Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixCPUInfo.java
// public class UnixCPUInfo {
//
// public String getProcessorData() {
// List<String> streamProcessorInfo = HardwareInfoUtils.readFile("/proc/cpuinfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamProcessorInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public Map<String, String> parseInfo() {
// HashMap<String, String> processorDataMap = new HashMap<>();
// String[] dataStringLines = getProcessorData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// processorDataMap.put(dataStringInfo[0].trim(),
// (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixMemoryInfo.java
// public class UnixMemoryInfo {
//
// private String getMemoryData() {
// List<String> streamMemoryInfo = HardwareInfoUtils.readFile("/proc/meminfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamMemoryInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public HashMap<String, String> parseInfo() {
// HashMap<String, String> memoryDataMap = new HashMap<>();
// String[] dataStringLines = getMemoryData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// memoryDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return memoryDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsCPUInfo.java
// public class WindowsCPUInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> processorDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PROCESSOR);
// String lineInfos = processorDataMap.get("Description");
// String[] infos = lineInfos.split("\\s+");
// processorDataMap.put("cpu family", infos[2]);
// processorDataMap.put("model", infos[4]);
// processorDataMap.put("stepping", infos[6]);
// processorDataMap.put("model name", processorDataMap.get("Name"));
// processorDataMap.put("cpu MHz", processorDataMap.get("MaxClockSpeed"));
// processorDataMap.put("vendor_id", processorDataMap.get("Manufacturer"));
// processorDataMap.put("cpu cores", processorDataMap.get("NumberOfCores"));
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsMemoryInfo.java
// public class WindowsMemoryInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> memoryDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PERFFORMATTEDDATA_PERFOS_MEMORY);
// memoryDataMap.putAll(WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PHYSICALMEMORY));
// memoryDataMap.put("MemAvailable", memoryDataMap.get("AvailableKBytes"));
// memoryDataMap.put("MemFree", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
// memoryDataMap.put("MemTotal", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("TotalPhysicalMemory"));
// return memoryDataMap;
// }
// }
| import cn.jiongjionger.neverlag.hardware.UnixCPUInfo;
import cn.jiongjionger.neverlag.hardware.UnixMemoryInfo;
import cn.jiongjionger.neverlag.hardware.WindowsCPUInfo;
import cn.jiongjionger.neverlag.hardware.WindowsMemoryInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap;
import java.util.Map; | cpuInfoMap.get("cpu cores"),
cpuInfoMap.get("stepping"));
}
} catch (Exception e) {
return null;
}
}
// 获取JVM参数
public static String getJVMArg() {
StringBuilder sb = new StringBuilder();
for (String arg : runtimeMXBean.getInputArguments()) {
sb.append(arg).append(" ");
}
return sb.toString();
}
// 获取JVM名称和版本号
public static String getJVMInfo() {
return runtimeMXBean.getVmName() + " (" + runtimeMXBean.getVmVersion() + ")";
}
// 获取物理内存使用情况(使用量 / 总量)类似 109621MB / 262144MB
public static String getMemoryInfo() {
try {
Map<String, String> memoryInfoMap = new HashMap<>();
if (isWindows()) {
WindowsMemoryInfo memoryInfo = new WindowsMemoryInfo();
memoryInfoMap = memoryInfo.parseInfo();
} else if (isUnix()) { | // Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixCPUInfo.java
// public class UnixCPUInfo {
//
// public String getProcessorData() {
// List<String> streamProcessorInfo = HardwareInfoUtils.readFile("/proc/cpuinfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamProcessorInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public Map<String, String> parseInfo() {
// HashMap<String, String> processorDataMap = new HashMap<>();
// String[] dataStringLines = getProcessorData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// processorDataMap.put(dataStringInfo[0].trim(),
// (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/UnixMemoryInfo.java
// public class UnixMemoryInfo {
//
// private String getMemoryData() {
// List<String> streamMemoryInfo = HardwareInfoUtils.readFile("/proc/meminfo");
// final StringBuilder buffer = new StringBuilder();
// for (String line : streamMemoryInfo) {
// buffer.append(line).append("\r\n");
// }
// return buffer.toString();
// }
//
// public HashMap<String, String> parseInfo() {
// HashMap<String, String> memoryDataMap = new HashMap<>();
// String[] dataStringLines = getMemoryData().split("\\r?\\n");
// for (final String dataLine : dataStringLines) {
// String[] dataStringInfo = dataLine.split(":");
// memoryDataMap.put(dataStringInfo[0].trim(), (dataStringInfo.length == 2) ? dataStringInfo[1].trim() : "");
// }
// return memoryDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsCPUInfo.java
// public class WindowsCPUInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> processorDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PROCESSOR);
// String lineInfos = processorDataMap.get("Description");
// String[] infos = lineInfos.split("\\s+");
// processorDataMap.put("cpu family", infos[2]);
// processorDataMap.put("model", infos[4]);
// processorDataMap.put("stepping", infos[6]);
// processorDataMap.put("model name", processorDataMap.get("Name"));
// processorDataMap.put("cpu MHz", processorDataMap.get("MaxClockSpeed"));
// processorDataMap.put("vendor_id", processorDataMap.get("Manufacturer"));
// processorDataMap.put("cpu cores", processorDataMap.get("NumberOfCores"));
// return processorDataMap;
// }
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/hardware/WindowsMemoryInfo.java
// public class WindowsMemoryInfo {
//
// public Map<String, String> parseInfo() {
// Map<String, String> memoryDataMap = WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PERFFORMATTEDDATA_PERFOS_MEMORY);
// memoryDataMap.putAll(WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_PHYSICALMEMORY));
// memoryDataMap.put("MemAvailable", memoryDataMap.get("AvailableKBytes"));
// memoryDataMap.put("MemFree", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("FreePhysicalMemory"));
// memoryDataMap.put("MemTotal", WMI4Java.get().VBSEngine().getWMIObject(WMIClass.WIN32_OPERATINGSYSTEM).get("TotalPhysicalMemory"));
// return memoryDataMap;
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/utils/HardwareInfo.java
import cn.jiongjionger.neverlag.hardware.UnixCPUInfo;
import cn.jiongjionger.neverlag.hardware.UnixMemoryInfo;
import cn.jiongjionger.neverlag.hardware.WindowsCPUInfo;
import cn.jiongjionger.neverlag.hardware.WindowsMemoryInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap;
import java.util.Map;
cpuInfoMap.get("cpu cores"),
cpuInfoMap.get("stepping"));
}
} catch (Exception e) {
return null;
}
}
// 获取JVM参数
public static String getJVMArg() {
StringBuilder sb = new StringBuilder();
for (String arg : runtimeMXBean.getInputArguments()) {
sb.append(arg).append(" ");
}
return sb.toString();
}
// 获取JVM名称和版本号
public static String getJVMInfo() {
return runtimeMXBean.getVmName() + " (" + runtimeMXBean.getVmVersion() + ")";
}
// 获取物理内存使用情况(使用量 / 总量)类似 109621MB / 262144MB
public static String getMemoryInfo() {
try {
Map<String, String> memoryInfoMap = new HashMap<>();
if (isWindows()) {
WindowsMemoryInfo memoryInfo = new WindowsMemoryInfo();
memoryInfoMap = memoryInfo.parseInfo();
} else if (isUnix()) { | UnixMemoryInfo memoryInfo = new UnixMemoryInfo(); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_12_R1/PandaRedstoneWire.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_12_R1.BaseBlockPosition;
import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_12_R1.BlockPiston;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_12_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_12_R1.BlockRedstoneWire;
import net.minecraft.server.v1_12_R1.EnumDirection;
import net.minecraft.server.v1_12_R1.IBlockAccess;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.SoundEffectType;
import net.minecraft.server.v1_12_R1.World; | package cn.jiongjionger.neverlag.module.pandawire.v1_12_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_12_R1/PandaRedstoneWire.java
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_12_R1.BaseBlockPosition;
import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_12_R1.BlockPiston;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_12_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_12_R1.BlockRedstoneWire;
import net.minecraft.server.v1_12_R1.EnumDirection;
import net.minecraft.server.v1_12_R1.IBlockAccess;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.SoundEffectType;
import net.minecraft.server.v1_12_R1.World;
package cn.jiongjionger.neverlag.module.pandawire.v1_12_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | set.add(PandaWireReflectUtil.getOfT(facing, BaseBlockPosition.class)); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R3/PandaRedstoneWire.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R3.BaseBlockPosition;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockDiodeAbstract;
import net.minecraft.server.v1_8_R3.BlockDirectional;
import net.minecraft.server.v1_8_R3.BlockPiston;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.BlockRedstoneComparator;
import net.minecraft.server.v1_8_R3.BlockRedstoneTorch;
import net.minecraft.server.v1_8_R3.BlockRedstoneWire;
import net.minecraft.server.v1_8_R3.BlockTorch;
import net.minecraft.server.v1_8_R3.EnumDirection;
import net.minecraft.server.v1_8_R3.IBlockAccess;
import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.World; | package cn.jiongjionger.neverlag.module.pandawire.v1_8_R3;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
// facing方向的枚举
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
// facing垂直的枚举
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
// 上述两者之和
private static final EnumDirection[] facings = ArrayUtils.addAll(facingsVertical, facingsHorizontal);
// facing的X、Y、Z的偏移量位置数组
private static final BaseBlockPosition[] surroundingBlocksOffset;
// 初始化surroundingBlocksOffset
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R3/PandaRedstoneWire.java
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R3.BaseBlockPosition;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockDiodeAbstract;
import net.minecraft.server.v1_8_R3.BlockDirectional;
import net.minecraft.server.v1_8_R3.BlockPiston;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.BlockRedstoneComparator;
import net.minecraft.server.v1_8_R3.BlockRedstoneTorch;
import net.minecraft.server.v1_8_R3.BlockRedstoneWire;
import net.minecraft.server.v1_8_R3.BlockTorch;
import net.minecraft.server.v1_8_R3.EnumDirection;
import net.minecraft.server.v1_8_R3.IBlockAccess;
import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.World;
package cn.jiongjionger.neverlag.module.pandawire.v1_8_R3;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
// facing方向的枚举
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
// facing垂直的枚举
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
// 上述两者之和
private static final EnumDirection[] facings = ArrayUtils.addAll(facingsVertical, facingsHorizontal);
// facing的X、Y、Z的偏移量位置数组
private static final BaseBlockPosition[] surroundingBlocksOffset;
// 初始化surroundingBlocksOffset
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | set.add(PandaWireReflectUtil.getOfT(facing, BaseBlockPosition.class)); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_11_R1/PandaRedstoneWire.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_11_R1.BaseBlockPosition;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_11_R1.BlockPiston;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_11_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_11_R1.BlockRedstoneWire;
import net.minecraft.server.v1_11_R1.EnumDirection;
import net.minecraft.server.v1_11_R1.IBlockAccess;
import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.SoundEffectType;
import net.minecraft.server.v1_11_R1.World; | package cn.jiongjionger.neverlag.module.pandawire.v1_11_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_11_R1/PandaRedstoneWire.java
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_11_R1.BaseBlockPosition;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_11_R1.BlockPiston;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_11_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_11_R1.BlockRedstoneWire;
import net.minecraft.server.v1_11_R1.EnumDirection;
import net.minecraft.server.v1_11_R1.IBlockAccess;
import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.SoundEffectType;
import net.minecraft.server.v1_11_R1.World;
package cn.jiongjionger.neverlag.module.pandawire.v1_11_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | set.add(PandaWireReflectUtil.getOfT(facing, BaseBlockPosition.class)); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R3/PandaWireInjector.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import org.bukkit.Bukkit;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockRedstoneWire;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.MinecraftKey; | package cn.jiongjionger.neverlag.module.pandawire.v1_8_R3;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/IPandaWireInjector.java
// public interface IPandaWireInjector {
//
// public static void inject() {
// }
//
// public static void uninject() {
// }
//
// }
//
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R3/PandaWireInjector.java
import org.bukkit.Bukkit;
import cn.jiongjionger.neverlag.module.pandawire.IPandaWireInjector;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockRedstoneWire;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.MinecraftKey;
package cn.jiongjionger.neverlag.module.pandawire.v1_8_R3;
public class PandaWireInjector implements IPandaWireInjector{
private static Block get(final String s) {
return Block.REGISTRY.get(new MinecraftKey(s));
}
public static void inject() {
try {
register(55, "redstone_wire", new PandaRedstoneWire()); | PandaWireReflectUtil.setStatic("REDSTONE_WIRE", Blocks.class, get("redstone_wire")); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_9_R1/PandaRedstoneWire.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_9_R1.BaseBlockPosition;
import net.minecraft.server.v1_9_R1.Block;
import net.minecraft.server.v1_9_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_9_R1.BlockPiston;
import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_9_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_9_R1.BlockRedstoneWire;
import net.minecraft.server.v1_9_R1.EnumDirection;
import net.minecraft.server.v1_9_R1.IBlockAccess;
import net.minecraft.server.v1_9_R1.IBlockData;
import net.minecraft.server.v1_9_R1.SoundEffectType;
import net.minecraft.server.v1_9_R1.World; | package cn.jiongjionger.neverlag.module.pandawire.v1_9_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_9_R1/PandaRedstoneWire.java
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_9_R1.BaseBlockPosition;
import net.minecraft.server.v1_9_R1.Block;
import net.minecraft.server.v1_9_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_9_R1.BlockPiston;
import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_9_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_9_R1.BlockRedstoneWire;
import net.minecraft.server.v1_9_R1.EnumDirection;
import net.minecraft.server.v1_9_R1.IBlockAccess;
import net.minecraft.server.v1_9_R1.IBlockData;
import net.minecraft.server.v1_9_R1.SoundEffectType;
import net.minecraft.server.v1_9_R1.World;
package cn.jiongjionger.neverlag.module.pandawire.v1_9_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
/*
* 作者说用LinkedHashSet替代arraylist没有明显的性能提示,红石设备不多的时候的确如此
* 但是实测在红石设备数量很大的时候,有2~5%的性能提升(基于PaperSpigot1.10.2测试),所以还是改用LinkedHashSet来实现
*/
// 需要被断路的红石位置
private Set<BlockPosition> turnOff = Sets.newLinkedHashSet();
// 需要被激活的红石位置
private Set<BlockPosition> turnOn = Sets.newLinkedHashSet();
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
private static final EnumDirection[] facings = (EnumDirection[]) ArrayUtils.addAll(facingsVertical, facingsHorizontal);
private static final BaseBlockPosition[] surroundingBlocksOffset;
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | set.add(PandaWireReflectUtil.getOfT(facing, BaseBlockPosition.class)); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R1/PandaRedstoneWire.java | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
| import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R1.BaseBlockPosition;
import net.minecraft.server.v1_8_R1.Block;
import net.minecraft.server.v1_8_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_8_R1.BlockDirectional;
import net.minecraft.server.v1_8_R1.BlockPiston;
import net.minecraft.server.v1_8_R1.BlockPosition;
import net.minecraft.server.v1_8_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_8_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_8_R1.BlockRedstoneWire;
import net.minecraft.server.v1_8_R1.BlockTorch;
import net.minecraft.server.v1_8_R1.EnumDirection;
import net.minecraft.server.v1_8_R1.EnumDirectionLimit;
import net.minecraft.server.v1_8_R1.IBlockAccess;
import net.minecraft.server.v1_8_R1.IBlockData;
import net.minecraft.server.v1_8_R1.World; | package cn.jiongjionger.neverlag.module.pandawire.v1_8_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
// facing方向的枚举
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
// facing垂直的枚举
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
// 上述两者之和
private static final EnumDirection[] facings = ArrayUtils.addAll(facingsVertical, facingsHorizontal);
// facing的X、Y、Z的偏移量位置数组
private static final BaseBlockPosition[] surroundingBlocksOffset;
// 初始化surroundingBlocksOffset
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | // Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/PandaWireReflectUtil.java
// public class PandaWireReflectUtil {
//
// /*
// * @author md_5
// */
//
// public static <T> T get(final Object obj, final Field field, final Class<T> type) {
// try {
// return type.cast(setAccessible(field).get(obj));
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// return null;
// }
// }
//
// public static <T> T getOfT(final Object obj, final Class<T> type) {
// for (final Field field : obj.getClass().getDeclaredFields()) {
// if (type.equals(field.getType())) {
// return get(obj, field, type);
// }
// }
// return null;
// }
//
// public static <T extends AccessibleObject> T setAccessible(T object) {
// object.setAccessible(true);
// return object;
// }
//
// public static void setStatic(final String name, final Class<?> clazz, final Object val) {
// try {
// final Field field = clazz.getDeclaredField(name);
// setAccessible(Field.class.getDeclaredField("modifiers")).setInt(field, field.getModifiers() & ~Modifier.FINAL);
// setAccessible(Field.class.getDeclaredField("root")).set(field, null);
// setAccessible(Field.class.getDeclaredField("overrideFieldAccessor")).set(field, null);
// setAccessible(field).set(null, val);
// } catch (ReflectiveOperationException ex) {
// ex.printStackTrace();
// }
// }
// }
// Path: src/main/java/cn/jiongjionger/neverlag/module/pandawire/v1_8_R1/PandaRedstoneWire.java
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cn.jiongjionger.neverlag.module.pandawire.PandaWireReflectUtil;
import net.minecraft.server.v1_8_R1.BaseBlockPosition;
import net.minecraft.server.v1_8_R1.Block;
import net.minecraft.server.v1_8_R1.BlockDiodeAbstract;
import net.minecraft.server.v1_8_R1.BlockDirectional;
import net.minecraft.server.v1_8_R1.BlockPiston;
import net.minecraft.server.v1_8_R1.BlockPosition;
import net.minecraft.server.v1_8_R1.BlockRedstoneComparator;
import net.minecraft.server.v1_8_R1.BlockRedstoneTorch;
import net.minecraft.server.v1_8_R1.BlockRedstoneWire;
import net.minecraft.server.v1_8_R1.BlockTorch;
import net.minecraft.server.v1_8_R1.EnumDirection;
import net.minecraft.server.v1_8_R1.EnumDirectionLimit;
import net.minecraft.server.v1_8_R1.IBlockAccess;
import net.minecraft.server.v1_8_R1.IBlockData;
import net.minecraft.server.v1_8_R1.World;
package cn.jiongjionger.neverlag.module.pandawire.v1_8_R1;
/*
* @author Panda4994
*/
public class PandaRedstoneWire extends BlockRedstoneWire {
// facing方向的枚举
private static final EnumDirection[] facingsHorizontal = { EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH };
// facing垂直的枚举
private static final EnumDirection[] facingsVertical = { EnumDirection.DOWN, EnumDirection.UP };
// 上述两者之和
private static final EnumDirection[] facings = ArrayUtils.addAll(facingsVertical, facingsHorizontal);
// facing的X、Y、Z的偏移量位置数组
private static final BaseBlockPosition[] surroundingBlocksOffset;
// 初始化surroundingBlocksOffset
static {
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
for (EnumDirection facing : facings) { | set.add(PandaWireReflectUtil.getOfT(facing, BaseBlockPosition.class)); |
jiongjionger/NeverLag | src/main/java/cn/jiongjionger/neverlag/command/CommandClear.java | // Path: src/main/java/cn/jiongjionger/neverlag/utils/NeverLagUtils.java
// public final class NeverLagUtils {
// public static int getMaxPermission(Player p, String node) {
// int maxLimit = 0;
// for (PermissionAttachmentInfo perm : p.getEffectivePermissions()) {
// String permission = perm.getPermission();
// if (!permission.toLowerCase().startsWith(node.toLowerCase())) {
// continue;
// }
// String[] split = permission.split("\\.");
// try {
// int number = Integer.parseInt(split[split.length - 1]);
// if (number > maxLimit) {
// maxLimit = number;
// }
// } catch (NumberFormatException ignore) { }
// }
// return maxLimit;
// }
//
// public static LinkedHashMap<String, Integer> sortMapByValues(HashMap<String, Integer> map) {
// if (map.isEmpty()) {
// return null;
// }
// Set<Map.Entry<String, Integer>> entries = map.entrySet();
// List<Map.Entry<String, Integer>> list = new LinkedList<>(entries);
// Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
// @Override
// public int compare(Map.Entry<String, Integer> entry1, Map.Entry<String, Integer> entry2) {
// return entry1.getValue().compareTo(entry2.getValue());
// }
// });
// LinkedHashMap<String, Integer> sortMap = new LinkedHashMap<>();
// for (Map.Entry<String, Integer> entry : list) {
// sortMap.put(entry.getKey(), entry.getValue());
// }
// return sortMap;
// }
//
// public static boolean checkCustomNpc(Entity entity) {
// return entity == null || entity.hasMetadata("NPC") || entity.hasMetadata("MyPet");
// }
//
// /*
// * 判断掉落物附近有没有玩家
// *
// * @param item 掉落物
// * @param distance 判断距离
// * @return 是否存在玩家
// */
// public static boolean hasPlayerNearby(Entity entity, int distance) {
// for (Entity e : entity.getNearbyEntities(distance, distance, distance)) {
// if (e instanceof Player && !checkCustomNpc(e)) {
// return true;
// }
// }
// return false;
// }
//
// public static Locale toLocale(String str) {
// String language;
// String country = "";
//
// int idx = str.indexOf('_');
// if (idx == -1) {
// idx = str.indexOf('-');
// }
// if (idx == -1) {
// language = str;
// } else {
// language = str.substring(0, idx);
// country = str.substring(idx + 1, str.length());
// }
//
// return new Locale(language, country);
// }
//
// public static void broadcastIfOnline(String message) {
// if (!Bukkit.getOnlinePlayers().isEmpty())
// Bukkit.broadcastMessage(message);
// }
//
// private NeverLagUtils() {}
// }
| import cn.jiongjionger.neverlag.utils.NeverLagUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; | package cn.jiongjionger.neverlag.command;
public class CommandClear extends AbstractSubCommand {
private static final List<String> COMPLETION_LIST;
static {
List<String> list = new ArrayList<>(Arrays.asList("monsters", "monster", "animals", "animal", "dropitems", "dropitem", "items", "item"));
for (EntityType type : EntityType.values()) {
if (type != EntityType.PLAYER) {
@SuppressWarnings("deprecation")
String name = type.getName();
if (name != null) {
list.add(name.toLowerCase());
}
}
}
COMPLETION_LIST = Collections.unmodifiableList(new ArrayList<>(list));
}
public CommandClear() {
super("clear", 1);
}
@SuppressWarnings("deprecation")
@Override
public void onCommand(CommandSender sender, String[] args) {
String type = args[0].toLowerCase();
if (!COMPLETION_LIST.contains(type)) {
sender.sendMessage(i18n.tr("illegalType", COMPLETION_LIST));
return;
}
int count = 0;
for (World w : Bukkit.getWorlds()) {
for (Entity entity : w.getEntities()) { | // Path: src/main/java/cn/jiongjionger/neverlag/utils/NeverLagUtils.java
// public final class NeverLagUtils {
// public static int getMaxPermission(Player p, String node) {
// int maxLimit = 0;
// for (PermissionAttachmentInfo perm : p.getEffectivePermissions()) {
// String permission = perm.getPermission();
// if (!permission.toLowerCase().startsWith(node.toLowerCase())) {
// continue;
// }
// String[] split = permission.split("\\.");
// try {
// int number = Integer.parseInt(split[split.length - 1]);
// if (number > maxLimit) {
// maxLimit = number;
// }
// } catch (NumberFormatException ignore) { }
// }
// return maxLimit;
// }
//
// public static LinkedHashMap<String, Integer> sortMapByValues(HashMap<String, Integer> map) {
// if (map.isEmpty()) {
// return null;
// }
// Set<Map.Entry<String, Integer>> entries = map.entrySet();
// List<Map.Entry<String, Integer>> list = new LinkedList<>(entries);
// Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
// @Override
// public int compare(Map.Entry<String, Integer> entry1, Map.Entry<String, Integer> entry2) {
// return entry1.getValue().compareTo(entry2.getValue());
// }
// });
// LinkedHashMap<String, Integer> sortMap = new LinkedHashMap<>();
// for (Map.Entry<String, Integer> entry : list) {
// sortMap.put(entry.getKey(), entry.getValue());
// }
// return sortMap;
// }
//
// public static boolean checkCustomNpc(Entity entity) {
// return entity == null || entity.hasMetadata("NPC") || entity.hasMetadata("MyPet");
// }
//
// /*
// * 判断掉落物附近有没有玩家
// *
// * @param item 掉落物
// * @param distance 判断距离
// * @return 是否存在玩家
// */
// public static boolean hasPlayerNearby(Entity entity, int distance) {
// for (Entity e : entity.getNearbyEntities(distance, distance, distance)) {
// if (e instanceof Player && !checkCustomNpc(e)) {
// return true;
// }
// }
// return false;
// }
//
// public static Locale toLocale(String str) {
// String language;
// String country = "";
//
// int idx = str.indexOf('_');
// if (idx == -1) {
// idx = str.indexOf('-');
// }
// if (idx == -1) {
// language = str;
// } else {
// language = str.substring(0, idx);
// country = str.substring(idx + 1, str.length());
// }
//
// return new Locale(language, country);
// }
//
// public static void broadcastIfOnline(String message) {
// if (!Bukkit.getOnlinePlayers().isEmpty())
// Bukkit.broadcastMessage(message);
// }
//
// private NeverLagUtils() {}
// }
// Path: src/main/java/cn/jiongjionger/neverlag/command/CommandClear.java
import cn.jiongjionger.neverlag.utils.NeverLagUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
package cn.jiongjionger.neverlag.command;
public class CommandClear extends AbstractSubCommand {
private static final List<String> COMPLETION_LIST;
static {
List<String> list = new ArrayList<>(Arrays.asList("monsters", "monster", "animals", "animal", "dropitems", "dropitem", "items", "item"));
for (EntityType type : EntityType.values()) {
if (type != EntityType.PLAYER) {
@SuppressWarnings("deprecation")
String name = type.getName();
if (name != null) {
list.add(name.toLowerCase());
}
}
}
COMPLETION_LIST = Collections.unmodifiableList(new ArrayList<>(list));
}
public CommandClear() {
super("clear", 1);
}
@SuppressWarnings("deprecation")
@Override
public void onCommand(CommandSender sender, String[] args) {
String type = args[0].toLowerCase();
if (!COMPLETION_LIST.contains(type)) {
sender.sendMessage(i18n.tr("illegalType", COMPLETION_LIST));
return;
}
int count = 0;
for (World w : Bukkit.getWorlds()) {
for (Entity entity : w.getEntities()) { | if (entity instanceof Player || NeverLagUtils.checkCustomNpc(entity)) { |
dbdkmezz/true-sight-dota | app/src/main/java/com/carver/paul/truesight/Ui/AbilityInfo/AbilityInfoCard/TalentsCardView.java | // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
| import android.animation.LayoutTransition;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.carver.paul.truesight.Models.HeroAbilityInfo;
import com.carver.paul.truesight.R;
import java.util.List; | package com.carver.paul.truesight.Ui.AbilityInfo.AbilityInfoCard;
/**
* Created by paul on 30/12/16.
*/
public class TalentsCardView extends FrameLayout {
private TalentsCardPresenter mPresenter;
private Context mContext;
private final int TOTAL_TALENTS_PER_HERO = 4;
| // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
// Path: app/src/main/java/com/carver/paul/truesight/Ui/AbilityInfo/AbilityInfoCard/TalentsCardView.java
import android.animation.LayoutTransition;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.carver.paul.truesight.Models.HeroAbilityInfo;
import com.carver.paul.truesight.R;
import java.util.List;
package com.carver.paul.truesight.Ui.AbilityInfo.AbilityInfoCard;
/**
* Created by paul on 30/12/16.
*/
public class TalentsCardView extends FrameLayout {
private TalentsCardPresenter mPresenter;
private Context mContext;
private final int TOTAL_TALENTS_PER_HERO = 4;
| public TalentsCardView(Context context, List<HeroAbilityInfo.Talent> talents) { |
dbdkmezz/true-sight-dota | app/src/main/java/com/carver/paul/truesight/Ui/AbilityInfo/AbilityInfoCard/AbilityCardView.java | // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
| import android.animation.LayoutTransition;
import android.content.Context;
import android.text.Html;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.carver.paul.truesight.Models.HeroAbilityInfo;
import com.carver.paul.truesight.R;
import java.util.List; | /**
* True Sight for Dota 2
* Copyright (C) 2015 Paul Broadbent
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.Ui.AbilityInfo.AbilityInfoCard;
/**
* AbilityCardView is a card in which the information about an ability is shown.
*
* When pressed the card will toggle between an expanded and non-expanded view, show that the full
* info on tbe ability can be seen when pressed. By default just the three-line non-expanded version
* will be shown.
*/
public class AbilityCardView extends FrameLayout {
private AbilityCardPresenter mPresenter;
/**
*
* @param context
* @param ability
* @param showHeroName
* @param abilityType The type of ability which this card is being used to demonstrate.
*/ | // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
// Path: app/src/main/java/com/carver/paul/truesight/Ui/AbilityInfo/AbilityInfoCard/AbilityCardView.java
import android.animation.LayoutTransition;
import android.content.Context;
import android.text.Html;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.carver.paul.truesight.Models.HeroAbilityInfo;
import com.carver.paul.truesight.R;
import java.util.List;
/**
* True Sight for Dota 2
* Copyright (C) 2015 Paul Broadbent
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.Ui.AbilityInfo.AbilityInfoCard;
/**
* AbilityCardView is a card in which the information about an ability is shown.
*
* When pressed the card will toggle between an expanded and non-expanded view, show that the full
* info on tbe ability can be seen when pressed. By default just the three-line non-expanded version
* will be shown.
*/
public class AbilityCardView extends FrameLayout {
private AbilityCardPresenter mPresenter;
/**
*
* @param context
* @param ability
* @param showHeroName
* @param abilityType The type of ability which this card is being used to demonstrate.
*/ | public AbilityCardView(Context context, HeroAbilityInfo ability, boolean showHeroName, |
dbdkmezz/true-sight-dota | app/src/main/java/com/carver/paul/truesight/ImageRecognition/LoadHeroXml.java | // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
//
// Path: app/src/main/java/com/carver/paul/truesight/Models/HeroInfo.java
// public class HeroInfo {
// public String name;
// public String imageName;
// public String bioRoles;
// public String intelligence;
// public String agility;
// public String strength;
// public String attack;
// public String speed;
// public String defence;
// public List<HeroAbilityInfo> abilities;
// public List<HeroAbilityInfo.Talent> talents;
//
// public HeroInfo() {
// abilities = new ArrayList<>();
// talents = new ArrayList<>();
// }
//
// public boolean hasName(String string) {
// return (string.equals(imageName) || string.equalsIgnoreCase(name));
// }
// }
| import android.content.res.XmlResourceParser;
import android.util.Log;
import com.carver.paul.truesight.BuildConfig;
import com.carver.paul.truesight.Models.HeroAbilityInfo;
import com.carver.paul.truesight.Models.HeroInfo;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.List; | /**
* True Sight for Dota 2
* Copyright (C) 2015 Paul Broadbent
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.ImageRecognition;
//TODO-someday: Consider switching to sqlite database for hero info instead of an XML file
public class LoadHeroXml {
static final String sNullString = null;
private static final String TAG = "LoadHeroXml";
private LoadHeroXml() {}
| // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
//
// Path: app/src/main/java/com/carver/paul/truesight/Models/HeroInfo.java
// public class HeroInfo {
// public String name;
// public String imageName;
// public String bioRoles;
// public String intelligence;
// public String agility;
// public String strength;
// public String attack;
// public String speed;
// public String defence;
// public List<HeroAbilityInfo> abilities;
// public List<HeroAbilityInfo.Talent> talents;
//
// public HeroInfo() {
// abilities = new ArrayList<>();
// talents = new ArrayList<>();
// }
//
// public boolean hasName(String string) {
// return (string.equals(imageName) || string.equalsIgnoreCase(name));
// }
// }
// Path: app/src/main/java/com/carver/paul/truesight/ImageRecognition/LoadHeroXml.java
import android.content.res.XmlResourceParser;
import android.util.Log;
import com.carver.paul.truesight.BuildConfig;
import com.carver.paul.truesight.Models.HeroAbilityInfo;
import com.carver.paul.truesight.Models.HeroInfo;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.List;
/**
* True Sight for Dota 2
* Copyright (C) 2015 Paul Broadbent
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.ImageRecognition;
//TODO-someday: Consider switching to sqlite database for hero info instead of an XML file
public class LoadHeroXml {
static final String sNullString = null;
private static final String TAG = "LoadHeroXml";
private LoadHeroXml() {}
| public static void Load(XmlResourceParser parser, List<HeroInfo> heroInfoList) { |
dbdkmezz/true-sight-dota | app/src/main/java/com/carver/paul/truesight/ImageRecognition/LoadHeroXml.java | // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
//
// Path: app/src/main/java/com/carver/paul/truesight/Models/HeroInfo.java
// public class HeroInfo {
// public String name;
// public String imageName;
// public String bioRoles;
// public String intelligence;
// public String agility;
// public String strength;
// public String attack;
// public String speed;
// public String defence;
// public List<HeroAbilityInfo> abilities;
// public List<HeroAbilityInfo.Talent> talents;
//
// public HeroInfo() {
// abilities = new ArrayList<>();
// talents = new ArrayList<>();
// }
//
// public boolean hasName(String string) {
// return (string.equals(imageName) || string.equalsIgnoreCase(name));
// }
// }
| import android.content.res.XmlResourceParser;
import android.util.Log;
import com.carver.paul.truesight.BuildConfig;
import com.carver.paul.truesight.Models.HeroAbilityInfo;
import com.carver.paul.truesight.Models.HeroInfo;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.List; | parser.require(XmlPullParser.END_TAG, sNullString, "bioRoles");
} else if (parser.getName().equals("intelligence")) {
hero.intelligence = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "intelligence");
} else if (parser.getName().equals("agility")) {
hero.agility = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "agility");
} else if (parser.getName().equals("strength")) {
hero.strength = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "strength");
} else if (parser.getName().equals("attack")) {
hero.attack = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "attack");
} else if (parser.getName().equals("speed")) {
hero.speed = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "speed");
} else if (parser.getName().equals("defence")) {
hero.defence = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "defence");
} else if (parser.getName().equals("abilities")) {
hero.abilities.add(LoadHeroAbilities(parser));
parser.require(XmlPullParser.END_TAG, sNullString, "abilities");
} else if (parser.getName().equals("talents")) {
hero.talents.add(LoadHeroTalent(parser));
parser.require(XmlPullParser.END_TAG, sNullString, "talents");
} else {
throw new RuntimeException("Loading XML Error, in LoadIndividualHeroInfo. Name:" + parser.getName());
}
}
| // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
//
// Path: app/src/main/java/com/carver/paul/truesight/Models/HeroInfo.java
// public class HeroInfo {
// public String name;
// public String imageName;
// public String bioRoles;
// public String intelligence;
// public String agility;
// public String strength;
// public String attack;
// public String speed;
// public String defence;
// public List<HeroAbilityInfo> abilities;
// public List<HeroAbilityInfo.Talent> talents;
//
// public HeroInfo() {
// abilities = new ArrayList<>();
// talents = new ArrayList<>();
// }
//
// public boolean hasName(String string) {
// return (string.equals(imageName) || string.equalsIgnoreCase(name));
// }
// }
// Path: app/src/main/java/com/carver/paul/truesight/ImageRecognition/LoadHeroXml.java
import android.content.res.XmlResourceParser;
import android.util.Log;
import com.carver.paul.truesight.BuildConfig;
import com.carver.paul.truesight.Models.HeroAbilityInfo;
import com.carver.paul.truesight.Models.HeroInfo;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.List;
parser.require(XmlPullParser.END_TAG, sNullString, "bioRoles");
} else if (parser.getName().equals("intelligence")) {
hero.intelligence = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "intelligence");
} else if (parser.getName().equals("agility")) {
hero.agility = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "agility");
} else if (parser.getName().equals("strength")) {
hero.strength = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "strength");
} else if (parser.getName().equals("attack")) {
hero.attack = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "attack");
} else if (parser.getName().equals("speed")) {
hero.speed = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "speed");
} else if (parser.getName().equals("defence")) {
hero.defence = readText(parser);
parser.require(XmlPullParser.END_TAG, sNullString, "defence");
} else if (parser.getName().equals("abilities")) {
hero.abilities.add(LoadHeroAbilities(parser));
parser.require(XmlPullParser.END_TAG, sNullString, "abilities");
} else if (parser.getName().equals("talents")) {
hero.talents.add(LoadHeroTalent(parser));
parser.require(XmlPullParser.END_TAG, sNullString, "talents");
} else {
throw new RuntimeException("Loading XML Error, in LoadIndividualHeroInfo. Name:" + parser.getName());
}
}
| for(HeroAbilityInfo ability : hero.abilities) |
dbdkmezz/true-sight-dota | app/src/main/java/com/carver/paul/truesight/Models/HeroAndAdvantages.java | // Path: app/src/main/java/com/carver/paul/truesight/Models/AdvantagesDownloader/AdvantagesDatum.java
// public class AdvantagesDatum {
//
// @SerializedName("is_carry")
// @Expose
// private Boolean isCarry;
// @SerializedName("id_num")
// @Expose
// private Integer idNum;
// @SerializedName("is_roaming")
// @Expose
// private Boolean isRoaming;
// @SerializedName("name")
// @Expose
// private String name;
// @SerializedName("advantages")
// @Expose
// private List<Double> advantages = new ArrayList<Double>();
// @SerializedName("is_mid")
// @Expose
// private Boolean isMid;
// @SerializedName("is_jungler")
// @Expose
// private Boolean isJungler;
// @SerializedName("is_off_lane")
// @Expose
// private Boolean isOffLane;
// @SerializedName("is_support")
// @Expose
// private Boolean isSupport;
//
// /**
// *
// * @return
// * The isCarry
// */
// public Boolean getIsCarry() {
// return isCarry;
// }
//
// /**
// *
// * @param isCarry
// * The is_carry
// */
// public void setIsCarry(Boolean isCarry) {
// this.isCarry = isCarry;
// }
//
// /**
// *
// * @return
// * The idNum
// */
// public Integer getIdNum() {
// return idNum;
// }
//
// /**
// *
// * @param idNum
// * The id_num
// */
// public void setIdNum(Integer idNum) {
// this.idNum = idNum;
// }
//
// /**
// *
// * @return
// * The isRoaming
// */
// public Boolean getIsRoaming() {
// return isRoaming;
// }
//
// /**
// *
// * @param isRoaming
// * The is_roaming
// */
// public void setIsRoaming(Boolean isRoaming) {
// this.isRoaming = isRoaming;
// }
//
// /**
// *
// * @return
// * The name
// */
// public String getName() {
// return name;
// }
//
// /**
// *
// * @param name
// * The name
// */
// public void setName(String name) {
// this.name = name;
// }
//
// /**
// *
// * @return
// * The advantages
// */
// public List<Double> getAdvantages() {
// return advantages;
// }
//
// /**
// *
// * @param advantages
// * The advantages
// */
// public void setAdvantages(List<Double> advantages) {
// this.advantages = advantages;
// }
//
// /**
// *
// * @return
// * The isMid
// */
// public Boolean getIsMid() {
// return isMid;
// }
//
// /**
// *
// * @param isMid
// * The is_mid
// */
// public void setIsMid(Boolean isMid) {
// this.isMid = isMid;
// }
//
// /**
// *
// * @return
// * The isJungler
// */
// public Boolean getIsJungler() {
// return isJungler;
// }
//
// /**
// *
// * @param isJungler
// * The is_jungler
// */
// public void setIsJungler(Boolean isJungler) {
// this.isJungler = isJungler;
// }
//
// /**
// *
// * @return
// * The isOffLane
// */
// public Boolean getIsOffLane() {
// return isOffLane;
// }
//
// /**
// *
// * @param isOffLane
// * The is_off_lane
// */
// public void setIsOffLane(Boolean isOffLane) {
// this.isOffLane = isOffLane;
// }
//
// /**
// *
// * @return
// * The isSupport
// */
// public Boolean getIsSupport() {
// return isSupport;
// }
//
// /**
// *
// * @param isSupport
// * The is_support
// */
// public void setIsSupport(Boolean isSupport) {
// this.isSupport = isSupport;
// }
//
// }
| import java.util.ArrayList;
import java.util.List;
import android.database.Cursor;
import com.carver.paul.truesight.Models.AdvantagesDownloader.AdvantagesDatum; | /**
* True Sight for Dota 2
* Copyright (C) 2016 Paul Broadbent
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.Models;
public class HeroAndAdvantages implements Comparable<HeroAndAdvantages> {
public static final double NEUTRAL_ADVANTAGE = 999;
private static final String ID_COLUMN = "_id";
private static final String NAME_COLUMN = "name";
private static final String CARRY_COLUMN = "is_carry";
private static final String SUPPORT_COLUMN = "is_support";
private static final String MID_COLUMN = "is_mid";
private static final String ROAMING_COLUMN = "is_roaming";
private static final String JUNGLER_COLUMN = "is_jungler";
private static final String OFF_LANE_COLUMN = "is_off_lane";
private final int mId;
private final String mName;
private final boolean mIsCarry;
private final boolean mIsSupport;
private final boolean mIsMid;
private final boolean mIsRoaming;
private final boolean mIsJungler;
private final boolean mIsOffLane;
// The list of advantages this hero has over those in the photo
private List<Double> mAdvantages;
private double mTotalAdvantage = 0;
| // Path: app/src/main/java/com/carver/paul/truesight/Models/AdvantagesDownloader/AdvantagesDatum.java
// public class AdvantagesDatum {
//
// @SerializedName("is_carry")
// @Expose
// private Boolean isCarry;
// @SerializedName("id_num")
// @Expose
// private Integer idNum;
// @SerializedName("is_roaming")
// @Expose
// private Boolean isRoaming;
// @SerializedName("name")
// @Expose
// private String name;
// @SerializedName("advantages")
// @Expose
// private List<Double> advantages = new ArrayList<Double>();
// @SerializedName("is_mid")
// @Expose
// private Boolean isMid;
// @SerializedName("is_jungler")
// @Expose
// private Boolean isJungler;
// @SerializedName("is_off_lane")
// @Expose
// private Boolean isOffLane;
// @SerializedName("is_support")
// @Expose
// private Boolean isSupport;
//
// /**
// *
// * @return
// * The isCarry
// */
// public Boolean getIsCarry() {
// return isCarry;
// }
//
// /**
// *
// * @param isCarry
// * The is_carry
// */
// public void setIsCarry(Boolean isCarry) {
// this.isCarry = isCarry;
// }
//
// /**
// *
// * @return
// * The idNum
// */
// public Integer getIdNum() {
// return idNum;
// }
//
// /**
// *
// * @param idNum
// * The id_num
// */
// public void setIdNum(Integer idNum) {
// this.idNum = idNum;
// }
//
// /**
// *
// * @return
// * The isRoaming
// */
// public Boolean getIsRoaming() {
// return isRoaming;
// }
//
// /**
// *
// * @param isRoaming
// * The is_roaming
// */
// public void setIsRoaming(Boolean isRoaming) {
// this.isRoaming = isRoaming;
// }
//
// /**
// *
// * @return
// * The name
// */
// public String getName() {
// return name;
// }
//
// /**
// *
// * @param name
// * The name
// */
// public void setName(String name) {
// this.name = name;
// }
//
// /**
// *
// * @return
// * The advantages
// */
// public List<Double> getAdvantages() {
// return advantages;
// }
//
// /**
// *
// * @param advantages
// * The advantages
// */
// public void setAdvantages(List<Double> advantages) {
// this.advantages = advantages;
// }
//
// /**
// *
// * @return
// * The isMid
// */
// public Boolean getIsMid() {
// return isMid;
// }
//
// /**
// *
// * @param isMid
// * The is_mid
// */
// public void setIsMid(Boolean isMid) {
// this.isMid = isMid;
// }
//
// /**
// *
// * @return
// * The isJungler
// */
// public Boolean getIsJungler() {
// return isJungler;
// }
//
// /**
// *
// * @param isJungler
// * The is_jungler
// */
// public void setIsJungler(Boolean isJungler) {
// this.isJungler = isJungler;
// }
//
// /**
// *
// * @return
// * The isOffLane
// */
// public Boolean getIsOffLane() {
// return isOffLane;
// }
//
// /**
// *
// * @param isOffLane
// * The is_off_lane
// */
// public void setIsOffLane(Boolean isOffLane) {
// this.isOffLane = isOffLane;
// }
//
// /**
// *
// * @return
// * The isSupport
// */
// public Boolean getIsSupport() {
// return isSupport;
// }
//
// /**
// *
// * @param isSupport
// * The is_support
// */
// public void setIsSupport(Boolean isSupport) {
// this.isSupport = isSupport;
// }
//
// }
// Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAndAdvantages.java
import java.util.ArrayList;
import java.util.List;
import android.database.Cursor;
import com.carver.paul.truesight.Models.AdvantagesDownloader.AdvantagesDatum;
/**
* True Sight for Dota 2
* Copyright (C) 2016 Paul Broadbent
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.Models;
public class HeroAndAdvantages implements Comparable<HeroAndAdvantages> {
public static final double NEUTRAL_ADVANTAGE = 999;
private static final String ID_COLUMN = "_id";
private static final String NAME_COLUMN = "name";
private static final String CARRY_COLUMN = "is_carry";
private static final String SUPPORT_COLUMN = "is_support";
private static final String MID_COLUMN = "is_mid";
private static final String ROAMING_COLUMN = "is_roaming";
private static final String JUNGLER_COLUMN = "is_jungler";
private static final String OFF_LANE_COLUMN = "is_off_lane";
private final int mId;
private final String mName;
private final boolean mIsCarry;
private final boolean mIsSupport;
private final boolean mIsMid;
private final boolean mIsRoaming;
private final boolean mIsJungler;
private final boolean mIsOffLane;
// The list of advantages this hero has over those in the photo
private List<Double> mAdvantages;
private double mTotalAdvantage = 0;
| public HeroAndAdvantages(AdvantagesDatum downloadedDatum) { |
dbdkmezz/true-sight-dota | app/src/main/java/com/carver/paul/truesight/Models/HeroAndSimilarity.java | // Path: app/src/main/java/com/carver/paul/truesight/ImageRecognition/LoadedHeroImage.java
// public class LoadedHeroImage {
// public Mat mat;
// public Mat comparisonMat;
// public String name;
//
// private int mDrawableId;
//
// public LoadedHeroImage(Context context, int drawableId, String name) {
// Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), drawableId);
// mat = ImageTools.GetMatFromBitmap(bitmap);
// this.name = name;
// mDrawableId = drawableId;
// }
//
// public int getImageResource() {
// return mDrawableId;
// }
//
// public static LoadedHeroImage newMissingHero() {
// LoadedHeroImage missingHero = new LoadedHeroImage();
// missingHero.mat = null;
// missingHero.name = "";
// missingHero.mDrawableId = R.drawable.missing_hero;
// return missingHero;
// }
//
// /**
// * private constructor for creating missing heroes
// */
// private LoadedHeroImage() {}
// }
| import com.carver.paul.truesight.ImageRecognition.LoadedHeroImage; | /**
* True Sight for Dota 2
* Copyright (C) 2015 Paul Broadbent
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.Models;
/**
* HeroAndSimilarity stores a LoadedHeroImage with a similarity value. It overrides the equals function
* so that two heroes with the same name are equal.
*/
public class HeroAndSimilarity implements Comparable<HeroAndSimilarity> {
public Double similarity; | // Path: app/src/main/java/com/carver/paul/truesight/ImageRecognition/LoadedHeroImage.java
// public class LoadedHeroImage {
// public Mat mat;
// public Mat comparisonMat;
// public String name;
//
// private int mDrawableId;
//
// public LoadedHeroImage(Context context, int drawableId, String name) {
// Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), drawableId);
// mat = ImageTools.GetMatFromBitmap(bitmap);
// this.name = name;
// mDrawableId = drawableId;
// }
//
// public int getImageResource() {
// return mDrawableId;
// }
//
// public static LoadedHeroImage newMissingHero() {
// LoadedHeroImage missingHero = new LoadedHeroImage();
// missingHero.mat = null;
// missingHero.name = "";
// missingHero.mDrawableId = R.drawable.missing_hero;
// return missingHero;
// }
//
// /**
// * private constructor for creating missing heroes
// */
// private LoadedHeroImage() {}
// }
// Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAndSimilarity.java
import com.carver.paul.truesight.ImageRecognition.LoadedHeroImage;
/**
* True Sight for Dota 2
* Copyright (C) 2015 Paul Broadbent
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.Models;
/**
* HeroAndSimilarity stores a LoadedHeroImage with a similarity value. It overrides the equals function
* so that two heroes with the same name are equal.
*/
public class HeroAndSimilarity implements Comparable<HeroAndSimilarity> {
public Double similarity; | public LoadedHeroImage hero; |
dbdkmezz/true-sight-dota | app/src/main/java/com/carver/paul/truesight/ImageRecognition/SimilarityTest.java | // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAndSimilarity.java
// public class HeroAndSimilarity implements Comparable<HeroAndSimilarity> {
// public Double similarity;
// public LoadedHeroImage hero;
//
// public HeroAndSimilarity(LoadedHeroImage hero, double similarity) {
// this.hero = hero;
// this.similarity = similarity;
// }
//
// @Override
// public int compareTo(HeroAndSimilarity other) {
// return this.similarity.compareTo(other.similarity);
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == this)
// return true;
// if (o instanceof String) {
// String string = (String) o;
// return string.equals(this.hero.name);
// }
// if (!(o instanceof HeroAndSimilarity))
// return false;
// HeroAndSimilarity hhs = (HeroAndSimilarity) o;
// return this.hero.name.equals(hhs.hero.name);
// }
//
// @Override
// public int hashCode() {
// return hero.name.hashCode();
// }
// }
| import org.opencv.imgproc.Imgproc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import android.content.Context;
import android.util.Log;
import android.util.Pair;
import com.carver.paul.truesight.BuildConfig;
import com.carver.paul.truesight.Models.HeroAndSimilarity;
import com.carver.paul.truesight.R;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Size; | //new Pair<>(R.drawable.blank_hero, "blank_hero"));
}
public int NumberOfHeroesLoaded() {
return mHeroes.size();
}
/**
* This constructor sets loading all the heroes needed for the comparison work
* @param context
*/
public SimilarityTest(Context context) {
if (BuildConfig.DEBUG) Log.d(TAG, "Loading comparison images.");
for (Pair<Integer, String> drawableIdAndName : mHeroIconDrawables) {
LoadedHeroImage hero = new LoadedHeroImage(context, drawableIdAndName.first, drawableIdAndName.second);
mHeroes.add(hero);
}
if (BuildConfig.DEBUG) {
Log.d(TAG, "Loaded " + NumberOfHeroesLoaded() + " hero images.");
}
}
/**
* Return a list of heroes with the similarity to the photo, ordered with the most similar
* first.
* @param photo
* @return
*/ | // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAndSimilarity.java
// public class HeroAndSimilarity implements Comparable<HeroAndSimilarity> {
// public Double similarity;
// public LoadedHeroImage hero;
//
// public HeroAndSimilarity(LoadedHeroImage hero, double similarity) {
// this.hero = hero;
// this.similarity = similarity;
// }
//
// @Override
// public int compareTo(HeroAndSimilarity other) {
// return this.similarity.compareTo(other.similarity);
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == this)
// return true;
// if (o instanceof String) {
// String string = (String) o;
// return string.equals(this.hero.name);
// }
// if (!(o instanceof HeroAndSimilarity))
// return false;
// HeroAndSimilarity hhs = (HeroAndSimilarity) o;
// return this.hero.name.equals(hhs.hero.name);
// }
//
// @Override
// public int hashCode() {
// return hero.name.hashCode();
// }
// }
// Path: app/src/main/java/com/carver/paul/truesight/ImageRecognition/SimilarityTest.java
import org.opencv.imgproc.Imgproc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import android.content.Context;
import android.util.Log;
import android.util.Pair;
import com.carver.paul.truesight.BuildConfig;
import com.carver.paul.truesight.Models.HeroAndSimilarity;
import com.carver.paul.truesight.R;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Size;
//new Pair<>(R.drawable.blank_hero, "blank_hero"));
}
public int NumberOfHeroesLoaded() {
return mHeroes.size();
}
/**
* This constructor sets loading all the heroes needed for the comparison work
* @param context
*/
public SimilarityTest(Context context) {
if (BuildConfig.DEBUG) Log.d(TAG, "Loading comparison images.");
for (Pair<Integer, String> drawableIdAndName : mHeroIconDrawables) {
LoadedHeroImage hero = new LoadedHeroImage(context, drawableIdAndName.first, drawableIdAndName.second);
mHeroes.add(hero);
}
if (BuildConfig.DEBUG) {
Log.d(TAG, "Loaded " + NumberOfHeroesLoaded() + " hero images.");
}
}
/**
* Return a list of heroes with the similarity to the photo, ordered with the most similar
* first.
* @param photo
* @return
*/ | public List<HeroAndSimilarity> OrderedListOfTemplateSimilarHeroes(Mat photo) { |
dbdkmezz/true-sight-dota | app/src/main/java/com/carver/paul/truesight/Models/HeroImageAndPosition.java | // Path: app/src/main/java/com/carver/paul/truesight/ImageRecognition/ImageTools.java
// public class ImageTools {
//
// private ImageTools() {}
//
// private static final String TAG = "ImageTools";
//
// public static void MaskAColourFromImage(Mat image, Scalar lowerHsv, Scalar upperHsv, Mat mask) {
// Imgproc.cvtColor(image, mask, Imgproc.COLOR_BGR2HSV);
// Core.inRange(mask, lowerHsv, upperHsv, mask);
// }
//
// public static Bitmap GetBitmapFromMat(Mat mat) {
// return GetBitmapFromMat(mat, true);
// }
//
// public static Bitmap GetBitmapFromMat(Mat mat, boolean convertColor) {
// Bitmap bitmap = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
// if (convertColor) {
// Mat finalColourMat = new Mat();
// Imgproc.cvtColor(mat, finalColourMat, Imgproc.COLOR_BGR2RGB);
// matToBitmap(finalColourMat, bitmap);
// } else {
// matToBitmap(mat, bitmap);
// }
//
// return bitmap;
// }
//
// public static Mat GetMatFromBitmap(Bitmap bitmap) {
// Mat mat = new Mat();
// bitmapToMat(bitmap, mat);
// Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2BGR);
// return mat;
// }
//
// public static void getLineFromTopRectMask(Mat mask, Mat lines, int minLineLength) {
// Imgproc.HoughLinesP(mask, lines, 1, Math.PI / 180, 80, minLineLength, 10);
// }
//
// public static int getDrawableForAbility(String abilityImageName) {
// for (Pair<Integer, String> pair : Variables.abilityDrawables) {
// if (pair.second.equals(abilityImageName))
// return pair.first;
// }
//
// Log.d(TAG, "No image found for ability " + abilityImageName);
// return -1;
// }
//
// public static int getResIdForHeroImage(String heroImageName) {
// if(heroImageName == null || heroImageName.equals("")) {
// return R.drawable.missing_hero;
// }
//
// for (Pair<Integer, String> pair : SimilarityTest.mHeroIconDrawables) {
// if (pair.second.equals(heroImageName))
// return pair.first;
// }
//
// Log.d(TAG, "No image for hero " + heroImageName + " found");
// return -1;
// }
//
// public static void drawLinesOnImage(Mat lines, Mat image) {
// for (int i = 0; i < lines.rows(); i++) {
// double[] val = lines.get(i, 0);
// Imgproc.line(image, new Point(val[0], val[1]), new Point(val[2], val[3]), new Scalar(0, 255, 0), 2);
// }
// }
//
// public static int findLongestLine(List<Mat> linesList) {
// int longestLine = 0;
//
// for (Mat lines : linesList) {
// for (int i = 0; i < lines.rows(); i++) {
// if (lineLength(lines.get(i, 0)) > longestLine)
// longestLine = lineLength(lines.get(i, 0));
// }
// }
//
// return longestLine;
// }
//
// private static int lineLength(double[] line) {
// if (line[2] > line[0])
// return (int) (line[2] - line[0]);
//
// return (int) (line[0] - line[1]);
// }
// }
| import org.opencv.core.Mat;
import android.graphics.Bitmap;
import com.carver.paul.truesight.ImageRecognition.ImageTools; | /**
* True Sight for Dota 2
* Copyright (C) 2016 Paul Broadbent
* <p/>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p/>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p/>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.Models;
/**
* HeroImageAndPosition contains an image of a hero taken from the photo and the position in
* the photo of the image.
*/
public class HeroImageAndPosition {
private final Bitmap mImage;
private final int mPosition;
/**
* HeroImageAndPosition contains an image of a hero taken from the photo and the position in
* the photo of the image.
* @param image
* @param position A number between 0 and 4, giving the position of the image in the photo
* (counting from left to right).
*/
public HeroImageAndPosition(Mat image, int position) {
if (position < 0 || position > 4) {
throw new RuntimeException("Attempting to create a HeroImageAndPosition with an " +
"invalid position");
} | // Path: app/src/main/java/com/carver/paul/truesight/ImageRecognition/ImageTools.java
// public class ImageTools {
//
// private ImageTools() {}
//
// private static final String TAG = "ImageTools";
//
// public static void MaskAColourFromImage(Mat image, Scalar lowerHsv, Scalar upperHsv, Mat mask) {
// Imgproc.cvtColor(image, mask, Imgproc.COLOR_BGR2HSV);
// Core.inRange(mask, lowerHsv, upperHsv, mask);
// }
//
// public static Bitmap GetBitmapFromMat(Mat mat) {
// return GetBitmapFromMat(mat, true);
// }
//
// public static Bitmap GetBitmapFromMat(Mat mat, boolean convertColor) {
// Bitmap bitmap = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
// if (convertColor) {
// Mat finalColourMat = new Mat();
// Imgproc.cvtColor(mat, finalColourMat, Imgproc.COLOR_BGR2RGB);
// matToBitmap(finalColourMat, bitmap);
// } else {
// matToBitmap(mat, bitmap);
// }
//
// return bitmap;
// }
//
// public static Mat GetMatFromBitmap(Bitmap bitmap) {
// Mat mat = new Mat();
// bitmapToMat(bitmap, mat);
// Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2BGR);
// return mat;
// }
//
// public static void getLineFromTopRectMask(Mat mask, Mat lines, int minLineLength) {
// Imgproc.HoughLinesP(mask, lines, 1, Math.PI / 180, 80, minLineLength, 10);
// }
//
// public static int getDrawableForAbility(String abilityImageName) {
// for (Pair<Integer, String> pair : Variables.abilityDrawables) {
// if (pair.second.equals(abilityImageName))
// return pair.first;
// }
//
// Log.d(TAG, "No image found for ability " + abilityImageName);
// return -1;
// }
//
// public static int getResIdForHeroImage(String heroImageName) {
// if(heroImageName == null || heroImageName.equals("")) {
// return R.drawable.missing_hero;
// }
//
// for (Pair<Integer, String> pair : SimilarityTest.mHeroIconDrawables) {
// if (pair.second.equals(heroImageName))
// return pair.first;
// }
//
// Log.d(TAG, "No image for hero " + heroImageName + " found");
// return -1;
// }
//
// public static void drawLinesOnImage(Mat lines, Mat image) {
// for (int i = 0; i < lines.rows(); i++) {
// double[] val = lines.get(i, 0);
// Imgproc.line(image, new Point(val[0], val[1]), new Point(val[2], val[3]), new Scalar(0, 255, 0), 2);
// }
// }
//
// public static int findLongestLine(List<Mat> linesList) {
// int longestLine = 0;
//
// for (Mat lines : linesList) {
// for (int i = 0; i < lines.rows(); i++) {
// if (lineLength(lines.get(i, 0)) > longestLine)
// longestLine = lineLength(lines.get(i, 0));
// }
// }
//
// return longestLine;
// }
//
// private static int lineLength(double[] line) {
// if (line[2] > line[0])
// return (int) (line[2] - line[0]);
//
// return (int) (line[0] - line[1]);
// }
// }
// Path: app/src/main/java/com/carver/paul/truesight/Models/HeroImageAndPosition.java
import org.opencv.core.Mat;
import android.graphics.Bitmap;
import com.carver.paul.truesight.ImageRecognition.ImageTools;
/**
* True Sight for Dota 2
* Copyright (C) 2016 Paul Broadbent
* <p/>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p/>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p/>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*/
package com.carver.paul.truesight.Models;
/**
* HeroImageAndPosition contains an image of a hero taken from the photo and the position in
* the photo of the image.
*/
public class HeroImageAndPosition {
private final Bitmap mImage;
private final int mPosition;
/**
* HeroImageAndPosition contains an image of a hero taken from the photo and the position in
* the photo of the image.
* @param image
* @param position A number between 0 and 4, giving the position of the image in the photo
* (counting from left to right).
*/
public HeroImageAndPosition(Mat image, int position) {
if (position < 0 || position > 4) {
throw new RuntimeException("Attempting to create a HeroImageAndPosition with an " +
"invalid position");
} | mImage = ImageTools.GetBitmapFromMat(image); |
dbdkmezz/true-sight-dota | app/src/main/java/com/carver/paul/truesight/Ui/AbilityInfo/AbilityInfoCard/TalentsCardPresenter.java | // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
| import com.carver.paul.truesight.Models.HeroAbilityInfo;
import java.util.List; | package com.carver.paul.truesight.Ui.AbilityInfo.AbilityInfoCard;
public class TalentsCardPresenter {
private TalentsCardView mView; | // Path: app/src/main/java/com/carver/paul/truesight/Models/HeroAbilityInfo.java
// public class HeroAbilityInfo {
// public static final int STUN = 0;
// public static final int DISABLE_NOT_STUN = 1;
// public static final int SILENCE = 2;
// public static final int ULTIMATE = 3;
// public static final int SPELL_IMMUNITY = 4;
//
// public boolean isUltimate;
// public boolean isStun;
// public boolean isDisable;
// public boolean isSilence;
// public boolean isMute;
// public String heroName;
// public String name;
// public String imageName;
// public String description;
// public String manaCost;
// public String cooldown;
// public String disableDuration;
// public List<String> abilityDetails;
// public List<RemovableBuff> removableDebuffs;
// public Boolean piercesSpellImmunity = null;
// public String piercesSIType = null;
// public String piercesSIDetail = null;
//
// public HeroAbilityInfo() {
// abilityDetails = new ArrayList<>();
// removableDebuffs = new ArrayList<>();
// }
//
// public HeroAbilityInfo Copy()
// {
// HeroAbilityInfo ability = new HeroAbilityInfo();
// ability.isUltimate = isUltimate;ability.isStun = isStun;
// ability.isDisable = isDisable;
// ability.isSilence = isSilence;
// ability.isMute = isMute;
// ability.heroName = heroName;
// ability.name = name;
// ability.imageName = imageName;
// ability.description = description;
// ability.manaCost = manaCost;
// ability.cooldown = cooldown;
// ability.disableDuration = disableDuration;
// ability.abilityDetails = abilityDetails;
// ability.removableDebuffs = removableDebuffs;
// ability.piercesSpellImmunity = piercesSpellImmunity;
// ability.piercesSIType = piercesSIType;
// ability.piercesSIDetail = piercesSIDetail;
//
// return ability;
// }
//
// //TODO: save silence durations in the XML too
// public String guessAbilityDuration(int abilityType) {
// if (abilityType != STUN && abilityType != SILENCE && abilityType != DISABLE_NOT_STUN)
// throw new RuntimeException("guessAbilityDuration passed wrong abilityType");
//
// if (abilityType == STUN || abilityType == DISABLE_NOT_STUN) {
// if (isDisable != true) {
// return null;
// }
// else {
// return disableDuration;
// }
// }
//
// if (abilityType != SILENCE)
// throw new RuntimeException("abilityType should be silence by now");
//
// for (String detail : abilityDetails) {
// if (detail.contains("SILENCE")
// && (detail.contains("MAX") || detail.contains("DURATION"))) {
// return detail;
// } else if (detail.startsWith("DURATION:")) {
// return detail;
// } else if (detail.startsWith("HERO DURATION:")) {
// return detail;
// }
// }
//
// // If still not found the duration, then just use any old detail string with a DURATION or
// // MAX
// for (String detail : abilityDetails) {
// if (detail.contains("DURATION") || detail.contains("MAX")) {
// return detail;
// }
// }
//
// return null;
// }
//
// public static class RemovableBuff {
// public String description;
// public boolean basicDispel;
// public boolean strongDispel;
// }
//
// public static class Talent {
// public int level;
// public String optionOne;
// public String optionTwo;
// }
// }
// Path: app/src/main/java/com/carver/paul/truesight/Ui/AbilityInfo/AbilityInfoCard/TalentsCardPresenter.java
import com.carver.paul.truesight.Models.HeroAbilityInfo;
import java.util.List;
package com.carver.paul.truesight.Ui.AbilityInfo.AbilityInfoCard;
public class TalentsCardPresenter {
private TalentsCardView mView; | private List<HeroAbilityInfo.Talent> mTalents; |
mborjesson/LG-Optimus-2X-Black-Notifications | src/com/martinborjesson/o2xtouchlednotifications/ui/MainPreferences.java | // Path: src/com/martinborjesson/o2xtouchlednotifications/services/AccessibilityService.java
// static public class NotificationEvent {
// public long time = 0;
// public String packageName = null;
// public String label = null;
// public boolean lights = false;
// }
//
// Path: src/com/martinborjesson/o2xtouchlednotifications/ui/preference/SeekBarPreference.java
// static public interface OnNoChangeListener {
// public void onNoChange(Preference preference);
// }
| import java.io.*;
import java.util.*;
import android.accounts.*;
import android.app.*;
import android.content.*;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.*;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.os.*;
import android.preference.*;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.provider.*;
import android.provider.Settings.SettingNotFoundException;
import android.text.format.*;
import android.text.method.*;
import android.util.*;
import android.widget.*;
import android.widget.SeekBar.OnSeekBarChangeListener;
import com.martinborjesson.o2xtouchlednotifications.*;
import com.martinborjesson.o2xtouchlednotifications.notifications.*;
import com.martinborjesson.o2xtouchlednotifications.services.*;
import com.martinborjesson.o2xtouchlednotifications.services.AccessibilityService.NotificationEvent;
import com.martinborjesson.o2xtouchlednotifications.touchled.*;
import com.martinborjesson.o2xtouchlednotifications.touchled.devices.*;
import com.martinborjesson.o2xtouchlednotifications.ui.preference.*;
import com.martinborjesson.o2xtouchlednotifications.ui.preference.SeekBarPreference.OnNoChangeListener;
import com.martinborjesson.o2xtouchlednotifications.utils.*; | // @Override
// public boolean onPreferenceClick(Preference preference) {
// AlertDialog.Builder builder = new AlertDialog.Builder(MainPreferences.this);
// builder.setTitle("Testing pulse...");
// builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
//
// @Override
// public void onClick(DialogInterface dialog, int which) {
// BootReceiver.stopPulse(MainPreferences.this);
// }
// });
// testPulseDialog = builder.create();
// testPulseDialog.show();
//
// BootReceiver.startService(MainPreferences.this, null);
//
// return true;
// }
// });
}
{ // log all notifications
Preference p = findPreference("buttonListNotificationsFromActivities");
p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Context context = MainPreferences.this;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.dialog_title_logged_notifications);
builder.setPositiveButton(android.R.string.ok, null); | // Path: src/com/martinborjesson/o2xtouchlednotifications/services/AccessibilityService.java
// static public class NotificationEvent {
// public long time = 0;
// public String packageName = null;
// public String label = null;
// public boolean lights = false;
// }
//
// Path: src/com/martinborjesson/o2xtouchlednotifications/ui/preference/SeekBarPreference.java
// static public interface OnNoChangeListener {
// public void onNoChange(Preference preference);
// }
// Path: src/com/martinborjesson/o2xtouchlednotifications/ui/MainPreferences.java
import java.io.*;
import java.util.*;
import android.accounts.*;
import android.app.*;
import android.content.*;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.*;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.os.*;
import android.preference.*;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.provider.*;
import android.provider.Settings.SettingNotFoundException;
import android.text.format.*;
import android.text.method.*;
import android.util.*;
import android.widget.*;
import android.widget.SeekBar.OnSeekBarChangeListener;
import com.martinborjesson.o2xtouchlednotifications.*;
import com.martinborjesson.o2xtouchlednotifications.notifications.*;
import com.martinborjesson.o2xtouchlednotifications.services.*;
import com.martinborjesson.o2xtouchlednotifications.services.AccessibilityService.NotificationEvent;
import com.martinborjesson.o2xtouchlednotifications.touchled.*;
import com.martinborjesson.o2xtouchlednotifications.touchled.devices.*;
import com.martinborjesson.o2xtouchlednotifications.ui.preference.*;
import com.martinborjesson.o2xtouchlednotifications.ui.preference.SeekBarPreference.OnNoChangeListener;
import com.martinborjesson.o2xtouchlednotifications.utils.*;
// @Override
// public boolean onPreferenceClick(Preference preference) {
// AlertDialog.Builder builder = new AlertDialog.Builder(MainPreferences.this);
// builder.setTitle("Testing pulse...");
// builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
//
// @Override
// public void onClick(DialogInterface dialog, int which) {
// BootReceiver.stopPulse(MainPreferences.this);
// }
// });
// testPulseDialog = builder.create();
// testPulseDialog.show();
//
// BootReceiver.startService(MainPreferences.this, null);
//
// return true;
// }
// });
}
{ // log all notifications
Preference p = findPreference("buttonListNotificationsFromActivities");
p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Context context = MainPreferences.this;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.dialog_title_logged_notifications);
builder.setPositiveButton(android.R.string.ok, null); | List<NotificationEvent> events = AccessibilityService.getNotificationEvents(); |
mborjesson/LG-Optimus-2X-Black-Notifications | src/com/martinborjesson/o2xtouchlednotifications/ui/MainPreferences.java | // Path: src/com/martinborjesson/o2xtouchlednotifications/services/AccessibilityService.java
// static public class NotificationEvent {
// public long time = 0;
// public String packageName = null;
// public String label = null;
// public boolean lights = false;
// }
//
// Path: src/com/martinborjesson/o2xtouchlednotifications/ui/preference/SeekBarPreference.java
// static public interface OnNoChangeListener {
// public void onNoChange(Preference preference);
// }
| import java.io.*;
import java.util.*;
import android.accounts.*;
import android.app.*;
import android.content.*;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.*;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.os.*;
import android.preference.*;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.provider.*;
import android.provider.Settings.SettingNotFoundException;
import android.text.format.*;
import android.text.method.*;
import android.util.*;
import android.widget.*;
import android.widget.SeekBar.OnSeekBarChangeListener;
import com.martinborjesson.o2xtouchlednotifications.*;
import com.martinborjesson.o2xtouchlednotifications.notifications.*;
import com.martinborjesson.o2xtouchlednotifications.services.*;
import com.martinborjesson.o2xtouchlednotifications.services.AccessibilityService.NotificationEvent;
import com.martinborjesson.o2xtouchlednotifications.touchled.*;
import com.martinborjesson.o2xtouchlednotifications.touchled.devices.*;
import com.martinborjesson.o2xtouchlednotifications.ui.preference.*;
import com.martinborjesson.o2xtouchlednotifications.ui.preference.SeekBarPreference.OnNoChangeListener;
import com.martinborjesson.o2xtouchlednotifications.utils.*; | @Override
public boolean onPreferenceClick(Preference preference) {
touchLEDStrength = touchLED.getCurrent();
touchLED.setAll(((SeekBarPreference)preference).getProgress());
return true;
}
});
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (fromUser) {
// touchLED.setAll(progress);
}
}
});
| // Path: src/com/martinborjesson/o2xtouchlednotifications/services/AccessibilityService.java
// static public class NotificationEvent {
// public long time = 0;
// public String packageName = null;
// public String label = null;
// public boolean lights = false;
// }
//
// Path: src/com/martinborjesson/o2xtouchlednotifications/ui/preference/SeekBarPreference.java
// static public interface OnNoChangeListener {
// public void onNoChange(Preference preference);
// }
// Path: src/com/martinborjesson/o2xtouchlednotifications/ui/MainPreferences.java
import java.io.*;
import java.util.*;
import android.accounts.*;
import android.app.*;
import android.content.*;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.*;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.os.*;
import android.preference.*;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.provider.*;
import android.provider.Settings.SettingNotFoundException;
import android.text.format.*;
import android.text.method.*;
import android.util.*;
import android.widget.*;
import android.widget.SeekBar.OnSeekBarChangeListener;
import com.martinborjesson.o2xtouchlednotifications.*;
import com.martinborjesson.o2xtouchlednotifications.notifications.*;
import com.martinborjesson.o2xtouchlednotifications.services.*;
import com.martinborjesson.o2xtouchlednotifications.services.AccessibilityService.NotificationEvent;
import com.martinborjesson.o2xtouchlednotifications.touchled.*;
import com.martinborjesson.o2xtouchlednotifications.touchled.devices.*;
import com.martinborjesson.o2xtouchlednotifications.ui.preference.*;
import com.martinborjesson.o2xtouchlednotifications.ui.preference.SeekBarPreference.OnNoChangeListener;
import com.martinborjesson.o2xtouchlednotifications.utils.*;
@Override
public boolean onPreferenceClick(Preference preference) {
touchLEDStrength = touchLED.getCurrent();
touchLED.setAll(((SeekBarPreference)preference).getProgress());
return true;
}
});
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (fromUser) {
// touchLED.setAll(progress);
}
}
});
| seekBar.setOnNoChangeListener(new OnNoChangeListener() { |
eBay/mTracker | core/src/test/java/com/ccoe/build/core/utils/StringUtilsTest.java | // Path: core/src/main/java/com/ccoe/build/core/utils/StringUtils.java
// public class StringUtils {
//
// public static boolean isEmpty(String str) {
// return (str == null) || (str.length() == 0);
// }
//
// public static List<String> getFound(String contents, String regex,
// boolean isCaseInsensitive) {
// if (isEmpty(regex) || isEmpty(contents)) {
// return new ArrayList<String>();
// }
// List<String> results = new ArrayList<String>();
// Pattern pattern;
// if (isCaseInsensitive) {
// pattern = Pattern.compile(regex, Pattern.UNICODE_CASE
// | Pattern.CASE_INSENSITIVE);
// } else {
// pattern = Pattern.compile(regex, Pattern.UNICODE_CASE);
// }
// Matcher matcher = pattern.matcher(contents);
// while (matcher.find()) {
// if (matcher.groupCount() > 0) {
// for (int i = 1; i <= matcher.groupCount(); i++) {
// if (!isEmpty(matcher.group(i))) {
// results.add(matcher.group(i));
// }
// }
// } else {
// if (!isEmpty(matcher.group())) {
// results.add(matcher.group());
// }
// }
// }
// return results;
// }
//
// public static String getFirstFound(String contents, String regex,
// boolean isCaseInsensitive) {
// if (isEmpty(contents) || isEmpty(regex)) {
// return null;
// }
// List<String> found = getFound(contents, regex, isCaseInsensitive);
// if (found.size() > 0) {
// return (String) found.iterator().next();
// }
// return "";
// }
//
// public static Date setTime(Date date, String timeString) {
// Calendar cal1 = Calendar.getInstance();
// cal1.setTime(date);
//
// Calendar cal2 = Calendar.getInstance();
//
// String[] time = timeString.split(":");
//
// cal2.set(cal1.get(Calendar.YEAR),
// cal1.get(Calendar.MONTH),
// cal1.get(Calendar.DAY_OF_MONTH),
// Integer.parseInt(time[0]),
// Integer.parseInt(time[1]),
// Integer.parseInt(time[2]));
//
// return cal2.getTime();
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.Calendar;
import java.util.List;
import org.junit.Test;
import com.ccoe.build.core.utils.StringUtils; | /*
Copyright [2013-2014] eBay Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.ccoe.build.core.utils;
public class StringUtilsTest {
@Test
public void testGetFirstFound() { | // Path: core/src/main/java/com/ccoe/build/core/utils/StringUtils.java
// public class StringUtils {
//
// public static boolean isEmpty(String str) {
// return (str == null) || (str.length() == 0);
// }
//
// public static List<String> getFound(String contents, String regex,
// boolean isCaseInsensitive) {
// if (isEmpty(regex) || isEmpty(contents)) {
// return new ArrayList<String>();
// }
// List<String> results = new ArrayList<String>();
// Pattern pattern;
// if (isCaseInsensitive) {
// pattern = Pattern.compile(regex, Pattern.UNICODE_CASE
// | Pattern.CASE_INSENSITIVE);
// } else {
// pattern = Pattern.compile(regex, Pattern.UNICODE_CASE);
// }
// Matcher matcher = pattern.matcher(contents);
// while (matcher.find()) {
// if (matcher.groupCount() > 0) {
// for (int i = 1; i <= matcher.groupCount(); i++) {
// if (!isEmpty(matcher.group(i))) {
// results.add(matcher.group(i));
// }
// }
// } else {
// if (!isEmpty(matcher.group())) {
// results.add(matcher.group());
// }
// }
// }
// return results;
// }
//
// public static String getFirstFound(String contents, String regex,
// boolean isCaseInsensitive) {
// if (isEmpty(contents) || isEmpty(regex)) {
// return null;
// }
// List<String> found = getFound(contents, regex, isCaseInsensitive);
// if (found.size() > 0) {
// return (String) found.iterator().next();
// }
// return "";
// }
//
// public static Date setTime(Date date, String timeString) {
// Calendar cal1 = Calendar.getInstance();
// cal1.setTime(date);
//
// Calendar cal2 = Calendar.getInstance();
//
// String[] time = timeString.split(":");
//
// cal2.set(cal1.get(Calendar.YEAR),
// cal1.get(Calendar.MONTH),
// cal1.get(Calendar.DAY_OF_MONTH),
// Integer.parseInt(time[0]),
// Integer.parseInt(time[1]),
// Integer.parseInt(time[2]));
//
// return cal2.getTime();
// }
// }
// Path: core/src/test/java/com/ccoe/build/core/utils/StringUtilsTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.Calendar;
import java.util.List;
import org.junit.Test;
import com.ccoe.build.core.utils.StringUtils;
/*
Copyright [2013-2014] eBay Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.ccoe.build.core.utils;
public class StringUtilsTest {
@Test
public void testGetFirstFound() { | assertNull(StringUtils.getFirstFound("", "", true)); |
eBay/mTracker | publisher/src/main/java/com/ccoe/build/dal/RawDataJDBCTemplate.java | // Path: core/src/main/java/com/ccoe/build/core/model/Plugin.java
// public class Plugin extends TrackingModel {
// private String groupId;
// private String artifactId;
// private String version;
//
// private String status;
// private String executionId;
//
// private String phaseName;
// private String pluginKey;
//
// private int id;
//
// private String payload;
//
// public String getGroupId() {
// return groupId;
// }
//
// public void setGroupId(String groupId) {
// this.groupId = groupId;
// }
//
// public String getArtifactId() {
// return artifactId;
// }
//
// public void setArtifactId(String artifactId) {
// this.artifactId = artifactId;
// }
//
// public String getVersion() {
// return version;
// }
//
// public void setVersion(String version) {
// this.version = version;
// }
//
// public String getStatus() {
// return status;
// }
//
// public void setStatus(String status) {
// this.status = status;
// }
//
// public String getExecutionId() {
// return executionId;
// }
//
// public void setExecutionId(String executionId) {
// this.executionId = executionId;
// }
//
// public String getPhaseName() {
// return phaseName;
// }
//
// public void setPhaseName(String phaseName) {
// this.phaseName = phaseName;
// }
//
// public String getPluginKey() {
// return pluginKey;
// }
//
// public void setPluginKey(String pluginKey) {
// this.pluginKey = pluginKey;
// }
//
// public int getId() {
// return id;
// }
//
// public void setId(int id) {
// this.id = id;
// }
//
// public String getPayload() {
// return payload;
// }
//
// public void setPayload(String payload) {
// this.payload = payload;
// }
//
// public String toString() {
// StringBuffer sBuffer = new StringBuffer();
// appendTransactionAtom(sBuffer, 4, "Plugin", getPluginKey(), this.getStatus(), getDuration().toString(), getPayload());
// return sBuffer.toString();
// }
// }
| import com.ccoe.build.core.model.Plugin;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder; | /*
Copyright [2013-2014] eBay Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.ccoe.build.dal;
public class RawDataJDBCTemplate {
private DataSource dataSource;
private JdbcTemplate jdbcTemplateObject;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplateObject = new JdbcTemplate(dataSource);
}
// TODO event date | // Path: core/src/main/java/com/ccoe/build/core/model/Plugin.java
// public class Plugin extends TrackingModel {
// private String groupId;
// private String artifactId;
// private String version;
//
// private String status;
// private String executionId;
//
// private String phaseName;
// private String pluginKey;
//
// private int id;
//
// private String payload;
//
// public String getGroupId() {
// return groupId;
// }
//
// public void setGroupId(String groupId) {
// this.groupId = groupId;
// }
//
// public String getArtifactId() {
// return artifactId;
// }
//
// public void setArtifactId(String artifactId) {
// this.artifactId = artifactId;
// }
//
// public String getVersion() {
// return version;
// }
//
// public void setVersion(String version) {
// this.version = version;
// }
//
// public String getStatus() {
// return status;
// }
//
// public void setStatus(String status) {
// this.status = status;
// }
//
// public String getExecutionId() {
// return executionId;
// }
//
// public void setExecutionId(String executionId) {
// this.executionId = executionId;
// }
//
// public String getPhaseName() {
// return phaseName;
// }
//
// public void setPhaseName(String phaseName) {
// this.phaseName = phaseName;
// }
//
// public String getPluginKey() {
// return pluginKey;
// }
//
// public void setPluginKey(String pluginKey) {
// this.pluginKey = pluginKey;
// }
//
// public int getId() {
// return id;
// }
//
// public void setId(int id) {
// this.id = id;
// }
//
// public String getPayload() {
// return payload;
// }
//
// public void setPayload(String payload) {
// this.payload = payload;
// }
//
// public String toString() {
// StringBuffer sBuffer = new StringBuffer();
// appendTransactionAtom(sBuffer, 4, "Plugin", getPluginKey(), this.getStatus(), getDuration().toString(), getPayload());
// return sBuffer.toString();
// }
// }
// Path: publisher/src/main/java/com/ccoe/build/dal/RawDataJDBCTemplate.java
import com.ccoe.build.core.model.Plugin;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
/*
Copyright [2013-2014] eBay Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.ccoe.build.dal;
public class RawDataJDBCTemplate {
private DataSource dataSource;
private JdbcTemplate jdbcTemplateObject;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplateObject = new JdbcTemplate(dataSource);
}
// TODO event date | public int create(final Plugin plugin, final int sessionID, final int projectID) { |
eBay/mTracker | core/src/main/java/com/ccoe/build/core/filter/FilterMatcher.java | // Path: core/src/main/java/com/ccoe/build/core/filter/model/Cause.java
// @XmlAccessorType(XmlAccessType.FIELD)
// public class Cause {
//
// @XmlAttribute
// private String source;
//
// @XmlAttribute
// private String keyword;
//
// @XmlAttribute
// private String pattern;
//
// @XmlAttribute
// private String value;
//
// public String getSource() {
// return source;
// }
//
// public void setSource(String source) {
// this.source = source;
// }
//
// public String getKeyword() {
// return keyword;
// }
//
// public void setKeyword(String keyword) {
// this.keyword = keyword;
// }
//
// public String getPattern() {
// return this.pattern;
// }
//
// public void setPattern(String p) {
// this.pattern = p;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
// }
//
// Path: core/src/main/java/com/ccoe/build/core/filter/model/Filter.java
// @XmlAccessorType(XmlAccessType.FIELD)
// public class Filter {
// @XmlAttribute
// private String name;
//
// @XmlAttribute
// private String description;
//
// private String category;
//
// @XmlElement(name="cause")
// private List<Cause> cause = new ArrayList<Cause>();
//
// public List<Cause> getCause() {
// return this.cause;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description= description;
// }
//
// public String getCategory() {
// return category;
// }
//
// public void setCategory(String category) {
// this.category = category;
// }
//
// public void setCauses(List<Cause> lsCause){
// this.cause = lsCause;
// }
// }
//
// Path: core/src/main/java/com/ccoe/build/core/utils/StringUtils.java
// public class StringUtils {
//
// public static boolean isEmpty(String str) {
// return (str == null) || (str.length() == 0);
// }
//
// public static List<String> getFound(String contents, String regex,
// boolean isCaseInsensitive) {
// if (isEmpty(regex) || isEmpty(contents)) {
// return new ArrayList<String>();
// }
// List<String> results = new ArrayList<String>();
// Pattern pattern;
// if (isCaseInsensitive) {
// pattern = Pattern.compile(regex, Pattern.UNICODE_CASE
// | Pattern.CASE_INSENSITIVE);
// } else {
// pattern = Pattern.compile(regex, Pattern.UNICODE_CASE);
// }
// Matcher matcher = pattern.matcher(contents);
// while (matcher.find()) {
// if (matcher.groupCount() > 0) {
// for (int i = 1; i <= matcher.groupCount(); i++) {
// if (!isEmpty(matcher.group(i))) {
// results.add(matcher.group(i));
// }
// }
// } else {
// if (!isEmpty(matcher.group())) {
// results.add(matcher.group());
// }
// }
// }
// return results;
// }
//
// public static String getFirstFound(String contents, String regex,
// boolean isCaseInsensitive) {
// if (isEmpty(contents) || isEmpty(regex)) {
// return null;
// }
// List<String> found = getFound(contents, regex, isCaseInsensitive);
// if (found.size() > 0) {
// return (String) found.iterator().next();
// }
// return "";
// }
//
// public static Date setTime(Date date, String timeString) {
// Calendar cal1 = Calendar.getInstance();
// cal1.setTime(date);
//
// Calendar cal2 = Calendar.getInstance();
//
// String[] time = timeString.split(":");
//
// cal2.set(cal1.get(Calendar.YEAR),
// cal1.get(Calendar.MONTH),
// cal1.get(Calendar.DAY_OF_MONTH),
// Integer.parseInt(time[0]),
// Integer.parseInt(time[1]),
// Integer.parseInt(time[2]));
//
// return cal2.getTime();
// }
// }
| import java.util.HashMap;
import java.util.regex.Pattern;
import com.ccoe.build.core.filter.model.Cause;
import com.ccoe.build.core.filter.model.Filter;
import com.ccoe.build.core.utils.StringUtils; | /*
Copyright [2013-2014] eBay Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.ccoe.build.core.filter;
public class FilterMatcher {
public boolean isMatch(HashMap<String, String> source, Filter filter) { | // Path: core/src/main/java/com/ccoe/build/core/filter/model/Cause.java
// @XmlAccessorType(XmlAccessType.FIELD)
// public class Cause {
//
// @XmlAttribute
// private String source;
//
// @XmlAttribute
// private String keyword;
//
// @XmlAttribute
// private String pattern;
//
// @XmlAttribute
// private String value;
//
// public String getSource() {
// return source;
// }
//
// public void setSource(String source) {
// this.source = source;
// }
//
// public String getKeyword() {
// return keyword;
// }
//
// public void setKeyword(String keyword) {
// this.keyword = keyword;
// }
//
// public String getPattern() {
// return this.pattern;
// }
//
// public void setPattern(String p) {
// this.pattern = p;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
// }
//
// Path: core/src/main/java/com/ccoe/build/core/filter/model/Filter.java
// @XmlAccessorType(XmlAccessType.FIELD)
// public class Filter {
// @XmlAttribute
// private String name;
//
// @XmlAttribute
// private String description;
//
// private String category;
//
// @XmlElement(name="cause")
// private List<Cause> cause = new ArrayList<Cause>();
//
// public List<Cause> getCause() {
// return this.cause;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description= description;
// }
//
// public String getCategory() {
// return category;
// }
//
// public void setCategory(String category) {
// this.category = category;
// }
//
// public void setCauses(List<Cause> lsCause){
// this.cause = lsCause;
// }
// }
//
// Path: core/src/main/java/com/ccoe/build/core/utils/StringUtils.java
// public class StringUtils {
//
// public static boolean isEmpty(String str) {
// return (str == null) || (str.length() == 0);
// }
//
// public static List<String> getFound(String contents, String regex,
// boolean isCaseInsensitive) {
// if (isEmpty(regex) || isEmpty(contents)) {
// return new ArrayList<String>();
// }
// List<String> results = new ArrayList<String>();
// Pattern pattern;
// if (isCaseInsensitive) {
// pattern = Pattern.compile(regex, Pattern.UNICODE_CASE
// | Pattern.CASE_INSENSITIVE);
// } else {
// pattern = Pattern.compile(regex, Pattern.UNICODE_CASE);
// }
// Matcher matcher = pattern.matcher(contents);
// while (matcher.find()) {
// if (matcher.groupCount() > 0) {
// for (int i = 1; i <= matcher.groupCount(); i++) {
// if (!isEmpty(matcher.group(i))) {
// results.add(matcher.group(i));
// }
// }
// } else {
// if (!isEmpty(matcher.group())) {
// results.add(matcher.group());
// }
// }
// }
// return results;
// }
//
// public static String getFirstFound(String contents, String regex,
// boolean isCaseInsensitive) {
// if (isEmpty(contents) || isEmpty(regex)) {
// return null;
// }
// List<String> found = getFound(contents, regex, isCaseInsensitive);
// if (found.size() > 0) {
// return (String) found.iterator().next();
// }
// return "";
// }
//
// public static Date setTime(Date date, String timeString) {
// Calendar cal1 = Calendar.getInstance();
// cal1.setTime(date);
//
// Calendar cal2 = Calendar.getInstance();
//
// String[] time = timeString.split(":");
//
// cal2.set(cal1.get(Calendar.YEAR),
// cal1.get(Calendar.MONTH),
// cal1.get(Calendar.DAY_OF_MONTH),
// Integer.parseInt(time[0]),
// Integer.parseInt(time[1]),
// Integer.parseInt(time[2]));
//
// return cal2.getTime();
// }
// }
// Path: core/src/main/java/com/ccoe/build/core/filter/FilterMatcher.java
import java.util.HashMap;
import java.util.regex.Pattern;
import com.ccoe.build.core.filter.model.Cause;
import com.ccoe.build.core.filter.model.Filter;
import com.ccoe.build.core.utils.StringUtils;
/*
Copyright [2013-2014] eBay Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.ccoe.build.core.filter;
public class FilterMatcher {
public boolean isMatch(HashMap<String, String> source, Filter filter) { | for (Cause cause : filter.getCause()) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.