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 |
|---|---|---|---|---|---|---|
berry-cs/big-data-cse | big-data-java/src/easy/data/xml/XMLInstantiator.java | // Path: big-data-java/src/easy/data/DataInstantiationException.java
// @SuppressWarnings("serial")
// public class DataInstantiationException extends RuntimeException {
// public DataInstantiationException(String message) {
// super(message);
// }
// }
//
// Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDFVisitor.java
// public interface IDFVisitor<T> {
// public T defaultVisit(IDataField df);
// public T visitPrimField(PrimField f, String basePath, String description);
// public T visitCompField(CompField f, String basePath, String description, HashMap<String, IDataField> fieldMap);
// public T visitListField(ListField f, String basePath, String description, String elemPath, IDataField elemField);
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
| import java.lang.reflect.*;
import java.util.*;
import easy.data.DataInstantiationException;
import easy.data.field.CompField;
import easy.data.field.IDFVisitor;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*; | package easy.data.xml;
/**
* Attempt to instantiate an object of the given signature
* using the structure of the xml data described by the field
* to which this visitor is applied
*
* @author Nadeem Abdul Hamid
*
*/
@SuppressWarnings("unchecked")
public class XMLInstantiator<T> implements IDFVisitor<T> {
private XML xml;
private ISig s;
public XMLInstantiator(XML xml, ISig s) {
this.xml = xml;
this.s = s;
}
public T defaultVisit(IDataField df) { | // Path: big-data-java/src/easy/data/DataInstantiationException.java
// @SuppressWarnings("serial")
// public class DataInstantiationException extends RuntimeException {
// public DataInstantiationException(String message) {
// super(message);
// }
// }
//
// Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDFVisitor.java
// public interface IDFVisitor<T> {
// public T defaultVisit(IDataField df);
// public T visitPrimField(PrimField f, String basePath, String description);
// public T visitCompField(CompField f, String basePath, String description, HashMap<String, IDataField> fieldMap);
// public T visitListField(ListField f, String basePath, String description, String elemPath, IDataField elemField);
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
// Path: big-data-java/src/easy/data/xml/XMLInstantiator.java
import java.lang.reflect.*;
import java.util.*;
import easy.data.DataInstantiationException;
import easy.data.field.CompField;
import easy.data.field.IDFVisitor;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
package easy.data.xml;
/**
* Attempt to instantiate an object of the given signature
* using the structure of the xml data described by the field
* to which this visitor is applied
*
* @author Nadeem Abdul Hamid
*
*/
@SuppressWarnings("unchecked")
public class XMLInstantiator<T> implements IDFVisitor<T> {
private XML xml;
private ISig s;
public XMLInstantiator(XML xml, ISig s) {
this.xml = xml;
this.s = s;
}
public T defaultVisit(IDataField df) { | throw new DataInstantiationException("Unable to instantiate data field " + df); |
berry-cs/big-data-cse | big-data-java/src/easy/data/xml/XMLInstantiator.java | // Path: big-data-java/src/easy/data/DataInstantiationException.java
// @SuppressWarnings("serial")
// public class DataInstantiationException extends RuntimeException {
// public DataInstantiationException(String message) {
// super(message);
// }
// }
//
// Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDFVisitor.java
// public interface IDFVisitor<T> {
// public T defaultVisit(IDataField df);
// public T visitPrimField(PrimField f, String basePath, String description);
// public T visitCompField(CompField f, String basePath, String description, HashMap<String, IDataField> fieldMap);
// public T visitListField(ListField f, String basePath, String description, String elemPath, IDataField elemField);
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
| import java.lang.reflect.*;
import java.util.*;
import easy.data.DataInstantiationException;
import easy.data.field.CompField;
import easy.data.field.IDFVisitor;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*; | package easy.data.xml;
/**
* Attempt to instantiate an object of the given signature
* using the structure of the xml data described by the field
* to which this visitor is applied
*
* @author Nadeem Abdul Hamid
*
*/
@SuppressWarnings("unchecked")
public class XMLInstantiator<T> implements IDFVisitor<T> {
private XML xml;
private ISig s;
public XMLInstantiator(XML xml, ISig s) {
this.xml = xml;
this.s = s;
}
public T defaultVisit(IDataField df) {
throw new DataInstantiationException("Unable to instantiate data field " + df);
}
| // Path: big-data-java/src/easy/data/DataInstantiationException.java
// @SuppressWarnings("serial")
// public class DataInstantiationException extends RuntimeException {
// public DataInstantiationException(String message) {
// super(message);
// }
// }
//
// Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDFVisitor.java
// public interface IDFVisitor<T> {
// public T defaultVisit(IDataField df);
// public T visitPrimField(PrimField f, String basePath, String description);
// public T visitCompField(CompField f, String basePath, String description, HashMap<String, IDataField> fieldMap);
// public T visitListField(ListField f, String basePath, String description, String elemPath, IDataField elemField);
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
// Path: big-data-java/src/easy/data/xml/XMLInstantiator.java
import java.lang.reflect.*;
import java.util.*;
import easy.data.DataInstantiationException;
import easy.data.field.CompField;
import easy.data.field.IDFVisitor;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
package easy.data.xml;
/**
* Attempt to instantiate an object of the given signature
* using the structure of the xml data described by the field
* to which this visitor is applied
*
* @author Nadeem Abdul Hamid
*
*/
@SuppressWarnings("unchecked")
public class XMLInstantiator<T> implements IDFVisitor<T> {
private XML xml;
private ISig s;
public XMLInstantiator(XML xml, ISig s) {
this.xml = xml;
this.s = s;
}
public T defaultVisit(IDataField df) {
throw new DataInstantiationException("Unable to instantiate data field " + df);
}
| public T visitPrimField(final PrimField f, String basePath, String description) { |
berry-cs/big-data-cse | big-data-java/src/easy/data/xml/XMLInstantiator.java | // Path: big-data-java/src/easy/data/DataInstantiationException.java
// @SuppressWarnings("serial")
// public class DataInstantiationException extends RuntimeException {
// public DataInstantiationException(String message) {
// super(message);
// }
// }
//
// Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDFVisitor.java
// public interface IDFVisitor<T> {
// public T defaultVisit(IDataField df);
// public T visitPrimField(PrimField f, String basePath, String description);
// public T visitCompField(CompField f, String basePath, String description, HashMap<String, IDataField> fieldMap);
// public T visitListField(ListField f, String basePath, String description, String elemPath, IDataField elemField);
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
| import java.lang.reflect.*;
import java.util.*;
import easy.data.DataInstantiationException;
import easy.data.field.CompField;
import easy.data.field.IDFVisitor;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*; | } catch (InvocationTargetException e) {
e.printStackTrace();
}
}
return (T) lst;
} else { */
String[] sigflds = new String[cs.getFieldCount()];
for (int i = 0; i < sigflds.length; i++) {
sigflds[i] = cs.getFieldName(i);
}
String commonPrefix = longestCommonPrefix(sigflds);
if (commonPrefix == null) commonPrefix = "";
//System.out.println("prefix: " + commonPrefix);
int prefixLength = commonPrefix.length();
if (commonPrefix.endsWith("/"))
commonPrefix = commonPrefix.substring(0, prefixLength-1);
if (f.hasField(commonPrefix)) {
@SuppressWarnings("rawtypes")
CompSig<?> newsig = new CompSig(cs.getAssociatedClass());
for (int i = 0; i < sigflds.length; i++) {
String oldname = sigflds[i];
String newname = oldname.substring(prefixLength);
newsig.addField(cs.getFieldSig(i), newname);
}
IDataField fsubfld = f.getField(commonPrefix);
XML fbasexml = basexml; | // Path: big-data-java/src/easy/data/DataInstantiationException.java
// @SuppressWarnings("serial")
// public class DataInstantiationException extends RuntimeException {
// public DataInstantiationException(String message) {
// super(message);
// }
// }
//
// Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDFVisitor.java
// public interface IDFVisitor<T> {
// public T defaultVisit(IDataField df);
// public T visitPrimField(PrimField f, String basePath, String description);
// public T visitCompField(CompField f, String basePath, String description, HashMap<String, IDataField> fieldMap);
// public T visitListField(ListField f, String basePath, String description, String elemPath, IDataField elemField);
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
// Path: big-data-java/src/easy/data/xml/XMLInstantiator.java
import java.lang.reflect.*;
import java.util.*;
import easy.data.DataInstantiationException;
import easy.data.field.CompField;
import easy.data.field.IDFVisitor;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
return (T) lst;
} else { */
String[] sigflds = new String[cs.getFieldCount()];
for (int i = 0; i < sigflds.length; i++) {
sigflds[i] = cs.getFieldName(i);
}
String commonPrefix = longestCommonPrefix(sigflds);
if (commonPrefix == null) commonPrefix = "";
//System.out.println("prefix: " + commonPrefix);
int prefixLength = commonPrefix.length();
if (commonPrefix.endsWith("/"))
commonPrefix = commonPrefix.substring(0, prefixLength-1);
if (f.hasField(commonPrefix)) {
@SuppressWarnings("rawtypes")
CompSig<?> newsig = new CompSig(cs.getAssociatedClass());
for (int i = 0; i < sigflds.length; i++) {
String oldname = sigflds[i];
String newname = oldname.substring(prefixLength);
newsig.addField(cs.getFieldSig(i), newname);
}
IDataField fsubfld = f.getField(commonPrefix);
XML fbasexml = basexml; | if (!(fsubfld instanceof ListField)) { // only one element of the spec field in the data source |
berry-cs/big-data-cse | big-data-java/src/easy/data/tests/XMLInstantiatorTest.java | // Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
| import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import easy.data.field.CompField;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
import easy.data.xml.*;
import java.util.*; | package easy.data.tests;
public class XMLInstantiatorTest {
XML xml1; | // Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
// Path: big-data-java/src/easy/data/tests/XMLInstantiatorTest.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import easy.data.field.CompField;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
import easy.data.xml.*;
import java.util.*;
package easy.data.tests;
public class XMLInstantiatorTest {
XML xml1; | PrimField pf1; |
berry-cs/big-data-cse | big-data-java/src/easy/data/tests/XMLInstantiatorTest.java | // Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
| import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import easy.data.field.CompField;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
import easy.data.xml.*;
import java.util.*; | package easy.data.tests;
public class XMLInstantiatorTest {
XML xml1;
PrimField pf1;
PrimField pf2;
PrimField pf3;
PrimField pf4; | // Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
// Path: big-data-java/src/easy/data/tests/XMLInstantiatorTest.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import easy.data.field.CompField;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
import easy.data.xml.*;
import java.util.*;
package easy.data.tests;
public class XMLInstantiatorTest {
XML xml1;
PrimField pf1;
PrimField pf2;
PrimField pf3;
PrimField pf4; | CompField cf1; |
berry-cs/big-data-cse | big-data-java/src/easy/data/tests/XMLInstantiatorTest.java | // Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
| import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import easy.data.field.CompField;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
import easy.data.xml.*;
import java.util.*; | package easy.data.tests;
public class XMLInstantiatorTest {
XML xml1;
PrimField pf1;
PrimField pf2;
PrimField pf3;
PrimField pf4;
CompField cf1;
CompField cf2; | // Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
// Path: big-data-java/src/easy/data/tests/XMLInstantiatorTest.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import easy.data.field.CompField;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
import easy.data.xml.*;
import java.util.*;
package easy.data.tests;
public class XMLInstantiatorTest {
XML xml1;
PrimField pf1;
PrimField pf2;
PrimField pf3;
PrimField pf4;
CompField cf1;
CompField cf2; | ListField lf1; |
berry-cs/big-data-cse | big-data-java/src/easy/data/tests/XMLInstantiatorTest.java | // Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
| import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import easy.data.field.CompField;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
import easy.data.xml.*;
import java.util.*; | public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
xml1 = IOUtil.loadXML("src/big/data/tests/dsspec1.xml");
pf1 = new PrimField("name", "option name");
pf2 = new PrimField("value", "option setting");
pf3 = new PrimField(null);
pf4 = new PrimField("dataspec/compfield/fields/field/name");
cf1 = new CompField(null, "an option setting pair");
cf2 = new CompField("options/option", "an option setting pair");
lf1 = new ListField("options", "option", cf1, "list of option settings");
lf2 = new ListField("blah", "blup", pf3, "messed up");
lf3 = new ListField(null, "dataspec/compfield/fields/field/name", pf3, "top level field names");
cf1.addField("value", pf2);
cf1.addField("name", pf1);
cf2.addField("value", pf2);
cf2.addField("name", pf1);
cspair = new CompSig<Pair>(Pair.class);
cspair.addField(PrimSig.STRING_SIG, "name");
cspair.addField(PrimSig.STRING_SIG, "value");
}
@After
public void tearDown() throws Exception {
}
| // Path: big-data-java/src/easy/data/field/CompField.java
// public class CompField extends ADataField implements IDataField {
// private HashMap<String, IDataField> fieldMap;
//
// public CompField() {
// this(null);
// }
//
// public CompField(String basePath) {
// this(basePath, null);
// }
//
// public CompField(String basePath, String description) {
// super(basePath, description);
// this.fieldMap = new HashMap<String, IDataField>();
// }
//
// public IDataField addField(String name, IDataField fld) {
// return fieldMap.put(name, fld);
// }
//
// public String[] fieldNames() {
// return fieldMap.keySet().toArray(new String[] {});
// }
//
// public Collection<IDataField> fields() {
// return fieldMap.values();
// }
//
// public IDataField getField(String name) {
// return fieldMap.get(name);
// }
//
// public boolean hasField(String name) {
// return fieldMap.containsKey(name);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitCompField(this, this.basePath, this.description, this.fieldMap);
// }
//
// public String toString() {
// String m = "{_<" + basePath + "> ";
// boolean firstDone = false;
// for (String k : fieldNames()) {
// if (firstDone) { m += ", "; } else { firstDone = true; }
// m += (k + ": " + fieldMap.get(k));
// }
// m += "}";
// return m;
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
//
// Path: big-data-java/src/easy/data/field/ListField.java
// public class ListField extends ADataField implements IDataField {
// private String elemPath;
// private IDataField elemField;
//
// public ListField(String basepath, String elempath, IDataField basefld) {
// this(basepath, elempath, basefld, null);
// }
//
// public ListField(String basepath, String elemPath, IDataField elemField, String description) {
// super(basepath, description);
// this.elemPath = elemPath;
// this.elemField = elemField;
// }
//
// public String getElemPath() {
// return this.elemPath;
// }
//
// public IDataField getElemField() {
// return this.elemField;
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitListField(this, this.basePath, this.description, this.elemPath, this.elemField);
// }
//
// public String toString() {
// return "[_<" + basePath + "," + elemPath + "> " + elemField + "]";
// }
//
// }
//
// Path: big-data-java/src/easy/data/field/PrimField.java
// public class PrimField extends ADataField implements IDataField {
// public PrimField() {
// super(null, null);
// }
//
// public PrimField(String path) {
// super(path, null);
// }
//
// public PrimField(String path, String description) {
// super(path, description);
// }
//
// public <T> T apply(IDFVisitor<T> fv) {
// return fv.visitPrimField(this, this.basePath, this.description);
// }
//
// public String toString() {
// return "<" + basePath + ">";
// }
// }
// Path: big-data-java/src/easy/data/tests/XMLInstantiatorTest.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import easy.data.field.CompField;
import easy.data.field.IDataField;
import easy.data.field.ListField;
import easy.data.field.PrimField;
import easy.data.sig.*;
import easy.data.util.*;
import easy.data.xml.*;
import java.util.*;
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
xml1 = IOUtil.loadXML("src/big/data/tests/dsspec1.xml");
pf1 = new PrimField("name", "option name");
pf2 = new PrimField("value", "option setting");
pf3 = new PrimField(null);
pf4 = new PrimField("dataspec/compfield/fields/field/name");
cf1 = new CompField(null, "an option setting pair");
cf2 = new CompField("options/option", "an option setting pair");
lf1 = new ListField("options", "option", cf1, "list of option settings");
lf2 = new ListField("blah", "blup", pf3, "messed up");
lf3 = new ListField(null, "dataspec/compfield/fields/field/name", pf3, "top level field names");
cf1.addField("value", pf2);
cf1.addField("name", pf1);
cf2.addField("value", pf2);
cf2.addField("name", pf1);
cspair = new CompSig<Pair>(Pair.class);
cspair.addField(PrimSig.STRING_SIG, "name");
cspair.addField(PrimSig.STRING_SIG, "value");
}
@After
public void tearDown() throws Exception {
}
| private static <T> T instantiate(IDataField f, XML xml, ISig s) { |
berry-cs/big-data-cse | big-data-java/src/easy/data/IDataSource.java | // Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
| import java.util.ArrayList;
import java.util.List;
import easy.data.field.IDataField; | package easy.data;
/**
* Represents a data source
*
* @author Nadeem Abdul Hamid
*
*/
public interface IDataSource {
/**
* Produce the name of this data source
* @return the name of this data source
*/
public String getName();
/**
* Produce a description of this data source
* @return a description of this data source
*/
public String getDescription();
/**
* Produce a URL to more information about this data source
* @return a URL to more information about this data source
*/
public String getInfoURL();
/**
* Determines whether all required parameters have been supplied for this data source
* @return whether all required parameters have been supplied for this data source
*/
public boolean readyToLoad();
/**
* Produces a list of keys of required parameters that have not
* been supplied yet
* @return a list of parameter keys
*/
public List<String> missingParams();
/**
* Determines whether data has been successfully loaded and parsed from the data source
* @return whether data has been successfully loaded and parsed from the data source
*/
public boolean hasData();
/**
* Determines whether data has been successfully loaded and parsed from the data source
* (i.e. it calls hasData()),
* and whether data elements with the given keys (field labels) are available
* in this data source.
*/
public boolean hasFields(String... keys);
/**
* Registers a request parameter with this data source
* @param param the parameter specification
* @return this updated data source
*/
public IDataSource addParam(IParam param);
/**
* Sets a value for a parameter (either query or path)
* @param op key for the parameter
* @param val value for the parameter
* @return this updated data source
*/
public IDataSource set(String op, String val);
/**
* Sets the cache timeout value, in <em>minutes</em>. This should be called before load() to have effect.
*/
public IDataSource setCacheTimeout(int val);
public IDataSource setCacheDirectory(String path);
/**
* Sets an internal option for the data source
* @return this updated data source
*/
public IDataSource setOption(String op, String val);
/**
* Sets the data structure specification for extracting
* data from this source
*/ | // Path: big-data-java/src/easy/data/field/IDataField.java
// public interface IDataField {
// public String getDescription();
// public <T> T apply(IDFVisitor<T> fv);
// }
// Path: big-data-java/src/easy/data/IDataSource.java
import java.util.ArrayList;
import java.util.List;
import easy.data.field.IDataField;
package easy.data;
/**
* Represents a data source
*
* @author Nadeem Abdul Hamid
*
*/
public interface IDataSource {
/**
* Produce the name of this data source
* @return the name of this data source
*/
public String getName();
/**
* Produce a description of this data source
* @return a description of this data source
*/
public String getDescription();
/**
* Produce a URL to more information about this data source
* @return a URL to more information about this data source
*/
public String getInfoURL();
/**
* Determines whether all required parameters have been supplied for this data source
* @return whether all required parameters have been supplied for this data source
*/
public boolean readyToLoad();
/**
* Produces a list of keys of required parameters that have not
* been supplied yet
* @return a list of parameter keys
*/
public List<String> missingParams();
/**
* Determines whether data has been successfully loaded and parsed from the data source
* @return whether data has been successfully loaded and parsed from the data source
*/
public boolean hasData();
/**
* Determines whether data has been successfully loaded and parsed from the data source
* (i.e. it calls hasData()),
* and whether data elements with the given keys (field labels) are available
* in this data source.
*/
public boolean hasFields(String... keys);
/**
* Registers a request parameter with this data source
* @param param the parameter specification
* @return this updated data source
*/
public IDataSource addParam(IParam param);
/**
* Sets a value for a parameter (either query or path)
* @param op key for the parameter
* @param val value for the parameter
* @return this updated data source
*/
public IDataSource set(String op, String val);
/**
* Sets the cache timeout value, in <em>minutes</em>. This should be called before load() to have effect.
*/
public IDataSource setCacheTimeout(int val);
public IDataSource setCacheDirectory(String path);
/**
* Sets an internal option for the data source
* @return this updated data source
*/
public IDataSource setOption(String op, String val);
/**
* Sets the data structure specification for extracting
* data from this source
*/ | public IDataSource setFieldSpec(IDataField spec); |
sonatype/nexus-perf | src/main/java/com/sonatype/nexus/perftest/maven/BatchDownloadsOperation.java | // Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
// public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
//
// protected final String username;
//
// protected final String password;
//
// protected final String nexusBaseurl;
//
// public AbstractNexusOperation(Nexus nexus) {
// this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
// this.username = nexus.getUsername();
// this.password = nexus.getPassword();
// }
//
// private static String sanitizeBaseurl(String nexusBaseurl) {
// if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
// return null;
// }
// nexusBaseurl = nexusBaseurl.trim();
// return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
// }
//
// protected DefaultHttpClient getHttpClient() {
// ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
//
// DefaultHttpClient httpclient = info.getContextValue("httpclient");
// if (httpclient == null) {
// HttpParams params = new BasicHttpParams();
// HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
// HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
// httpclient = new DefaultHttpClient(params);
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
// new UsernamePasswordCredentials(username, password));
// info.setContextValue("httpclient", httpclient);
// }
// return httpclient;
// }
//
// protected boolean isSuccess(HttpResponse response) {
// return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
// }
//
// @SuppressWarnings("unchecked")
// protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
// if (nexusBaseurl == null) {
// throw new IllegalStateException();
// }
// BaseUrl baseUrl;
// try {
// baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
// }
// catch (MalformedURLException e) {
// throw new RuntimeException(e);
// }
// AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
// ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
// return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
// }
//
// @SuppressWarnings("rawtypes")
// protected JerseyRepositoriesFactory newRepositoryFactories() {
// Set<RepositoryFactory> repositoryFactories = new HashSet<>();
// repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
// repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
// repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
// return new JerseyRepositoriesFactory(repositoryFactories);
// }
//
// @SuppressWarnings("unchecked")
// protected String getRepoBaseurl(String repoid) {
// final String layout = System.getProperty("nexus.layout", "NX3");
// switch (layout) {
// case "NX2":
// return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
// case "NX3":
// return this.nexusBaseurl + "repository/" + repoid;
// default:
// throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
// }
// }
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
// public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
// private final String baseurl;
//
// private final String username;
//
// private final String password;
//
// public Nexus() {
// this.baseurl = System.getProperty("nexus.baseurl");
// this.username = System.getProperty("nexus.username");
// this.password = System.getProperty("nexus.password");
// }
//
// @JsonCreator
// public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
// @JsonProperty("password") String password) {
// this.baseurl = baseurl;
// this.username = username;
// this.password = password;
// }
//
// public String getBaseurl() {
// return baseurl;
// }
//
// public String getUsername() {
// return username;
// }
//
// public String getPassword() {
// return password;
// }
// }
| import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.http.impl.client.DefaultHttpClient; | /*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.maven;
/**
* Simulates repository requests performed during a maven build. List of artifacts requested by the build comes from
* httpd/jetty access log file
*/
public class BatchDownloadsOperation extends AbstractNexusOperation implements Operation {
private final String repoBaseurl;
private final DownloadPaths paths;
@JsonCreator | // Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
// public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
//
// protected final String username;
//
// protected final String password;
//
// protected final String nexusBaseurl;
//
// public AbstractNexusOperation(Nexus nexus) {
// this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
// this.username = nexus.getUsername();
// this.password = nexus.getPassword();
// }
//
// private static String sanitizeBaseurl(String nexusBaseurl) {
// if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
// return null;
// }
// nexusBaseurl = nexusBaseurl.trim();
// return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
// }
//
// protected DefaultHttpClient getHttpClient() {
// ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
//
// DefaultHttpClient httpclient = info.getContextValue("httpclient");
// if (httpclient == null) {
// HttpParams params = new BasicHttpParams();
// HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
// HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
// httpclient = new DefaultHttpClient(params);
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
// new UsernamePasswordCredentials(username, password));
// info.setContextValue("httpclient", httpclient);
// }
// return httpclient;
// }
//
// protected boolean isSuccess(HttpResponse response) {
// return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
// }
//
// @SuppressWarnings("unchecked")
// protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
// if (nexusBaseurl == null) {
// throw new IllegalStateException();
// }
// BaseUrl baseUrl;
// try {
// baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
// }
// catch (MalformedURLException e) {
// throw new RuntimeException(e);
// }
// AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
// ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
// return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
// }
//
// @SuppressWarnings("rawtypes")
// protected JerseyRepositoriesFactory newRepositoryFactories() {
// Set<RepositoryFactory> repositoryFactories = new HashSet<>();
// repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
// repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
// repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
// return new JerseyRepositoriesFactory(repositoryFactories);
// }
//
// @SuppressWarnings("unchecked")
// protected String getRepoBaseurl(String repoid) {
// final String layout = System.getProperty("nexus.layout", "NX3");
// switch (layout) {
// case "NX2":
// return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
// case "NX3":
// return this.nexusBaseurl + "repository/" + repoid;
// default:
// throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
// }
// }
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
// public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
// private final String baseurl;
//
// private final String username;
//
// private final String password;
//
// public Nexus() {
// this.baseurl = System.getProperty("nexus.baseurl");
// this.username = System.getProperty("nexus.username");
// this.password = System.getProperty("nexus.password");
// }
//
// @JsonCreator
// public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
// @JsonProperty("password") String password) {
// this.baseurl = baseurl;
// this.username = username;
// this.password = password;
// }
//
// public String getBaseurl() {
// return baseurl;
// }
//
// public String getUsername() {
// return username;
// }
//
// public String getPassword() {
// return password;
// }
// }
// Path: src/main/java/com/sonatype/nexus/perftest/maven/BatchDownloadsOperation.java
import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.http.impl.client.DefaultHttpClient;
/*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.maven;
/**
* Simulates repository requests performed during a maven build. List of artifacts requested by the build comes from
* httpd/jetty access log file
*/
public class BatchDownloadsOperation extends AbstractNexusOperation implements Operation {
private final String repoBaseurl;
private final DownloadPaths paths;
@JsonCreator | public BatchDownloadsOperation(@JacksonInject Nexus nexus, @JsonProperty("repo") String repo, |
sonatype/nexus-perf | src/main/java/com/sonatype/nexus/perftest/maven/DownloadOperation.java | // Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
// public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
//
// protected final String username;
//
// protected final String password;
//
// protected final String nexusBaseurl;
//
// public AbstractNexusOperation(Nexus nexus) {
// this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
// this.username = nexus.getUsername();
// this.password = nexus.getPassword();
// }
//
// private static String sanitizeBaseurl(String nexusBaseurl) {
// if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
// return null;
// }
// nexusBaseurl = nexusBaseurl.trim();
// return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
// }
//
// protected DefaultHttpClient getHttpClient() {
// ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
//
// DefaultHttpClient httpclient = info.getContextValue("httpclient");
// if (httpclient == null) {
// HttpParams params = new BasicHttpParams();
// HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
// HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
// httpclient = new DefaultHttpClient(params);
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
// new UsernamePasswordCredentials(username, password));
// info.setContextValue("httpclient", httpclient);
// }
// return httpclient;
// }
//
// protected boolean isSuccess(HttpResponse response) {
// return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
// }
//
// @SuppressWarnings("unchecked")
// protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
// if (nexusBaseurl == null) {
// throw new IllegalStateException();
// }
// BaseUrl baseUrl;
// try {
// baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
// }
// catch (MalformedURLException e) {
// throw new RuntimeException(e);
// }
// AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
// ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
// return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
// }
//
// @SuppressWarnings("rawtypes")
// protected JerseyRepositoriesFactory newRepositoryFactories() {
// Set<RepositoryFactory> repositoryFactories = new HashSet<>();
// repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
// repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
// repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
// return new JerseyRepositoriesFactory(repositoryFactories);
// }
//
// @SuppressWarnings("unchecked")
// protected String getRepoBaseurl(String repoid) {
// final String layout = System.getProperty("nexus.layout", "NX3");
// switch (layout) {
// case "NX2":
// return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
// case "NX3":
// return this.nexusBaseurl + "repository/" + repoid;
// default:
// throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
// }
// }
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
// public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
// private final String baseurl;
//
// private final String username;
//
// private final String password;
//
// public Nexus() {
// this.baseurl = System.getProperty("nexus.baseurl");
// this.username = System.getProperty("nexus.username");
// this.password = System.getProperty("nexus.password");
// }
//
// @JsonCreator
// public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
// @JsonProperty("password") String password) {
// this.baseurl = baseurl;
// this.username = username;
// this.password = password;
// }
//
// public String getBaseurl() {
// return baseurl;
// }
//
// public String getUsername() {
// return username;
// }
//
// public String getPassword() {
// return password;
// }
// }
| import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonProperty; | /*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.maven;
/**
* Downloads series of artifacts from a maven2 repository.
*/
public class DownloadOperation extends AbstractNexusOperation implements Operation {
private final String repoBaseurl;
private final DownloadPaths paths;
| // Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
// public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
//
// protected final String username;
//
// protected final String password;
//
// protected final String nexusBaseurl;
//
// public AbstractNexusOperation(Nexus nexus) {
// this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
// this.username = nexus.getUsername();
// this.password = nexus.getPassword();
// }
//
// private static String sanitizeBaseurl(String nexusBaseurl) {
// if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
// return null;
// }
// nexusBaseurl = nexusBaseurl.trim();
// return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
// }
//
// protected DefaultHttpClient getHttpClient() {
// ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
//
// DefaultHttpClient httpclient = info.getContextValue("httpclient");
// if (httpclient == null) {
// HttpParams params = new BasicHttpParams();
// HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
// HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
// httpclient = new DefaultHttpClient(params);
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
// new UsernamePasswordCredentials(username, password));
// info.setContextValue("httpclient", httpclient);
// }
// return httpclient;
// }
//
// protected boolean isSuccess(HttpResponse response) {
// return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
// }
//
// @SuppressWarnings("unchecked")
// protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
// if (nexusBaseurl == null) {
// throw new IllegalStateException();
// }
// BaseUrl baseUrl;
// try {
// baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
// }
// catch (MalformedURLException e) {
// throw new RuntimeException(e);
// }
// AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
// ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
// return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
// }
//
// @SuppressWarnings("rawtypes")
// protected JerseyRepositoriesFactory newRepositoryFactories() {
// Set<RepositoryFactory> repositoryFactories = new HashSet<>();
// repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
// repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
// repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
// return new JerseyRepositoriesFactory(repositoryFactories);
// }
//
// @SuppressWarnings("unchecked")
// protected String getRepoBaseurl(String repoid) {
// final String layout = System.getProperty("nexus.layout", "NX3");
// switch (layout) {
// case "NX2":
// return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
// case "NX3":
// return this.nexusBaseurl + "repository/" + repoid;
// default:
// throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
// }
// }
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
// public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
// private final String baseurl;
//
// private final String username;
//
// private final String password;
//
// public Nexus() {
// this.baseurl = System.getProperty("nexus.baseurl");
// this.username = System.getProperty("nexus.username");
// this.password = System.getProperty("nexus.password");
// }
//
// @JsonCreator
// public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
// @JsonProperty("password") String password) {
// this.baseurl = baseurl;
// this.username = username;
// this.password = password;
// }
//
// public String getBaseurl() {
// return baseurl;
// }
//
// public String getUsername() {
// return username;
// }
//
// public String getPassword() {
// return password;
// }
// }
// Path: src/main/java/com/sonatype/nexus/perftest/maven/DownloadOperation.java
import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonProperty;
/*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.maven;
/**
* Downloads series of artifacts from a maven2 repository.
*/
public class DownloadOperation extends AbstractNexusOperation implements Operation {
private final String repoBaseurl;
private final DownloadPaths paths;
| public DownloadOperation(@JacksonInject Nexus nexus, @JsonProperty("repo") String repoid, |
sonatype/nexus-perf | src/main/java/com/sonatype/nexus/perftest/maven/DownloadOperation.java | // Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
// public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
//
// protected final String username;
//
// protected final String password;
//
// protected final String nexusBaseurl;
//
// public AbstractNexusOperation(Nexus nexus) {
// this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
// this.username = nexus.getUsername();
// this.password = nexus.getPassword();
// }
//
// private static String sanitizeBaseurl(String nexusBaseurl) {
// if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
// return null;
// }
// nexusBaseurl = nexusBaseurl.trim();
// return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
// }
//
// protected DefaultHttpClient getHttpClient() {
// ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
//
// DefaultHttpClient httpclient = info.getContextValue("httpclient");
// if (httpclient == null) {
// HttpParams params = new BasicHttpParams();
// HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
// HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
// httpclient = new DefaultHttpClient(params);
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
// new UsernamePasswordCredentials(username, password));
// info.setContextValue("httpclient", httpclient);
// }
// return httpclient;
// }
//
// protected boolean isSuccess(HttpResponse response) {
// return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
// }
//
// @SuppressWarnings("unchecked")
// protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
// if (nexusBaseurl == null) {
// throw new IllegalStateException();
// }
// BaseUrl baseUrl;
// try {
// baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
// }
// catch (MalformedURLException e) {
// throw new RuntimeException(e);
// }
// AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
// ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
// return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
// }
//
// @SuppressWarnings("rawtypes")
// protected JerseyRepositoriesFactory newRepositoryFactories() {
// Set<RepositoryFactory> repositoryFactories = new HashSet<>();
// repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
// repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
// repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
// return new JerseyRepositoriesFactory(repositoryFactories);
// }
//
// @SuppressWarnings("unchecked")
// protected String getRepoBaseurl(String repoid) {
// final String layout = System.getProperty("nexus.layout", "NX3");
// switch (layout) {
// case "NX2":
// return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
// case "NX3":
// return this.nexusBaseurl + "repository/" + repoid;
// default:
// throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
// }
// }
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
// public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
// private final String baseurl;
//
// private final String username;
//
// private final String password;
//
// public Nexus() {
// this.baseurl = System.getProperty("nexus.baseurl");
// this.username = System.getProperty("nexus.username");
// this.password = System.getProperty("nexus.password");
// }
//
// @JsonCreator
// public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
// @JsonProperty("password") String password) {
// this.baseurl = baseurl;
// this.username = username;
// this.password = password;
// }
//
// public String getBaseurl() {
// return baseurl;
// }
//
// public String getUsername() {
// return username;
// }
//
// public String getPassword() {
// return password;
// }
// }
| import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonProperty; | /*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.maven;
/**
* Downloads series of artifacts from a maven2 repository.
*/
public class DownloadOperation extends AbstractNexusOperation implements Operation {
private final String repoBaseurl;
private final DownloadPaths paths;
public DownloadOperation(@JacksonInject Nexus nexus, @JsonProperty("repo") String repoid,
@JsonProperty("paths") DownloadPaths paths ) {
super(nexus);
this.repoBaseurl = getRepoBaseurl(repoid);
this.paths = paths;
}
@Override | // Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
// public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
//
// protected final String username;
//
// protected final String password;
//
// protected final String nexusBaseurl;
//
// public AbstractNexusOperation(Nexus nexus) {
// this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
// this.username = nexus.getUsername();
// this.password = nexus.getPassword();
// }
//
// private static String sanitizeBaseurl(String nexusBaseurl) {
// if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
// return null;
// }
// nexusBaseurl = nexusBaseurl.trim();
// return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
// }
//
// protected DefaultHttpClient getHttpClient() {
// ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
//
// DefaultHttpClient httpclient = info.getContextValue("httpclient");
// if (httpclient == null) {
// HttpParams params = new BasicHttpParams();
// HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
// HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
// httpclient = new DefaultHttpClient(params);
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
// new UsernamePasswordCredentials(username, password));
// info.setContextValue("httpclient", httpclient);
// }
// return httpclient;
// }
//
// protected boolean isSuccess(HttpResponse response) {
// return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
// }
//
// @SuppressWarnings("unchecked")
// protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
// if (nexusBaseurl == null) {
// throw new IllegalStateException();
// }
// BaseUrl baseUrl;
// try {
// baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
// }
// catch (MalformedURLException e) {
// throw new RuntimeException(e);
// }
// AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
// ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
// return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
// }
//
// @SuppressWarnings("rawtypes")
// protected JerseyRepositoriesFactory newRepositoryFactories() {
// Set<RepositoryFactory> repositoryFactories = new HashSet<>();
// repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
// repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
// repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
// return new JerseyRepositoriesFactory(repositoryFactories);
// }
//
// @SuppressWarnings("unchecked")
// protected String getRepoBaseurl(String repoid) {
// final String layout = System.getProperty("nexus.layout", "NX3");
// switch (layout) {
// case "NX2":
// return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
// case "NX3":
// return this.nexusBaseurl + "repository/" + repoid;
// default:
// throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
// }
// }
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
// public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
// private final String baseurl;
//
// private final String username;
//
// private final String password;
//
// public Nexus() {
// this.baseurl = System.getProperty("nexus.baseurl");
// this.username = System.getProperty("nexus.username");
// this.password = System.getProperty("nexus.password");
// }
//
// @JsonCreator
// public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
// @JsonProperty("password") String password) {
// this.baseurl = baseurl;
// this.username = username;
// this.password = password;
// }
//
// public String getBaseurl() {
// return baseurl;
// }
//
// public String getUsername() {
// return username;
// }
//
// public String getPassword() {
// return password;
// }
// }
// Path: src/main/java/com/sonatype/nexus/perftest/maven/DownloadOperation.java
import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonProperty;
/*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.maven;
/**
* Downloads series of artifacts from a maven2 repository.
*/
public class DownloadOperation extends AbstractNexusOperation implements Operation {
private final String repoBaseurl;
private final DownloadPaths paths;
public DownloadOperation(@JacksonInject Nexus nexus, @JsonProperty("repo") String repoid,
@JsonProperty("paths") DownloadPaths paths ) {
super(nexus);
this.repoBaseurl = getRepoBaseurl(repoid);
this.paths = paths;
}
@Override | public void perform(ClientRequestInfo requestInfo) throws Exception { |
sonatype/nexus-perf | src/main/java/com/sonatype/nexus/perftest/PerformanceTest.java | // Path: src/main/java/com/sonatype/nexus/perftest/db/TestExecutions.java
// public class TestExecutions {
//
// static {
// try {
// Class.forName("org.h2.Driver");
// } catch (ClassNotFoundException e) {
// // this is going to be fun to debug
// throw new LinkageError("Could not load required class", e);
// }
// }
//
// private static void createTables(Connection conn) throws SQLException {
// try (Statement statement = conn.createStatement()) {
// statement.executeUpdate("CREATE TABLE IF NOT EXISTS executions (" //
// + " test_id VARCHAR(255)," //
// + " execution_id VARCHAR(255)," //
// + " metric_id VARCHAR(255)," //
// + " value DOUBLE," //
// + " PRIMARY KEY(test_id, execution_id, metric_id)" //
// + ")");
// }
// }
//
// private static boolean delete(Connection conn, TestExecution execution) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("DELETE FROM executions WHERE test_id = ? AND execution_id = ?")) {
// statement.setString(1, execution.getTestId());
// statement.setString(2, execution.getExecutionId());
// return statement.executeUpdate() > 0;
// }
// }
//
// private static void insert(Connection conn, TestExecution execution) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("INSERT INTO executions (test_id, execution_id, metric_id, value) VALUES (?, ?, ?, ?)")) {
// for (String metricId : execution.getMetricIds()) {
// statement.setString(1, execution.getTestId());
// statement.setString(2, execution.getExecutionId());
// statement.setString(3, metricId);
// statement.setDouble(4, execution.getMetric(metricId));
// statement.executeUpdate();
// }
// }
// }
//
// private static TestExecution select(Connection conn, String testId, String executionId) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("SELECT metric_id, value FROM executions WHERE test_id = ? AND execution_id = ?")) {
// statement.setString(1, testId);
// statement.setString(2, executionId);
// try (ResultSet resultSet = statement.executeQuery()) {
// TestExecution execution = new TestExecution(testId, executionId);
// while (resultSet.next()) {
// execution.addMetric(resultSet.getString(1), resultSet.getDouble(2));
// }
// return execution.getMetricIds().isEmpty() ? null : execution;
// }
// }
// }
//
// public static void main(String[] args) throws Exception {
// TestExecution execution = new TestExecution("test", "execution");
// execution.addMetric("foo", 123.45);
// try (Connection conn = getConnection()) {
// createTables(conn);
// System.err.println(delete(conn, execution));
// insert(conn, execution);
//
// select(conn, execution.getTestId(), execution.getExecutionId());
//
// System.err.println(delete(conn, execution));
// }
// }
//
// private static Connection getConnection() throws SQLException {
// Connection conn = DriverManager.getConnection("jdbc:h2:~/nexusperftest");
// createTables(conn);
// return conn;
// }
//
// public static void assertUnique(String testId, String executionId) {
// try (Connection conn = getConnection()) {
// Assert.assertNull(select(conn, testId, executionId));
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static TestExecution select(String testId, String executionId) {
// try (Connection conn = getConnection()) {
// return select(conn, testId, executionId);
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static void insert(TestExecution execution) {
// try (Connection conn = getConnection()) {
// delete(conn, execution); // uniqueness is enforced at test level
// insert(conn, execution);
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static void assertPerformance(Collection<PerformanceMetricDescriptor> metrics, TestExecution baseline,
// TestExecution actual) {
// ArrayList<String> errors = new ArrayList<>();
// for (PerformanceMetricDescriptor metric : metrics) {
// String error = metric.assertPerformance(baseline, actual);
// if (error != null) {
// errors.add(error);
// }
// }
// if (!errors.isEmpty()) {
// throw new PerformanceAssertionFailure(baseline, actual, errors);
// }
// }
//
// }
| import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import java.util.concurrent.TimeUnit;
import com.sonatype.nexus.perftest.db.PerformanceMetricDescriptor;
import com.sonatype.nexus.perftest.db.TestExecution;
import com.sonatype.nexus.perftest.db.TestExecutions;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; | public Duration(long value, TimeUnit unit) {
this.value = value;
this.unit = unit;
}
@JsonCreator
@SuppressWarnings("unused")
public Duration(String value) {
StringTokenizer st = new StringTokenizer(value);
this.value = Long.parseLong(st.nextToken());
this.unit = TimeUnit.valueOf(st.nextToken());
}
public long toMillis() {
return unit.toMillis(value);
}
}
@JsonCreator
public PerformanceTest(@JsonProperty("name") String name, @JsonProperty("duration") Duration duration,
@JsonProperty("swarms") Collection<ClientSwarm> swarms)
{
this.name = name;
this.duration = duration;
this.swarms = Collections.unmodifiableCollection(new ArrayList<>(swarms));
}
public void run() throws InterruptedException {
TestExecution baseline = null;
if (baselineId != null) { | // Path: src/main/java/com/sonatype/nexus/perftest/db/TestExecutions.java
// public class TestExecutions {
//
// static {
// try {
// Class.forName("org.h2.Driver");
// } catch (ClassNotFoundException e) {
// // this is going to be fun to debug
// throw new LinkageError("Could not load required class", e);
// }
// }
//
// private static void createTables(Connection conn) throws SQLException {
// try (Statement statement = conn.createStatement()) {
// statement.executeUpdate("CREATE TABLE IF NOT EXISTS executions (" //
// + " test_id VARCHAR(255)," //
// + " execution_id VARCHAR(255)," //
// + " metric_id VARCHAR(255)," //
// + " value DOUBLE," //
// + " PRIMARY KEY(test_id, execution_id, metric_id)" //
// + ")");
// }
// }
//
// private static boolean delete(Connection conn, TestExecution execution) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("DELETE FROM executions WHERE test_id = ? AND execution_id = ?")) {
// statement.setString(1, execution.getTestId());
// statement.setString(2, execution.getExecutionId());
// return statement.executeUpdate() > 0;
// }
// }
//
// private static void insert(Connection conn, TestExecution execution) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("INSERT INTO executions (test_id, execution_id, metric_id, value) VALUES (?, ?, ?, ?)")) {
// for (String metricId : execution.getMetricIds()) {
// statement.setString(1, execution.getTestId());
// statement.setString(2, execution.getExecutionId());
// statement.setString(3, metricId);
// statement.setDouble(4, execution.getMetric(metricId));
// statement.executeUpdate();
// }
// }
// }
//
// private static TestExecution select(Connection conn, String testId, String executionId) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("SELECT metric_id, value FROM executions WHERE test_id = ? AND execution_id = ?")) {
// statement.setString(1, testId);
// statement.setString(2, executionId);
// try (ResultSet resultSet = statement.executeQuery()) {
// TestExecution execution = new TestExecution(testId, executionId);
// while (resultSet.next()) {
// execution.addMetric(resultSet.getString(1), resultSet.getDouble(2));
// }
// return execution.getMetricIds().isEmpty() ? null : execution;
// }
// }
// }
//
// public static void main(String[] args) throws Exception {
// TestExecution execution = new TestExecution("test", "execution");
// execution.addMetric("foo", 123.45);
// try (Connection conn = getConnection()) {
// createTables(conn);
// System.err.println(delete(conn, execution));
// insert(conn, execution);
//
// select(conn, execution.getTestId(), execution.getExecutionId());
//
// System.err.println(delete(conn, execution));
// }
// }
//
// private static Connection getConnection() throws SQLException {
// Connection conn = DriverManager.getConnection("jdbc:h2:~/nexusperftest");
// createTables(conn);
// return conn;
// }
//
// public static void assertUnique(String testId, String executionId) {
// try (Connection conn = getConnection()) {
// Assert.assertNull(select(conn, testId, executionId));
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static TestExecution select(String testId, String executionId) {
// try (Connection conn = getConnection()) {
// return select(conn, testId, executionId);
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static void insert(TestExecution execution) {
// try (Connection conn = getConnection()) {
// delete(conn, execution); // uniqueness is enforced at test level
// insert(conn, execution);
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static void assertPerformance(Collection<PerformanceMetricDescriptor> metrics, TestExecution baseline,
// TestExecution actual) {
// ArrayList<String> errors = new ArrayList<>();
// for (PerformanceMetricDescriptor metric : metrics) {
// String error = metric.assertPerformance(baseline, actual);
// if (error != null) {
// errors.add(error);
// }
// }
// if (!errors.isEmpty()) {
// throw new PerformanceAssertionFailure(baseline, actual, errors);
// }
// }
//
// }
// Path: src/main/java/com/sonatype/nexus/perftest/PerformanceTest.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import java.util.concurrent.TimeUnit;
import com.sonatype.nexus.perftest.db.PerformanceMetricDescriptor;
import com.sonatype.nexus.perftest.db.TestExecution;
import com.sonatype.nexus.perftest.db.TestExecutions;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public Duration(long value, TimeUnit unit) {
this.value = value;
this.unit = unit;
}
@JsonCreator
@SuppressWarnings("unused")
public Duration(String value) {
StringTokenizer st = new StringTokenizer(value);
this.value = Long.parseLong(st.nextToken());
this.unit = TimeUnit.valueOf(st.nextToken());
}
public long toMillis() {
return unit.toMillis(value);
}
}
@JsonCreator
public PerformanceTest(@JsonProperty("name") String name, @JsonProperty("duration") Duration duration,
@JsonProperty("swarms") Collection<ClientSwarm> swarms)
{
this.name = name;
this.duration = duration;
this.swarms = Collections.unmodifiableCollection(new ArrayList<>(swarms));
}
public void run() throws InterruptedException {
TestExecution baseline = null;
if (baselineId != null) { | baseline = TestExecutions.select(name, baselineId); |
sonatype/nexus-perf | src/main/java/com/sonatype/nexus/perftest/maven/DownloadAction.java | // Path: src/main/java/com/sonatype/nexus/perftest/Digests.java
// public class Digests {
// public static String getDigest(HttpEntity entity, String algorithm) throws IOException {
// try (InputStream is = entity.getContent()) {
// byte[] buffer = new byte[1024];
//
// MessageDigest md = MessageDigest.getInstance(algorithm);
//
// int numRead;
//
// do {
// numRead = is.read(buffer);
//
// if (numRead > 0) {
// md.update(buffer, 0, numRead);
// }
// } while (numRead != -1);
//
// return new String(encodeHex(md.digest()));
// } catch (NoSuchAlgorithmException e) {
// throw new IOException(e);
// }
// }
//
// private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
//
// public static char[] encodeHex(byte[] data) {
// int l = data.length;
//
// char[] out = new char[l << 1];
//
// // two characters form the hex value.
// for (int i = 0, j = 0; i < l; i++) {
// out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];
// out[j++] = DIGITS[0x0F & data[i]];
// }
//
// return out;
// }
//
// }
| import java.io.IOException;
import java.nio.charset.Charset;
import com.sonatype.nexus.perftest.Digests;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils; | /*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.maven;
/**
* Downloads specified artifact, verifies checksum, throws IOException if downloads fails or checksum is invalid
*/
public class DownloadAction
{
private final HttpClient httpClient;
private final String baseUrl;
private static class Checksumer
{
private final HttpEntity entity;
private String sha1;
public Checksumer(HttpEntity entity) {
this.entity = entity;
}
public void consumeEntity() throws IOException { | // Path: src/main/java/com/sonatype/nexus/perftest/Digests.java
// public class Digests {
// public static String getDigest(HttpEntity entity, String algorithm) throws IOException {
// try (InputStream is = entity.getContent()) {
// byte[] buffer = new byte[1024];
//
// MessageDigest md = MessageDigest.getInstance(algorithm);
//
// int numRead;
//
// do {
// numRead = is.read(buffer);
//
// if (numRead > 0) {
// md.update(buffer, 0, numRead);
// }
// } while (numRead != -1);
//
// return new String(encodeHex(md.digest()));
// } catch (NoSuchAlgorithmException e) {
// throw new IOException(e);
// }
// }
//
// private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
//
// public static char[] encodeHex(byte[] data) {
// int l = data.length;
//
// char[] out = new char[l << 1];
//
// // two characters form the hex value.
// for (int i = 0, j = 0; i < l; i++) {
// out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];
// out[j++] = DIGITS[0x0F & data[i]];
// }
//
// return out;
// }
//
// }
// Path: src/main/java/com/sonatype/nexus/perftest/maven/DownloadAction.java
import java.io.IOException;
import java.nio.charset.Charset;
import com.sonatype.nexus.perftest.Digests;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;
/*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.maven;
/**
* Downloads specified artifact, verifies checksum, throws IOException if downloads fails or checksum is invalid
*/
public class DownloadAction
{
private final HttpClient httpClient;
private final String baseUrl;
private static class Checksumer
{
private final HttpEntity entity;
private String sha1;
public Checksumer(HttpEntity entity) {
this.entity = entity;
}
public void consumeEntity() throws IOException { | this.sha1 = Digests.getDigest(entity, "sha1"); |
sonatype/nexus-perf | src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java | // Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
| import java.net.MalformedURLException;
import java.util.HashSet;
import java.util.Set;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import org.sonatype.nexus.client.core.NexusClient;
import org.sonatype.nexus.client.core.spi.SubsystemFactory;
import org.sonatype.nexus.client.core.spi.subsystem.repository.RepositoryFactory;
import org.sonatype.nexus.client.core.subsystem.repository.Repositories;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.maven.JerseyMavenGroupRepositoryFactory;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.maven.JerseyMavenHostedRepositoryFactory;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.maven.JerseyMavenProxyRepositoryFactory;
import org.sonatype.nexus.client.rest.AuthenticationInfo;
import org.sonatype.nexus.client.rest.BaseUrl;
import org.sonatype.nexus.client.rest.ConnectionInfo;
import org.sonatype.nexus.client.rest.UsernamePasswordAuthenticationInfo;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClientFactory;
import org.sonatype.nexus.client.rest.jersey.subsystem.JerseyRepositoriesFactory;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams; | /*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest;
public abstract class AbstractNexusOperation
{
public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
protected final String username;
protected final String password;
protected final String nexusBaseurl;
public AbstractNexusOperation(Nexus nexus) {
this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
this.username = nexus.getUsername();
this.password = nexus.getPassword();
}
private static String sanitizeBaseurl(String nexusBaseurl) {
if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
return null;
}
nexusBaseurl = nexusBaseurl.trim();
return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
}
protected DefaultHttpClient getHttpClient() { | // Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
// Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
import java.net.MalformedURLException;
import java.util.HashSet;
import java.util.Set;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import org.sonatype.nexus.client.core.NexusClient;
import org.sonatype.nexus.client.core.spi.SubsystemFactory;
import org.sonatype.nexus.client.core.spi.subsystem.repository.RepositoryFactory;
import org.sonatype.nexus.client.core.subsystem.repository.Repositories;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.maven.JerseyMavenGroupRepositoryFactory;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.maven.JerseyMavenHostedRepositoryFactory;
import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.maven.JerseyMavenProxyRepositoryFactory;
import org.sonatype.nexus.client.rest.AuthenticationInfo;
import org.sonatype.nexus.client.rest.BaseUrl;
import org.sonatype.nexus.client.rest.ConnectionInfo;
import org.sonatype.nexus.client.rest.UsernamePasswordAuthenticationInfo;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClientFactory;
import org.sonatype.nexus.client.rest.jersey.subsystem.JerseyRepositoriesFactory;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
/*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest;
public abstract class AbstractNexusOperation
{
public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
protected final String username;
protected final String password;
protected final String nexusBaseurl;
public AbstractNexusOperation(Nexus nexus) {
this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
this.username = nexus.getUsername();
this.password = nexus.getPassword();
}
private static String sanitizeBaseurl(String nexusBaseurl) {
if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
return null;
}
nexusBaseurl = nexusBaseurl.trim();
return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
}
protected DefaultHttpClient getHttpClient() { | ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread()); |
sonatype/nexus-perf | src/main/java/com/sonatype/nexus/perftest/maven/ArtifactDeployer.java | // Path: src/main/java/com/sonatype/nexus/perftest/Digests.java
// public class Digests {
// public static String getDigest(HttpEntity entity, String algorithm) throws IOException {
// try (InputStream is = entity.getContent()) {
// byte[] buffer = new byte[1024];
//
// MessageDigest md = MessageDigest.getInstance(algorithm);
//
// int numRead;
//
// do {
// numRead = is.read(buffer);
//
// if (numRead > 0) {
// md.update(buffer, 0, numRead);
// }
// } while (numRead != -1);
//
// return new String(encodeHex(md.digest()));
// } catch (NoSuchAlgorithmException e) {
// throw new IOException(e);
// }
// }
//
// private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
//
// public static char[] encodeHex(byte[] data) {
// int l = data.length;
//
// char[] out = new char[l << 1];
//
// // two characters form the hex value.
// for (int i = 0, j = 0; i < l; i++) {
// out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];
// out[j++] = DIGITS[0x0F & data[i]];
// }
//
// return out;
// }
//
// }
| import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.sonatype.nexus.perftest.Digests;
import de.pdark.decentxml.Document;
import de.pdark.decentxml.XMLParser;
import de.pdark.decentxml.XMLWriter; | throws IOException {
StringBuilder path = new StringBuilder();
path.append(groupId.replace('.', '/')).append('/');
path.append(artifactId).append('/');
path.append(version).append('/');
path.append(artifactId).append('-').append(version).append(extension);
HttpPut httpPut = new HttpPut(repoUrl + path);
httpPut.setEntity(entity);
HttpResponse response;
try {
response = httpclient.execute(httpPut);
try {
EntityUtils.consume(response.getEntity());
} finally {
httpPut.releaseConnection();
}
} catch (IOException e) {
throw new IOException("IOException executing " + httpPut.toString(), e);
}
if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() > 299) {
throw new IOException(httpPut.toString() + " : " + response.getStatusLine().toString());
}
}
public static StringEntity getDigest(HttpEntity entity, String algorithm) throws IOException { | // Path: src/main/java/com/sonatype/nexus/perftest/Digests.java
// public class Digests {
// public static String getDigest(HttpEntity entity, String algorithm) throws IOException {
// try (InputStream is = entity.getContent()) {
// byte[] buffer = new byte[1024];
//
// MessageDigest md = MessageDigest.getInstance(algorithm);
//
// int numRead;
//
// do {
// numRead = is.read(buffer);
//
// if (numRead > 0) {
// md.update(buffer, 0, numRead);
// }
// } while (numRead != -1);
//
// return new String(encodeHex(md.digest()));
// } catch (NoSuchAlgorithmException e) {
// throw new IOException(e);
// }
// }
//
// private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
//
// public static char[] encodeHex(byte[] data) {
// int l = data.length;
//
// char[] out = new char[l << 1];
//
// // two characters form the hex value.
// for (int i = 0, j = 0; i < l; i++) {
// out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];
// out[j++] = DIGITS[0x0F & data[i]];
// }
//
// return out;
// }
//
// }
// Path: src/main/java/com/sonatype/nexus/perftest/maven/ArtifactDeployer.java
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.sonatype.nexus.perftest.Digests;
import de.pdark.decentxml.Document;
import de.pdark.decentxml.XMLParser;
import de.pdark.decentxml.XMLWriter;
throws IOException {
StringBuilder path = new StringBuilder();
path.append(groupId.replace('.', '/')).append('/');
path.append(artifactId).append('/');
path.append(version).append('/');
path.append(artifactId).append('-').append(version).append(extension);
HttpPut httpPut = new HttpPut(repoUrl + path);
httpPut.setEntity(entity);
HttpResponse response;
try {
response = httpclient.execute(httpPut);
try {
EntityUtils.consume(response.getEntity());
} finally {
httpPut.releaseConnection();
}
} catch (IOException e) {
throw new IOException("IOException executing " + httpPut.toString(), e);
}
if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() > 299) {
throw new IOException(httpPut.toString() + " : " + response.getStatusLine().toString());
}
}
public static StringEntity getDigest(HttpEntity entity, String algorithm) throws IOException { | return new StringEntity(Digests.getDigest(entity, algorithm), ContentType.TEXT_PLAIN); |
sonatype/nexus-perf | src/main/java/com/sonatype/nexus/perftest/ossrh/ProjectProvisioningOperation.java | // Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
// public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
//
// protected final String username;
//
// protected final String password;
//
// protected final String nexusBaseurl;
//
// public AbstractNexusOperation(Nexus nexus) {
// this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
// this.username = nexus.getUsername();
// this.password = nexus.getPassword();
// }
//
// private static String sanitizeBaseurl(String nexusBaseurl) {
// if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
// return null;
// }
// nexusBaseurl = nexusBaseurl.trim();
// return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
// }
//
// protected DefaultHttpClient getHttpClient() {
// ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
//
// DefaultHttpClient httpclient = info.getContextValue("httpclient");
// if (httpclient == null) {
// HttpParams params = new BasicHttpParams();
// HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
// HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
// httpclient = new DefaultHttpClient(params);
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
// new UsernamePasswordCredentials(username, password));
// info.setContextValue("httpclient", httpclient);
// }
// return httpclient;
// }
//
// protected boolean isSuccess(HttpResponse response) {
// return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
// }
//
// @SuppressWarnings("unchecked")
// protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
// if (nexusBaseurl == null) {
// throw new IllegalStateException();
// }
// BaseUrl baseUrl;
// try {
// baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
// }
// catch (MalformedURLException e) {
// throw new RuntimeException(e);
// }
// AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
// ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
// return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
// }
//
// @SuppressWarnings("rawtypes")
// protected JerseyRepositoriesFactory newRepositoryFactories() {
// Set<RepositoryFactory> repositoryFactories = new HashSet<>();
// repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
// repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
// repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
// return new JerseyRepositoriesFactory(repositoryFactories);
// }
//
// @SuppressWarnings("unchecked")
// protected String getRepoBaseurl(String repoid) {
// final String layout = System.getProperty("nexus.layout", "NX3");
// switch (layout) {
// case "NX2":
// return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
// case "NX3":
// return this.nexusBaseurl + "repository/" + repoid;
// default:
// throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
// }
// }
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
// public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
// private final String baseurl;
//
// private final String username;
//
// private final String password;
//
// public Nexus() {
// this.baseurl = System.getProperty("nexus.baseurl");
// this.username = System.getProperty("nexus.username");
// this.password = System.getProperty("nexus.password");
// }
//
// @JsonCreator
// public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
// @JsonProperty("password") String password) {
// this.baseurl = baseurl;
// this.username = username;
// this.password = password;
// }
//
// public String getBaseurl() {
// return baseurl;
// }
//
// public String getUsername() {
// return username;
// }
//
// public String getPassword() {
// return password;
// }
// }
| import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus; | /*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.ossrh;
public class ProjectProvisioningOperation extends AbstractNexusOperation implements Operation {
public ProjectProvisioningOperation(Nexus nexus) {
super(nexus);
}
@Override | // Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
// public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
//
// protected final String username;
//
// protected final String password;
//
// protected final String nexusBaseurl;
//
// public AbstractNexusOperation(Nexus nexus) {
// this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
// this.username = nexus.getUsername();
// this.password = nexus.getPassword();
// }
//
// private static String sanitizeBaseurl(String nexusBaseurl) {
// if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
// return null;
// }
// nexusBaseurl = nexusBaseurl.trim();
// return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
// }
//
// protected DefaultHttpClient getHttpClient() {
// ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
//
// DefaultHttpClient httpclient = info.getContextValue("httpclient");
// if (httpclient == null) {
// HttpParams params = new BasicHttpParams();
// HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
// HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
// httpclient = new DefaultHttpClient(params);
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
// new UsernamePasswordCredentials(username, password));
// info.setContextValue("httpclient", httpclient);
// }
// return httpclient;
// }
//
// protected boolean isSuccess(HttpResponse response) {
// return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
// }
//
// @SuppressWarnings("unchecked")
// protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
// if (nexusBaseurl == null) {
// throw new IllegalStateException();
// }
// BaseUrl baseUrl;
// try {
// baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
// }
// catch (MalformedURLException e) {
// throw new RuntimeException(e);
// }
// AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
// ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
// return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
// }
//
// @SuppressWarnings("rawtypes")
// protected JerseyRepositoriesFactory newRepositoryFactories() {
// Set<RepositoryFactory> repositoryFactories = new HashSet<>();
// repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
// repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
// repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
// return new JerseyRepositoriesFactory(repositoryFactories);
// }
//
// @SuppressWarnings("unchecked")
// protected String getRepoBaseurl(String repoid) {
// final String layout = System.getProperty("nexus.layout", "NX3");
// switch (layout) {
// case "NX2":
// return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
// case "NX3":
// return this.nexusBaseurl + "repository/" + repoid;
// default:
// throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
// }
// }
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
// String getSwarmName();
//
// int getClientId();
//
// int getRequestId();
//
// <T> void setContextValue(String key, T value);
//
// <T> T getContextValue(String key);
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
// public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
//
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
// private final String baseurl;
//
// private final String username;
//
// private final String password;
//
// public Nexus() {
// this.baseurl = System.getProperty("nexus.baseurl");
// this.username = System.getProperty("nexus.username");
// this.password = System.getProperty("nexus.password");
// }
//
// @JsonCreator
// public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
// @JsonProperty("password") String password) {
// this.baseurl = baseurl;
// this.username = username;
// this.password = password;
// }
//
// public String getBaseurl() {
// return baseurl;
// }
//
// public String getUsername() {
// return username;
// }
//
// public String getPassword() {
// return password;
// }
// }
// Path: src/main/java/com/sonatype/nexus/perftest/ossrh/ProjectProvisioningOperation.java
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus;
/*
* Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*/
package com.sonatype.nexus.perftest.ossrh;
public class ProjectProvisioningOperation extends AbstractNexusOperation implements Operation {
public ProjectProvisioningOperation(Nexus nexus) {
super(nexus);
}
@Override | public void perform(ClientRequestInfo requestInfo) throws Exception { |
sonatype/nexus-perf | src/main/java/com/sonatype/nexus/perftest/PerformanceTestAsserter.java | // Path: src/main/java/com/sonatype/nexus/perftest/db/TestExecutions.java
// public class TestExecutions {
//
// static {
// try {
// Class.forName("org.h2.Driver");
// } catch (ClassNotFoundException e) {
// // this is going to be fun to debug
// throw new LinkageError("Could not load required class", e);
// }
// }
//
// private static void createTables(Connection conn) throws SQLException {
// try (Statement statement = conn.createStatement()) {
// statement.executeUpdate("CREATE TABLE IF NOT EXISTS executions (" //
// + " test_id VARCHAR(255)," //
// + " execution_id VARCHAR(255)," //
// + " metric_id VARCHAR(255)," //
// + " value DOUBLE," //
// + " PRIMARY KEY(test_id, execution_id, metric_id)" //
// + ")");
// }
// }
//
// private static boolean delete(Connection conn, TestExecution execution) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("DELETE FROM executions WHERE test_id = ? AND execution_id = ?")) {
// statement.setString(1, execution.getTestId());
// statement.setString(2, execution.getExecutionId());
// return statement.executeUpdate() > 0;
// }
// }
//
// private static void insert(Connection conn, TestExecution execution) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("INSERT INTO executions (test_id, execution_id, metric_id, value) VALUES (?, ?, ?, ?)")) {
// for (String metricId : execution.getMetricIds()) {
// statement.setString(1, execution.getTestId());
// statement.setString(2, execution.getExecutionId());
// statement.setString(3, metricId);
// statement.setDouble(4, execution.getMetric(metricId));
// statement.executeUpdate();
// }
// }
// }
//
// private static TestExecution select(Connection conn, String testId, String executionId) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("SELECT metric_id, value FROM executions WHERE test_id = ? AND execution_id = ?")) {
// statement.setString(1, testId);
// statement.setString(2, executionId);
// try (ResultSet resultSet = statement.executeQuery()) {
// TestExecution execution = new TestExecution(testId, executionId);
// while (resultSet.next()) {
// execution.addMetric(resultSet.getString(1), resultSet.getDouble(2));
// }
// return execution.getMetricIds().isEmpty() ? null : execution;
// }
// }
// }
//
// public static void main(String[] args) throws Exception {
// TestExecution execution = new TestExecution("test", "execution");
// execution.addMetric("foo", 123.45);
// try (Connection conn = getConnection()) {
// createTables(conn);
// System.err.println(delete(conn, execution));
// insert(conn, execution);
//
// select(conn, execution.getTestId(), execution.getExecutionId());
//
// System.err.println(delete(conn, execution));
// }
// }
//
// private static Connection getConnection() throws SQLException {
// Connection conn = DriverManager.getConnection("jdbc:h2:~/nexusperftest");
// createTables(conn);
// return conn;
// }
//
// public static void assertUnique(String testId, String executionId) {
// try (Connection conn = getConnection()) {
// Assert.assertNull(select(conn, testId, executionId));
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static TestExecution select(String testId, String executionId) {
// try (Connection conn = getConnection()) {
// return select(conn, testId, executionId);
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static void insert(TestExecution execution) {
// try (Connection conn = getConnection()) {
// delete(conn, execution); // uniqueness is enforced at test level
// insert(conn, execution);
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static void assertPerformance(Collection<PerformanceMetricDescriptor> metrics, TestExecution baseline,
// TestExecution actual) {
// ArrayList<String> errors = new ArrayList<>();
// for (PerformanceMetricDescriptor metric : metrics) {
// String error = metric.assertPerformance(baseline, actual);
// if (error != null) {
// errors.add(error);
// }
// }
// if (!errors.isEmpty()) {
// throw new PerformanceAssertionFailure(baseline, actual, errors);
// }
// }
//
// }
| import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.sonatype.nexus.perftest.db.PerformanceMetricDescriptor;
import com.sonatype.nexus.perftest.db.TestExecution;
import com.sonatype.nexus.perftest.db.TestExecutions;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List; | public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty,
Object beanInstance) {
if (Nexus.class.getName().equals(valueId)) {
return nexus;
}
return null;
}
});
File src = new File(args[0]).getCanonicalFile();
String name = src.getName().substring(0, src.getName().lastIndexOf("."));
Collection<ClientSwarm> swarms = mapper.readValue(src, PerformanceTest.class).getSwarms();
List<Metric> metrics = new ArrayList<>();
for (ClientSwarm swarm : swarms) {
metrics.add(swarm.getMetric());
}
System.out.println("Test " + name + " metrics:" + metrics);
assertTest(name, metrics);
System.out.println("Exit");
System.exit(0);
}
public static void assertTest(String name, List<Metric> metrics) throws InterruptedException {
TestExecution baseline = null;
if (baselineId != null) { | // Path: src/main/java/com/sonatype/nexus/perftest/db/TestExecutions.java
// public class TestExecutions {
//
// static {
// try {
// Class.forName("org.h2.Driver");
// } catch (ClassNotFoundException e) {
// // this is going to be fun to debug
// throw new LinkageError("Could not load required class", e);
// }
// }
//
// private static void createTables(Connection conn) throws SQLException {
// try (Statement statement = conn.createStatement()) {
// statement.executeUpdate("CREATE TABLE IF NOT EXISTS executions (" //
// + " test_id VARCHAR(255)," //
// + " execution_id VARCHAR(255)," //
// + " metric_id VARCHAR(255)," //
// + " value DOUBLE," //
// + " PRIMARY KEY(test_id, execution_id, metric_id)" //
// + ")");
// }
// }
//
// private static boolean delete(Connection conn, TestExecution execution) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("DELETE FROM executions WHERE test_id = ? AND execution_id = ?")) {
// statement.setString(1, execution.getTestId());
// statement.setString(2, execution.getExecutionId());
// return statement.executeUpdate() > 0;
// }
// }
//
// private static void insert(Connection conn, TestExecution execution) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("INSERT INTO executions (test_id, execution_id, metric_id, value) VALUES (?, ?, ?, ?)")) {
// for (String metricId : execution.getMetricIds()) {
// statement.setString(1, execution.getTestId());
// statement.setString(2, execution.getExecutionId());
// statement.setString(3, metricId);
// statement.setDouble(4, execution.getMetric(metricId));
// statement.executeUpdate();
// }
// }
// }
//
// private static TestExecution select(Connection conn, String testId, String executionId) throws SQLException {
// try (PreparedStatement statement =
// conn.prepareStatement("SELECT metric_id, value FROM executions WHERE test_id = ? AND execution_id = ?")) {
// statement.setString(1, testId);
// statement.setString(2, executionId);
// try (ResultSet resultSet = statement.executeQuery()) {
// TestExecution execution = new TestExecution(testId, executionId);
// while (resultSet.next()) {
// execution.addMetric(resultSet.getString(1), resultSet.getDouble(2));
// }
// return execution.getMetricIds().isEmpty() ? null : execution;
// }
// }
// }
//
// public static void main(String[] args) throws Exception {
// TestExecution execution = new TestExecution("test", "execution");
// execution.addMetric("foo", 123.45);
// try (Connection conn = getConnection()) {
// createTables(conn);
// System.err.println(delete(conn, execution));
// insert(conn, execution);
//
// select(conn, execution.getTestId(), execution.getExecutionId());
//
// System.err.println(delete(conn, execution));
// }
// }
//
// private static Connection getConnection() throws SQLException {
// Connection conn = DriverManager.getConnection("jdbc:h2:~/nexusperftest");
// createTables(conn);
// return conn;
// }
//
// public static void assertUnique(String testId, String executionId) {
// try (Connection conn = getConnection()) {
// Assert.assertNull(select(conn, testId, executionId));
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static TestExecution select(String testId, String executionId) {
// try (Connection conn = getConnection()) {
// return select(conn, testId, executionId);
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static void insert(TestExecution execution) {
// try (Connection conn = getConnection()) {
// delete(conn, execution); // uniqueness is enforced at test level
// insert(conn, execution);
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static void assertPerformance(Collection<PerformanceMetricDescriptor> metrics, TestExecution baseline,
// TestExecution actual) {
// ArrayList<String> errors = new ArrayList<>();
// for (PerformanceMetricDescriptor metric : metrics) {
// String error = metric.assertPerformance(baseline, actual);
// if (error != null) {
// errors.add(error);
// }
// }
// if (!errors.isEmpty()) {
// throw new PerformanceAssertionFailure(baseline, actual, errors);
// }
// }
//
// }
// Path: src/main/java/com/sonatype/nexus/perftest/PerformanceTestAsserter.java
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.sonatype.nexus.perftest.db.PerformanceMetricDescriptor;
import com.sonatype.nexus.perftest.db.TestExecution;
import com.sonatype.nexus.perftest.db.TestExecutions;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty,
Object beanInstance) {
if (Nexus.class.getName().equals(valueId)) {
return nexus;
}
return null;
}
});
File src = new File(args[0]).getCanonicalFile();
String name = src.getName().substring(0, src.getName().lastIndexOf("."));
Collection<ClientSwarm> swarms = mapper.readValue(src, PerformanceTest.class).getSwarms();
List<Metric> metrics = new ArrayList<>();
for (ClientSwarm swarm : swarms) {
metrics.add(swarm.getMetric());
}
System.out.println("Test " + name + " metrics:" + metrics);
assertTest(name, metrics);
System.out.println("Exit");
System.exit(0);
}
public static void assertTest(String name, List<Metric> metrics) throws InterruptedException {
TestExecution baseline = null;
if (baselineId != null) { | baseline = TestExecutions.select(name, baselineId); |
jiangqqlmj/Android-Universal-Image-Loader-Modify | library/src/main/java/com/nostra13/universalimageloader/utils/DiskCacheUtils.java | // Path: library/src/main/java/com/nostra13/universalimageloader/cache/disc/DiskCache.java
// public interface DiskCache {
// /**
// *
// * Returns root directory of disk cache
// *
// * @return Root directory of disk cache
// */
// File getDirectory();
//
// /**
// * 根据图片地址从缓存中获取文件
// * Returns file of cached image
// *
// * @param imageUri Original image URI
// * @return File of cached image or <b>null</b> if image wasn't cached
// */
// File get(String imageUri);
//
// /**
// * 进行保存图片流到缓存中
// * Saves image stream in disk cache.
// * Incoming image stream shouldn't be closed in this method.
// *
// * @param imageUri Original image URI
// * @param imageStream Input stream of image (shouldn't be closed in this method)
// * @param listener Listener for saving progress, can be ignored if you don't use
// * {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
// * progress listener} in ImageLoader calls
// * @return <b>true</b> - if image was saved successfully; <b>false</b> - if image wasn't saved in disk cache.
// * @throws java.io.IOException
// */
// boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener) throws IOException;
//
// /**
// * 进行保存图片 bitmap到缓存中
// * Saves image bitmap in disk cache.
// *
// * @param imageUri Original image URI
// * @param bitmap Image bitmap
// * @return <b>true</b> - if bitmap was saved successfully; <b>false</b> - if bitmap wasn't saved in disk cache.
// * @throws IOException
// */
// boolean save(String imageUri, Bitmap bitmap) throws IOException;
//
// /**
// * 根据图片地址来从缓存中删除文件
// * Removes image file associated with incoming URI
// *
// * @param imageUri Image URI
// * @return <b>true</b> - if image file is deleted successfully; <b>false</b> - if image file doesn't exist for
// * incoming URI or image file can't be deleted.
// */
// boolean remove(String imageUri);
//
// /**
// * Closes disk cache, releases resources.
// * 关闭缓存,释放资源
// */
// void close();
//
// /**
// * Clears disk cache.
// * 进行清除文件缓存
// */
// void clear();
// }
| import com.nostra13.universalimageloader.cache.disc.DiskCache;
import java.io.File; | /*******************************************************************************
* Copyright 2011-2014 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.utils;
/**
* 操作本地文件系统缓存工具类
* Utility for convenient work with disk cache.<br />
* <b>NOTE:</b> This utility works with file system so avoid using it on application main thread.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.8.0
*/
public final class DiskCacheUtils {
private DiskCacheUtils() {
}
/**
* Returns {@link File} of cached image or <b>null</b> if image was not cached in disk cache
* 从文件缓存中根据图片链接地址获取缓存的文件
*/ | // Path: library/src/main/java/com/nostra13/universalimageloader/cache/disc/DiskCache.java
// public interface DiskCache {
// /**
// *
// * Returns root directory of disk cache
// *
// * @return Root directory of disk cache
// */
// File getDirectory();
//
// /**
// * 根据图片地址从缓存中获取文件
// * Returns file of cached image
// *
// * @param imageUri Original image URI
// * @return File of cached image or <b>null</b> if image wasn't cached
// */
// File get(String imageUri);
//
// /**
// * 进行保存图片流到缓存中
// * Saves image stream in disk cache.
// * Incoming image stream shouldn't be closed in this method.
// *
// * @param imageUri Original image URI
// * @param imageStream Input stream of image (shouldn't be closed in this method)
// * @param listener Listener for saving progress, can be ignored if you don't use
// * {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
// * progress listener} in ImageLoader calls
// * @return <b>true</b> - if image was saved successfully; <b>false</b> - if image wasn't saved in disk cache.
// * @throws java.io.IOException
// */
// boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener) throws IOException;
//
// /**
// * 进行保存图片 bitmap到缓存中
// * Saves image bitmap in disk cache.
// *
// * @param imageUri Original image URI
// * @param bitmap Image bitmap
// * @return <b>true</b> - if bitmap was saved successfully; <b>false</b> - if bitmap wasn't saved in disk cache.
// * @throws IOException
// */
// boolean save(String imageUri, Bitmap bitmap) throws IOException;
//
// /**
// * 根据图片地址来从缓存中删除文件
// * Removes image file associated with incoming URI
// *
// * @param imageUri Image URI
// * @return <b>true</b> - if image file is deleted successfully; <b>false</b> - if image file doesn't exist for
// * incoming URI or image file can't be deleted.
// */
// boolean remove(String imageUri);
//
// /**
// * Closes disk cache, releases resources.
// * 关闭缓存,释放资源
// */
// void close();
//
// /**
// * Clears disk cache.
// * 进行清除文件缓存
// */
// void clear();
// }
// Path: library/src/main/java/com/nostra13/universalimageloader/utils/DiskCacheUtils.java
import com.nostra13.universalimageloader.cache.disc.DiskCache;
import java.io.File;
/*******************************************************************************
* Copyright 2011-2014 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.utils;
/**
* 操作本地文件系统缓存工具类
* Utility for convenient work with disk cache.<br />
* <b>NOTE:</b> This utility works with file system so avoid using it on application main thread.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.8.0
*/
public final class DiskCacheUtils {
private DiskCacheUtils() {
}
/**
* Returns {@link File} of cached image or <b>null</b> if image was not cached in disk cache
* 从文件缓存中根据图片链接地址获取缓存的文件
*/ | public static File findInCache(String imageUri, DiskCache diskCache) { |
jiangqqlmj/Android-Universal-Image-Loader-Modify | library/src/main/java/com/nostra13/universalimageloader/core/display/SimpleBitmapDisplayer.java | // Path: library/src/main/java/com/nostra13/universalimageloader/core/imageaware/ImageAware.java
// public interface ImageAware {
// /**
// * 返回图片的宽度,改为原始图片尺寸
// * Returns width of image aware view. This value is used to define scale size for original image.
// * Can return 0 if width is undefined.<br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// */
// int getWidth();
//
// /**
// * 返回图片的高度,改为原始图片尺寸
// * Returns height of image aware view. This value is used to define scale size for original image.
// * Can return 0 if height is undefined.<br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// */
// int getHeight();
//
// /**
// * Returns {@linkplain com.nostra13.universalimageloader.core.assist.ViewScaleType scale type} which is used for
// * scaling image for this image aware view. Must <b>NOT</b> return <b>null</b>.
// */
// ViewScaleType getScaleType();
//
// /**
// * 返回被包装的View
// * Returns wrapped Android {@link android.view.View View}. Can return <b>null</b> if no view is wrapped or view was
// * collected by GC.<br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// */
// View getWrappedView();
//
// /**
// * Returns a flag whether image aware view is collected by GC or whatsoever. If so then ImageLoader stop processing
// * of task for this image aware view and fires
// * {@link com.nostra13.universalimageloader.core.listener.ImageLoadingListener#onLoadingCancelled(String,
// * android.view.View) ImageLoadingListener#onLoadingCancelled(String, View)} callback.<br />
// * Mey be called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// *
// * @return <b>true</b> - if view is collected by GC and ImageLoader should stop processing this image aware view;
// * <b>false</b> - otherwise
// */
// boolean isCollected();
//
// /**
// * 返回图片控件的ID
// * Returns ID of image aware view. Point of ID is similar to Object's hashCode. This ID should be unique for every
// * image view instance and should be the same for same instances. This ID identifies processing task in ImageLoader
// * so ImageLoader won't process two image aware views with the same ID in one time. When ImageLoader get new task
// * it cancels old task with this ID (if any) and starts new task.
// * <p/>
// * It's reasonable to return hash code of wrapped view (if any) to prevent displaying non-actual images in view
// * because of view re-using.
// */
// int getId();
//
// /**
// * 给图片控件设置drawable
// * Sets image drawable into this image aware view.<br />
// * Displays drawable in this image aware view
// * {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#showImageForEmptyUri(
// *android.graphics.drawable.Drawable) for empty Uri},
// * {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#showImageOnLoading(
// *android.graphics.drawable.Drawable) on loading} or
// * {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#showImageOnFail(
// *android.graphics.drawable.Drawable) on loading fail}. These drawables can be specified in
// * {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions display options}.<br />
// * Also can be called in {@link com.nostra13.universalimageloader.core.display.BitmapDisplayer BitmapDisplayer}.< br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// *
// * @return <b>true</b> if drawable was set successfully; <b>false</b> - otherwise
// */
// boolean setImageDrawable(Drawable drawable);
//
// /**
// * 给图片控件设置bitmap
// * Sets image bitmap into this image aware view.<br />
// * Displays loaded and decoded image {@link android.graphics.Bitmap} in this image view aware.
// * Actually it's used only in
// * {@link com.nostra13.universalimageloader.core.display.BitmapDisplayer BitmapDisplayer}.< br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// *
// * @return <b>true</b> if bitmap was set successfully; <b>false</b> - otherwise
// */
// boolean setImageBitmap(Bitmap bitmap);
// }
| import android.graphics.Bitmap;
import com.nostra13.universalimageloader.core.assist.LoadedFrom;
import com.nostra13.universalimageloader.core.imageaware.ImageAware; | /*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.core.display;
/**
* 简化的图片显示器 就直接显示图片即可
* Just displays {@link Bitmap} in {@link com.nostra13.universalimageloader.core.imageaware.ImageAware}
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.5.6
*/
public final class SimpleBitmapDisplayer implements BitmapDisplayer {
@Override | // Path: library/src/main/java/com/nostra13/universalimageloader/core/imageaware/ImageAware.java
// public interface ImageAware {
// /**
// * 返回图片的宽度,改为原始图片尺寸
// * Returns width of image aware view. This value is used to define scale size for original image.
// * Can return 0 if width is undefined.<br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// */
// int getWidth();
//
// /**
// * 返回图片的高度,改为原始图片尺寸
// * Returns height of image aware view. This value is used to define scale size for original image.
// * Can return 0 if height is undefined.<br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// */
// int getHeight();
//
// /**
// * Returns {@linkplain com.nostra13.universalimageloader.core.assist.ViewScaleType scale type} which is used for
// * scaling image for this image aware view. Must <b>NOT</b> return <b>null</b>.
// */
// ViewScaleType getScaleType();
//
// /**
// * 返回被包装的View
// * Returns wrapped Android {@link android.view.View View}. Can return <b>null</b> if no view is wrapped or view was
// * collected by GC.<br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// */
// View getWrappedView();
//
// /**
// * Returns a flag whether image aware view is collected by GC or whatsoever. If so then ImageLoader stop processing
// * of task for this image aware view and fires
// * {@link com.nostra13.universalimageloader.core.listener.ImageLoadingListener#onLoadingCancelled(String,
// * android.view.View) ImageLoadingListener#onLoadingCancelled(String, View)} callback.<br />
// * Mey be called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// *
// * @return <b>true</b> - if view is collected by GC and ImageLoader should stop processing this image aware view;
// * <b>false</b> - otherwise
// */
// boolean isCollected();
//
// /**
// * 返回图片控件的ID
// * Returns ID of image aware view. Point of ID is similar to Object's hashCode. This ID should be unique for every
// * image view instance and should be the same for same instances. This ID identifies processing task in ImageLoader
// * so ImageLoader won't process two image aware views with the same ID in one time. When ImageLoader get new task
// * it cancels old task with this ID (if any) and starts new task.
// * <p/>
// * It's reasonable to return hash code of wrapped view (if any) to prevent displaying non-actual images in view
// * because of view re-using.
// */
// int getId();
//
// /**
// * 给图片控件设置drawable
// * Sets image drawable into this image aware view.<br />
// * Displays drawable in this image aware view
// * {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#showImageForEmptyUri(
// *android.graphics.drawable.Drawable) for empty Uri},
// * {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#showImageOnLoading(
// *android.graphics.drawable.Drawable) on loading} or
// * {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions.Builder#showImageOnFail(
// *android.graphics.drawable.Drawable) on loading fail}. These drawables can be specified in
// * {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions display options}.<br />
// * Also can be called in {@link com.nostra13.universalimageloader.core.display.BitmapDisplayer BitmapDisplayer}.< br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// *
// * @return <b>true</b> if drawable was set successfully; <b>false</b> - otherwise
// */
// boolean setImageDrawable(Drawable drawable);
//
// /**
// * 给图片控件设置bitmap
// * Sets image bitmap into this image aware view.<br />
// * Displays loaded and decoded image {@link android.graphics.Bitmap} in this image view aware.
// * Actually it's used only in
// * {@link com.nostra13.universalimageloader.core.display.BitmapDisplayer BitmapDisplayer}.< br />
// * Is called on UI thread if ImageLoader was called on UI thread. Otherwise - on background thread.
// *
// * @return <b>true</b> if bitmap was set successfully; <b>false</b> - otherwise
// */
// boolean setImageBitmap(Bitmap bitmap);
// }
// Path: library/src/main/java/com/nostra13/universalimageloader/core/display/SimpleBitmapDisplayer.java
import android.graphics.Bitmap;
import com.nostra13.universalimageloader.core.assist.LoadedFrom;
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.core.display;
/**
* 简化的图片显示器 就直接显示图片即可
* Just displays {@link Bitmap} in {@link com.nostra13.universalimageloader.core.imageaware.ImageAware}
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.5.6
*/
public final class SimpleBitmapDisplayer implements BitmapDisplayer {
@Override | public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) { |
jiangqqlmj/Android-Universal-Image-Loader-Modify | library/src/main/java/com/nostra13/universalimageloader/cache/disc/naming/Md5FileNameGenerator.java | // Path: library/src/main/java/com/nostra13/universalimageloader/utils/L.java
// public final class L {
//
// private static final String LOG_FORMAT = "%1$s\n%2$s";
// private static volatile boolean writeDebugLogs = false;
// private static volatile boolean writeLogs = true;
//
// private L() {
// }
//
// /**
// * 打开日志打印 已废弃
// * Enables logger (if {@link #disableLogging()} was called before)
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(true)} instead
// */
// @Deprecated
// public static void enableLogging() {
// writeLogs(true);
// }
//
// /**
// * 关闭日志打印 已废弃
// * Disables logger, no logs will be passed to LogCat, all log methods will do nothing
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(false)} instead
// */
// @Deprecated
// public static void disableLogging() {
// writeLogs(false);
// }
//
// /**
// * 进行打开或者关闭调试日志打印功能
// * Enables/disables detail logging of {@link ImageLoader} work.
// * Consider {@link com.nostra13.universalimageloader.utils.L#disableLogging()} to disable
// * ImageLoader logging completely (even error logs)<br />
// * Debug logs are disabled by default.
// */
// public static void writeDebugLogs(boolean writeDebugLogs) {
// L.writeDebugLogs = writeDebugLogs;
// }
//
// /**
// * Enables/disables logging of {@link ImageLoader} completely (even error logs).
// * 打开或者关闭所有日志打印功能
// */
// public static void writeLogs(boolean writeLogs) {
// L.writeLogs = writeLogs;
// }
//
// public static void d(String message, Object... args) {
// if (writeDebugLogs) {
// log(Log.DEBUG, null, message, args);
// }
// }
//
// public static void i(String message, Object... args) {
// log(Log.INFO, null, message, args);
// }
//
// public static void w(String message, Object... args) {
// log(Log.WARN, null, message, args);
// }
//
// public static void e(Throwable ex) {
// log(Log.ERROR, ex, null);
// }
//
// public static void e(String message, Object... args) {
// log(Log.ERROR, null, message, args);
// }
//
// public static void e(Throwable ex, String message, Object... args) {
// log(Log.ERROR, ex, message, args);
// }
//
// /**
// * 日志格式转换 以及输出
// * @param priority
// * @param ex
// * @param message
// * @param args
// */
// private static void log(int priority, Throwable ex, String message, Object... args) {
// if (!writeLogs) return;
// if (args.length > 0) {
// message = String.format(message, args);
// }
//
// String log;
// if (ex == null) {
// log = message;
// } else {
// String logMessage = message == null ? ex.getMessage() : message;
// String logBody = Log.getStackTraceString(ex);
// log = String.format(LOG_FORMAT, logMessage, logBody);
// }
// Log.println(priority, ImageLoader.TAG, log);
// }
// }
| import com.nostra13.universalimageloader.utils.L;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; | /*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.cache.disc.naming;
/**
* 使用图片URL地址的 MD5编码来进行生成缓存的文件名称
* Names image file as MD5 hash of image URI
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.4.0
*/
public class Md5FileNameGenerator implements FileNameGenerator {
private static final String HASH_ALGORITHM = "MD5";
private static final int RADIX = 10 + 26; // 10 digits + 26 letters
@Override
public String generate(String imageUri) {
byte[] md5 = getMD5(imageUri.getBytes());
BigInteger bi = new BigInteger(md5).abs();
return bi.toString(RADIX);
}
/**
* 获取MD5格式的文件
* @param data
* @return
*/
private byte[] getMD5(byte[] data) {
byte[] hash = null;
try {
MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);
digest.update(data);
hash = digest.digest();
} catch (NoSuchAlgorithmException e) { | // Path: library/src/main/java/com/nostra13/universalimageloader/utils/L.java
// public final class L {
//
// private static final String LOG_FORMAT = "%1$s\n%2$s";
// private static volatile boolean writeDebugLogs = false;
// private static volatile boolean writeLogs = true;
//
// private L() {
// }
//
// /**
// * 打开日志打印 已废弃
// * Enables logger (if {@link #disableLogging()} was called before)
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(true)} instead
// */
// @Deprecated
// public static void enableLogging() {
// writeLogs(true);
// }
//
// /**
// * 关闭日志打印 已废弃
// * Disables logger, no logs will be passed to LogCat, all log methods will do nothing
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(false)} instead
// */
// @Deprecated
// public static void disableLogging() {
// writeLogs(false);
// }
//
// /**
// * 进行打开或者关闭调试日志打印功能
// * Enables/disables detail logging of {@link ImageLoader} work.
// * Consider {@link com.nostra13.universalimageloader.utils.L#disableLogging()} to disable
// * ImageLoader logging completely (even error logs)<br />
// * Debug logs are disabled by default.
// */
// public static void writeDebugLogs(boolean writeDebugLogs) {
// L.writeDebugLogs = writeDebugLogs;
// }
//
// /**
// * Enables/disables logging of {@link ImageLoader} completely (even error logs).
// * 打开或者关闭所有日志打印功能
// */
// public static void writeLogs(boolean writeLogs) {
// L.writeLogs = writeLogs;
// }
//
// public static void d(String message, Object... args) {
// if (writeDebugLogs) {
// log(Log.DEBUG, null, message, args);
// }
// }
//
// public static void i(String message, Object... args) {
// log(Log.INFO, null, message, args);
// }
//
// public static void w(String message, Object... args) {
// log(Log.WARN, null, message, args);
// }
//
// public static void e(Throwable ex) {
// log(Log.ERROR, ex, null);
// }
//
// public static void e(String message, Object... args) {
// log(Log.ERROR, null, message, args);
// }
//
// public static void e(Throwable ex, String message, Object... args) {
// log(Log.ERROR, ex, message, args);
// }
//
// /**
// * 日志格式转换 以及输出
// * @param priority
// * @param ex
// * @param message
// * @param args
// */
// private static void log(int priority, Throwable ex, String message, Object... args) {
// if (!writeLogs) return;
// if (args.length > 0) {
// message = String.format(message, args);
// }
//
// String log;
// if (ex == null) {
// log = message;
// } else {
// String logMessage = message == null ? ex.getMessage() : message;
// String logBody = Log.getStackTraceString(ex);
// log = String.format(LOG_FORMAT, logMessage, logBody);
// }
// Log.println(priority, ImageLoader.TAG, log);
// }
// }
// Path: library/src/main/java/com/nostra13/universalimageloader/cache/disc/naming/Md5FileNameGenerator.java
import com.nostra13.universalimageloader.utils.L;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.cache.disc.naming;
/**
* 使用图片URL地址的 MD5编码来进行生成缓存的文件名称
* Names image file as MD5 hash of image URI
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.4.0
*/
public class Md5FileNameGenerator implements FileNameGenerator {
private static final String HASH_ALGORITHM = "MD5";
private static final int RADIX = 10 + 26; // 10 digits + 26 letters
@Override
public String generate(String imageUri) {
byte[] md5 = getMD5(imageUri.getBytes());
BigInteger bi = new BigInteger(md5).abs();
return bi.toString(RADIX);
}
/**
* 获取MD5格式的文件
* @param data
* @return
*/
private byte[] getMD5(byte[] data) {
byte[] hash = null;
try {
MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);
digest.update(data);
hash = digest.digest();
} catch (NoSuchAlgorithmException e) { | L.e(e); |
jiangqqlmj/Android-Universal-Image-Loader-Modify | library/src/main/java/com/nostra13/universalimageloader/core/imageaware/ImageViewAware.java | // Path: library/src/main/java/com/nostra13/universalimageloader/utils/L.java
// public final class L {
//
// private static final String LOG_FORMAT = "%1$s\n%2$s";
// private static volatile boolean writeDebugLogs = false;
// private static volatile boolean writeLogs = true;
//
// private L() {
// }
//
// /**
// * 打开日志打印 已废弃
// * Enables logger (if {@link #disableLogging()} was called before)
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(true)} instead
// */
// @Deprecated
// public static void enableLogging() {
// writeLogs(true);
// }
//
// /**
// * 关闭日志打印 已废弃
// * Disables logger, no logs will be passed to LogCat, all log methods will do nothing
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(false)} instead
// */
// @Deprecated
// public static void disableLogging() {
// writeLogs(false);
// }
//
// /**
// * 进行打开或者关闭调试日志打印功能
// * Enables/disables detail logging of {@link ImageLoader} work.
// * Consider {@link com.nostra13.universalimageloader.utils.L#disableLogging()} to disable
// * ImageLoader logging completely (even error logs)<br />
// * Debug logs are disabled by default.
// */
// public static void writeDebugLogs(boolean writeDebugLogs) {
// L.writeDebugLogs = writeDebugLogs;
// }
//
// /**
// * Enables/disables logging of {@link ImageLoader} completely (even error logs).
// * 打开或者关闭所有日志打印功能
// */
// public static void writeLogs(boolean writeLogs) {
// L.writeLogs = writeLogs;
// }
//
// public static void d(String message, Object... args) {
// if (writeDebugLogs) {
// log(Log.DEBUG, null, message, args);
// }
// }
//
// public static void i(String message, Object... args) {
// log(Log.INFO, null, message, args);
// }
//
// public static void w(String message, Object... args) {
// log(Log.WARN, null, message, args);
// }
//
// public static void e(Throwable ex) {
// log(Log.ERROR, ex, null);
// }
//
// public static void e(String message, Object... args) {
// log(Log.ERROR, null, message, args);
// }
//
// public static void e(Throwable ex, String message, Object... args) {
// log(Log.ERROR, ex, message, args);
// }
//
// /**
// * 日志格式转换 以及输出
// * @param priority
// * @param ex
// * @param message
// * @param args
// */
// private static void log(int priority, Throwable ex, String message, Object... args) {
// if (!writeLogs) return;
// if (args.length > 0) {
// message = String.format(message, args);
// }
//
// String log;
// if (ex == null) {
// log = message;
// } else {
// String logMessage = message == null ? ex.getMessage() : message;
// String logBody = Log.getStackTraceString(ex);
// log = String.format(LOG_FORMAT, logMessage, logBody);
// }
// Log.println(priority, ImageLoader.TAG, log);
// }
// }
| import android.graphics.Bitmap;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import com.nostra13.universalimageloader.core.assist.ViewScaleType;
import com.nostra13.universalimageloader.utils.L;
import java.lang.reflect.Field; | ((AnimationDrawable)drawable).start();
}
}
/**
* ViewAware的实现类 设置图片 bitmap
* @param bitmap
* @param view
*/
@Override
protected void setImageBitmapInto(Bitmap bitmap, View view) {
((ImageView) view).setImageBitmap(bitmap);
}
/**
* 通过反射方式来获取ImageView的最大宽度
* @param object
* @param fieldName
* @return
*/
private static int getImageViewFieldValue(Object object, String fieldName) {
int value = 0;
try {
Field field = ImageView.class.getDeclaredField(fieldName);
field.setAccessible(true);
int fieldValue = (Integer) field.get(object);
if (fieldValue > 0 && fieldValue < Integer.MAX_VALUE) {
value = fieldValue;
}
} catch (Exception e) { | // Path: library/src/main/java/com/nostra13/universalimageloader/utils/L.java
// public final class L {
//
// private static final String LOG_FORMAT = "%1$s\n%2$s";
// private static volatile boolean writeDebugLogs = false;
// private static volatile boolean writeLogs = true;
//
// private L() {
// }
//
// /**
// * 打开日志打印 已废弃
// * Enables logger (if {@link #disableLogging()} was called before)
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(true)} instead
// */
// @Deprecated
// public static void enableLogging() {
// writeLogs(true);
// }
//
// /**
// * 关闭日志打印 已废弃
// * Disables logger, no logs will be passed to LogCat, all log methods will do nothing
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(false)} instead
// */
// @Deprecated
// public static void disableLogging() {
// writeLogs(false);
// }
//
// /**
// * 进行打开或者关闭调试日志打印功能
// * Enables/disables detail logging of {@link ImageLoader} work.
// * Consider {@link com.nostra13.universalimageloader.utils.L#disableLogging()} to disable
// * ImageLoader logging completely (even error logs)<br />
// * Debug logs are disabled by default.
// */
// public static void writeDebugLogs(boolean writeDebugLogs) {
// L.writeDebugLogs = writeDebugLogs;
// }
//
// /**
// * Enables/disables logging of {@link ImageLoader} completely (even error logs).
// * 打开或者关闭所有日志打印功能
// */
// public static void writeLogs(boolean writeLogs) {
// L.writeLogs = writeLogs;
// }
//
// public static void d(String message, Object... args) {
// if (writeDebugLogs) {
// log(Log.DEBUG, null, message, args);
// }
// }
//
// public static void i(String message, Object... args) {
// log(Log.INFO, null, message, args);
// }
//
// public static void w(String message, Object... args) {
// log(Log.WARN, null, message, args);
// }
//
// public static void e(Throwable ex) {
// log(Log.ERROR, ex, null);
// }
//
// public static void e(String message, Object... args) {
// log(Log.ERROR, null, message, args);
// }
//
// public static void e(Throwable ex, String message, Object... args) {
// log(Log.ERROR, ex, message, args);
// }
//
// /**
// * 日志格式转换 以及输出
// * @param priority
// * @param ex
// * @param message
// * @param args
// */
// private static void log(int priority, Throwable ex, String message, Object... args) {
// if (!writeLogs) return;
// if (args.length > 0) {
// message = String.format(message, args);
// }
//
// String log;
// if (ex == null) {
// log = message;
// } else {
// String logMessage = message == null ? ex.getMessage() : message;
// String logBody = Log.getStackTraceString(ex);
// log = String.format(LOG_FORMAT, logMessage, logBody);
// }
// Log.println(priority, ImageLoader.TAG, log);
// }
// }
// Path: library/src/main/java/com/nostra13/universalimageloader/core/imageaware/ImageViewAware.java
import android.graphics.Bitmap;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import com.nostra13.universalimageloader.core.assist.ViewScaleType;
import com.nostra13.universalimageloader.utils.L;
import java.lang.reflect.Field;
((AnimationDrawable)drawable).start();
}
}
/**
* ViewAware的实现类 设置图片 bitmap
* @param bitmap
* @param view
*/
@Override
protected void setImageBitmapInto(Bitmap bitmap, View view) {
((ImageView) view).setImageBitmap(bitmap);
}
/**
* 通过反射方式来获取ImageView的最大宽度
* @param object
* @param fieldName
* @return
*/
private static int getImageViewFieldValue(Object object, String fieldName) {
int value = 0;
try {
Field field = ImageView.class.getDeclaredField(fieldName);
field.setAccessible(true);
int fieldValue = (Integer) field.get(object);
if (fieldValue > 0 && fieldValue < Integer.MAX_VALUE) {
value = fieldValue;
}
} catch (Exception e) { | L.e(e); |
jiangqqlmj/Android-Universal-Image-Loader-Modify | library/src/main/java/com/nostra13/universalimageloader/core/imageaware/ViewAware.java | // Path: library/src/main/java/com/nostra13/universalimageloader/utils/L.java
// public final class L {
//
// private static final String LOG_FORMAT = "%1$s\n%2$s";
// private static volatile boolean writeDebugLogs = false;
// private static volatile boolean writeLogs = true;
//
// private L() {
// }
//
// /**
// * 打开日志打印 已废弃
// * Enables logger (if {@link #disableLogging()} was called before)
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(true)} instead
// */
// @Deprecated
// public static void enableLogging() {
// writeLogs(true);
// }
//
// /**
// * 关闭日志打印 已废弃
// * Disables logger, no logs will be passed to LogCat, all log methods will do nothing
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(false)} instead
// */
// @Deprecated
// public static void disableLogging() {
// writeLogs(false);
// }
//
// /**
// * 进行打开或者关闭调试日志打印功能
// * Enables/disables detail logging of {@link ImageLoader} work.
// * Consider {@link com.nostra13.universalimageloader.utils.L#disableLogging()} to disable
// * ImageLoader logging completely (even error logs)<br />
// * Debug logs are disabled by default.
// */
// public static void writeDebugLogs(boolean writeDebugLogs) {
// L.writeDebugLogs = writeDebugLogs;
// }
//
// /**
// * Enables/disables logging of {@link ImageLoader} completely (even error logs).
// * 打开或者关闭所有日志打印功能
// */
// public static void writeLogs(boolean writeLogs) {
// L.writeLogs = writeLogs;
// }
//
// public static void d(String message, Object... args) {
// if (writeDebugLogs) {
// log(Log.DEBUG, null, message, args);
// }
// }
//
// public static void i(String message, Object... args) {
// log(Log.INFO, null, message, args);
// }
//
// public static void w(String message, Object... args) {
// log(Log.WARN, null, message, args);
// }
//
// public static void e(Throwable ex) {
// log(Log.ERROR, ex, null);
// }
//
// public static void e(String message, Object... args) {
// log(Log.ERROR, null, message, args);
// }
//
// public static void e(Throwable ex, String message, Object... args) {
// log(Log.ERROR, ex, message, args);
// }
//
// /**
// * 日志格式转换 以及输出
// * @param priority
// * @param ex
// * @param message
// * @param args
// */
// private static void log(int priority, Throwable ex, String message, Object... args) {
// if (!writeLogs) return;
// if (args.length > 0) {
// message = String.format(message, args);
// }
//
// String log;
// if (ex == null) {
// log = message;
// } else {
// String logMessage = message == null ? ex.getMessage() : message;
// String logBody = Log.getStackTraceString(ex);
// log = String.format(LOG_FORMAT, logMessage, logBody);
// }
// Log.println(priority, ImageLoader.TAG, log);
// }
// }
| import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Looper;
import android.view.View;
import android.view.ViewGroup;
import com.nostra13.universalimageloader.core.assist.ViewScaleType;
import com.nostra13.universalimageloader.utils.L;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference; |
/**
* 表示当前iamgeview引用是否被回收
* @return
*/
@Override
public boolean isCollected() {
return viewRef.get() == null;
}
@Override
public int getId() {
View view = viewRef.get();
return view == null ? super.hashCode() : view.hashCode();
}
/**
* 切换主线程进行设置图片资源 drawable
* @param drawable
* @return
*/
@Override
public boolean setImageDrawable(Drawable drawable) {
if (Looper.myLooper() == Looper.getMainLooper()) {
View view = viewRef.get();
if (view != null) {
setImageDrawableInto(drawable, view);
return true;
}
} else { | // Path: library/src/main/java/com/nostra13/universalimageloader/utils/L.java
// public final class L {
//
// private static final String LOG_FORMAT = "%1$s\n%2$s";
// private static volatile boolean writeDebugLogs = false;
// private static volatile boolean writeLogs = true;
//
// private L() {
// }
//
// /**
// * 打开日志打印 已废弃
// * Enables logger (if {@link #disableLogging()} was called before)
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(true)} instead
// */
// @Deprecated
// public static void enableLogging() {
// writeLogs(true);
// }
//
// /**
// * 关闭日志打印 已废弃
// * Disables logger, no logs will be passed to LogCat, all log methods will do nothing
// *
// * @deprecated Use {@link #writeLogs(boolean) writeLogs(false)} instead
// */
// @Deprecated
// public static void disableLogging() {
// writeLogs(false);
// }
//
// /**
// * 进行打开或者关闭调试日志打印功能
// * Enables/disables detail logging of {@link ImageLoader} work.
// * Consider {@link com.nostra13.universalimageloader.utils.L#disableLogging()} to disable
// * ImageLoader logging completely (even error logs)<br />
// * Debug logs are disabled by default.
// */
// public static void writeDebugLogs(boolean writeDebugLogs) {
// L.writeDebugLogs = writeDebugLogs;
// }
//
// /**
// * Enables/disables logging of {@link ImageLoader} completely (even error logs).
// * 打开或者关闭所有日志打印功能
// */
// public static void writeLogs(boolean writeLogs) {
// L.writeLogs = writeLogs;
// }
//
// public static void d(String message, Object... args) {
// if (writeDebugLogs) {
// log(Log.DEBUG, null, message, args);
// }
// }
//
// public static void i(String message, Object... args) {
// log(Log.INFO, null, message, args);
// }
//
// public static void w(String message, Object... args) {
// log(Log.WARN, null, message, args);
// }
//
// public static void e(Throwable ex) {
// log(Log.ERROR, ex, null);
// }
//
// public static void e(String message, Object... args) {
// log(Log.ERROR, null, message, args);
// }
//
// public static void e(Throwable ex, String message, Object... args) {
// log(Log.ERROR, ex, message, args);
// }
//
// /**
// * 日志格式转换 以及输出
// * @param priority
// * @param ex
// * @param message
// * @param args
// */
// private static void log(int priority, Throwable ex, String message, Object... args) {
// if (!writeLogs) return;
// if (args.length > 0) {
// message = String.format(message, args);
// }
//
// String log;
// if (ex == null) {
// log = message;
// } else {
// String logMessage = message == null ? ex.getMessage() : message;
// String logBody = Log.getStackTraceString(ex);
// log = String.format(LOG_FORMAT, logMessage, logBody);
// }
// Log.println(priority, ImageLoader.TAG, log);
// }
// }
// Path: library/src/main/java/com/nostra13/universalimageloader/core/imageaware/ViewAware.java
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Looper;
import android.view.View;
import android.view.ViewGroup;
import com.nostra13.universalimageloader.core.assist.ViewScaleType;
import com.nostra13.universalimageloader.utils.L;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
/**
* 表示当前iamgeview引用是否被回收
* @return
*/
@Override
public boolean isCollected() {
return viewRef.get() == null;
}
@Override
public int getId() {
View view = viewRef.get();
return view == null ? super.hashCode() : view.hashCode();
}
/**
* 切换主线程进行设置图片资源 drawable
* @param drawable
* @return
*/
@Override
public boolean setImageDrawable(Drawable drawable) {
if (Looper.myLooper() == Looper.getMainLooper()) {
View view = viewRef.get();
if (view != null) {
setImageDrawableInto(drawable, view);
return true;
}
} else { | L.w(WARN_CANT_SET_DRAWABLE); |
jiangqqlmj/Android-Universal-Image-Loader-Modify | library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiskCache.java | // Path: library/src/main/java/com/nostra13/universalimageloader/cache/disc/naming/FileNameGenerator.java
// public interface FileNameGenerator {
//
// /**
// * Generates unique file name for image defined by URI
// * 根据图片地址来进行生成特定的文件名
// */
// String generate(String imageUri);
// }
| import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
import java.io.File; | /*******************************************************************************
* Copyright 2011-2014 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.cache.disc.impl;
/**
* 默认无限制本地文件系统缓存(磁盘缓存)
* Default implementation of {@linkplain com.nostra13.universalimageloader.cache.disc.DiskCache disk cache}.
* Cache size is unlimited.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.0.0
*/
public class UnlimitedDiskCache extends BaseDiskCache {
/** @param cacheDir Directory for file caching */
public UnlimitedDiskCache(File cacheDir) {
super(cacheDir);
}
/**
* 构造器 无限制磁盘缓存器初始化
* @param cacheDir Directory for file caching 缓存文件夹
* @param reserveCacheDir 备用缓存文件夹
* null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.
*/
public UnlimitedDiskCache(File cacheDir, File reserveCacheDir) {
super(cacheDir, reserveCacheDir);
}
/**
* 构造器 无限制磁盘缓存器初始化
* @param cacheDir Directory for file caching 缓存文件夹
* @param reserveCacheDir 备用缓存文件夹
* null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.
* @param fileNameGenerator 缓存文件名生成器
* {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator
* Name generator} for cached files
*/ | // Path: library/src/main/java/com/nostra13/universalimageloader/cache/disc/naming/FileNameGenerator.java
// public interface FileNameGenerator {
//
// /**
// * Generates unique file name for image defined by URI
// * 根据图片地址来进行生成特定的文件名
// */
// String generate(String imageUri);
// }
// Path: library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiskCache.java
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
import java.io.File;
/*******************************************************************************
* Copyright 2011-2014 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.cache.disc.impl;
/**
* 默认无限制本地文件系统缓存(磁盘缓存)
* Default implementation of {@linkplain com.nostra13.universalimageloader.cache.disc.DiskCache disk cache}.
* Cache size is unlimited.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.0.0
*/
public class UnlimitedDiskCache extends BaseDiskCache {
/** @param cacheDir Directory for file caching */
public UnlimitedDiskCache(File cacheDir) {
super(cacheDir);
}
/**
* 构造器 无限制磁盘缓存器初始化
* @param cacheDir Directory for file caching 缓存文件夹
* @param reserveCacheDir 备用缓存文件夹
* null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.
*/
public UnlimitedDiskCache(File cacheDir, File reserveCacheDir) {
super(cacheDir, reserveCacheDir);
}
/**
* 构造器 无限制磁盘缓存器初始化
* @param cacheDir Directory for file caching 缓存文件夹
* @param reserveCacheDir 备用缓存文件夹
* null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.
* @param fileNameGenerator 缓存文件名生成器
* {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator
* Name generator} for cached files
*/ | public UnlimitedDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) { |
jiangqqlmj/Android-Universal-Image-Loader-Modify | library/src/main/java/com/nostra13/universalimageloader/core/listener/SimpleImageLoadingListener.java | // Path: library/src/main/java/com/nostra13/universalimageloader/core/assist/FailReason.java
// public class FailReason {
// /*失败原因*/
// private final FailType type;
// /*错误信息*/
// private final Throwable cause;
//
// public FailReason(FailType type, Throwable cause) {
// this.type = type;
// this.cause = cause;
// }
//
// /** @return {@linkplain FailType Fail type} */
// public FailType getType() {
// return type;
// }
//
// /** @return Thrown exception/error, can be <b>null</b> */
// public Throwable getCause() {
// return cause;
// }
//
// /**
// * Presents type of fail while image loading
// * 图片加载失败原因 类型枚举
// */
// public static enum FailType {
// /**
// * IO流相关错误
// * Input/output error. Can be caused by network communication fail or error while caching image on file system. */
// IO_ERROR,
// /**
// * Error while 解码错误
// * {@linkplain android.graphics.BitmapFactory#decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options)
// * decode image to Bitmap}
// */
// DECODING_ERROR,
// /**
// * 网络被拒绝错误
// * {@linkplain com.nostra13.universalimageloader.core.ImageLoader#denyNetworkDownloads(boolean) Network
// * downloads are denied} and requested image wasn't cached in disk cache before.
// */
// NETWORK_DENIED,
// /**
// * 内存溢出
// * Not enough memory to create needed Bitmap for image */
// OUT_OF_MEMORY,
// /**
// * 不明错误
// * Unknown error was occurred while loading image */
// UNKNOWN
// }
// }
| import android.graphics.Bitmap;
import android.view.View;
import com.nostra13.universalimageloader.core.assist.FailReason; | /*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.core.listener;
/**
* 该为一个简便的图片加载监听器,如果我们需要监听图片加载过程中的部分事件,就可以使用这个进行选择性实现
* A convenient class to extend when you only want to listen for a subset of all the image loading events. This
* implements all methods in the {@link com.nostra13.universalimageloader.core.listener.ImageLoadingListener} but does
* nothing.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.4.0
*/
public class SimpleImageLoadingListener implements ImageLoadingListener {
/**
* 图片加载开始回调
* @param imageUri Loading image URI
* @param view View for image
*/
@Override
public void onLoadingStarted(String imageUri, View view) {
// Empty implementation
}
/**
* 图片加载失败回调
* @param imageUri Loading image URI
* @param view View for image. Can be <b>null</b>.
* @param failReason {@linkplain com.nostra13.universalimageloader.core.assist.FailReason The reason} why image
*/
@Override | // Path: library/src/main/java/com/nostra13/universalimageloader/core/assist/FailReason.java
// public class FailReason {
// /*失败原因*/
// private final FailType type;
// /*错误信息*/
// private final Throwable cause;
//
// public FailReason(FailType type, Throwable cause) {
// this.type = type;
// this.cause = cause;
// }
//
// /** @return {@linkplain FailType Fail type} */
// public FailType getType() {
// return type;
// }
//
// /** @return Thrown exception/error, can be <b>null</b> */
// public Throwable getCause() {
// return cause;
// }
//
// /**
// * Presents type of fail while image loading
// * 图片加载失败原因 类型枚举
// */
// public static enum FailType {
// /**
// * IO流相关错误
// * Input/output error. Can be caused by network communication fail or error while caching image on file system. */
// IO_ERROR,
// /**
// * Error while 解码错误
// * {@linkplain android.graphics.BitmapFactory#decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options)
// * decode image to Bitmap}
// */
// DECODING_ERROR,
// /**
// * 网络被拒绝错误
// * {@linkplain com.nostra13.universalimageloader.core.ImageLoader#denyNetworkDownloads(boolean) Network
// * downloads are denied} and requested image wasn't cached in disk cache before.
// */
// NETWORK_DENIED,
// /**
// * 内存溢出
// * Not enough memory to create needed Bitmap for image */
// OUT_OF_MEMORY,
// /**
// * 不明错误
// * Unknown error was occurred while loading image */
// UNKNOWN
// }
// }
// Path: library/src/main/java/com/nostra13/universalimageloader/core/listener/SimpleImageLoadingListener.java
import android.graphics.Bitmap;
import android.view.View;
import com.nostra13.universalimageloader.core.assist.FailReason;
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.core.listener;
/**
* 该为一个简便的图片加载监听器,如果我们需要监听图片加载过程中的部分事件,就可以使用这个进行选择性实现
* A convenient class to extend when you only want to listen for a subset of all the image loading events. This
* implements all methods in the {@link com.nostra13.universalimageloader.core.listener.ImageLoadingListener} but does
* nothing.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.4.0
*/
public class SimpleImageLoadingListener implements ImageLoadingListener {
/**
* 图片加载开始回调
* @param imageUri Loading image URI
* @param view View for image
*/
@Override
public void onLoadingStarted(String imageUri, View view) {
// Empty implementation
}
/**
* 图片加载失败回调
* @param imageUri Loading image URI
* @param view View for image. Can be <b>null</b>.
* @param failReason {@linkplain com.nostra13.universalimageloader.core.assist.FailReason The reason} why image
*/
@Override | public void onLoadingFailed(String imageUri, View view, FailReason failReason) { |
jiangqqlmj/Android-Universal-Image-Loader-Modify | library/src/main/java/com/nostra13/universalimageloader/core/listener/ImageLoadingListener.java | // Path: library/src/main/java/com/nostra13/universalimageloader/core/assist/FailReason.java
// public class FailReason {
// /*失败原因*/
// private final FailType type;
// /*错误信息*/
// private final Throwable cause;
//
// public FailReason(FailType type, Throwable cause) {
// this.type = type;
// this.cause = cause;
// }
//
// /** @return {@linkplain FailType Fail type} */
// public FailType getType() {
// return type;
// }
//
// /** @return Thrown exception/error, can be <b>null</b> */
// public Throwable getCause() {
// return cause;
// }
//
// /**
// * Presents type of fail while image loading
// * 图片加载失败原因 类型枚举
// */
// public static enum FailType {
// /**
// * IO流相关错误
// * Input/output error. Can be caused by network communication fail or error while caching image on file system. */
// IO_ERROR,
// /**
// * Error while 解码错误
// * {@linkplain android.graphics.BitmapFactory#decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options)
// * decode image to Bitmap}
// */
// DECODING_ERROR,
// /**
// * 网络被拒绝错误
// * {@linkplain com.nostra13.universalimageloader.core.ImageLoader#denyNetworkDownloads(boolean) Network
// * downloads are denied} and requested image wasn't cached in disk cache before.
// */
// NETWORK_DENIED,
// /**
// * 内存溢出
// * Not enough memory to create needed Bitmap for image */
// OUT_OF_MEMORY,
// /**
// * 不明错误
// * Unknown error was occurred while loading image */
// UNKNOWN
// }
// }
| import android.graphics.Bitmap;
import android.view.View;
import com.nostra13.universalimageloader.core.assist.FailReason; | /*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.core.listener;
/**
* 图片加载处理的监听回调接口
* Listener for image loading process.<br />
* You can use {@link SimpleImageLoadingListener} for implementing only needed methods.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @see SimpleImageLoadingListener
* @see com.nostra13.universalimageloader.core.assist.FailReason
* @since 1.0.0
*/
public interface ImageLoadingListener {
/**
* 图片加载任务开始的时候回调
* Is called when image loading task was started
*
* @param imageUri Loading image URI
* @param view View for image
*/
void onLoadingStarted(String imageUri, View view);
/**
* 图片加载过程中发生错误回调
* Is called when an error was occurred during image loading
*
* @param imageUri Loading image URI
* @param view View for image. Can be <b>null</b>.
* @param failReason {@linkplain com.nostra13.universalimageloader.core.assist.FailReason The reason} why image
* loading was failed
*/ | // Path: library/src/main/java/com/nostra13/universalimageloader/core/assist/FailReason.java
// public class FailReason {
// /*失败原因*/
// private final FailType type;
// /*错误信息*/
// private final Throwable cause;
//
// public FailReason(FailType type, Throwable cause) {
// this.type = type;
// this.cause = cause;
// }
//
// /** @return {@linkplain FailType Fail type} */
// public FailType getType() {
// return type;
// }
//
// /** @return Thrown exception/error, can be <b>null</b> */
// public Throwable getCause() {
// return cause;
// }
//
// /**
// * Presents type of fail while image loading
// * 图片加载失败原因 类型枚举
// */
// public static enum FailType {
// /**
// * IO流相关错误
// * Input/output error. Can be caused by network communication fail or error while caching image on file system. */
// IO_ERROR,
// /**
// * Error while 解码错误
// * {@linkplain android.graphics.BitmapFactory#decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options)
// * decode image to Bitmap}
// */
// DECODING_ERROR,
// /**
// * 网络被拒绝错误
// * {@linkplain com.nostra13.universalimageloader.core.ImageLoader#denyNetworkDownloads(boolean) Network
// * downloads are denied} and requested image wasn't cached in disk cache before.
// */
// NETWORK_DENIED,
// /**
// * 内存溢出
// * Not enough memory to create needed Bitmap for image */
// OUT_OF_MEMORY,
// /**
// * 不明错误
// * Unknown error was occurred while loading image */
// UNKNOWN
// }
// }
// Path: library/src/main/java/com/nostra13/universalimageloader/core/listener/ImageLoadingListener.java
import android.graphics.Bitmap;
import android.view.View;
import com.nostra13.universalimageloader.core.assist.FailReason;
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* 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.nostra13.universalimageloader.core.listener;
/**
* 图片加载处理的监听回调接口
* Listener for image loading process.<br />
* You can use {@link SimpleImageLoadingListener} for implementing only needed methods.
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @see SimpleImageLoadingListener
* @see com.nostra13.universalimageloader.core.assist.FailReason
* @since 1.0.0
*/
public interface ImageLoadingListener {
/**
* 图片加载任务开始的时候回调
* Is called when image loading task was started
*
* @param imageUri Loading image URI
* @param view View for image
*/
void onLoadingStarted(String imageUri, View view);
/**
* 图片加载过程中发生错误回调
* Is called when an error was occurred during image loading
*
* @param imageUri Loading image URI
* @param view View for image. Can be <b>null</b>.
* @param failReason {@linkplain com.nostra13.universalimageloader.core.assist.FailReason The reason} why image
* loading was failed
*/ | void onLoadingFailed(String imageUri, View view, FailReason failReason); |
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/testing/ConsoleOutput.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
// @ToString
// public class Layout implements Serializable {
//
// private final StockSheet sheet;
// private final int id;
// private final CutTree cutTree;
//
// public Layout(@NonNull final StockSheet sheet, final int id) {
// this.sheet = sheet;
// this.id = id;
// this.cutTree = new CutTree(sheet);
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public int getId() {
// return id;
// }
//
// public int getNumberOfPlacedPanels() {
// int num = 0;
// for (CutTreeNode node : getCutTree()) {
// if (node instanceof PanelNode) {
// num++;
// }
// }
// return num;
// }
//
// public int getNumberOfSubSheets() {
// int num = 0;
// for (CutTreeNode n : getCutTree()) {
// num++;
// }
// return num;
// }
//
// public CutTree getCutTree() {
// return cutTree;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java
// @ToString
// public class OptimizationResult implements Serializable {
//
// private final List<Layout> layouts = new ArrayList<>();
// private double runtime;
//
// public void createNewLayout(@NonNull PanelInstance p) {
// addLayout(new Layout(p.getSheet(), layouts.size()));
// }
//
// private void addLayout(Layout l) {
// layouts.add(l);
// }
//
// public OptimizationResultStats getStats() {
// int numberOfCuts = 0;
// int numberOfLayouts = layouts.size();
// double totalCutLength = 0;
// double sheetArea = 0;
// double usedArea = 0;
// double boundingBoxArea = 0;
// for (Layout layout : layouts) {
// CutTreeStats substats = layout.getCutTree().getStats();
// numberOfCuts += substats.getNumberOfCuts();
// totalCutLength += substats.getTotalCutLength();
// sheetArea += substats.getSheetArea();
// usedArea += substats.getUsedArea();
// boundingBoxArea += substats.getBoundingBoxArea();
// }
// OptimizationResultStats stats = new OptimizationResultStats(numberOfLayouts,
// numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
// return stats;
// }
//
// public List<Layout> getLayouts() {
// return layouts;
// }
//
// public double getRuntime() {
// return runtime;
// }
//
// public void setRuntime(double runtime) {
// this.runtime = runtime;
// }
//
// }
| import java.io.PrintStream;
import lombok.NonNull;
import com.cutlet.lib.model.Layout;
import com.cutlet.lib.optimizer.OptimizationResult;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class ConsoleOutput {
public static void dumpResult(@NonNull OptimizationResult r) {
dumpResult(System.err, r);
}
public static void dumpResult(@NonNull PrintStream out, @NonNull OptimizationResult r) {
out.println("");
out.println("");
out.println("RESULT");
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
// @ToString
// public class Layout implements Serializable {
//
// private final StockSheet sheet;
// private final int id;
// private final CutTree cutTree;
//
// public Layout(@NonNull final StockSheet sheet, final int id) {
// this.sheet = sheet;
// this.id = id;
// this.cutTree = new CutTree(sheet);
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public int getId() {
// return id;
// }
//
// public int getNumberOfPlacedPanels() {
// int num = 0;
// for (CutTreeNode node : getCutTree()) {
// if (node instanceof PanelNode) {
// num++;
// }
// }
// return num;
// }
//
// public int getNumberOfSubSheets() {
// int num = 0;
// for (CutTreeNode n : getCutTree()) {
// num++;
// }
// return num;
// }
//
// public CutTree getCutTree() {
// return cutTree;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java
// @ToString
// public class OptimizationResult implements Serializable {
//
// private final List<Layout> layouts = new ArrayList<>();
// private double runtime;
//
// public void createNewLayout(@NonNull PanelInstance p) {
// addLayout(new Layout(p.getSheet(), layouts.size()));
// }
//
// private void addLayout(Layout l) {
// layouts.add(l);
// }
//
// public OptimizationResultStats getStats() {
// int numberOfCuts = 0;
// int numberOfLayouts = layouts.size();
// double totalCutLength = 0;
// double sheetArea = 0;
// double usedArea = 0;
// double boundingBoxArea = 0;
// for (Layout layout : layouts) {
// CutTreeStats substats = layout.getCutTree().getStats();
// numberOfCuts += substats.getNumberOfCuts();
// totalCutLength += substats.getTotalCutLength();
// sheetArea += substats.getSheetArea();
// usedArea += substats.getUsedArea();
// boundingBoxArea += substats.getBoundingBoxArea();
// }
// OptimizationResultStats stats = new OptimizationResultStats(numberOfLayouts,
// numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
// return stats;
// }
//
// public List<Layout> getLayouts() {
// return layouts;
// }
//
// public double getRuntime() {
// return runtime;
// }
//
// public void setRuntime(double runtime) {
// this.runtime = runtime;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/ConsoleOutput.java
import java.io.PrintStream;
import lombok.NonNull;
import com.cutlet.lib.model.Layout;
import com.cutlet.lib.optimizer.OptimizationResult;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class ConsoleOutput {
public static void dumpResult(@NonNull OptimizationResult r) {
dumpResult(System.err, r);
}
public static void dumpResult(@NonNull PrintStream out, @NonNull OptimizationResult r) {
out.println("");
out.println("");
out.println("RESULT");
| for (Layout l : r.getLayouts()) {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
| import lombok.NonNull;
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/*
* ---------------------l-------------------- ^
* | ^ | |
* | t|r r | y
* | v -h-> w
* | | t |
* | |
* (0,0)--------------------------------------- x->
*/
/**
*
* @author rmuehlba
*/
public class CutNode extends AbstractCutTreeNode {
public enum Direction {
VERTICAL, HORIZONTAL,
};
private CutTreeNode target;
private CutTreeNode rest;
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutNode.java
import lombok.NonNull;
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/*
* ---------------------l-------------------- ^
* | ^ | |
* | t|r r | y
* | v -h-> w
* | | t |
* | |
* (0,0)--------------------------------------- x->
*/
/**
*
* @author rmuehlba
*/
public class CutNode extends AbstractCutTreeNode {
public enum Direction {
VERTICAL, HORIZONTAL,
};
private CutTreeNode target;
private CutTreeNode rest;
| private final Position cutPos;
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
| import lombok.NonNull;
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/*
* ---------------------l-------------------- ^
* | ^ | |
* | t|r r | y
* | v -h-> w
* | | t |
* | |
* (0,0)--------------------------------------- x->
*/
/**
*
* @author rmuehlba
*/
public class CutNode extends AbstractCutTreeNode {
public enum Direction {
VERTICAL, HORIZONTAL,
};
private CutTreeNode target;
private CutTreeNode rest;
private final Position cutPos;
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutNode.java
import lombok.NonNull;
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/*
* ---------------------l-------------------- ^
* | ^ | |
* | t|r r | y
* | v -h-> w
* | | t |
* | |
* (0,0)--------------------------------------- x->
*/
/**
*
* @author rmuehlba
*/
public class CutNode extends AbstractCutTreeNode {
public enum Direction {
VERTICAL, HORIZONTAL,
};
private CutTreeNode target;
private CutTreeNode rest;
private final Position cutPos;
| private final Dimension cutDim;
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
| import com.cutlet.lib.model.Position;
import lombok.NonNull;
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public class FreeNode extends AbstractCutTreeNode {
public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
super(parent, position, dimension);
}
@Override
public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
}
public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
final CutTreeNode parent = this.getParent();
final CutNode cut = new CutNode(parent,
bladeWidth, cutPosition, direction,
getPosition(),
getDimension());
parent.replaceChild(this, cut);
return cut;
}
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
import com.cutlet.lib.model.Position;
import lombok.NonNull;
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public class FreeNode extends AbstractCutTreeNode {
public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
super(parent, position, dimension);
}
@Override
public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
}
public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
final CutTreeNode parent = this.getParent();
final CutNode cut = new CutNode(parent,
bladeWidth, cutPosition, direction,
getPosition(),
getDimension());
parent.replaceChild(this, cut);
return cut;
}
| public PanelNode setPanel(@NonNull PanelInstance panel) {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/GAOptimizationStrategy.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
| import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import lombok.NonNull;
import org.jenetics.EnumGene;
import org.jenetics.Optimize;
import org.jenetics.engine.Codec;
import org.jenetics.engine.Engine;
import org.jenetics.engine.EvolutionResult;
import org.jenetics.engine.codecs;
import org.jenetics.util.ISeq;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class GAOptimizationStrategy extends AbstractOptimizationStrategy {
private static final Logger log = Logger.getLogger(GAOptimizationStrategy.class.getName());
public static java.util.Random random = new java.util.Random();
@Override
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/GAOptimizationStrategy.java
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import lombok.NonNull;
import org.jenetics.EnumGene;
import org.jenetics.Optimize;
import org.jenetics.engine.Codec;
import org.jenetics.engine.Engine;
import org.jenetics.engine.EvolutionResult;
import org.jenetics.engine.codecs;
import org.jenetics.util.ISeq;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class GAOptimizationStrategy extends AbstractOptimizationStrategy {
private static final Logger log = Logger.getLogger(GAOptimizationStrategy.class.getName());
public static java.util.Random random = new java.util.Random();
@Override
| public OptimizationResult optimize(@NonNull final Project project,
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/GAOptimizationStrategy.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
| import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import lombok.NonNull;
import org.jenetics.EnumGene;
import org.jenetics.Optimize;
import org.jenetics.engine.Codec;
import org.jenetics.engine.Engine;
import org.jenetics.engine.EvolutionResult;
import org.jenetics.engine.codecs;
import org.jenetics.util.ISeq;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class GAOptimizationStrategy extends AbstractOptimizationStrategy {
private static final Logger log = Logger.getLogger(GAOptimizationStrategy.class.getName());
public static java.util.Random random = new java.util.Random();
@Override
public OptimizationResult optimize(@NonNull final Project project,
@NonNull final FitnessFunction fitness) {
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/GAOptimizationStrategy.java
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import lombok.NonNull;
import org.jenetics.EnumGene;
import org.jenetics.Optimize;
import org.jenetics.engine.Codec;
import org.jenetics.engine.Engine;
import org.jenetics.engine.EvolutionResult;
import org.jenetics.engine.codecs;
import org.jenetics.util.ISeq;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class GAOptimizationStrategy extends AbstractOptimizationStrategy {
private static final Logger log = Logger.getLogger(GAOptimizationStrategy.class.getName());
public static java.util.Random random = new java.util.Random();
@Override
public OptimizationResult optimize(@NonNull final Project project,
@NonNull final FitnessFunction fitness) {
| final ISeq<PanelInstance> panels = ISeq.of(project.getPanelInstances());
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/model/Project.java | // Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java
// @ToString
// public class OptimizationResult implements Serializable {
//
// private final List<Layout> layouts = new ArrayList<>();
// private double runtime;
//
// public void createNewLayout(@NonNull PanelInstance p) {
// addLayout(new Layout(p.getSheet(), layouts.size()));
// }
//
// private void addLayout(Layout l) {
// layouts.add(l);
// }
//
// public OptimizationResultStats getStats() {
// int numberOfCuts = 0;
// int numberOfLayouts = layouts.size();
// double totalCutLength = 0;
// double sheetArea = 0;
// double usedArea = 0;
// double boundingBoxArea = 0;
// for (Layout layout : layouts) {
// CutTreeStats substats = layout.getCutTree().getStats();
// numberOfCuts += substats.getNumberOfCuts();
// totalCutLength += substats.getTotalCutLength();
// sheetArea += substats.getSheetArea();
// usedArea += substats.getUsedArea();
// boundingBoxArea += substats.getBoundingBoxArea();
// }
// OptimizationResultStats stats = new OptimizationResultStats(numberOfLayouts,
// numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
// return stats;
// }
//
// public List<Layout> getLayouts() {
// return layouts;
// }
//
// public double getRuntime() {
// return runtime;
// }
//
// public void setRuntime(double runtime) {
// this.runtime = runtime;
// }
//
// }
| import com.cutlet.lib.optimizer.OptimizationResult;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
// we use guava's Optional here, because it is serializable, jdks is not
// http://stackoverflow.com/a/39637752/1689451
/**
*
* @author rmuehlba
*/
public class Project implements Serializable {
private List<Panel> panels = new ArrayList<>();
private double bladeWidth = 3;
| // Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java
// @ToString
// public class OptimizationResult implements Serializable {
//
// private final List<Layout> layouts = new ArrayList<>();
// private double runtime;
//
// public void createNewLayout(@NonNull PanelInstance p) {
// addLayout(new Layout(p.getSheet(), layouts.size()));
// }
//
// private void addLayout(Layout l) {
// layouts.add(l);
// }
//
// public OptimizationResultStats getStats() {
// int numberOfCuts = 0;
// int numberOfLayouts = layouts.size();
// double totalCutLength = 0;
// double sheetArea = 0;
// double usedArea = 0;
// double boundingBoxArea = 0;
// for (Layout layout : layouts) {
// CutTreeStats substats = layout.getCutTree().getStats();
// numberOfCuts += substats.getNumberOfCuts();
// totalCutLength += substats.getTotalCutLength();
// sheetArea += substats.getSheetArea();
// usedArea += substats.getUsedArea();
// boundingBoxArea += substats.getBoundingBoxArea();
// }
// OptimizationResultStats stats = new OptimizationResultStats(numberOfLayouts,
// numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
// return stats;
// }
//
// public List<Layout> getLayouts() {
// return layouts;
// }
//
// public double getRuntime() {
// return runtime;
// }
//
// public void setRuntime(double runtime) {
// this.runtime = runtime;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
import com.cutlet.lib.optimizer.OptimizationResult;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
// we use guava's Optional here, because it is serializable, jdks is not
// http://stackoverflow.com/a/39637752/1689451
/**
*
* @author rmuehlba
*/
public class Project implements Serializable {
private List<Panel> panels = new ArrayList<>();
private double bladeWidth = 3;
| private Optional<OptimizationResult> optimizationResult;
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/testing/DataNoPanels.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class DataNoPanels extends AbstractTestData {
@Override
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataNoPanels.java
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class DataNoPanels extends AbstractTestData {
@Override
| public Project getData() {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/testing/DataNoPanels.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class DataNoPanels extends AbstractTestData {
@Override
public Project getData() {
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataNoPanels.java
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class DataNoPanels extends AbstractTestData {
@Override
public Project getData() {
| StockSheet sheet = makeSheet(800, 600);
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/testing/DataNoPanels.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class DataNoPanels extends AbstractTestData {
@Override
public Project getData() {
StockSheet sheet = makeSheet(800, 600);
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataNoPanels.java
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class DataNoPanels extends AbstractTestData {
@Override
public Project getData() {
StockSheet sheet = makeSheet(800, 600);
| List<Panel> inputs = new ArrayList<>();
|
mru00/cutlet | CutletLib/src/test/java/com/cutlet/lib/optimizer/OptimizerTest.java | // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataRegal.java
// public class DataRegal extends AbstractTestData {
//
// @Override
// public Project getData() {
//
// final StockSheet sheet = makeSheet(2500, 1250);
// int i;
//
// final double w = 600;
// final boolean canRotate = false;
// List<Panel> inputs = new ArrayList<>();
// inputs.add(new Panel(sheet, new Dimension(500, w), "side short", canRotate, 8));
// inputs.add(new Panel(sheet, new Dimension(560, w), "side long", canRotate, 4));
// inputs.add(new Panel(sheet, new Dimension(450, w), "top_bottom", canRotate, 12));
// inputs.add(new Panel(sheet, new Dimension(25, w), "halter", canRotate, 16));
//
// return makeProject(inputs, 4);
// }
//
// @Override
// public String getTitle() {
// return "DataRegal";
// }
//
// }
| import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.testing.DataRegal;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
| /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class OptimizerTest {
public OptimizerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of optimize method, of class Optimizer.
*/
@org.junit.Test
| // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataRegal.java
// public class DataRegal extends AbstractTestData {
//
// @Override
// public Project getData() {
//
// final StockSheet sheet = makeSheet(2500, 1250);
// int i;
//
// final double w = 600;
// final boolean canRotate = false;
// List<Panel> inputs = new ArrayList<>();
// inputs.add(new Panel(sheet, new Dimension(500, w), "side short", canRotate, 8));
// inputs.add(new Panel(sheet, new Dimension(560, w), "side long", canRotate, 4));
// inputs.add(new Panel(sheet, new Dimension(450, w), "top_bottom", canRotate, 12));
// inputs.add(new Panel(sheet, new Dimension(25, w), "halter", canRotate, 16));
//
// return makeProject(inputs, 4);
// }
//
// @Override
// public String getTitle() {
// return "DataRegal";
// }
//
// }
// Path: CutletLib/src/test/java/com/cutlet/lib/optimizer/OptimizerTest.java
import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.testing.DataRegal;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class OptimizerTest {
public OptimizerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of optimize method, of class Optimizer.
*/
@org.junit.Test
| public void testOptimize() throws EmptyProjectException, OptimizationFailedException {
|
mru00/cutlet | CutletLib/src/test/java/com/cutlet/lib/optimizer/OptimizerTest.java | // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataRegal.java
// public class DataRegal extends AbstractTestData {
//
// @Override
// public Project getData() {
//
// final StockSheet sheet = makeSheet(2500, 1250);
// int i;
//
// final double w = 600;
// final boolean canRotate = false;
// List<Panel> inputs = new ArrayList<>();
// inputs.add(new Panel(sheet, new Dimension(500, w), "side short", canRotate, 8));
// inputs.add(new Panel(sheet, new Dimension(560, w), "side long", canRotate, 4));
// inputs.add(new Panel(sheet, new Dimension(450, w), "top_bottom", canRotate, 12));
// inputs.add(new Panel(sheet, new Dimension(25, w), "halter", canRotate, 16));
//
// return makeProject(inputs, 4);
// }
//
// @Override
// public String getTitle() {
// return "DataRegal";
// }
//
// }
| import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.testing.DataRegal;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
| /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class OptimizerTest {
public OptimizerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of optimize method, of class Optimizer.
*/
@org.junit.Test
| // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataRegal.java
// public class DataRegal extends AbstractTestData {
//
// @Override
// public Project getData() {
//
// final StockSheet sheet = makeSheet(2500, 1250);
// int i;
//
// final double w = 600;
// final boolean canRotate = false;
// List<Panel> inputs = new ArrayList<>();
// inputs.add(new Panel(sheet, new Dimension(500, w), "side short", canRotate, 8));
// inputs.add(new Panel(sheet, new Dimension(560, w), "side long", canRotate, 4));
// inputs.add(new Panel(sheet, new Dimension(450, w), "top_bottom", canRotate, 12));
// inputs.add(new Panel(sheet, new Dimension(25, w), "halter", canRotate, 16));
//
// return makeProject(inputs, 4);
// }
//
// @Override
// public String getTitle() {
// return "DataRegal";
// }
//
// }
// Path: CutletLib/src/test/java/com/cutlet/lib/optimizer/OptimizerTest.java
import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.testing.DataRegal;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class OptimizerTest {
public OptimizerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of optimize method, of class Optimizer.
*/
@org.junit.Test
| public void testOptimize() throws EmptyProjectException, OptimizationFailedException {
|
mru00/cutlet | CutletLib/src/test/java/com/cutlet/lib/optimizer/OptimizerTest.java | // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataRegal.java
// public class DataRegal extends AbstractTestData {
//
// @Override
// public Project getData() {
//
// final StockSheet sheet = makeSheet(2500, 1250);
// int i;
//
// final double w = 600;
// final boolean canRotate = false;
// List<Panel> inputs = new ArrayList<>();
// inputs.add(new Panel(sheet, new Dimension(500, w), "side short", canRotate, 8));
// inputs.add(new Panel(sheet, new Dimension(560, w), "side long", canRotate, 4));
// inputs.add(new Panel(sheet, new Dimension(450, w), "top_bottom", canRotate, 12));
// inputs.add(new Panel(sheet, new Dimension(25, w), "halter", canRotate, 16));
//
// return makeProject(inputs, 4);
// }
//
// @Override
// public String getTitle() {
// return "DataRegal";
// }
//
// }
| import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.testing.DataRegal;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
| /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class OptimizerTest {
public OptimizerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of optimize method, of class Optimizer.
*/
@org.junit.Test
public void testOptimize() throws EmptyProjectException, OptimizationFailedException {
System.out.println("optimize");
| // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataRegal.java
// public class DataRegal extends AbstractTestData {
//
// @Override
// public Project getData() {
//
// final StockSheet sheet = makeSheet(2500, 1250);
// int i;
//
// final double w = 600;
// final boolean canRotate = false;
// List<Panel> inputs = new ArrayList<>();
// inputs.add(new Panel(sheet, new Dimension(500, w), "side short", canRotate, 8));
// inputs.add(new Panel(sheet, new Dimension(560, w), "side long", canRotate, 4));
// inputs.add(new Panel(sheet, new Dimension(450, w), "top_bottom", canRotate, 12));
// inputs.add(new Panel(sheet, new Dimension(25, w), "halter", canRotate, 16));
//
// return makeProject(inputs, 4);
// }
//
// @Override
// public String getTitle() {
// return "DataRegal";
// }
//
// }
// Path: CutletLib/src/test/java/com/cutlet/lib/optimizer/OptimizerTest.java
import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.testing.DataRegal;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class OptimizerTest {
public OptimizerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of optimize method, of class Optimizer.
*/
@org.junit.Test
public void testOptimize() throws EmptyProjectException, OptimizationFailedException {
System.out.println("optimize");
| Project project = (new DataRegal()).getData();
|
mru00/cutlet | CutletLib/src/test/java/com/cutlet/lib/optimizer/OptimizerTest.java | // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataRegal.java
// public class DataRegal extends AbstractTestData {
//
// @Override
// public Project getData() {
//
// final StockSheet sheet = makeSheet(2500, 1250);
// int i;
//
// final double w = 600;
// final boolean canRotate = false;
// List<Panel> inputs = new ArrayList<>();
// inputs.add(new Panel(sheet, new Dimension(500, w), "side short", canRotate, 8));
// inputs.add(new Panel(sheet, new Dimension(560, w), "side long", canRotate, 4));
// inputs.add(new Panel(sheet, new Dimension(450, w), "top_bottom", canRotate, 12));
// inputs.add(new Panel(sheet, new Dimension(25, w), "halter", canRotate, 16));
//
// return makeProject(inputs, 4);
// }
//
// @Override
// public String getTitle() {
// return "DataRegal";
// }
//
// }
| import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.testing.DataRegal;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
| /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class OptimizerTest {
public OptimizerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of optimize method, of class Optimizer.
*/
@org.junit.Test
public void testOptimize() throws EmptyProjectException, OptimizationFailedException {
System.out.println("optimize");
| // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/DataRegal.java
// public class DataRegal extends AbstractTestData {
//
// @Override
// public Project getData() {
//
// final StockSheet sheet = makeSheet(2500, 1250);
// int i;
//
// final double w = 600;
// final boolean canRotate = false;
// List<Panel> inputs = new ArrayList<>();
// inputs.add(new Panel(sheet, new Dimension(500, w), "side short", canRotate, 8));
// inputs.add(new Panel(sheet, new Dimension(560, w), "side long", canRotate, 4));
// inputs.add(new Panel(sheet, new Dimension(450, w), "top_bottom", canRotate, 12));
// inputs.add(new Panel(sheet, new Dimension(25, w), "halter", canRotate, 16));
//
// return makeProject(inputs, 4);
// }
//
// @Override
// public String getTitle() {
// return "DataRegal";
// }
//
// }
// Path: CutletLib/src/test/java/com/cutlet/lib/optimizer/OptimizerTest.java
import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.testing.DataRegal;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class OptimizerTest {
public OptimizerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of optimize method, of class Optimizer.
*/
@org.junit.Test
public void testOptimize() throws EmptyProjectException, OptimizationFailedException {
System.out.println("optimize");
| Project project = (new DataRegal()).getData();
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/SmartOptimizationStrategy.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
| import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class SmartOptimizationStrategy extends AbstractOptimizationStrategy {
private static final Logger log = Logger.getLogger(SmartOptimizationStrategy.class.getName());
@Override
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/SmartOptimizationStrategy.java
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class SmartOptimizationStrategy extends AbstractOptimizationStrategy {
private static final Logger log = Logger.getLogger(SmartOptimizationStrategy.class.getName());
@Override
| public OptimizationResult optimize(@NonNull Project project, @NonNull FitnessFunction fitness) {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/SmartOptimizationStrategy.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
| import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class SmartOptimizationStrategy extends AbstractOptimizationStrategy {
private static final Logger log = Logger.getLogger(SmartOptimizationStrategy.class.getName());
@Override
public OptimizationResult optimize(@NonNull Project project, @NonNull FitnessFunction fitness) {
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/SmartOptimizationStrategy.java
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class SmartOptimizationStrategy extends AbstractOptimizationStrategy {
private static final Logger log = Logger.getLogger(SmartOptimizationStrategy.class.getName());
@Override
public OptimizationResult optimize(@NonNull Project project, @NonNull FitnessFunction fitness) {
| List<PanelInstance> panels = project.getPanelInstances().stream()
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/PermutationOptimizationStrategy.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
| import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import com.cutlet.lib.errors.OptimizationFailedException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.logging.Logger;
import java.lang.reflect.Array;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class PermutationOptimizationStrategy extends AbstractOptimizationStrategy {
private final Logger log = Logger.getLogger("PermutationOptimizationStrategy");
@Override
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/PermutationOptimizationStrategy.java
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import com.cutlet.lib.errors.OptimizationFailedException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.logging.Logger;
import java.lang.reflect.Array;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class PermutationOptimizationStrategy extends AbstractOptimizationStrategy {
private final Logger log = Logger.getLogger("PermutationOptimizationStrategy");
@Override
| public OptimizationResult optimize(Project project, FitnessFunction fitness) throws OptimizationFailedException {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/PermutationOptimizationStrategy.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
| import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import com.cutlet.lib.errors.OptimizationFailedException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.logging.Logger;
import java.lang.reflect.Array;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class PermutationOptimizationStrategy extends AbstractOptimizationStrategy {
private final Logger log = Logger.getLogger("PermutationOptimizationStrategy");
@Override
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/PermutationOptimizationStrategy.java
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import com.cutlet.lib.errors.OptimizationFailedException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.logging.Logger;
import java.lang.reflect.Array;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class PermutationOptimizationStrategy extends AbstractOptimizationStrategy {
private final Logger log = Logger.getLogger("PermutationOptimizationStrategy");
@Override
| public OptimizationResult optimize(Project project, FitnessFunction fitness) throws OptimizationFailedException {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
// @ToString
// public class Layout implements Serializable {
//
// private final StockSheet sheet;
// private final int id;
// private final CutTree cutTree;
//
// public Layout(@NonNull final StockSheet sheet, final int id) {
// this.sheet = sheet;
// this.id = id;
// this.cutTree = new CutTree(sheet);
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public int getId() {
// return id;
// }
//
// public int getNumberOfPlacedPanels() {
// int num = 0;
// for (CutTreeNode node : getCutTree()) {
// if (node instanceof PanelNode) {
// num++;
// }
// }
// return num;
// }
//
// public int getNumberOfSubSheets() {
// int num = 0;
// for (CutTreeNode n : getCutTree()) {
// num++;
// }
// return num;
// }
//
// public CutTree getCutTree() {
// return cutTree;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeStats.java
// @ToString
// public class CutTreeStats {
//
// private final int numberOfCuts;
// private final double totalCutLength;
// private final double sheetArea;
// private final double usedArea;
// private final double wastagePercent;
// private final double boundingBoxArea;
//
// public CutTreeStats(
// final int numberOfCuts,
// final double totalCutLength,
// final double sheetArea,
// final double usedArea,
// final double boundingBoxArea) {
//
// this.numberOfCuts = numberOfCuts;
// this.totalCutLength = totalCutLength;
// this.sheetArea = sheetArea;
// this.usedArea = usedArea;
// this.wastagePercent = 100 * (1 - (usedArea / sheetArea));
// this.boundingBoxArea = boundingBoxArea;
// }
//
// public int getNumberOfCuts() {
// return numberOfCuts;
// }
//
// public double getTotalCutLength() {
// return totalCutLength;
// }
//
// public double getSheetArea() {
// return sheetArea;
// }
//
// public double getUsedArea() {
// return usedArea;
// }
//
// public double getWastagePercent() {
// return wastagePercent;
// }
//
// public double getBoundingBoxArea() {
// return boundingBoxArea;
// }
//
// }
| import com.cutlet.lib.model.Layout;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.data.cuttree.CutTreeStats;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import lombok.NonNull;
import lombok.ToString;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
@ToString
public class OptimizationResult implements Serializable {
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
// @ToString
// public class Layout implements Serializable {
//
// private final StockSheet sheet;
// private final int id;
// private final CutTree cutTree;
//
// public Layout(@NonNull final StockSheet sheet, final int id) {
// this.sheet = sheet;
// this.id = id;
// this.cutTree = new CutTree(sheet);
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public int getId() {
// return id;
// }
//
// public int getNumberOfPlacedPanels() {
// int num = 0;
// for (CutTreeNode node : getCutTree()) {
// if (node instanceof PanelNode) {
// num++;
// }
// }
// return num;
// }
//
// public int getNumberOfSubSheets() {
// int num = 0;
// for (CutTreeNode n : getCutTree()) {
// num++;
// }
// return num;
// }
//
// public CutTree getCutTree() {
// return cutTree;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeStats.java
// @ToString
// public class CutTreeStats {
//
// private final int numberOfCuts;
// private final double totalCutLength;
// private final double sheetArea;
// private final double usedArea;
// private final double wastagePercent;
// private final double boundingBoxArea;
//
// public CutTreeStats(
// final int numberOfCuts,
// final double totalCutLength,
// final double sheetArea,
// final double usedArea,
// final double boundingBoxArea) {
//
// this.numberOfCuts = numberOfCuts;
// this.totalCutLength = totalCutLength;
// this.sheetArea = sheetArea;
// this.usedArea = usedArea;
// this.wastagePercent = 100 * (1 - (usedArea / sheetArea));
// this.boundingBoxArea = boundingBoxArea;
// }
//
// public int getNumberOfCuts() {
// return numberOfCuts;
// }
//
// public double getTotalCutLength() {
// return totalCutLength;
// }
//
// public double getSheetArea() {
// return sheetArea;
// }
//
// public double getUsedArea() {
// return usedArea;
// }
//
// public double getWastagePercent() {
// return wastagePercent;
// }
//
// public double getBoundingBoxArea() {
// return boundingBoxArea;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java
import com.cutlet.lib.model.Layout;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.data.cuttree.CutTreeStats;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import lombok.NonNull;
import lombok.ToString;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
@ToString
public class OptimizationResult implements Serializable {
| private final List<Layout> layouts = new ArrayList<>();
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
// @ToString
// public class Layout implements Serializable {
//
// private final StockSheet sheet;
// private final int id;
// private final CutTree cutTree;
//
// public Layout(@NonNull final StockSheet sheet, final int id) {
// this.sheet = sheet;
// this.id = id;
// this.cutTree = new CutTree(sheet);
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public int getId() {
// return id;
// }
//
// public int getNumberOfPlacedPanels() {
// int num = 0;
// for (CutTreeNode node : getCutTree()) {
// if (node instanceof PanelNode) {
// num++;
// }
// }
// return num;
// }
//
// public int getNumberOfSubSheets() {
// int num = 0;
// for (CutTreeNode n : getCutTree()) {
// num++;
// }
// return num;
// }
//
// public CutTree getCutTree() {
// return cutTree;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeStats.java
// @ToString
// public class CutTreeStats {
//
// private final int numberOfCuts;
// private final double totalCutLength;
// private final double sheetArea;
// private final double usedArea;
// private final double wastagePercent;
// private final double boundingBoxArea;
//
// public CutTreeStats(
// final int numberOfCuts,
// final double totalCutLength,
// final double sheetArea,
// final double usedArea,
// final double boundingBoxArea) {
//
// this.numberOfCuts = numberOfCuts;
// this.totalCutLength = totalCutLength;
// this.sheetArea = sheetArea;
// this.usedArea = usedArea;
// this.wastagePercent = 100 * (1 - (usedArea / sheetArea));
// this.boundingBoxArea = boundingBoxArea;
// }
//
// public int getNumberOfCuts() {
// return numberOfCuts;
// }
//
// public double getTotalCutLength() {
// return totalCutLength;
// }
//
// public double getSheetArea() {
// return sheetArea;
// }
//
// public double getUsedArea() {
// return usedArea;
// }
//
// public double getWastagePercent() {
// return wastagePercent;
// }
//
// public double getBoundingBoxArea() {
// return boundingBoxArea;
// }
//
// }
| import com.cutlet.lib.model.Layout;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.data.cuttree.CutTreeStats;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import lombok.NonNull;
import lombok.ToString;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
@ToString
public class OptimizationResult implements Serializable {
private final List<Layout> layouts = new ArrayList<>();
private double runtime;
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
// @ToString
// public class Layout implements Serializable {
//
// private final StockSheet sheet;
// private final int id;
// private final CutTree cutTree;
//
// public Layout(@NonNull final StockSheet sheet, final int id) {
// this.sheet = sheet;
// this.id = id;
// this.cutTree = new CutTree(sheet);
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public int getId() {
// return id;
// }
//
// public int getNumberOfPlacedPanels() {
// int num = 0;
// for (CutTreeNode node : getCutTree()) {
// if (node instanceof PanelNode) {
// num++;
// }
// }
// return num;
// }
//
// public int getNumberOfSubSheets() {
// int num = 0;
// for (CutTreeNode n : getCutTree()) {
// num++;
// }
// return num;
// }
//
// public CutTree getCutTree() {
// return cutTree;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeStats.java
// @ToString
// public class CutTreeStats {
//
// private final int numberOfCuts;
// private final double totalCutLength;
// private final double sheetArea;
// private final double usedArea;
// private final double wastagePercent;
// private final double boundingBoxArea;
//
// public CutTreeStats(
// final int numberOfCuts,
// final double totalCutLength,
// final double sheetArea,
// final double usedArea,
// final double boundingBoxArea) {
//
// this.numberOfCuts = numberOfCuts;
// this.totalCutLength = totalCutLength;
// this.sheetArea = sheetArea;
// this.usedArea = usedArea;
// this.wastagePercent = 100 * (1 - (usedArea / sheetArea));
// this.boundingBoxArea = boundingBoxArea;
// }
//
// public int getNumberOfCuts() {
// return numberOfCuts;
// }
//
// public double getTotalCutLength() {
// return totalCutLength;
// }
//
// public double getSheetArea() {
// return sheetArea;
// }
//
// public double getUsedArea() {
// return usedArea;
// }
//
// public double getWastagePercent() {
// return wastagePercent;
// }
//
// public double getBoundingBoxArea() {
// return boundingBoxArea;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java
import com.cutlet.lib.model.Layout;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.data.cuttree.CutTreeStats;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import lombok.NonNull;
import lombok.ToString;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
@ToString
public class OptimizationResult implements Serializable {
private final List<Layout> layouts = new ArrayList<>();
private double runtime;
| public void createNewLayout(@NonNull PanelInstance p) {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
// @ToString
// public class Layout implements Serializable {
//
// private final StockSheet sheet;
// private final int id;
// private final CutTree cutTree;
//
// public Layout(@NonNull final StockSheet sheet, final int id) {
// this.sheet = sheet;
// this.id = id;
// this.cutTree = new CutTree(sheet);
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public int getId() {
// return id;
// }
//
// public int getNumberOfPlacedPanels() {
// int num = 0;
// for (CutTreeNode node : getCutTree()) {
// if (node instanceof PanelNode) {
// num++;
// }
// }
// return num;
// }
//
// public int getNumberOfSubSheets() {
// int num = 0;
// for (CutTreeNode n : getCutTree()) {
// num++;
// }
// return num;
// }
//
// public CutTree getCutTree() {
// return cutTree;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeStats.java
// @ToString
// public class CutTreeStats {
//
// private final int numberOfCuts;
// private final double totalCutLength;
// private final double sheetArea;
// private final double usedArea;
// private final double wastagePercent;
// private final double boundingBoxArea;
//
// public CutTreeStats(
// final int numberOfCuts,
// final double totalCutLength,
// final double sheetArea,
// final double usedArea,
// final double boundingBoxArea) {
//
// this.numberOfCuts = numberOfCuts;
// this.totalCutLength = totalCutLength;
// this.sheetArea = sheetArea;
// this.usedArea = usedArea;
// this.wastagePercent = 100 * (1 - (usedArea / sheetArea));
// this.boundingBoxArea = boundingBoxArea;
// }
//
// public int getNumberOfCuts() {
// return numberOfCuts;
// }
//
// public double getTotalCutLength() {
// return totalCutLength;
// }
//
// public double getSheetArea() {
// return sheetArea;
// }
//
// public double getUsedArea() {
// return usedArea;
// }
//
// public double getWastagePercent() {
// return wastagePercent;
// }
//
// public double getBoundingBoxArea() {
// return boundingBoxArea;
// }
//
// }
| import com.cutlet.lib.model.Layout;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.data.cuttree.CutTreeStats;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import lombok.NonNull;
import lombok.ToString;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
@ToString
public class OptimizationResult implements Serializable {
private final List<Layout> layouts = new ArrayList<>();
private double runtime;
public void createNewLayout(@NonNull PanelInstance p) {
addLayout(new Layout(p.getSheet(), layouts.size()));
}
private void addLayout(Layout l) {
layouts.add(l);
}
public OptimizationResultStats getStats() {
int numberOfCuts = 0;
int numberOfLayouts = layouts.size();
double totalCutLength = 0;
double sheetArea = 0;
double usedArea = 0;
double boundingBoxArea = 0;
for (Layout layout : layouts) {
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
// @ToString
// public class Layout implements Serializable {
//
// private final StockSheet sheet;
// private final int id;
// private final CutTree cutTree;
//
// public Layout(@NonNull final StockSheet sheet, final int id) {
// this.sheet = sheet;
// this.id = id;
// this.cutTree = new CutTree(sheet);
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public int getId() {
// return id;
// }
//
// public int getNumberOfPlacedPanels() {
// int num = 0;
// for (CutTreeNode node : getCutTree()) {
// if (node instanceof PanelNode) {
// num++;
// }
// }
// return num;
// }
//
// public int getNumberOfSubSheets() {
// int num = 0;
// for (CutTreeNode n : getCutTree()) {
// num++;
// }
// return num;
// }
//
// public CutTree getCutTree() {
// return cutTree;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeStats.java
// @ToString
// public class CutTreeStats {
//
// private final int numberOfCuts;
// private final double totalCutLength;
// private final double sheetArea;
// private final double usedArea;
// private final double wastagePercent;
// private final double boundingBoxArea;
//
// public CutTreeStats(
// final int numberOfCuts,
// final double totalCutLength,
// final double sheetArea,
// final double usedArea,
// final double boundingBoxArea) {
//
// this.numberOfCuts = numberOfCuts;
// this.totalCutLength = totalCutLength;
// this.sheetArea = sheetArea;
// this.usedArea = usedArea;
// this.wastagePercent = 100 * (1 - (usedArea / sheetArea));
// this.boundingBoxArea = boundingBoxArea;
// }
//
// public int getNumberOfCuts() {
// return numberOfCuts;
// }
//
// public double getTotalCutLength() {
// return totalCutLength;
// }
//
// public double getSheetArea() {
// return sheetArea;
// }
//
// public double getUsedArea() {
// return usedArea;
// }
//
// public double getWastagePercent() {
// return wastagePercent;
// }
//
// public double getBoundingBoxArea() {
// return boundingBoxArea;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/OptimizationResult.java
import com.cutlet.lib.model.Layout;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.data.cuttree.CutTreeStats;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import lombok.NonNull;
import lombok.ToString;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
@ToString
public class OptimizationResult implements Serializable {
private final List<Layout> layouts = new ArrayList<>();
private double runtime;
public void createNewLayout(@NonNull PanelInstance p) {
addLayout(new Layout(p.getSheet(), layouts.size()));
}
private void addLayout(Layout l) {
layouts.add(l);
}
public OptimizationResultStats getStats() {
int numberOfCuts = 0;
int numberOfLayouts = layouts.size();
double totalCutLength = 0;
double sheetArea = 0;
double usedArea = 0;
double boundingBoxArea = 0;
for (Layout layout : layouts) {
| CutTreeStats substats = layout.getCutTree().getStats();
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
import com.cutlet.lib.model.StockSheet;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public class CutTree implements Iterable<CutTreeNode>, Serializable {
private final RootNode root;
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
import com.cutlet.lib.model.StockSheet;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public class CutTree implements Iterable<CutTreeNode>, Serializable {
private final RootNode root;
| public CutTree(@NonNull final StockSheet sheet) {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
import com.cutlet.lib.model.StockSheet;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public class CutTree implements Iterable<CutTreeNode>, Serializable {
private final RootNode root;
public CutTree(@NonNull final StockSheet sheet) {
root = new RootNode(sheet.getDimension());
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
import com.cutlet.lib.model.StockSheet;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public class CutTree implements Iterable<CutTreeNode>, Serializable {
private final RootNode root;
public CutTree(@NonNull final StockSheet sheet) {
root = new RootNode(sheet.getDimension());
| final FreeNode free = new FreeNode(root, new Position(0, 0), sheet.getDimension());
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
import com.cutlet.lib.model.StockSheet;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import lombok.NonNull;
| free.add((FreeNode) node);
}
}
return free;
}
@Override
public Iterator<CutTreeNode> iterator() {
return new CutTreeIterator(this);
}
public CutTreeStats getStats() {
int numberOfCuts = 0;
double totalCutLength = 0;
double sheetArea = root.getDimension().getArea();
double usedArea = 0;
double boundingBoxMinX = Double.MAX_VALUE;
double boundingBoxMaxX = Double.MIN_VALUE;
double boundingBoxMinY = Double.MAX_VALUE;
double boundingBoxMaxY = Double.MIN_VALUE;
for (CutTreeNode node : this) {
if (node instanceof FreeNode) {
} else if (node instanceof PanelNode) {
final PanelNode pn = (PanelNode) node;
usedArea += pn.getDimension().getArea();
// this is only partly correct...
// we should also take cuts into consideration!
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Position;
import com.cutlet.lib.model.StockSheet;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import lombok.NonNull;
free.add((FreeNode) node);
}
}
return free;
}
@Override
public Iterator<CutTreeNode> iterator() {
return new CutTreeIterator(this);
}
public CutTreeStats getStats() {
int numberOfCuts = 0;
double totalCutLength = 0;
double sheetArea = root.getDimension().getArea();
double usedArea = 0;
double boundingBoxMinX = Double.MAX_VALUE;
double boundingBoxMaxX = Double.MIN_VALUE;
double boundingBoxMinY = Double.MAX_VALUE;
double boundingBoxMaxY = Double.MIN_VALUE;
for (CutTreeNode node : this) {
if (node instanceof FreeNode) {
} else if (node instanceof PanelNode) {
final PanelNode pn = (PanelNode) node;
usedArea += pn.getDimension().getArea();
// this is only partly correct...
// we should also take cuts into consideration!
| Dimension dim = pn.getDimension();
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java | // Path: CutletLib/src/main/java/com/cutlet/lib/material/Material.java
// public interface Material {
//
// }
| import lombok.NonNull;
import lombok.ToString;
import com.cutlet.lib.material.Material;
import java.io.Serializable;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
/**
*
* @author rmuehlba
*/
@ToString
public class StockSheet implements Serializable {
| // Path: CutletLib/src/main/java/com/cutlet/lib/material/Material.java
// public interface Material {
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
import lombok.NonNull;
import lombok.ToString;
import com.cutlet.lib.material.Material;
import java.io.Serializable;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
/**
*
* @author rmuehlba
*/
@ToString
public class StockSheet implements Serializable {
| private final Material material;
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/testing/Data1.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class Data1 extends AbstractTestData {
@Override
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/Data1.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class Data1 extends AbstractTestData {
@Override
| public Project getData() {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/testing/Data1.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class Data1 extends AbstractTestData {
@Override
public Project getData() {
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/Data1.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class Data1 extends AbstractTestData {
@Override
public Project getData() {
| StockSheet sheet = makeSheet(800, 600);
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/testing/Data1.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class Data1 extends AbstractTestData {
@Override
public Project getData() {
StockSheet sheet = makeSheet(800, 600);
final boolean canRotate = false;
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/Data1.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class Data1 extends AbstractTestData {
@Override
public Project getData() {
StockSheet sheet = makeSheet(800, 600);
final boolean canRotate = false;
| List<Panel> inputs = new ArrayList<>();
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/testing/Data1.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class Data1 extends AbstractTestData {
@Override
public Project getData() {
StockSheet sheet = makeSheet(800, 600);
final boolean canRotate = false;
List<Panel> inputs = new ArrayList<>();
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Panel.java
// @ToString(exclude = "sheet")
// public class Panel implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int count;
//
// public String getTitle() {
// return title;
// }
//
// public Panel(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final boolean canRotate,
// final int count) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.count = count;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public boolean canRotate() {
// return canRotate;
// }
//
// public boolean isCanRotate() {
// return canRotate;
// }
//
// public int getCount() {
// return count;
// }
//
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/StockSheet.java
// @ToString
// public class StockSheet implements Serializable {
//
// private final Material material;
// private final double thickness;
// private final String title;
// private final Dimension dimension;
//
//
//
// public StockSheet(@NonNull final String title,
// @NonNull final Material material,
// @NonNull final Dimension dimension,
// final double thickness) {
//
// this.material = material;
// this.dimension = dimension;
// this.thickness = thickness;
// this.title = title;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public double getThickness() {
// return thickness;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/testing/Data1.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.Panel;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.model.StockSheet;
import java.util.ArrayList;
import java.util.List;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.testing;
/**
*
* @author rmuehlba
*/
public class Data1 extends AbstractTestData {
@Override
public Project getData() {
StockSheet sheet = makeSheet(800, 600);
final boolean canRotate = false;
List<Panel> inputs = new ArrayList<>();
| inputs.add(new Panel(sheet, new Dimension(100, 100), "p1", canRotate, 1));
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/RootNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
| import lombok.NonNull;
import com.cutlet.lib.model.Dimension;
import java.io.Serializable;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public class RootNode implements CutTreeNode, Serializable {
private CutTreeNode child;
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/RootNode.java
import lombok.NonNull;
import com.cutlet.lib.model.Dimension;
import java.io.Serializable;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public class RootNode implements CutTreeNode, Serializable {
private CutTreeNode child;
| private Dimension dimension;
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/NaiiveOptimizationStrategy.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
| import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class NaiiveOptimizationStrategy extends AbstractOptimizationStrategy {
private final static Logger log = Logger.getLogger(NaiiveOptimizationStrategy.class.getName());
@Override
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/NaiiveOptimizationStrategy.java
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class NaiiveOptimizationStrategy extends AbstractOptimizationStrategy {
private final static Logger log = Logger.getLogger(NaiiveOptimizationStrategy.class.getName());
@Override
| public OptimizationResult optimize(@NonNull final Project project, @NonNull final FitnessFunction fitness) {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/NaiiveOptimizationStrategy.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
| import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class NaiiveOptimizationStrategy extends AbstractOptimizationStrategy {
private final static Logger log = Logger.getLogger(NaiiveOptimizationStrategy.class.getName());
@Override
public OptimizationResult optimize(@NonNull final Project project, @NonNull final FitnessFunction fitness) {
OptimizationResult optimizationResult = new OptimizationResult();
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/NaiiveOptimizationStrategy.java
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class NaiiveOptimizationStrategy extends AbstractOptimizationStrategy {
private final static Logger log = Logger.getLogger(NaiiveOptimizationStrategy.class.getName());
@Override
public OptimizationResult optimize(@NonNull final Project project, @NonNull final FitnessFunction fitness) {
OptimizationResult optimizationResult = new OptimizationResult();
| List<PanelInstance> panels = project.getPanelInstances().stream()
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/NaiiveOptimizationStrategy.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
| import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class NaiiveOptimizationStrategy extends AbstractOptimizationStrategy {
private final static Logger log = Logger.getLogger(NaiiveOptimizationStrategy.class.getName());
@Override
public OptimizationResult optimize(@NonNull final Project project, @NonNull final FitnessFunction fitness) {
OptimizationResult optimizationResult = new OptimizationResult();
List<PanelInstance> panels = project.getPanelInstances().stream()
.sorted((b, a) -> Double.compare(a.getDimension().getLength(), b.getDimension().getLength()))
.collect(Collectors.toList());
for (PanelInstance p : panels) {
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/FreeNode.java
// public class FreeNode extends AbstractCutTreeNode {
//
// public FreeNode(@NonNull CutTreeNode parent, @NonNull Position position, @NonNull Dimension dimension) {
// super(parent, position, dimension);
// }
//
// @Override
// public void replaceChild(@NonNull CutTreeNode from, @NonNull CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
//
// public CutNode cut(double bladeWidth, double cutPosition, @NonNull CutNode.Direction direction) {
// final CutTreeNode parent = this.getParent();
// final CutNode cut = new CutNode(parent,
// bladeWidth, cutPosition, direction,
// getPosition(),
// getDimension());
//
// parent.replaceChild(this, cut);
//
// return cut;
// }
//
// public PanelNode setPanel(@NonNull PanelInstance panel) {
// final CutTreeNode parent = this.getParent();
// final PanelNode pn = new PanelNode(parent, panel, getPosition(), getDimension());
// parent.replaceChild(this, pn);
// return pn;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/NaiiveOptimizationStrategy.java
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Project;
import com.cutlet.lib.data.cuttree.FreeNode;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class NaiiveOptimizationStrategy extends AbstractOptimizationStrategy {
private final static Logger log = Logger.getLogger(NaiiveOptimizationStrategy.class.getName());
@Override
public OptimizationResult optimize(@NonNull final Project project, @NonNull final FitnessFunction fitness) {
OptimizationResult optimizationResult = new OptimizationResult();
List<PanelInstance> panels = project.getPanelInstances().stream()
.sorted((b, a) -> Double.compare(a.getDimension().getLength(), b.getDimension().getLength()))
.collect(Collectors.toList());
for (PanelInstance p : panels) {
| FreeNode candidate = findSheet(optimizationResult, p);
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/Optimizer.java | // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
| import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.google.common.base.Stopwatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class Optimizer {
private static final Logger log = Logger.getLogger("Optimizer");
| // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/Optimizer.java
import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.google.common.base.Stopwatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class Optimizer {
private static final Logger log = Logger.getLogger("Optimizer");
| public OptimizationResult optimize(@NonNull Project project, @NonNull OptimizationStrategy strategy) throws OptimizationFailedException {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/Optimizer.java | // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
| import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.google.common.base.Stopwatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class Optimizer {
private static final Logger log = Logger.getLogger("Optimizer");
| // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/Optimizer.java
import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.google.common.base.Stopwatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class Optimizer {
private static final Logger log = Logger.getLogger("Optimizer");
| public OptimizationResult optimize(@NonNull Project project, @NonNull OptimizationStrategy strategy) throws OptimizationFailedException {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/optimizer/Optimizer.java | // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
| import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.google.common.base.Stopwatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class Optimizer {
private static final Logger log = Logger.getLogger("Optimizer");
public OptimizationResult optimize(@NonNull Project project, @NonNull OptimizationStrategy strategy) throws OptimizationFailedException {
if (project.getPanels().isEmpty()) {
| // Path: CutletLib/src/main/java/com/cutlet/lib/errors/EmptyProjectException.java
// public class EmptyProjectException extends OptimizationFailedException {
//
// /**
// * Creates a new instance of <code>EmptyProjectException</code> without
// * detail message.
// */
// public EmptyProjectException() {
// }
//
// /**
// * Constructs an instance of <code>EmptyProjectException</code> with the
// * specified detail message.
// *
// * @param msg the detail message.
// */
// public EmptyProjectException(String msg) {
// super(msg);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/errors/OptimizationFailedException.java
// public class OptimizationFailedException extends Exception {
//
// /**
// * Creates a new instance of <code>OptimizationFailedException</code>
// * without detail message.
// */
// public OptimizationFailedException() {
// }
//
// /**
// * Constructs an instance of <code>OptimizationFailedException</code> with
// * the specified detail message.
// *
// * @param msg the detail message.
// */
// public OptimizationFailedException(String msg) {
// super(msg);
// }
//
// public OptimizationFailedException(Throwable other) {
// super(other);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Project.java
// public class Project implements Serializable {
//
// private List<Panel> panels = new ArrayList<>();
// private double bladeWidth = 3;
// private Optional<OptimizationResult> optimizationResult;
//
// public List<Panel> getPanels() {
// return panels;
// }
//
// public void setPanels(@NonNull final List<Panel> inputs) {
// this.panels = inputs;
// }
//
// public double getBladeWidth() {
// return bladeWidth;
// }
//
// public void setBladeWidth(final double bladeWidth) {
// checkArgument(bladeWidth >= 0, "bladeWidth can't be negative");
// this.bladeWidth = bladeWidth;
// }
//
// public Optional<OptimizationResult> getOptimizationResult() {
// return optimizationResult;
// }
//
// public void setOptimizationResult(@NonNull final Optional<OptimizationResult> optimizationResult) {
// this.optimizationResult = optimizationResult;
// }
//
// public void setOptimizationResult(java.util.Optional<OptimizationResult> newValue) {
// if (newValue.isPresent()) {
// this.optimizationResult = Optional.of(newValue.get());
//
// } else {
// this.optimizationResult = Optional.absent();
//
// }
// }
//
// public List<PanelInstance> getPanelInstances() {
// List<PanelInstance> pis = new ArrayList<>();
// for (Panel p : panels) {
// for (int i = 0; i < p.getCount(); i++) {
// pis.add(new PanelInstance(p.getSheet(), p.getDimension(), p.getTitle(), i, p.canRotate()));
// }
// }
// return pis;
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/optimizer/Optimizer.java
import com.cutlet.lib.errors.EmptyProjectException;
import com.cutlet.lib.errors.OptimizationFailedException;
import com.cutlet.lib.model.Project;
import com.google.common.base.Stopwatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.optimizer;
/**
*
* @author rmuehlba
*/
public class Optimizer {
private static final Logger log = Logger.getLogger("Optimizer");
public OptimizationResult optimize(@NonNull Project project, @NonNull OptimizationStrategy strategy) throws OptimizationFailedException {
if (project.getPanels().isEmpty()) {
| throw new EmptyProjectException("Project doesn't have any panels configured; nothing to optimize");
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/AbstractCutTreeNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import java.io.Serializable;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public abstract class AbstractCutTreeNode implements CutTreeNode, Serializable {
private final CutTreeNode parent;
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/AbstractCutTreeNode.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import java.io.Serializable;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public abstract class AbstractCutTreeNode implements CutTreeNode, Serializable {
private final CutTreeNode parent;
| private final Position position;
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/AbstractCutTreeNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import java.io.Serializable;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public abstract class AbstractCutTreeNode implements CutTreeNode, Serializable {
private final CutTreeNode parent;
private final Position position;
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/AbstractCutTreeNode.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import java.io.Serializable;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public abstract class AbstractCutTreeNode implements CutTreeNode, Serializable {
private final CutTreeNode parent;
private final Position position;
| private final Dimension dimension;
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/AbstractCutTreeNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import java.io.Serializable;
import lombok.NonNull;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public abstract class AbstractCutTreeNode implements CutTreeNode, Serializable {
private final CutTreeNode parent;
private final Position position;
private final Dimension dimension;
public AbstractCutTreeNode(@NonNull final CutTreeNode parent,
@NonNull final Position position,
@NonNull final Dimension dimension) {
this.dimension = dimension;
this.position = position;
this.parent = parent;
}
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/AbstractCutTreeNode.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import java.io.Serializable;
import lombok.NonNull;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
public abstract class AbstractCutTreeNode implements CutTreeNode, Serializable {
private final CutTreeNode parent;
private final Position position;
private final Dimension dimension;
public AbstractCutTreeNode(@NonNull final CutTreeNode parent,
@NonNull final Position position,
@NonNull final Dimension dimension) {
this.dimension = dimension;
this.position = position;
this.parent = parent;
}
| public boolean canHold(@NonNull final PanelInstance p) {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/model/Layout.java | // Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java
// public class CutTree implements Iterable<CutTreeNode>, Serializable {
//
// private final RootNode root;
//
// public CutTree(@NonNull final StockSheet sheet) {
// root = new RootNode(sheet.getDimension());
// final FreeNode free = new FreeNode(root, new Position(0, 0), sheet.getDimension());
// root.setChild(free);
// }
//
// public CutTreeNode getRoot() {
// return root;
// }
//
// public List<FreeNode> getFreeNodes() {
// List<FreeNode> free = new ArrayList<>();
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// free.add((FreeNode) node);
// }
// }
// return free;
// }
//
// @Override
// public Iterator<CutTreeNode> iterator() {
// return new CutTreeIterator(this);
// }
//
// public CutTreeStats getStats() {
//
// int numberOfCuts = 0;
// double totalCutLength = 0;
// double sheetArea = root.getDimension().getArea();
// double usedArea = 0;
// double boundingBoxMinX = Double.MAX_VALUE;
// double boundingBoxMaxX = Double.MIN_VALUE;
// double boundingBoxMinY = Double.MAX_VALUE;
// double boundingBoxMaxY = Double.MIN_VALUE;
//
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// } else if (node instanceof PanelNode) {
// final PanelNode pn = (PanelNode) node;
// usedArea += pn.getDimension().getArea();
//
// // this is only partly correct...
// // we should also take cuts into consideration!
// Dimension dim = pn.getDimension();
// Position pos = pn.getPosition();
// boundingBoxMinX = Math.min(pos.getX(), boundingBoxMinX);
// boundingBoxMaxX = Math.max(pos.getX() + dim.getLength(), boundingBoxMaxX);
// boundingBoxMinY = Math.min(pos.getY(), boundingBoxMinY);
// boundingBoxMaxY = Math.max(pos.getY() + dim.getWidth(), boundingBoxMaxY);
//
// } else if (node instanceof CutNode) {
// final CutNode cn = (CutNode) node;
// numberOfCuts++;
// totalCutLength += cn.getCutLength();
// }
// }
// double boundingBoxArea = (boundingBoxMaxX - boundingBoxMinX) * (boundingBoxMaxY - boundingBoxMinY);
//
// CutTreeStats stats = new CutTreeStats(numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
//
// return stats;
// }
//
// class CutTreeIterator implements Iterator<CutTreeNode> {
//
// private final Queue<CutTreeNode> queue = new ArrayDeque<>();
//
// CutTreeIterator(@NonNull final CutTree tree) {
// queue.add(root.getChild());
// }
//
// @Override
// public boolean hasNext() {
// return !queue.isEmpty();
// }
//
// @Override
// public CutTreeNode next() {
//
// if (queue.isEmpty()) {
// throw new RuntimeException("can't get element from empty iterator");
// }
// final CutTreeNode node = queue.remove();
// if (node instanceof CutNode) {
// final CutNode cut = (CutNode) node;
// queue.add(cut.getTarget());
// queue.add(cut.getRest());
// }
// return node;
// }
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeNode.java
// public interface CutTreeNode {
//
// public void replaceChild(@NonNull final CutTreeNode from,
// @NonNull final CutTreeNode to);
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
| import com.cutlet.lib.data.cuttree.CutTree;
import com.cutlet.lib.data.cuttree.CutTreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.io.Serializable;
import lombok.NonNull;
import lombok.ToString;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
/**
*
* @author rmuehlba
*/
@ToString
public class Layout implements Serializable {
private final StockSheet sheet;
private final int id;
| // Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java
// public class CutTree implements Iterable<CutTreeNode>, Serializable {
//
// private final RootNode root;
//
// public CutTree(@NonNull final StockSheet sheet) {
// root = new RootNode(sheet.getDimension());
// final FreeNode free = new FreeNode(root, new Position(0, 0), sheet.getDimension());
// root.setChild(free);
// }
//
// public CutTreeNode getRoot() {
// return root;
// }
//
// public List<FreeNode> getFreeNodes() {
// List<FreeNode> free = new ArrayList<>();
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// free.add((FreeNode) node);
// }
// }
// return free;
// }
//
// @Override
// public Iterator<CutTreeNode> iterator() {
// return new CutTreeIterator(this);
// }
//
// public CutTreeStats getStats() {
//
// int numberOfCuts = 0;
// double totalCutLength = 0;
// double sheetArea = root.getDimension().getArea();
// double usedArea = 0;
// double boundingBoxMinX = Double.MAX_VALUE;
// double boundingBoxMaxX = Double.MIN_VALUE;
// double boundingBoxMinY = Double.MAX_VALUE;
// double boundingBoxMaxY = Double.MIN_VALUE;
//
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// } else if (node instanceof PanelNode) {
// final PanelNode pn = (PanelNode) node;
// usedArea += pn.getDimension().getArea();
//
// // this is only partly correct...
// // we should also take cuts into consideration!
// Dimension dim = pn.getDimension();
// Position pos = pn.getPosition();
// boundingBoxMinX = Math.min(pos.getX(), boundingBoxMinX);
// boundingBoxMaxX = Math.max(pos.getX() + dim.getLength(), boundingBoxMaxX);
// boundingBoxMinY = Math.min(pos.getY(), boundingBoxMinY);
// boundingBoxMaxY = Math.max(pos.getY() + dim.getWidth(), boundingBoxMaxY);
//
// } else if (node instanceof CutNode) {
// final CutNode cn = (CutNode) node;
// numberOfCuts++;
// totalCutLength += cn.getCutLength();
// }
// }
// double boundingBoxArea = (boundingBoxMaxX - boundingBoxMinX) * (boundingBoxMaxY - boundingBoxMinY);
//
// CutTreeStats stats = new CutTreeStats(numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
//
// return stats;
// }
//
// class CutTreeIterator implements Iterator<CutTreeNode> {
//
// private final Queue<CutTreeNode> queue = new ArrayDeque<>();
//
// CutTreeIterator(@NonNull final CutTree tree) {
// queue.add(root.getChild());
// }
//
// @Override
// public boolean hasNext() {
// return !queue.isEmpty();
// }
//
// @Override
// public CutTreeNode next() {
//
// if (queue.isEmpty()) {
// throw new RuntimeException("can't get element from empty iterator");
// }
// final CutTreeNode node = queue.remove();
// if (node instanceof CutNode) {
// final CutNode cut = (CutNode) node;
// queue.add(cut.getTarget());
// queue.add(cut.getRest());
// }
// return node;
// }
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeNode.java
// public interface CutTreeNode {
//
// public void replaceChild(@NonNull final CutTreeNode from,
// @NonNull final CutTreeNode to);
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
import com.cutlet.lib.data.cuttree.CutTree;
import com.cutlet.lib.data.cuttree.CutTreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.io.Serializable;
import lombok.NonNull;
import lombok.ToString;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
/**
*
* @author rmuehlba
*/
@ToString
public class Layout implements Serializable {
private final StockSheet sheet;
private final int id;
| private final CutTree cutTree;
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/model/Layout.java | // Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java
// public class CutTree implements Iterable<CutTreeNode>, Serializable {
//
// private final RootNode root;
//
// public CutTree(@NonNull final StockSheet sheet) {
// root = new RootNode(sheet.getDimension());
// final FreeNode free = new FreeNode(root, new Position(0, 0), sheet.getDimension());
// root.setChild(free);
// }
//
// public CutTreeNode getRoot() {
// return root;
// }
//
// public List<FreeNode> getFreeNodes() {
// List<FreeNode> free = new ArrayList<>();
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// free.add((FreeNode) node);
// }
// }
// return free;
// }
//
// @Override
// public Iterator<CutTreeNode> iterator() {
// return new CutTreeIterator(this);
// }
//
// public CutTreeStats getStats() {
//
// int numberOfCuts = 0;
// double totalCutLength = 0;
// double sheetArea = root.getDimension().getArea();
// double usedArea = 0;
// double boundingBoxMinX = Double.MAX_VALUE;
// double boundingBoxMaxX = Double.MIN_VALUE;
// double boundingBoxMinY = Double.MAX_VALUE;
// double boundingBoxMaxY = Double.MIN_VALUE;
//
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// } else if (node instanceof PanelNode) {
// final PanelNode pn = (PanelNode) node;
// usedArea += pn.getDimension().getArea();
//
// // this is only partly correct...
// // we should also take cuts into consideration!
// Dimension dim = pn.getDimension();
// Position pos = pn.getPosition();
// boundingBoxMinX = Math.min(pos.getX(), boundingBoxMinX);
// boundingBoxMaxX = Math.max(pos.getX() + dim.getLength(), boundingBoxMaxX);
// boundingBoxMinY = Math.min(pos.getY(), boundingBoxMinY);
// boundingBoxMaxY = Math.max(pos.getY() + dim.getWidth(), boundingBoxMaxY);
//
// } else if (node instanceof CutNode) {
// final CutNode cn = (CutNode) node;
// numberOfCuts++;
// totalCutLength += cn.getCutLength();
// }
// }
// double boundingBoxArea = (boundingBoxMaxX - boundingBoxMinX) * (boundingBoxMaxY - boundingBoxMinY);
//
// CutTreeStats stats = new CutTreeStats(numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
//
// return stats;
// }
//
// class CutTreeIterator implements Iterator<CutTreeNode> {
//
// private final Queue<CutTreeNode> queue = new ArrayDeque<>();
//
// CutTreeIterator(@NonNull final CutTree tree) {
// queue.add(root.getChild());
// }
//
// @Override
// public boolean hasNext() {
// return !queue.isEmpty();
// }
//
// @Override
// public CutTreeNode next() {
//
// if (queue.isEmpty()) {
// throw new RuntimeException("can't get element from empty iterator");
// }
// final CutTreeNode node = queue.remove();
// if (node instanceof CutNode) {
// final CutNode cut = (CutNode) node;
// queue.add(cut.getTarget());
// queue.add(cut.getRest());
// }
// return node;
// }
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeNode.java
// public interface CutTreeNode {
//
// public void replaceChild(@NonNull final CutTreeNode from,
// @NonNull final CutTreeNode to);
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
| import com.cutlet.lib.data.cuttree.CutTree;
import com.cutlet.lib.data.cuttree.CutTreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.io.Serializable;
import lombok.NonNull;
import lombok.ToString;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
/**
*
* @author rmuehlba
*/
@ToString
public class Layout implements Serializable {
private final StockSheet sheet;
private final int id;
private final CutTree cutTree;
public Layout(@NonNull final StockSheet sheet, final int id) {
this.sheet = sheet;
this.id = id;
this.cutTree = new CutTree(sheet);
}
public StockSheet getSheet() {
return sheet;
}
public int getId() {
return id;
}
public int getNumberOfPlacedPanels() {
int num = 0;
| // Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java
// public class CutTree implements Iterable<CutTreeNode>, Serializable {
//
// private final RootNode root;
//
// public CutTree(@NonNull final StockSheet sheet) {
// root = new RootNode(sheet.getDimension());
// final FreeNode free = new FreeNode(root, new Position(0, 0), sheet.getDimension());
// root.setChild(free);
// }
//
// public CutTreeNode getRoot() {
// return root;
// }
//
// public List<FreeNode> getFreeNodes() {
// List<FreeNode> free = new ArrayList<>();
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// free.add((FreeNode) node);
// }
// }
// return free;
// }
//
// @Override
// public Iterator<CutTreeNode> iterator() {
// return new CutTreeIterator(this);
// }
//
// public CutTreeStats getStats() {
//
// int numberOfCuts = 0;
// double totalCutLength = 0;
// double sheetArea = root.getDimension().getArea();
// double usedArea = 0;
// double boundingBoxMinX = Double.MAX_VALUE;
// double boundingBoxMaxX = Double.MIN_VALUE;
// double boundingBoxMinY = Double.MAX_VALUE;
// double boundingBoxMaxY = Double.MIN_VALUE;
//
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// } else if (node instanceof PanelNode) {
// final PanelNode pn = (PanelNode) node;
// usedArea += pn.getDimension().getArea();
//
// // this is only partly correct...
// // we should also take cuts into consideration!
// Dimension dim = pn.getDimension();
// Position pos = pn.getPosition();
// boundingBoxMinX = Math.min(pos.getX(), boundingBoxMinX);
// boundingBoxMaxX = Math.max(pos.getX() + dim.getLength(), boundingBoxMaxX);
// boundingBoxMinY = Math.min(pos.getY(), boundingBoxMinY);
// boundingBoxMaxY = Math.max(pos.getY() + dim.getWidth(), boundingBoxMaxY);
//
// } else if (node instanceof CutNode) {
// final CutNode cn = (CutNode) node;
// numberOfCuts++;
// totalCutLength += cn.getCutLength();
// }
// }
// double boundingBoxArea = (boundingBoxMaxX - boundingBoxMinX) * (boundingBoxMaxY - boundingBoxMinY);
//
// CutTreeStats stats = new CutTreeStats(numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
//
// return stats;
// }
//
// class CutTreeIterator implements Iterator<CutTreeNode> {
//
// private final Queue<CutTreeNode> queue = new ArrayDeque<>();
//
// CutTreeIterator(@NonNull final CutTree tree) {
// queue.add(root.getChild());
// }
//
// @Override
// public boolean hasNext() {
// return !queue.isEmpty();
// }
//
// @Override
// public CutTreeNode next() {
//
// if (queue.isEmpty()) {
// throw new RuntimeException("can't get element from empty iterator");
// }
// final CutTreeNode node = queue.remove();
// if (node instanceof CutNode) {
// final CutNode cut = (CutNode) node;
// queue.add(cut.getTarget());
// queue.add(cut.getRest());
// }
// return node;
// }
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeNode.java
// public interface CutTreeNode {
//
// public void replaceChild(@NonNull final CutTreeNode from,
// @NonNull final CutTreeNode to);
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
import com.cutlet.lib.data.cuttree.CutTree;
import com.cutlet.lib.data.cuttree.CutTreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.io.Serializable;
import lombok.NonNull;
import lombok.ToString;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
/**
*
* @author rmuehlba
*/
@ToString
public class Layout implements Serializable {
private final StockSheet sheet;
private final int id;
private final CutTree cutTree;
public Layout(@NonNull final StockSheet sheet, final int id) {
this.sheet = sheet;
this.id = id;
this.cutTree = new CutTree(sheet);
}
public StockSheet getSheet() {
return sheet;
}
public int getId() {
return id;
}
public int getNumberOfPlacedPanels() {
int num = 0;
| for (CutTreeNode node : getCutTree()) {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/model/Layout.java | // Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java
// public class CutTree implements Iterable<CutTreeNode>, Serializable {
//
// private final RootNode root;
//
// public CutTree(@NonNull final StockSheet sheet) {
// root = new RootNode(sheet.getDimension());
// final FreeNode free = new FreeNode(root, new Position(0, 0), sheet.getDimension());
// root.setChild(free);
// }
//
// public CutTreeNode getRoot() {
// return root;
// }
//
// public List<FreeNode> getFreeNodes() {
// List<FreeNode> free = new ArrayList<>();
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// free.add((FreeNode) node);
// }
// }
// return free;
// }
//
// @Override
// public Iterator<CutTreeNode> iterator() {
// return new CutTreeIterator(this);
// }
//
// public CutTreeStats getStats() {
//
// int numberOfCuts = 0;
// double totalCutLength = 0;
// double sheetArea = root.getDimension().getArea();
// double usedArea = 0;
// double boundingBoxMinX = Double.MAX_VALUE;
// double boundingBoxMaxX = Double.MIN_VALUE;
// double boundingBoxMinY = Double.MAX_VALUE;
// double boundingBoxMaxY = Double.MIN_VALUE;
//
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// } else if (node instanceof PanelNode) {
// final PanelNode pn = (PanelNode) node;
// usedArea += pn.getDimension().getArea();
//
// // this is only partly correct...
// // we should also take cuts into consideration!
// Dimension dim = pn.getDimension();
// Position pos = pn.getPosition();
// boundingBoxMinX = Math.min(pos.getX(), boundingBoxMinX);
// boundingBoxMaxX = Math.max(pos.getX() + dim.getLength(), boundingBoxMaxX);
// boundingBoxMinY = Math.min(pos.getY(), boundingBoxMinY);
// boundingBoxMaxY = Math.max(pos.getY() + dim.getWidth(), boundingBoxMaxY);
//
// } else if (node instanceof CutNode) {
// final CutNode cn = (CutNode) node;
// numberOfCuts++;
// totalCutLength += cn.getCutLength();
// }
// }
// double boundingBoxArea = (boundingBoxMaxX - boundingBoxMinX) * (boundingBoxMaxY - boundingBoxMinY);
//
// CutTreeStats stats = new CutTreeStats(numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
//
// return stats;
// }
//
// class CutTreeIterator implements Iterator<CutTreeNode> {
//
// private final Queue<CutTreeNode> queue = new ArrayDeque<>();
//
// CutTreeIterator(@NonNull final CutTree tree) {
// queue.add(root.getChild());
// }
//
// @Override
// public boolean hasNext() {
// return !queue.isEmpty();
// }
//
// @Override
// public CutTreeNode next() {
//
// if (queue.isEmpty()) {
// throw new RuntimeException("can't get element from empty iterator");
// }
// final CutTreeNode node = queue.remove();
// if (node instanceof CutNode) {
// final CutNode cut = (CutNode) node;
// queue.add(cut.getTarget());
// queue.add(cut.getRest());
// }
// return node;
// }
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeNode.java
// public interface CutTreeNode {
//
// public void replaceChild(@NonNull final CutTreeNode from,
// @NonNull final CutTreeNode to);
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
| import com.cutlet.lib.data.cuttree.CutTree;
import com.cutlet.lib.data.cuttree.CutTreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.io.Serializable;
import lombok.NonNull;
import lombok.ToString;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
/**
*
* @author rmuehlba
*/
@ToString
public class Layout implements Serializable {
private final StockSheet sheet;
private final int id;
private final CutTree cutTree;
public Layout(@NonNull final StockSheet sheet, final int id) {
this.sheet = sheet;
this.id = id;
this.cutTree = new CutTree(sheet);
}
public StockSheet getSheet() {
return sheet;
}
public int getId() {
return id;
}
public int getNumberOfPlacedPanels() {
int num = 0;
for (CutTreeNode node : getCutTree()) {
| // Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTree.java
// public class CutTree implements Iterable<CutTreeNode>, Serializable {
//
// private final RootNode root;
//
// public CutTree(@NonNull final StockSheet sheet) {
// root = new RootNode(sheet.getDimension());
// final FreeNode free = new FreeNode(root, new Position(0, 0), sheet.getDimension());
// root.setChild(free);
// }
//
// public CutTreeNode getRoot() {
// return root;
// }
//
// public List<FreeNode> getFreeNodes() {
// List<FreeNode> free = new ArrayList<>();
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// free.add((FreeNode) node);
// }
// }
// return free;
// }
//
// @Override
// public Iterator<CutTreeNode> iterator() {
// return new CutTreeIterator(this);
// }
//
// public CutTreeStats getStats() {
//
// int numberOfCuts = 0;
// double totalCutLength = 0;
// double sheetArea = root.getDimension().getArea();
// double usedArea = 0;
// double boundingBoxMinX = Double.MAX_VALUE;
// double boundingBoxMaxX = Double.MIN_VALUE;
// double boundingBoxMinY = Double.MAX_VALUE;
// double boundingBoxMaxY = Double.MIN_VALUE;
//
// for (CutTreeNode node : this) {
// if (node instanceof FreeNode) {
// } else if (node instanceof PanelNode) {
// final PanelNode pn = (PanelNode) node;
// usedArea += pn.getDimension().getArea();
//
// // this is only partly correct...
// // we should also take cuts into consideration!
// Dimension dim = pn.getDimension();
// Position pos = pn.getPosition();
// boundingBoxMinX = Math.min(pos.getX(), boundingBoxMinX);
// boundingBoxMaxX = Math.max(pos.getX() + dim.getLength(), boundingBoxMaxX);
// boundingBoxMinY = Math.min(pos.getY(), boundingBoxMinY);
// boundingBoxMaxY = Math.max(pos.getY() + dim.getWidth(), boundingBoxMaxY);
//
// } else if (node instanceof CutNode) {
// final CutNode cn = (CutNode) node;
// numberOfCuts++;
// totalCutLength += cn.getCutLength();
// }
// }
// double boundingBoxArea = (boundingBoxMaxX - boundingBoxMinX) * (boundingBoxMaxY - boundingBoxMinY);
//
// CutTreeStats stats = new CutTreeStats(numberOfCuts,
// totalCutLength,
// sheetArea,
// usedArea,
// boundingBoxArea);
//
// return stats;
// }
//
// class CutTreeIterator implements Iterator<CutTreeNode> {
//
// private final Queue<CutTreeNode> queue = new ArrayDeque<>();
//
// CutTreeIterator(@NonNull final CutTree tree) {
// queue.add(root.getChild());
// }
//
// @Override
// public boolean hasNext() {
// return !queue.isEmpty();
// }
//
// @Override
// public CutTreeNode next() {
//
// if (queue.isEmpty()) {
// throw new RuntimeException("can't get element from empty iterator");
// }
// final CutTreeNode node = queue.remove();
// if (node instanceof CutNode) {
// final CutNode cut = (CutNode) node;
// queue.add(cut.getTarget());
// queue.add(cut.getRest());
// }
// return node;
// }
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/CutTreeNode.java
// public interface CutTreeNode {
//
// public void replaceChild(@NonNull final CutTreeNode from,
// @NonNull final CutTreeNode to);
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
// @ToString
// public class PanelNode extends AbstractCutTreeNode {
//
// private final PanelInstance panel;
//
// public PanelNode(@NonNull final CutTreeNode parent,
// @NonNull final PanelInstance panel,
// @NonNull final Position position,
// @NonNull final Dimension dimension) {
//
// super(parent, position, dimension);
// this.panel = panel;
// }
//
// public PanelInstance getPanel() {
// return panel;
// }
//
// @Override
// public void replaceChild(@NonNull final CutTreeNode from, @NonNull final CutTreeNode to) {
// throw new UnsupportedOperationException("Not supported: Freepanel.replace.");
// }
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Layout.java
import com.cutlet.lib.data.cuttree.CutTree;
import com.cutlet.lib.data.cuttree.CutTreeNode;
import com.cutlet.lib.data.cuttree.PanelNode;
import java.io.Serializable;
import lombok.NonNull;
import lombok.ToString;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.model;
/**
*
* @author rmuehlba
*/
@ToString
public class Layout implements Serializable {
private final StockSheet sheet;
private final int id;
private final CutTree cutTree;
public Layout(@NonNull final StockSheet sheet, final int id) {
this.sheet = sheet;
this.id = id;
this.cutTree = new CutTree(sheet);
}
public StockSheet getSheet() {
return sheet;
}
public int getId() {
return id;
}
public int getNumberOfPlacedPanels() {
int num = 0;
for (CutTreeNode node : getCutTree()) {
| if (node instanceof PanelNode) {
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import lombok.NonNull;
import lombok.ToString;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
@ToString
public class PanelNode extends AbstractCutTreeNode {
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import lombok.NonNull;
import lombok.ToString;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
@ToString
public class PanelNode extends AbstractCutTreeNode {
| private final PanelInstance panel;
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import lombok.NonNull;
import lombok.ToString;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
@ToString
public class PanelNode extends AbstractCutTreeNode {
private final PanelInstance panel;
public PanelNode(@NonNull final CutTreeNode parent,
@NonNull final PanelInstance panel,
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import lombok.NonNull;
import lombok.ToString;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
@ToString
public class PanelNode extends AbstractCutTreeNode {
private final PanelInstance panel;
public PanelNode(@NonNull final CutTreeNode parent,
@NonNull final PanelInstance panel,
| @NonNull final Position position,
|
mru00/cutlet | CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java | // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
| import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import lombok.NonNull;
import lombok.ToString;
| /*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
@ToString
public class PanelNode extends AbstractCutTreeNode {
private final PanelInstance panel;
public PanelNode(@NonNull final CutTreeNode parent,
@NonNull final PanelInstance panel,
@NonNull final Position position,
| // Path: CutletLib/src/main/java/com/cutlet/lib/model/Dimension.java
// @ToString
// public class Dimension implements Serializable{
//
// private double length;
// private double width;
//
// public Dimension(final double length, final double width) {
// this.length = length;
// this.width = width;
// }
//
// public double getLength() {
// return length;
// }
//
// public void setLength(final double length) {
// this.length = length;
// }
//
// public double getWidth() {
// return width;
// }
//
// public void setWidth(final double width) {
// this.width = width;
// }
//
// public double getArea() {
// return getLength() * getWidth();
// }
//
// public boolean canHold(@NonNull final Dimension other) {
// return other.getLength() <= this.getLength() && other.getWidth() <= this.getWidth();
// }
//
// public Dimension rotated() {
// return new Dimension(width, length);
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/PanelInstance.java
// @ToString(exclude = "sheet")
// public class PanelInstance implements Serializable {
//
// private final String title;
// private final StockSheet sheet;
// private final Dimension dimension;
// private final boolean canRotate;
// private final int instanceId;
//
// public String getTitle() {
// return title;
// }
//
// public PanelInstance(@NonNull final StockSheet sheet,
// @NonNull final Dimension dimension,
// @NonNull final String title,
// final int instanceId,
// final boolean canRotate) {
//
// this.sheet = sheet;
// this.title = title;
// this.dimension = dimension;
// this.canRotate = canRotate;
// this.instanceId = instanceId;
//
// if (dimension.getWidth() > sheet.getDimension().getWidth() || dimension.getLength() > sheet.getDimension().getLength()) {
// throw new RuntimeException("panel too large for sheet");
// }
// }
//
// public StockSheet getSheet() {
// return sheet;
// }
//
// public Dimension getDimension() {
// return dimension;
// }
//
// public int getInstanceId() {
// return instanceId;
// }
// }
//
// Path: CutletLib/src/main/java/com/cutlet/lib/model/Position.java
// @ToString
// public class Position implements Serializable {
//
// private double x, y;
//
// public Position(final double x, final double y) {
// this.x = x;
// this.y = y;
// }
//
// public double getX() {
// return x;
// }
//
// public void setX(final double x) {
// this.x = x;
// }
//
// public double getY() {
// return y;
// }
//
// public void setY(final double y) {
// this.y = y;
// }
//
// }
// Path: CutletLib/src/main/java/com/cutlet/lib/data/cuttree/PanelNode.java
import com.cutlet.lib.model.Dimension;
import com.cutlet.lib.model.PanelInstance;
import com.cutlet.lib.model.Position;
import lombok.NonNull;
import lombok.ToString;
/*
* Copyright (C) 2017 rudolf.muehlbauer@gmail.com
*/
package com.cutlet.lib.data.cuttree;
/**
*
* @author rmuehlba
*/
@ToString
public class PanelNode extends AbstractCutTreeNode {
private final PanelInstance panel;
public PanelNode(@NonNull final CutTreeNode parent,
@NonNull final PanelInstance panel,
@NonNull final Position position,
| @NonNull final Dimension dimension) {
|
thshdw/lixia-javardp | src/com/lixia/rdp/ISO.java | // Path: src/com/lixia/rdp/crypto/CryptoException.java
// public class CryptoException
// extends Exception
// {
// public CryptoException() { super(); }
// /** @param reason the reason why the exception was thrown. */
// public CryptoException(String reason) { super(reason); }
// }
| import java.io.*;
import java.net.*;
import com.lixia.rdp.crypto.CryptoException;
import com.lixia.uag.websocket.LocalHttpTunnel;
import org.apache.log4j.Logger;
| LocalHttpTunnel tunnel = new LocalHttpTunnel(Options.http_server,
new InetSocketAddress(host,port),
Options.username,
Options.password,
Options.command);
SocketAddress endpoint = tunnel.createTunnel();
if(endpoint != null){
this.rdpsock = new Socket();
rdpsock.connect(endpoint,timeout_ms);
}
else{
throw new IOException("failed to create tunnel!");
}
}
else{
rdpsock = new Socket();
rdpsock.connect(new InetSocketAddress(host,port),timeout_ms);
}
}
/**
* Connect to a server
* @param host Address of server
* @param port Port to connect to on server
* @throws IOException
* @throws RdesktopException
* @throws OrderException
* @throws CryptoException
*/
public void connect(InetAddress host, int port) throws IOException,
| // Path: src/com/lixia/rdp/crypto/CryptoException.java
// public class CryptoException
// extends Exception
// {
// public CryptoException() { super(); }
// /** @param reason the reason why the exception was thrown. */
// public CryptoException(String reason) { super(reason); }
// }
// Path: src/com/lixia/rdp/ISO.java
import java.io.*;
import java.net.*;
import com.lixia.rdp.crypto.CryptoException;
import com.lixia.uag.websocket.LocalHttpTunnel;
import org.apache.log4j.Logger;
LocalHttpTunnel tunnel = new LocalHttpTunnel(Options.http_server,
new InetSocketAddress(host,port),
Options.username,
Options.password,
Options.command);
SocketAddress endpoint = tunnel.createTunnel();
if(endpoint != null){
this.rdpsock = new Socket();
rdpsock.connect(endpoint,timeout_ms);
}
else{
throw new IOException("failed to create tunnel!");
}
}
else{
rdpsock = new Socket();
rdpsock.connect(new InetSocketAddress(host,port),timeout_ms);
}
}
/**
* Connect to a server
* @param host Address of server
* @param port Port to connect to on server
* @throws IOException
* @throws RdesktopException
* @throws OrderException
* @throws CryptoException
*/
public void connect(InetAddress host, int port) throws IOException,
| RdesktopException, OrderException, CryptoException {
|
thshdw/lixia-javardp | src/com/lixia/rdp/rdp5/cliprdr/ImageSelection.java | // Path: src/com/lixia/rdp/Common.java
// public class Common {
//
// public static boolean underApplet = false;
// public static Rdp5JPanel rdp;
// public static Secure secure;
// public static MCS mcs;
// public static RdesktopJFrame frame;
//
// /**
// * Quit the application
// */
// public static void exit(){
// RdesktopSwing.exit(0,rdp,frame,true);
// }
// }
//
// Path: src1.6/com/lixia/rdp/Utilities_Localised.java
// public class Utilities_Localised extends Utilities {
//
// public static DataFlavor imageFlavor = DataFlavor.imageFlavor;
//
// public static String strReplaceAll(String in, String find, String replace){
// return in.replaceAll(find, replace);
// }
//
// public static String[] split(String in, String splitWith){
// return in.split(splitWith);
// }
//
// }
| import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import com.lixia.rdp.Common;
import com.lixia.rdp.Utilities_Localised;
| /* ImageSelection.java
* Component: ProperJavaRDP
*
* Revision: $Revision: 1.1.1.1 $
* Author: $Author: suvarov $
* Date: $Date: 2007/03/08 00:26:41 $
*
* Copyright (c) 2005 Propero Limited
*
* Purpose:
*/
package com.lixia.rdp.rdp5.cliprdr;
public class ImageSelection
implements Transferable
{
// the Image object which will be housed by the ImageSelection
private Image image;
public ImageSelection(Image image) {
this.image = image;
}
// Returns the supported flavors of our implementation
public DataFlavor[] getTransferDataFlavors()
{
| // Path: src/com/lixia/rdp/Common.java
// public class Common {
//
// public static boolean underApplet = false;
// public static Rdp5JPanel rdp;
// public static Secure secure;
// public static MCS mcs;
// public static RdesktopJFrame frame;
//
// /**
// * Quit the application
// */
// public static void exit(){
// RdesktopSwing.exit(0,rdp,frame,true);
// }
// }
//
// Path: src1.6/com/lixia/rdp/Utilities_Localised.java
// public class Utilities_Localised extends Utilities {
//
// public static DataFlavor imageFlavor = DataFlavor.imageFlavor;
//
// public static String strReplaceAll(String in, String find, String replace){
// return in.replaceAll(find, replace);
// }
//
// public static String[] split(String in, String splitWith){
// return in.split(splitWith);
// }
//
// }
// Path: src/com/lixia/rdp/rdp5/cliprdr/ImageSelection.java
import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import com.lixia.rdp.Common;
import com.lixia.rdp.Utilities_Localised;
/* ImageSelection.java
* Component: ProperJavaRDP
*
* Revision: $Revision: 1.1.1.1 $
* Author: $Author: suvarov $
* Date: $Date: 2007/03/08 00:26:41 $
*
* Copyright (c) 2005 Propero Limited
*
* Purpose:
*/
package com.lixia.rdp.rdp5.cliprdr;
public class ImageSelection
implements Transferable
{
// the Image object which will be housed by the ImageSelection
private Image image;
public ImageSelection(Image image) {
this.image = image;
}
// Returns the supported flavors of our implementation
public DataFlavor[] getTransferDataFlavors()
{
| return new DataFlavor[] {Utilities_Localised.imageFlavor};
|
thshdw/lixia-javardp | src/com/lixia/rdp/Common.java | // Path: src/com/lixia/rdp/rdp5/Rdp5JPanel.java
// public class Rdp5JPanel extends RdpJPanel {
//
// private VChannels channels;
//
// /**
// * Initialise the RDP5 communications layer, with specified virtual channels
// *
// * @param channels
// * Virtual channels for RDP layer
// */
// public Rdp5JPanel(VChannels channels) {
// super(channels);
// this.channels = channels;
// }
//
// /**
// * Process an RDP5 packet
// *
// * @param s
// * Packet to be processed
// * @param e
// * True if packet is encrypted
// * @throws RdesktopException
// * @throws OrderException
// * @throws CryptoException
// */
// public void rdp5_process(RdpPacket_Localised s, boolean e)
// throws RdesktopException, OrderException, CryptoException {
// rdp5_process(s, e, false);
// }
//
// /**
// * Process an RDP5 packet
// *
// * @param s
// * Packet to be processed
// * @param encryption
// * True if packet is encrypted
// * @param shortform
// * True if packet is of the "short" form
// * @throws RdesktopException
// * @throws OrderException
// * @throws CryptoException
// */
// public void rdp5_process(RdpPacket_Localised s, boolean encryption,
// boolean shortform) throws RdesktopException, OrderException,
// CryptoException {
// // logger.debug("Processing RDP 5 order");
//
// int length, count;
// int type;
// int next;
//
// if (encryption) {
// s.incrementPosition(8);/* signature */
// byte[] data = new byte[s.size() - s.getPosition()];
// s.copyToByteArray(data, 0, s.getPosition(), data.length);
// byte[] packet = SecureLayer.decrypt(data);
// s.copyFromByteArray(packet, 0, s.getPosition(), packet.length);
// }
//
// while (s.getPosition() < s.getEnd()) {
// type = s.get8();
//
// if ((type & 0x80) >0)
// {
// type ^= 0x80;
// }
// else
// {
// }
// length = s.getLittleEndian16();
// /* next_packet = */next = s.getPosition() + length;
// // logger.debug("RDP5: type = " + type);
// switch (type) {
// case 0: /* orders */
// count = s.getLittleEndian16();
// orders.processOrders(s, next, count);
// break;
// case 1: /* bitmap update (???) */
// s.incrementPosition(2); /* part length */
// processBitmapUpdates(s);
// break;
// case 2: /* palette */
// s.incrementPosition(2);
// processPalette(s);
// break;
// case 3: /* probably an palette with offset 3. Weird */
// break;
// case 5:
// process_null_system_pointer_pdu(s);
// break;
// case 6: // default pointer
// break;
// case 9:
// process_colour_pointer_pdu(s);
// break;
// case 10:
// process_cached_pointer_pdu(s);
// break;
// default:
// logger.warn("Unimplemented RDP5 opcode " + type);
// }
//
// s.setPosition(next);
// }
// }
//
// /**
// * Process an RDP5 packet from a virtual channel
// * @param s Packet to be processed
// * @param channelno Channel on which packet was received
// */
// void rdp5_process_channel(RdpPacket_Localised s, int channelno) {
// VChannel channel = channels.find_channel_by_channelno(channelno);
// if (channel != null) {
// try {
// channel.process(s);
// } catch (Exception e) {
// }
// }
// }
//
// }
| import com.lixia.rdp.rdp5.Rdp5JPanel;
| /* Common.java
* Component: ProperJavaRDP
*
* Revision: $Revision: 1.1.1.1 $
* Author: $Author: suvarov $
* Date: $Date: 2007/03/08 00:26:14 $
*
* Copyright (c) 2005 Propero Limited
*
* Purpose: Provide a static interface to individual network layers
* and UI components
*/
package com.lixia.rdp;
public class Common {
public static boolean underApplet = false;
| // Path: src/com/lixia/rdp/rdp5/Rdp5JPanel.java
// public class Rdp5JPanel extends RdpJPanel {
//
// private VChannels channels;
//
// /**
// * Initialise the RDP5 communications layer, with specified virtual channels
// *
// * @param channels
// * Virtual channels for RDP layer
// */
// public Rdp5JPanel(VChannels channels) {
// super(channels);
// this.channels = channels;
// }
//
// /**
// * Process an RDP5 packet
// *
// * @param s
// * Packet to be processed
// * @param e
// * True if packet is encrypted
// * @throws RdesktopException
// * @throws OrderException
// * @throws CryptoException
// */
// public void rdp5_process(RdpPacket_Localised s, boolean e)
// throws RdesktopException, OrderException, CryptoException {
// rdp5_process(s, e, false);
// }
//
// /**
// * Process an RDP5 packet
// *
// * @param s
// * Packet to be processed
// * @param encryption
// * True if packet is encrypted
// * @param shortform
// * True if packet is of the "short" form
// * @throws RdesktopException
// * @throws OrderException
// * @throws CryptoException
// */
// public void rdp5_process(RdpPacket_Localised s, boolean encryption,
// boolean shortform) throws RdesktopException, OrderException,
// CryptoException {
// // logger.debug("Processing RDP 5 order");
//
// int length, count;
// int type;
// int next;
//
// if (encryption) {
// s.incrementPosition(8);/* signature */
// byte[] data = new byte[s.size() - s.getPosition()];
// s.copyToByteArray(data, 0, s.getPosition(), data.length);
// byte[] packet = SecureLayer.decrypt(data);
// s.copyFromByteArray(packet, 0, s.getPosition(), packet.length);
// }
//
// while (s.getPosition() < s.getEnd()) {
// type = s.get8();
//
// if ((type & 0x80) >0)
// {
// type ^= 0x80;
// }
// else
// {
// }
// length = s.getLittleEndian16();
// /* next_packet = */next = s.getPosition() + length;
// // logger.debug("RDP5: type = " + type);
// switch (type) {
// case 0: /* orders */
// count = s.getLittleEndian16();
// orders.processOrders(s, next, count);
// break;
// case 1: /* bitmap update (???) */
// s.incrementPosition(2); /* part length */
// processBitmapUpdates(s);
// break;
// case 2: /* palette */
// s.incrementPosition(2);
// processPalette(s);
// break;
// case 3: /* probably an palette with offset 3. Weird */
// break;
// case 5:
// process_null_system_pointer_pdu(s);
// break;
// case 6: // default pointer
// break;
// case 9:
// process_colour_pointer_pdu(s);
// break;
// case 10:
// process_cached_pointer_pdu(s);
// break;
// default:
// logger.warn("Unimplemented RDP5 opcode " + type);
// }
//
// s.setPosition(next);
// }
// }
//
// /**
// * Process an RDP5 packet from a virtual channel
// * @param s Packet to be processed
// * @param channelno Channel on which packet was received
// */
// void rdp5_process_channel(RdpPacket_Localised s, int channelno) {
// VChannel channel = channels.find_channel_by_channelno(channelno);
// if (channel != null) {
// try {
// channel.process(s);
// } catch (Exception e) {
// }
// }
// }
//
// }
// Path: src/com/lixia/rdp/Common.java
import com.lixia.rdp.rdp5.Rdp5JPanel;
/* Common.java
* Component: ProperJavaRDP
*
* Revision: $Revision: 1.1.1.1 $
* Author: $Author: suvarov $
* Date: $Date: 2007/03/08 00:26:14 $
*
* Copyright (c) 2005 Propero Limited
*
* Purpose: Provide a static interface to individual network layers
* and UI components
*/
package com.lixia.rdp;
public class Common {
public static boolean underApplet = false;
| public static Rdp5JPanel rdp;
|
Asqatasun/Web-Snapshot | websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/service/UrlDataServiceImpl.java | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Url.java
// public interface Url extends Entity {
//
// /**
// *
// * @return the url of the image
// */
// String getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(String url);
// }
//
// Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/dao/UrlDAO.java
// public interface UrlDAO extends GenericDAO<Url, Long> {
//
// /**
// *
// * @param url
// * @return
// */
// Url findUrlByStringUrl(String url);
//
// Long count();
// }
| import javax.persistence.NoResultException;
import org.apache.log4j.Logger;
import org.asqatasun.sdk.entity.service.AbstractGenericDataService;
import org.asqatasun.websnapshot.entity.Url;
import org.asqatasun.websnapshot.entity.dao.UrlDAO; | /*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.entity.service;
public class UrlDataServiceImpl extends AbstractGenericDataService<Url, Long>
implements UrlDataService {
public UrlDataServiceImpl() {
super();
}
@Override
public Url getUrlFromStringUrl(String url) {
try { | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Url.java
// public interface Url extends Entity {
//
// /**
// *
// * @return the url of the image
// */
// String getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(String url);
// }
//
// Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/dao/UrlDAO.java
// public interface UrlDAO extends GenericDAO<Url, Long> {
//
// /**
// *
// * @param url
// * @return
// */
// Url findUrlByStringUrl(String url);
//
// Long count();
// }
// Path: websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/service/UrlDataServiceImpl.java
import javax.persistence.NoResultException;
import org.apache.log4j.Logger;
import org.asqatasun.sdk.entity.service.AbstractGenericDataService;
import org.asqatasun.websnapshot.entity.Url;
import org.asqatasun.websnapshot.entity.dao.UrlDAO;
/*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.entity.service;
public class UrlDataServiceImpl extends AbstractGenericDataService<Url, Long>
implements UrlDataService {
public UrlDataServiceImpl() {
super();
}
@Override
public Url getUrlFromStringUrl(String url) {
try { | return ((UrlDAO) entityDao).findUrlByStringUrl(url); |
Asqatasun/Web-Snapshot | websnapshot-service/src/main/java/org/asqatasun/websnapshot/service/SnapshotCreatorImpl.java | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/urlmanager/utils/UrlUtils.java
// public final class UrlUtils {
//
// public static final String URL_AVAILABLE = "OK";
// public static final String URL_NOT_AVAILABLE = "This url is not available";
// private static final int MIN_HTTP_VALID_CODE = 200;
// private static final int MAX_HTTP_VALID_CODE = 400;
//
// /**
// * private constructor
// */
// private UrlUtils() {
// }
//
// /**
// *
// * @param url
// * @return
// */
// public static boolean checkIfURLIsValid(String url) {
// String[] schemes = {"http", "https"};
// UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_2_SLASHES);
// return urlValidator.isValid(url);
// }
//
// /**
// *
// * @param targetUrl
// * @return
// */
// public static String checkURLAvailable(String targetUrl) {
// try {
// URL url = new URL(targetUrl);
// URLConnection urlConnection = url.openConnection();
//
// HttpURLConnection.setFollowRedirects(true);
// HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
// httpURLConnection.setRequestMethod("HEAD");
//
// if (httpURLConnection.getResponseCode() >= MIN_HTTP_VALID_CODE
// && httpURLConnection.getResponseCode() < MAX_HTTP_VALID_CODE) {
// return URL_AVAILABLE;
// }
// urlConnection = url.openConnection();
// httpURLConnection.disconnect();
// HttpURLConnection.setFollowRedirects(true);
// httpURLConnection = (HttpURLConnection) urlConnection;
// httpURLConnection.setRequestMethod("GET");
//
// if (httpURLConnection.getResponseCode()
// >= MIN_HTTP_VALID_CODE
// && httpURLConnection.getResponseCode() < MAX_HTTP_VALID_CODE) {
// return URL_AVAILABLE;
// } else {
// return Integer.toString(httpURLConnection.getResponseCode()) + " " + httpURLConnection.getResponseMessage();
// }
// } catch (Exception e) {
// return URL_NOT_AVAILABLE;
// }
// }
// }
| import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.asqatasun.websnapshot.urlmanager.utils.UrlUtils;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.apache.log4j.Logger;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver; | if (webDriver.equals(FIREFOX_BROWSER_NAME)) {
driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxBinaryPath)), new FirefoxProfile());
} else {
DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
phantomJsBinaryPath);
driver = new PhantomJSDriver(caps);
}
driver.manage().window().setSize(new Dimension(windowWidth, windowHeight));
return driver;
}
/**
*
* @param driver
* @param url
*/
private String loadPage(RemoteWebDriver driver, String url) {
try {
driver.get(url);
driver.executeScript("if (getComputedStyle(document.body, null).backgroundColor === 'rgba(0, 0, 0, 0)'"
+ "|| getComputedStyle(document.body, null).backgroundColor === 'transparent') {"
+ "document.body.style.backgroundColor = 'white';"
+ "}");
} catch (Exception e) {
Logger.getLogger(this.getClass()).debug("Cannot load this url : " + url);
return SnapshotCreationResponse.ERROR;
}
if (!url.equals(driver.getCurrentUrl())) { | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/urlmanager/utils/UrlUtils.java
// public final class UrlUtils {
//
// public static final String URL_AVAILABLE = "OK";
// public static final String URL_NOT_AVAILABLE = "This url is not available";
// private static final int MIN_HTTP_VALID_CODE = 200;
// private static final int MAX_HTTP_VALID_CODE = 400;
//
// /**
// * private constructor
// */
// private UrlUtils() {
// }
//
// /**
// *
// * @param url
// * @return
// */
// public static boolean checkIfURLIsValid(String url) {
// String[] schemes = {"http", "https"};
// UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_2_SLASHES);
// return urlValidator.isValid(url);
// }
//
// /**
// *
// * @param targetUrl
// * @return
// */
// public static String checkURLAvailable(String targetUrl) {
// try {
// URL url = new URL(targetUrl);
// URLConnection urlConnection = url.openConnection();
//
// HttpURLConnection.setFollowRedirects(true);
// HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
// httpURLConnection.setRequestMethod("HEAD");
//
// if (httpURLConnection.getResponseCode() >= MIN_HTTP_VALID_CODE
// && httpURLConnection.getResponseCode() < MAX_HTTP_VALID_CODE) {
// return URL_AVAILABLE;
// }
// urlConnection = url.openConnection();
// httpURLConnection.disconnect();
// HttpURLConnection.setFollowRedirects(true);
// httpURLConnection = (HttpURLConnection) urlConnection;
// httpURLConnection.setRequestMethod("GET");
//
// if (httpURLConnection.getResponseCode()
// >= MIN_HTTP_VALID_CODE
// && httpURLConnection.getResponseCode() < MAX_HTTP_VALID_CODE) {
// return URL_AVAILABLE;
// } else {
// return Integer.toString(httpURLConnection.getResponseCode()) + " " + httpURLConnection.getResponseMessage();
// }
// } catch (Exception e) {
// return URL_NOT_AVAILABLE;
// }
// }
// }
// Path: websnapshot-service/src/main/java/org/asqatasun/websnapshot/service/SnapshotCreatorImpl.java
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.asqatasun.websnapshot.urlmanager.utils.UrlUtils;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.apache.log4j.Logger;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
if (webDriver.equals(FIREFOX_BROWSER_NAME)) {
driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxBinaryPath)), new FirefoxProfile());
} else {
DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
phantomJsBinaryPath);
driver = new PhantomJSDriver(caps);
}
driver.manage().window().setSize(new Dimension(windowWidth, windowHeight));
return driver;
}
/**
*
* @param driver
* @param url
*/
private String loadPage(RemoteWebDriver driver, String url) {
try {
driver.get(url);
driver.executeScript("if (getComputedStyle(document.body, null).backgroundColor === 'rgba(0, 0, 0, 0)'"
+ "|| getComputedStyle(document.body, null).backgroundColor === 'transparent') {"
+ "document.body.style.backgroundColor = 'white';"
+ "}");
} catch (Exception e) {
Logger.getLogger(this.getClass()).debug("Cannot load this url : " + url);
return SnapshotCreationResponse.ERROR;
}
if (!url.equals(driver.getCurrentUrl())) { | String urlAvailibility = UrlUtils.checkURLAvailable(driver.getCurrentUrl()); |
Asqatasun/Web-Snapshot | websnapshot-webapp/src/main/java/org/asqatasun/websnapshot/webapp/controller/JsonImage.java | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Image.java
// public interface Image extends Entity {
//
// enum Status {
//
// CREATED("CREATED"),
// IN_PROGRESS("IN_PROGRESS"),
// ERROR("ERROR"),
// QUEUED("QUEUED"),
// HACK_CREATED("HACK_CREATED"),
// MUST_BE_CREATE("MUST_BE_CREATE"),
// NOT_EXIST("NOT_EXIST");
//
// private final String text;
// /**
// * @param text
// */
// private Status(final String text) {
// this.text = text;
// }
//
// /* (non-Javadoc)
// * @see java.lang.Enum#toString()
// */
// @Override
// public String toString() {
// return text;
// }
// }
//
// /**
// *
// * @return the date of creating snapshot
// */
// Date getDateOfCreation();
//
// /**
// *
// * @param date
// */
// void setDateOfCreation(Date date);
//
// /**
// *
// * @return the width of the image
// */
// int getWidth();
//
// /**
// *
// * @param width
// */
// void setWidth(int width);
//
// /**
// *
// * @return the height of the image
// */
// int getHeight();
//
// /**
// *
// * @param height
// */
// void setHeight(int height);
//
// /**
// *
// * @return
// */
// byte[] getRawData();
//
// /**
// *
// * @param thumbnail
// */
// void setRawData(byte[] thumbnail);
//
// /**
// *
// * @return true if the image is the canonical format
// */
// boolean getIsCanonical();
//
// /**
// *
// * @param canonical
// */
// void setIsCanonical(boolean canonical);
//
// /**
// *
// * @return the status : CREATED, IN_PROGRESS, ERROR, QUEUED
// */
// Status getStatus();
//
// /**
// *
// * @param status
// */
// void setStatus(Status status);
//
// /**
// *
// * @return the url entity
// */
// Url getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(Url url);
// }
//
// Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Image.java
// enum Status {
//
// CREATED("CREATED"),
// IN_PROGRESS("IN_PROGRESS"),
// ERROR("ERROR"),
// QUEUED("QUEUED"),
// HACK_CREATED("HACK_CREATED"),
// MUST_BE_CREATE("MUST_BE_CREATE"),
// NOT_EXIST("NOT_EXIST");
//
// private final String text;
// /**
// * @param text
// */
// private Status(final String text) {
// this.text = text;
// }
//
// /* (non-Javadoc)
// * @see java.lang.Enum#toString()
// */
// @Override
// public String toString() {
// return text;
// }
// }
| import org.asqatasun.websnapshot.entity.Image;
import org.asqatasun.websnapshot.entity.Image.Status; | /*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.webapp.controller;
/**
*
* @author alingua
*/
public class JsonImage {
private Image image;
public JsonImage(Image image) {
this.image = image;
}
public Long getId() {
return image.getId();
}
public int getHeight() {
return image.getHeight();
}
public int getWidth() {
return image.getWidth();
}
| // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Image.java
// public interface Image extends Entity {
//
// enum Status {
//
// CREATED("CREATED"),
// IN_PROGRESS("IN_PROGRESS"),
// ERROR("ERROR"),
// QUEUED("QUEUED"),
// HACK_CREATED("HACK_CREATED"),
// MUST_BE_CREATE("MUST_BE_CREATE"),
// NOT_EXIST("NOT_EXIST");
//
// private final String text;
// /**
// * @param text
// */
// private Status(final String text) {
// this.text = text;
// }
//
// /* (non-Javadoc)
// * @see java.lang.Enum#toString()
// */
// @Override
// public String toString() {
// return text;
// }
// }
//
// /**
// *
// * @return the date of creating snapshot
// */
// Date getDateOfCreation();
//
// /**
// *
// * @param date
// */
// void setDateOfCreation(Date date);
//
// /**
// *
// * @return the width of the image
// */
// int getWidth();
//
// /**
// *
// * @param width
// */
// void setWidth(int width);
//
// /**
// *
// * @return the height of the image
// */
// int getHeight();
//
// /**
// *
// * @param height
// */
// void setHeight(int height);
//
// /**
// *
// * @return
// */
// byte[] getRawData();
//
// /**
// *
// * @param thumbnail
// */
// void setRawData(byte[] thumbnail);
//
// /**
// *
// * @return true if the image is the canonical format
// */
// boolean getIsCanonical();
//
// /**
// *
// * @param canonical
// */
// void setIsCanonical(boolean canonical);
//
// /**
// *
// * @return the status : CREATED, IN_PROGRESS, ERROR, QUEUED
// */
// Status getStatus();
//
// /**
// *
// * @param status
// */
// void setStatus(Status status);
//
// /**
// *
// * @return the url entity
// */
// Url getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(Url url);
// }
//
// Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Image.java
// enum Status {
//
// CREATED("CREATED"),
// IN_PROGRESS("IN_PROGRESS"),
// ERROR("ERROR"),
// QUEUED("QUEUED"),
// HACK_CREATED("HACK_CREATED"),
// MUST_BE_CREATE("MUST_BE_CREATE"),
// NOT_EXIST("NOT_EXIST");
//
// private final String text;
// /**
// * @param text
// */
// private Status(final String text) {
// this.text = text;
// }
//
// /* (non-Javadoc)
// * @see java.lang.Enum#toString()
// */
// @Override
// public String toString() {
// return text;
// }
// }
// Path: websnapshot-webapp/src/main/java/org/asqatasun/websnapshot/webapp/controller/JsonImage.java
import org.asqatasun.websnapshot.entity.Image;
import org.asqatasun.websnapshot.entity.Image.Status;
/*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.webapp.controller;
/**
*
* @author alingua
*/
public class JsonImage {
private Image image;
public JsonImage(Image image) {
this.image = image;
}
public Long getId() {
return image.getId();
}
public int getHeight() {
return image.getHeight();
}
public int getWidth() {
return image.getWidth();
}
| public Status getStatus() { |
Asqatasun/Web-Snapshot | websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/factory/UrlFactoryImpl.java | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Url.java
// public interface Url extends Entity {
//
// /**
// *
// * @return the url of the image
// */
// String getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(String url);
// }
//
// Path: websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/UrlImpl.java
// @Entity
// @Table(name = "url")
// @XmlRootElement
// public class UrlImpl implements Url, Serializable {
//
// private static final int HASH_NUMBER = 5;
// private static final int HASH_COEFFICIENT = 67;
// @Id
// @GeneratedValue
// @Column(name = "id")
// private Long id;
// @Column(name = "url")
// private String url;
//
// @Override
// public Long getId() {
// return id;
// }
//
// @Override
// public void setId(Long id) {
// this.id = id;
// }
//
// @Override
// public String getUrl() {
// return url;
// }
//
// @Override
// public void setUrl(String url) {
// this.url = url;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final UrlImpl other = (UrlImpl) obj;
// if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
// return false;
// }
// if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// int hash = HASH_NUMBER;
// hash = HASH_COEFFICIENT * hash + (this.id != null ? this.id.hashCode() : 0);
// hash = HASH_COEFFICIENT * hash + (this.url != null ? this.url.hashCode() : 0);
// return hash;
// }
// }
| import org.asqatasun.websnapshot.entity.Url;
import org.asqatasun.websnapshot.entity.UrlImpl; | /*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.entity.factory;
public class UrlFactoryImpl implements UrlFactory {
public UrlFactoryImpl() {
super();
}
@Override | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Url.java
// public interface Url extends Entity {
//
// /**
// *
// * @return the url of the image
// */
// String getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(String url);
// }
//
// Path: websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/UrlImpl.java
// @Entity
// @Table(name = "url")
// @XmlRootElement
// public class UrlImpl implements Url, Serializable {
//
// private static final int HASH_NUMBER = 5;
// private static final int HASH_COEFFICIENT = 67;
// @Id
// @GeneratedValue
// @Column(name = "id")
// private Long id;
// @Column(name = "url")
// private String url;
//
// @Override
// public Long getId() {
// return id;
// }
//
// @Override
// public void setId(Long id) {
// this.id = id;
// }
//
// @Override
// public String getUrl() {
// return url;
// }
//
// @Override
// public void setUrl(String url) {
// this.url = url;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final UrlImpl other = (UrlImpl) obj;
// if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
// return false;
// }
// if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// int hash = HASH_NUMBER;
// hash = HASH_COEFFICIENT * hash + (this.id != null ? this.id.hashCode() : 0);
// hash = HASH_COEFFICIENT * hash + (this.url != null ? this.url.hashCode() : 0);
// return hash;
// }
// }
// Path: websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/factory/UrlFactoryImpl.java
import org.asqatasun.websnapshot.entity.Url;
import org.asqatasun.websnapshot.entity.UrlImpl;
/*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.entity.factory;
public class UrlFactoryImpl implements UrlFactory {
public UrlFactoryImpl() {
super();
}
@Override | public Url create() { |
Asqatasun/Web-Snapshot | websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/factory/UrlFactoryImpl.java | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Url.java
// public interface Url extends Entity {
//
// /**
// *
// * @return the url of the image
// */
// String getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(String url);
// }
//
// Path: websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/UrlImpl.java
// @Entity
// @Table(name = "url")
// @XmlRootElement
// public class UrlImpl implements Url, Serializable {
//
// private static final int HASH_NUMBER = 5;
// private static final int HASH_COEFFICIENT = 67;
// @Id
// @GeneratedValue
// @Column(name = "id")
// private Long id;
// @Column(name = "url")
// private String url;
//
// @Override
// public Long getId() {
// return id;
// }
//
// @Override
// public void setId(Long id) {
// this.id = id;
// }
//
// @Override
// public String getUrl() {
// return url;
// }
//
// @Override
// public void setUrl(String url) {
// this.url = url;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final UrlImpl other = (UrlImpl) obj;
// if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
// return false;
// }
// if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// int hash = HASH_NUMBER;
// hash = HASH_COEFFICIENT * hash + (this.id != null ? this.id.hashCode() : 0);
// hash = HASH_COEFFICIENT * hash + (this.url != null ? this.url.hashCode() : 0);
// return hash;
// }
// }
| import org.asqatasun.websnapshot.entity.Url;
import org.asqatasun.websnapshot.entity.UrlImpl; | /*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.entity.factory;
public class UrlFactoryImpl implements UrlFactory {
public UrlFactoryImpl() {
super();
}
@Override
public Url create() { | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Url.java
// public interface Url extends Entity {
//
// /**
// *
// * @return the url of the image
// */
// String getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(String url);
// }
//
// Path: websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/UrlImpl.java
// @Entity
// @Table(name = "url")
// @XmlRootElement
// public class UrlImpl implements Url, Serializable {
//
// private static final int HASH_NUMBER = 5;
// private static final int HASH_COEFFICIENT = 67;
// @Id
// @GeneratedValue
// @Column(name = "id")
// private Long id;
// @Column(name = "url")
// private String url;
//
// @Override
// public Long getId() {
// return id;
// }
//
// @Override
// public void setId(Long id) {
// this.id = id;
// }
//
// @Override
// public String getUrl() {
// return url;
// }
//
// @Override
// public void setUrl(String url) {
// this.url = url;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final UrlImpl other = (UrlImpl) obj;
// if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
// return false;
// }
// if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// int hash = HASH_NUMBER;
// hash = HASH_COEFFICIENT * hash + (this.id != null ? this.id.hashCode() : 0);
// hash = HASH_COEFFICIENT * hash + (this.url != null ? this.url.hashCode() : 0);
// return hash;
// }
// }
// Path: websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/factory/UrlFactoryImpl.java
import org.asqatasun.websnapshot.entity.Url;
import org.asqatasun.websnapshot.entity.UrlImpl;
/*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.entity.factory;
public class UrlFactoryImpl implements UrlFactory {
public UrlFactoryImpl() {
super();
}
@Override
public Url create() { | return new UrlImpl(); |
Asqatasun/Web-Snapshot | websnapshot-persistence/src/main/java/org/asqatasun/websnapshot/entity/dao/UrlDAOImpl.java | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Url.java
// public interface Url extends Entity {
//
// /**
// *
// * @return the url of the image
// */
// String getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(String url);
// }
//
// Path: websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/UrlImpl.java
// @Entity
// @Table(name = "url")
// @XmlRootElement
// public class UrlImpl implements Url, Serializable {
//
// private static final int HASH_NUMBER = 5;
// private static final int HASH_COEFFICIENT = 67;
// @Id
// @GeneratedValue
// @Column(name = "id")
// private Long id;
// @Column(name = "url")
// private String url;
//
// @Override
// public Long getId() {
// return id;
// }
//
// @Override
// public void setId(Long id) {
// this.id = id;
// }
//
// @Override
// public String getUrl() {
// return url;
// }
//
// @Override
// public void setUrl(String url) {
// this.url = url;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final UrlImpl other = (UrlImpl) obj;
// if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
// return false;
// }
// if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// int hash = HASH_NUMBER;
// hash = HASH_COEFFICIENT * hash + (this.id != null ? this.id.hashCode() : 0);
// hash = HASH_COEFFICIENT * hash + (this.url != null ? this.url.hashCode() : 0);
// return hash;
// }
// }
| import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.asqatasun.sdk.entity.dao.jpa.AbstractJPADAO;
import org.asqatasun.websnapshot.entity.Url;
import org.asqatasun.websnapshot.entity.UrlImpl; | /*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.entity.dao;
public class UrlDAOImpl extends AbstractJPADAO<Url, Long>
implements UrlDAO {
public UrlDAOImpl() {
super();
}
@Override
protected Class<? extends Url> getEntityClass() { | // Path: websnapshot-api/src/main/java/org/asqatasun/websnapshot/entity/Url.java
// public interface Url extends Entity {
//
// /**
// *
// * @return the url of the image
// */
// String getUrl();
//
// /**
// *
// * @param url
// */
// void setUrl(String url);
// }
//
// Path: websnapshot-impl/src/main/java/org/asqatasun/websnapshot/entity/UrlImpl.java
// @Entity
// @Table(name = "url")
// @XmlRootElement
// public class UrlImpl implements Url, Serializable {
//
// private static final int HASH_NUMBER = 5;
// private static final int HASH_COEFFICIENT = 67;
// @Id
// @GeneratedValue
// @Column(name = "id")
// private Long id;
// @Column(name = "url")
// private String url;
//
// @Override
// public Long getId() {
// return id;
// }
//
// @Override
// public void setId(Long id) {
// this.id = id;
// }
//
// @Override
// public String getUrl() {
// return url;
// }
//
// @Override
// public void setUrl(String url) {
// this.url = url;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// final UrlImpl other = (UrlImpl) obj;
// if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
// return false;
// }
// if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// int hash = HASH_NUMBER;
// hash = HASH_COEFFICIENT * hash + (this.id != null ? this.id.hashCode() : 0);
// hash = HASH_COEFFICIENT * hash + (this.url != null ? this.url.hashCode() : 0);
// return hash;
// }
// }
// Path: websnapshot-persistence/src/main/java/org/asqatasun/websnapshot/entity/dao/UrlDAOImpl.java
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.asqatasun.sdk.entity.dao.jpa.AbstractJPADAO;
import org.asqatasun.websnapshot.entity.Url;
import org.asqatasun.websnapshot.entity.UrlImpl;
/*
* Web-Snapshot
* Copyright (C) 2008-2017 Asqatasun.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact us by mail: asqatasun AT asqatasun DOT org
*/
package org.asqatasun.websnapshot.entity.dao;
public class UrlDAOImpl extends AbstractJPADAO<Url, Long>
implements UrlDAO {
public UrlDAOImpl() {
super();
}
@Override
protected Class<? extends Url> getEntityClass() { | return UrlImpl.class; |
chanjarster/spring-tx-learn | src/main/java/manual/FooServiceImpl.java | // Path: src/main/java/exception/FooException.java
// public class FooException extends Exception {
//
// public FooException() {
// super();
// }
//
// public FooException(String message) {
// super(message);
// }
//
// public FooException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public FooException(Throwable cause) {
// super(cause);
// }
//
// protected FooException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
| import exception.FooException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.List; | package manual;
/**
* Created by qianjia on 2017/1/22.
*/
@Component
public class FooServiceImpl implements FooService {
private final static Logger LOGGER = LoggerFactory.getLogger(FooServiceImpl.class);
private final JdbcTemplate jdbcTemplate;
public FooServiceImpl(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
@Transactional(isolation = Isolation.DEFAULT) | // Path: src/main/java/exception/FooException.java
// public class FooException extends Exception {
//
// public FooException() {
// super();
// }
//
// public FooException(String message) {
// super(message);
// }
//
// public FooException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public FooException(Throwable cause) {
// super(cause);
// }
//
// protected FooException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// }
// Path: src/main/java/manual/FooServiceImpl.java
import exception.FooException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.List;
package manual;
/**
* Created by qianjia on 2017/1/22.
*/
@Component
public class FooServiceImpl implements FooService {
private final static Logger LOGGER = LoggerFactory.getLogger(FooServiceImpl.class);
private final JdbcTemplate jdbcTemplate;
public FooServiceImpl(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
@Transactional(isolation = Isolation.DEFAULT) | public void insert(boolean rollback, String... names) throws FooException { |
wdullaer/MaterialDateTimePicker | library/src/test/java/com/wdullaer/materialdatetimepicker/time/DefaultTimepointLimiterTest.java | // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int HOUR_INDEX = 0;
//
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int MINUTE_INDEX = 1;
| import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.HOUR_INDEX;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.MINUTE_INDEX;
import org.junit.Test;
import org.junit.Assert; | Timepoint[] selectableDays = {
new Timepoint(13),
new Timepoint(14)
};
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
limiter.setSelectableTimes(selectableDays);
Assert.assertTrue(limiter.isOutOfRange(input));
}
@Test
public void isOutOfRangeShouldReturnFalseIfInputSelectable() {
Timepoint input = new Timepoint(15);
Timepoint[] selectableDays = {
new Timepoint(4),
new Timepoint(10),
new Timepoint(15)
};
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
limiter.setSelectableTimes(selectableDays);
Assert.assertFalse(limiter.isOutOfRange(input));
}
@Test
public void isOutOfRangeWithIndexShouldHandleNull() {
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
| // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int HOUR_INDEX = 0;
//
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int MINUTE_INDEX = 1;
// Path: library/src/test/java/com/wdullaer/materialdatetimepicker/time/DefaultTimepointLimiterTest.java
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.HOUR_INDEX;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.MINUTE_INDEX;
import org.junit.Test;
import org.junit.Assert;
Timepoint[] selectableDays = {
new Timepoint(13),
new Timepoint(14)
};
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
limiter.setSelectableTimes(selectableDays);
Assert.assertTrue(limiter.isOutOfRange(input));
}
@Test
public void isOutOfRangeShouldReturnFalseIfInputSelectable() {
Timepoint input = new Timepoint(15);
Timepoint[] selectableDays = {
new Timepoint(4),
new Timepoint(10),
new Timepoint(15)
};
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
limiter.setSelectableTimes(selectableDays);
Assert.assertFalse(limiter.isOutOfRange(input));
}
@Test
public void isOutOfRangeWithIndexShouldHandleNull() {
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
| Assert.assertFalse(limiter.isOutOfRange(null, HOUR_INDEX, Timepoint.TYPE.SECOND)); |
wdullaer/MaterialDateTimePicker | library/src/test/java/com/wdullaer/materialdatetimepicker/time/DefaultTimepointLimiterTest.java | // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int HOUR_INDEX = 0;
//
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int MINUTE_INDEX = 1;
| import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.HOUR_INDEX;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.MINUTE_INDEX;
import org.junit.Test;
import org.junit.Assert; | @Test
public void isOutOfRangeShouldReturnFalseIfInputSelectable() {
Timepoint input = new Timepoint(15);
Timepoint[] selectableDays = {
new Timepoint(4),
new Timepoint(10),
new Timepoint(15)
};
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
limiter.setSelectableTimes(selectableDays);
Assert.assertFalse(limiter.isOutOfRange(input));
}
@Test
public void isOutOfRangeWithIndexShouldHandleNull() {
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
Assert.assertFalse(limiter.isOutOfRange(null, HOUR_INDEX, Timepoint.TYPE.SECOND));
}
@Test
public void isOutOfRangeMinuteShouldReturnFalseWhenMinTimeEqualsToTheMinute() {
Timepoint minTime = new Timepoint(12, 13, 14);
Timepoint input = new Timepoint(12, 13);
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
limiter.setMinTime(minTime);
| // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int HOUR_INDEX = 0;
//
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int MINUTE_INDEX = 1;
// Path: library/src/test/java/com/wdullaer/materialdatetimepicker/time/DefaultTimepointLimiterTest.java
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.HOUR_INDEX;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.MINUTE_INDEX;
import org.junit.Test;
import org.junit.Assert;
@Test
public void isOutOfRangeShouldReturnFalseIfInputSelectable() {
Timepoint input = new Timepoint(15);
Timepoint[] selectableDays = {
new Timepoint(4),
new Timepoint(10),
new Timepoint(15)
};
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
limiter.setSelectableTimes(selectableDays);
Assert.assertFalse(limiter.isOutOfRange(input));
}
@Test
public void isOutOfRangeWithIndexShouldHandleNull() {
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
Assert.assertFalse(limiter.isOutOfRange(null, HOUR_INDEX, Timepoint.TYPE.SECOND));
}
@Test
public void isOutOfRangeMinuteShouldReturnFalseWhenMinTimeEqualsToTheMinute() {
Timepoint minTime = new Timepoint(12, 13, 14);
Timepoint input = new Timepoint(12, 13);
DefaultTimepointLimiter limiter = new DefaultTimepointLimiter();
limiter.setMinTime(minTime);
| Assert.assertFalse(limiter.isOutOfRange(input, MINUTE_INDEX, Timepoint.TYPE.SECOND)); |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/DefaultTimepointLimiter.java | // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int HOUR_INDEX = 0;
//
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int MINUTE_INDEX = 1;
| import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Arrays;
import java.util.TreeSet;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.HOUR_INDEX;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.MINUTE_INDEX; | mDisabledTimes.addAll(Arrays.asList(disabledTimes));
exclusiveSelectableTimes = getExclusiveSelectableTimes(mSelectableTimes, mDisabledTimes);
}
@Nullable Timepoint getMinTime() {
return mMinTime;
}
@Nullable Timepoint getMaxTime() {
return mMaxTime;
}
@NonNull Timepoint[] getSelectableTimes() {
return mSelectableTimes.toArray(new Timepoint[mSelectableTimes.size()]);
}
@NonNull Timepoint[] getDisabledTimes() {
return mDisabledTimes.toArray(new Timepoint[mDisabledTimes.size()]);
}
@NonNull private TreeSet<Timepoint> getExclusiveSelectableTimes(@NonNull TreeSet<Timepoint> selectable, @NonNull TreeSet<Timepoint> disabled) {
TreeSet<Timepoint> output = new TreeSet<>(selectable);
output.removeAll(disabled);
return output;
}
@Override
public boolean isOutOfRange(@Nullable Timepoint current, int index, @NonNull Timepoint.TYPE resolution) {
if (current == null) return false;
| // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int HOUR_INDEX = 0;
//
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int MINUTE_INDEX = 1;
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/DefaultTimepointLimiter.java
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Arrays;
import java.util.TreeSet;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.HOUR_INDEX;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.MINUTE_INDEX;
mDisabledTimes.addAll(Arrays.asList(disabledTimes));
exclusiveSelectableTimes = getExclusiveSelectableTimes(mSelectableTimes, mDisabledTimes);
}
@Nullable Timepoint getMinTime() {
return mMinTime;
}
@Nullable Timepoint getMaxTime() {
return mMaxTime;
}
@NonNull Timepoint[] getSelectableTimes() {
return mSelectableTimes.toArray(new Timepoint[mSelectableTimes.size()]);
}
@NonNull Timepoint[] getDisabledTimes() {
return mDisabledTimes.toArray(new Timepoint[mDisabledTimes.size()]);
}
@NonNull private TreeSet<Timepoint> getExclusiveSelectableTimes(@NonNull TreeSet<Timepoint> selectable, @NonNull TreeSet<Timepoint> disabled) {
TreeSet<Timepoint> output = new TreeSet<>(selectable);
output.removeAll(disabled);
return output;
}
@Override
public boolean isOutOfRange(@Nullable Timepoint current, int index, @NonNull Timepoint.TYPE resolution) {
if (current == null) return false;
| if (index == HOUR_INDEX) { |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/DefaultTimepointLimiter.java | // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int HOUR_INDEX = 0;
//
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int MINUTE_INDEX = 1;
| import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Arrays;
import java.util.TreeSet;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.HOUR_INDEX;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.MINUTE_INDEX; |
@NonNull private TreeSet<Timepoint> getExclusiveSelectableTimes(@NonNull TreeSet<Timepoint> selectable, @NonNull TreeSet<Timepoint> disabled) {
TreeSet<Timepoint> output = new TreeSet<>(selectable);
output.removeAll(disabled);
return output;
}
@Override
public boolean isOutOfRange(@Nullable Timepoint current, int index, @NonNull Timepoint.TYPE resolution) {
if (current == null) return false;
if (index == HOUR_INDEX) {
if (mMinTime != null && mMinTime.getHour() > current.getHour()) return true;
if (mMaxTime != null && mMaxTime.getHour()+1 <= current.getHour()) return true;
if (!exclusiveSelectableTimes.isEmpty()) {
Timepoint ceil = exclusiveSelectableTimes.ceiling(current);
Timepoint floor = exclusiveSelectableTimes.floor(current);
return !(current.equals(ceil, Timepoint.TYPE.HOUR) || current.equals(floor, Timepoint.TYPE.HOUR));
}
if (!mDisabledTimes.isEmpty() && resolution == Timepoint.TYPE.HOUR) {
Timepoint ceil = mDisabledTimes.ceiling(current);
Timepoint floor = mDisabledTimes.floor(current);
return current.equals(ceil, Timepoint.TYPE.HOUR) || current.equals(floor, Timepoint.TYPE.HOUR);
}
return false;
} | // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int HOUR_INDEX = 0;
//
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java
// public static final int MINUTE_INDEX = 1;
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/time/DefaultTimepointLimiter.java
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Arrays;
import java.util.TreeSet;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.HOUR_INDEX;
import static com.wdullaer.materialdatetimepicker.time.TimePickerDialog.MINUTE_INDEX;
@NonNull private TreeSet<Timepoint> getExclusiveSelectableTimes(@NonNull TreeSet<Timepoint> selectable, @NonNull TreeSet<Timepoint> disabled) {
TreeSet<Timepoint> output = new TreeSet<>(selectable);
output.removeAll(disabled);
return output;
}
@Override
public boolean isOutOfRange(@Nullable Timepoint current, int index, @NonNull Timepoint.TYPE resolution) {
if (current == null) return false;
if (index == HOUR_INDEX) {
if (mMinTime != null && mMinTime.getHour() > current.getHour()) return true;
if (mMaxTime != null && mMaxTime.getHour()+1 <= current.getHour()) return true;
if (!exclusiveSelectableTimes.isEmpty()) {
Timepoint ceil = exclusiveSelectableTimes.ceiling(current);
Timepoint floor = exclusiveSelectableTimes.floor(current);
return !(current.equals(ceil, Timepoint.TYPE.HOUR) || current.equals(floor, Timepoint.TYPE.HOUR));
}
if (!mDisabledTimes.isEmpty() && resolution == Timepoint.TYPE.HOUR) {
Timepoint ceil = mDisabledTimes.ceiling(current);
Timepoint floor = mDisabledTimes.floor(current);
return current.equals(ceil, Timepoint.TYPE.HOUR) || current.equals(floor, Timepoint.TYPE.HOUR);
}
return false;
} | else if (index == MINUTE_INDEX) { |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java | // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthAdapter.java
// public static class CalendarDay {
// private Calendar calendar;
// int year;
// int month;
// int day;
// TimeZone mTimeZone;
//
// public CalendarDay(TimeZone timeZone) {
// mTimeZone = timeZone;
// setTime(System.currentTimeMillis());
// }
//
// public CalendarDay(long timeInMillis, TimeZone timeZone) {
// mTimeZone = timeZone;
// setTime(timeInMillis);
// }
//
// public CalendarDay(Calendar calendar, TimeZone timeZone) {
// mTimeZone = timeZone;
// year = calendar.get(Calendar.YEAR);
// month = calendar.get(Calendar.MONTH);
// day = calendar.get(Calendar.DAY_OF_MONTH);
// }
//
// @SuppressWarnings("unused")
// public CalendarDay(int year, int month, int day) {
// setDay(year, month, day);
// }
//
// public CalendarDay(int year, int month, int day, TimeZone timezone) {
// mTimeZone = timezone;
// setDay(year, month, day);
// }
//
// public void set(CalendarDay date) {
// year = date.year;
// month = date.month;
// day = date.day;
// }
//
// public void setDay(int year, int month, int day) {
// this.year = year;
// this.month = month;
// this.day = day;
// }
//
// private void setTime(long timeInMillis) {
// if (calendar == null) {
// calendar = Calendar.getInstance(mTimeZone);
// }
// calendar.setTimeInMillis(timeInMillis);
// month = calendar.get(Calendar.MONTH);
// year = calendar.get(Calendar.YEAR);
// day = calendar.get(Calendar.DAY_OF_MONTH);
// }
//
// public int getYear() {
// return year;
// }
//
// public int getMonth() {
// return month;
// }
//
// public int getDay() {
// return day;
// }
// }
| import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.customview.widget.ExploreByTouchHelper;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.wdullaer.materialdatetimepicker.R;
import com.wdullaer.materialdatetimepicker.date.MonthAdapter.CalendarDay;
import java.security.InvalidParameterException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Locale; | protected int getInternalDayFromLocation(float x, float y) {
int dayStart = mEdgePadding;
if (x < dayStart || x > mWidth - mEdgePadding) {
return -1;
}
// Selection is (x - start) / (pixels/day) == (x -s) * day / pixels
int row = (int) (y - getMonthHeaderSize()) / mRowHeight;
int column = (int) ((x - dayStart) * mNumDays / (mWidth - dayStart - mEdgePadding));
int day = column - findDayOffset() + 1;
day += row * mNumDays;
return day;
}
/**
* Called when the user clicks on a day. Handles callbacks to the
* {@link OnDayClickListener} if one is set.
* <p/>
* If the day is out of the range set by minDate and/or maxDate, this is a no-op.
*
* @param day The day that was clicked
*/
private void onDayClick(int day) {
// If the min / max date are set, only process the click if it's a valid selection.
if (mController.isOutOfRange(mYear, mMonth, day)) {
return;
}
if (mOnDayClickListener != null) { | // Path: library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthAdapter.java
// public static class CalendarDay {
// private Calendar calendar;
// int year;
// int month;
// int day;
// TimeZone mTimeZone;
//
// public CalendarDay(TimeZone timeZone) {
// mTimeZone = timeZone;
// setTime(System.currentTimeMillis());
// }
//
// public CalendarDay(long timeInMillis, TimeZone timeZone) {
// mTimeZone = timeZone;
// setTime(timeInMillis);
// }
//
// public CalendarDay(Calendar calendar, TimeZone timeZone) {
// mTimeZone = timeZone;
// year = calendar.get(Calendar.YEAR);
// month = calendar.get(Calendar.MONTH);
// day = calendar.get(Calendar.DAY_OF_MONTH);
// }
//
// @SuppressWarnings("unused")
// public CalendarDay(int year, int month, int day) {
// setDay(year, month, day);
// }
//
// public CalendarDay(int year, int month, int day, TimeZone timezone) {
// mTimeZone = timezone;
// setDay(year, month, day);
// }
//
// public void set(CalendarDay date) {
// year = date.year;
// month = date.month;
// day = date.day;
// }
//
// public void setDay(int year, int month, int day) {
// this.year = year;
// this.month = month;
// this.day = day;
// }
//
// private void setTime(long timeInMillis) {
// if (calendar == null) {
// calendar = Calendar.getInstance(mTimeZone);
// }
// calendar.setTimeInMillis(timeInMillis);
// month = calendar.get(Calendar.MONTH);
// year = calendar.get(Calendar.YEAR);
// day = calendar.get(Calendar.DAY_OF_MONTH);
// }
//
// public int getYear() {
// return year;
// }
//
// public int getMonth() {
// return month;
// }
//
// public int getDay() {
// return day;
// }
// }
// Path: library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.customview.widget.ExploreByTouchHelper;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import com.wdullaer.materialdatetimepicker.R;
import com.wdullaer.materialdatetimepicker.date.MonthAdapter.CalendarDay;
import java.security.InvalidParameterException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
protected int getInternalDayFromLocation(float x, float y) {
int dayStart = mEdgePadding;
if (x < dayStart || x > mWidth - mEdgePadding) {
return -1;
}
// Selection is (x - start) / (pixels/day) == (x -s) * day / pixels
int row = (int) (y - getMonthHeaderSize()) / mRowHeight;
int column = (int) ((x - dayStart) * mNumDays / (mWidth - dayStart - mEdgePadding));
int day = column - findDayOffset() + 1;
day += row * mNumDays;
return day;
}
/**
* Called when the user clicks on a day. Handles callbacks to the
* {@link OnDayClickListener} if one is set.
* <p/>
* If the day is out of the range set by minDate and/or maxDate, this is a no-op.
*
* @param day The day that was clicked
*/
private void onDayClick(int day) {
// If the min / max date are set, only process the click if it's a valid selection.
if (mController.isOutOfRange(mYear, mMonth, day)) {
return;
}
if (mOnDayClickListener != null) { | mOnDayClickListener.onDayClick(this, new CalendarDay(mYear, mMonth, day, mController.getTimeZone())); |
iluu/algs-progfun | src/test/java/com/hackerrank/JumpingOnTheCloudsRevisitedTest.java | // Path: src/main/java/com/hackerrank/JumpingOnTheCloudsRevisited.java
// static int calculateEnergy(byte[] c, int k) {
// int energy = 100;
// int i = 0;
// while ((i = (i + k) % c.length) != 0) {
// energy = calculateEnergy(c, energy, i);
// }
//
// return calculateEnergy(c, energy, i);
// }
| import org.junit.Test;
import static com.hackerrank.JumpingOnTheCloudsRevisited.calculateEnergy;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | package com.hackerrank;
public class JumpingOnTheCloudsRevisitedTest {
@Test
public void baseTestCase() { | // Path: src/main/java/com/hackerrank/JumpingOnTheCloudsRevisited.java
// static int calculateEnergy(byte[] c, int k) {
// int energy = 100;
// int i = 0;
// while ((i = (i + k) % c.length) != 0) {
// energy = calculateEnergy(c, energy, i);
// }
//
// return calculateEnergy(c, energy, i);
// }
// Path: src/test/java/com/hackerrank/JumpingOnTheCloudsRevisitedTest.java
import org.junit.Test;
import static com.hackerrank.JumpingOnTheCloudsRevisited.calculateEnergy;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
package com.hackerrank;
public class JumpingOnTheCloudsRevisitedTest {
@Test
public void baseTestCase() { | assertThat(calculateEnergy(new byte[]{0, 0, 1, 0, 0, 1, 1, 0}, 2)).isEqualTo(92); |
iluu/algs-progfun | src/test/java/com/hackerrank/LeftRotationTest.java | // Path: src/main/java/com/hackerrank/LeftRotation.java
// static String rotateLeft(int[] a, int d) {
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < a.length; i++) {
// int rIdx = rotatedIdx(i, d, a.length);
// sb.append(a[rIdx]);
// if (i != a.length - 1) {
// sb.append(" ");
// }
//
// }
// return sb.toString();
// }
| import org.junit.Test;
import static com.hackerrank.LeftRotation.rotateLeft;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | package com.hackerrank;
public class LeftRotationTest {
@Test
public void simpleTestCase() { | // Path: src/main/java/com/hackerrank/LeftRotation.java
// static String rotateLeft(int[] a, int d) {
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < a.length; i++) {
// int rIdx = rotatedIdx(i, d, a.length);
// sb.append(a[rIdx]);
// if (i != a.length - 1) {
// sb.append(" ");
// }
//
// }
// return sb.toString();
// }
// Path: src/test/java/com/hackerrank/LeftRotationTest.java
import org.junit.Test;
import static com.hackerrank.LeftRotation.rotateLeft;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
package com.hackerrank;
public class LeftRotationTest {
@Test
public void simpleTestCase() { | assertThat(rotateLeft(new int[]{1, 2, 3, 4, 5}, 4)) |
iluu/algs-progfun | src/test/java/com/hackerrank/ChocolateFeastTest.java | // Path: src/main/java/com/hackerrank/ChocolateFeast.java
// static int chocolatesEaten(int nDollars, int cPrice, int mWrappersForC) {
// int wrappers = nDollars / cPrice;
// int result = wrappers;
// while (wrappers >= mWrappersForC) {
// result += wrappers / mWrappersForC;
// wrappers = wrappers / mWrappersForC + wrappers % mWrappersForC;
// }
// return result;
// }
| import org.junit.Test;
import static com.hackerrank.ChocolateFeast.chocolatesEaten;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | package com.hackerrank;
public class ChocolateFeastTest {
@Test
public void simpleTestCase() { | // Path: src/main/java/com/hackerrank/ChocolateFeast.java
// static int chocolatesEaten(int nDollars, int cPrice, int mWrappersForC) {
// int wrappers = nDollars / cPrice;
// int result = wrappers;
// while (wrappers >= mWrappersForC) {
// result += wrappers / mWrappersForC;
// wrappers = wrappers / mWrappersForC + wrappers % mWrappersForC;
// }
// return result;
// }
// Path: src/test/java/com/hackerrank/ChocolateFeastTest.java
import org.junit.Test;
import static com.hackerrank.ChocolateFeast.chocolatesEaten;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
package com.hackerrank;
public class ChocolateFeastTest {
@Test
public void simpleTestCase() { | assertThat(chocolatesEaten(10, 2, 5)).isEqualTo(6); |
iluu/algs-progfun | src/test/java/com/hackerrank/SherlockAndArrayTest.java | // Path: src/main/java/com/hackerrank/SherlockAndArray.java
// static String findIndex(int[] arr) {
// long sum = 0;
// for (int anArr : arr) {
// sum += anArr;
// }
//
// long rightSum = 0;
// long leftSum = 0;
// for (int i = 1; i < arr.length; i++) {
// leftSum += arr[i - 1];
// rightSum = sum - (leftSum + arr[i]);
// if (leftSum == rightSum) {
// return "YES";
// }
// }
// return leftSum == rightSum ? "YES" : "NO";
// }
| import org.junit.Test;
import static com.hackerrank.SherlockAndArray.findIndex;
import static org.junit.Assert.assertEquals; | package com.hackerrank;
public class SherlockAndArrayTest {
@Test
public void test1() throws Exception {
int[] arr = new int[]{1}; | // Path: src/main/java/com/hackerrank/SherlockAndArray.java
// static String findIndex(int[] arr) {
// long sum = 0;
// for (int anArr : arr) {
// sum += anArr;
// }
//
// long rightSum = 0;
// long leftSum = 0;
// for (int i = 1; i < arr.length; i++) {
// leftSum += arr[i - 1];
// rightSum = sum - (leftSum + arr[i]);
// if (leftSum == rightSum) {
// return "YES";
// }
// }
// return leftSum == rightSum ? "YES" : "NO";
// }
// Path: src/test/java/com/hackerrank/SherlockAndArrayTest.java
import org.junit.Test;
import static com.hackerrank.SherlockAndArray.findIndex;
import static org.junit.Assert.assertEquals;
package com.hackerrank;
public class SherlockAndArrayTest {
@Test
public void test1() throws Exception {
int[] arr = new int[]{1}; | assertEquals(findIndex(arr), "YES"); |
iluu/algs-progfun | src/test/java/com/hackerrank/MaximumSubarrayTest.java | // Path: src/main/java/com/hackerrank/MaximumSubarray.java
// static String findAnswer(long[] a) {
// long current = a[0];
// long maxCont = a[0];
// long max = a[0];
//
// for (int i = 1; i < a.length; i++) {
// if (a[i] > 0) {
// max += a[i];
// }
//
// current = Math.max(a[i], current + a[i]);
// maxCont = current > maxCont ? current : maxCont;
// max = a[i] > max ? a[i] : max;
//
// }
// return maxCont + " " + max;
// }
| import org.junit.Test;
import static com.hackerrank.MaximumSubarray.findAnswer;
import static org.junit.Assert.assertEquals; | package com.hackerrank;
public class MaximumSubarrayTest {
@Test
public void sampleTest1() { | // Path: src/main/java/com/hackerrank/MaximumSubarray.java
// static String findAnswer(long[] a) {
// long current = a[0];
// long maxCont = a[0];
// long max = a[0];
//
// for (int i = 1; i < a.length; i++) {
// if (a[i] > 0) {
// max += a[i];
// }
//
// current = Math.max(a[i], current + a[i]);
// maxCont = current > maxCont ? current : maxCont;
// max = a[i] > max ? a[i] : max;
//
// }
// return maxCont + " " + max;
// }
// Path: src/test/java/com/hackerrank/MaximumSubarrayTest.java
import org.junit.Test;
import static com.hackerrank.MaximumSubarray.findAnswer;
import static org.junit.Assert.assertEquals;
package com.hackerrank;
public class MaximumSubarrayTest {
@Test
public void sampleTest1() { | assertEquals("10 10", findAnswer(new long[]{1, 2, 3, 4})); |
iluu/algs-progfun | src/test/java/com/hackerrank/NonDivisibleSubsetTest.java | // Path: src/main/java/com/hackerrank/NonDivisibleSubset.java
// static int findMaxSubset(int[] a, int k) {
// List<Integer> subset = new ArrayList<>();
// for (int i = 0; i < a.length; i++) {
// if (a[i] % k != 0) {
// subset.add(a[i]);
// }
// if (subset.size() > 0 && divisible(subset, k)) {
// List<Integer> alter = new ArrayList<>();
// alter.addAll(subset);
// alter.remove(i - 1);
//
// if (!divisible(alter, k)) {
// subset = alter;
// } else {
// subset.remove((Integer) a[i]);
// }
// }
//
// }
// return subset.size();
// }
| import org.junit.Test;
import static com.hackerrank.NonDivisibleSubset.findMaxSubset;
import static org.junit.Assert.assertEquals; | package com.hackerrank;
public class NonDivisibleSubsetTest {
@Test
public void maxSubset() throws Exception { | // Path: src/main/java/com/hackerrank/NonDivisibleSubset.java
// static int findMaxSubset(int[] a, int k) {
// List<Integer> subset = new ArrayList<>();
// for (int i = 0; i < a.length; i++) {
// if (a[i] % k != 0) {
// subset.add(a[i]);
// }
// if (subset.size() > 0 && divisible(subset, k)) {
// List<Integer> alter = new ArrayList<>();
// alter.addAll(subset);
// alter.remove(i - 1);
//
// if (!divisible(alter, k)) {
// subset = alter;
// } else {
// subset.remove((Integer) a[i]);
// }
// }
//
// }
// return subset.size();
// }
// Path: src/test/java/com/hackerrank/NonDivisibleSubsetTest.java
import org.junit.Test;
import static com.hackerrank.NonDivisibleSubset.findMaxSubset;
import static org.junit.Assert.assertEquals;
package com.hackerrank;
public class NonDivisibleSubsetTest {
@Test
public void maxSubset() throws Exception { | assertEquals(findMaxSubset(new int[]{1, 7, 2, 4}, 3), 3); |
iluu/algs-progfun | src/test/java/com/hackerrank/SherlockAndAnagramsTest.java | // Path: src/main/java/com/hackerrank/SherlockAndAnagrams.java
// static int countAnagrams(String input) {
// int result = 0;
// for (int i = 0; i < input.length(); i++) {
// for (int j = i + 1; j < input.length(); j++) {
// result += count(input.substring(i, j), input.substring(i + 1, input.length()));
// }
// }
// return result;
// }
| import org.junit.Test;
import static com.hackerrank.SherlockAndAnagrams.countAnagrams;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | package com.hackerrank;
public class SherlockAndAnagramsTest {
@Test
public void noAnagrams() { | // Path: src/main/java/com/hackerrank/SherlockAndAnagrams.java
// static int countAnagrams(String input) {
// int result = 0;
// for (int i = 0; i < input.length(); i++) {
// for (int j = i + 1; j < input.length(); j++) {
// result += count(input.substring(i, j), input.substring(i + 1, input.length()));
// }
// }
// return result;
// }
// Path: src/test/java/com/hackerrank/SherlockAndAnagramsTest.java
import org.junit.Test;
import static com.hackerrank.SherlockAndAnagrams.countAnagrams;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
package com.hackerrank;
public class SherlockAndAnagramsTest {
@Test
public void noAnagrams() { | assertThat(countAnagrams("abcd")).isEqualTo(0); |
iluu/algs-progfun | src/test/java/com/hackerrank/MinimumDistancesTest.java | // Path: src/main/java/com/hackerrank/MinimumDistances.java
// static int minimumDistance(int[] arr) {
// Map<Integer, Integer> entries = new HashMap<>();
// int min = Integer.MAX_VALUE;
// for (int i = 0; i < arr.length; i++) {
// if (!entries.containsKey(arr[i])) {
// entries.put(arr[i], i);
// } else {
// int dist = i - (entries.get(arr[i]));
// if (min > dist) {
// min = dist;
// }
// }
// }
// return min == Integer.MAX_VALUE ? -1 : min;
// }
| import org.junit.Test;
import static com.hackerrank.MinimumDistances.minimumDistance;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | package com.hackerrank;
public class MinimumDistancesTest {
@Test
public void firstTestCase() { | // Path: src/main/java/com/hackerrank/MinimumDistances.java
// static int minimumDistance(int[] arr) {
// Map<Integer, Integer> entries = new HashMap<>();
// int min = Integer.MAX_VALUE;
// for (int i = 0; i < arr.length; i++) {
// if (!entries.containsKey(arr[i])) {
// entries.put(arr[i], i);
// } else {
// int dist = i - (entries.get(arr[i]));
// if (min > dist) {
// min = dist;
// }
// }
// }
// return min == Integer.MAX_VALUE ? -1 : min;
// }
// Path: src/test/java/com/hackerrank/MinimumDistancesTest.java
import org.junit.Test;
import static com.hackerrank.MinimumDistances.minimumDistance;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
package com.hackerrank;
public class MinimumDistancesTest {
@Test
public void firstTestCase() { | assertThat(minimumDistance(new int[]{7, 1, 3, 4, 1, 7})).isEqualTo(3); |
iluu/algs-progfun | src/test/java/com/hackerrank/LibraryFineTest.java | // Path: src/main/java/com/hackerrank/LibraryFine.java
// static int calculateFine(int d1, int m1, int y1, int d2, int m2, int y2) {
// final Calendar c1 = Calendar.getInstance();
// final Calendar c2 = Calendar.getInstance();
//
// c1.set(y1, m1, d1);
// c2.set(y2, m2, d2);
//
// if (c1.compareTo(c2) <= 0) {
// return 0;
// } else if (y1 > y2) {
// return 10000;
// } else if (m1 > m2) {
// return 500 * (m1 - m2);
// } else {
// return 15 * (d1 - d2);
// }
// }
| import org.junit.Test;
import static com.hackerrank.LibraryFine.calculateFine;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat; | package com.hackerrank;
public class LibraryFineTest {
@Test
public void sampleTest() { | // Path: src/main/java/com/hackerrank/LibraryFine.java
// static int calculateFine(int d1, int m1, int y1, int d2, int m2, int y2) {
// final Calendar c1 = Calendar.getInstance();
// final Calendar c2 = Calendar.getInstance();
//
// c1.set(y1, m1, d1);
// c2.set(y2, m2, d2);
//
// if (c1.compareTo(c2) <= 0) {
// return 0;
// } else if (y1 > y2) {
// return 10000;
// } else if (m1 > m2) {
// return 500 * (m1 - m2);
// } else {
// return 15 * (d1 - d2);
// }
// }
// Path: src/test/java/com/hackerrank/LibraryFineTest.java
import org.junit.Test;
import static com.hackerrank.LibraryFine.calculateFine;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
package com.hackerrank;
public class LibraryFineTest {
@Test
public void sampleTest() { | assertThat(calculateFine(9, 6, 2015, 6, 6, 2015), equalTo(45)); |
iluu/algs-progfun | src/test/java/com/hackerrank/CountingValleysTest.java | // Path: src/main/java/com/hackerrank/CountingValleys.java
// static int countValleys(String s) {
// int result = 0;
// int currentLevel = 0;
// for (Character c : s.toCharArray()) {
// if (c == 'U') {
// currentLevel++;
// if (currentLevel == 0) {
// result++;
// }
// } else {
// currentLevel--;
// }
// }
// return result;
// }
| import org.junit.Test;
import static com.hackerrank.CountingValleys.countValleys;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | package com.hackerrank;
public class CountingValleysTest {
@Test
public void firstTestCase() { | // Path: src/main/java/com/hackerrank/CountingValleys.java
// static int countValleys(String s) {
// int result = 0;
// int currentLevel = 0;
// for (Character c : s.toCharArray()) {
// if (c == 'U') {
// currentLevel++;
// if (currentLevel == 0) {
// result++;
// }
// } else {
// currentLevel--;
// }
// }
// return result;
// }
// Path: src/test/java/com/hackerrank/CountingValleysTest.java
import org.junit.Test;
import static com.hackerrank.CountingValleys.countValleys;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
package com.hackerrank;
public class CountingValleysTest {
@Test
public void firstTestCase() { | assertThat(countValleys("UDDDUDUU")).isEqualTo(1); |
iluu/algs-progfun | src/test/java/com/hackerrank/CircularArrayRotationTest.java | // Path: src/main/java/com/hackerrank/CircularArrayRotation.java
// static int getValueAfterRotation(int[] arr, int rot, int idx) {
// return arr[(arr.length + (idx - rot % arr.length)) % arr.length];
// }
| import org.junit.Test;
import static com.hackerrank.CircularArrayRotation.getValueAfterRotation;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*; | package com.hackerrank;
public class CircularArrayRotationTest {
@Test
public void shouldRotateShortArray() {
int arr[] = new int[]{1, 2}; | // Path: src/main/java/com/hackerrank/CircularArrayRotation.java
// static int getValueAfterRotation(int[] arr, int rot, int idx) {
// return arr[(arr.length + (idx - rot % arr.length)) % arr.length];
// }
// Path: src/test/java/com/hackerrank/CircularArrayRotationTest.java
import org.junit.Test;
import static com.hackerrank.CircularArrayRotation.getValueAfterRotation;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*;
package com.hackerrank;
public class CircularArrayRotationTest {
@Test
public void shouldRotateShortArray() {
int arr[] = new int[]{1, 2}; | int value = getValueAfterRotation(arr, 1, 0); |
iluu/algs-progfun | src/test/java/com/hackerrank/AngryProfessorTest.java | // Path: src/main/java/com/hackerrank/AngryProfessor.java
// static String isClassCancelled(int threshold, int[] arrivals) {
// int onTime = 0;
// for (int arrival : arrivals) {
// if (arrival <= 0) {
// onTime++;
// }
// if (onTime >= threshold) {
// return "NO";
// }
// }
// return "YES";
// }
| import org.junit.Test;
import static com.hackerrank.AngryProfessor.isClassCancelled;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo; | package com.hackerrank;
public class AngryProfessorTest {
@Test
public void handlesSampleCase1() {
int[] arrivals = {-1, -3, 4, 2}; | // Path: src/main/java/com/hackerrank/AngryProfessor.java
// static String isClassCancelled(int threshold, int[] arrivals) {
// int onTime = 0;
// for (int arrival : arrivals) {
// if (arrival <= 0) {
// onTime++;
// }
// if (onTime >= threshold) {
// return "NO";
// }
// }
// return "YES";
// }
// Path: src/test/java/com/hackerrank/AngryProfessorTest.java
import org.junit.Test;
import static com.hackerrank.AngryProfessor.isClassCancelled;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
package com.hackerrank;
public class AngryProfessorTest {
@Test
public void handlesSampleCase1() {
int[] arrivals = {-1, -3, 4, 2}; | assertThat(isClassCancelled(3, arrivals), is(equalTo("YES"))); |
iluu/algs-progfun | src/test/java/com/hackerrank/SherlockAndTheBeastTest.java | // Path: src/main/java/com/hackerrank/SherlockAndTheBeast.java
// static String findLargestDecentNumber(int digits) {
// for (int i = digits / 3; i >= 0; i--) {
// if ((digits - 3 * i) % 5 == 0) {
// String result = new String(new char[3 * i]).replace("\0", "5");
// result += new String(new char[digits - 3 * i]).replace("\0", "3");
// return result;
// }
// }
// return "-1";
// }
| import org.junit.Test;
import static com.hackerrank.SherlockAndTheBeast.findLargestDecentNumber;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo; | package com.hackerrank;
public class SherlockAndTheBeastTest {
@Test
public void canHandleMissingValue() { | // Path: src/main/java/com/hackerrank/SherlockAndTheBeast.java
// static String findLargestDecentNumber(int digits) {
// for (int i = digits / 3; i >= 0; i--) {
// if ((digits - 3 * i) % 5 == 0) {
// String result = new String(new char[3 * i]).replace("\0", "5");
// result += new String(new char[digits - 3 * i]).replace("\0", "3");
// return result;
// }
// }
// return "-1";
// }
// Path: src/test/java/com/hackerrank/SherlockAndTheBeastTest.java
import org.junit.Test;
import static com.hackerrank.SherlockAndTheBeast.findLargestDecentNumber;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
package com.hackerrank;
public class SherlockAndTheBeastTest {
@Test
public void canHandleMissingValue() { | assertThat(findLargestDecentNumber(1), is(equalTo("-1"))); |
iluu/algs-progfun | src/test/java/com/hackerrank/BreadthFirstSearchShortestReachTest.java | // Path: src/main/java/com/hackerrank/BreadthFirstSearchShortestReach.java
// static class Graph {
// boolean[][] nodes;
//
// Graph(int size) {
// nodes = new boolean[size][size];
// }
//
// void addEdge(int u, int v) {
// nodes[u][v] = true;
// nodes[v][u] = true;
// }
//
// Set<Integer> getEdges(int u) {
// Set<Integer> result = new HashSet<>();
// for (int i = 0; i < nodes.length; i++) {
// if (nodes[u][i]) {
// result.add(i);
// }
// }
// return result;
// }
// }
//
// Path: src/main/java/com/hackerrank/BreadthFirstSearchShortestReach.java
// static String shortestDistanceForAllNodes(int s, int n, Graph graph) {
// StringBuilder sb = new StringBuilder();
// int[] distances = shortestDistances(s, graph);
// for (int i = 0; i < n; i++) {
// if (distances[i] != 0) {
// sb.append(distances[i]).append(" ");
// }
// }
// return sb.toString().trim();
// }
| import com.hackerrank.BreadthFirstSearchShortestReach.Graph;
import org.junit.Test;
import static com.hackerrank.BreadthFirstSearchShortestReach.shortestDistanceForAllNodes;
import static org.assertj.core.api.Assertions.assertThat; | package com.hackerrank;
public class BreadthFirstSearchShortestReachTest {
@Test
public void shouldFindSingleJumpDistances() {
int start = 0; | // Path: src/main/java/com/hackerrank/BreadthFirstSearchShortestReach.java
// static class Graph {
// boolean[][] nodes;
//
// Graph(int size) {
// nodes = new boolean[size][size];
// }
//
// void addEdge(int u, int v) {
// nodes[u][v] = true;
// nodes[v][u] = true;
// }
//
// Set<Integer> getEdges(int u) {
// Set<Integer> result = new HashSet<>();
// for (int i = 0; i < nodes.length; i++) {
// if (nodes[u][i]) {
// result.add(i);
// }
// }
// return result;
// }
// }
//
// Path: src/main/java/com/hackerrank/BreadthFirstSearchShortestReach.java
// static String shortestDistanceForAllNodes(int s, int n, Graph graph) {
// StringBuilder sb = new StringBuilder();
// int[] distances = shortestDistances(s, graph);
// for (int i = 0; i < n; i++) {
// if (distances[i] != 0) {
// sb.append(distances[i]).append(" ");
// }
// }
// return sb.toString().trim();
// }
// Path: src/test/java/com/hackerrank/BreadthFirstSearchShortestReachTest.java
import com.hackerrank.BreadthFirstSearchShortestReach.Graph;
import org.junit.Test;
import static com.hackerrank.BreadthFirstSearchShortestReach.shortestDistanceForAllNodes;
import static org.assertj.core.api.Assertions.assertThat;
package com.hackerrank;
public class BreadthFirstSearchShortestReachTest {
@Test
public void shouldFindSingleJumpDistances() {
int start = 0; | Graph graph = new Graph(3); |
iluu/algs-progfun | src/test/java/com/hackerrank/BreadthFirstSearchShortestReachTest.java | // Path: src/main/java/com/hackerrank/BreadthFirstSearchShortestReach.java
// static class Graph {
// boolean[][] nodes;
//
// Graph(int size) {
// nodes = new boolean[size][size];
// }
//
// void addEdge(int u, int v) {
// nodes[u][v] = true;
// nodes[v][u] = true;
// }
//
// Set<Integer> getEdges(int u) {
// Set<Integer> result = new HashSet<>();
// for (int i = 0; i < nodes.length; i++) {
// if (nodes[u][i]) {
// result.add(i);
// }
// }
// return result;
// }
// }
//
// Path: src/main/java/com/hackerrank/BreadthFirstSearchShortestReach.java
// static String shortestDistanceForAllNodes(int s, int n, Graph graph) {
// StringBuilder sb = new StringBuilder();
// int[] distances = shortestDistances(s, graph);
// for (int i = 0; i < n; i++) {
// if (distances[i] != 0) {
// sb.append(distances[i]).append(" ");
// }
// }
// return sb.toString().trim();
// }
| import com.hackerrank.BreadthFirstSearchShortestReach.Graph;
import org.junit.Test;
import static com.hackerrank.BreadthFirstSearchShortestReach.shortestDistanceForAllNodes;
import static org.assertj.core.api.Assertions.assertThat; | package com.hackerrank;
public class BreadthFirstSearchShortestReachTest {
@Test
public void shouldFindSingleJumpDistances() {
int start = 0;
Graph graph = new Graph(3);
graph.addEdge(0, 1);
graph.addEdge(0, 2);
| // Path: src/main/java/com/hackerrank/BreadthFirstSearchShortestReach.java
// static class Graph {
// boolean[][] nodes;
//
// Graph(int size) {
// nodes = new boolean[size][size];
// }
//
// void addEdge(int u, int v) {
// nodes[u][v] = true;
// nodes[v][u] = true;
// }
//
// Set<Integer> getEdges(int u) {
// Set<Integer> result = new HashSet<>();
// for (int i = 0; i < nodes.length; i++) {
// if (nodes[u][i]) {
// result.add(i);
// }
// }
// return result;
// }
// }
//
// Path: src/main/java/com/hackerrank/BreadthFirstSearchShortestReach.java
// static String shortestDistanceForAllNodes(int s, int n, Graph graph) {
// StringBuilder sb = new StringBuilder();
// int[] distances = shortestDistances(s, graph);
// for (int i = 0; i < n; i++) {
// if (distances[i] != 0) {
// sb.append(distances[i]).append(" ");
// }
// }
// return sb.toString().trim();
// }
// Path: src/test/java/com/hackerrank/BreadthFirstSearchShortestReachTest.java
import com.hackerrank.BreadthFirstSearchShortestReach.Graph;
import org.junit.Test;
import static com.hackerrank.BreadthFirstSearchShortestReach.shortestDistanceForAllNodes;
import static org.assertj.core.api.Assertions.assertThat;
package com.hackerrank;
public class BreadthFirstSearchShortestReachTest {
@Test
public void shouldFindSingleJumpDistances() {
int start = 0;
Graph graph = new Graph(3);
graph.addEdge(0, 1);
graph.addEdge(0, 2);
| assertThat(shortestDistanceForAllNodes(start, 3, graph)).isEqualTo("6 6"); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.