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
leandreck/spring-typescript-services
annotations/src/main/java/org/leandreck/endpoints/processor/model/TypeNodeFactory.java
// Path: annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/TypeNodeUtils.java // public class TypeNodeUtils { // // static final String NO_TEMPLATE = "NO_TEMPLATE"; // static final String UNDEFINED_TYPE_NAME = "UNDEFINED"; // static final String JAVA_LANG_OBJECT = "java.lang.Object"; // static TypeMirror objectMirror; // // public static <A extends Annotation> A getAnnotationForClass(final TypeMirror typeMirror, final Class<A> annotation, final Types typeUtils) { // final TypeKind kind = typeMirror.getKind(); // final TypeMirror realMirror; // if (TypeKind.ARRAY.equals(kind)) { // realMirror = ((ArrayType) typeMirror).getComponentType(); // } else { // realMirror = typeMirror; // } // // final Element definingElement = typeUtils.asElement(realMirror); // return (definingElement != null) ? definingElement.getAnnotation(annotation) : null; // } // // static String defineTemplate(final String typeNodeTemplate, // final TypeScriptType typeScriptTypeAnnotation, // final Element element) { // // if (typeNodeTemplate == null || typeNodeTemplate.isEmpty()) { // throw new MissingConfigurationTemplateException("TemplateConfiguration is null while processing Element", element); // } // // final String template; // if (typeScriptTypeAnnotation == null || typeScriptTypeAnnotation.template().isEmpty()) { // template = typeNodeTemplate; // } else { // template = typeScriptTypeAnnotation.template(); // } // // return template; // } // // static String defineName(final TypeMirror typeMirror, final TypeScriptType typeScriptTypeAnnotation, final Function<TypeMirror, String> nameFunction) { // //check if has a annotation and a type // final String typeFromAnnotation = TypeNodeUtils.defineTypeFromAnnotation(typeScriptTypeAnnotation); // if (!UNDEFINED_TYPE_NAME.equals(typeFromAnnotation)) { // return typeFromAnnotation; // } // //forward to furter determination // return nameFunction.apply(typeMirror); // } // // static TypeMirror getObjectMirror(final Elements elementUtils) { // if (objectMirror == null) { // objectMirror = elementUtils.getTypeElement(JAVA_LANG_OBJECT).asType(); // } // return objectMirror; // } // // private static String defineTypeFromAnnotation(final TypeScriptType annotation) { // if (annotation != null && !annotation.value().isEmpty()) { // return annotation.value(); // } // return UNDEFINED_TYPE_NAME; // } // // /** // * No Instances of this utility class. // */ // private TypeNodeUtils() { // } // } // // Path: annotations/src/main/java/org/leandreck/endpoints/processor/model/TypeNode.java // protected static final String EMPTY_JAVA_DOC = "";
import org.leandreck.endpoints.annotations.TypeScriptIgnore; import org.leandreck.endpoints.processor.config.TemplateConfiguration; import org.leandreck.endpoints.processor.model.typefactories.ConcreteTypeNodeFactory; import org.leandreck.endpoints.processor.model.typefactories.TypeNodeKind; import org.leandreck.endpoints.processor.model.typefactories.TypeNodeUtils; import javax.lang.model.element.ElementKind; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import java.util.Arrays; import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import static java.util.stream.Collectors.toList; import static org.leandreck.endpoints.processor.model.TypeNode.EMPTY_JAVA_DOC; import static org.leandreck.endpoints.processor.model.typefactories.TypeNodeKind.OPTIONAL;
.filter(c -> filterVariableElements(c, publicGetter)) .map(it -> this.createTypeNode(it, /* parameterName */ null, typeMirror)) .collect(toList()); } private static List<String> definePublicGetter(final TypeElement typeElement, final TypeMirror typeMirror, final Types typeUtils) { final List<String> publicGetters = ElementFilter.methodsIn(typeElement.getEnclosedElements()).stream() .filter(g -> g.getSimpleName().toString().startsWith("get") || g.getSimpleName().toString().startsWith("is")) .filter(g -> g.getModifiers().contains(Modifier.PUBLIC)) .filter(g -> !g.getModifiers().contains(Modifier.ABSTRACT))//FIXME filter remaining modifiers .map(g -> g.getSimpleName().toString()) .collect(toList()); if (isLombokAnnotatedType(typeMirror, typeUtils)) { ElementFilter.fieldsIn(typeElement.getEnclosedElements()).stream() .filter(g -> !g.getModifiers().contains(Modifier.STATIC)) .map(g -> g.getSimpleName().toString()) .forEach(publicGetters::add); } return publicGetters; } @SuppressWarnings("unchecked") private static boolean isLombokAnnotatedType(final TypeMirror typeMirror, final Types typeUtils) { return Arrays.stream(new String[]{"lombok.Data", "lombok.Value", "lombok.Getter"}) .anyMatch(annotationName -> { try { Class dataAnnotationClass = Class.forName(annotationName);
// Path: annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/TypeNodeUtils.java // public class TypeNodeUtils { // // static final String NO_TEMPLATE = "NO_TEMPLATE"; // static final String UNDEFINED_TYPE_NAME = "UNDEFINED"; // static final String JAVA_LANG_OBJECT = "java.lang.Object"; // static TypeMirror objectMirror; // // public static <A extends Annotation> A getAnnotationForClass(final TypeMirror typeMirror, final Class<A> annotation, final Types typeUtils) { // final TypeKind kind = typeMirror.getKind(); // final TypeMirror realMirror; // if (TypeKind.ARRAY.equals(kind)) { // realMirror = ((ArrayType) typeMirror).getComponentType(); // } else { // realMirror = typeMirror; // } // // final Element definingElement = typeUtils.asElement(realMirror); // return (definingElement != null) ? definingElement.getAnnotation(annotation) : null; // } // // static String defineTemplate(final String typeNodeTemplate, // final TypeScriptType typeScriptTypeAnnotation, // final Element element) { // // if (typeNodeTemplate == null || typeNodeTemplate.isEmpty()) { // throw new MissingConfigurationTemplateException("TemplateConfiguration is null while processing Element", element); // } // // final String template; // if (typeScriptTypeAnnotation == null || typeScriptTypeAnnotation.template().isEmpty()) { // template = typeNodeTemplate; // } else { // template = typeScriptTypeAnnotation.template(); // } // // return template; // } // // static String defineName(final TypeMirror typeMirror, final TypeScriptType typeScriptTypeAnnotation, final Function<TypeMirror, String> nameFunction) { // //check if has a annotation and a type // final String typeFromAnnotation = TypeNodeUtils.defineTypeFromAnnotation(typeScriptTypeAnnotation); // if (!UNDEFINED_TYPE_NAME.equals(typeFromAnnotation)) { // return typeFromAnnotation; // } // //forward to furter determination // return nameFunction.apply(typeMirror); // } // // static TypeMirror getObjectMirror(final Elements elementUtils) { // if (objectMirror == null) { // objectMirror = elementUtils.getTypeElement(JAVA_LANG_OBJECT).asType(); // } // return objectMirror; // } // // private static String defineTypeFromAnnotation(final TypeScriptType annotation) { // if (annotation != null && !annotation.value().isEmpty()) { // return annotation.value(); // } // return UNDEFINED_TYPE_NAME; // } // // /** // * No Instances of this utility class. // */ // private TypeNodeUtils() { // } // } // // Path: annotations/src/main/java/org/leandreck/endpoints/processor/model/TypeNode.java // protected static final String EMPTY_JAVA_DOC = ""; // Path: annotations/src/main/java/org/leandreck/endpoints/processor/model/TypeNodeFactory.java import org.leandreck.endpoints.annotations.TypeScriptIgnore; import org.leandreck.endpoints.processor.config.TemplateConfiguration; import org.leandreck.endpoints.processor.model.typefactories.ConcreteTypeNodeFactory; import org.leandreck.endpoints.processor.model.typefactories.TypeNodeKind; import org.leandreck.endpoints.processor.model.typefactories.TypeNodeUtils; import javax.lang.model.element.ElementKind; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import java.util.Arrays; import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import static java.util.stream.Collectors.toList; import static org.leandreck.endpoints.processor.model.TypeNode.EMPTY_JAVA_DOC; import static org.leandreck.endpoints.processor.model.typefactories.TypeNodeKind.OPTIONAL; .filter(c -> filterVariableElements(c, publicGetter)) .map(it -> this.createTypeNode(it, /* parameterName */ null, typeMirror)) .collect(toList()); } private static List<String> definePublicGetter(final TypeElement typeElement, final TypeMirror typeMirror, final Types typeUtils) { final List<String> publicGetters = ElementFilter.methodsIn(typeElement.getEnclosedElements()).stream() .filter(g -> g.getSimpleName().toString().startsWith("get") || g.getSimpleName().toString().startsWith("is")) .filter(g -> g.getModifiers().contains(Modifier.PUBLIC)) .filter(g -> !g.getModifiers().contains(Modifier.ABSTRACT))//FIXME filter remaining modifiers .map(g -> g.getSimpleName().toString()) .collect(toList()); if (isLombokAnnotatedType(typeMirror, typeUtils)) { ElementFilter.fieldsIn(typeElement.getEnclosedElements()).stream() .filter(g -> !g.getModifiers().contains(Modifier.STATIC)) .map(g -> g.getSimpleName().toString()) .forEach(publicGetters::add); } return publicGetters; } @SuppressWarnings("unchecked") private static boolean isLombokAnnotatedType(final TypeMirror typeMirror, final Types typeUtils) { return Arrays.stream(new String[]{"lombok.Data", "lombok.Value", "lombok.Getter"}) .anyMatch(annotationName -> { try { Class dataAnnotationClass = Class.forName(annotationName);
Object dataAnnotation = TypeNodeUtils.getAnnotationForClass(typeMirror, dataAnnotationClass, typeUtils);
lucassaldanha/playdoh
src/main/java/com/lsoftware/playdoh/reader/YamlModelReader.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/CaseUtils.java // public class CaseUtils { // // public static String toSnakeCase(String s) { // return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, s); // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.util.CaseUtils; import com.lsoftware.playdoh.util.FileUtils; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.HashMap; import java.util.Map;
package com.lsoftware.playdoh.reader; public class YamlModelReader implements ModelReader { private FileUtils fileUtils; private Yaml yaml; public YamlModelReader() { this.fileUtils = new FileUtils(); this.yaml = new Yaml(); } @Override public <T> Map<String, T> read(Class<T> type) { Map<String, T> objects = new HashMap<String, T>(); try { InputStream inputStream = fileUtils.readFileFromClasspath(getYamlFilename(type)); Map map = (Map) yaml.load(inputStream); if(map != null) { for (Object o : map.keySet()) { String key = (String) o; objects.put(key, yaml.loadAs(yaml.dump(map.get(key)), type)); } } return objects; } catch (FileNotFoundException e) {
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/CaseUtils.java // public class CaseUtils { // // public static String toSnakeCase(String s) { // return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, s); // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // } // Path: src/main/java/com/lsoftware/playdoh/reader/YamlModelReader.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.util.CaseUtils; import com.lsoftware.playdoh.util.FileUtils; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; package com.lsoftware.playdoh.reader; public class YamlModelReader implements ModelReader { private FileUtils fileUtils; private Yaml yaml; public YamlModelReader() { this.fileUtils = new FileUtils(); this.yaml = new Yaml(); } @Override public <T> Map<String, T> read(Class<T> type) { Map<String, T> objects = new HashMap<String, T>(); try { InputStream inputStream = fileUtils.readFileFromClasspath(getYamlFilename(type)); Map map = (Map) yaml.load(inputStream); if(map != null) { for (Object o : map.keySet()) { String key = (String) o; objects.put(key, yaml.loadAs(yaml.dump(map.get(key)), type)); } } return objects; } catch (FileNotFoundException e) {
throw new FixtureNotFoundException(getYamlFilename(type));
lucassaldanha/playdoh
src/main/java/com/lsoftware/playdoh/reader/YamlModelReader.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/CaseUtils.java // public class CaseUtils { // // public static String toSnakeCase(String s) { // return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, s); // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.util.CaseUtils; import com.lsoftware.playdoh.util.FileUtils; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.HashMap; import java.util.Map;
Map map = (Map) yaml.load(inputStream); if(map != null) { for (Object o : map.keySet()) { String key = (String) o; objects.put(key, yaml.loadAs(yaml.dump(map.get(key)), type)); } } return objects; } catch (FileNotFoundException e) { throw new FixtureNotFoundException(getYamlFilename(type)); } } @Override public <T> T read(String identifier, Class<T> type) { try { InputStream inputStream = fileUtils.readFileFromClasspath(getYamlFilename(type)); Map map = (Map) yaml.load(inputStream); Object obj = map.get(identifier); return yaml.loadAs(yaml.dump(obj), type); } catch (FileNotFoundException e) { throw new FixtureNotFoundException(getYamlFilename(type)); } catch(ConstructorException e) { throw new IllegalArgumentException(e); } } private <T> String getYamlFilename(Class<T> type) {
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/CaseUtils.java // public class CaseUtils { // // public static String toSnakeCase(String s) { // return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, s); // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // } // Path: src/main/java/com/lsoftware/playdoh/reader/YamlModelReader.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.util.CaseUtils; import com.lsoftware.playdoh.util.FileUtils; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; Map map = (Map) yaml.load(inputStream); if(map != null) { for (Object o : map.keySet()) { String key = (String) o; objects.put(key, yaml.loadAs(yaml.dump(map.get(key)), type)); } } return objects; } catch (FileNotFoundException e) { throw new FixtureNotFoundException(getYamlFilename(type)); } } @Override public <T> T read(String identifier, Class<T> type) { try { InputStream inputStream = fileUtils.readFileFromClasspath(getYamlFilename(type)); Map map = (Map) yaml.load(inputStream); Object obj = map.get(identifier); return yaml.loadAs(yaml.dump(obj), type); } catch (FileNotFoundException e) { throw new FixtureNotFoundException(getYamlFilename(type)); } catch(ConstructorException e) { throw new IllegalArgumentException(e); } } private <T> String getYamlFilename(Class<T> type) {
return CaseUtils.toSnakeCase(type.getSimpleName()) + ".yml";
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/YamlFixtureObjectBuilderTest.java
// Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // }
import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.io.FileNotFoundException; import java.util.List; import static org.junit.Assert.assertEquals;
package com.lsoftware.playdoh; public class YamlFixtureObjectBuilderTest { private YamlFixtureObjectBuilder builder = new YamlFixtureObjectBuilder(); @Test public void testBuildUserObjectFromFixture() throws FileNotFoundException {
// Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // Path: src/test/java/com/lsoftware/playdoh/YamlFixtureObjectBuilderTest.java import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.io.FileNotFoundException; import java.util.List; import static org.junit.Assert.assertEquals; package com.lsoftware.playdoh; public class YamlFixtureObjectBuilderTest { private YamlFixtureObjectBuilder builder = new YamlFixtureObjectBuilder(); @Test public void testBuildUserObjectFromFixture() throws FileNotFoundException {
User user = builder.build(User.class, "aUser");
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/objects/arrays/ArrayObjectsTest.java
// Path: src/main/java/com/lsoftware/playdoh/Playdoh.java // public final class Playdoh { // // private static PlaydohConfiguration configuration = PlaydohConfiguration.getInstance(); // // /** // * Builds an instance of a class with random data // * @param type The class to be instanced // * @return a object with random data // */ // public static <T> T build(Class<T> type) { // return new ObjectBuilderImpl(type).build(); // } // // /** // * Create an ObjectBuilder for a object of a specific type. // * With an ObjectBuilder it is possible to customize the object creation, as setting specific valuesto some fields. // * @param type the type of the object to be created by the ObjectBuilder // * @return a ObjectBuilder // */ // public static <T> ObjectBuilder builder(Class<T> type) { // return new ObjectBuilderImpl(type); // } // // /** // * Builds an instance of a class with data specified in the yml file with corresponding snake-case name. // * i.e. For an user class will look for a user.yml file with data. // * @param type The class to be instanced // * @param name Tha name of the set of data inside the yml file to be used // * @return a object with data corresponding the yml fixture file // */ // public static <T> T build(Class<T> type, String name) { // return configuration.getFixtureObjectBuilder().build(type, name); // } // // }
import com.lsoftware.playdoh.Playdoh; import org.junit.Test; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue;
package com.lsoftware.playdoh.objects.arrays; public class ArrayObjectsTest { @Test public void testGenerateObjectWithBooleanArray() throws Exception {
// Path: src/main/java/com/lsoftware/playdoh/Playdoh.java // public final class Playdoh { // // private static PlaydohConfiguration configuration = PlaydohConfiguration.getInstance(); // // /** // * Builds an instance of a class with random data // * @param type The class to be instanced // * @return a object with random data // */ // public static <T> T build(Class<T> type) { // return new ObjectBuilderImpl(type).build(); // } // // /** // * Create an ObjectBuilder for a object of a specific type. // * With an ObjectBuilder it is possible to customize the object creation, as setting specific valuesto some fields. // * @param type the type of the object to be created by the ObjectBuilder // * @return a ObjectBuilder // */ // public static <T> ObjectBuilder builder(Class<T> type) { // return new ObjectBuilderImpl(type); // } // // /** // * Builds an instance of a class with data specified in the yml file with corresponding snake-case name. // * i.e. For an user class will look for a user.yml file with data. // * @param type The class to be instanced // * @param name Tha name of the set of data inside the yml file to be used // * @return a object with data corresponding the yml fixture file // */ // public static <T> T build(Class<T> type, String name) { // return configuration.getFixtureObjectBuilder().build(type, name); // } // // } // Path: src/test/java/com/lsoftware/playdoh/objects/arrays/ArrayObjectsTest.java import com.lsoftware.playdoh.Playdoh; import org.junit.Test; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; package com.lsoftware.playdoh.objects.arrays; public class ArrayObjectsTest { @Test public void testGenerateObjectWithBooleanArray() throws Exception {
ObjectWithBooleanArray obj = Playdoh.build(ObjectWithBooleanArray.class);
lucassaldanha/playdoh
src/main/java/com/lsoftware/playdoh/generator/ValueGeneratorFactoryImpl.java
// Path: src/main/java/com/lsoftware/playdoh/util/Primitives.java // public enum Primitives { // // BYTE ("byte", Byte.class, "[B"), // SHORT ("short", Short.class, "[S"), // INT ("int", Integer.class, "[I"), // LONG ("long", Long.class, "[J"), // FLOAT ("float", Float.class, "[F"), // DOUBLE ("double", Double.class, "D"), // BOOLEAN ("boolean", Boolean.class, "[Z"), // CHAR ("char", Character.class, "[C"); // // private final String label; // // private final Class wrapperType; // // private final String primitiveArrayName; // // Primitives(String label, Class wrapperType, String primitiveArrayName) { // this.label = label; // this.wrapperType = wrapperType; // this.primitiveArrayName = primitiveArrayName; // } // // private String getLabel() { // return this.label; // } // // public static Class getWrapper(Class type) { // if(isPrimitive(type)) { // return Primitives.findByLabel(type.getSimpleName()).wrapperType; // } else if(isPrimitiveArray(type)) { // return Primitives.findByLabel(ClassUtils.getClassNameFromArray(type)) // .wrapperType; // } else { // throw new IllegalArgumentException("Not a primitive type: " + type.getSimpleName()); // } // } // // public static boolean isPrimitive(Class type) { // return isPrimitive(type.getSimpleName()); // } // // private static boolean isPrimitive(String typeName) { // for (Primitives primitives : Primitives.values()) { // if(typeName.equals(primitives.getLabel())) { // return true; // } // } // // return false; // } // // public static boolean isPrimitiveArray(Class type) { // return isPrimitive(type.getSimpleName().substring(0, type.getSimpleName().length() - 2)); // } // // private static Primitives findByLabel(String label) { // for (Primitives primitive : Primitives.values()) { // if(primitive.getLabel().equals(label)) { // return primitive; // } // } // // throw new IllegalArgumentException("Not a primitive label: " + label); // } // // }
import com.lsoftware.playdoh.util.Primitives; import java.util.HashMap; import java.util.Map;
package com.lsoftware.playdoh.generator; public class ValueGeneratorFactoryImpl implements ValueGeneratorFactory { private final Map<Class, TypeValueGenerator> generators = new HashMap<Class, TypeValueGenerator>(){{ put( Byte.class, new ByteGenerator()); put( Short.class, new ShortGenerator()); put( Integer.class, new IntegerGenerator()); put( Long.class, new LongGenerator()); put( Float.class, new FloatGenerator()); put( Double.class, new DoubleGenerator()); put( Boolean.class, new BooleanGenerator()); put( Character.class, new CharacterGenerator()); put( String.class, new StringGenerator()); }}; public TypeValueGenerator getFromType(Class type) {
// Path: src/main/java/com/lsoftware/playdoh/util/Primitives.java // public enum Primitives { // // BYTE ("byte", Byte.class, "[B"), // SHORT ("short", Short.class, "[S"), // INT ("int", Integer.class, "[I"), // LONG ("long", Long.class, "[J"), // FLOAT ("float", Float.class, "[F"), // DOUBLE ("double", Double.class, "D"), // BOOLEAN ("boolean", Boolean.class, "[Z"), // CHAR ("char", Character.class, "[C"); // // private final String label; // // private final Class wrapperType; // // private final String primitiveArrayName; // // Primitives(String label, Class wrapperType, String primitiveArrayName) { // this.label = label; // this.wrapperType = wrapperType; // this.primitiveArrayName = primitiveArrayName; // } // // private String getLabel() { // return this.label; // } // // public static Class getWrapper(Class type) { // if(isPrimitive(type)) { // return Primitives.findByLabel(type.getSimpleName()).wrapperType; // } else if(isPrimitiveArray(type)) { // return Primitives.findByLabel(ClassUtils.getClassNameFromArray(type)) // .wrapperType; // } else { // throw new IllegalArgumentException("Not a primitive type: " + type.getSimpleName()); // } // } // // public static boolean isPrimitive(Class type) { // return isPrimitive(type.getSimpleName()); // } // // private static boolean isPrimitive(String typeName) { // for (Primitives primitives : Primitives.values()) { // if(typeName.equals(primitives.getLabel())) { // return true; // } // } // // return false; // } // // public static boolean isPrimitiveArray(Class type) { // return isPrimitive(type.getSimpleName().substring(0, type.getSimpleName().length() - 2)); // } // // private static Primitives findByLabel(String label) { // for (Primitives primitive : Primitives.values()) { // if(primitive.getLabel().equals(label)) { // return primitive; // } // } // // throw new IllegalArgumentException("Not a primitive label: " + label); // } // // } // Path: src/main/java/com/lsoftware/playdoh/generator/ValueGeneratorFactoryImpl.java import com.lsoftware.playdoh.util.Primitives; import java.util.HashMap; import java.util.Map; package com.lsoftware.playdoh.generator; public class ValueGeneratorFactoryImpl implements ValueGeneratorFactory { private final Map<Class, TypeValueGenerator> generators = new HashMap<Class, TypeValueGenerator>(){{ put( Byte.class, new ByteGenerator()); put( Short.class, new ShortGenerator()); put( Integer.class, new IntegerGenerator()); put( Long.class, new LongGenerator()); put( Float.class, new FloatGenerator()); put( Double.class, new DoubleGenerator()); put( Boolean.class, new BooleanGenerator()); put( Character.class, new CharacterGenerator()); put( String.class, new StringGenerator()); }}; public TypeValueGenerator getFromType(Class type) {
if(Primitives.isPrimitive(type) || Primitives.isPrimitiveArray(type)) {
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // }
import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*;
package com.lsoftware.playdoh; public class PlaydohRandomDataObjectBuilder { @Test public void testBuildDummyObject() throws Exception { final Dummy builtDummy = Playdoh.build(Dummy.class); assertNotNull(builtDummy); assertNotNull(builtDummy.getIntegerValue()); assertNotNull(builtDummy.getStringValue()); final NestedDummy nestedDummy = builtDummy.getNestedDummy(); assertNotNull(nestedDummy); assertNotNull(nestedDummy.getIntValue()); assertNotNull(nestedDummy.getStringValue()); } @Test public void testBuildParentObject() { final ParentObject builtParent = Playdoh.build(ParentObject.class); assertNotNull(builtParent.getParentString()); } @Test public void testBuildInheritanceObject() { final InheritanceObject builtInheritance = Playdoh.build(InheritanceObject.class); assertNotNull(builtInheritance.getInheritanceString()); assertNotNull(builtInheritance.getParentString()); } @Test public void testBuildObjectWithArray() {
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*; package com.lsoftware.playdoh; public class PlaydohRandomDataObjectBuilder { @Test public void testBuildDummyObject() throws Exception { final Dummy builtDummy = Playdoh.build(Dummy.class); assertNotNull(builtDummy); assertNotNull(builtDummy.getIntegerValue()); assertNotNull(builtDummy.getStringValue()); final NestedDummy nestedDummy = builtDummy.getNestedDummy(); assertNotNull(nestedDummy); assertNotNull(nestedDummy.getIntValue()); assertNotNull(nestedDummy.getStringValue()); } @Test public void testBuildParentObject() { final ParentObject builtParent = Playdoh.build(ParentObject.class); assertNotNull(builtParent.getParentString()); } @Test public void testBuildInheritanceObject() { final InheritanceObject builtInheritance = Playdoh.build(InheritanceObject.class); assertNotNull(builtInheritance.getInheritanceString()); assertNotNull(builtInheritance.getParentString()); } @Test public void testBuildObjectWithArray() {
final ObjectWithArray objectWithArray = Playdoh.build(ObjectWithArray.class);
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // }
import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*;
@Test public void testBuildInheritanceObject() { final InheritanceObject builtInheritance = Playdoh.build(InheritanceObject.class); assertNotNull(builtInheritance.getInheritanceString()); assertNotNull(builtInheritance.getParentString()); } @Test public void testBuildObjectWithArray() { final ObjectWithArray objectWithArray = Playdoh.build(ObjectWithArray.class); assertNotNull(objectWithArray); assertTrue(objectWithArray.getIntArray().length > 0); } @Test public void testBuildObjectWithPrimitiveArray() { final ObjectWithPrimitiveArray objectWithPrimitiveArray = Playdoh.build(ObjectWithPrimitiveArray.class); assertNotNull(objectWithPrimitiveArray); assertTrue(objectWithPrimitiveArray.getIntArray().length > 0); } @Test public void testBuildObjectWithEnum() { final ObjectWithEnum objectWithEnum = Playdoh.build(ObjectWithEnum.class); assertNotNull(objectWithEnum); } @Test public void testBuildObjectWithMap() {
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*; @Test public void testBuildInheritanceObject() { final InheritanceObject builtInheritance = Playdoh.build(InheritanceObject.class); assertNotNull(builtInheritance.getInheritanceString()); assertNotNull(builtInheritance.getParentString()); } @Test public void testBuildObjectWithArray() { final ObjectWithArray objectWithArray = Playdoh.build(ObjectWithArray.class); assertNotNull(objectWithArray); assertTrue(objectWithArray.getIntArray().length > 0); } @Test public void testBuildObjectWithPrimitiveArray() { final ObjectWithPrimitiveArray objectWithPrimitiveArray = Playdoh.build(ObjectWithPrimitiveArray.class); assertNotNull(objectWithPrimitiveArray); assertTrue(objectWithPrimitiveArray.getIntArray().length > 0); } @Test public void testBuildObjectWithEnum() { final ObjectWithEnum objectWithEnum = Playdoh.build(ObjectWithEnum.class); assertNotNull(objectWithEnum); } @Test public void testBuildObjectWithMap() {
ObjectWithStringObjectMap objectWithMap = Playdoh.build(ObjectWithStringObjectMap.class);
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // }
import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*;
@Test public void testBuildObjectWithArray() { final ObjectWithArray objectWithArray = Playdoh.build(ObjectWithArray.class); assertNotNull(objectWithArray); assertTrue(objectWithArray.getIntArray().length > 0); } @Test public void testBuildObjectWithPrimitiveArray() { final ObjectWithPrimitiveArray objectWithPrimitiveArray = Playdoh.build(ObjectWithPrimitiveArray.class); assertNotNull(objectWithPrimitiveArray); assertTrue(objectWithPrimitiveArray.getIntArray().length > 0); } @Test public void testBuildObjectWithEnum() { final ObjectWithEnum objectWithEnum = Playdoh.build(ObjectWithEnum.class); assertNotNull(objectWithEnum); } @Test public void testBuildObjectWithMap() { ObjectWithStringObjectMap objectWithMap = Playdoh.build(ObjectWithStringObjectMap.class); assertNotNull(objectWithMap); assertEquals(0, objectWithMap.getMap().size()); } @Test public void testBuildObjectWithCollection() {
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*; @Test public void testBuildObjectWithArray() { final ObjectWithArray objectWithArray = Playdoh.build(ObjectWithArray.class); assertNotNull(objectWithArray); assertTrue(objectWithArray.getIntArray().length > 0); } @Test public void testBuildObjectWithPrimitiveArray() { final ObjectWithPrimitiveArray objectWithPrimitiveArray = Playdoh.build(ObjectWithPrimitiveArray.class); assertNotNull(objectWithPrimitiveArray); assertTrue(objectWithPrimitiveArray.getIntArray().length > 0); } @Test public void testBuildObjectWithEnum() { final ObjectWithEnum objectWithEnum = Playdoh.build(ObjectWithEnum.class); assertNotNull(objectWithEnum); } @Test public void testBuildObjectWithMap() { ObjectWithStringObjectMap objectWithMap = Playdoh.build(ObjectWithStringObjectMap.class); assertNotNull(objectWithMap); assertEquals(0, objectWithMap.getMap().size()); } @Test public void testBuildObjectWithCollection() {
ObjectWithCollection objectWithCollection = Playdoh.build(ObjectWithCollection.class);
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // }
import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*;
} @Test public void testBuildObjectWithMap() { ObjectWithStringObjectMap objectWithMap = Playdoh.build(ObjectWithStringObjectMap.class); assertNotNull(objectWithMap); assertEquals(0, objectWithMap.getMap().size()); } @Test public void testBuildObjectWithCollection() { ObjectWithCollection objectWithCollection = Playdoh.build(ObjectWithCollection.class); assertNotNull(objectWithCollection); assertEquals(0, objectWithCollection.getCollection().size()); } @Test public void testBuildObjectWithInaccessibleFieldsShouldSucceed() { ObjectWithInaccessibleFields object = Playdoh.build(ObjectWithInaccessibleFields.class); assertNotNull(object); } @Test public void testBuildObjectWithSelfReferenceShouldSucceed() { ClassWithSelfReference object = Playdoh.build(ClassWithSelfReference.class); assertNotNull(object); } @Test public void testBuildObjectWithNoSetterShouldSucceedWithNoValueForField(){
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*; } @Test public void testBuildObjectWithMap() { ObjectWithStringObjectMap objectWithMap = Playdoh.build(ObjectWithStringObjectMap.class); assertNotNull(objectWithMap); assertEquals(0, objectWithMap.getMap().size()); } @Test public void testBuildObjectWithCollection() { ObjectWithCollection objectWithCollection = Playdoh.build(ObjectWithCollection.class); assertNotNull(objectWithCollection); assertEquals(0, objectWithCollection.getCollection().size()); } @Test public void testBuildObjectWithInaccessibleFieldsShouldSucceed() { ObjectWithInaccessibleFields object = Playdoh.build(ObjectWithInaccessibleFields.class); assertNotNull(object); } @Test public void testBuildObjectWithSelfReferenceShouldSucceed() { ClassWithSelfReference object = Playdoh.build(ClassWithSelfReference.class); assertNotNull(object); } @Test public void testBuildObjectWithNoSetterShouldSucceedWithNoValueForField(){
ClassWithoutSetter object = Playdoh.build(ClassWithoutSetter.class);
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // }
import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*;
@Test public void testBuildObjectWithCollection() { ObjectWithCollection objectWithCollection = Playdoh.build(ObjectWithCollection.class); assertNotNull(objectWithCollection); assertEquals(0, objectWithCollection.getCollection().size()); } @Test public void testBuildObjectWithInaccessibleFieldsShouldSucceed() { ObjectWithInaccessibleFields object = Playdoh.build(ObjectWithInaccessibleFields.class); assertNotNull(object); } @Test public void testBuildObjectWithSelfReferenceShouldSucceed() { ClassWithSelfReference object = Playdoh.build(ClassWithSelfReference.class); assertNotNull(object); } @Test public void testBuildObjectWithNoSetterShouldSucceedWithNoValueForField(){ ClassWithoutSetter object = Playdoh.build(ClassWithoutSetter.class); assertNotNull(object); assertNull(object.getField()); assertNotNull(object.getAnotherField()); } @Test public void testBuildObjectWithNoDefaultConstructorShouldSucceed(){
// Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithArray.java // public class ObjectWithArray { // // private Integer[] intArray; // // public ObjectWithArray() {} // // public void setIntArray(Integer[] intArray) { // this.intArray = intArray; // } // // public Integer[] getIntArray() { // return intArray; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithCollection.java // public class ObjectWithCollection { // // private Collection collection; // // public ObjectWithCollection() {} // // public Collection getCollection() { // return collection; // } // // public void setCollection(Collection collection) { // this.collection = collection; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/collections/ObjectWithStringObjectMap.java // public class ObjectWithStringObjectMap { // // private Map<String, Object> map; // // public ObjectWithStringObjectMap() {} // // public Map<String, Object> getMap() { // return map; // } // // public void setMap(Map<String, Object> map) { // this.map = map; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutDefaultConstructor.java // public class ClassWithoutDefaultConstructor { // // public String field; // // public ClassWithoutDefaultConstructor(String field) { // this.field = field; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohRandomDataObjectBuilder.java import com.lsoftware.playdoh.objects.collections.ObjectWithArray; import com.lsoftware.playdoh.objects.collections.ObjectWithCollection; import com.lsoftware.playdoh.objects.collections.ObjectWithStringObjectMap; import com.lsoftware.playdoh.objects.models.*; import com.lsoftware.playdoh.objects.models.ClassWithoutDefaultConstructor; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.*; @Test public void testBuildObjectWithCollection() { ObjectWithCollection objectWithCollection = Playdoh.build(ObjectWithCollection.class); assertNotNull(objectWithCollection); assertEquals(0, objectWithCollection.getCollection().size()); } @Test public void testBuildObjectWithInaccessibleFieldsShouldSucceed() { ObjectWithInaccessibleFields object = Playdoh.build(ObjectWithInaccessibleFields.class); assertNotNull(object); } @Test public void testBuildObjectWithSelfReferenceShouldSucceed() { ClassWithSelfReference object = Playdoh.build(ClassWithSelfReference.class); assertNotNull(object); } @Test public void testBuildObjectWithNoSetterShouldSucceedWithNoValueForField(){ ClassWithoutSetter object = Playdoh.build(ClassWithoutSetter.class); assertNotNull(object); assertNull(object.getField()); assertNotNull(object.getAnotherField()); } @Test public void testBuildObjectWithNoDefaultConstructorShouldSucceed(){
ClassWithoutDefaultConstructor object = Playdoh.build(ClassWithoutDefaultConstructor.class);
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohSpecificFieldsObjectBuilderTest.java
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // }
import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.assertEquals;
package com.lsoftware.playdoh; public class PlaydohSpecificFieldsObjectBuilderTest { @Test public void testBuildObjectWithSpecificValueOnField() {
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohSpecificFieldsObjectBuilderTest.java import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.assertEquals; package com.lsoftware.playdoh; public class PlaydohSpecificFieldsObjectBuilderTest { @Test public void testBuildObjectWithSpecificValueOnField() {
Dummy dummy = Playdoh.builder(Dummy.class)
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohSpecificFieldsObjectBuilderTest.java
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // }
import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.assertEquals;
package com.lsoftware.playdoh; public class PlaydohSpecificFieldsObjectBuilderTest { @Test public void testBuildObjectWithSpecificValueOnField() { Dummy dummy = Playdoh.builder(Dummy.class) .with("stringValue", "test") .with("integerValue", 123) .build(); assertEquals("test", dummy.getStringValue()); assertEquals(123, dummy.getIntegerValue()); } @Test public void testBuildObjectWithSpecificNestedObject() {
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohSpecificFieldsObjectBuilderTest.java import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.assertEquals; package com.lsoftware.playdoh; public class PlaydohSpecificFieldsObjectBuilderTest { @Test public void testBuildObjectWithSpecificValueOnField() { Dummy dummy = Playdoh.builder(Dummy.class) .with("stringValue", "test") .with("integerValue", 123) .build(); assertEquals("test", dummy.getStringValue()); assertEquals(123, dummy.getIntegerValue()); } @Test public void testBuildObjectWithSpecificNestedObject() {
NestedDummy nestedDummy = Playdoh.build(NestedDummy.class);
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohSpecificFieldsObjectBuilderTest.java
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // }
import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.assertEquals;
package com.lsoftware.playdoh; public class PlaydohSpecificFieldsObjectBuilderTest { @Test public void testBuildObjectWithSpecificValueOnField() { Dummy dummy = Playdoh.builder(Dummy.class) .with("stringValue", "test") .with("integerValue", 123) .build(); assertEquals("test", dummy.getStringValue()); assertEquals(123, dummy.getIntegerValue()); } @Test public void testBuildObjectWithSpecificNestedObject() { NestedDummy nestedDummy = Playdoh.build(NestedDummy.class); Dummy dummy = Playdoh.builder(Dummy.class) .with("nestedDummy", nestedDummy) .build(); assertEquals(nestedDummy, dummy.getNestedDummy()); } @Test(expected = IllegalArgumentException.class) public void testBuildObjectWithAbsentSpecificFieldName() { Playdoh.builder(Dummy.class) .with("absentValue", "test") .build(); } @Test(expected = IllegalArgumentException.class) public void testBuildObjectWithoutSetterForFieldsShouldThrowError() {
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutSetter.java // public class ClassWithoutSetter { // // private String field; // // private String anotherField; // // public ClassWithoutSetter() { // } // // public String getAnotherField() { // return anotherField; // } // // public void setAnotherField(String anotherField) { // this.anotherField = anotherField; // } // // public String getField() { // return field; // } // // // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohSpecificFieldsObjectBuilderTest.java import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.ClassWithoutSetter; import org.junit.Test; import static org.junit.Assert.assertEquals; package com.lsoftware.playdoh; public class PlaydohSpecificFieldsObjectBuilderTest { @Test public void testBuildObjectWithSpecificValueOnField() { Dummy dummy = Playdoh.builder(Dummy.class) .with("stringValue", "test") .with("integerValue", 123) .build(); assertEquals("test", dummy.getStringValue()); assertEquals(123, dummy.getIntegerValue()); } @Test public void testBuildObjectWithSpecificNestedObject() { NestedDummy nestedDummy = Playdoh.build(NestedDummy.class); Dummy dummy = Playdoh.builder(Dummy.class) .with("nestedDummy", nestedDummy) .build(); assertEquals(nestedDummy, dummy.getNestedDummy()); } @Test(expected = IllegalArgumentException.class) public void testBuildObjectWithAbsentSpecificFieldName() { Playdoh.builder(Dummy.class) .with("absentValue", "test") .build(); } @Test(expected = IllegalArgumentException.class) public void testBuildObjectWithoutSetterForFieldsShouldThrowError() {
Playdoh.builder(ClassWithoutSetter.class).with("field", "aString").build();
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*;
package com.lsoftware.playdoh; public class PlaydohFixtureObjectBuilder { @Test public void testBuildObjectFromFixture() {
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*; package com.lsoftware.playdoh; public class PlaydohFixtureObjectBuilder { @Test public void testBuildObjectFromFixture() {
User user1 = Playdoh.build(User.class, "aUser");
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*;
package com.lsoftware.playdoh; public class PlaydohFixtureObjectBuilder { @Test public void testBuildObjectFromFixture() { User user1 = Playdoh.build(User.class, "aUser"); assertNotNull(user1); assertEquals("Lucas Saldanha", user1.getName()); assertEquals("lucas@example.com", user1.getEmail()); assertEquals(123, user1.getAge()); } @Test public void testBuildOtherObjectFromFixture() { User user1 = Playdoh.build(User.class, "anotherUser"); assertNotNull(user1); assertEquals("Abdi Abidu", user1.getName()); assertEquals("aa@example.com", user1.getEmail()); assertEquals(999, user1.getAge()); } @Test public void testBuildNestedObjectFromFixture() {
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*; package com.lsoftware.playdoh; public class PlaydohFixtureObjectBuilder { @Test public void testBuildObjectFromFixture() { User user1 = Playdoh.build(User.class, "aUser"); assertNotNull(user1); assertEquals("Lucas Saldanha", user1.getName()); assertEquals("lucas@example.com", user1.getEmail()); assertEquals(123, user1.getAge()); } @Test public void testBuildOtherObjectFromFixture() { User user1 = Playdoh.build(User.class, "anotherUser"); assertNotNull(user1); assertEquals("Abdi Abidu", user1.getName()); assertEquals("aa@example.com", user1.getEmail()); assertEquals(999, user1.getAge()); } @Test public void testBuildNestedObjectFromFixture() {
Dummy dummy = Playdoh.build(Dummy.class, "dummy1");
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*;
package com.lsoftware.playdoh; public class PlaydohFixtureObjectBuilder { @Test public void testBuildObjectFromFixture() { User user1 = Playdoh.build(User.class, "aUser"); assertNotNull(user1); assertEquals("Lucas Saldanha", user1.getName()); assertEquals("lucas@example.com", user1.getEmail()); assertEquals(123, user1.getAge()); } @Test public void testBuildOtherObjectFromFixture() { User user1 = Playdoh.build(User.class, "anotherUser"); assertNotNull(user1); assertEquals("Abdi Abidu", user1.getName()); assertEquals("aa@example.com", user1.getEmail()); assertEquals(999, user1.getAge()); } @Test public void testBuildNestedObjectFromFixture() { Dummy dummy = Playdoh.build(Dummy.class, "dummy1"); assertNotNull(dummy); assertNotNull(dummy.getNestedDummy()); assertEquals(123, dummy.getIntegerValue()); assertEquals("abc", dummy.getStringValue()); assertEquals(321, dummy.getNestedDummy().getIntValue()); assertEquals("xyz", dummy.getNestedDummy().getStringValue()); } @Test public void testBuildObjectWithEnumFromFixture() {
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*; package com.lsoftware.playdoh; public class PlaydohFixtureObjectBuilder { @Test public void testBuildObjectFromFixture() { User user1 = Playdoh.build(User.class, "aUser"); assertNotNull(user1); assertEquals("Lucas Saldanha", user1.getName()); assertEquals("lucas@example.com", user1.getEmail()); assertEquals(123, user1.getAge()); } @Test public void testBuildOtherObjectFromFixture() { User user1 = Playdoh.build(User.class, "anotherUser"); assertNotNull(user1); assertEquals("Abdi Abidu", user1.getName()); assertEquals("aa@example.com", user1.getEmail()); assertEquals(999, user1.getAge()); } @Test public void testBuildNestedObjectFromFixture() { Dummy dummy = Playdoh.build(Dummy.class, "dummy1"); assertNotNull(dummy); assertNotNull(dummy.getNestedDummy()); assertEquals(123, dummy.getIntegerValue()); assertEquals("abc", dummy.getStringValue()); assertEquals(321, dummy.getNestedDummy().getIntValue()); assertEquals("xyz", dummy.getNestedDummy().getStringValue()); } @Test public void testBuildObjectWithEnumFromFixture() {
ObjectWithEnum objectWithEnum = Playdoh.build(ObjectWithEnum.class, "objectWithEnum");
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*;
} @Test public void testBuildOtherObjectFromFixture() { User user1 = Playdoh.build(User.class, "anotherUser"); assertNotNull(user1); assertEquals("Abdi Abidu", user1.getName()); assertEquals("aa@example.com", user1.getEmail()); assertEquals(999, user1.getAge()); } @Test public void testBuildNestedObjectFromFixture() { Dummy dummy = Playdoh.build(Dummy.class, "dummy1"); assertNotNull(dummy); assertNotNull(dummy.getNestedDummy()); assertEquals(123, dummy.getIntegerValue()); assertEquals("abc", dummy.getStringValue()); assertEquals(321, dummy.getNestedDummy().getIntValue()); assertEquals("xyz", dummy.getNestedDummy().getStringValue()); } @Test public void testBuildObjectWithEnumFromFixture() { ObjectWithEnum objectWithEnum = Playdoh.build(ObjectWithEnum.class, "objectWithEnum"); assertNotNull(objectWithEnum); assertEquals(ObjectWithEnum.AnEnum.X, objectWithEnum.getAnEnum()); }
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*; } @Test public void testBuildOtherObjectFromFixture() { User user1 = Playdoh.build(User.class, "anotherUser"); assertNotNull(user1); assertEquals("Abdi Abidu", user1.getName()); assertEquals("aa@example.com", user1.getEmail()); assertEquals(999, user1.getAge()); } @Test public void testBuildNestedObjectFromFixture() { Dummy dummy = Playdoh.build(Dummy.class, "dummy1"); assertNotNull(dummy); assertNotNull(dummy.getNestedDummy()); assertEquals(123, dummy.getIntegerValue()); assertEquals("abc", dummy.getStringValue()); assertEquals(321, dummy.getNestedDummy().getIntValue()); assertEquals("xyz", dummy.getNestedDummy().getStringValue()); } @Test public void testBuildObjectWithEnumFromFixture() { ObjectWithEnum objectWithEnum = Playdoh.build(ObjectWithEnum.class, "objectWithEnum"); assertNotNull(objectWithEnum); assertEquals(ObjectWithEnum.AnEnum.X, objectWithEnum.getAnEnum()); }
@Test(expected = FixtureNotFoundException.class)
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*;
@Test public void testBuildOtherObjectFromFixture() { User user1 = Playdoh.build(User.class, "anotherUser"); assertNotNull(user1); assertEquals("Abdi Abidu", user1.getName()); assertEquals("aa@example.com", user1.getEmail()); assertEquals(999, user1.getAge()); } @Test public void testBuildNestedObjectFromFixture() { Dummy dummy = Playdoh.build(Dummy.class, "dummy1"); assertNotNull(dummy); assertNotNull(dummy.getNestedDummy()); assertEquals(123, dummy.getIntegerValue()); assertEquals("abc", dummy.getStringValue()); assertEquals(321, dummy.getNestedDummy().getIntValue()); assertEquals("xyz", dummy.getNestedDummy().getStringValue()); } @Test public void testBuildObjectWithEnumFromFixture() { ObjectWithEnum objectWithEnum = Playdoh.build(ObjectWithEnum.class, "objectWithEnum"); assertNotNull(objectWithEnum); assertEquals(ObjectWithEnum.AnEnum.X, objectWithEnum.getAnEnum()); } @Test(expected = FixtureNotFoundException.class) public void testBuildObjectFromAbsentFixture() {
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ObjectWithEnum.java // public class ObjectWithEnum { // // private AnEnum anEnum; // // public ObjectWithEnum() { // } // // public AnEnum getAnEnum() { // return anEnum; // } // // public void setAnEnum(AnEnum anEnum) { // this.anEnum = anEnum; // } // // public enum AnEnum { // X, Y // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohFixtureObjectBuilder.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.collections.*; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.ObjectWithEnum; import com.lsoftware.playdoh.objects.models.User; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import static org.junit.Assert.*; @Test public void testBuildOtherObjectFromFixture() { User user1 = Playdoh.build(User.class, "anotherUser"); assertNotNull(user1); assertEquals("Abdi Abidu", user1.getName()); assertEquals("aa@example.com", user1.getEmail()); assertEquals(999, user1.getAge()); } @Test public void testBuildNestedObjectFromFixture() { Dummy dummy = Playdoh.build(Dummy.class, "dummy1"); assertNotNull(dummy); assertNotNull(dummy.getNestedDummy()); assertEquals(123, dummy.getIntegerValue()); assertEquals("abc", dummy.getStringValue()); assertEquals(321, dummy.getNestedDummy().getIntValue()); assertEquals("xyz", dummy.getNestedDummy().getStringValue()); } @Test public void testBuildObjectWithEnumFromFixture() { ObjectWithEnum objectWithEnum = Playdoh.build(ObjectWithEnum.class, "objectWithEnum"); assertNotNull(objectWithEnum); assertEquals(ObjectWithEnum.AnEnum.X, objectWithEnum.getAnEnum()); } @Test(expected = FixtureNotFoundException.class) public void testBuildObjectFromAbsentFixture() {
Playdoh.build(ClassWithoutFixture.class, "aClass");
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*;
package com.lsoftware.playdoh.reader; public class YamlModelReaderTest { public static final String USERS_YAML_FILE = "user.yml"; private YamlModelReader reader = new YamlModelReader();
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // } // Path: src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; package com.lsoftware.playdoh.reader; public class YamlModelReaderTest { public static final String USERS_YAML_FILE = "user.yml"; private YamlModelReader reader = new YamlModelReader();
private FileUtils mockFileUtils;
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*;
package com.lsoftware.playdoh.reader; public class YamlModelReaderTest { public static final String USERS_YAML_FILE = "user.yml"; private YamlModelReader reader = new YamlModelReader(); private FileUtils mockFileUtils; @Before public void setUp() throws Exception { configureFileUtilsMock(); } private void configureFileUtilsMock() throws FileNotFoundException { mockFileUtils = mock(FileUtils.class); reader.setFileUtils(mockFileUtils); } private void mockFileUtilsToReturnFileInputStream(String filename) throws FileNotFoundException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream(filename); assertNotNull(inputStream); when(mockFileUtils.readFileFromClasspath(eq(filename))).thenReturn(inputStream); } @After public void tearDown() { Mockito.reset(mockFileUtils); } @Test public void testYamlReaderSearchFileWithNameOfClass() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream(USERS_YAML_FILE);
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // } // Path: src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; package com.lsoftware.playdoh.reader; public class YamlModelReaderTest { public static final String USERS_YAML_FILE = "user.yml"; private YamlModelReader reader = new YamlModelReader(); private FileUtils mockFileUtils; @Before public void setUp() throws Exception { configureFileUtilsMock(); } private void configureFileUtilsMock() throws FileNotFoundException { mockFileUtils = mock(FileUtils.class); reader.setFileUtils(mockFileUtils); } private void mockFileUtilsToReturnFileInputStream(String filename) throws FileNotFoundException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream(filename); assertNotNull(inputStream); when(mockFileUtils.readFileFromClasspath(eq(filename))).thenReturn(inputStream); } @After public void tearDown() { Mockito.reset(mockFileUtils); } @Test public void testYamlReaderSearchFileWithNameOfClass() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream(USERS_YAML_FILE);
reader.read(User.class);
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*;
private void configureFileUtilsMock() throws FileNotFoundException { mockFileUtils = mock(FileUtils.class); reader.setFileUtils(mockFileUtils); } private void mockFileUtilsToReturnFileInputStream(String filename) throws FileNotFoundException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream(filename); assertNotNull(inputStream); when(mockFileUtils.readFileFromClasspath(eq(filename))).thenReturn(inputStream); } @After public void tearDown() { Mockito.reset(mockFileUtils); } @Test public void testYamlReaderSearchFileWithNameOfClass() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream(USERS_YAML_FILE); reader.read(User.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq(USERS_YAML_FILE)); } @Test public void testYamlReaderSearchFileWithComposedNameAsSnakeCase() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream("nested_dummy.yml");
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // } // Path: src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; private void configureFileUtilsMock() throws FileNotFoundException { mockFileUtils = mock(FileUtils.class); reader.setFileUtils(mockFileUtils); } private void mockFileUtilsToReturnFileInputStream(String filename) throws FileNotFoundException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream(filename); assertNotNull(inputStream); when(mockFileUtils.readFileFromClasspath(eq(filename))).thenReturn(inputStream); } @After public void tearDown() { Mockito.reset(mockFileUtils); } @Test public void testYamlReaderSearchFileWithNameOfClass() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream(USERS_YAML_FILE); reader.read(User.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq(USERS_YAML_FILE)); } @Test public void testYamlReaderSearchFileWithComposedNameAsSnakeCase() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream("nested_dummy.yml");
reader.read(NestedDummy.class);
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*;
private void mockFileUtilsToReturnFileInputStream(String filename) throws FileNotFoundException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream(filename); assertNotNull(inputStream); when(mockFileUtils.readFileFromClasspath(eq(filename))).thenReturn(inputStream); } @After public void tearDown() { Mockito.reset(mockFileUtils); } @Test public void testYamlReaderSearchFileWithNameOfClass() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream(USERS_YAML_FILE); reader.read(User.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq(USERS_YAML_FILE)); } @Test public void testYamlReaderSearchFileWithComposedNameAsSnakeCase() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream("nested_dummy.yml"); reader.read(NestedDummy.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq("nested_dummy.yml")); }
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // } // Path: src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; private void mockFileUtilsToReturnFileInputStream(String filename) throws FileNotFoundException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream(filename); assertNotNull(inputStream); when(mockFileUtils.readFileFromClasspath(eq(filename))).thenReturn(inputStream); } @After public void tearDown() { Mockito.reset(mockFileUtils); } @Test public void testYamlReaderSearchFileWithNameOfClass() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream(USERS_YAML_FILE); reader.read(User.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq(USERS_YAML_FILE)); } @Test public void testYamlReaderSearchFileWithComposedNameAsSnakeCase() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream("nested_dummy.yml"); reader.read(NestedDummy.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq("nested_dummy.yml")); }
@Test(expected = FixtureNotFoundException.class)
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // }
import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*;
} @After public void tearDown() { Mockito.reset(mockFileUtils); } @Test public void testYamlReaderSearchFileWithNameOfClass() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream(USERS_YAML_FILE); reader.read(User.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq(USERS_YAML_FILE)); } @Test public void testYamlReaderSearchFileWithComposedNameAsSnakeCase() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream("nested_dummy.yml"); reader.read(NestedDummy.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq("nested_dummy.yml")); } @Test(expected = FixtureNotFoundException.class) public void testReadAbsentFileThrowsFixtureNotFoundException() throws FileNotFoundException { when(mockFileUtils.readFileFromClasspath(eq("class_without_fixture.yml"))) .thenThrow(new FileNotFoundException());
// Path: src/main/java/com/lsoftware/playdoh/exception/FixtureNotFoundException.java // public class FixtureNotFoundException extends PlaydohException { // // public FixtureNotFoundException(String fixtureName) { // super("Can't find " + fixtureName + " fixture on classpath"); // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/ClassWithoutFixture.java // public class ClassWithoutFixture { // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/NestedDummy.java // public class NestedDummy { // // private int intValue; // // private String stringValue; // // NestedDummy(int intValue, String stringValue) { // this.intValue = intValue; // this.stringValue = stringValue; // } // // NestedDummy(){} // // public int getIntValue() { // return intValue; // } // // public void setIntValue(int intValue) { // this.intValue = intValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // @Override // public String toString() { // return "NestedDummy{" + // "intValue=" + intValue + // ", stringValue='" + stringValue + '\'' + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof NestedDummy)) return false; // // NestedDummy that = (NestedDummy) o; // // if (intValue != that.intValue) return false; // return !(stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null); // // } // // @Override // public int hashCode() { // int result = intValue; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // // Path: src/main/java/com/lsoftware/playdoh/util/FileUtils.java // public class FileUtils { // // public InputStream readFileFromClasspath(String filename) throws FileNotFoundException { // InputStream in = FileUtils.class.getClassLoader().getResourceAsStream(filename); // // if(in == null) { // throw new FileNotFoundException("Can't find file " + filename); // } // // return in; // } // } // Path: src/test/java/com/lsoftware/playdoh/reader/YamlModelReaderTest.java import com.lsoftware.playdoh.exception.FixtureNotFoundException; import com.lsoftware.playdoh.objects.models.ClassWithoutFixture; import com.lsoftware.playdoh.objects.models.NestedDummy; import com.lsoftware.playdoh.objects.models.User; import com.lsoftware.playdoh.util.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.ConstructorException; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; } @After public void tearDown() { Mockito.reset(mockFileUtils); } @Test public void testYamlReaderSearchFileWithNameOfClass() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream(USERS_YAML_FILE); reader.read(User.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq(USERS_YAML_FILE)); } @Test public void testYamlReaderSearchFileWithComposedNameAsSnakeCase() throws FileNotFoundException { mockFileUtilsToReturnFileInputStream("nested_dummy.yml"); reader.read(NestedDummy.class); verify(mockFileUtils, times(1)).readFileFromClasspath(eq("nested_dummy.yml")); } @Test(expected = FixtureNotFoundException.class) public void testReadAbsentFileThrowsFixtureNotFoundException() throws FileNotFoundException { when(mockFileUtils.readFileFromClasspath(eq("class_without_fixture.yml"))) .thenThrow(new FileNotFoundException());
reader.read(ClassWithoutFixture.class);
lucassaldanha/playdoh
src/main/java/com/lsoftware/playdoh/YamlFixtureObjectBuilder.java
// Path: src/main/java/com/lsoftware/playdoh/reader/YamlModelReader.java // public class YamlModelReader implements ModelReader { // // private FileUtils fileUtils; // // private Yaml yaml; // // public YamlModelReader() { // this.fileUtils = new FileUtils(); // this.yaml = new Yaml(); // } // // @Override // public <T> Map<String, T> read(Class<T> type) { // Map<String, T> objects = new HashMap<String, T>(); // try { // InputStream inputStream = fileUtils.readFileFromClasspath(getYamlFilename(type)); // Map map = (Map) yaml.load(inputStream); // // if(map != null) { // for (Object o : map.keySet()) { // String key = (String) o; // objects.put(key, yaml.loadAs(yaml.dump(map.get(key)), type)); // } // } // // return objects; // } catch (FileNotFoundException e) { // throw new FixtureNotFoundException(getYamlFilename(type)); // } // } // // @Override // public <T> T read(String identifier, Class<T> type) { // try { // InputStream inputStream = fileUtils.readFileFromClasspath(getYamlFilename(type)); // Map map = (Map) yaml.load(inputStream); // Object obj = map.get(identifier); // return yaml.loadAs(yaml.dump(obj), type); // } catch (FileNotFoundException e) { // throw new FixtureNotFoundException(getYamlFilename(type)); // } catch(ConstructorException e) { // throw new IllegalArgumentException(e); // } // } // // private <T> String getYamlFilename(Class<T> type) { // return CaseUtils.toSnakeCase(type.getSimpleName()) + ".yml"; // } // // void setFileUtils(FileUtils fileUtils) { // this.fileUtils = fileUtils; // } // // // void setYaml(Yaml yaml) { // this.yaml = yaml; // } // }
import com.lsoftware.playdoh.reader.YamlModelReader; import java.util.ArrayList; import java.util.List; import java.util.Map;
package com.lsoftware.playdoh; public class YamlFixtureObjectBuilder extends AbstractFixtureObjectBuilder { protected YamlFixtureObjectBuilder() {
// Path: src/main/java/com/lsoftware/playdoh/reader/YamlModelReader.java // public class YamlModelReader implements ModelReader { // // private FileUtils fileUtils; // // private Yaml yaml; // // public YamlModelReader() { // this.fileUtils = new FileUtils(); // this.yaml = new Yaml(); // } // // @Override // public <T> Map<String, T> read(Class<T> type) { // Map<String, T> objects = new HashMap<String, T>(); // try { // InputStream inputStream = fileUtils.readFileFromClasspath(getYamlFilename(type)); // Map map = (Map) yaml.load(inputStream); // // if(map != null) { // for (Object o : map.keySet()) { // String key = (String) o; // objects.put(key, yaml.loadAs(yaml.dump(map.get(key)), type)); // } // } // // return objects; // } catch (FileNotFoundException e) { // throw new FixtureNotFoundException(getYamlFilename(type)); // } // } // // @Override // public <T> T read(String identifier, Class<T> type) { // try { // InputStream inputStream = fileUtils.readFileFromClasspath(getYamlFilename(type)); // Map map = (Map) yaml.load(inputStream); // Object obj = map.get(identifier); // return yaml.loadAs(yaml.dump(obj), type); // } catch (FileNotFoundException e) { // throw new FixtureNotFoundException(getYamlFilename(type)); // } catch(ConstructorException e) { // throw new IllegalArgumentException(e); // } // } // // private <T> String getYamlFilename(Class<T> type) { // return CaseUtils.toSnakeCase(type.getSimpleName()) + ".yml"; // } // // void setFileUtils(FileUtils fileUtils) { // this.fileUtils = fileUtils; // } // // // void setYaml(Yaml yaml) { // this.yaml = yaml; // } // } // Path: src/main/java/com/lsoftware/playdoh/YamlFixtureObjectBuilder.java import com.lsoftware.playdoh.reader.YamlModelReader; import java.util.ArrayList; import java.util.List; import java.util.Map; package com.lsoftware.playdoh; public class YamlFixtureObjectBuilder extends AbstractFixtureObjectBuilder { protected YamlFixtureObjectBuilder() {
super(new YamlModelReader());
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/generator/ValueGeneratorFactoryImplTest.java
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // }
import com.lsoftware.playdoh.objects.models.Dummy; import org.junit.Test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue;
package com.lsoftware.playdoh.generator; public class ValueGeneratorFactoryImplTest { private ValueGeneratorFactoryImpl valueGeneratorFactory = new ValueGeneratorFactoryImpl(); @Test public void testRegister() throws Exception {
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // Path: src/test/java/com/lsoftware/playdoh/generator/ValueGeneratorFactoryImplTest.java import com.lsoftware.playdoh.objects.models.Dummy; import org.junit.Test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; package com.lsoftware.playdoh.generator; public class ValueGeneratorFactoryImplTest { private ValueGeneratorFactoryImpl valueGeneratorFactory = new ValueGeneratorFactoryImpl(); @Test public void testRegister() throws Exception {
assertFalse(valueGeneratorFactory.existsForType(Dummy.class));
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohExample.java
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // }
import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.User;
package com.lsoftware.playdoh; class PlaydohExample { public static void main(String[] args) { /* Creating Dummy instance with random data */
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohExample.java import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.User; package com.lsoftware.playdoh; class PlaydohExample { public static void main(String[] args) { /* Creating Dummy instance with random data */
final Dummy dummy = Playdoh.build(Dummy.class);
lucassaldanha/playdoh
src/test/java/com/lsoftware/playdoh/PlaydohExample.java
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // }
import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.User;
package com.lsoftware.playdoh; class PlaydohExample { public static void main(String[] args) { /* Creating Dummy instance with random data */ final Dummy dummy = Playdoh.build(Dummy.class); System.out.println(dummy); /* Look the user.yml file to see the data specification */
// Path: src/test/java/com/lsoftware/playdoh/objects/models/Dummy.java // public class Dummy { // // private Integer integerValue; // // private String stringValue; // // private NestedDummy nestedDummy; // // Dummy(int integerValue, String stringValue, NestedDummy nestedDummy) { // this.integerValue = integerValue; // this.stringValue = stringValue; // this.nestedDummy = nestedDummy; // } // // public Dummy(){} // // public int getIntegerValue() { // return integerValue; // } // // public void setIntegerValue(int integerValue) { // this.integerValue = integerValue; // } // // public String getStringValue() { // return stringValue; // } // // public void setStringValue(String stringValue) { // this.stringValue = stringValue; // } // // public NestedDummy getNestedDummy() { // return nestedDummy; // } // // public void setNestedDummy(NestedDummy nestedDummy) { // this.nestedDummy = nestedDummy; // } // // @Override // public String toString() { // return "Dummy{" + // "integerValue=" + integerValue + // ", stringValue='" + stringValue + '\'' + // ", nested=" + nestedDummy + // '}'; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Dummy)) return false; // // Dummy dummy = (Dummy) o; // // if (integerValue != null ? !integerValue.equals(dummy.integerValue) : dummy.integerValue != null) return false; // if (stringValue != null ? !stringValue.equals(dummy.stringValue) : dummy.stringValue != null) return false; // return !(nestedDummy != null ? !nestedDummy.equals(dummy.nestedDummy) : dummy.nestedDummy != null); // // } // // @Override // public int hashCode() { // int result = integerValue != null ? integerValue.hashCode() : 0; // result = 31 * result + (stringValue != null ? stringValue.hashCode() : 0); // result = 31 * result + (nestedDummy != null ? nestedDummy.hashCode() : 0); // return result; // } // } // // Path: src/test/java/com/lsoftware/playdoh/objects/models/User.java // public class User { // // private String name; // private String email; // private int age; // // public User() { // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getEmail() { // return email; // } // // public void setEmail(String email) { // this.email = email; // } // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // @Override // public String toString() { // return "User{" + // "name='" + name + '\'' + // ", email='" + email + '\'' + // ", age=" + age + // '}'; // } // } // Path: src/test/java/com/lsoftware/playdoh/PlaydohExample.java import com.lsoftware.playdoh.objects.models.Dummy; import com.lsoftware.playdoh.objects.models.User; package com.lsoftware.playdoh; class PlaydohExample { public static void main(String[] args) { /* Creating Dummy instance with random data */ final Dummy dummy = Playdoh.build(Dummy.class); System.out.println(dummy); /* Look the user.yml file to see the data specification */
final User user = Playdoh.build(User.class, "aUser");
vbier/habpanelviewer
app/src/main/java/de/vier_bier/habpanelviewer/openhab/RestClient.java
// Path: app/src/main/java/de/vier_bier/habpanelviewer/connection/OkHttpClientFactory.java // public class OkHttpClientFactory { // private static OkHttpClientFactory ourInstance; // // public Credentials mCred = null; // private String mHost; // private String mRealm; // // public static synchronized OkHttpClientFactory getInstance() { // if (ourInstance == null) { // ourInstance = new OkHttpClientFactory(); // } // return ourInstance; // } // // public OkHttpClient create() { // OkHttpClient.Builder builder = new OkHttpClient.Builder().readTimeout(0, TimeUnit.SECONDS); // // builder.sslSocketFactory(CertificateManager.getInstance().getSocketFactory(), // CertificateManager.getInstance().getTrustManager()) // .hostnameVerifier((s, session) -> { // try { // Certificate[] certificates = session.getPeerCertificates(); // for (Certificate certificate : certificates) { // if (!(certificate instanceof X509Certificate)) { // return false; // } // if (CertificateManager.getInstance().isTrusted((X509Certificate) certificate)) { // return true; // } // } // } catch (SSLException e) { // // return false; // } // return false; // }); // // if (mCred != null) { // // create a copy so it can not be nulled again // Credentials copy = new Credentials(mCred.getUserName(), mCred.getPassword()); // // final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>(); // final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(copy); // final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(copy); // // // note that all auth schemes should be registered as lowercase! // DispatchingAuthenticator authenticator = new DispatchingAuthenticator.Builder() // .with("digest", digestAuthenticator) // .with("basic", basicAuthenticator) // .build(); // // builder.authenticator(new CachingAuthenticatorDecorator(authenticator, authCache)) // .addInterceptor(new AuthenticationCacheInterceptor(authCache)); // } // // return builder.build(); // } // // public void setAuth(String user, String pass) { // mCred = new Credentials(user, pass); // } // // public void removeAuth() { // mCred = null; // } // // public void setHost(String host) { // mHost = host; // } // // public void setRealm(String realm) { // mRealm = realm; // } // // public String getHost() { // return mHost; // } // // public String getRealm() { // return mRealm; // } // }
import android.os.Handler; import android.os.HandlerThread; import android.util.Log; import java.io.IOException; import de.vier_bier.habpanelviewer.connection.OkHttpClientFactory; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody;
super("RestClient"); start(); } void getItemState(String serverURL, ISubscriptionListener l, String itemName) { mWorkerHandler.obtainMessage(GET_ID, new ItemSubscription(serverURL, l, itemName)).sendToTarget(); } void setItemState(String serverURL, ItemState itemState) { mWorkerHandler.obtainMessage(SET_ID, new ItemModification(serverURL, itemState)).sendToTarget(); } @Override protected void onLooperPrepared() { super.onLooperPrepared(); mWorkerHandler = new Handler(getLooper(), msg -> { switch (msg.what) { case GET_ID: getRequest((ItemSubscription) msg.obj); break; case SET_ID: putRequest((ItemModification) msg.obj); break; } return true; }); } private void putRequest(ItemModification item) { try {
// Path: app/src/main/java/de/vier_bier/habpanelviewer/connection/OkHttpClientFactory.java // public class OkHttpClientFactory { // private static OkHttpClientFactory ourInstance; // // public Credentials mCred = null; // private String mHost; // private String mRealm; // // public static synchronized OkHttpClientFactory getInstance() { // if (ourInstance == null) { // ourInstance = new OkHttpClientFactory(); // } // return ourInstance; // } // // public OkHttpClient create() { // OkHttpClient.Builder builder = new OkHttpClient.Builder().readTimeout(0, TimeUnit.SECONDS); // // builder.sslSocketFactory(CertificateManager.getInstance().getSocketFactory(), // CertificateManager.getInstance().getTrustManager()) // .hostnameVerifier((s, session) -> { // try { // Certificate[] certificates = session.getPeerCertificates(); // for (Certificate certificate : certificates) { // if (!(certificate instanceof X509Certificate)) { // return false; // } // if (CertificateManager.getInstance().isTrusted((X509Certificate) certificate)) { // return true; // } // } // } catch (SSLException e) { // // return false; // } // return false; // }); // // if (mCred != null) { // // create a copy so it can not be nulled again // Credentials copy = new Credentials(mCred.getUserName(), mCred.getPassword()); // // final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>(); // final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(copy); // final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(copy); // // // note that all auth schemes should be registered as lowercase! // DispatchingAuthenticator authenticator = new DispatchingAuthenticator.Builder() // .with("digest", digestAuthenticator) // .with("basic", basicAuthenticator) // .build(); // // builder.authenticator(new CachingAuthenticatorDecorator(authenticator, authCache)) // .addInterceptor(new AuthenticationCacheInterceptor(authCache)); // } // // return builder.build(); // } // // public void setAuth(String user, String pass) { // mCred = new Credentials(user, pass); // } // // public void removeAuth() { // mCred = null; // } // // public void setHost(String host) { // mHost = host; // } // // public void setRealm(String realm) { // mRealm = realm; // } // // public String getHost() { // return mHost; // } // // public String getRealm() { // return mRealm; // } // } // Path: app/src/main/java/de/vier_bier/habpanelviewer/openhab/RestClient.java import android.os.Handler; import android.os.HandlerThread; import android.util.Log; import java.io.IOException; import de.vier_bier.habpanelviewer.connection.OkHttpClientFactory; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody; super("RestClient"); start(); } void getItemState(String serverURL, ISubscriptionListener l, String itemName) { mWorkerHandler.obtainMessage(GET_ID, new ItemSubscription(serverURL, l, itemName)).sendToTarget(); } void setItemState(String serverURL, ItemState itemState) { mWorkerHandler.obtainMessage(SET_ID, new ItemModification(serverURL, itemState)).sendToTarget(); } @Override protected void onLooperPrepared() { super.onLooperPrepared(); mWorkerHandler = new Handler(getLooper(), msg -> { switch (msg.what) { case GET_ID: getRequest((ItemSubscription) msg.obj); break; case SET_ID: putRequest((ItemModification) msg.obj); break; } return true; }); } private void putRequest(ItemModification item) { try {
OkHttpClient client = OkHttpClientFactory.getInstance().create();
vbier/habpanelviewer
app/src/main/java/de/vier_bier/habpanelviewer/AppRestartingExceptionHandler.java
// Path: app/src/main/java/de/vier_bier/habpanelviewer/status/ApplicationStatus.java // public class ApplicationStatus { // private final ArrayList<StatusItem> mValues = new ArrayList<>(); // private final HashMap<String, StatusItem> mIndices = new HashMap<>(); // // public synchronized void set(String key, String value) { // StatusItem item = mIndices.get(key); // if (item == null) { // item = new StatusItem(key, value); // mValues.add(item); // mIndices.put(key, item); // } else { // item.setValue(value); // } // } // // int getItemCount() { // return mValues.size(); // } // // StatusItem getItem(int i) { // return mValues.get(i); // } // }
import android.content.Intent; import android.content.SharedPreferences; import android.util.Log; import com.jakewharton.processphoenix.ProcessPhoenix; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.jetbrains.annotations.NotNull; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import de.vier_bier.habpanelviewer.status.ApplicationStatus;
package de.vier_bier.habpanelviewer; /** * UncaughtExceptionHandler that restarts the app in case of exceptions. */ class AppRestartingExceptionHandler implements Thread.UncaughtExceptionHandler { private static final String TAG = "HPV-AppRestartingExHa"; private final MainActivity mCtx; private final int mCount; private int mMaxRestarts; private boolean mRestartEnabled; private final Thread.UncaughtExceptionHandler mDefaultHandler; AppRestartingExceptionHandler(MainActivity context, Thread.UncaughtExceptionHandler defaultHandler, int restartCount) { mCtx = context; mDefaultHandler = defaultHandler; mCount = restartCount; EventBus.getDefault().register(this); Thread.setDefaultUncaughtExceptionHandler(this); } @Subscribe(threadMode = ThreadMode.MAIN)
// Path: app/src/main/java/de/vier_bier/habpanelviewer/status/ApplicationStatus.java // public class ApplicationStatus { // private final ArrayList<StatusItem> mValues = new ArrayList<>(); // private final HashMap<String, StatusItem> mIndices = new HashMap<>(); // // public synchronized void set(String key, String value) { // StatusItem item = mIndices.get(key); // if (item == null) { // item = new StatusItem(key, value); // mValues.add(item); // mIndices.put(key, item); // } else { // item.setValue(value); // } // } // // int getItemCount() { // return mValues.size(); // } // // StatusItem getItem(int i) { // return mValues.get(i); // } // } // Path: app/src/main/java/de/vier_bier/habpanelviewer/AppRestartingExceptionHandler.java import android.content.Intent; import android.content.SharedPreferences; import android.util.Log; import com.jakewharton.processphoenix.ProcessPhoenix; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.jetbrains.annotations.NotNull; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import de.vier_bier.habpanelviewer.status.ApplicationStatus; package de.vier_bier.habpanelviewer; /** * UncaughtExceptionHandler that restarts the app in case of exceptions. */ class AppRestartingExceptionHandler implements Thread.UncaughtExceptionHandler { private static final String TAG = "HPV-AppRestartingExHa"; private final MainActivity mCtx; private final int mCount; private int mMaxRestarts; private boolean mRestartEnabled; private final Thread.UncaughtExceptionHandler mDefaultHandler; AppRestartingExceptionHandler(MainActivity context, Thread.UncaughtExceptionHandler defaultHandler, int restartCount) { mCtx = context; mDefaultHandler = defaultHandler; mCount = restartCount; EventBus.getDefault().register(this); Thread.setDefaultUncaughtExceptionHandler(this); } @Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(ApplicationStatus status) {
vbier/habpanelviewer
app/src/main/java/de/vier_bier/habpanelviewer/command/AdminHandler.java
// Path: app/src/main/java/de/vier_bier/habpanelviewer/AdminReceiver.java // public class AdminReceiver extends DeviceAdminReceiver { // public static final ComponentName COMP = // new ComponentName("de.vier_bier.habpanelviewer", "de.vier_bier.habpanelviewer.AdminReceiver"); // // public AdminReceiver() { // } // }
import android.app.Activity; import android.app.admin.DevicePolicyManager; import android.content.Context; import de.vier_bier.habpanelviewer.AdminReceiver;
package de.vier_bier.habpanelviewer.command; /** * Handler for ADMIN_LOCK_SCREEN command. */ public class AdminHandler implements ICommandHandler { private final DevicePolicyManager mDPM; public AdminHandler(Activity activity) { mDPM = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE); } @Override public boolean handleCommand(Command cmd) { final String cmdStr = cmd.getCommand(); if ("ADMIN_LOCK_SCREEN".equals(cmdStr)) {
// Path: app/src/main/java/de/vier_bier/habpanelviewer/AdminReceiver.java // public class AdminReceiver extends DeviceAdminReceiver { // public static final ComponentName COMP = // new ComponentName("de.vier_bier.habpanelviewer", "de.vier_bier.habpanelviewer.AdminReceiver"); // // public AdminReceiver() { // } // } // Path: app/src/main/java/de/vier_bier/habpanelviewer/command/AdminHandler.java import android.app.Activity; import android.app.admin.DevicePolicyManager; import android.content.Context; import de.vier_bier.habpanelviewer.AdminReceiver; package de.vier_bier.habpanelviewer.command; /** * Handler for ADMIN_LOCK_SCREEN command. */ public class AdminHandler implements ICommandHandler { private final DevicePolicyManager mDPM; public AdminHandler(Activity activity) { mDPM = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE); } @Override public boolean handleCommand(Command cmd) { final String cmdStr = cmd.getCommand(); if ("ADMIN_LOCK_SCREEN".equals(cmdStr)) {
if (mDPM.isAdminActive(AdminReceiver.COMP)) {
vbier/habpanelviewer
app/src/main/java/de/vier_bier/habpanelviewer/openhab/average/AveragePropagator.java
// Path: app/src/main/java/de/vier_bier/habpanelviewer/openhab/FutureState.java // public class FutureState extends ItemState implements Delayed { // private final int delayInMillis; // private long origin = System.currentTimeMillis(); // // public FutureState(String item, int interval, String state) { // super(item, state); // // delayInMillis = interval * 1000; // // resetTime(); // } // // public void resetTime() { // origin = System.currentTimeMillis(); // } // // @Override // public long getDelay(@NonNull TimeUnit timeUnit) { // return timeUnit.convert(delayInMillis - (System.currentTimeMillis() - origin), TimeUnit.MILLISECONDS); // } // // @Override // public int compareTo(@NonNull Delayed delayed) { // if (delayed == this) { // return 0; // } // // return Long.compare(getDelay(TimeUnit.MILLISECONDS), delayed.getDelay(TimeUnit.MILLISECONDS)); // } // // @Override // public boolean equals(Object obj) { // return obj instanceof FutureState && mItemName.equals(((FutureState) obj).mItemName); // } // }
import java.util.HashMap; import java.util.concurrent.BlockingQueue; import java.util.concurrent.DelayQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import de.vier_bier.habpanelviewer.openhab.FutureState;
package de.vier_bier.habpanelviewer.openhab.average; /** * Thread that does cyclic propagation of state averages or timed state updates */ public class AveragePropagator extends Thread { private final IStatePropagator mStatePropagator; private final AtomicBoolean mRunning = new AtomicBoolean(true); private final BlockingQueue<Average> mAvgQueue = new DelayQueue<>(); private final HashMap<String, Average> mAverages = new HashMap<>();
// Path: app/src/main/java/de/vier_bier/habpanelviewer/openhab/FutureState.java // public class FutureState extends ItemState implements Delayed { // private final int delayInMillis; // private long origin = System.currentTimeMillis(); // // public FutureState(String item, int interval, String state) { // super(item, state); // // delayInMillis = interval * 1000; // // resetTime(); // } // // public void resetTime() { // origin = System.currentTimeMillis(); // } // // @Override // public long getDelay(@NonNull TimeUnit timeUnit) { // return timeUnit.convert(delayInMillis - (System.currentTimeMillis() - origin), TimeUnit.MILLISECONDS); // } // // @Override // public int compareTo(@NonNull Delayed delayed) { // if (delayed == this) { // return 0; // } // // return Long.compare(getDelay(TimeUnit.MILLISECONDS), delayed.getDelay(TimeUnit.MILLISECONDS)); // } // // @Override // public boolean equals(Object obj) { // return obj instanceof FutureState && mItemName.equals(((FutureState) obj).mItemName); // } // } // Path: app/src/main/java/de/vier_bier/habpanelviewer/openhab/average/AveragePropagator.java import java.util.HashMap; import java.util.concurrent.BlockingQueue; import java.util.concurrent.DelayQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import de.vier_bier.habpanelviewer.openhab.FutureState; package de.vier_bier.habpanelviewer.openhab.average; /** * Thread that does cyclic propagation of state averages or timed state updates */ public class AveragePropagator extends Thread { private final IStatePropagator mStatePropagator; private final AtomicBoolean mRunning = new AtomicBoolean(true); private final BlockingQueue<Average> mAvgQueue = new DelayQueue<>(); private final HashMap<String, Average> mAverages = new HashMap<>();
private final BlockingQueue<FutureState> mFutureStateQueue = new DelayQueue<>();
vbier/habpanelviewer
app/src/main/java/de/vier_bier/habpanelviewer/connection/ConnectionStatistics.java
// Path: app/src/main/java/de/vier_bier/habpanelviewer/status/ApplicationStatus.java // public class ApplicationStatus { // private final ArrayList<StatusItem> mValues = new ArrayList<>(); // private final HashMap<String, StatusItem> mIndices = new HashMap<>(); // // public synchronized void set(String key, String value) { // StatusItem item = mIndices.get(key); // if (item == null) { // item = new StatusItem(key, value); // mValues.add(item); // mIndices.put(key, item); // } else { // item.setValue(value); // } // } // // int getItemCount() { // return mValues.size(); // } // // StatusItem getItem(int i) { // return mValues.get(i); // } // }
import android.content.Context; import android.content.res.Resources; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import de.vier_bier.habpanelviewer.R; import de.vier_bier.habpanelviewer.status.ApplicationStatus;
package de.vier_bier.habpanelviewer.connection; /** * Holds information about online/offline times. */ public class ConnectionStatistics { private final Context mCtx; private final long mStartTime = System.currentTimeMillis(); private State mState = State.DISCONNECTED; private long mLastOnlineTime = -1; private long mLastOfflineTime = mStartTime; private long mOfflinePeriods = 0; private long mOfflineMillis = 0; private long mOfflineMaxMillis = 0; private long mOfflineAverage = 0; private long mOnlinePeriods = 0; private long mOnlineMillis = 0; private long mOnlineMaxMillis = 0; private long mOnlineAverage = 0; public ConnectionStatistics(Context context) { mCtx = context; EventBus.getDefault().register(this); } @Subscribe(threadMode = ThreadMode.MAIN)
// Path: app/src/main/java/de/vier_bier/habpanelviewer/status/ApplicationStatus.java // public class ApplicationStatus { // private final ArrayList<StatusItem> mValues = new ArrayList<>(); // private final HashMap<String, StatusItem> mIndices = new HashMap<>(); // // public synchronized void set(String key, String value) { // StatusItem item = mIndices.get(key); // if (item == null) { // item = new StatusItem(key, value); // mValues.add(item); // mIndices.put(key, item); // } else { // item.setValue(value); // } // } // // int getItemCount() { // return mValues.size(); // } // // StatusItem getItem(int i) { // return mValues.get(i); // } // } // Path: app/src/main/java/de/vier_bier/habpanelviewer/connection/ConnectionStatistics.java import android.content.Context; import android.content.res.Resources; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import de.vier_bier.habpanelviewer.R; import de.vier_bier.habpanelviewer.status.ApplicationStatus; package de.vier_bier.habpanelviewer.connection; /** * Holds information about online/offline times. */ public class ConnectionStatistics { private final Context mCtx; private final long mStartTime = System.currentTimeMillis(); private State mState = State.DISCONNECTED; private long mLastOnlineTime = -1; private long mLastOfflineTime = mStartTime; private long mOfflinePeriods = 0; private long mOfflineMillis = 0; private long mOfflineMaxMillis = 0; private long mOfflineAverage = 0; private long mOnlinePeriods = 0; private long mOnlineMillis = 0; private long mOnlineMaxMillis = 0; private long mOnlineAverage = 0; public ConnectionStatistics(Context context) { mCtx = context; EventBus.getDefault().register(this); } @Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(ApplicationStatus status) {
vbier/habpanelviewer
app/src/main/java/de/vier_bier/habpanelviewer/preferences/ItemValidator.java
// Path: app/src/main/java/de/vier_bier/habpanelviewer/connection/OkHttpClientFactory.java // public class OkHttpClientFactory { // private static OkHttpClientFactory ourInstance; // // public Credentials mCred = null; // private String mHost; // private String mRealm; // // public static synchronized OkHttpClientFactory getInstance() { // if (ourInstance == null) { // ourInstance = new OkHttpClientFactory(); // } // return ourInstance; // } // // public OkHttpClient create() { // OkHttpClient.Builder builder = new OkHttpClient.Builder().readTimeout(0, TimeUnit.SECONDS); // // builder.sslSocketFactory(CertificateManager.getInstance().getSocketFactory(), // CertificateManager.getInstance().getTrustManager()) // .hostnameVerifier((s, session) -> { // try { // Certificate[] certificates = session.getPeerCertificates(); // for (Certificate certificate : certificates) { // if (!(certificate instanceof X509Certificate)) { // return false; // } // if (CertificateManager.getInstance().isTrusted((X509Certificate) certificate)) { // return true; // } // } // } catch (SSLException e) { // // return false; // } // return false; // }); // // if (mCred != null) { // // create a copy so it can not be nulled again // Credentials copy = new Credentials(mCred.getUserName(), mCred.getPassword()); // // final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>(); // final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(copy); // final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(copy); // // // note that all auth schemes should be registered as lowercase! // DispatchingAuthenticator authenticator = new DispatchingAuthenticator.Builder() // .with("digest", digestAuthenticator) // .with("basic", basicAuthenticator) // .build(); // // builder.authenticator(new CachingAuthenticatorDecorator(authenticator, authCache)) // .addInterceptor(new AuthenticationCacheInterceptor(authCache)); // } // // return builder.build(); // } // // public void setAuth(String user, String pass) { // mCred = new Credentials(user, pass); // } // // public void removeAuth() { // mCred = null; // } // // public void setHost(String host) { // mHost = host; // } // // public void setRealm(String realm) { // mRealm = realm; // } // // public String getHost() { // return mHost; // } // // public String getRealm() { // return mRealm; // } // }
import android.util.Log; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import java.util.ArrayList; import java.util.List; import de.vier_bier.habpanelviewer.connection.OkHttpClientFactory; import okhttp3.Call; import okhttp3.Callback; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody;
package de.vier_bier.habpanelviewer.preferences; class ItemValidator { private static final String TAG = "HPV-ItemValidator"; private final List<String> mNames = new ArrayList<>(); void setServerUrl(String serverUrl, ValidationStateListener l) {
// Path: app/src/main/java/de/vier_bier/habpanelviewer/connection/OkHttpClientFactory.java // public class OkHttpClientFactory { // private static OkHttpClientFactory ourInstance; // // public Credentials mCred = null; // private String mHost; // private String mRealm; // // public static synchronized OkHttpClientFactory getInstance() { // if (ourInstance == null) { // ourInstance = new OkHttpClientFactory(); // } // return ourInstance; // } // // public OkHttpClient create() { // OkHttpClient.Builder builder = new OkHttpClient.Builder().readTimeout(0, TimeUnit.SECONDS); // // builder.sslSocketFactory(CertificateManager.getInstance().getSocketFactory(), // CertificateManager.getInstance().getTrustManager()) // .hostnameVerifier((s, session) -> { // try { // Certificate[] certificates = session.getPeerCertificates(); // for (Certificate certificate : certificates) { // if (!(certificate instanceof X509Certificate)) { // return false; // } // if (CertificateManager.getInstance().isTrusted((X509Certificate) certificate)) { // return true; // } // } // } catch (SSLException e) { // // return false; // } // return false; // }); // // if (mCred != null) { // // create a copy so it can not be nulled again // Credentials copy = new Credentials(mCred.getUserName(), mCred.getPassword()); // // final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>(); // final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(copy); // final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(copy); // // // note that all auth schemes should be registered as lowercase! // DispatchingAuthenticator authenticator = new DispatchingAuthenticator.Builder() // .with("digest", digestAuthenticator) // .with("basic", basicAuthenticator) // .build(); // // builder.authenticator(new CachingAuthenticatorDecorator(authenticator, authCache)) // .addInterceptor(new AuthenticationCacheInterceptor(authCache)); // } // // return builder.build(); // } // // public void setAuth(String user, String pass) { // mCred = new Credentials(user, pass); // } // // public void removeAuth() { // mCred = null; // } // // public void setHost(String host) { // mHost = host; // } // // public void setRealm(String realm) { // mRealm = realm; // } // // public String getHost() { // return mHost; // } // // public String getRealm() { // return mRealm; // } // } // Path: app/src/main/java/de/vier_bier/habpanelviewer/preferences/ItemValidator.java import android.util.Log; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import java.util.ArrayList; import java.util.List; import de.vier_bier.habpanelviewer.connection.OkHttpClientFactory; import okhttp3.Call; import okhttp3.Callback; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; package de.vier_bier.habpanelviewer.preferences; class ItemValidator { private static final String TAG = "HPV-ItemValidator"; private final List<String> mNames = new ArrayList<>(); void setServerUrl(String serverUrl, ValidationStateListener l) {
OkHttpClient client = OkHttpClientFactory.getInstance().create();
vihuela/Lay-s
lay-s/src/main/java/com/hadlink/lay_s/datamanager/net/MyNet.java
// Path: lay-s/src/main/java/com/hadlink/lay_s/conf/C.java // public final class C { // // /** // * 主机 // */ // public static final class Host { // public static final String host = "http://eptapi.imchehu.com/"; // public static final String BAIDU_IMAGES_URLS = "http://image.baidu.com/data/imgs"; // } // // /** // * 列表常量 // */ // public static final class List { // //每页加载数 // public static final int numPerPage = 10; // } // // }
import com.hadlink.easynet.util.NetUtils; import com.hadlink.lay_s.conf.C;
/* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.datamanager.net; /** * Created by zhouml on 2015/12/1. */ public class MyNet { public static ApiOverview get() {
// Path: lay-s/src/main/java/com/hadlink/lay_s/conf/C.java // public final class C { // // /** // * 主机 // */ // public static final class Host { // public static final String host = "http://eptapi.imchehu.com/"; // public static final String BAIDU_IMAGES_URLS = "http://image.baidu.com/data/imgs"; // } // // /** // * 列表常量 // */ // public static final class List { // //每页加载数 // public static final int numPerPage = 10; // } // // } // Path: lay-s/src/main/java/com/hadlink/lay_s/datamanager/net/MyNet.java import com.hadlink.easynet.util.NetUtils; import com.hadlink.lay_s.conf.C; /* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.datamanager.net; /** * Created by zhouml on 2015/12/1. */ public class MyNet { public static ApiOverview get() {
return NetUtils.createApi(ApiOverview.class, C.Host.host);
vihuela/Lay-s
library/src/main/java/com/hadlink/library/widget/pla/PLALoadMoreListView.java
// Path: library/src/main/java/com/hadlink/library/widget/progress/CircularProgressBar.java // public class CircularProgressBar extends ProgressBar { // // public CircularProgressBar(Context context) { // this(context, null); // } // // public CircularProgressBar(Context context, AttributeSet attrs) { // this(context, attrs, R.attr.cpbStyle); // } // // public CircularProgressBar(Context context, AttributeSet attrs, int defStyle) { // super(context, attrs, defStyle); // // if (isInEditMode()) { // setIndeterminateDrawable(new CircularProgressDrawable.Builder(context, true).build()); // return; // } // // Resources res = context.getResources(); // TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircularProgressBar, defStyle, 0); // // // final int color = a.getColor(R.styleable.CircularProgressBar_cpb_color, res.getColor(R.color.cpb_default_color)); // final float strokeWidth = a.getDimension(R.styleable.CircularProgressBar_cpb_stroke_width, res.getDimension(R.dimen.cpb_default_stroke_width)); // final float sweepSpeed = a.getFloat(R.styleable.CircularProgressBar_cpb_sweep_speed, Float.parseFloat(res.getString(R.string.cpb_default_sweep_speed))); // final float rotationSpeed = a.getFloat(R.styleable.CircularProgressBar_cpb_rotation_speed, Float.parseFloat(res.getString(R.string.cpb_default_rotation_speed))); // final int colorsId = a.getResourceId(R.styleable.CircularProgressBar_cpb_colors, 0); // final int minSweepAngle = a.getInteger(R.styleable.CircularProgressBar_cpb_min_sweep_angle, res.getInteger(R.integer.cpb_default_min_sweep_angle)); // final int maxSweepAngle = a.getInteger(R.styleable.CircularProgressBar_cpb_max_sweep_angle, res.getInteger(R.integer.cpb_default_max_sweep_angle)); // a.recycle(); // // int[] colors = null; // //colors // if (colorsId != 0) { // colors = res.getIntArray(colorsId); // } // // Drawable indeterminateDrawable; // CircularProgressDrawable.Builder builder = new CircularProgressDrawable.Builder(context) // .sweepSpeed(sweepSpeed) // .rotationSpeed(rotationSpeed) // .strokeWidth(strokeWidth) // .minSweepAngle(minSweepAngle) // .maxSweepAngle(maxSweepAngle); // // if (colors != null && colors.length > 0) // builder.colors(colors); // else // builder.color(color); // // indeterminateDrawable = builder.build(); // setIndeterminateDrawable(indeterminateDrawable); // } // // private CircularProgressDrawable checkIndeterminateDrawable() { // Drawable ret = getIndeterminateDrawable(); // if (ret == null || !(ret instanceof CircularProgressDrawable)) // throw new RuntimeException("The drawable is not a CircularProgressDrawable"); // return (CircularProgressDrawable) ret; // } // // public void progressiveStop() { // checkIndeterminateDrawable().progressiveStop(); // } // // public void progressiveStop(CircularProgressDrawable.OnEndListener listener) { // checkIndeterminateDrawable().progressiveStop(listener); // } // }
import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.RelativeLayout; import android.widget.TextView; import com.hadlink.library.R; import com.hadlink.library.widget.progress.CircularProgressBar;
/* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.library.widget.pla; public class PLALoadMoreListView extends PLAMultiColumnListView implements PLAAbsListView.OnScrollListener { private OnScrollListener mOnScrollListener; private LayoutInflater mInflater; // footer view private RelativeLayout mFooterView; private TextView mLabLoadMore;
// Path: library/src/main/java/com/hadlink/library/widget/progress/CircularProgressBar.java // public class CircularProgressBar extends ProgressBar { // // public CircularProgressBar(Context context) { // this(context, null); // } // // public CircularProgressBar(Context context, AttributeSet attrs) { // this(context, attrs, R.attr.cpbStyle); // } // // public CircularProgressBar(Context context, AttributeSet attrs, int defStyle) { // super(context, attrs, defStyle); // // if (isInEditMode()) { // setIndeterminateDrawable(new CircularProgressDrawable.Builder(context, true).build()); // return; // } // // Resources res = context.getResources(); // TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircularProgressBar, defStyle, 0); // // // final int color = a.getColor(R.styleable.CircularProgressBar_cpb_color, res.getColor(R.color.cpb_default_color)); // final float strokeWidth = a.getDimension(R.styleable.CircularProgressBar_cpb_stroke_width, res.getDimension(R.dimen.cpb_default_stroke_width)); // final float sweepSpeed = a.getFloat(R.styleable.CircularProgressBar_cpb_sweep_speed, Float.parseFloat(res.getString(R.string.cpb_default_sweep_speed))); // final float rotationSpeed = a.getFloat(R.styleable.CircularProgressBar_cpb_rotation_speed, Float.parseFloat(res.getString(R.string.cpb_default_rotation_speed))); // final int colorsId = a.getResourceId(R.styleable.CircularProgressBar_cpb_colors, 0); // final int minSweepAngle = a.getInteger(R.styleable.CircularProgressBar_cpb_min_sweep_angle, res.getInteger(R.integer.cpb_default_min_sweep_angle)); // final int maxSweepAngle = a.getInteger(R.styleable.CircularProgressBar_cpb_max_sweep_angle, res.getInteger(R.integer.cpb_default_max_sweep_angle)); // a.recycle(); // // int[] colors = null; // //colors // if (colorsId != 0) { // colors = res.getIntArray(colorsId); // } // // Drawable indeterminateDrawable; // CircularProgressDrawable.Builder builder = new CircularProgressDrawable.Builder(context) // .sweepSpeed(sweepSpeed) // .rotationSpeed(rotationSpeed) // .strokeWidth(strokeWidth) // .minSweepAngle(minSweepAngle) // .maxSweepAngle(maxSweepAngle); // // if (colors != null && colors.length > 0) // builder.colors(colors); // else // builder.color(color); // // indeterminateDrawable = builder.build(); // setIndeterminateDrawable(indeterminateDrawable); // } // // private CircularProgressDrawable checkIndeterminateDrawable() { // Drawable ret = getIndeterminateDrawable(); // if (ret == null || !(ret instanceof CircularProgressDrawable)) // throw new RuntimeException("The drawable is not a CircularProgressDrawable"); // return (CircularProgressDrawable) ret; // } // // public void progressiveStop() { // checkIndeterminateDrawable().progressiveStop(); // } // // public void progressiveStop(CircularProgressDrawable.OnEndListener listener) { // checkIndeterminateDrawable().progressiveStop(listener); // } // } // Path: library/src/main/java/com/hadlink/library/widget/pla/PLALoadMoreListView.java import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.RelativeLayout; import android.widget.TextView; import com.hadlink.library.R; import com.hadlink.library.widget.progress.CircularProgressBar; /* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.library.widget.pla; public class PLALoadMoreListView extends PLAMultiColumnListView implements PLAAbsListView.OnScrollListener { private OnScrollListener mOnScrollListener; private LayoutInflater mInflater; // footer view private RelativeLayout mFooterView; private TextView mLabLoadMore;
private CircularProgressBar mProgressBarLoadMore;
vihuela/Lay-s
lay-s/src/main/java/com/hadlink/lay_s/utils/UriHelper.java
// Path: lay-s/src/main/java/com/hadlink/lay_s/conf/C.java // public final class C { // // /** // * 主机 // */ // public static final class Host { // public static final String host = "http://eptapi.imchehu.com/"; // public static final String BAIDU_IMAGES_URLS = "http://image.baidu.com/data/imgs"; // } // // /** // * 列表常量 // */ // public static final class List { // //每页加载数 // public static final int numPerPage = 10; // } // // }
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import com.hadlink.lay_s.conf.C;
/* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.utils; public class UriHelper { private static volatile UriHelper instance = null; /** * 20 datas per page */ public static final int PAGE_LIMIT = 200; private UriHelper() { } public static UriHelper getInstance() { if (null == instance) { synchronized (UriHelper.class) { if (null == instance) { instance = new UriHelper(); } } } return instance; } public int calculateTotalPages(int totalNumber) { if (totalNumber > 0) { return totalNumber % PAGE_LIMIT != 0 ? (totalNumber / PAGE_LIMIT + 1) : totalNumber / PAGE_LIMIT; } else { return 0; } } public String getImagesListUrl(String category, int pageNum) { StringBuffer sb = new StringBuffer();
// Path: lay-s/src/main/java/com/hadlink/lay_s/conf/C.java // public final class C { // // /** // * 主机 // */ // public static final class Host { // public static final String host = "http://eptapi.imchehu.com/"; // public static final String BAIDU_IMAGES_URLS = "http://image.baidu.com/data/imgs"; // } // // /** // * 列表常量 // */ // public static final class List { // //每页加载数 // public static final int numPerPage = 10; // } // // } // Path: lay-s/src/main/java/com/hadlink/lay_s/utils/UriHelper.java import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import com.hadlink.lay_s.conf.C; /* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.utils; public class UriHelper { private static volatile UriHelper instance = null; /** * 20 datas per page */ public static final int PAGE_LIMIT = 200; private UriHelper() { } public static UriHelper getInstance() { if (null == instance) { synchronized (UriHelper.class) { if (null == instance) { instance = new UriHelper(); } } } return instance; } public int calculateTotalPages(int totalNumber) { if (totalNumber > 0) { return totalNumber % PAGE_LIMIT != 0 ? (totalNumber / PAGE_LIMIT + 1) : totalNumber / PAGE_LIMIT; } else { return 0; } } public String getImagesListUrl(String category, int pageNum) { StringBuffer sb = new StringBuffer();
sb.append(C.Host.BAIDU_IMAGES_URLS);
vihuela/Lay-s
lay-s/src/main/java/com/hadlink/lay_s/datamanager/net/netcallback/MyNetCallBack.java
// Path: lay-s/src/main/java/com/hadlink/lay_s/model/EventImpl.java // public class EventImpl extends Event { // // // } // // Path: library/src/main/java/com/hadlink/library/model/Event.java // public class Event { // // public final static int NET_REQUEST_ERROR = 0x10; // // public int arg; // private Object object; // // public <T extends Object> T getObject() { // return (T) object; // } // // public void setObject(Object obj) { // this.object = obj; // } // } // // Path: library/src/main/java/com/hadlink/library/util/rx/RxBus.java // public class RxBus { // // private RxBus() { // } // // private static volatile RxBus mInstance; // // public static RxBus getDefault() { // if (mInstance == null) { // synchronized (RxBus.class) { // if (mInstance == null) { // mInstance = new RxBus(); // } // } // } // return mInstance; // } // // private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create()); // // public void post(Object event) { // bus.onNext(event); // } // // public <T> Observable<T> take(final Class<T> eventType) { // return bus.filter(new Func1<Object, Boolean>() { // @Override // public Boolean call(Object o) { // return eventType.isInstance(o); // } // }).cast(eventType); // } // //usage // /*private void setTabTitle(int position) { // Event event = new Event(); // event.setAction(Event.SEND_TAB_TITLE_ACTION); // CharSequence pageTitle = viewpager.getAdapter().getPageTitle(position); // event.setObject(pageTitle); // RxBus.getDefault().post(event); // }*/ // /*rxBusSubscript = RxBus.getDefault().take(Event.class) // .subscribe(new Action1<Event>() { // @Override // public void call(Event event) { // changeContent(event); // } // }, new Action1<Throwable>() { // @Override // public void call(Throwable throwable) { // } // });*/ // }
import com.hadlink.easynet.conf.ErrorInfo; import com.hadlink.easynet.util.NetUtils; import com.hadlink.lay_s.model.EventImpl; import com.hadlink.library.model.Event; import com.hadlink.library.util.rx.RxBus;
/* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.datamanager.net.netcallback; public abstract class MyNetCallBack<T> extends NetUtils.callBack<T> { public MyNetCallBack(String eventTag) { super(eventTag); } public MyNetCallBack() { super(null); } /** * 除了Invalid 返回的是原对象之外,其余都是String */ @Override public void onDispatchError(Error error, ErrorInfo e) { switch (error) { case Internal: break; case Invalid: /** * 当数据无效时候你做的处理 */ T result = (T) e.getObject(); break; case NetWork: break; case Server: break; case UnKnow: break; } //post event
// Path: lay-s/src/main/java/com/hadlink/lay_s/model/EventImpl.java // public class EventImpl extends Event { // // // } // // Path: library/src/main/java/com/hadlink/library/model/Event.java // public class Event { // // public final static int NET_REQUEST_ERROR = 0x10; // // public int arg; // private Object object; // // public <T extends Object> T getObject() { // return (T) object; // } // // public void setObject(Object obj) { // this.object = obj; // } // } // // Path: library/src/main/java/com/hadlink/library/util/rx/RxBus.java // public class RxBus { // // private RxBus() { // } // // private static volatile RxBus mInstance; // // public static RxBus getDefault() { // if (mInstance == null) { // synchronized (RxBus.class) { // if (mInstance == null) { // mInstance = new RxBus(); // } // } // } // return mInstance; // } // // private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create()); // // public void post(Object event) { // bus.onNext(event); // } // // public <T> Observable<T> take(final Class<T> eventType) { // return bus.filter(new Func1<Object, Boolean>() { // @Override // public Boolean call(Object o) { // return eventType.isInstance(o); // } // }).cast(eventType); // } // //usage // /*private void setTabTitle(int position) { // Event event = new Event(); // event.setAction(Event.SEND_TAB_TITLE_ACTION); // CharSequence pageTitle = viewpager.getAdapter().getPageTitle(position); // event.setObject(pageTitle); // RxBus.getDefault().post(event); // }*/ // /*rxBusSubscript = RxBus.getDefault().take(Event.class) // .subscribe(new Action1<Event>() { // @Override // public void call(Event event) { // changeContent(event); // } // }, new Action1<Throwable>() { // @Override // public void call(Throwable throwable) { // } // });*/ // } // Path: lay-s/src/main/java/com/hadlink/lay_s/datamanager/net/netcallback/MyNetCallBack.java import com.hadlink.easynet.conf.ErrorInfo; import com.hadlink.easynet.util.NetUtils; import com.hadlink.lay_s.model.EventImpl; import com.hadlink.library.model.Event; import com.hadlink.library.util.rx.RxBus; /* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.datamanager.net.netcallback; public abstract class MyNetCallBack<T> extends NetUtils.callBack<T> { public MyNetCallBack(String eventTag) { super(eventTag); } public MyNetCallBack() { super(null); } /** * 除了Invalid 返回的是原对象之外,其余都是String */ @Override public void onDispatchError(Error error, ErrorInfo e) { switch (error) { case Internal: break; case Invalid: /** * 当数据无效时候你做的处理 */ T result = (T) e.getObject(); break; case NetWork: break; case Server: break; case UnKnow: break; } //post event
Event event = new EventImpl();
vihuela/Lay-s
lay-s/src/main/java/com/hadlink/lay_s/datamanager/net/netcallback/MyNetCallBack.java
// Path: lay-s/src/main/java/com/hadlink/lay_s/model/EventImpl.java // public class EventImpl extends Event { // // // } // // Path: library/src/main/java/com/hadlink/library/model/Event.java // public class Event { // // public final static int NET_REQUEST_ERROR = 0x10; // // public int arg; // private Object object; // // public <T extends Object> T getObject() { // return (T) object; // } // // public void setObject(Object obj) { // this.object = obj; // } // } // // Path: library/src/main/java/com/hadlink/library/util/rx/RxBus.java // public class RxBus { // // private RxBus() { // } // // private static volatile RxBus mInstance; // // public static RxBus getDefault() { // if (mInstance == null) { // synchronized (RxBus.class) { // if (mInstance == null) { // mInstance = new RxBus(); // } // } // } // return mInstance; // } // // private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create()); // // public void post(Object event) { // bus.onNext(event); // } // // public <T> Observable<T> take(final Class<T> eventType) { // return bus.filter(new Func1<Object, Boolean>() { // @Override // public Boolean call(Object o) { // return eventType.isInstance(o); // } // }).cast(eventType); // } // //usage // /*private void setTabTitle(int position) { // Event event = new Event(); // event.setAction(Event.SEND_TAB_TITLE_ACTION); // CharSequence pageTitle = viewpager.getAdapter().getPageTitle(position); // event.setObject(pageTitle); // RxBus.getDefault().post(event); // }*/ // /*rxBusSubscript = RxBus.getDefault().take(Event.class) // .subscribe(new Action1<Event>() { // @Override // public void call(Event event) { // changeContent(event); // } // }, new Action1<Throwable>() { // @Override // public void call(Throwable throwable) { // } // });*/ // }
import com.hadlink.easynet.conf.ErrorInfo; import com.hadlink.easynet.util.NetUtils; import com.hadlink.lay_s.model.EventImpl; import com.hadlink.library.model.Event; import com.hadlink.library.util.rx.RxBus;
/* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.datamanager.net.netcallback; public abstract class MyNetCallBack<T> extends NetUtils.callBack<T> { public MyNetCallBack(String eventTag) { super(eventTag); } public MyNetCallBack() { super(null); } /** * 除了Invalid 返回的是原对象之外,其余都是String */ @Override public void onDispatchError(Error error, ErrorInfo e) { switch (error) { case Internal: break; case Invalid: /** * 当数据无效时候你做的处理 */ T result = (T) e.getObject(); break; case NetWork: break; case Server: break; case UnKnow: break; } //post event
// Path: lay-s/src/main/java/com/hadlink/lay_s/model/EventImpl.java // public class EventImpl extends Event { // // // } // // Path: library/src/main/java/com/hadlink/library/model/Event.java // public class Event { // // public final static int NET_REQUEST_ERROR = 0x10; // // public int arg; // private Object object; // // public <T extends Object> T getObject() { // return (T) object; // } // // public void setObject(Object obj) { // this.object = obj; // } // } // // Path: library/src/main/java/com/hadlink/library/util/rx/RxBus.java // public class RxBus { // // private RxBus() { // } // // private static volatile RxBus mInstance; // // public static RxBus getDefault() { // if (mInstance == null) { // synchronized (RxBus.class) { // if (mInstance == null) { // mInstance = new RxBus(); // } // } // } // return mInstance; // } // // private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create()); // // public void post(Object event) { // bus.onNext(event); // } // // public <T> Observable<T> take(final Class<T> eventType) { // return bus.filter(new Func1<Object, Boolean>() { // @Override // public Boolean call(Object o) { // return eventType.isInstance(o); // } // }).cast(eventType); // } // //usage // /*private void setTabTitle(int position) { // Event event = new Event(); // event.setAction(Event.SEND_TAB_TITLE_ACTION); // CharSequence pageTitle = viewpager.getAdapter().getPageTitle(position); // event.setObject(pageTitle); // RxBus.getDefault().post(event); // }*/ // /*rxBusSubscript = RxBus.getDefault().take(Event.class) // .subscribe(new Action1<Event>() { // @Override // public void call(Event event) { // changeContent(event); // } // }, new Action1<Throwable>() { // @Override // public void call(Throwable throwable) { // } // });*/ // } // Path: lay-s/src/main/java/com/hadlink/lay_s/datamanager/net/netcallback/MyNetCallBack.java import com.hadlink.easynet.conf.ErrorInfo; import com.hadlink.easynet.util.NetUtils; import com.hadlink.lay_s.model.EventImpl; import com.hadlink.library.model.Event; import com.hadlink.library.util.rx.RxBus; /* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.datamanager.net.netcallback; public abstract class MyNetCallBack<T> extends NetUtils.callBack<T> { public MyNetCallBack(String eventTag) { super(eventTag); } public MyNetCallBack() { super(null); } /** * 除了Invalid 返回的是原对象之外,其余都是String */ @Override public void onDispatchError(Error error, ErrorInfo e) { switch (error) { case Internal: break; case Invalid: /** * 当数据无效时候你做的处理 */ T result = (T) e.getObject(); break; case NetWork: break; case Server: break; case UnKnow: break; } //post event
Event event = new EventImpl();
vihuela/Lay-s
lay-s/src/main/java/com/hadlink/lay_s/datamanager/net/netcallback/MyNetCallBack.java
// Path: lay-s/src/main/java/com/hadlink/lay_s/model/EventImpl.java // public class EventImpl extends Event { // // // } // // Path: library/src/main/java/com/hadlink/library/model/Event.java // public class Event { // // public final static int NET_REQUEST_ERROR = 0x10; // // public int arg; // private Object object; // // public <T extends Object> T getObject() { // return (T) object; // } // // public void setObject(Object obj) { // this.object = obj; // } // } // // Path: library/src/main/java/com/hadlink/library/util/rx/RxBus.java // public class RxBus { // // private RxBus() { // } // // private static volatile RxBus mInstance; // // public static RxBus getDefault() { // if (mInstance == null) { // synchronized (RxBus.class) { // if (mInstance == null) { // mInstance = new RxBus(); // } // } // } // return mInstance; // } // // private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create()); // // public void post(Object event) { // bus.onNext(event); // } // // public <T> Observable<T> take(final Class<T> eventType) { // return bus.filter(new Func1<Object, Boolean>() { // @Override // public Boolean call(Object o) { // return eventType.isInstance(o); // } // }).cast(eventType); // } // //usage // /*private void setTabTitle(int position) { // Event event = new Event(); // event.setAction(Event.SEND_TAB_TITLE_ACTION); // CharSequence pageTitle = viewpager.getAdapter().getPageTitle(position); // event.setObject(pageTitle); // RxBus.getDefault().post(event); // }*/ // /*rxBusSubscript = RxBus.getDefault().take(Event.class) // .subscribe(new Action1<Event>() { // @Override // public void call(Event event) { // changeContent(event); // } // }, new Action1<Throwable>() { // @Override // public void call(Throwable throwable) { // } // });*/ // }
import com.hadlink.easynet.conf.ErrorInfo; import com.hadlink.easynet.util.NetUtils; import com.hadlink.lay_s.model.EventImpl; import com.hadlink.library.model.Event; import com.hadlink.library.util.rx.RxBus;
/* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.datamanager.net.netcallback; public abstract class MyNetCallBack<T> extends NetUtils.callBack<T> { public MyNetCallBack(String eventTag) { super(eventTag); } public MyNetCallBack() { super(null); } /** * 除了Invalid 返回的是原对象之外,其余都是String */ @Override public void onDispatchError(Error error, ErrorInfo e) { switch (error) { case Internal: break; case Invalid: /** * 当数据无效时候你做的处理 */ T result = (T) e.getObject(); break; case NetWork: break; case Server: break; case UnKnow: break; } //post event Event event = new EventImpl(); event.arg = EventImpl.NET_REQUEST_ERROR; event.setObject(e);
// Path: lay-s/src/main/java/com/hadlink/lay_s/model/EventImpl.java // public class EventImpl extends Event { // // // } // // Path: library/src/main/java/com/hadlink/library/model/Event.java // public class Event { // // public final static int NET_REQUEST_ERROR = 0x10; // // public int arg; // private Object object; // // public <T extends Object> T getObject() { // return (T) object; // } // // public void setObject(Object obj) { // this.object = obj; // } // } // // Path: library/src/main/java/com/hadlink/library/util/rx/RxBus.java // public class RxBus { // // private RxBus() { // } // // private static volatile RxBus mInstance; // // public static RxBus getDefault() { // if (mInstance == null) { // synchronized (RxBus.class) { // if (mInstance == null) { // mInstance = new RxBus(); // } // } // } // return mInstance; // } // // private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create()); // // public void post(Object event) { // bus.onNext(event); // } // // public <T> Observable<T> take(final Class<T> eventType) { // return bus.filter(new Func1<Object, Boolean>() { // @Override // public Boolean call(Object o) { // return eventType.isInstance(o); // } // }).cast(eventType); // } // //usage // /*private void setTabTitle(int position) { // Event event = new Event(); // event.setAction(Event.SEND_TAB_TITLE_ACTION); // CharSequence pageTitle = viewpager.getAdapter().getPageTitle(position); // event.setObject(pageTitle); // RxBus.getDefault().post(event); // }*/ // /*rxBusSubscript = RxBus.getDefault().take(Event.class) // .subscribe(new Action1<Event>() { // @Override // public void call(Event event) { // changeContent(event); // } // }, new Action1<Throwable>() { // @Override // public void call(Throwable throwable) { // } // });*/ // } // Path: lay-s/src/main/java/com/hadlink/lay_s/datamanager/net/netcallback/MyNetCallBack.java import com.hadlink.easynet.conf.ErrorInfo; import com.hadlink.easynet.util.NetUtils; import com.hadlink.lay_s.model.EventImpl; import com.hadlink.library.model.Event; import com.hadlink.library.util.rx.RxBus; /* * Copyright (c) 2016, lyao. lomoliger@hotmail.com * * Part of the code from the open source community, * thanks stackOverflow & gitHub . * 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.hadlink.lay_s.datamanager.net.netcallback; public abstract class MyNetCallBack<T> extends NetUtils.callBack<T> { public MyNetCallBack(String eventTag) { super(eventTag); } public MyNetCallBack() { super(null); } /** * 除了Invalid 返回的是原对象之外,其余都是String */ @Override public void onDispatchError(Error error, ErrorInfo e) { switch (error) { case Internal: break; case Invalid: /** * 当数据无效时候你做的处理 */ T result = (T) e.getObject(); break; case NetWork: break; case Server: break; case UnKnow: break; } //post event Event event = new EventImpl(); event.arg = EventImpl.NET_REQUEST_ERROR; event.setObject(e);
RxBus.getDefault().post(event);
iconmaster5326/Source
src/com/iconmaster/source/element/Element.java
// Path: src/com/iconmaster/source/util/IDirectable.java // public interface IDirectable { // public ArrayList<String> getDirectives(); // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.util.IDirectable; import com.iconmaster.source.util.Range; import java.util.ArrayList;
package com.iconmaster.source.element; /** * * @author iconmaster */ public class Element implements IDirectable { public IElementType type; public Object[] args = new Object[10]; public Element dataType = null; public ArrayList<String> directives = new ArrayList<>();
// Path: src/com/iconmaster/source/util/IDirectable.java // public interface IDirectable { // public ArrayList<String> getDirectives(); // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/element/Element.java import com.iconmaster.source.util.IDirectable; import com.iconmaster.source.util.Range; import java.util.ArrayList; package com.iconmaster.source.element; /** * * @author iconmaster */ public class Element implements IDirectable { public IElementType type; public Object[] args = new Object[10]; public Element dataType = null; public ArrayList<String> directives = new ArrayList<>();
public Range range;
iconmaster5326/Source
src/com/iconmaster/source/prototype/Import.java
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.util.Range;
package com.iconmaster.source.prototype; /** * * @author iconmaster */ public class Import { public String name; public String alias; public boolean isFile; public boolean resolved = false; public boolean compiled = false;
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/prototype/Import.java import com.iconmaster.source.util.Range; package com.iconmaster.source.prototype; /** * * @author iconmaster */ public class Import { public String name; public String alias; public boolean isFile; public boolean resolved = false; public boolean compiled = false;
public Range range;
iconmaster5326/Source
src/com/iconmaster/source/exception/SourceUninitializedVariableException.java
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.util.Range;
package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceUninitializedVariableException extends SourceException { public String var;
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/exception/SourceUninitializedVariableException.java import com.iconmaster.source.util.Range; package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceUninitializedVariableException extends SourceException { public String var;
public SourceUninitializedVariableException(Range range, String message, String var) {
iconmaster5326/Source
src/com/iconmaster/source/tokenize/TokenRule.java
// Path: src/com/iconmaster/source/element/IElementType.java // public interface IElementType { // public String getAlias(); // } // // Path: src/com/iconmaster/source/util/StringUtils.java // public class StringUtils { // public static String nameString(Element e) { // if (e==null) { // return null; // } else if (e.type==TokenRule.WORD || e.type==TokenRule.STRING) { // return (String) e.args[0]; // } else if (e.type == Rule.CHAIN) { // String str = null; // for (Element e2 : (ArrayList<Element>)e.args[0]) { // if (e2.type==TokenRule.WORD) { // if (str==null) { // str = (String) e2.args[0]; // } else { // str += "." + (String) e2.args[0]; // } // } // } // return str; // } // return null; // } // // public static boolean isReal(String n) { // return n.contains("."); // } // // public static String unescape(String s) { // String out = ""; // boolean esc = false; // for (char c : s.toCharArray()) { // if (esc) { // if (c=='n') { // out += '\n'; // } else if (c=='t') { // out += '\t'; // } else { // out += c; // } // esc = false; // } else { // if (c=='\\') { // esc = true; // } else { // out += c; // } // } // } // return out; // } // // public static String mathElementToString(Element e) { // if (e.type instanceof Rule) { // switch ((Rule)e.type) { // case ADD: // return "_add"; // case SUB: // return "_sub"; // case MUL: // return "_mul"; // case DIV: // return "_div"; // case POW: // return "_pow"; // case MOD: // return "_mod"; // case CONCAT: // return "_concat"; // case EQ: // return "_eq"; // case NEQ: // return "_neq"; // case LT: // return "_lt"; // case GT: // return "_gt"; // case LTE: // return "_lte"; // case GTE: // return "_gte"; // case AND: // return "_and"; // case OR: // return "_or"; // case BIT_AND: // return "_band"; // case BIT_OR: // return "_bor"; // case SLL: // return "_sll"; // case SRL: // return "_srl"; // case SRA: // return "_sra"; // } // } // return null; // } // }
import com.iconmaster.source.element.IElementType; import com.iconmaster.source.util.StringUtils;
NUMBER("n","[\\d\\.]+"), STRING("s","\"(\\\\.|[^\"])*\""), CHAR(null,"\'(\\\\.|[^\'])\'"), SEP(";",";+"), DIRECTIVE("r","@[\\S]*"), SYMBOL("y","([\\Q+-*/=<>~:!&|%^\\E]+|\\(|\\)|\\[|\\]|\\{|\\}|,)"); public final String match; public String alias; TokenRule(String alias, String match) { this.match = "^"+match; this.alias = alias; } TokenRule(String match) { this(null,match); } TokenRule() { this(null,"[^.]"); } public String format(String input) { switch (this) { case SPACE: case COMMENT: return null; case CHAR: case STRING:
// Path: src/com/iconmaster/source/element/IElementType.java // public interface IElementType { // public String getAlias(); // } // // Path: src/com/iconmaster/source/util/StringUtils.java // public class StringUtils { // public static String nameString(Element e) { // if (e==null) { // return null; // } else if (e.type==TokenRule.WORD || e.type==TokenRule.STRING) { // return (String) e.args[0]; // } else if (e.type == Rule.CHAIN) { // String str = null; // for (Element e2 : (ArrayList<Element>)e.args[0]) { // if (e2.type==TokenRule.WORD) { // if (str==null) { // str = (String) e2.args[0]; // } else { // str += "." + (String) e2.args[0]; // } // } // } // return str; // } // return null; // } // // public static boolean isReal(String n) { // return n.contains("."); // } // // public static String unescape(String s) { // String out = ""; // boolean esc = false; // for (char c : s.toCharArray()) { // if (esc) { // if (c=='n') { // out += '\n'; // } else if (c=='t') { // out += '\t'; // } else { // out += c; // } // esc = false; // } else { // if (c=='\\') { // esc = true; // } else { // out += c; // } // } // } // return out; // } // // public static String mathElementToString(Element e) { // if (e.type instanceof Rule) { // switch ((Rule)e.type) { // case ADD: // return "_add"; // case SUB: // return "_sub"; // case MUL: // return "_mul"; // case DIV: // return "_div"; // case POW: // return "_pow"; // case MOD: // return "_mod"; // case CONCAT: // return "_concat"; // case EQ: // return "_eq"; // case NEQ: // return "_neq"; // case LT: // return "_lt"; // case GT: // return "_gt"; // case LTE: // return "_lte"; // case GTE: // return "_gte"; // case AND: // return "_and"; // case OR: // return "_or"; // case BIT_AND: // return "_band"; // case BIT_OR: // return "_bor"; // case SLL: // return "_sll"; // case SRL: // return "_srl"; // case SRA: // return "_sra"; // } // } // return null; // } // } // Path: src/com/iconmaster/source/tokenize/TokenRule.java import com.iconmaster.source.element.IElementType; import com.iconmaster.source.util.StringUtils; NUMBER("n","[\\d\\.]+"), STRING("s","\"(\\\\.|[^\"])*\""), CHAR(null,"\'(\\\\.|[^\'])\'"), SEP(";",";+"), DIRECTIVE("r","@[\\S]*"), SYMBOL("y","([\\Q+-*/=<>~:!&|%^\\E]+|\\(|\\)|\\[|\\]|\\{|\\}|,)"); public final String match; public String alias; TokenRule(String alias, String match) { this.match = "^"+match; this.alias = alias; } TokenRule(String match) { this(null,match); } TokenRule() { this(null,"[^.]"); } public String format(String input) { switch (this) { case SPACE: case COMMENT: return null; case CHAR: case STRING:
return StringUtils.unescape(input.substring(1, input.length()-1));
iconmaster5326/Source
src/com/iconmaster/source/element/Rule.java
// Path: src/com/iconmaster/source/element/ISpecialRule.java // public class RuleResult { // public Element ret; // public int del; // // public RuleResult(Element ret, int del) { // this.ret = ret; // this.del = del; // } // } // // Path: src/com/iconmaster/source/parse/Parser.java // public class Parser { // private static final HashMap<String,IElementType> aliases = new HashMap<>(); // // public static void addAlias(IElementType type) { // aliases.put(type.getAlias(),type); // } // // static { // for (IElementType rule : Rule.values()) { // addAlias(rule); // } // for (IElementType rule : TokenRule.values()) { // addAlias(rule); // } // } // // public static ArrayList<Element> parse(ArrayList<Element> a) throws SourceException { // //System.out.println("Initial tree: "+a); // for (Rule rule : Rule.values()) { // for (int i=0;i<a.size();i++) { // ISpecialRule.RuleResult m = rule.rule.match(a, i); // if (m!=null) { // for (int j=0;j<m.del;j++) { // a.remove(i); // } // if (m.ret!=null) { // a.add(i, m.ret); // i-=1; // } // //System.out.print("matched rule "+rule.toString()+": "); // //System.out.println(a); // } // } // } // //Make sure there is no invalid tokens left lying around // check(a); // return a; // } // // public static IElementType getAlias(String toMatch) { // return aliases.get(toMatch); // } // // public static void check(ArrayList<Element> a) throws SourceException { // for (Element v : a) { // if (v.type instanceof TokenRule) { // // } // } // } // } // // Path: src/com/iconmaster/source/tokenize/Token.java // public class Token extends Element { // public Token(Range range, IElementType type, Object value) { // super(range,type); // this.args[0] = value; // } // // @Override // public String toString() { // return "["+type+" "+args[0]+"]"; // } // // public String string() { // return (String) args[0]; // } // // public ArrayList<Element> array() { // return (ArrayList<Element>) args[0]; // } // // public boolean isString() { // return args[0] instanceof String; // } // // public boolean isArray() { // return args[0] instanceof ArrayList; // } // } // // Path: src/com/iconmaster/source/tokenize/TokenRule.java // public enum TokenRule implements IElementType { // COMMENT(null,"\\/\\/[^\n]*\n?"), // SPACE(" ","[\\s]+"), // RESWORD(null,"(local|function|and|or|not|for|in|as|return|break|struct|if|else|elseif|while|repeat|until|field|import|package|enum|true|false|iterator|new|extends|to|continue|type|class)\\b"), // WORD("w","[\\w\\?&&[^\\d]][\\w\\?\\.]*"), // NUMBER("n","[\\d\\.]+"), // STRING("s","\"(\\\\.|[^\"])*\""), // CHAR(null,"\'(\\\\.|[^\'])\'"), // SEP(";",";+"), // DIRECTIVE("r","@[\\S]*"), // SYMBOL("y","([\\Q+-*/=<>~:!&|%^\\E]+|\\(|\\)|\\[|\\]|\\{|\\}|,)"); // // public final String match; // public String alias; // // TokenRule(String alias, String match) { // this.match = "^"+match; // this.alias = alias; // } // // TokenRule(String match) { // this(null,match); // } // // TokenRule() { // this(null,"[^.]"); // } // // public String format(String input) { // switch (this) { // case SPACE: // case COMMENT: // return null; // case CHAR: // case STRING: // return StringUtils.unescape(input.substring(1, input.length()-1)); // case DIRECTIVE: // return input.substring(1); // default: // return input; // } // } // // @Override // public String getAlias() { // return alias; // } // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.element.ISpecialRule.RuleResult; import com.iconmaster.source.parse.Parser; import com.iconmaster.source.tokenize.Token; import com.iconmaster.source.tokenize.TokenRule; import com.iconmaster.source.util.Range; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;
package com.iconmaster.source.element; /** * * @author iconmaster */ public enum Rule implements IElementType { BLOCK_COMMENT(null,(a,i)->{
// Path: src/com/iconmaster/source/element/ISpecialRule.java // public class RuleResult { // public Element ret; // public int del; // // public RuleResult(Element ret, int del) { // this.ret = ret; // this.del = del; // } // } // // Path: src/com/iconmaster/source/parse/Parser.java // public class Parser { // private static final HashMap<String,IElementType> aliases = new HashMap<>(); // // public static void addAlias(IElementType type) { // aliases.put(type.getAlias(),type); // } // // static { // for (IElementType rule : Rule.values()) { // addAlias(rule); // } // for (IElementType rule : TokenRule.values()) { // addAlias(rule); // } // } // // public static ArrayList<Element> parse(ArrayList<Element> a) throws SourceException { // //System.out.println("Initial tree: "+a); // for (Rule rule : Rule.values()) { // for (int i=0;i<a.size();i++) { // ISpecialRule.RuleResult m = rule.rule.match(a, i); // if (m!=null) { // for (int j=0;j<m.del;j++) { // a.remove(i); // } // if (m.ret!=null) { // a.add(i, m.ret); // i-=1; // } // //System.out.print("matched rule "+rule.toString()+": "); // //System.out.println(a); // } // } // } // //Make sure there is no invalid tokens left lying around // check(a); // return a; // } // // public static IElementType getAlias(String toMatch) { // return aliases.get(toMatch); // } // // public static void check(ArrayList<Element> a) throws SourceException { // for (Element v : a) { // if (v.type instanceof TokenRule) { // // } // } // } // } // // Path: src/com/iconmaster/source/tokenize/Token.java // public class Token extends Element { // public Token(Range range, IElementType type, Object value) { // super(range,type); // this.args[0] = value; // } // // @Override // public String toString() { // return "["+type+" "+args[0]+"]"; // } // // public String string() { // return (String) args[0]; // } // // public ArrayList<Element> array() { // return (ArrayList<Element>) args[0]; // } // // public boolean isString() { // return args[0] instanceof String; // } // // public boolean isArray() { // return args[0] instanceof ArrayList; // } // } // // Path: src/com/iconmaster/source/tokenize/TokenRule.java // public enum TokenRule implements IElementType { // COMMENT(null,"\\/\\/[^\n]*\n?"), // SPACE(" ","[\\s]+"), // RESWORD(null,"(local|function|and|or|not|for|in|as|return|break|struct|if|else|elseif|while|repeat|until|field|import|package|enum|true|false|iterator|new|extends|to|continue|type|class)\\b"), // WORD("w","[\\w\\?&&[^\\d]][\\w\\?\\.]*"), // NUMBER("n","[\\d\\.]+"), // STRING("s","\"(\\\\.|[^\"])*\""), // CHAR(null,"\'(\\\\.|[^\'])\'"), // SEP(";",";+"), // DIRECTIVE("r","@[\\S]*"), // SYMBOL("y","([\\Q+-*/=<>~:!&|%^\\E]+|\\(|\\)|\\[|\\]|\\{|\\}|,)"); // // public final String match; // public String alias; // // TokenRule(String alias, String match) { // this.match = "^"+match; // this.alias = alias; // } // // TokenRule(String match) { // this(null,match); // } // // TokenRule() { // this(null,"[^.]"); // } // // public String format(String input) { // switch (this) { // case SPACE: // case COMMENT: // return null; // case CHAR: // case STRING: // return StringUtils.unescape(input.substring(1, input.length()-1)); // case DIRECTIVE: // return input.substring(1); // default: // return input; // } // } // // @Override // public String getAlias() { // return alias; // } // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/element/Rule.java import com.iconmaster.source.element.ISpecialRule.RuleResult; import com.iconmaster.source.parse.Parser; import com.iconmaster.source.tokenize.Token; import com.iconmaster.source.tokenize.TokenRule; import com.iconmaster.source.util.Range; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; package com.iconmaster.source.element; /** * * @author iconmaster */ public enum Rule implements IElementType { BLOCK_COMMENT(null,(a,i)->{
if (a.get(i).type==TokenRule.SYMBOL && "/*".equals(a.get(i).args[0])) {
iconmaster5326/Source
src/com/iconmaster/source/link/LinkGraph.java
// Path: src/com/iconmaster/source/prototype/Import.java // public class Import { // public String name; // public String alias; // public boolean isFile; // public boolean resolved = false; // public boolean compiled = false; // public Range range; // public SourcePackage pkg = null; // // public Import(String name, String alias, boolean isFile, Range range) { // this.name = name; // this.alias = alias; // this.isFile = isFile; // this.range = range; // } // // @Override // public String toString() { // return (isFile?"(f) ":"")+name+(alias==null?"":("="+alias)); // } // }
import com.iconmaster.source.prototype.Import; import java.util.ArrayList; import java.util.HashMap;
package com.iconmaster.source.link; /** * * @author iconmaster */ public class LinkGraph { public static class LinkNode { public ArrayList<LinkNode> connectedTo = new ArrayList<>(); public String name;
// Path: src/com/iconmaster/source/prototype/Import.java // public class Import { // public String name; // public String alias; // public boolean isFile; // public boolean resolved = false; // public boolean compiled = false; // public Range range; // public SourcePackage pkg = null; // // public Import(String name, String alias, boolean isFile, Range range) { // this.name = name; // this.alias = alias; // this.isFile = isFile; // this.range = range; // } // // @Override // public String toString() { // return (isFile?"(f) ":"")+name+(alias==null?"":("="+alias)); // } // } // Path: src/com/iconmaster/source/link/LinkGraph.java import com.iconmaster.source.prototype.Import; import java.util.ArrayList; import java.util.HashMap; package com.iconmaster.source.link; /** * * @author iconmaster */ public class LinkGraph { public static class LinkNode { public ArrayList<LinkNode> connectedTo = new ArrayList<>(); public String name;
public Import data;
iconmaster5326/Source
src/com/iconmaster/source/element/ISpecialRule.java
// Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // }
import com.iconmaster.source.exception.SourceException; import java.util.ArrayList;
package com.iconmaster.source.element; /** * * @author iconmaster */ public interface ISpecialRule { public class RuleResult { public Element ret; public int del; public RuleResult(Element ret, int del) { this.ret = ret; this.del = del; } }
// Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // } // Path: src/com/iconmaster/source/element/ISpecialRule.java import com.iconmaster.source.exception.SourceException; import java.util.ArrayList; package com.iconmaster.source.element; /** * * @author iconmaster */ public interface ISpecialRule { public class RuleResult { public Element ret; public int del; public RuleResult(Element ret, int del) { this.ret = ret; this.del = del; } }
public RuleResult match(ArrayList<Element> a, int i) throws SourceException;
iconmaster5326/Source
src/com/iconmaster/source/compile/Operation.java
// Path: src/com/iconmaster/source/prototype/TypeDef.java // public class TypeDef { // public static final TypeDef UNKNOWN = new TypeDef(); // public static final TypeDef STRING = new TypeDef("string"); // public static final TypeDef ARRAY = new TypeDef("array"); // public static final TypeDef LIST = new TypeDef("list"); // public static final TypeDef BOOLEAN = new TypeDef("bool"); // public static final TypeDef MAP = new TypeDef("map"); // public static final TypeDef PTR = new TypeDef("ptr"); // public static final TypeDef FPTR = new TypeDef("fptr"); // // public static final TypeDef INT8 = new TypeDef("int8"); // public static final TypeDef INT16 = new TypeDef("int16"); // public static final TypeDef INT32 = new TypeDef("int32"); // public static final TypeDef INT64 = new TypeDef("int64"); // // public static final TypeDef REAL32 = new TypeDef("real32"); // public static final TypeDef REAL64 = new TypeDef("real64"); // // public static final TypeDef REAL = new TypeDef("real", TypeDef.REAL32); // public static final TypeDef INT = new TypeDef("int", TypeDef.INT32); // public static final TypeDef CHAR = new TypeDef("char", TypeDef.INT8); // // public String name; // public String pkgName; // // public TypeDef parent = null; // // public TypeDef() { // this.name = "?"; // } // // public TypeDef(String name) { // this(name,TypeDef.UNKNOWN); // } // // public TypeDef(String name, TypeDef parent) { // this.name = name; // this.parent = parent; // } // // @Override // public String toString() { // return name; // } // // public static TypeDef getCommonParent(TypeDef type1,TypeDef type2) { // if (type1==null || type2==null) { // return TypeDef.UNKNOWN; // } // if (type1==type2) { // return type1; // } // if (type1.parent==type2) { // return type2; // } // if (type1==type2.parent) { // return type1; // } // return getCommonParent(type1.parent,type2.parent); // } // // public static void addBaseTypes(SourcePackage pkg) { // pkg.addType(TypeDef.UNKNOWN); // pkg.addType(TypeDef.INT); // pkg.addType(TypeDef.REAL); // pkg.addType(TypeDef.STRING); // pkg.addType(TypeDef.ARRAY); // pkg.addType(TypeDef.LIST); // pkg.addType(TypeDef.CHAR); // pkg.addType(TypeDef.BOOLEAN); // pkg.addType(TypeDef.MAP); // pkg.addType(TypeDef.INT8); // pkg.addType(TypeDef.INT16); // pkg.addType(TypeDef.INT32); // pkg.addType(TypeDef.INT64); // pkg.addType(TypeDef.REAL32); // pkg.addType(TypeDef.REAL64); // } // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.prototype.TypeDef; import com.iconmaster.source.util.Range; import java.util.ArrayList; import java.util.Arrays; import java.util.Objects;
case ENDB: case DO: case LABEL: case GOTO: case GOTOT: case GOTOF: case NATIVE: case DEF: case ITER: return false; default: return true; } } public boolean isBlockStarter() { switch (this) { case IF: case WHILE: case REP: case FOR: return true; default: return false; } } } public OpType op; public String[] args;
// Path: src/com/iconmaster/source/prototype/TypeDef.java // public class TypeDef { // public static final TypeDef UNKNOWN = new TypeDef(); // public static final TypeDef STRING = new TypeDef("string"); // public static final TypeDef ARRAY = new TypeDef("array"); // public static final TypeDef LIST = new TypeDef("list"); // public static final TypeDef BOOLEAN = new TypeDef("bool"); // public static final TypeDef MAP = new TypeDef("map"); // public static final TypeDef PTR = new TypeDef("ptr"); // public static final TypeDef FPTR = new TypeDef("fptr"); // // public static final TypeDef INT8 = new TypeDef("int8"); // public static final TypeDef INT16 = new TypeDef("int16"); // public static final TypeDef INT32 = new TypeDef("int32"); // public static final TypeDef INT64 = new TypeDef("int64"); // // public static final TypeDef REAL32 = new TypeDef("real32"); // public static final TypeDef REAL64 = new TypeDef("real64"); // // public static final TypeDef REAL = new TypeDef("real", TypeDef.REAL32); // public static final TypeDef INT = new TypeDef("int", TypeDef.INT32); // public static final TypeDef CHAR = new TypeDef("char", TypeDef.INT8); // // public String name; // public String pkgName; // // public TypeDef parent = null; // // public TypeDef() { // this.name = "?"; // } // // public TypeDef(String name) { // this(name,TypeDef.UNKNOWN); // } // // public TypeDef(String name, TypeDef parent) { // this.name = name; // this.parent = parent; // } // // @Override // public String toString() { // return name; // } // // public static TypeDef getCommonParent(TypeDef type1,TypeDef type2) { // if (type1==null || type2==null) { // return TypeDef.UNKNOWN; // } // if (type1==type2) { // return type1; // } // if (type1.parent==type2) { // return type2; // } // if (type1==type2.parent) { // return type1; // } // return getCommonParent(type1.parent,type2.parent); // } // // public static void addBaseTypes(SourcePackage pkg) { // pkg.addType(TypeDef.UNKNOWN); // pkg.addType(TypeDef.INT); // pkg.addType(TypeDef.REAL); // pkg.addType(TypeDef.STRING); // pkg.addType(TypeDef.ARRAY); // pkg.addType(TypeDef.LIST); // pkg.addType(TypeDef.CHAR); // pkg.addType(TypeDef.BOOLEAN); // pkg.addType(TypeDef.MAP); // pkg.addType(TypeDef.INT8); // pkg.addType(TypeDef.INT16); // pkg.addType(TypeDef.INT32); // pkg.addType(TypeDef.INT64); // pkg.addType(TypeDef.REAL32); // pkg.addType(TypeDef.REAL64); // } // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/compile/Operation.java import com.iconmaster.source.prototype.TypeDef; import com.iconmaster.source.util.Range; import java.util.ArrayList; import java.util.Arrays; import java.util.Objects; case ENDB: case DO: case LABEL: case GOTO: case GOTOT: case GOTOF: case NATIVE: case DEF: case ITER: return false; default: return true; } } public boolean isBlockStarter() { switch (this) { case IF: case WHILE: case REP: case FOR: return true; default: return false; } } } public OpType op; public String[] args;
public Range range;
iconmaster5326/Source
src/com/iconmaster/source/compile/Operation.java
// Path: src/com/iconmaster/source/prototype/TypeDef.java // public class TypeDef { // public static final TypeDef UNKNOWN = new TypeDef(); // public static final TypeDef STRING = new TypeDef("string"); // public static final TypeDef ARRAY = new TypeDef("array"); // public static final TypeDef LIST = new TypeDef("list"); // public static final TypeDef BOOLEAN = new TypeDef("bool"); // public static final TypeDef MAP = new TypeDef("map"); // public static final TypeDef PTR = new TypeDef("ptr"); // public static final TypeDef FPTR = new TypeDef("fptr"); // // public static final TypeDef INT8 = new TypeDef("int8"); // public static final TypeDef INT16 = new TypeDef("int16"); // public static final TypeDef INT32 = new TypeDef("int32"); // public static final TypeDef INT64 = new TypeDef("int64"); // // public static final TypeDef REAL32 = new TypeDef("real32"); // public static final TypeDef REAL64 = new TypeDef("real64"); // // public static final TypeDef REAL = new TypeDef("real", TypeDef.REAL32); // public static final TypeDef INT = new TypeDef("int", TypeDef.INT32); // public static final TypeDef CHAR = new TypeDef("char", TypeDef.INT8); // // public String name; // public String pkgName; // // public TypeDef parent = null; // // public TypeDef() { // this.name = "?"; // } // // public TypeDef(String name) { // this(name,TypeDef.UNKNOWN); // } // // public TypeDef(String name, TypeDef parent) { // this.name = name; // this.parent = parent; // } // // @Override // public String toString() { // return name; // } // // public static TypeDef getCommonParent(TypeDef type1,TypeDef type2) { // if (type1==null || type2==null) { // return TypeDef.UNKNOWN; // } // if (type1==type2) { // return type1; // } // if (type1.parent==type2) { // return type2; // } // if (type1==type2.parent) { // return type1; // } // return getCommonParent(type1.parent,type2.parent); // } // // public static void addBaseTypes(SourcePackage pkg) { // pkg.addType(TypeDef.UNKNOWN); // pkg.addType(TypeDef.INT); // pkg.addType(TypeDef.REAL); // pkg.addType(TypeDef.STRING); // pkg.addType(TypeDef.ARRAY); // pkg.addType(TypeDef.LIST); // pkg.addType(TypeDef.CHAR); // pkg.addType(TypeDef.BOOLEAN); // pkg.addType(TypeDef.MAP); // pkg.addType(TypeDef.INT8); // pkg.addType(TypeDef.INT16); // pkg.addType(TypeDef.INT32); // pkg.addType(TypeDef.INT64); // pkg.addType(TypeDef.REAL32); // pkg.addType(TypeDef.REAL64); // } // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.prototype.TypeDef; import com.iconmaster.source.util.Range; import java.util.ArrayList; import java.util.Arrays; import java.util.Objects;
case DO: case LABEL: case GOTO: case GOTOT: case GOTOF: case NATIVE: case DEF: case ITER: return false; default: return true; } } public boolean isBlockStarter() { switch (this) { case IF: case WHILE: case REP: case FOR: return true; default: return false; } } } public OpType op; public String[] args; public Range range;
// Path: src/com/iconmaster/source/prototype/TypeDef.java // public class TypeDef { // public static final TypeDef UNKNOWN = new TypeDef(); // public static final TypeDef STRING = new TypeDef("string"); // public static final TypeDef ARRAY = new TypeDef("array"); // public static final TypeDef LIST = new TypeDef("list"); // public static final TypeDef BOOLEAN = new TypeDef("bool"); // public static final TypeDef MAP = new TypeDef("map"); // public static final TypeDef PTR = new TypeDef("ptr"); // public static final TypeDef FPTR = new TypeDef("fptr"); // // public static final TypeDef INT8 = new TypeDef("int8"); // public static final TypeDef INT16 = new TypeDef("int16"); // public static final TypeDef INT32 = new TypeDef("int32"); // public static final TypeDef INT64 = new TypeDef("int64"); // // public static final TypeDef REAL32 = new TypeDef("real32"); // public static final TypeDef REAL64 = new TypeDef("real64"); // // public static final TypeDef REAL = new TypeDef("real", TypeDef.REAL32); // public static final TypeDef INT = new TypeDef("int", TypeDef.INT32); // public static final TypeDef CHAR = new TypeDef("char", TypeDef.INT8); // // public String name; // public String pkgName; // // public TypeDef parent = null; // // public TypeDef() { // this.name = "?"; // } // // public TypeDef(String name) { // this(name,TypeDef.UNKNOWN); // } // // public TypeDef(String name, TypeDef parent) { // this.name = name; // this.parent = parent; // } // // @Override // public String toString() { // return name; // } // // public static TypeDef getCommonParent(TypeDef type1,TypeDef type2) { // if (type1==null || type2==null) { // return TypeDef.UNKNOWN; // } // if (type1==type2) { // return type1; // } // if (type1.parent==type2) { // return type2; // } // if (type1==type2.parent) { // return type1; // } // return getCommonParent(type1.parent,type2.parent); // } // // public static void addBaseTypes(SourcePackage pkg) { // pkg.addType(TypeDef.UNKNOWN); // pkg.addType(TypeDef.INT); // pkg.addType(TypeDef.REAL); // pkg.addType(TypeDef.STRING); // pkg.addType(TypeDef.ARRAY); // pkg.addType(TypeDef.LIST); // pkg.addType(TypeDef.CHAR); // pkg.addType(TypeDef.BOOLEAN); // pkg.addType(TypeDef.MAP); // pkg.addType(TypeDef.INT8); // pkg.addType(TypeDef.INT16); // pkg.addType(TypeDef.INT32); // pkg.addType(TypeDef.INT64); // pkg.addType(TypeDef.REAL32); // pkg.addType(TypeDef.REAL64); // } // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/compile/Operation.java import com.iconmaster.source.prototype.TypeDef; import com.iconmaster.source.util.Range; import java.util.ArrayList; import java.util.Arrays; import java.util.Objects; case DO: case LABEL: case GOTO: case GOTOT: case GOTOF: case NATIVE: case DEF: case ITER: return false; default: return true; } } public boolean isBlockStarter() { switch (this) { case IF: case WHILE: case REP: case FOR: return true; default: return false; } } } public OpType op; public String[] args; public Range range;
public TypeDef type;
iconmaster5326/Source
src/com/iconmaster/source/exception/SourceUndefinedFunctionException.java
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.util.Range;
package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceUndefinedFunctionException extends SourceException { public String var;
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/exception/SourceUndefinedFunctionException.java import com.iconmaster.source.util.Range; package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceUndefinedFunctionException extends SourceException { public String var;
public SourceUndefinedFunctionException(Range range, String message, String var) {
iconmaster5326/Source
src/com/iconmaster/source/link/platform/hppl/HPPLNaming.java
// Path: src/com/iconmaster/source/prototype/Function.java // public class Function implements IDirectable { // protected String name; // protected ArrayList<Field> args; // public Element rawReturns; // protected ArrayList<String> directives = new ArrayList<>(); // public ArrayList<Element> rawCode; // protected boolean library = false; // // protected boolean compiled = false; // protected ArrayList<Operation> code; // private DataType returns; // // public String pkgName; // // public int order = 0; // public int references = 0; // // public ArrayList<Field> rawParams; // // /** // * A map used to store item information for the platform. // */ // public HashMap data = new HashMap<>(); // // public Function(String name, ArrayList<Field> args, Element returns) { // this.name = name; // this.args = args; // this.rawReturns = returns; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(getFullName()+args+" as "+returns); // if (code!=null) { // sb.append(". CODE:"); // // for (Operation op : code) { // sb.append("\n\t"); // sb.append(op.toString()); // } // } // return sb.toString(); // } // // public static Function libraryFunction(String name, String[] args, Object[] argTypes, Object ret) { // ArrayList<Field> argList = new ArrayList<>(); // ArrayList<DataType> retList = new ArrayList<>(); // // int i = 0; // for (String arg : args) { // Element e = null; // Field f = new Field(arg, null); // if (i<argTypes.length) { // DataType dt = null; // if (argTypes[i] instanceof TypeDef) { // dt = new DataType((TypeDef)argTypes[i],false); // } else if (argTypes[i] instanceof DataType) { // dt = (DataType) argTypes[i]; // } // f.setType(dt); // } // argList.add(f); // i++; // } // // // Function fn = new Function(name, argList, null); // DataType dt = null; // if (ret instanceof TypeDef) { // dt = new DataType((TypeDef)ret,false); // } else if (ret instanceof DataType) { // dt = (DataType) ret; // } // fn.setReturnType(dt); // fn.library = true; // fn.compiled = true; // return fn; // } // // public void setCompiled(ArrayList<Operation> code) { // this.compiled = true; // this.code = code; // } // // public ArrayList<Element> rawData() { // return rawCode; // } // // public boolean isCompiled() { // return compiled; // } // // public String getName() { // return name; // } // // public String getFullName() { // return ((pkgName==null || pkgName.isEmpty())?"":(pkgName+"."))+name+(order==0?"":("%"+order)); // } // // public ArrayList<Operation> getCode() { // return code; // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // // public ArrayList<Field> getArguments() { // return args; // } // // public boolean isLibrary() { // return library; // } // // public Element getReturn() { // return rawReturns; // } // // public DataType getReturnType() { // return returns; // } // // public void setReturnType(DataType returns) { // this.returns = returns; // } // // public static interface OnCompile { // public String compile(SourcePackage pkg, Object... args); // } // // public static interface OnRun { // public Object run(SourcePackage pkg, Object... args); // } // }
import com.iconmaster.source.prototype.Function;
package com.iconmaster.source.link.platform.hppl; /** * * @author iconmaster */ public class HPPLNaming { public static String[] ILLEGAL_IDENTIFIERS = new String[] { //Someday, I need to put ALL HPPL function names here. "i","e" }; public static int varsMade = -1; public static String getNewName() { varsMade++; return HPPLCharacters.VAR_BEGIN+new String(new char[] {(char) (0xF000 + varsMade)}); } public static String formatVarName(String name) { name = name.replace(".", "_").replace("?", "_").replace("%", "_"); if (name.startsWith("_")) { name = HPPLCharacters.VAR_BEGIN+name; } for (String id : ILLEGAL_IDENTIFIERS) { if (id.equals(name)) { name = getNewName(); break; } } return name; }
// Path: src/com/iconmaster/source/prototype/Function.java // public class Function implements IDirectable { // protected String name; // protected ArrayList<Field> args; // public Element rawReturns; // protected ArrayList<String> directives = new ArrayList<>(); // public ArrayList<Element> rawCode; // protected boolean library = false; // // protected boolean compiled = false; // protected ArrayList<Operation> code; // private DataType returns; // // public String pkgName; // // public int order = 0; // public int references = 0; // // public ArrayList<Field> rawParams; // // /** // * A map used to store item information for the platform. // */ // public HashMap data = new HashMap<>(); // // public Function(String name, ArrayList<Field> args, Element returns) { // this.name = name; // this.args = args; // this.rawReturns = returns; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(getFullName()+args+" as "+returns); // if (code!=null) { // sb.append(". CODE:"); // // for (Operation op : code) { // sb.append("\n\t"); // sb.append(op.toString()); // } // } // return sb.toString(); // } // // public static Function libraryFunction(String name, String[] args, Object[] argTypes, Object ret) { // ArrayList<Field> argList = new ArrayList<>(); // ArrayList<DataType> retList = new ArrayList<>(); // // int i = 0; // for (String arg : args) { // Element e = null; // Field f = new Field(arg, null); // if (i<argTypes.length) { // DataType dt = null; // if (argTypes[i] instanceof TypeDef) { // dt = new DataType((TypeDef)argTypes[i],false); // } else if (argTypes[i] instanceof DataType) { // dt = (DataType) argTypes[i]; // } // f.setType(dt); // } // argList.add(f); // i++; // } // // // Function fn = new Function(name, argList, null); // DataType dt = null; // if (ret instanceof TypeDef) { // dt = new DataType((TypeDef)ret,false); // } else if (ret instanceof DataType) { // dt = (DataType) ret; // } // fn.setReturnType(dt); // fn.library = true; // fn.compiled = true; // return fn; // } // // public void setCompiled(ArrayList<Operation> code) { // this.compiled = true; // this.code = code; // } // // public ArrayList<Element> rawData() { // return rawCode; // } // // public boolean isCompiled() { // return compiled; // } // // public String getName() { // return name; // } // // public String getFullName() { // return ((pkgName==null || pkgName.isEmpty())?"":(pkgName+"."))+name+(order==0?"":("%"+order)); // } // // public ArrayList<Operation> getCode() { // return code; // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // // public ArrayList<Field> getArguments() { // return args; // } // // public boolean isLibrary() { // return library; // } // // public Element getReturn() { // return rawReturns; // } // // public DataType getReturnType() { // return returns; // } // // public void setReturnType(DataType returns) { // this.returns = returns; // } // // public static interface OnCompile { // public String compile(SourcePackage pkg, Object... args); // } // // public static interface OnRun { // public Object run(SourcePackage pkg, Object... args); // } // } // Path: src/com/iconmaster/source/link/platform/hppl/HPPLNaming.java import com.iconmaster.source.prototype.Function; package com.iconmaster.source.link.platform.hppl; /** * * @author iconmaster */ public class HPPLNaming { public static String[] ILLEGAL_IDENTIFIERS = new String[] { //Someday, I need to put ALL HPPL function names here. "i","e" }; public static int varsMade = -1; public static String getNewName() { varsMade++; return HPPLCharacters.VAR_BEGIN+new String(new char[] {(char) (0xF000 + varsMade)}); } public static String formatVarName(String name) { name = name.replace(".", "_").replace("?", "_").replace("%", "_"); if (name.startsWith("_")) { name = HPPLCharacters.VAR_BEGIN+name; } for (String id : ILLEGAL_IDENTIFIERS) { if (id.equals(name)) { name = getNewName(); break; } } return name; }
public static String formatFuncName(Function fn) {
iconmaster5326/Source
src/com/iconmaster/source/link/platform/hppl/HPPLField.java
// Path: src/com/iconmaster/source/link/platform/hppl/InlinedExpression.java // public static class InlineOp { // public Operation op; // public Status status = null; // public int refs = 0; // public SpecialOp spec; // public int matchingBlock = -1; // // public InlineOp(Operation op) { // this.op = op; // } // // public InlineOp(Operation op, SpecialOp spec) { // this.op = op; // this.spec = spec; // } // // public void addRef() { // refs++; // } // // public void setStatus() { // if (!op.op.hasLVar()) { // status = Status.NOT_APPLICABLE; // } else if (refs==0) { // status = Status.KEEP_NO_LVAL; // } else if (refs==1 && op.op!=OpType.MOVA && op.op!=OpType.MOVL) { // status = Status.INLINE; // } else { // status = Status.KEEP; // } // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(); // sb.append("<"); // sb.append(refs); // sb.append("-"); // sb.append(status); // if (spec!=null) { // sb.append(" "); // sb.append(spec); // } // if (matchingBlock!=-1) { // sb.append("(loop "); // sb.append(matchingBlock); // sb.append(")"); // } // sb.append("> "); // sb.append(op); // return sb.toString(); // } // } // // Path: src/com/iconmaster/source/prototype/Field.java // public class Field implements IDirectable { // protected String name; // public Element rawType; // public Element rawValue; // protected ArrayList<String> directives = new ArrayList<>();; // // protected boolean compiled; // protected boolean library; // protected Expression value; // private DataType type; // // public String pkgName; // // /** // * A map used to store item information for the platform. // */ // public HashMap data = new HashMap<>(); // // public Field(String name) { // this(name,null); // } // // public Field(String name, Element type) { // this.name = name; // this.rawType = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name+"="+getType()); // if (value!=null) { // sb.append(". CODE:"); // // for (Operation op : value) { // sb.append("\n\t"); // sb.append(op.toString()); // } // } // return sb.toString(); // } // // public String getName() { // return name; // } // // public void setCompiled(Expression code) { // this.compiled = true; // this.value = code; // } // // public Element rawData() { // return rawValue; // } // // public boolean isCompiled() { // return compiled; // } // // public Expression getValue() { // return value; // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // // public boolean isLibrary() { // return library; // } // // public Element getRawType() { // return rawType; // } // // public DataType getType() { // return type; // } // // public void setType(DataType type) { // this.type = type; // } // // public static Field libraryField(String name, TypeDef type) { // Field f = new Field(name); // if (type!=null) { // f.setType(new DataType(type,false)); // } // f.library = true; // return f; // } // // public static interface OnCompile { // public String compile(SourcePackage pkg, boolean isGet, Object... args); // } // // public static interface OnRun { // public Object run(SourcePackage pkg, boolean isGet, Object... args); // } // }
import com.iconmaster.source.link.platform.hppl.InlinedExpression.InlineOp; import com.iconmaster.source.prototype.Field;
package com.iconmaster.source.link.platform.hppl; /** * * @author iconmaster */ public class HPPLField { public String compileName; public InlinedExpression expr;
// Path: src/com/iconmaster/source/link/platform/hppl/InlinedExpression.java // public static class InlineOp { // public Operation op; // public Status status = null; // public int refs = 0; // public SpecialOp spec; // public int matchingBlock = -1; // // public InlineOp(Operation op) { // this.op = op; // } // // public InlineOp(Operation op, SpecialOp spec) { // this.op = op; // this.spec = spec; // } // // public void addRef() { // refs++; // } // // public void setStatus() { // if (!op.op.hasLVar()) { // status = Status.NOT_APPLICABLE; // } else if (refs==0) { // status = Status.KEEP_NO_LVAL; // } else if (refs==1 && op.op!=OpType.MOVA && op.op!=OpType.MOVL) { // status = Status.INLINE; // } else { // status = Status.KEEP; // } // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(); // sb.append("<"); // sb.append(refs); // sb.append("-"); // sb.append(status); // if (spec!=null) { // sb.append(" "); // sb.append(spec); // } // if (matchingBlock!=-1) { // sb.append("(loop "); // sb.append(matchingBlock); // sb.append(")"); // } // sb.append("> "); // sb.append(op); // return sb.toString(); // } // } // // Path: src/com/iconmaster/source/prototype/Field.java // public class Field implements IDirectable { // protected String name; // public Element rawType; // public Element rawValue; // protected ArrayList<String> directives = new ArrayList<>();; // // protected boolean compiled; // protected boolean library; // protected Expression value; // private DataType type; // // public String pkgName; // // /** // * A map used to store item information for the platform. // */ // public HashMap data = new HashMap<>(); // // public Field(String name) { // this(name,null); // } // // public Field(String name, Element type) { // this.name = name; // this.rawType = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name+"="+getType()); // if (value!=null) { // sb.append(". CODE:"); // // for (Operation op : value) { // sb.append("\n\t"); // sb.append(op.toString()); // } // } // return sb.toString(); // } // // public String getName() { // return name; // } // // public void setCompiled(Expression code) { // this.compiled = true; // this.value = code; // } // // public Element rawData() { // return rawValue; // } // // public boolean isCompiled() { // return compiled; // } // // public Expression getValue() { // return value; // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // // public boolean isLibrary() { // return library; // } // // public Element getRawType() { // return rawType; // } // // public DataType getType() { // return type; // } // // public void setType(DataType type) { // this.type = type; // } // // public static Field libraryField(String name, TypeDef type) { // Field f = new Field(name); // if (type!=null) { // f.setType(new DataType(type,false)); // } // f.library = true; // return f; // } // // public static interface OnCompile { // public String compile(SourcePackage pkg, boolean isGet, Object... args); // } // // public static interface OnRun { // public Object run(SourcePackage pkg, boolean isGet, Object... args); // } // } // Path: src/com/iconmaster/source/link/platform/hppl/HPPLField.java import com.iconmaster.source.link.platform.hppl.InlinedExpression.InlineOp; import com.iconmaster.source.prototype.Field; package com.iconmaster.source.link.platform.hppl; /** * * @author iconmaster */ public class HPPLField { public String compileName; public InlinedExpression expr;
public Field f;
iconmaster5326/Source
src/com/iconmaster/source/link/platform/hppl/HPPLField.java
// Path: src/com/iconmaster/source/link/platform/hppl/InlinedExpression.java // public static class InlineOp { // public Operation op; // public Status status = null; // public int refs = 0; // public SpecialOp spec; // public int matchingBlock = -1; // // public InlineOp(Operation op) { // this.op = op; // } // // public InlineOp(Operation op, SpecialOp spec) { // this.op = op; // this.spec = spec; // } // // public void addRef() { // refs++; // } // // public void setStatus() { // if (!op.op.hasLVar()) { // status = Status.NOT_APPLICABLE; // } else if (refs==0) { // status = Status.KEEP_NO_LVAL; // } else if (refs==1 && op.op!=OpType.MOVA && op.op!=OpType.MOVL) { // status = Status.INLINE; // } else { // status = Status.KEEP; // } // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(); // sb.append("<"); // sb.append(refs); // sb.append("-"); // sb.append(status); // if (spec!=null) { // sb.append(" "); // sb.append(spec); // } // if (matchingBlock!=-1) { // sb.append("(loop "); // sb.append(matchingBlock); // sb.append(")"); // } // sb.append("> "); // sb.append(op); // return sb.toString(); // } // } // // Path: src/com/iconmaster/source/prototype/Field.java // public class Field implements IDirectable { // protected String name; // public Element rawType; // public Element rawValue; // protected ArrayList<String> directives = new ArrayList<>();; // // protected boolean compiled; // protected boolean library; // protected Expression value; // private DataType type; // // public String pkgName; // // /** // * A map used to store item information for the platform. // */ // public HashMap data = new HashMap<>(); // // public Field(String name) { // this(name,null); // } // // public Field(String name, Element type) { // this.name = name; // this.rawType = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name+"="+getType()); // if (value!=null) { // sb.append(". CODE:"); // // for (Operation op : value) { // sb.append("\n\t"); // sb.append(op.toString()); // } // } // return sb.toString(); // } // // public String getName() { // return name; // } // // public void setCompiled(Expression code) { // this.compiled = true; // this.value = code; // } // // public Element rawData() { // return rawValue; // } // // public boolean isCompiled() { // return compiled; // } // // public Expression getValue() { // return value; // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // // public boolean isLibrary() { // return library; // } // // public Element getRawType() { // return rawType; // } // // public DataType getType() { // return type; // } // // public void setType(DataType type) { // this.type = type; // } // // public static Field libraryField(String name, TypeDef type) { // Field f = new Field(name); // if (type!=null) { // f.setType(new DataType(type,false)); // } // f.library = true; // return f; // } // // public static interface OnCompile { // public String compile(SourcePackage pkg, boolean isGet, Object... args); // } // // public static interface OnRun { // public Object run(SourcePackage pkg, boolean isGet, Object... args); // } // }
import com.iconmaster.source.link.platform.hppl.InlinedExpression.InlineOp; import com.iconmaster.source.prototype.Field;
package com.iconmaster.source.link.platform.hppl; /** * * @author iconmaster */ public class HPPLField { public String compileName; public InlinedExpression expr; public Field f; public HPPLField(String compileName, InlinedExpression expr, Field f) { this.compileName = compileName; this.expr = expr; this.f = f; } public String output; public void toString(AssemblyData ad) { StringBuilder sb = new StringBuilder(); ad.pushFrame(); ad.frame().dirs.addAll(f.getDirectives()); if (PlatformHPPL.shouldExport(f)) { sb.append("EXPORT "); } sb.append(PlatformHPPL.shouldExport(f) ? HPPLNaming.formatVarName(f.getName()) : compileName); if (f.getValue()!=null) {
// Path: src/com/iconmaster/source/link/platform/hppl/InlinedExpression.java // public static class InlineOp { // public Operation op; // public Status status = null; // public int refs = 0; // public SpecialOp spec; // public int matchingBlock = -1; // // public InlineOp(Operation op) { // this.op = op; // } // // public InlineOp(Operation op, SpecialOp spec) { // this.op = op; // this.spec = spec; // } // // public void addRef() { // refs++; // } // // public void setStatus() { // if (!op.op.hasLVar()) { // status = Status.NOT_APPLICABLE; // } else if (refs==0) { // status = Status.KEEP_NO_LVAL; // } else if (refs==1 && op.op!=OpType.MOVA && op.op!=OpType.MOVL) { // status = Status.INLINE; // } else { // status = Status.KEEP; // } // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(); // sb.append("<"); // sb.append(refs); // sb.append("-"); // sb.append(status); // if (spec!=null) { // sb.append(" "); // sb.append(spec); // } // if (matchingBlock!=-1) { // sb.append("(loop "); // sb.append(matchingBlock); // sb.append(")"); // } // sb.append("> "); // sb.append(op); // return sb.toString(); // } // } // // Path: src/com/iconmaster/source/prototype/Field.java // public class Field implements IDirectable { // protected String name; // public Element rawType; // public Element rawValue; // protected ArrayList<String> directives = new ArrayList<>();; // // protected boolean compiled; // protected boolean library; // protected Expression value; // private DataType type; // // public String pkgName; // // /** // * A map used to store item information for the platform. // */ // public HashMap data = new HashMap<>(); // // public Field(String name) { // this(name,null); // } // // public Field(String name, Element type) { // this.name = name; // this.rawType = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(name+"="+getType()); // if (value!=null) { // sb.append(". CODE:"); // // for (Operation op : value) { // sb.append("\n\t"); // sb.append(op.toString()); // } // } // return sb.toString(); // } // // public String getName() { // return name; // } // // public void setCompiled(Expression code) { // this.compiled = true; // this.value = code; // } // // public Element rawData() { // return rawValue; // } // // public boolean isCompiled() { // return compiled; // } // // public Expression getValue() { // return value; // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // // public boolean isLibrary() { // return library; // } // // public Element getRawType() { // return rawType; // } // // public DataType getType() { // return type; // } // // public void setType(DataType type) { // this.type = type; // } // // public static Field libraryField(String name, TypeDef type) { // Field f = new Field(name); // if (type!=null) { // f.setType(new DataType(type,false)); // } // f.library = true; // return f; // } // // public static interface OnCompile { // public String compile(SourcePackage pkg, boolean isGet, Object... args); // } // // public static interface OnRun { // public Object run(SourcePackage pkg, boolean isGet, Object... args); // } // } // Path: src/com/iconmaster/source/link/platform/hppl/HPPLField.java import com.iconmaster.source.link.platform.hppl.InlinedExpression.InlineOp; import com.iconmaster.source.prototype.Field; package com.iconmaster.source.link.platform.hppl; /** * * @author iconmaster */ public class HPPLField { public String compileName; public InlinedExpression expr; public Field f; public HPPLField(String compileName, InlinedExpression expr, Field f) { this.compileName = compileName; this.expr = expr; this.f = f; } public String output; public void toString(AssemblyData ad) { StringBuilder sb = new StringBuilder(); ad.pushFrame(); ad.frame().dirs.addAll(f.getDirectives()); if (PlatformHPPL.shouldExport(f)) { sb.append("EXPORT "); } sb.append(PlatformHPPL.shouldExport(f) ? HPPLNaming.formatVarName(f.getName()) : compileName); if (f.getValue()!=null) {
InlineOp op = expr.get(expr.size()-1);
iconmaster5326/Source
src/com/iconmaster/source/compile/Expression.java
// Path: src/com/iconmaster/source/prototype/TypeDef.java // public class TypeDef { // public static final TypeDef UNKNOWN = new TypeDef(); // public static final TypeDef STRING = new TypeDef("string"); // public static final TypeDef ARRAY = new TypeDef("array"); // public static final TypeDef LIST = new TypeDef("list"); // public static final TypeDef BOOLEAN = new TypeDef("bool"); // public static final TypeDef MAP = new TypeDef("map"); // public static final TypeDef PTR = new TypeDef("ptr"); // public static final TypeDef FPTR = new TypeDef("fptr"); // // public static final TypeDef INT8 = new TypeDef("int8"); // public static final TypeDef INT16 = new TypeDef("int16"); // public static final TypeDef INT32 = new TypeDef("int32"); // public static final TypeDef INT64 = new TypeDef("int64"); // // public static final TypeDef REAL32 = new TypeDef("real32"); // public static final TypeDef REAL64 = new TypeDef("real64"); // // public static final TypeDef REAL = new TypeDef("real", TypeDef.REAL32); // public static final TypeDef INT = new TypeDef("int", TypeDef.INT32); // public static final TypeDef CHAR = new TypeDef("char", TypeDef.INT8); // // public String name; // public String pkgName; // // public TypeDef parent = null; // // public TypeDef() { // this.name = "?"; // } // // public TypeDef(String name) { // this(name,TypeDef.UNKNOWN); // } // // public TypeDef(String name, TypeDef parent) { // this.name = name; // this.parent = parent; // } // // @Override // public String toString() { // return name; // } // // public static TypeDef getCommonParent(TypeDef type1,TypeDef type2) { // if (type1==null || type2==null) { // return TypeDef.UNKNOWN; // } // if (type1==type2) { // return type1; // } // if (type1.parent==type2) { // return type2; // } // if (type1==type2.parent) { // return type1; // } // return getCommonParent(type1.parent,type2.parent); // } // // public static void addBaseTypes(SourcePackage pkg) { // pkg.addType(TypeDef.UNKNOWN); // pkg.addType(TypeDef.INT); // pkg.addType(TypeDef.REAL); // pkg.addType(TypeDef.STRING); // pkg.addType(TypeDef.ARRAY); // pkg.addType(TypeDef.LIST); // pkg.addType(TypeDef.CHAR); // pkg.addType(TypeDef.BOOLEAN); // pkg.addType(TypeDef.MAP); // pkg.addType(TypeDef.INT8); // pkg.addType(TypeDef.INT16); // pkg.addType(TypeDef.INT32); // pkg.addType(TypeDef.INT64); // pkg.addType(TypeDef.REAL32); // pkg.addType(TypeDef.REAL64); // } // }
import com.iconmaster.source.prototype.TypeDef; import java.util.ArrayList;
package com.iconmaster.source.compile; /** * * @author iconmaster */ public class Expression extends ArrayList<Operation> { public String retVar;
// Path: src/com/iconmaster/source/prototype/TypeDef.java // public class TypeDef { // public static final TypeDef UNKNOWN = new TypeDef(); // public static final TypeDef STRING = new TypeDef("string"); // public static final TypeDef ARRAY = new TypeDef("array"); // public static final TypeDef LIST = new TypeDef("list"); // public static final TypeDef BOOLEAN = new TypeDef("bool"); // public static final TypeDef MAP = new TypeDef("map"); // public static final TypeDef PTR = new TypeDef("ptr"); // public static final TypeDef FPTR = new TypeDef("fptr"); // // public static final TypeDef INT8 = new TypeDef("int8"); // public static final TypeDef INT16 = new TypeDef("int16"); // public static final TypeDef INT32 = new TypeDef("int32"); // public static final TypeDef INT64 = new TypeDef("int64"); // // public static final TypeDef REAL32 = new TypeDef("real32"); // public static final TypeDef REAL64 = new TypeDef("real64"); // // public static final TypeDef REAL = new TypeDef("real", TypeDef.REAL32); // public static final TypeDef INT = new TypeDef("int", TypeDef.INT32); // public static final TypeDef CHAR = new TypeDef("char", TypeDef.INT8); // // public String name; // public String pkgName; // // public TypeDef parent = null; // // public TypeDef() { // this.name = "?"; // } // // public TypeDef(String name) { // this(name,TypeDef.UNKNOWN); // } // // public TypeDef(String name, TypeDef parent) { // this.name = name; // this.parent = parent; // } // // @Override // public String toString() { // return name; // } // // public static TypeDef getCommonParent(TypeDef type1,TypeDef type2) { // if (type1==null || type2==null) { // return TypeDef.UNKNOWN; // } // if (type1==type2) { // return type1; // } // if (type1.parent==type2) { // return type2; // } // if (type1==type2.parent) { // return type1; // } // return getCommonParent(type1.parent,type2.parent); // } // // public static void addBaseTypes(SourcePackage pkg) { // pkg.addType(TypeDef.UNKNOWN); // pkg.addType(TypeDef.INT); // pkg.addType(TypeDef.REAL); // pkg.addType(TypeDef.STRING); // pkg.addType(TypeDef.ARRAY); // pkg.addType(TypeDef.LIST); // pkg.addType(TypeDef.CHAR); // pkg.addType(TypeDef.BOOLEAN); // pkg.addType(TypeDef.MAP); // pkg.addType(TypeDef.INT8); // pkg.addType(TypeDef.INT16); // pkg.addType(TypeDef.INT32); // pkg.addType(TypeDef.INT64); // pkg.addType(TypeDef.REAL32); // pkg.addType(TypeDef.REAL64); // } // } // Path: src/com/iconmaster/source/compile/Expression.java import com.iconmaster.source.prototype.TypeDef; import java.util.ArrayList; package com.iconmaster.source.compile; /** * * @author iconmaster */ public class Expression extends ArrayList<Operation> { public String retVar;
public DataType type = new DataType(TypeDef.UNKNOWN,true);
iconmaster5326/Source
src/com/iconmaster/source/prototype/Prototyper.java
// Path: src/com/iconmaster/source/element/Element.java // public class Element implements IDirectable { // public IElementType type; // public Object[] args = new Object[10]; // public Element dataType = null; // public ArrayList<String> directives = new ArrayList<>(); // public Range range; // // public Element(Range range, IElementType type) { // this.range = range; // this.type = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder("{"); // sb.append(type).append(" as ").append(dataType).append(": [").append(args[0]).append(" ").append(args[1]).append(" ").append(args[2]).append(" ").append(args[3]).append("]"); // return sb.append("}").toString(); // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // } // // Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // }
import com.iconmaster.source.element.Element; import com.iconmaster.source.exception.SourceException; import java.util.ArrayList;
package com.iconmaster.source.prototype; /** * * @author iconmaster */ public class Prototyper { public static class PrototypeResult { public SourcePackage result;
// Path: src/com/iconmaster/source/element/Element.java // public class Element implements IDirectable { // public IElementType type; // public Object[] args = new Object[10]; // public Element dataType = null; // public ArrayList<String> directives = new ArrayList<>(); // public Range range; // // public Element(Range range, IElementType type) { // this.range = range; // this.type = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder("{"); // sb.append(type).append(" as ").append(dataType).append(": [").append(args[0]).append(" ").append(args[1]).append(" ").append(args[2]).append(" ").append(args[3]).append("]"); // return sb.append("}").toString(); // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // } // // Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // } // Path: src/com/iconmaster/source/prototype/Prototyper.java import com.iconmaster.source.element.Element; import com.iconmaster.source.exception.SourceException; import java.util.ArrayList; package com.iconmaster.source.prototype; /** * * @author iconmaster */ public class Prototyper { public static class PrototypeResult { public SourcePackage result;
public ArrayList<SourceException> errors;
iconmaster5326/Source
src/com/iconmaster/source/prototype/Prototyper.java
// Path: src/com/iconmaster/source/element/Element.java // public class Element implements IDirectable { // public IElementType type; // public Object[] args = new Object[10]; // public Element dataType = null; // public ArrayList<String> directives = new ArrayList<>(); // public Range range; // // public Element(Range range, IElementType type) { // this.range = range; // this.type = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder("{"); // sb.append(type).append(" as ").append(dataType).append(": [").append(args[0]).append(" ").append(args[1]).append(" ").append(args[2]).append(" ").append(args[3]).append("]"); // return sb.append("}").toString(); // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // } // // Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // }
import com.iconmaster.source.element.Element; import com.iconmaster.source.exception.SourceException; import java.util.ArrayList;
package com.iconmaster.source.prototype; /** * * @author iconmaster */ public class Prototyper { public static class PrototypeResult { public SourcePackage result; public ArrayList<SourceException> errors; public PrototypeResult(SourcePackage result, ArrayList<SourceException> errors) { this.result = result; this.errors = errors; } }
// Path: src/com/iconmaster/source/element/Element.java // public class Element implements IDirectable { // public IElementType type; // public Object[] args = new Object[10]; // public Element dataType = null; // public ArrayList<String> directives = new ArrayList<>(); // public Range range; // // public Element(Range range, IElementType type) { // this.range = range; // this.type = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder("{"); // sb.append(type).append(" as ").append(dataType).append(": [").append(args[0]).append(" ").append(args[1]).append(" ").append(args[2]).append(" ").append(args[3]).append("]"); // return sb.append("}").toString(); // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // } // // Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // } // Path: src/com/iconmaster/source/prototype/Prototyper.java import com.iconmaster.source.element.Element; import com.iconmaster.source.exception.SourceException; import java.util.ArrayList; package com.iconmaster.source.prototype; /** * * @author iconmaster */ public class Prototyper { public static class PrototypeResult { public SourcePackage result; public ArrayList<SourceException> errors; public PrototypeResult(SourcePackage result, ArrayList<SourceException> errors) { this.result = result; this.errors = errors; } }
public static PrototypeResult prototype(ArrayList<Element> a) {
iconmaster5326/Source
src/com/iconmaster/source/exception/SourceImportException.java
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.util.Range;
package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceImportException extends SourceException { public String var;
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/exception/SourceImportException.java import com.iconmaster.source.util.Range; package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceImportException extends SourceException { public String var;
public SourceImportException(Range range, String message, String var) {
iconmaster5326/Source
src/com/iconmaster/source/compile/DataType.java
// Path: src/com/iconmaster/source/prototype/ParamTypeDef.java // public class ParamTypeDef extends TypeDef { // public int paramNo; // public TypeDef baseType; // // public ParamTypeDef(String name, int paramNo) { // this(name,paramNo,TypeDef.UNKNOWN); // } // // public ParamTypeDef(String name, int paramNo, TypeDef baseType) { // super(name,baseType); // this.paramNo = paramNo; // this.baseType = baseType; // } // } // // Path: src/com/iconmaster/source/prototype/TypeDef.java // public class TypeDef { // public static final TypeDef UNKNOWN = new TypeDef(); // public static final TypeDef STRING = new TypeDef("string"); // public static final TypeDef ARRAY = new TypeDef("array"); // public static final TypeDef LIST = new TypeDef("list"); // public static final TypeDef BOOLEAN = new TypeDef("bool"); // public static final TypeDef MAP = new TypeDef("map"); // public static final TypeDef PTR = new TypeDef("ptr"); // public static final TypeDef FPTR = new TypeDef("fptr"); // // public static final TypeDef INT8 = new TypeDef("int8"); // public static final TypeDef INT16 = new TypeDef("int16"); // public static final TypeDef INT32 = new TypeDef("int32"); // public static final TypeDef INT64 = new TypeDef("int64"); // // public static final TypeDef REAL32 = new TypeDef("real32"); // public static final TypeDef REAL64 = new TypeDef("real64"); // // public static final TypeDef REAL = new TypeDef("real", TypeDef.REAL32); // public static final TypeDef INT = new TypeDef("int", TypeDef.INT32); // public static final TypeDef CHAR = new TypeDef("char", TypeDef.INT8); // // public String name; // public String pkgName; // // public TypeDef parent = null; // // public TypeDef() { // this.name = "?"; // } // // public TypeDef(String name) { // this(name,TypeDef.UNKNOWN); // } // // public TypeDef(String name, TypeDef parent) { // this.name = name; // this.parent = parent; // } // // @Override // public String toString() { // return name; // } // // public static TypeDef getCommonParent(TypeDef type1,TypeDef type2) { // if (type1==null || type2==null) { // return TypeDef.UNKNOWN; // } // if (type1==type2) { // return type1; // } // if (type1.parent==type2) { // return type2; // } // if (type1==type2.parent) { // return type1; // } // return getCommonParent(type1.parent,type2.parent); // } // // public static void addBaseTypes(SourcePackage pkg) { // pkg.addType(TypeDef.UNKNOWN); // pkg.addType(TypeDef.INT); // pkg.addType(TypeDef.REAL); // pkg.addType(TypeDef.STRING); // pkg.addType(TypeDef.ARRAY); // pkg.addType(TypeDef.LIST); // pkg.addType(TypeDef.CHAR); // pkg.addType(TypeDef.BOOLEAN); // pkg.addType(TypeDef.MAP); // pkg.addType(TypeDef.INT8); // pkg.addType(TypeDef.INT16); // pkg.addType(TypeDef.INT32); // pkg.addType(TypeDef.INT64); // pkg.addType(TypeDef.REAL32); // pkg.addType(TypeDef.REAL64); // } // }
import com.iconmaster.source.prototype.ParamTypeDef; import com.iconmaster.source.prototype.TypeDef; import java.util.Arrays;
public static DataType getNewType(DataType thisType, DataType other) { if (thisType==null) { return other; } if (other==null) { other = new DataType(true); } if (!thisType.weak) { return thisType; } return commonType(thisType, other); } public static DataType commonType(DataType type1, DataType type2) { if (type1==null) { type1 = new DataType(true); } if (type2==null) { type2 = new DataType(true); } return new DataType(TypeDef.getCommonParent(type1.type, type2.type),true); } public static boolean canCastTo(DataType thisType, DataType other) { if (thisType==null) { thisType = new DataType(true); } if (other==null) { other = new DataType(true); }
// Path: src/com/iconmaster/source/prototype/ParamTypeDef.java // public class ParamTypeDef extends TypeDef { // public int paramNo; // public TypeDef baseType; // // public ParamTypeDef(String name, int paramNo) { // this(name,paramNo,TypeDef.UNKNOWN); // } // // public ParamTypeDef(String name, int paramNo, TypeDef baseType) { // super(name,baseType); // this.paramNo = paramNo; // this.baseType = baseType; // } // } // // Path: src/com/iconmaster/source/prototype/TypeDef.java // public class TypeDef { // public static final TypeDef UNKNOWN = new TypeDef(); // public static final TypeDef STRING = new TypeDef("string"); // public static final TypeDef ARRAY = new TypeDef("array"); // public static final TypeDef LIST = new TypeDef("list"); // public static final TypeDef BOOLEAN = new TypeDef("bool"); // public static final TypeDef MAP = new TypeDef("map"); // public static final TypeDef PTR = new TypeDef("ptr"); // public static final TypeDef FPTR = new TypeDef("fptr"); // // public static final TypeDef INT8 = new TypeDef("int8"); // public static final TypeDef INT16 = new TypeDef("int16"); // public static final TypeDef INT32 = new TypeDef("int32"); // public static final TypeDef INT64 = new TypeDef("int64"); // // public static final TypeDef REAL32 = new TypeDef("real32"); // public static final TypeDef REAL64 = new TypeDef("real64"); // // public static final TypeDef REAL = new TypeDef("real", TypeDef.REAL32); // public static final TypeDef INT = new TypeDef("int", TypeDef.INT32); // public static final TypeDef CHAR = new TypeDef("char", TypeDef.INT8); // // public String name; // public String pkgName; // // public TypeDef parent = null; // // public TypeDef() { // this.name = "?"; // } // // public TypeDef(String name) { // this(name,TypeDef.UNKNOWN); // } // // public TypeDef(String name, TypeDef parent) { // this.name = name; // this.parent = parent; // } // // @Override // public String toString() { // return name; // } // // public static TypeDef getCommonParent(TypeDef type1,TypeDef type2) { // if (type1==null || type2==null) { // return TypeDef.UNKNOWN; // } // if (type1==type2) { // return type1; // } // if (type1.parent==type2) { // return type2; // } // if (type1==type2.parent) { // return type1; // } // return getCommonParent(type1.parent,type2.parent); // } // // public static void addBaseTypes(SourcePackage pkg) { // pkg.addType(TypeDef.UNKNOWN); // pkg.addType(TypeDef.INT); // pkg.addType(TypeDef.REAL); // pkg.addType(TypeDef.STRING); // pkg.addType(TypeDef.ARRAY); // pkg.addType(TypeDef.LIST); // pkg.addType(TypeDef.CHAR); // pkg.addType(TypeDef.BOOLEAN); // pkg.addType(TypeDef.MAP); // pkg.addType(TypeDef.INT8); // pkg.addType(TypeDef.INT16); // pkg.addType(TypeDef.INT32); // pkg.addType(TypeDef.INT64); // pkg.addType(TypeDef.REAL32); // pkg.addType(TypeDef.REAL64); // } // } // Path: src/com/iconmaster/source/compile/DataType.java import com.iconmaster.source.prototype.ParamTypeDef; import com.iconmaster.source.prototype.TypeDef; import java.util.Arrays; public static DataType getNewType(DataType thisType, DataType other) { if (thisType==null) { return other; } if (other==null) { other = new DataType(true); } if (!thisType.weak) { return thisType; } return commonType(thisType, other); } public static DataType commonType(DataType type1, DataType type2) { if (type1==null) { type1 = new DataType(true); } if (type2==null) { type2 = new DataType(true); } return new DataType(TypeDef.getCommonParent(type1.type, type2.type),true); } public static boolean canCastTo(DataType thisType, DataType other) { if (thisType==null) { thisType = new DataType(true); } if (other==null) { other = new DataType(true); }
if (thisType.type instanceof ParamTypeDef) {
iconmaster5326/Source
src/com/iconmaster/source/link/platform/hppl/HPPLFunction.java
// Path: src/com/iconmaster/source/prototype/Function.java // public class Function implements IDirectable { // protected String name; // protected ArrayList<Field> args; // public Element rawReturns; // protected ArrayList<String> directives = new ArrayList<>(); // public ArrayList<Element> rawCode; // protected boolean library = false; // // protected boolean compiled = false; // protected ArrayList<Operation> code; // private DataType returns; // // public String pkgName; // // public int order = 0; // public int references = 0; // // public ArrayList<Field> rawParams; // // /** // * A map used to store item information for the platform. // */ // public HashMap data = new HashMap<>(); // // public Function(String name, ArrayList<Field> args, Element returns) { // this.name = name; // this.args = args; // this.rawReturns = returns; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(getFullName()+args+" as "+returns); // if (code!=null) { // sb.append(". CODE:"); // // for (Operation op : code) { // sb.append("\n\t"); // sb.append(op.toString()); // } // } // return sb.toString(); // } // // public static Function libraryFunction(String name, String[] args, Object[] argTypes, Object ret) { // ArrayList<Field> argList = new ArrayList<>(); // ArrayList<DataType> retList = new ArrayList<>(); // // int i = 0; // for (String arg : args) { // Element e = null; // Field f = new Field(arg, null); // if (i<argTypes.length) { // DataType dt = null; // if (argTypes[i] instanceof TypeDef) { // dt = new DataType((TypeDef)argTypes[i],false); // } else if (argTypes[i] instanceof DataType) { // dt = (DataType) argTypes[i]; // } // f.setType(dt); // } // argList.add(f); // i++; // } // // // Function fn = new Function(name, argList, null); // DataType dt = null; // if (ret instanceof TypeDef) { // dt = new DataType((TypeDef)ret,false); // } else if (ret instanceof DataType) { // dt = (DataType) ret; // } // fn.setReturnType(dt); // fn.library = true; // fn.compiled = true; // return fn; // } // // public void setCompiled(ArrayList<Operation> code) { // this.compiled = true; // this.code = code; // } // // public ArrayList<Element> rawData() { // return rawCode; // } // // public boolean isCompiled() { // return compiled; // } // // public String getName() { // return name; // } // // public String getFullName() { // return ((pkgName==null || pkgName.isEmpty())?"":(pkgName+"."))+name+(order==0?"":("%"+order)); // } // // public ArrayList<Operation> getCode() { // return code; // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // // public ArrayList<Field> getArguments() { // return args; // } // // public boolean isLibrary() { // return library; // } // // public Element getReturn() { // return rawReturns; // } // // public DataType getReturnType() { // return returns; // } // // public void setReturnType(DataType returns) { // this.returns = returns; // } // // public static interface OnCompile { // public String compile(SourcePackage pkg, Object... args); // } // // public static interface OnRun { // public Object run(SourcePackage pkg, Object... args); // } // } // // Path: src/com/iconmaster/source/util/Directives.java // public class Directives { // public static boolean has(ArrayList<String> dirs, String dir) { // boolean neg = false; // if (dir.startsWith("!")) { // dir = dir.substring(1); // neg = true; // } // int count = 0; // for (String dir2 : dirs) { // if (dir2.startsWith(dir)) { // count++; // } else if (dir2.startsWith("!"+dir)) { // count--; // } // } // return neg?count<0:count>0; // } // // public static boolean has(IDirectable obj, String dir) { // return obj==null ? false : has(obj.getDirectives(),dir); // } // // public static ArrayList<String> getAll(IDirectable obj) { // return obj.getDirectives(); // } // // public static ArrayList<String> getValues(IDirectable obj, String dir) { // return getValues(obj.getDirectives(),dir); // } // // public static ArrayList<String> getValues(ArrayList<String> dirs, String dir) { // ArrayList<String> a = new ArrayList<>(); // for (String dir2 : dirs) { // if (dir2.startsWith(dir+"=")) { // a.add(dir2.substring(dir2.indexOf("=")+1)); // } // } // return a; // } // }
import com.iconmaster.source.prototype.Function; import com.iconmaster.source.util.Directives; import java.util.ArrayList;
package com.iconmaster.source.link.platform.hppl; /** * * @author iconmaster */ public class HPPLFunction { public String compileName; public ArrayList<HPPLVariable> args; public InlinedExpression code;
// Path: src/com/iconmaster/source/prototype/Function.java // public class Function implements IDirectable { // protected String name; // protected ArrayList<Field> args; // public Element rawReturns; // protected ArrayList<String> directives = new ArrayList<>(); // public ArrayList<Element> rawCode; // protected boolean library = false; // // protected boolean compiled = false; // protected ArrayList<Operation> code; // private DataType returns; // // public String pkgName; // // public int order = 0; // public int references = 0; // // public ArrayList<Field> rawParams; // // /** // * A map used to store item information for the platform. // */ // public HashMap data = new HashMap<>(); // // public Function(String name, ArrayList<Field> args, Element returns) { // this.name = name; // this.args = args; // this.rawReturns = returns; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(getFullName()+args+" as "+returns); // if (code!=null) { // sb.append(". CODE:"); // // for (Operation op : code) { // sb.append("\n\t"); // sb.append(op.toString()); // } // } // return sb.toString(); // } // // public static Function libraryFunction(String name, String[] args, Object[] argTypes, Object ret) { // ArrayList<Field> argList = new ArrayList<>(); // ArrayList<DataType> retList = new ArrayList<>(); // // int i = 0; // for (String arg : args) { // Element e = null; // Field f = new Field(arg, null); // if (i<argTypes.length) { // DataType dt = null; // if (argTypes[i] instanceof TypeDef) { // dt = new DataType((TypeDef)argTypes[i],false); // } else if (argTypes[i] instanceof DataType) { // dt = (DataType) argTypes[i]; // } // f.setType(dt); // } // argList.add(f); // i++; // } // // // Function fn = new Function(name, argList, null); // DataType dt = null; // if (ret instanceof TypeDef) { // dt = new DataType((TypeDef)ret,false); // } else if (ret instanceof DataType) { // dt = (DataType) ret; // } // fn.setReturnType(dt); // fn.library = true; // fn.compiled = true; // return fn; // } // // public void setCompiled(ArrayList<Operation> code) { // this.compiled = true; // this.code = code; // } // // public ArrayList<Element> rawData() { // return rawCode; // } // // public boolean isCompiled() { // return compiled; // } // // public String getName() { // return name; // } // // public String getFullName() { // return ((pkgName==null || pkgName.isEmpty())?"":(pkgName+"."))+name+(order==0?"":("%"+order)); // } // // public ArrayList<Operation> getCode() { // return code; // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // // public ArrayList<Field> getArguments() { // return args; // } // // public boolean isLibrary() { // return library; // } // // public Element getReturn() { // return rawReturns; // } // // public DataType getReturnType() { // return returns; // } // // public void setReturnType(DataType returns) { // this.returns = returns; // } // // public static interface OnCompile { // public String compile(SourcePackage pkg, Object... args); // } // // public static interface OnRun { // public Object run(SourcePackage pkg, Object... args); // } // } // // Path: src/com/iconmaster/source/util/Directives.java // public class Directives { // public static boolean has(ArrayList<String> dirs, String dir) { // boolean neg = false; // if (dir.startsWith("!")) { // dir = dir.substring(1); // neg = true; // } // int count = 0; // for (String dir2 : dirs) { // if (dir2.startsWith(dir)) { // count++; // } else if (dir2.startsWith("!"+dir)) { // count--; // } // } // return neg?count<0:count>0; // } // // public static boolean has(IDirectable obj, String dir) { // return obj==null ? false : has(obj.getDirectives(),dir); // } // // public static ArrayList<String> getAll(IDirectable obj) { // return obj.getDirectives(); // } // // public static ArrayList<String> getValues(IDirectable obj, String dir) { // return getValues(obj.getDirectives(),dir); // } // // public static ArrayList<String> getValues(ArrayList<String> dirs, String dir) { // ArrayList<String> a = new ArrayList<>(); // for (String dir2 : dirs) { // if (dir2.startsWith(dir+"=")) { // a.add(dir2.substring(dir2.indexOf("=")+1)); // } // } // return a; // } // } // Path: src/com/iconmaster/source/link/platform/hppl/HPPLFunction.java import com.iconmaster.source.prototype.Function; import com.iconmaster.source.util.Directives; import java.util.ArrayList; package com.iconmaster.source.link.platform.hppl; /** * * @author iconmaster */ public class HPPLFunction { public String compileName; public ArrayList<HPPLVariable> args; public InlinedExpression code;
public Function fn;
iconmaster5326/Source
src/com/iconmaster/source/tokenize/Tokenizer.java
// Path: src/com/iconmaster/source/element/Element.java // public class Element implements IDirectable { // public IElementType type; // public Object[] args = new Object[10]; // public Element dataType = null; // public ArrayList<String> directives = new ArrayList<>(); // public Range range; // // public Element(Range range, IElementType type) { // this.range = range; // this.type = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder("{"); // sb.append(type).append(" as ").append(dataType).append(": [").append(args[0]).append(" ").append(args[1]).append(" ").append(args[2]).append(" ").append(args[3]).append("]"); // return sb.append("}").toString(); // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // } // // Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.element.Element; import com.iconmaster.source.exception.SourceException; import com.iconmaster.source.util.Range; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern;
package com.iconmaster.source.tokenize; /** * * @author iconmaster */ public class Tokenizer { public static ArrayList<Element> tokenize(String input) throws SourceException { return tokenize(input, true); } public static ArrayList<Element> tokenize(String input, boolean expand) throws SourceException { ArrayList<Token> a = new ArrayList<>(); //add basic tokens int len = 0; while (!input.isEmpty()) { //System.out.println(input); boolean found = false; for (TokenRule rule : TokenRule.values()) { Matcher m = Pattern.compile(rule.match).matcher(input); if (m.find()) { String got = m.group(); int olen = len; len+=got.length(); if (expand) { got = rule.format(got); } input = m.replaceFirst(""); if (got!=null) {
// Path: src/com/iconmaster/source/element/Element.java // public class Element implements IDirectable { // public IElementType type; // public Object[] args = new Object[10]; // public Element dataType = null; // public ArrayList<String> directives = new ArrayList<>(); // public Range range; // // public Element(Range range, IElementType type) { // this.range = range; // this.type = type; // } // // @Override // public String toString() { // StringBuilder sb = new StringBuilder("{"); // sb.append(type).append(" as ").append(dataType).append(": [").append(args[0]).append(" ").append(args[1]).append(" ").append(args[2]).append(" ").append(args[3]).append("]"); // return sb.append("}").toString(); // } // // @Override // public ArrayList<String> getDirectives() { // return directives; // } // } // // Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // } // // Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/tokenize/Tokenizer.java import com.iconmaster.source.element.Element; import com.iconmaster.source.exception.SourceException; import com.iconmaster.source.util.Range; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; package com.iconmaster.source.tokenize; /** * * @author iconmaster */ public class Tokenizer { public static ArrayList<Element> tokenize(String input) throws SourceException { return tokenize(input, true); } public static ArrayList<Element> tokenize(String input, boolean expand) throws SourceException { ArrayList<Token> a = new ArrayList<>(); //add basic tokens int len = 0; while (!input.isEmpty()) { //System.out.println(input); boolean found = false; for (TokenRule rule : TokenRule.values()) { Matcher m = Pattern.compile(rule.match).matcher(input); if (m.find()) { String got = m.group(); int olen = len; len+=got.length(); if (expand) { got = rule.format(got); } input = m.replaceFirst(""); if (got!=null) {
a.add(new Token(new Range(olen,len),rule,got));
iconmaster5326/Source
src/com/iconmaster/source/exception/SourceSafeModeException.java
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.util.Range;
package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceSafeModeException extends SourceException { public String var;
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/exception/SourceSafeModeException.java import com.iconmaster.source.util.Range; package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceSafeModeException extends SourceException { public String var;
public SourceSafeModeException(Range range, String message, String var) {
iconmaster5326/Source
src/com/iconmaster/source/exception/SourceUndefinedVariableException.java
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // }
import com.iconmaster.source.util.Range;
package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceUndefinedVariableException extends SourceException { public String var;
// Path: src/com/iconmaster/source/util/Range.java // public class Range { // public final int low; // public final int high; // // public Range(int low, int high) { // this.low = Math.min(low, high); // this.high = Math.max(low, high); // } // // @Override // public String toString() { // return low+"~"+high; // } // // public static Range from(Range r1, Range r2) { // return new Range(r1==null?0:r1.low,r2==null?0:r2.high); // } // // // } // Path: src/com/iconmaster/source/exception/SourceUndefinedVariableException.java import com.iconmaster.source.util.Range; package com.iconmaster.source.exception; /** * * @author iconmaster */ public class SourceUndefinedVariableException extends SourceException { public String var;
public SourceUndefinedVariableException(Range range, String message, String var) {
iconmaster5326/Source
src/com/iconmaster/source/assemble/AssembledOutput.java
// Path: src/com/iconmaster/source/SourceOptions.java // public class SourceOptions { // public String input; // public String platform; // public boolean compile; // // public File assets; // public File libs; // public File outputFile; // // public OutputStream sout = System.out; // public InputStream sin = System.in; // public OutputStream serr = System.err; // // public boolean noRunAssemble = false; // // public SourceOptions(String input, String platform, boolean compile) { // this.input = input; // this.platform = platform; // this.compile = compile; // } // // public SourceOptions setFiles(File assets, File libs, File outputFile) { // this.assets = assets; // this.libs = libs; // this.outputFile = outputFile; // return this; // } // // public SourceOptions setStreams(OutputStream sout, InputStream sin, OutputStream serr) { // this.sout = sout; // this.sin = sin; // this.serr = serr; // return this; // } // } // // Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // }
import com.iconmaster.source.SourceOptions; import com.iconmaster.source.exception.SourceException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger;
package com.iconmaster.source.assemble; /** * * @author iconmaster */ public abstract class AssembledOutput { public ArrayList<SourceException> errs = new ArrayList<>();
// Path: src/com/iconmaster/source/SourceOptions.java // public class SourceOptions { // public String input; // public String platform; // public boolean compile; // // public File assets; // public File libs; // public File outputFile; // // public OutputStream sout = System.out; // public InputStream sin = System.in; // public OutputStream serr = System.err; // // public boolean noRunAssemble = false; // // public SourceOptions(String input, String platform, boolean compile) { // this.input = input; // this.platform = platform; // this.compile = compile; // } // // public SourceOptions setFiles(File assets, File libs, File outputFile) { // this.assets = assets; // this.libs = libs; // this.outputFile = outputFile; // return this; // } // // public SourceOptions setStreams(OutputStream sout, InputStream sin, OutputStream serr) { // this.sout = sout; // this.sin = sin; // this.serr = serr; // return this; // } // } // // Path: src/com/iconmaster/source/exception/SourceException.java // public class SourceException extends Exception { // private final Range range; // // public SourceException(Range range) { // super(range.toString()+": Unknown Source exception"); // this.range = range; // } // // public SourceException(Range range, String message) { // super((range==null?"null: ":range.toString()+": ")+message); // this.range = range; // } // // @Override // public String getMessage() { // return super.getMessage(); // } // // public Range getRange() { // return range; // } // } // Path: src/com/iconmaster/source/assemble/AssembledOutput.java import com.iconmaster.source.SourceOptions; import com.iconmaster.source.exception.SourceException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; package com.iconmaster.source.assemble; /** * * @author iconmaster */ public abstract class AssembledOutput { public ArrayList<SourceException> errs = new ArrayList<>();
public void saveToFile(SourceOptions opts) {
iconmaster5326/Source
src/com/iconmaster/source/prototype/FunctionCall.java
// Path: src/com/iconmaster/source/compile/DataType.java // public class DataType { // public TypeDef type; // public boolean weak; // public DataType[] params = new DataType[0]; // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(); // sb.append(""); // sb.append(type); // sb.append(weak?"?":""); // if (params.length!=0) { // sb.append("["); // for (DataType param : params) { // sb.append(param); // sb.append(","); // } // sb.deleteCharAt(sb.length()-1); // sb.append("]"); // } // return sb.toString(); // } // // public DataType() { // this(TypeDef.UNKNOWN,false); // } // // public DataType(TypeDef def) { // this(def,false); // } // // public DataType(boolean def) { // this(TypeDef.UNKNOWN,def); // } // // public DataType(TypeDef def, boolean w) { // type = def; // weak = w; // } // // public static DataType getNewType(DataType thisType, DataType other) { // if (thisType==null) { // return other; // } // if (other==null) { // other = new DataType(true); // } // if (!thisType.weak) { // return thisType; // } // return commonType(thisType, other); // } // // public static DataType commonType(DataType type1, DataType type2) { // if (type1==null) { // type1 = new DataType(true); // } // if (type2==null) { // type2 = new DataType(true); // } // return new DataType(TypeDef.getCommonParent(type1.type, type2.type),true); // } // // public static boolean canCastTo(DataType thisType, DataType other) { // if (thisType==null) { // thisType = new DataType(true); // } // if (other==null) { // other = new DataType(true); // } // if (thisType.type instanceof ParamTypeDef) { // thisType = new DataType(thisType.type.parent); // } // if (other.type instanceof ParamTypeDef) { // other = new DataType(other.type.parent); // } // if (thisType.weak) { // return TypeDef.getCommonParent(thisType.type, other.type)!=null; // } else { // return TypeDef.getCommonParent(thisType.type, other.type)==thisType.type; // } // } // // public DataType cloneType() { // DataType dt = new DataType(type, weak); // dt.params = Arrays.copyOf(dt.params, dt.params.length); // return dt; // } // }
import com.iconmaster.source.compile.DataType; import java.util.ArrayList;
package com.iconmaster.source.prototype; /** * * @author iconmaster */ public class FunctionCall { public String name;
// Path: src/com/iconmaster/source/compile/DataType.java // public class DataType { // public TypeDef type; // public boolean weak; // public DataType[] params = new DataType[0]; // // @Override // public String toString() { // StringBuilder sb = new StringBuilder(); // sb.append(""); // sb.append(type); // sb.append(weak?"?":""); // if (params.length!=0) { // sb.append("["); // for (DataType param : params) { // sb.append(param); // sb.append(","); // } // sb.deleteCharAt(sb.length()-1); // sb.append("]"); // } // return sb.toString(); // } // // public DataType() { // this(TypeDef.UNKNOWN,false); // } // // public DataType(TypeDef def) { // this(def,false); // } // // public DataType(boolean def) { // this(TypeDef.UNKNOWN,def); // } // // public DataType(TypeDef def, boolean w) { // type = def; // weak = w; // } // // public static DataType getNewType(DataType thisType, DataType other) { // if (thisType==null) { // return other; // } // if (other==null) { // other = new DataType(true); // } // if (!thisType.weak) { // return thisType; // } // return commonType(thisType, other); // } // // public static DataType commonType(DataType type1, DataType type2) { // if (type1==null) { // type1 = new DataType(true); // } // if (type2==null) { // type2 = new DataType(true); // } // return new DataType(TypeDef.getCommonParent(type1.type, type2.type),true); // } // // public static boolean canCastTo(DataType thisType, DataType other) { // if (thisType==null) { // thisType = new DataType(true); // } // if (other==null) { // other = new DataType(true); // } // if (thisType.type instanceof ParamTypeDef) { // thisType = new DataType(thisType.type.parent); // } // if (other.type instanceof ParamTypeDef) { // other = new DataType(other.type.parent); // } // if (thisType.weak) { // return TypeDef.getCommonParent(thisType.type, other.type)!=null; // } else { // return TypeDef.getCommonParent(thisType.type, other.type)==thisType.type; // } // } // // public DataType cloneType() { // DataType dt = new DataType(type, weak); // dt.params = Arrays.copyOf(dt.params, dt.params.length); // return dt; // } // } // Path: src/com/iconmaster/source/prototype/FunctionCall.java import com.iconmaster.source.compile.DataType; import java.util.ArrayList; package com.iconmaster.source.prototype; /** * * @author iconmaster */ public class FunctionCall { public String name;
public ArrayList<DataType> args;
kenwdelong/stability-utils
src/main/java/com/kendelong/util/spring/JmxExportingAspectPostProcessor.java
// Path: src/main/java/com/kendelong/util/monitoring/webservice/ExternalNameElementComputer.java // public class ExternalNameElementComputer // { // private final Logger logger = LoggerFactory.getLogger(this.getClass()); // // public String computeExternalNameElement(Class<?> clazz) // { // Class<?> correctClazz = findOriginalClass(clazz); // String nameElement = null; // if(correctClazz.isAnnotationPresent(WebServiceClient.class)) // { // nameElement = "client"; // } // if(correctClazz.isAnnotationPresent(WebServiceEndpoint.class)) // { // nameElement = "endpoint"; // } // // return nameElement; // } // // private Class<?> findOriginalClass(Class<?> clazz) // { // String className = clazz.getName(); // String newClassName = cleanClassName(className); // if(newClassName.equals(className)) // { // return clazz; // } // else // { // try // { // return clazz.getClassLoader().loadClass(newClassName); // } // catch(ClassNotFoundException e) // { // logger.warn("Class not found: [" + newClassName + "]"); // return clazz; // } // } // } // // String cleanClassName(String cn) // { // int index = cn.indexOf("$$EnhancerBySpring"); // if(index < 0) // { // return cn; // } // else // { // return cn.substring(0, index); // } // } // }
import java.util.Map; import javax.management.ObjectName; import org.aopalliance.aop.Advice; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.AbstractAspectJAdvice; import org.springframework.aop.framework.Advised; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.jmx.export.MBeanExportException; import org.springframework.jmx.export.MBeanExporter; import com.kendelong.util.monitoring.webservice.ExternalNameElementComputer;
package com.kendelong.util.spring; /** * This bean can export AspectJ-style aspects to JMX when registered. For example: * * <pre> * {@code <bean class="com.kendelong.util.circuitbreaker.CircuitBreakerAspect" scope="prototype"/> <bean class="com.kendelong.util.spring.JmxExportingAspectPostProcessor" lazy-init="false"> <property name="mbeanExporter" ref="mbeanExporter"/> <property name="annotationToServiceNames"> <map> <entry key="com.kendelong.util.circuitbreaker.CircuitBreakerAspect" value="circuitbreaker"/> </map> </property> <property name="jmxDomain" value="app.mystuff"/> </bean> } </pre> * * Important properties to set are the jmxDomain to use for the ONames of the MBeans, * and the value of the map which will be also used for the OName. OName structure is * jmxDomain:service=[map value],bean=[original advised bean name] * * @author Ken DeLong * */ public class JmxExportingAspectPostProcessor implements BeanPostProcessor { private MBeanExporter mbeanExporter; private Map<Class<?>, String> annotationToServiceNames; private String jmxDomain; private final Logger logger = LoggerFactory.getLogger(this.getClass());
// Path: src/main/java/com/kendelong/util/monitoring/webservice/ExternalNameElementComputer.java // public class ExternalNameElementComputer // { // private final Logger logger = LoggerFactory.getLogger(this.getClass()); // // public String computeExternalNameElement(Class<?> clazz) // { // Class<?> correctClazz = findOriginalClass(clazz); // String nameElement = null; // if(correctClazz.isAnnotationPresent(WebServiceClient.class)) // { // nameElement = "client"; // } // if(correctClazz.isAnnotationPresent(WebServiceEndpoint.class)) // { // nameElement = "endpoint"; // } // // return nameElement; // } // // private Class<?> findOriginalClass(Class<?> clazz) // { // String className = clazz.getName(); // String newClassName = cleanClassName(className); // if(newClassName.equals(className)) // { // return clazz; // } // else // { // try // { // return clazz.getClassLoader().loadClass(newClassName); // } // catch(ClassNotFoundException e) // { // logger.warn("Class not found: [" + newClassName + "]"); // return clazz; // } // } // } // // String cleanClassName(String cn) // { // int index = cn.indexOf("$$EnhancerBySpring"); // if(index < 0) // { // return cn; // } // else // { // return cn.substring(0, index); // } // } // } // Path: src/main/java/com/kendelong/util/spring/JmxExportingAspectPostProcessor.java import java.util.Map; import javax.management.ObjectName; import org.aopalliance.aop.Advice; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.AbstractAspectJAdvice; import org.springframework.aop.framework.Advised; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.jmx.export.MBeanExportException; import org.springframework.jmx.export.MBeanExporter; import com.kendelong.util.monitoring.webservice.ExternalNameElementComputer; package com.kendelong.util.spring; /** * This bean can export AspectJ-style aspects to JMX when registered. For example: * * <pre> * {@code <bean class="com.kendelong.util.circuitbreaker.CircuitBreakerAspect" scope="prototype"/> <bean class="com.kendelong.util.spring.JmxExportingAspectPostProcessor" lazy-init="false"> <property name="mbeanExporter" ref="mbeanExporter"/> <property name="annotationToServiceNames"> <map> <entry key="com.kendelong.util.circuitbreaker.CircuitBreakerAspect" value="circuitbreaker"/> </map> </property> <property name="jmxDomain" value="app.mystuff"/> </bean> } </pre> * * Important properties to set are the jmxDomain to use for the ONames of the MBeans, * and the value of the map which will be also used for the OName. OName structure is * jmxDomain:service=[map value],bean=[original advised bean name] * * @author Ken DeLong * */ public class JmxExportingAspectPostProcessor implements BeanPostProcessor { private MBeanExporter mbeanExporter; private Map<Class<?>, String> annotationToServiceNames; private String jmxDomain; private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final ExternalNameElementComputer nameElementComputer = new ExternalNameElementComputer();
PushOCCRP/Push-Android
app/src/main/java/com/pushapp/press/FragmentDrawer.java
// Path: app/src/main/java/com/pushapp/press/util/TypefaceManager.java // public class TypefaceManager { // private static final String ROBOTO_REGULAR = "Roboto-Regular.ttf"; // private static final String ROBOTO_MEDIUM = "Roboto-Medium.ttf"; // private static final String AMERICAN_TYPEWRITER = "AmericanTypewriter.ttf"; // private final LruCache<String, Typeface> mCache; // private final AssetManager mAssetManager; // // public TypefaceManager(AssetManager assetManager) { // mAssetManager = assetManager; // mCache = new LruCache<>(3); // } // // public Typeface getRobotoRegular() { // return getTypeface(ROBOTO_REGULAR); // } // // public Typeface getRobotoMedium() { // return getTypeface(ROBOTO_MEDIUM); // } // // public Typeface getAmericanTypewriter() { return getTypeface(AMERICAN_TYPEWRITER);} // // private Typeface getTypeface(final String filename) { // Typeface typeface = mCache.get(filename); // if (typeface == null) { // typeface = Typeface.createFromAsset(mAssetManager, "fonts/" + filename); // mCache.put(filename, typeface); // } // return typeface; // } // } // // Path: app/src/main/java/com/pushapp/press/adapter/NavigationDrawerAdapter.java // public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.MyViewHolder> { // List<NavDrawerItem> data = Collections.emptyList(); // private LayoutInflater inflater; // private Context context; // private int[] icons; // // public NavigationDrawerAdapter(Context context, List<NavDrawerItem> data) { // this.context = context; // inflater = LayoutInflater.from(context); // this.data = data; // icons = new int[]{ // R.mipmap.ic_home_black_24dp, // R.mipmap.dollar, // R.mipmap.about // }; // } // // public void delete(int position) { // data.remove(position); // notifyItemRemoved(position); // } // // @Override // public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View view = inflater.inflate(R.layout.nav_drawer_row, parent, false); // MyViewHolder holder = new MyViewHolder(view); // return holder; // } // // @Override // public void onBindViewHolder(MyViewHolder holder, int position) { // NavDrawerItem current = data.get(position); // holder.title.setText(current.getTitle()); // holder.mIcon.setImageResource(icons[position]); // } // // @Override // public int getItemCount() { // return data.size(); // } // // class MyViewHolder extends RecyclerView.ViewHolder { // // TextView title; // ImageView mIcon; // private boolean realColor; // // public MyViewHolder(View itemView) { // super(itemView); // title = (TextView) itemView.findViewById(R.id.section_text); // mIcon = (ImageView)itemView.findViewById(R.id.section_icon); // // // } // } // } // // Path: app/src/main/java/com/pushapp/press/model/NavDrawerItem.java // public class NavDrawerItem { // private boolean showNotify; // private String title; // private String iconID; // // public String getIconID() { // return iconID; // } // // public void setIconID(String iconID) { // this.iconID = iconID; // } // // public NavDrawerItem() { // // } // // public NavDrawerItem(boolean showNotify, String title,String iconID) { // this.showNotify = showNotify; // this.title = title; // this.iconID = iconID; // } // // public boolean isShowNotify() { // return showNotify; // } // // public void setShowNotify(boolean showNotify) { // this.showNotify = showNotify; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // }
import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.pushapp.press.util.TypefaceManager; import com.pushapp.press.adapter.NavigationDrawerAdapter; import com.pushapp.press.model.NavDrawerItem; import java.util.ArrayList; import java.util.List;
package com.pushapp.press; /** * @author Bryan Lamtoo */ public class FragmentDrawer extends Fragment { private static String TAG = FragmentDrawer.class.getSimpleName(); private RecyclerView recyclerView; private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout;
// Path: app/src/main/java/com/pushapp/press/util/TypefaceManager.java // public class TypefaceManager { // private static final String ROBOTO_REGULAR = "Roboto-Regular.ttf"; // private static final String ROBOTO_MEDIUM = "Roboto-Medium.ttf"; // private static final String AMERICAN_TYPEWRITER = "AmericanTypewriter.ttf"; // private final LruCache<String, Typeface> mCache; // private final AssetManager mAssetManager; // // public TypefaceManager(AssetManager assetManager) { // mAssetManager = assetManager; // mCache = new LruCache<>(3); // } // // public Typeface getRobotoRegular() { // return getTypeface(ROBOTO_REGULAR); // } // // public Typeface getRobotoMedium() { // return getTypeface(ROBOTO_MEDIUM); // } // // public Typeface getAmericanTypewriter() { return getTypeface(AMERICAN_TYPEWRITER);} // // private Typeface getTypeface(final String filename) { // Typeface typeface = mCache.get(filename); // if (typeface == null) { // typeface = Typeface.createFromAsset(mAssetManager, "fonts/" + filename); // mCache.put(filename, typeface); // } // return typeface; // } // } // // Path: app/src/main/java/com/pushapp/press/adapter/NavigationDrawerAdapter.java // public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.MyViewHolder> { // List<NavDrawerItem> data = Collections.emptyList(); // private LayoutInflater inflater; // private Context context; // private int[] icons; // // public NavigationDrawerAdapter(Context context, List<NavDrawerItem> data) { // this.context = context; // inflater = LayoutInflater.from(context); // this.data = data; // icons = new int[]{ // R.mipmap.ic_home_black_24dp, // R.mipmap.dollar, // R.mipmap.about // }; // } // // public void delete(int position) { // data.remove(position); // notifyItemRemoved(position); // } // // @Override // public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View view = inflater.inflate(R.layout.nav_drawer_row, parent, false); // MyViewHolder holder = new MyViewHolder(view); // return holder; // } // // @Override // public void onBindViewHolder(MyViewHolder holder, int position) { // NavDrawerItem current = data.get(position); // holder.title.setText(current.getTitle()); // holder.mIcon.setImageResource(icons[position]); // } // // @Override // public int getItemCount() { // return data.size(); // } // // class MyViewHolder extends RecyclerView.ViewHolder { // // TextView title; // ImageView mIcon; // private boolean realColor; // // public MyViewHolder(View itemView) { // super(itemView); // title = (TextView) itemView.findViewById(R.id.section_text); // mIcon = (ImageView)itemView.findViewById(R.id.section_icon); // // // } // } // } // // Path: app/src/main/java/com/pushapp/press/model/NavDrawerItem.java // public class NavDrawerItem { // private boolean showNotify; // private String title; // private String iconID; // // public String getIconID() { // return iconID; // } // // public void setIconID(String iconID) { // this.iconID = iconID; // } // // public NavDrawerItem() { // // } // // public NavDrawerItem(boolean showNotify, String title,String iconID) { // this.showNotify = showNotify; // this.title = title; // this.iconID = iconID; // } // // public boolean isShowNotify() { // return showNotify; // } // // public void setShowNotify(boolean showNotify) { // this.showNotify = showNotify; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // } // Path: app/src/main/java/com/pushapp/press/FragmentDrawer.java import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.pushapp.press.util.TypefaceManager; import com.pushapp.press.adapter.NavigationDrawerAdapter; import com.pushapp.press.model.NavDrawerItem; import java.util.ArrayList; import java.util.List; package com.pushapp.press; /** * @author Bryan Lamtoo */ public class FragmentDrawer extends Fragment { private static String TAG = FragmentDrawer.class.getSimpleName(); private RecyclerView recyclerView; private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout;
private NavigationDrawerAdapter adapter;
PushOCCRP/Push-Android
app/src/main/java/com/pushapp/press/FragmentDrawer.java
// Path: app/src/main/java/com/pushapp/press/util/TypefaceManager.java // public class TypefaceManager { // private static final String ROBOTO_REGULAR = "Roboto-Regular.ttf"; // private static final String ROBOTO_MEDIUM = "Roboto-Medium.ttf"; // private static final String AMERICAN_TYPEWRITER = "AmericanTypewriter.ttf"; // private final LruCache<String, Typeface> mCache; // private final AssetManager mAssetManager; // // public TypefaceManager(AssetManager assetManager) { // mAssetManager = assetManager; // mCache = new LruCache<>(3); // } // // public Typeface getRobotoRegular() { // return getTypeface(ROBOTO_REGULAR); // } // // public Typeface getRobotoMedium() { // return getTypeface(ROBOTO_MEDIUM); // } // // public Typeface getAmericanTypewriter() { return getTypeface(AMERICAN_TYPEWRITER);} // // private Typeface getTypeface(final String filename) { // Typeface typeface = mCache.get(filename); // if (typeface == null) { // typeface = Typeface.createFromAsset(mAssetManager, "fonts/" + filename); // mCache.put(filename, typeface); // } // return typeface; // } // } // // Path: app/src/main/java/com/pushapp/press/adapter/NavigationDrawerAdapter.java // public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.MyViewHolder> { // List<NavDrawerItem> data = Collections.emptyList(); // private LayoutInflater inflater; // private Context context; // private int[] icons; // // public NavigationDrawerAdapter(Context context, List<NavDrawerItem> data) { // this.context = context; // inflater = LayoutInflater.from(context); // this.data = data; // icons = new int[]{ // R.mipmap.ic_home_black_24dp, // R.mipmap.dollar, // R.mipmap.about // }; // } // // public void delete(int position) { // data.remove(position); // notifyItemRemoved(position); // } // // @Override // public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View view = inflater.inflate(R.layout.nav_drawer_row, parent, false); // MyViewHolder holder = new MyViewHolder(view); // return holder; // } // // @Override // public void onBindViewHolder(MyViewHolder holder, int position) { // NavDrawerItem current = data.get(position); // holder.title.setText(current.getTitle()); // holder.mIcon.setImageResource(icons[position]); // } // // @Override // public int getItemCount() { // return data.size(); // } // // class MyViewHolder extends RecyclerView.ViewHolder { // // TextView title; // ImageView mIcon; // private boolean realColor; // // public MyViewHolder(View itemView) { // super(itemView); // title = (TextView) itemView.findViewById(R.id.section_text); // mIcon = (ImageView)itemView.findViewById(R.id.section_icon); // // // } // } // } // // Path: app/src/main/java/com/pushapp/press/model/NavDrawerItem.java // public class NavDrawerItem { // private boolean showNotify; // private String title; // private String iconID; // // public String getIconID() { // return iconID; // } // // public void setIconID(String iconID) { // this.iconID = iconID; // } // // public NavDrawerItem() { // // } // // public NavDrawerItem(boolean showNotify, String title,String iconID) { // this.showNotify = showNotify; // this.title = title; // this.iconID = iconID; // } // // public boolean isShowNotify() { // return showNotify; // } // // public void setShowNotify(boolean showNotify) { // this.showNotify = showNotify; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // }
import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.pushapp.press.util.TypefaceManager; import com.pushapp.press.adapter.NavigationDrawerAdapter; import com.pushapp.press.model.NavDrawerItem; import java.util.ArrayList; import java.util.List;
package com.pushapp.press; /** * @author Bryan Lamtoo */ public class FragmentDrawer extends Fragment { private static String TAG = FragmentDrawer.class.getSimpleName(); private RecyclerView recyclerView; private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; private NavigationDrawerAdapter adapter; private View containerView; private static String[] titles = null; private static String[] icons = null; private FragmentDrawerListener drawerListener; public FragmentDrawer() { } public void setDrawerListener(FragmentDrawerListener listener) { this.drawerListener = listener; }
// Path: app/src/main/java/com/pushapp/press/util/TypefaceManager.java // public class TypefaceManager { // private static final String ROBOTO_REGULAR = "Roboto-Regular.ttf"; // private static final String ROBOTO_MEDIUM = "Roboto-Medium.ttf"; // private static final String AMERICAN_TYPEWRITER = "AmericanTypewriter.ttf"; // private final LruCache<String, Typeface> mCache; // private final AssetManager mAssetManager; // // public TypefaceManager(AssetManager assetManager) { // mAssetManager = assetManager; // mCache = new LruCache<>(3); // } // // public Typeface getRobotoRegular() { // return getTypeface(ROBOTO_REGULAR); // } // // public Typeface getRobotoMedium() { // return getTypeface(ROBOTO_MEDIUM); // } // // public Typeface getAmericanTypewriter() { return getTypeface(AMERICAN_TYPEWRITER);} // // private Typeface getTypeface(final String filename) { // Typeface typeface = mCache.get(filename); // if (typeface == null) { // typeface = Typeface.createFromAsset(mAssetManager, "fonts/" + filename); // mCache.put(filename, typeface); // } // return typeface; // } // } // // Path: app/src/main/java/com/pushapp/press/adapter/NavigationDrawerAdapter.java // public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.MyViewHolder> { // List<NavDrawerItem> data = Collections.emptyList(); // private LayoutInflater inflater; // private Context context; // private int[] icons; // // public NavigationDrawerAdapter(Context context, List<NavDrawerItem> data) { // this.context = context; // inflater = LayoutInflater.from(context); // this.data = data; // icons = new int[]{ // R.mipmap.ic_home_black_24dp, // R.mipmap.dollar, // R.mipmap.about // }; // } // // public void delete(int position) { // data.remove(position); // notifyItemRemoved(position); // } // // @Override // public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View view = inflater.inflate(R.layout.nav_drawer_row, parent, false); // MyViewHolder holder = new MyViewHolder(view); // return holder; // } // // @Override // public void onBindViewHolder(MyViewHolder holder, int position) { // NavDrawerItem current = data.get(position); // holder.title.setText(current.getTitle()); // holder.mIcon.setImageResource(icons[position]); // } // // @Override // public int getItemCount() { // return data.size(); // } // // class MyViewHolder extends RecyclerView.ViewHolder { // // TextView title; // ImageView mIcon; // private boolean realColor; // // public MyViewHolder(View itemView) { // super(itemView); // title = (TextView) itemView.findViewById(R.id.section_text); // mIcon = (ImageView)itemView.findViewById(R.id.section_icon); // // // } // } // } // // Path: app/src/main/java/com/pushapp/press/model/NavDrawerItem.java // public class NavDrawerItem { // private boolean showNotify; // private String title; // private String iconID; // // public String getIconID() { // return iconID; // } // // public void setIconID(String iconID) { // this.iconID = iconID; // } // // public NavDrawerItem() { // // } // // public NavDrawerItem(boolean showNotify, String title,String iconID) { // this.showNotify = showNotify; // this.title = title; // this.iconID = iconID; // } // // public boolean isShowNotify() { // return showNotify; // } // // public void setShowNotify(boolean showNotify) { // this.showNotify = showNotify; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // } // Path: app/src/main/java/com/pushapp/press/FragmentDrawer.java import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.pushapp.press.util.TypefaceManager; import com.pushapp.press.adapter.NavigationDrawerAdapter; import com.pushapp.press.model.NavDrawerItem; import java.util.ArrayList; import java.util.List; package com.pushapp.press; /** * @author Bryan Lamtoo */ public class FragmentDrawer extends Fragment { private static String TAG = FragmentDrawer.class.getSimpleName(); private RecyclerView recyclerView; private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; private NavigationDrawerAdapter adapter; private View containerView; private static String[] titles = null; private static String[] icons = null; private FragmentDrawerListener drawerListener; public FragmentDrawer() { } public void setDrawerListener(FragmentDrawerListener listener) { this.drawerListener = listener; }
public static List<NavDrawerItem> getData() {
PushOCCRP/Push-Android
app/src/main/java/com/pushapp/press/FragmentDrawer.java
// Path: app/src/main/java/com/pushapp/press/util/TypefaceManager.java // public class TypefaceManager { // private static final String ROBOTO_REGULAR = "Roboto-Regular.ttf"; // private static final String ROBOTO_MEDIUM = "Roboto-Medium.ttf"; // private static final String AMERICAN_TYPEWRITER = "AmericanTypewriter.ttf"; // private final LruCache<String, Typeface> mCache; // private final AssetManager mAssetManager; // // public TypefaceManager(AssetManager assetManager) { // mAssetManager = assetManager; // mCache = new LruCache<>(3); // } // // public Typeface getRobotoRegular() { // return getTypeface(ROBOTO_REGULAR); // } // // public Typeface getRobotoMedium() { // return getTypeface(ROBOTO_MEDIUM); // } // // public Typeface getAmericanTypewriter() { return getTypeface(AMERICAN_TYPEWRITER);} // // private Typeface getTypeface(final String filename) { // Typeface typeface = mCache.get(filename); // if (typeface == null) { // typeface = Typeface.createFromAsset(mAssetManager, "fonts/" + filename); // mCache.put(filename, typeface); // } // return typeface; // } // } // // Path: app/src/main/java/com/pushapp/press/adapter/NavigationDrawerAdapter.java // public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.MyViewHolder> { // List<NavDrawerItem> data = Collections.emptyList(); // private LayoutInflater inflater; // private Context context; // private int[] icons; // // public NavigationDrawerAdapter(Context context, List<NavDrawerItem> data) { // this.context = context; // inflater = LayoutInflater.from(context); // this.data = data; // icons = new int[]{ // R.mipmap.ic_home_black_24dp, // R.mipmap.dollar, // R.mipmap.about // }; // } // // public void delete(int position) { // data.remove(position); // notifyItemRemoved(position); // } // // @Override // public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View view = inflater.inflate(R.layout.nav_drawer_row, parent, false); // MyViewHolder holder = new MyViewHolder(view); // return holder; // } // // @Override // public void onBindViewHolder(MyViewHolder holder, int position) { // NavDrawerItem current = data.get(position); // holder.title.setText(current.getTitle()); // holder.mIcon.setImageResource(icons[position]); // } // // @Override // public int getItemCount() { // return data.size(); // } // // class MyViewHolder extends RecyclerView.ViewHolder { // // TextView title; // ImageView mIcon; // private boolean realColor; // // public MyViewHolder(View itemView) { // super(itemView); // title = (TextView) itemView.findViewById(R.id.section_text); // mIcon = (ImageView)itemView.findViewById(R.id.section_icon); // // // } // } // } // // Path: app/src/main/java/com/pushapp/press/model/NavDrawerItem.java // public class NavDrawerItem { // private boolean showNotify; // private String title; // private String iconID; // // public String getIconID() { // return iconID; // } // // public void setIconID(String iconID) { // this.iconID = iconID; // } // // public NavDrawerItem() { // // } // // public NavDrawerItem(boolean showNotify, String title,String iconID) { // this.showNotify = showNotify; // this.title = title; // this.iconID = iconID; // } // // public boolean isShowNotify() { // return showNotify; // } // // public void setShowNotify(boolean showNotify) { // this.showNotify = showNotify; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // }
import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.pushapp.press.util.TypefaceManager; import com.pushapp.press.adapter.NavigationDrawerAdapter; import com.pushapp.press.model.NavDrawerItem; import java.util.ArrayList; import java.util.List;
package com.pushapp.press; /** * @author Bryan Lamtoo */ public class FragmentDrawer extends Fragment { private static String TAG = FragmentDrawer.class.getSimpleName(); private RecyclerView recyclerView; private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; private NavigationDrawerAdapter adapter; private View containerView; private static String[] titles = null; private static String[] icons = null; private FragmentDrawerListener drawerListener; public FragmentDrawer() { } public void setDrawerListener(FragmentDrawerListener listener) { this.drawerListener = listener; } public static List<NavDrawerItem> getData() { List<NavDrawerItem> data = new ArrayList<>(); // preparing navigation drawer items for (int i = 0; i < titles.length; i++) { NavDrawerItem navItem = new NavDrawerItem(); navItem.setTitle(titles[i]); navItem.setIconID(icons[i]); data.add(navItem); } return data; } // resources private Resources resources;
// Path: app/src/main/java/com/pushapp/press/util/TypefaceManager.java // public class TypefaceManager { // private static final String ROBOTO_REGULAR = "Roboto-Regular.ttf"; // private static final String ROBOTO_MEDIUM = "Roboto-Medium.ttf"; // private static final String AMERICAN_TYPEWRITER = "AmericanTypewriter.ttf"; // private final LruCache<String, Typeface> mCache; // private final AssetManager mAssetManager; // // public TypefaceManager(AssetManager assetManager) { // mAssetManager = assetManager; // mCache = new LruCache<>(3); // } // // public Typeface getRobotoRegular() { // return getTypeface(ROBOTO_REGULAR); // } // // public Typeface getRobotoMedium() { // return getTypeface(ROBOTO_MEDIUM); // } // // public Typeface getAmericanTypewriter() { return getTypeface(AMERICAN_TYPEWRITER);} // // private Typeface getTypeface(final String filename) { // Typeface typeface = mCache.get(filename); // if (typeface == null) { // typeface = Typeface.createFromAsset(mAssetManager, "fonts/" + filename); // mCache.put(filename, typeface); // } // return typeface; // } // } // // Path: app/src/main/java/com/pushapp/press/adapter/NavigationDrawerAdapter.java // public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.MyViewHolder> { // List<NavDrawerItem> data = Collections.emptyList(); // private LayoutInflater inflater; // private Context context; // private int[] icons; // // public NavigationDrawerAdapter(Context context, List<NavDrawerItem> data) { // this.context = context; // inflater = LayoutInflater.from(context); // this.data = data; // icons = new int[]{ // R.mipmap.ic_home_black_24dp, // R.mipmap.dollar, // R.mipmap.about // }; // } // // public void delete(int position) { // data.remove(position); // notifyItemRemoved(position); // } // // @Override // public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View view = inflater.inflate(R.layout.nav_drawer_row, parent, false); // MyViewHolder holder = new MyViewHolder(view); // return holder; // } // // @Override // public void onBindViewHolder(MyViewHolder holder, int position) { // NavDrawerItem current = data.get(position); // holder.title.setText(current.getTitle()); // holder.mIcon.setImageResource(icons[position]); // } // // @Override // public int getItemCount() { // return data.size(); // } // // class MyViewHolder extends RecyclerView.ViewHolder { // // TextView title; // ImageView mIcon; // private boolean realColor; // // public MyViewHolder(View itemView) { // super(itemView); // title = (TextView) itemView.findViewById(R.id.section_text); // mIcon = (ImageView)itemView.findViewById(R.id.section_icon); // // // } // } // } // // Path: app/src/main/java/com/pushapp/press/model/NavDrawerItem.java // public class NavDrawerItem { // private boolean showNotify; // private String title; // private String iconID; // // public String getIconID() { // return iconID; // } // // public void setIconID(String iconID) { // this.iconID = iconID; // } // // public NavDrawerItem() { // // } // // public NavDrawerItem(boolean showNotify, String title,String iconID) { // this.showNotify = showNotify; // this.title = title; // this.iconID = iconID; // } // // public boolean isShowNotify() { // return showNotify; // } // // public void setShowNotify(boolean showNotify) { // this.showNotify = showNotify; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // } // Path: app/src/main/java/com/pushapp/press/FragmentDrawer.java import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.pushapp.press.util.TypefaceManager; import com.pushapp.press.adapter.NavigationDrawerAdapter; import com.pushapp.press.model.NavDrawerItem; import java.util.ArrayList; import java.util.List; package com.pushapp.press; /** * @author Bryan Lamtoo */ public class FragmentDrawer extends Fragment { private static String TAG = FragmentDrawer.class.getSimpleName(); private RecyclerView recyclerView; private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; private NavigationDrawerAdapter adapter; private View containerView; private static String[] titles = null; private static String[] icons = null; private FragmentDrawerListener drawerListener; public FragmentDrawer() { } public void setDrawerListener(FragmentDrawerListener listener) { this.drawerListener = listener; } public static List<NavDrawerItem> getData() { List<NavDrawerItem> data = new ArrayList<>(); // preparing navigation drawer items for (int i = 0; i < titles.length; i++) { NavDrawerItem navItem = new NavDrawerItem(); navItem.setTitle(titles[i]); navItem.setIconID(icons[i]); data.add(navItem); } return data; } // resources private Resources resources;
private TypefaceManager fontManager;
PushOCCRP/Push-Android
app/src/main/java/com/pushapp/press/util/ObjectSerializer.java
// Path: app/src/main/java/com/pushapp/press/model/WrappedIOException.java // public class WrappedIOException { // public static IOException wrap(final Throwable e) { // return wrap(e.getMessage(), e); // } // // public static IOException wrap(final String message, final Throwable e) { // final IOException wrappedException = new IOException(message + " [" + // e.getMessage() + "]"); // wrappedException.setStackTrace(e.getStackTrace()); // wrappedException.initCause(e); // return wrappedException; // } // }
import com.pushapp.press.model.WrappedIOException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable;
package com.pushapp.press.util; /** * @author Bryan Lamtoo. */ public class ObjectSerializer { public static String serialize(Serializable obj) throws IOException { if (obj == null) return ""; try { ByteArrayOutputStream serialObj = new ByteArrayOutputStream(); ObjectOutputStream objStream = new ObjectOutputStream(serialObj); objStream.writeObject(obj); objStream.close(); return encodeBytes(serialObj.toByteArray()); } catch (Exception e) {
// Path: app/src/main/java/com/pushapp/press/model/WrappedIOException.java // public class WrappedIOException { // public static IOException wrap(final Throwable e) { // return wrap(e.getMessage(), e); // } // // public static IOException wrap(final String message, final Throwable e) { // final IOException wrappedException = new IOException(message + " [" + // e.getMessage() + "]"); // wrappedException.setStackTrace(e.getStackTrace()); // wrappedException.initCause(e); // return wrappedException; // } // } // Path: app/src/main/java/com/pushapp/press/util/ObjectSerializer.java import com.pushapp.press.model.WrappedIOException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; package com.pushapp.press.util; /** * @author Bryan Lamtoo. */ public class ObjectSerializer { public static String serialize(Serializable obj) throws IOException { if (obj == null) return ""; try { ByteArrayOutputStream serialObj = new ByteArrayOutputStream(); ObjectOutputStream objStream = new ObjectOutputStream(serialObj); objStream.writeObject(obj); objStream.close(); return encodeBytes(serialObj.toByteArray()); } catch (Exception e) {
throw WrappedIOException.wrap("Serialization error: " + e.getMessage(), e);
PushOCCRP/Push-Android
app/src/androidTest/java/com/pushapp/press/BasicTest.java
// Path: app/src/androidTest/java/com/pushapp/press/ElapsedTimeIdlingResource.java // public class ElapsedTimeIdlingResource implements IdlingResource { // private final long startTime; // private final long waitingTime; // private ResourceCallback resourceCallback; // // public ElapsedTimeIdlingResource(long waitingTime) { // this.startTime = System.currentTimeMillis(); // this.waitingTime = waitingTime; // } // // @Override // public String getName() { // return ElapsedTimeIdlingResource.class.getName() + ":" + waitingTime; // } // // @Override // public boolean isIdleNow() { // long elapsed = System.currentTimeMillis() - startTime; // boolean idle = (elapsed >= waitingTime); // if (idle) { // resourceCallback.onTransitionToIdle(); // } // return idle; // } // // @Override // public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { // this.resourceCallback = resourceCallback; // } // } // // Path: app/src/androidTest/java/com/pushapp/press/ScreengrabHelper.java // public class ScreengrabHelper { // // private static ScreengrabHelper instance; // private static final long INIT_DELAY = 2000; // // private long delay; // private boolean screenShotTaken; // // public ScreengrabHelper() { // this.delay = INIT_DELAY; // } // // public static void delayScreenshot(String name) { // ensureInstance(); // instance.takeDelayScreenshot(name); // } // // private static void ensureInstance() { // if (instance == null) { // instance = new ScreengrabHelper(); // } // } // // private void takeDelayScreenshot(String name) { // screenShotTaken = false; // // new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { // @Override // public void run() { // screenShotTaken = true; // } // }, delay); // // new Wait(new Wait.Condition() { // @Override // public boolean check() { // return screenShotTaken; // } // }).waitForIt(); // // Screengrab.screenshot(name); // } // // public static void setDelay(long delay) { // ensureInstance(); // instance.changeDelay(delay); // } // // public void changeDelay(long delay) { // this.delay = delay; // } // }
import android.support.test.espresso.Espresso; import android.support.test.espresso.IdlingPolicies; import android.support.test.espresso.IdlingResource; import android.support.test.espresso.PerformException; import android.support.test.espresso.UiController; import android.support.test.espresso.ViewAction; import android.support.test.espresso.action.ViewActions; import android.support.test.espresso.matcher.ViewMatchers; import android.support.test.espresso.util.HumanReadables; import android.support.test.espresso.util.TreeIterables; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.view.View; import com.pushapp.press.ElapsedTimeIdlingResource; import org.hamcrest.Matcher; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.matcher.ViewMatchers.withId; import com.pushapp.press.ScreengrabHelper; import java.util.concurrent.TimeUnit;
package com.pushapp.press; //import tools.fastlane.screengrab.Screengrab; //import tools.fastlane.screengrab.locale.LocaleTestRule; @RunWith(AndroidJUnit4.class) public class BasicTest { // @ClassRule // public static final TestRule classRule = new LocaleTestRule(); @Rule public final ActivityTestRule<HomeActivity> activityTestRule = new ActivityTestRule<>(HomeActivity.class); @Test public void takeScreenshot() throws Exception { //onView(withId(R.id.mHomeLayout)).perform(ViewActions.swipeDown()); //onView(withId(R.id.mHomeLayout)) // .perform(withCustomConstraints(ViewActions.swipeDown(), ViewMatchers.isDisplayingAtLeast(10))); // // Make sure Espresso does not time out int waitingTime = 10000; IdlingPolicies.setMasterPolicyTimeout(waitingTime * 2, TimeUnit.MILLISECONDS); IdlingPolicies.setIdlingResourceTimeout(waitingTime * 2, TimeUnit.MILLISECONDS); // Now we wait
// Path: app/src/androidTest/java/com/pushapp/press/ElapsedTimeIdlingResource.java // public class ElapsedTimeIdlingResource implements IdlingResource { // private final long startTime; // private final long waitingTime; // private ResourceCallback resourceCallback; // // public ElapsedTimeIdlingResource(long waitingTime) { // this.startTime = System.currentTimeMillis(); // this.waitingTime = waitingTime; // } // // @Override // public String getName() { // return ElapsedTimeIdlingResource.class.getName() + ":" + waitingTime; // } // // @Override // public boolean isIdleNow() { // long elapsed = System.currentTimeMillis() - startTime; // boolean idle = (elapsed >= waitingTime); // if (idle) { // resourceCallback.onTransitionToIdle(); // } // return idle; // } // // @Override // public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { // this.resourceCallback = resourceCallback; // } // } // // Path: app/src/androidTest/java/com/pushapp/press/ScreengrabHelper.java // public class ScreengrabHelper { // // private static ScreengrabHelper instance; // private static final long INIT_DELAY = 2000; // // private long delay; // private boolean screenShotTaken; // // public ScreengrabHelper() { // this.delay = INIT_DELAY; // } // // public static void delayScreenshot(String name) { // ensureInstance(); // instance.takeDelayScreenshot(name); // } // // private static void ensureInstance() { // if (instance == null) { // instance = new ScreengrabHelper(); // } // } // // private void takeDelayScreenshot(String name) { // screenShotTaken = false; // // new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { // @Override // public void run() { // screenShotTaken = true; // } // }, delay); // // new Wait(new Wait.Condition() { // @Override // public boolean check() { // return screenShotTaken; // } // }).waitForIt(); // // Screengrab.screenshot(name); // } // // public static void setDelay(long delay) { // ensureInstance(); // instance.changeDelay(delay); // } // // public void changeDelay(long delay) { // this.delay = delay; // } // } // Path: app/src/androidTest/java/com/pushapp/press/BasicTest.java import android.support.test.espresso.Espresso; import android.support.test.espresso.IdlingPolicies; import android.support.test.espresso.IdlingResource; import android.support.test.espresso.PerformException; import android.support.test.espresso.UiController; import android.support.test.espresso.ViewAction; import android.support.test.espresso.action.ViewActions; import android.support.test.espresso.matcher.ViewMatchers; import android.support.test.espresso.util.HumanReadables; import android.support.test.espresso.util.TreeIterables; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.view.View; import com.pushapp.press.ElapsedTimeIdlingResource; import org.hamcrest.Matcher; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.matcher.ViewMatchers.withId; import com.pushapp.press.ScreengrabHelper; import java.util.concurrent.TimeUnit; package com.pushapp.press; //import tools.fastlane.screengrab.Screengrab; //import tools.fastlane.screengrab.locale.LocaleTestRule; @RunWith(AndroidJUnit4.class) public class BasicTest { // @ClassRule // public static final TestRule classRule = new LocaleTestRule(); @Rule public final ActivityTestRule<HomeActivity> activityTestRule = new ActivityTestRule<>(HomeActivity.class); @Test public void takeScreenshot() throws Exception { //onView(withId(R.id.mHomeLayout)).perform(ViewActions.swipeDown()); //onView(withId(R.id.mHomeLayout)) // .perform(withCustomConstraints(ViewActions.swipeDown(), ViewMatchers.isDisplayingAtLeast(10))); // // Make sure Espresso does not time out int waitingTime = 10000; IdlingPolicies.setMasterPolicyTimeout(waitingTime * 2, TimeUnit.MILLISECONDS); IdlingPolicies.setIdlingResourceTimeout(waitingTime * 2, TimeUnit.MILLISECONDS); // Now we wait
IdlingResource idlingResource = new ElapsedTimeIdlingResource(waitingTime);
PushOCCRP/Push-Android
app/src/main/java/com/pushapp/press/util/AuthenticationManager.java
// Path: app/src/main/java/com/pushapp/press/interfaces/AuthenticationManager/AuthenticationDelegate.java // public interface AuthenticationDelegate { // void didLoginSuccessfully(); // void didReceiveErrorOnLogin(); // } // // Path: app/src/main/java/com/pushapp/press/interfaces/RestApi.java // public interface RestApi { // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, Callback<ArticlePost> response, @Query("categories")boolean categories); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("language")String language, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("language")String language, @Query("categories")boolean categories, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("categories")boolean categories, @Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size, @Query("language")String language ,Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("categories")boolean categories,@Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size, @Query("language")String language ,Callback<ArticlePost> response); // // @GET("/search.json") // void searchArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("q")String query,@Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size,Callback<ArticlePost> response); // // @GET("/search.json") // void searchArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("q")String query,@Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size,@Query("language")String language,Callback<ArticlePost> response); // // @GET("/article.json") // void getArticle(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("id")String id, Callback<ArticlePost> response); // // @GET("/article.json") // void getArticle(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("id")String id,@Query("language")String language, Callback<ArticlePost> response); // // @POST("/authenticate") // void login(@Body()HashMap body, Callback<LoginRequest> response); // //void login(@Query("installation_uuid")String installation_uuid, @Query("language")String language, @Query("username")String username, @Query("password")String password, Callback<LoginRequest> response); // } // // Path: app/src/main/java/com/pushapp/press/model/LoginRequest.java // public class LoginRequest implements Serializable { // @SerializedName("code") // @Expose // private Integer code; // @SerializedName("status") // @Expose // private String status; // @SerializedName("api_key") // @Expose // private String apiKey; // @SerializedName("username") // @Expose // private String username; // // /** // * // * @return // * The code // */ // public Integer getCode() { // return code; // } // // /** // * // * @return // * The status // */ // public String getStatus() { // return status; // } // // /** // * // * @return // * The status // */ // public String getApiKey() { // return apiKey; // } // // /** // * // * @return // * The status // */ // public String getUsername() { // return username; // } // // }
import android.content.Context; import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; import com.pushapp.press.R; import com.pushapp.press.interfaces.AuthenticationManager.AuthenticationDelegate; import com.pushapp.press.interfaces.RestApi; import com.pushapp.press.model.LoginRequest; import com.google.gson.Gson; import com.google.gson.JsonElement; import java.util.HashMap; import java.util.Locale; import retrofit.Callback; import retrofit.RequestInterceptor; import retrofit.RestAdapter; import retrofit.RetrofitError; import retrofit.client.Response;
package com.pushapp.press.util; public class AuthenticationManager { public static AuthenticationManager authenticationManager; private Context applicationContext;
// Path: app/src/main/java/com/pushapp/press/interfaces/AuthenticationManager/AuthenticationDelegate.java // public interface AuthenticationDelegate { // void didLoginSuccessfully(); // void didReceiveErrorOnLogin(); // } // // Path: app/src/main/java/com/pushapp/press/interfaces/RestApi.java // public interface RestApi { // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, Callback<ArticlePost> response, @Query("categories")boolean categories); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("language")String language, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("language")String language, @Query("categories")boolean categories, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("categories")boolean categories, @Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size, Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size, @Query("language")String language ,Callback<ArticlePost> response); // // @GET("/articles.json") // void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("categories")boolean categories,@Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size, @Query("language")String language ,Callback<ArticlePost> response); // // @GET("/search.json") // void searchArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("q")String query,@Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size,Callback<ArticlePost> response); // // @GET("/search.json") // void searchArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("q")String query,@Query("start_date")long start_date,@Query("end_date")long end_date,@Query("pages")int pages,@Query("page_size")int page_size,@Query("language")String language,Callback<ArticlePost> response); // // @GET("/article.json") // void getArticle(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("id")String id, Callback<ArticlePost> response); // // @GET("/article.json") // void getArticle(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, @Query("id")String id,@Query("language")String language, Callback<ArticlePost> response); // // @POST("/authenticate") // void login(@Body()HashMap body, Callback<LoginRequest> response); // //void login(@Query("installation_uuid")String installation_uuid, @Query("language")String language, @Query("username")String username, @Query("password")String password, Callback<LoginRequest> response); // } // // Path: app/src/main/java/com/pushapp/press/model/LoginRequest.java // public class LoginRequest implements Serializable { // @SerializedName("code") // @Expose // private Integer code; // @SerializedName("status") // @Expose // private String status; // @SerializedName("api_key") // @Expose // private String apiKey; // @SerializedName("username") // @Expose // private String username; // // /** // * // * @return // * The code // */ // public Integer getCode() { // return code; // } // // /** // * // * @return // * The status // */ // public String getStatus() { // return status; // } // // /** // * // * @return // * The status // */ // public String getApiKey() { // return apiKey; // } // // /** // * // * @return // * The status // */ // public String getUsername() { // return username; // } // // } // Path: app/src/main/java/com/pushapp/press/util/AuthenticationManager.java import android.content.Context; import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; import com.pushapp.press.R; import com.pushapp.press.interfaces.AuthenticationManager.AuthenticationDelegate; import com.pushapp.press.interfaces.RestApi; import com.pushapp.press.model.LoginRequest; import com.google.gson.Gson; import com.google.gson.JsonElement; import java.util.HashMap; import java.util.Locale; import retrofit.Callback; import retrofit.RequestInterceptor; import retrofit.RestAdapter; import retrofit.RetrofitError; import retrofit.client.Response; package com.pushapp.press.util; public class AuthenticationManager { public static AuthenticationManager authenticationManager; private Context applicationContext;
private RestApi restAPI;
PushOCCRP/Push-Android
app/src/main/java/com/pushapp/press/fragment/YouTubeFragment.java
// Path: app/src/main/java/com/pushapp/press/interfaces/YouTubeFragmentInterface.java // public interface YouTubeFragmentInterface { // String getYouTubeVideoId(); // }
import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.google.android.youtube.player.YouTubeInitializationResult; import com.google.android.youtube.player.YouTubePlayer; import com.google.android.youtube.player.YouTubePlayerFragment; import com.pushapp.press.R; import com.pushapp.press.interfaces.YouTubeFragmentInterface;
package com.pushapp.press.fragment; /** * Created by christopher on 1/8/16. */ public class YouTubeFragment extends Fragment { private static YouTubePlayer mYoutubePlayer; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Path: app/src/main/java/com/pushapp/press/interfaces/YouTubeFragmentInterface.java // public interface YouTubeFragmentInterface { // String getYouTubeVideoId(); // } // Path: app/src/main/java/com/pushapp/press/fragment/YouTubeFragment.java import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.google.android.youtube.player.YouTubeInitializationResult; import com.google.android.youtube.player.YouTubePlayer; import com.google.android.youtube.player.YouTubePlayerFragment; import com.pushapp.press.R; import com.pushapp.press.interfaces.YouTubeFragmentInterface; package com.pushapp.press.fragment; /** * Created by christopher on 1/8/16. */ public class YouTubeFragment extends Fragment { private static YouTubePlayer mYoutubePlayer; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
YouTubeFragmentInterface parentActivity = (YouTubeFragmentInterface)getActivity();
PushOCCRP/Push-Android
app/src/main/java/com/pushapp/press/interfaces/RestApi.java
// Path: app/src/main/java/com/pushapp/press/model/ArticlePost.java // public class ArticlePost implements Serializable { // // @SerializedName("start_date") // @Expose // private Integer startDate; // @SerializedName("end_date") // @Expose // private Integer endDate; // @SerializedName("total_results") // @Expose // private Integer totalResults = 0; // @SerializedName("total_pages") // @Expose // private Integer totalPages; // @Expose // private Integer page; // @Expose // private Object results = new Object(); // // @Expose // private ArrayList<String> categories; // // /** // * // * @return // * The startDate // */ // public Integer getStartDate() { // return startDate; // } // // /** // * // * @param startDate // * The start_date // */ // public void setStartDate(Integer startDate) { // this.startDate = startDate; // } // // /** // * // * @return // * The endDate // */ // public Integer getEndDate() { // return endDate; // } // // /** // * // * @param endDate // * The end_date // */ // public void setEndDate(Integer endDate) { // this.endDate = endDate; // } // // /** // * // * @return // * The totalResults // */ // public Integer getTotalResults() { // return totalResults; // } // // /** // * // * @param totalResults // * The total_results // */ // public void setTotalResults(Integer totalResults) { // this.totalResults = totalResults; // } // // /** // * // * @return // * The totalPages // */ // public Integer getTotalPages() { // return totalPages; // } // // /** // * // * @param totalPages // * The total_pages // */ // public void setTotalPages(Integer totalPages) { // this.totalPages = totalPages; // } // // /** // * // * @return // * The page // */ // public Integer getPage() { // return page; // } // // /** // * // * @param page // * The page // */ // public void setPage(Integer page) { // this.page = page; // } // // /** // * // * @return // * The results // */ // public Object getResults(){ // return results; // } // // /** // * // * @param results // * The results // */ // public void setResults(Object results) { // this.results = results; // } // // /** // * // * @return // * The categories // */ // public ArrayList<String> getCategories(){ // return categories; // } // // /** // * // * @param categories // * The results // */ // public void setCategories(ArrayList<String> categories) { // this.categories = categories; // } // // } // // Path: app/src/main/java/com/pushapp/press/model/LoginRequest.java // public class LoginRequest implements Serializable { // @SerializedName("code") // @Expose // private Integer code; // @SerializedName("status") // @Expose // private String status; // @SerializedName("api_key") // @Expose // private String apiKey; // @SerializedName("username") // @Expose // private String username; // // /** // * // * @return // * The code // */ // public Integer getCode() { // return code; // } // // /** // * // * @return // * The status // */ // public String getStatus() { // return status; // } // // /** // * // * @return // * The status // */ // public String getApiKey() { // return apiKey; // } // // /** // * // * @return // * The status // */ // public String getUsername() { // return username; // } // // }
import com.pushapp.press.model.ArticlePost; import com.pushapp.press.model.LoginRequest; import java.util.HashMap; import retrofit.Callback; import retrofit.http.Body; import retrofit.http.GET; import retrofit.http.POST; import retrofit.http.Query;
package com.pushapp.press.interfaces; /** * @author Bryan Lamtoo. */ public interface RestApi { @GET("/articles.json")
// Path: app/src/main/java/com/pushapp/press/model/ArticlePost.java // public class ArticlePost implements Serializable { // // @SerializedName("start_date") // @Expose // private Integer startDate; // @SerializedName("end_date") // @Expose // private Integer endDate; // @SerializedName("total_results") // @Expose // private Integer totalResults = 0; // @SerializedName("total_pages") // @Expose // private Integer totalPages; // @Expose // private Integer page; // @Expose // private Object results = new Object(); // // @Expose // private ArrayList<String> categories; // // /** // * // * @return // * The startDate // */ // public Integer getStartDate() { // return startDate; // } // // /** // * // * @param startDate // * The start_date // */ // public void setStartDate(Integer startDate) { // this.startDate = startDate; // } // // /** // * // * @return // * The endDate // */ // public Integer getEndDate() { // return endDate; // } // // /** // * // * @param endDate // * The end_date // */ // public void setEndDate(Integer endDate) { // this.endDate = endDate; // } // // /** // * // * @return // * The totalResults // */ // public Integer getTotalResults() { // return totalResults; // } // // /** // * // * @param totalResults // * The total_results // */ // public void setTotalResults(Integer totalResults) { // this.totalResults = totalResults; // } // // /** // * // * @return // * The totalPages // */ // public Integer getTotalPages() { // return totalPages; // } // // /** // * // * @param totalPages // * The total_pages // */ // public void setTotalPages(Integer totalPages) { // this.totalPages = totalPages; // } // // /** // * // * @return // * The page // */ // public Integer getPage() { // return page; // } // // /** // * // * @param page // * The page // */ // public void setPage(Integer page) { // this.page = page; // } // // /** // * // * @return // * The results // */ // public Object getResults(){ // return results; // } // // /** // * // * @param results // * The results // */ // public void setResults(Object results) { // this.results = results; // } // // /** // * // * @return // * The categories // */ // public ArrayList<String> getCategories(){ // return categories; // } // // /** // * // * @param categories // * The results // */ // public void setCategories(ArrayList<String> categories) { // this.categories = categories; // } // // } // // Path: app/src/main/java/com/pushapp/press/model/LoginRequest.java // public class LoginRequest implements Serializable { // @SerializedName("code") // @Expose // private Integer code; // @SerializedName("status") // @Expose // private String status; // @SerializedName("api_key") // @Expose // private String apiKey; // @SerializedName("username") // @Expose // private String username; // // /** // * // * @return // * The code // */ // public Integer getCode() { // return code; // } // // /** // * // * @return // * The status // */ // public String getStatus() { // return status; // } // // /** // * // * @return // * The status // */ // public String getApiKey() { // return apiKey; // } // // /** // * // * @return // * The status // */ // public String getUsername() { // return username; // } // // } // Path: app/src/main/java/com/pushapp/press/interfaces/RestApi.java import com.pushapp.press.model.ArticlePost; import com.pushapp.press.model.LoginRequest; import java.util.HashMap; import retrofit.Callback; import retrofit.http.Body; import retrofit.http.GET; import retrofit.http.POST; import retrofit.http.Query; package com.pushapp.press.interfaces; /** * @author Bryan Lamtoo. */ public interface RestApi { @GET("/articles.json")
void getArticles(@Query("installation_uuid")String installation_uuid, @Query("api_key")String api_key, Callback<ArticlePost> response);
PushOCCRP/Push-Android
app/src/main/java/com/pushapp/press/fragment/DonationSummary.java
// Path: app/src/main/java/com/pushapp/press/interfaces/OnFragmentInteractionListener.java // public interface OnFragmentInteractionListener { // void onFragmentInteraction(Uri id); // void onFragmentInteraction(String id); // }
import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.androidquery.AQuery; import com.pushapp.press.interfaces.OnFragmentInteractionListener; import com.pushapp.press.R;
package com.pushapp.press.fragment; /** * Created by Zed on 6/15/2015. */ public class DonationSummary extends Fragment { AQuery aq;
// Path: app/src/main/java/com/pushapp/press/interfaces/OnFragmentInteractionListener.java // public interface OnFragmentInteractionListener { // void onFragmentInteraction(Uri id); // void onFragmentInteraction(String id); // } // Path: app/src/main/java/com/pushapp/press/fragment/DonationSummary.java import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.androidquery.AQuery; import com.pushapp.press.interfaces.OnFragmentInteractionListener; import com.pushapp.press.R; package com.pushapp.press.fragment; /** * Created by Zed on 6/15/2015. */ public class DonationSummary extends Fragment { AQuery aq;
private OnFragmentInteractionListener mListener;
PushOCCRP/Push-Android
app/src/main/java/com/pushapp/press/fragment/DonatePage.java
// Path: app/src/main/java/com/pushapp/press/interfaces/OnFragmentInteractionListener.java // public interface OnFragmentInteractionListener { // void onFragmentInteraction(Uri id); // void onFragmentInteraction(String id); // }
import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.Toast; import com.androidquery.AQuery; import com.pushapp.press.R; import com.pushapp.press.interfaces.OnFragmentInteractionListener; import java.text.DecimalFormat;
package com.pushapp.press.fragment; /** * A simple {@link Fragment} subclass. * Activities that contain this fragment must implement the * {@link OnFragmentInteractionListener} interface * to handle interaction events. * Use the {@link DonatePage#newInstance} factory method to * create an instance of this fragment. */ public class DonatePage extends Fragment { // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters private String mParam1; private String mParam2; AQuery aq;
// Path: app/src/main/java/com/pushapp/press/interfaces/OnFragmentInteractionListener.java // public interface OnFragmentInteractionListener { // void onFragmentInteraction(Uri id); // void onFragmentInteraction(String id); // } // Path: app/src/main/java/com/pushapp/press/fragment/DonatePage.java import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.Toast; import com.androidquery.AQuery; import com.pushapp.press.R; import com.pushapp.press.interfaces.OnFragmentInteractionListener; import java.text.DecimalFormat; package com.pushapp.press.fragment; /** * A simple {@link Fragment} subclass. * Activities that contain this fragment must implement the * {@link OnFragmentInteractionListener} interface * to handle interaction events. * Use the {@link DonatePage#newInstance} factory method to * create an instance of this fragment. */ public class DonatePage extends Fragment { // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; // TODO: Rename and change types of parameters private String mParam1; private String mParam2; AQuery aq;
private OnFragmentInteractionListener mListener;
katjas/PDFrenderer
src/com/sun/pdfview/font/ttf/CmapTable.java
// Path: src/com/sun/pdfview/PDFDebugger.java // public class PDFDebugger { // public final static String DEBUG_DCTDECODE_DATA = "debugdctdecode"; // public static final boolean DEBUG_TEXT = false; // public static final boolean DEBUG_IMAGES = false; // public static final boolean DEBUG_OPERATORS = false; // public static final boolean DEBUG_PATH = false; // public static final int DEBUG_STOP_AT_INDEX = 0; // public static final boolean DISABLE_TEXT = false; // public static final boolean DISABLE_IMAGES = false; // public static final boolean DISABLE_PATH_STROKE = false; // public static final boolean DISABLE_PATH_FILL = false; // public static final boolean DISABLE_PATH_STROKE_FILL = false; // public static final boolean DISABLE_CLIP = false; // public static final boolean DISABLE_FORMS = false; // public static final boolean DISABLE_SHADER = false; // public static final boolean SHOW_TEXT_REGIONS = false; // public static final boolean SHOW_TEXT_ANCHOR = false; // public static final boolean DISABLE_THUMBNAILS = false; // public static final long DRAW_DELAY = 0; // // public static int debuglevel = 4000; // // @SuppressWarnings("serial") // public static class DebugStopException extends Exception { // // nothing to do // } // // public static void debugImage(BufferedImage image, String name) { // if (PDFDebugger.DEBUG_IMAGES) { // if(image == null) { // return; // } // try { // // retrieve image // File outputfile = new File("D:/tmp/PDFimages/" + name + ".png"); // ImageIO.write(image, "png", outputfile); // } catch (IOException e) { // BaseWatchable.getErrorHandler().publishException(e); // } // } // } // // // TODO: add debug level and print it? // public static void debug(String msg, int level) { // if (level > debuglevel) { // System.out.println(escape(msg)); // } // } // // // TODO: add debug level and print it? // public static void debug(String msg) { // debug(msg, debuglevel); // } // // public static String escape(String msg) { // StringBuffer sb = new StringBuffer(); // for (int i = 0; i < msg.length(); i++) { // char c = msg.charAt(i); // if (c != '\n' && (c < 32 || c >= 127)) { // c = '?'; // } // sb.append(c); // } // return sb.toString(); // } // // public static void setDebugLevel(int level) { // debuglevel = level; // } // // // public static String dumpStream(byte[] stream) { // return PDFDebugger.escape(new String(stream).replace('\r', '\n')); // } // // public static void logPath(GeneralPath path, String operation) { // if (PDFDebugger.DEBUG_PATH){ // if (operation != null) { // System.out.println("Operation: " + operation + "; "); // } // System.out.println("Current path: "); // Rectangle b = path.getBounds(); // if (b != null) // System.out.println(" Bounds [x=" + b.x + ",y=" + b.y + ",width=" + b.width + ",height=" + b.height + "]"); // Point2D p = path.getCurrentPoint(); // if (p != null) // System.out.println(" Point [x=" + p.getX() + ",y=" + p.getY() + "]"); // } // } // // /** // * take a byte array and write a temporary file with it's data. // * This is intended to capture data for analysis, like after decoders. // * // * @param ary // * @param name // */ // public static void emitDataFile(byte[] ary, String name) { // FileOutputStream ostr; // try { // File file = File.createTempFile("DateFile", name); // ostr = new FileOutputStream(file); // PDFDebugger.debug("Write: " + file.getPath()); // ostr.write(ary); // ostr.close(); // } catch (IOException ex) { // // ignore // } // } // // public static void dump(PDFObject obj) throws IOException { // PDFDebugger.debug("dumping PDF object: " + obj); // if (obj == null) { // return; // } // HashMap<String, PDFObject> dict = obj.getDictionary(); // PDFDebugger.debug(" dict = " + dict); // for (Object key : dict.keySet()) { // PDFDebugger.debug("key = " + key + " value = " + dict.get(key)); // } // } // // }
import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.SortedMap; import java.util.TreeMap; import com.sun.pdfview.PDFDebugger;
public void removeCMap(short platformID, short platformSpecificID) { CmapSubtable key = new CmapSubtable(platformID, platformSpecificID); this.subtables.remove(key); } @Override public void setData(ByteBuffer data) { setVersion(data.getShort()); short numberSubtables = data.getShort(); for (int i = 0; i < numberSubtables; i++) { short platformID = data.getShort(); short platformSpecificID = data.getShort(); int offset = data.getInt(); data.mark(); // get the position from the start of this buffer data.position(offset); ByteBuffer mapData = data.slice(); data.reset(); try { CMap cMap = CMap.getMap(mapData); if (cMap != null) { addCMap(platformID, platformSpecificID, cMap); } } catch (Exception ex) {
// Path: src/com/sun/pdfview/PDFDebugger.java // public class PDFDebugger { // public final static String DEBUG_DCTDECODE_DATA = "debugdctdecode"; // public static final boolean DEBUG_TEXT = false; // public static final boolean DEBUG_IMAGES = false; // public static final boolean DEBUG_OPERATORS = false; // public static final boolean DEBUG_PATH = false; // public static final int DEBUG_STOP_AT_INDEX = 0; // public static final boolean DISABLE_TEXT = false; // public static final boolean DISABLE_IMAGES = false; // public static final boolean DISABLE_PATH_STROKE = false; // public static final boolean DISABLE_PATH_FILL = false; // public static final boolean DISABLE_PATH_STROKE_FILL = false; // public static final boolean DISABLE_CLIP = false; // public static final boolean DISABLE_FORMS = false; // public static final boolean DISABLE_SHADER = false; // public static final boolean SHOW_TEXT_REGIONS = false; // public static final boolean SHOW_TEXT_ANCHOR = false; // public static final boolean DISABLE_THUMBNAILS = false; // public static final long DRAW_DELAY = 0; // // public static int debuglevel = 4000; // // @SuppressWarnings("serial") // public static class DebugStopException extends Exception { // // nothing to do // } // // public static void debugImage(BufferedImage image, String name) { // if (PDFDebugger.DEBUG_IMAGES) { // if(image == null) { // return; // } // try { // // retrieve image // File outputfile = new File("D:/tmp/PDFimages/" + name + ".png"); // ImageIO.write(image, "png", outputfile); // } catch (IOException e) { // BaseWatchable.getErrorHandler().publishException(e); // } // } // } // // // TODO: add debug level and print it? // public static void debug(String msg, int level) { // if (level > debuglevel) { // System.out.println(escape(msg)); // } // } // // // TODO: add debug level and print it? // public static void debug(String msg) { // debug(msg, debuglevel); // } // // public static String escape(String msg) { // StringBuffer sb = new StringBuffer(); // for (int i = 0; i < msg.length(); i++) { // char c = msg.charAt(i); // if (c != '\n' && (c < 32 || c >= 127)) { // c = '?'; // } // sb.append(c); // } // return sb.toString(); // } // // public static void setDebugLevel(int level) { // debuglevel = level; // } // // // public static String dumpStream(byte[] stream) { // return PDFDebugger.escape(new String(stream).replace('\r', '\n')); // } // // public static void logPath(GeneralPath path, String operation) { // if (PDFDebugger.DEBUG_PATH){ // if (operation != null) { // System.out.println("Operation: " + operation + "; "); // } // System.out.println("Current path: "); // Rectangle b = path.getBounds(); // if (b != null) // System.out.println(" Bounds [x=" + b.x + ",y=" + b.y + ",width=" + b.width + ",height=" + b.height + "]"); // Point2D p = path.getCurrentPoint(); // if (p != null) // System.out.println(" Point [x=" + p.getX() + ",y=" + p.getY() + "]"); // } // } // // /** // * take a byte array and write a temporary file with it's data. // * This is intended to capture data for analysis, like after decoders. // * // * @param ary // * @param name // */ // public static void emitDataFile(byte[] ary, String name) { // FileOutputStream ostr; // try { // File file = File.createTempFile("DateFile", name); // ostr = new FileOutputStream(file); // PDFDebugger.debug("Write: " + file.getPath()); // ostr.write(ary); // ostr.close(); // } catch (IOException ex) { // // ignore // } // } // // public static void dump(PDFObject obj) throws IOException { // PDFDebugger.debug("dumping PDF object: " + obj); // if (obj == null) { // return; // } // HashMap<String, PDFObject> dict = obj.getDictionary(); // PDFDebugger.debug(" dict = " + dict); // for (Object key : dict.keySet()) { // PDFDebugger.debug("key = " + key + " value = " + dict.get(key)); // } // } // // } // Path: src/com/sun/pdfview/font/ttf/CmapTable.java import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.SortedMap; import java.util.TreeMap; import com.sun.pdfview.PDFDebugger; public void removeCMap(short platformID, short platformSpecificID) { CmapSubtable key = new CmapSubtable(platformID, platformSpecificID); this.subtables.remove(key); } @Override public void setData(ByteBuffer data) { setVersion(data.getShort()); short numberSubtables = data.getShort(); for (int i = 0; i < numberSubtables; i++) { short platformID = data.getShort(); short platformSpecificID = data.getShort(); int offset = data.getInt(); data.mark(); // get the position from the start of this buffer data.position(offset); ByteBuffer mapData = data.slice(); data.reset(); try { CMap cMap = CMap.getMap(mapData); if (cMap != null) { addCMap(platformID, platformSpecificID, cMap); } } catch (Exception ex) {
PDFDebugger.debug("Error reading map. PlatformID=" +
andriydruk/RxDNSSD
rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2RegisterListener.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java // public interface DNSSDRegistration extends DNSSDService { // /** Get a reference to the primary TXT record of a registered service.<P> // The record can be updated by sending it an update() message.<P> // // <P> // @return A {@link DNSRecord}. // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord getTXTRecord() throws DNSSDException; // // /** Add a record to a registered service.<P> // The name of the record will be the same as the registered service's name.<P> // The record can be updated or deregistered by sending it an update() or remove() message.<P> // // @param flags // Currently unused, reserved for future use. // <P> // @param rrType // The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h. // <P> // @param rData // The raw rdata to be contained in the added resource record. // <P> // @param ttl // The time to live of the resource record, in seconds. // <P> // @return A {@link DNSRecord} that may be passed to updateRecord() or removeRecord(). // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord addRecord(int flags, int rrType, byte[] rData, int ttl) throws DNSSDException; // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/RegisterListener.java // public interface RegisterListener extends BaseListener // { // /** Called when a registration has been completed.<P> // // @param registration // The active registration. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param serviceName // The service name registered (if the application did not specify a name in // DNSSD.register(), this indicates what name was automatically chosen). // <P> // @param regType // The type of service registered, as it was passed to DNSSD.register(). // <P> // @param domain // The domain on which the service was registered. If the application did not // specify a domain in DNSSD.register(), this is the default domain // on which the service was registered. // */ // void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain); // }
import com.github.druk.dnssd.DNSSDRegistration; import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.RegisterListener; import io.reactivex.FlowableEmitter;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; class Rx2RegisterListener implements RegisterListener { private final FlowableEmitter<? super BonjourService> emitter; Rx2RegisterListener(FlowableEmitter<? super BonjourService> emitter) { this.emitter = emitter; } @Override
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java // public interface DNSSDRegistration extends DNSSDService { // /** Get a reference to the primary TXT record of a registered service.<P> // The record can be updated by sending it an update() message.<P> // // <P> // @return A {@link DNSRecord}. // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord getTXTRecord() throws DNSSDException; // // /** Add a record to a registered service.<P> // The name of the record will be the same as the registered service's name.<P> // The record can be updated or deregistered by sending it an update() or remove() message.<P> // // @param flags // Currently unused, reserved for future use. // <P> // @param rrType // The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h. // <P> // @param rData // The raw rdata to be contained in the added resource record. // <P> // @param ttl // The time to live of the resource record, in seconds. // <P> // @return A {@link DNSRecord} that may be passed to updateRecord() or removeRecord(). // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord addRecord(int flags, int rrType, byte[] rData, int ttl) throws DNSSDException; // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/RegisterListener.java // public interface RegisterListener extends BaseListener // { // /** Called when a registration has been completed.<P> // // @param registration // The active registration. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param serviceName // The service name registered (if the application did not specify a name in // DNSSD.register(), this indicates what name was automatically chosen). // <P> // @param regType // The type of service registered, as it was passed to DNSSD.register(). // <P> // @param domain // The domain on which the service was registered. If the application did not // specify a domain in DNSSD.register(), this is the default domain // on which the service was registered. // */ // void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain); // } // Path: rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2RegisterListener.java import com.github.druk.dnssd.DNSSDRegistration; import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.RegisterListener; import io.reactivex.FlowableEmitter; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; class Rx2RegisterListener implements RegisterListener { private final FlowableEmitter<? super BonjourService> emitter; Rx2RegisterListener(FlowableEmitter<? super BonjourService> emitter) { this.emitter = emitter; } @Override
public void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain) {
andriydruk/RxDNSSD
rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2RegisterListener.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java // public interface DNSSDRegistration extends DNSSDService { // /** Get a reference to the primary TXT record of a registered service.<P> // The record can be updated by sending it an update() message.<P> // // <P> // @return A {@link DNSRecord}. // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord getTXTRecord() throws DNSSDException; // // /** Add a record to a registered service.<P> // The name of the record will be the same as the registered service's name.<P> // The record can be updated or deregistered by sending it an update() or remove() message.<P> // // @param flags // Currently unused, reserved for future use. // <P> // @param rrType // The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h. // <P> // @param rData // The raw rdata to be contained in the added resource record. // <P> // @param ttl // The time to live of the resource record, in seconds. // <P> // @return A {@link DNSRecord} that may be passed to updateRecord() or removeRecord(). // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord addRecord(int flags, int rrType, byte[] rData, int ttl) throws DNSSDException; // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/RegisterListener.java // public interface RegisterListener extends BaseListener // { // /** Called when a registration has been completed.<P> // // @param registration // The active registration. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param serviceName // The service name registered (if the application did not specify a name in // DNSSD.register(), this indicates what name was automatically chosen). // <P> // @param regType // The type of service registered, as it was passed to DNSSD.register(). // <P> // @param domain // The domain on which the service was registered. If the application did not // specify a domain in DNSSD.register(), this is the default domain // on which the service was registered. // */ // void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain); // }
import com.github.druk.dnssd.DNSSDRegistration; import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.RegisterListener; import io.reactivex.FlowableEmitter;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; class Rx2RegisterListener implements RegisterListener { private final FlowableEmitter<? super BonjourService> emitter; Rx2RegisterListener(FlowableEmitter<? super BonjourService> emitter) { this.emitter = emitter; } @Override public void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain) { if (emitter.isCancelled()) { return; } BonjourService service = new BonjourService.Builder(flags, 0, serviceName, regType, domain).build(); emitter.onNext(service); } @Override
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java // public interface DNSSDRegistration extends DNSSDService { // /** Get a reference to the primary TXT record of a registered service.<P> // The record can be updated by sending it an update() message.<P> // // <P> // @return A {@link DNSRecord}. // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord getTXTRecord() throws DNSSDException; // // /** Add a record to a registered service.<P> // The name of the record will be the same as the registered service's name.<P> // The record can be updated or deregistered by sending it an update() or remove() message.<P> // // @param flags // Currently unused, reserved for future use. // <P> // @param rrType // The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h. // <P> // @param rData // The raw rdata to be contained in the added resource record. // <P> // @param ttl // The time to live of the resource record, in seconds. // <P> // @return A {@link DNSRecord} that may be passed to updateRecord() or removeRecord(). // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord addRecord(int flags, int rrType, byte[] rData, int ttl) throws DNSSDException; // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/RegisterListener.java // public interface RegisterListener extends BaseListener // { // /** Called when a registration has been completed.<P> // // @param registration // The active registration. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param serviceName // The service name registered (if the application did not specify a name in // DNSSD.register(), this indicates what name was automatically chosen). // <P> // @param regType // The type of service registered, as it was passed to DNSSD.register(). // <P> // @param domain // The domain on which the service was registered. If the application did not // specify a domain in DNSSD.register(), this is the default domain // on which the service was registered. // */ // void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain); // } // Path: rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2RegisterListener.java import com.github.druk.dnssd.DNSSDRegistration; import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.RegisterListener; import io.reactivex.FlowableEmitter; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; class Rx2RegisterListener implements RegisterListener { private final FlowableEmitter<? super BonjourService> emitter; Rx2RegisterListener(FlowableEmitter<? super BonjourService> emitter) { this.emitter = emitter; } @Override public void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain) { if (emitter.isCancelled()) { return; } BonjourService service = new BonjourService.Builder(flags, 0, serviceName, regType, domain).build(); emitter.onNext(service); } @Override
public void operationFailed(DNSSDService service, int errorCode) {
andriydruk/RxDNSSD
rxdnssd/src/main/java/com/github/druk/rxdnssd/RxRegisterListener.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java // public interface DNSSDRegistration extends DNSSDService { // /** Get a reference to the primary TXT record of a registered service.<P> // The record can be updated by sending it an update() message.<P> // // <P> // @return A {@link DNSRecord}. // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord getTXTRecord() throws DNSSDException; // // /** Add a record to a registered service.<P> // The name of the record will be the same as the registered service's name.<P> // The record can be updated or deregistered by sending it an update() or remove() message.<P> // // @param flags // Currently unused, reserved for future use. // <P> // @param rrType // The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h. // <P> // @param rData // The raw rdata to be contained in the added resource record. // <P> // @param ttl // The time to live of the resource record, in seconds. // <P> // @return A {@link DNSRecord} that may be passed to updateRecord() or removeRecord(). // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord addRecord(int flags, int rrType, byte[] rData, int ttl) throws DNSSDException; // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/RegisterListener.java // public interface RegisterListener extends BaseListener // { // /** Called when a registration has been completed.<P> // // @param registration // The active registration. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param serviceName // The service name registered (if the application did not specify a name in // DNSSD.register(), this indicates what name was automatically chosen). // <P> // @param regType // The type of service registered, as it was passed to DNSSD.register(). // <P> // @param domain // The domain on which the service was registered. If the application did not // specify a domain in DNSSD.register(), this is the default domain // on which the service was registered. // */ // void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain); // }
import com.github.druk.dnssd.DNSSDRegistration; import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.RegisterListener; import rx.Subscriber;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; class RxRegisterListener implements RegisterListener { private final Subscriber<? super BonjourService> subscriber; RxRegisterListener(Subscriber<? super BonjourService> subscriber) { this.subscriber = subscriber; } @Override
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java // public interface DNSSDRegistration extends DNSSDService { // /** Get a reference to the primary TXT record of a registered service.<P> // The record can be updated by sending it an update() message.<P> // // <P> // @return A {@link DNSRecord}. // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord getTXTRecord() throws DNSSDException; // // /** Add a record to a registered service.<P> // The name of the record will be the same as the registered service's name.<P> // The record can be updated or deregistered by sending it an update() or remove() message.<P> // // @param flags // Currently unused, reserved for future use. // <P> // @param rrType // The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h. // <P> // @param rData // The raw rdata to be contained in the added resource record. // <P> // @param ttl // The time to live of the resource record, in seconds. // <P> // @return A {@link DNSRecord} that may be passed to updateRecord() or removeRecord(). // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord addRecord(int flags, int rrType, byte[] rData, int ttl) throws DNSSDException; // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/RegisterListener.java // public interface RegisterListener extends BaseListener // { // /** Called when a registration has been completed.<P> // // @param registration // The active registration. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param serviceName // The service name registered (if the application did not specify a name in // DNSSD.register(), this indicates what name was automatically chosen). // <P> // @param regType // The type of service registered, as it was passed to DNSSD.register(). // <P> // @param domain // The domain on which the service was registered. If the application did not // specify a domain in DNSSD.register(), this is the default domain // on which the service was registered. // */ // void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain); // } // Path: rxdnssd/src/main/java/com/github/druk/rxdnssd/RxRegisterListener.java import com.github.druk.dnssd.DNSSDRegistration; import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.RegisterListener; import rx.Subscriber; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; class RxRegisterListener implements RegisterListener { private final Subscriber<? super BonjourService> subscriber; RxRegisterListener(Subscriber<? super BonjourService> subscriber) { this.subscriber = subscriber; } @Override
public void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain) {
andriydruk/RxDNSSD
rxdnssd/src/main/java/com/github/druk/rxdnssd/RxRegisterListener.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java // public interface DNSSDRegistration extends DNSSDService { // /** Get a reference to the primary TXT record of a registered service.<P> // The record can be updated by sending it an update() message.<P> // // <P> // @return A {@link DNSRecord}. // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord getTXTRecord() throws DNSSDException; // // /** Add a record to a registered service.<P> // The name of the record will be the same as the registered service's name.<P> // The record can be updated or deregistered by sending it an update() or remove() message.<P> // // @param flags // Currently unused, reserved for future use. // <P> // @param rrType // The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h. // <P> // @param rData // The raw rdata to be contained in the added resource record. // <P> // @param ttl // The time to live of the resource record, in seconds. // <P> // @return A {@link DNSRecord} that may be passed to updateRecord() or removeRecord(). // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord addRecord(int flags, int rrType, byte[] rData, int ttl) throws DNSSDException; // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/RegisterListener.java // public interface RegisterListener extends BaseListener // { // /** Called when a registration has been completed.<P> // // @param registration // The active registration. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param serviceName // The service name registered (if the application did not specify a name in // DNSSD.register(), this indicates what name was automatically chosen). // <P> // @param regType // The type of service registered, as it was passed to DNSSD.register(). // <P> // @param domain // The domain on which the service was registered. If the application did not // specify a domain in DNSSD.register(), this is the default domain // on which the service was registered. // */ // void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain); // }
import com.github.druk.dnssd.DNSSDRegistration; import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.RegisterListener; import rx.Subscriber;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; class RxRegisterListener implements RegisterListener { private final Subscriber<? super BonjourService> subscriber; RxRegisterListener(Subscriber<? super BonjourService> subscriber) { this.subscriber = subscriber; } @Override public void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain) { if (subscriber.isUnsubscribed()) { return; } BonjourService service = new BonjourService.Builder(flags, 0, serviceName, regType, domain).build(); subscriber.onNext(service); } @Override
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java // public interface DNSSDRegistration extends DNSSDService { // /** Get a reference to the primary TXT record of a registered service.<P> // The record can be updated by sending it an update() message.<P> // // <P> // @return A {@link DNSRecord}. // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord getTXTRecord() throws DNSSDException; // // /** Add a record to a registered service.<P> // The name of the record will be the same as the registered service's name.<P> // The record can be updated or deregistered by sending it an update() or remove() message.<P> // // @param flags // Currently unused, reserved for future use. // <P> // @param rrType // The type of the record (e.g. TXT, SRV, etc), as defined in nameser.h. // <P> // @param rData // The raw rdata to be contained in the added resource record. // <P> // @param ttl // The time to live of the resource record, in seconds. // <P> // @return A {@link DNSRecord} that may be passed to updateRecord() or removeRecord(). // If {@link DNSSDRegistration#stop} is called, the DNSRecord is also // invalidated and may not be used further. // */ // DNSRecord addRecord(int flags, int rrType, byte[] rData, int ttl) throws DNSSDException; // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/RegisterListener.java // public interface RegisterListener extends BaseListener // { // /** Called when a registration has been completed.<P> // // @param registration // The active registration. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param serviceName // The service name registered (if the application did not specify a name in // DNSSD.register(), this indicates what name was automatically chosen). // <P> // @param regType // The type of service registered, as it was passed to DNSSD.register(). // <P> // @param domain // The domain on which the service was registered. If the application did not // specify a domain in DNSSD.register(), this is the default domain // on which the service was registered. // */ // void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain); // } // Path: rxdnssd/src/main/java/com/github/druk/rxdnssd/RxRegisterListener.java import com.github.druk.dnssd.DNSSDRegistration; import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.RegisterListener; import rx.Subscriber; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; class RxRegisterListener implements RegisterListener { private final Subscriber<? super BonjourService> subscriber; RxRegisterListener(Subscriber<? super BonjourService> subscriber) { this.subscriber = subscriber; } @Override public void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain) { if (subscriber.isUnsubscribed()) { return; } BonjourService service = new BonjourService.Builder(flags, 0, serviceName, regType, domain).build(); subscriber.onNext(service); } @Override
public void operationFailed(DNSSDService service, int errorCode) {
andriydruk/RxDNSSD
rxdnssd/src/main/java/com/github/druk/rxdnssd/RxDnssdEmbedded.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDEmbedded.java // public class DNSSDEmbedded extends DNSSD { // // public static final int DEFAULT_STOP_TIMER_DELAY = 5000; //5 sec // // private static final String TAG = "DNSSDEmbedded"; // private final long mStopTimerDelay; // private final Handler handler = new Handler(Looper.getMainLooper()); // private Thread mThread; // private volatile boolean isStarted = false; // private int serviceCount = 0; // // public DNSSDEmbedded(Context context) { // this(context, DEFAULT_STOP_TIMER_DELAY); // } // // public DNSSDEmbedded(Context context, long stopTimerDelay) { // super(context, "jdns_sd_embedded"); // mStopTimerDelay = stopTimerDelay; // } // // static native int nativeInit(); // // static native int nativeLoop(); // // static native void nativeExit(); // // /** // * Init DNS-SD thread and start event loop. Should be called before using any of DNSSD operations. // * If DNS-SD thread has already initialised will try to reuse it. // * // * Note: This method will block thread until DNS-SD initialization finish. // */ // public void init() { // handler.removeCallbacks(DNSSDEmbedded::nativeExit); // // if (mThread != null && mThread.isAlive()) { // Log.i(TAG, "already started"); // waitUntilStarted(); // return; // } // // isStarted = false; // // InternalDNSSD.getInstance(); // mThread = new Thread() { // public void run() { // Log.i(TAG, "init"); // int err = nativeInit(); // synchronized (DNSSDEmbedded.class) { // isStarted = true; // DNSSDEmbedded.class.notifyAll(); // } // if (err != 0) { // Log.e(TAG, "error: " + err); // return; // } // Log.i(TAG, "start"); // int ret = nativeLoop(); // isStarted = false; // Log.i(TAG, "finish with code: " + ret); // } // }; // mThread.setPriority(Thread.MAX_PRIORITY); // mThread.setName("DNS-SDEmbedded"); // mThread.start(); // // waitUntilStarted(); // } // // /** // * Exit from embedded DNS-SD loop. This method will stop DNS-SD after the delay (it makes possible to reuse already initialised DNS-SD thread). // * // * Note: method isn't blocking, can be used from any thread. // */ // public void exit() { // synchronized (DNSSDEmbedded.class) { // Log.i(TAG, "post exit"); // handler.postDelayed(DNSSDEmbedded::nativeExit, mStopTimerDelay); // } // } // // private void waitUntilStarted() { // synchronized (DNSSDEmbedded.class) { // while (!isStarted) { // try { // DNSSDEmbedded.class.wait(); // } catch (InterruptedException e) { // Log.e(TAG, "waitUntilStarted exception: ", e); // } // } // } // } // // @Override // public void onServiceStarting() { // super.onServiceStarting(); // this.init(); // serviceCount++; // } // // @Override // public void onServiceStopped() { // super.onServiceStopped(); // serviceCount--; // if (serviceCount == 0) { // this.exit(); // } // } // }
import android.content.Context; import com.github.druk.dnssd.DNSSDEmbedded;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; /** * RxDnssdEmbedded is implementation of RxDnssd with embedded DNS-SD {@link RxDnssd} */ public class RxDnssdEmbedded extends RxDnssdCommon { public RxDnssdEmbedded(Context context) {
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDEmbedded.java // public class DNSSDEmbedded extends DNSSD { // // public static final int DEFAULT_STOP_TIMER_DELAY = 5000; //5 sec // // private static final String TAG = "DNSSDEmbedded"; // private final long mStopTimerDelay; // private final Handler handler = new Handler(Looper.getMainLooper()); // private Thread mThread; // private volatile boolean isStarted = false; // private int serviceCount = 0; // // public DNSSDEmbedded(Context context) { // this(context, DEFAULT_STOP_TIMER_DELAY); // } // // public DNSSDEmbedded(Context context, long stopTimerDelay) { // super(context, "jdns_sd_embedded"); // mStopTimerDelay = stopTimerDelay; // } // // static native int nativeInit(); // // static native int nativeLoop(); // // static native void nativeExit(); // // /** // * Init DNS-SD thread and start event loop. Should be called before using any of DNSSD operations. // * If DNS-SD thread has already initialised will try to reuse it. // * // * Note: This method will block thread until DNS-SD initialization finish. // */ // public void init() { // handler.removeCallbacks(DNSSDEmbedded::nativeExit); // // if (mThread != null && mThread.isAlive()) { // Log.i(TAG, "already started"); // waitUntilStarted(); // return; // } // // isStarted = false; // // InternalDNSSD.getInstance(); // mThread = new Thread() { // public void run() { // Log.i(TAG, "init"); // int err = nativeInit(); // synchronized (DNSSDEmbedded.class) { // isStarted = true; // DNSSDEmbedded.class.notifyAll(); // } // if (err != 0) { // Log.e(TAG, "error: " + err); // return; // } // Log.i(TAG, "start"); // int ret = nativeLoop(); // isStarted = false; // Log.i(TAG, "finish with code: " + ret); // } // }; // mThread.setPriority(Thread.MAX_PRIORITY); // mThread.setName("DNS-SDEmbedded"); // mThread.start(); // // waitUntilStarted(); // } // // /** // * Exit from embedded DNS-SD loop. This method will stop DNS-SD after the delay (it makes possible to reuse already initialised DNS-SD thread). // * // * Note: method isn't blocking, can be used from any thread. // */ // public void exit() { // synchronized (DNSSDEmbedded.class) { // Log.i(TAG, "post exit"); // handler.postDelayed(DNSSDEmbedded::nativeExit, mStopTimerDelay); // } // } // // private void waitUntilStarted() { // synchronized (DNSSDEmbedded.class) { // while (!isStarted) { // try { // DNSSDEmbedded.class.wait(); // } catch (InterruptedException e) { // Log.e(TAG, "waitUntilStarted exception: ", e); // } // } // } // } // // @Override // public void onServiceStarting() { // super.onServiceStarting(); // this.init(); // serviceCount++; // } // // @Override // public void onServiceStopped() { // super.onServiceStopped(); // serviceCount--; // if (serviceCount == 0) { // this.exit(); // } // } // } // Path: rxdnssd/src/main/java/com/github/druk/rxdnssd/RxDnssdEmbedded.java import android.content.Context; import com.github.druk.dnssd.DNSSDEmbedded; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; /** * RxDnssdEmbedded is implementation of RxDnssd with embedded DNS-SD {@link RxDnssd} */ public class RxDnssdEmbedded extends RxDnssdCommon { public RxDnssdEmbedded(Context context) {
super(new DNSSDEmbedded(context));
andriydruk/RxDNSSD
rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2BrowseListener.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/BrowseListener.java // public interface BrowseListener extends BaseListener { // /** Called to report discovered services.<P> // // @param browser // The active browse service. // <P> // @param flags // Possible values are DNSSD.MORE_COMING. // <P> // @param ifIndex // The interface on which the service is advertised. This index should be passed // to {@link InternalDNSSD#resolve} when resolving the service. // <P> // @param serviceName // The service name discovered. // <P> // @param regType // The registration type, as passed in to DNSSD.browse(). // <P> // @param domain // The domain in which the service was discovered. // */ // void serviceFound(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain); // // /** Called to report services which have been deregistered.<P> // // @param browser // The active browse service. // <P> // @param flags // Possible values are DNSSD.MORE_COMING. // <P> // @param ifIndex // The interface on which the service is advertised. // <P> // @param serviceName // The service name which has deregistered. // <P> // @param regType // The registration type, as passed in to DNSSD.browse(). // <P> // @param domain // The domain in which the service was discovered. // */ // void serviceLost(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // }
import com.github.druk.dnssd.BrowseListener; import com.github.druk.dnssd.DNSSDService; import io.reactivex.FlowableEmitter;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; class Rx2BrowseListener implements BrowseListener { private final FlowableEmitter<? super BonjourService> emitter; Rx2BrowseListener(FlowableEmitter<? super BonjourService> emitter) { this.emitter = emitter; } @Override
// Path: dnssd/src/main/java/com/github/druk/dnssd/BrowseListener.java // public interface BrowseListener extends BaseListener { // /** Called to report discovered services.<P> // // @param browser // The active browse service. // <P> // @param flags // Possible values are DNSSD.MORE_COMING. // <P> // @param ifIndex // The interface on which the service is advertised. This index should be passed // to {@link InternalDNSSD#resolve} when resolving the service. // <P> // @param serviceName // The service name discovered. // <P> // @param regType // The registration type, as passed in to DNSSD.browse(). // <P> // @param domain // The domain in which the service was discovered. // */ // void serviceFound(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain); // // /** Called to report services which have been deregistered.<P> // // @param browser // The active browse service. // <P> // @param flags // Possible values are DNSSD.MORE_COMING. // <P> // @param ifIndex // The interface on which the service is advertised. // <P> // @param serviceName // The service name which has deregistered. // <P> // @param regType // The registration type, as passed in to DNSSD.browse(). // <P> // @param domain // The domain in which the service was discovered. // */ // void serviceLost(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // Path: rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2BrowseListener.java import com.github.druk.dnssd.BrowseListener; import com.github.druk.dnssd.DNSSDService; import io.reactivex.FlowableEmitter; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; class Rx2BrowseListener implements BrowseListener { private final FlowableEmitter<? super BonjourService> emitter; Rx2BrowseListener(FlowableEmitter<? super BonjourService> emitter) { this.emitter = emitter; } @Override
public void serviceFound(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain) {
andriydruk/RxDNSSD
rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2ResolveListener.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/ResolveListener.java // public interface ResolveListener extends BaseListener // { // /** Called when a service has been resolved.<P> // // @param resolver // The active resolver object. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param fullName // The full service domain name, in the form &lt;servicename&gt;.&lt;protocol&gt;.&lt;domain&gt;. // (Any literal dots (".") are escaped with a backslash ("\."), and literal // backslashes are escaped with a second backslash ("\\"), e.g. a web server // named "Dr. Pepper" would have the fullname "Dr\.\032Pepper._http._tcp.local."). // This is the appropriate format to pass to standard system DNS APIs such as // res_query(), or to the special-purpose functions included in this API that // take fullname parameters. // <P> // @param hostName // The target hostname of the machine providing the service. This name can // be passed to functions like queryRecord() to look up the host's IP address. // <P> // @param port // The port number on which connections are accepted for this service. // <P> // @param txtRecord // The service's primary txt record. // */ // void serviceResolved(DNSSDService resolver, int flags, int ifIndex, String fullName, String hostName, int port, Map<String, String> txtRecord); // }
import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.ResolveListener; import java.util.Map; import io.reactivex.FlowableEmitter;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; class Rx2ResolveListener implements ResolveListener { private final FlowableEmitter<? super BonjourService> emitter; private final BonjourService.Builder builder; Rx2ResolveListener(FlowableEmitter<? super BonjourService> emitter, BonjourService service) { this.emitter = emitter; this.builder = new BonjourService.Builder(service); } @Override
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/ResolveListener.java // public interface ResolveListener extends BaseListener // { // /** Called when a service has been resolved.<P> // // @param resolver // The active resolver object. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param fullName // The full service domain name, in the form &lt;servicename&gt;.&lt;protocol&gt;.&lt;domain&gt;. // (Any literal dots (".") are escaped with a backslash ("\."), and literal // backslashes are escaped with a second backslash ("\\"), e.g. a web server // named "Dr. Pepper" would have the fullname "Dr\.\032Pepper._http._tcp.local."). // This is the appropriate format to pass to standard system DNS APIs such as // res_query(), or to the special-purpose functions included in this API that // take fullname parameters. // <P> // @param hostName // The target hostname of the machine providing the service. This name can // be passed to functions like queryRecord() to look up the host's IP address. // <P> // @param port // The port number on which connections are accepted for this service. // <P> // @param txtRecord // The service's primary txt record. // */ // void serviceResolved(DNSSDService resolver, int flags, int ifIndex, String fullName, String hostName, int port, Map<String, String> txtRecord); // } // Path: rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2ResolveListener.java import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.ResolveListener; import java.util.Map; import io.reactivex.FlowableEmitter; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; class Rx2ResolveListener implements ResolveListener { private final FlowableEmitter<? super BonjourService> emitter; private final BonjourService.Builder builder; Rx2ResolveListener(FlowableEmitter<? super BonjourService> emitter, BonjourService service) { this.emitter = emitter; this.builder = new BonjourService.Builder(service); } @Override
public void serviceResolved(DNSSDService resolver, int flags, int ifIndex, String fullName, String hostName, int port, Map<String, String> txtRecord) {
andriydruk/RxDNSSD
rxdnssd/src/main/java/com/github/druk/rxdnssd/RxResolveListener.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/ResolveListener.java // public interface ResolveListener extends BaseListener // { // /** Called when a service has been resolved.<P> // // @param resolver // The active resolver object. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param fullName // The full service domain name, in the form &lt;servicename&gt;.&lt;protocol&gt;.&lt;domain&gt;. // (Any literal dots (".") are escaped with a backslash ("\."), and literal // backslashes are escaped with a second backslash ("\\"), e.g. a web server // named "Dr. Pepper" would have the fullname "Dr\.\032Pepper._http._tcp.local."). // This is the appropriate format to pass to standard system DNS APIs such as // res_query(), or to the special-purpose functions included in this API that // take fullname parameters. // <P> // @param hostName // The target hostname of the machine providing the service. This name can // be passed to functions like queryRecord() to look up the host's IP address. // <P> // @param port // The port number on which connections are accepted for this service. // <P> // @param txtRecord // The service's primary txt record. // */ // void serviceResolved(DNSSDService resolver, int flags, int ifIndex, String fullName, String hostName, int port, Map<String, String> txtRecord); // }
import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.ResolveListener; import java.util.Map; import rx.Subscriber;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; class RxResolveListener implements ResolveListener { private final Subscriber<? super BonjourService> subscriber; private final BonjourService.Builder builder; RxResolveListener(Subscriber<? super BonjourService> subscriber, BonjourService service) { this.subscriber = subscriber; this.builder = new BonjourService.Builder(service); } @Override
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/ResolveListener.java // public interface ResolveListener extends BaseListener // { // /** Called when a service has been resolved.<P> // // @param resolver // The active resolver object. // <P> // @param flags // Currently unused, reserved for future use. // <P> // @param fullName // The full service domain name, in the form &lt;servicename&gt;.&lt;protocol&gt;.&lt;domain&gt;. // (Any literal dots (".") are escaped with a backslash ("\."), and literal // backslashes are escaped with a second backslash ("\\"), e.g. a web server // named "Dr. Pepper" would have the fullname "Dr\.\032Pepper._http._tcp.local."). // This is the appropriate format to pass to standard system DNS APIs such as // res_query(), or to the special-purpose functions included in this API that // take fullname parameters. // <P> // @param hostName // The target hostname of the machine providing the service. This name can // be passed to functions like queryRecord() to look up the host's IP address. // <P> // @param port // The port number on which connections are accepted for this service. // <P> // @param txtRecord // The service's primary txt record. // */ // void serviceResolved(DNSSDService resolver, int flags, int ifIndex, String fullName, String hostName, int port, Map<String, String> txtRecord); // } // Path: rxdnssd/src/main/java/com/github/druk/rxdnssd/RxResolveListener.java import com.github.druk.dnssd.DNSSDService; import com.github.druk.dnssd.ResolveListener; import java.util.Map; import rx.Subscriber; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; class RxResolveListener implements ResolveListener { private final Subscriber<? super BonjourService> subscriber; private final BonjourService.Builder builder; RxResolveListener(Subscriber<? super BonjourService> subscriber, BonjourService service) { this.subscriber = subscriber; this.builder = new BonjourService.Builder(service); } @Override
public void serviceResolved(DNSSDService resolver, int flags, int ifIndex, String fullName, String hostName, int port, Map<String, String> txtRecord) {
andriydruk/RxDNSSD
rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2DnssdEmbedded.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDEmbedded.java // public class DNSSDEmbedded extends DNSSD { // // public static final int DEFAULT_STOP_TIMER_DELAY = 5000; //5 sec // // private static final String TAG = "DNSSDEmbedded"; // private final long mStopTimerDelay; // private final Handler handler = new Handler(Looper.getMainLooper()); // private Thread mThread; // private volatile boolean isStarted = false; // private int serviceCount = 0; // // public DNSSDEmbedded(Context context) { // this(context, DEFAULT_STOP_TIMER_DELAY); // } // // public DNSSDEmbedded(Context context, long stopTimerDelay) { // super(context, "jdns_sd_embedded"); // mStopTimerDelay = stopTimerDelay; // } // // static native int nativeInit(); // // static native int nativeLoop(); // // static native void nativeExit(); // // /** // * Init DNS-SD thread and start event loop. Should be called before using any of DNSSD operations. // * If DNS-SD thread has already initialised will try to reuse it. // * // * Note: This method will block thread until DNS-SD initialization finish. // */ // public void init() { // handler.removeCallbacks(DNSSDEmbedded::nativeExit); // // if (mThread != null && mThread.isAlive()) { // Log.i(TAG, "already started"); // waitUntilStarted(); // return; // } // // isStarted = false; // // InternalDNSSD.getInstance(); // mThread = new Thread() { // public void run() { // Log.i(TAG, "init"); // int err = nativeInit(); // synchronized (DNSSDEmbedded.class) { // isStarted = true; // DNSSDEmbedded.class.notifyAll(); // } // if (err != 0) { // Log.e(TAG, "error: " + err); // return; // } // Log.i(TAG, "start"); // int ret = nativeLoop(); // isStarted = false; // Log.i(TAG, "finish with code: " + ret); // } // }; // mThread.setPriority(Thread.MAX_PRIORITY); // mThread.setName("DNS-SDEmbedded"); // mThread.start(); // // waitUntilStarted(); // } // // /** // * Exit from embedded DNS-SD loop. This method will stop DNS-SD after the delay (it makes possible to reuse already initialised DNS-SD thread). // * // * Note: method isn't blocking, can be used from any thread. // */ // public void exit() { // synchronized (DNSSDEmbedded.class) { // Log.i(TAG, "post exit"); // handler.postDelayed(DNSSDEmbedded::nativeExit, mStopTimerDelay); // } // } // // private void waitUntilStarted() { // synchronized (DNSSDEmbedded.class) { // while (!isStarted) { // try { // DNSSDEmbedded.class.wait(); // } catch (InterruptedException e) { // Log.e(TAG, "waitUntilStarted exception: ", e); // } // } // } // } // // @Override // public void onServiceStarting() { // super.onServiceStarting(); // this.init(); // serviceCount++; // } // // @Override // public void onServiceStopped() { // super.onServiceStopped(); // serviceCount--; // if (serviceCount == 0) { // this.exit(); // } // } // }
import android.content.Context; import com.github.druk.dnssd.DNSSDEmbedded;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; /** * RxDnssdEmbedded is implementation of RxDnssd with embedded DNS-SD {@link Rx2Dnssd} */ public class Rx2DnssdEmbedded extends Rx2DnssdCommon { public Rx2DnssdEmbedded(Context context) {
// Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDEmbedded.java // public class DNSSDEmbedded extends DNSSD { // // public static final int DEFAULT_STOP_TIMER_DELAY = 5000; //5 sec // // private static final String TAG = "DNSSDEmbedded"; // private final long mStopTimerDelay; // private final Handler handler = new Handler(Looper.getMainLooper()); // private Thread mThread; // private volatile boolean isStarted = false; // private int serviceCount = 0; // // public DNSSDEmbedded(Context context) { // this(context, DEFAULT_STOP_TIMER_DELAY); // } // // public DNSSDEmbedded(Context context, long stopTimerDelay) { // super(context, "jdns_sd_embedded"); // mStopTimerDelay = stopTimerDelay; // } // // static native int nativeInit(); // // static native int nativeLoop(); // // static native void nativeExit(); // // /** // * Init DNS-SD thread and start event loop. Should be called before using any of DNSSD operations. // * If DNS-SD thread has already initialised will try to reuse it. // * // * Note: This method will block thread until DNS-SD initialization finish. // */ // public void init() { // handler.removeCallbacks(DNSSDEmbedded::nativeExit); // // if (mThread != null && mThread.isAlive()) { // Log.i(TAG, "already started"); // waitUntilStarted(); // return; // } // // isStarted = false; // // InternalDNSSD.getInstance(); // mThread = new Thread() { // public void run() { // Log.i(TAG, "init"); // int err = nativeInit(); // synchronized (DNSSDEmbedded.class) { // isStarted = true; // DNSSDEmbedded.class.notifyAll(); // } // if (err != 0) { // Log.e(TAG, "error: " + err); // return; // } // Log.i(TAG, "start"); // int ret = nativeLoop(); // isStarted = false; // Log.i(TAG, "finish with code: " + ret); // } // }; // mThread.setPriority(Thread.MAX_PRIORITY); // mThread.setName("DNS-SDEmbedded"); // mThread.start(); // // waitUntilStarted(); // } // // /** // * Exit from embedded DNS-SD loop. This method will stop DNS-SD after the delay (it makes possible to reuse already initialised DNS-SD thread). // * // * Note: method isn't blocking, can be used from any thread. // */ // public void exit() { // synchronized (DNSSDEmbedded.class) { // Log.i(TAG, "post exit"); // handler.postDelayed(DNSSDEmbedded::nativeExit, mStopTimerDelay); // } // } // // private void waitUntilStarted() { // synchronized (DNSSDEmbedded.class) { // while (!isStarted) { // try { // DNSSDEmbedded.class.wait(); // } catch (InterruptedException e) { // Log.e(TAG, "waitUntilStarted exception: ", e); // } // } // } // } // // @Override // public void onServiceStarting() { // super.onServiceStarting(); // this.init(); // serviceCount++; // } // // @Override // public void onServiceStopped() { // super.onServiceStopped(); // serviceCount--; // if (serviceCount == 0) { // this.exit(); // } // } // } // Path: rx2dnssd/src/main/java/com/github/druk/rx2dnssd/Rx2DnssdEmbedded.java import android.content.Context; import com.github.druk.dnssd.DNSSDEmbedded; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rx2dnssd; /** * RxDnssdEmbedded is implementation of RxDnssd with embedded DNS-SD {@link Rx2Dnssd} */ public class Rx2DnssdEmbedded extends Rx2DnssdCommon { public Rx2DnssdEmbedded(Context context) {
super(new DNSSDEmbedded(context));
andriydruk/RxDNSSD
rxdnssd/src/main/java/com/github/druk/rxdnssd/RxBrowseListener.java
// Path: dnssd/src/main/java/com/github/druk/dnssd/BrowseListener.java // public interface BrowseListener extends BaseListener { // /** Called to report discovered services.<P> // // @param browser // The active browse service. // <P> // @param flags // Possible values are DNSSD.MORE_COMING. // <P> // @param ifIndex // The interface on which the service is advertised. This index should be passed // to {@link InternalDNSSD#resolve} when resolving the service. // <P> // @param serviceName // The service name discovered. // <P> // @param regType // The registration type, as passed in to DNSSD.browse(). // <P> // @param domain // The domain in which the service was discovered. // */ // void serviceFound(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain); // // /** Called to report services which have been deregistered.<P> // // @param browser // The active browse service. // <P> // @param flags // Possible values are DNSSD.MORE_COMING. // <P> // @param ifIndex // The interface on which the service is advertised. // <P> // @param serviceName // The service name which has deregistered. // <P> // @param regType // The registration type, as passed in to DNSSD.browse(). // <P> // @param domain // The domain in which the service was discovered. // */ // void serviceLost(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // }
import com.github.druk.dnssd.BrowseListener; import com.github.druk.dnssd.DNSSDService; import rx.Subscriber;
/* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; class RxBrowseListener implements BrowseListener { private final Subscriber<? super BonjourService> subscriber; RxBrowseListener(Subscriber<? super BonjourService> subscriber) { this.subscriber = subscriber; } @Override
// Path: dnssd/src/main/java/com/github/druk/dnssd/BrowseListener.java // public interface BrowseListener extends BaseListener { // /** Called to report discovered services.<P> // // @param browser // The active browse service. // <P> // @param flags // Possible values are DNSSD.MORE_COMING. // <P> // @param ifIndex // The interface on which the service is advertised. This index should be passed // to {@link InternalDNSSD#resolve} when resolving the service. // <P> // @param serviceName // The service name discovered. // <P> // @param regType // The registration type, as passed in to DNSSD.browse(). // <P> // @param domain // The domain in which the service was discovered. // */ // void serviceFound(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain); // // /** Called to report services which have been deregistered.<P> // // @param browser // The active browse service. // <P> // @param flags // Possible values are DNSSD.MORE_COMING. // <P> // @param ifIndex // The interface on which the service is advertised. // <P> // @param serviceName // The service name which has deregistered. // <P> // @param regType // The registration type, as passed in to DNSSD.browse(). // <P> // @param domain // The domain in which the service was discovered. // */ // void serviceLost(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain); // } // // Path: dnssd/src/main/java/com/github/druk/dnssd/DNSSDService.java // public interface DNSSDService // { // /** // Halt the active operation and free resources associated with the DNSSDService.<P> // // Any services or records registered with this DNSSDService will be deregistered. Any // Browse, Resolve, or Query operations associated with this reference will be terminated.<P> // // Note: if the service was initialized with DNSSD.register(), and an extra resource record was // added to the service via {@link DNSSDRegistration#addRecord}, the DNSRecord so created // is invalidated when this method is called - the DNSRecord may not be used afterward. // */ // void stop(); // } // Path: rxdnssd/src/main/java/com/github/druk/rxdnssd/RxBrowseListener.java import com.github.druk.dnssd.BrowseListener; import com.github.druk.dnssd.DNSSDService; import rx.Subscriber; /* * Copyright (C) 2016 Andriy Druk * * 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.github.druk.rxdnssd; class RxBrowseListener implements BrowseListener { private final Subscriber<? super BonjourService> subscriber; RxBrowseListener(Subscriber<? super BonjourService> subscriber) { this.subscriber = subscriber; } @Override
public void serviceFound(DNSSDService browser, int flags, int ifIndex, String serviceName, String regType, String domain) {
USC-SQL/Violist
test/usc/sql/string/testcase/SimpleTest.java
// Path: src/LoggerLib/Logger.java // public class Logger { // static int counter=0; // public static void increase(int i) // { // counter+=i; // } // public static void report() // { // System.out.println(counter); // } // public static void reportString(String v, String log){ // System.out.println(log+"*"+v); // // // } // } // // Path: src/usc/sql/ir/Init.java // public class Init extends Variable{ // String name; // String line; // // List<Variable> initVar = new ArrayList<>(); // // public Init(String name,String line) // { // this.name = name; // this.line = line; // // } // // public Init(String name,String line,List<Variable> initVar) // { // this.name = name; // this.line = line; // this.initVar = initVar; // //initVar.addAll(initVar); // } // // public void setName(String name) // { // this.name = name; // } // // public String getName() // { // return name; // } // public String getLine() // { // return line; // } // public List<Variable> getInitVar() // { // return initVar; // } // public void setInitVar(List<Variable> initVar) // { // this.initVar = initVar; // // } // @Override // public String getValue() { // return "@"+name; // } // // // @Override // public String toString() // { // // if(initVar.isEmpty()) // return "\""+name+"\""+" "+line; // else // { // // // //return "\""+name+"\""; // return initVar.toString(); // } // // } // }
import LoggerLib.Logger; import usc.sql.ir.Init;
package usc.sql.string.testcase; class A { String a; public void setA(String a) { this.a = a; } } public class SimpleTest { static String aa = "A"; public static String addA(String v) { return v+"A"; } public static String tmp(String a) { for(int i=0;i<3;i++) a = a + "a"; a = addA(a); return a; //t(sigma_r0|ext_a+"a")|| ext_a } public static void main(String[] args) { /* String a="a"; String b="b"; for(int i=0;i<2;i++) { a=a+b+"a"; Logger.reportString(a,"Concat.NestedLoop_Branch"); for(int j=0;j<2;j++) { long time=(int)(Math.random()*100); if(time % 2 ==0) { b=b+"b"; } else{ b=b+"t"; } } } */ /* String a="a"; String b="b"; String c="c"; String e="l"; for(int i=0;i<3;i++) { a=a+b; b=b+c; long time=(int)(Math.random()*100); if(time % 2 ==0) { c=c+a+"c"; } else{ c=c+a+"d"; } Logger.reportString(c,"Concat.CircleLoop_Branch"); } */ String a="a"; String b="b"; StringBuilder c = new StringBuilder(); c.append("ccc"); b = b + c;
// Path: src/LoggerLib/Logger.java // public class Logger { // static int counter=0; // public static void increase(int i) // { // counter+=i; // } // public static void report() // { // System.out.println(counter); // } // public static void reportString(String v, String log){ // System.out.println(log+"*"+v); // // // } // } // // Path: src/usc/sql/ir/Init.java // public class Init extends Variable{ // String name; // String line; // // List<Variable> initVar = new ArrayList<>(); // // public Init(String name,String line) // { // this.name = name; // this.line = line; // // } // // public Init(String name,String line,List<Variable> initVar) // { // this.name = name; // this.line = line; // this.initVar = initVar; // //initVar.addAll(initVar); // } // // public void setName(String name) // { // this.name = name; // } // // public String getName() // { // return name; // } // public String getLine() // { // return line; // } // public List<Variable> getInitVar() // { // return initVar; // } // public void setInitVar(List<Variable> initVar) // { // this.initVar = initVar; // // } // @Override // public String getValue() { // return "@"+name; // } // // // @Override // public String toString() // { // // if(initVar.isEmpty()) // return "\""+name+"\""+" "+line; // else // { // // // //return "\""+name+"\""; // return initVar.toString(); // } // // } // } // Path: test/usc/sql/string/testcase/SimpleTest.java import LoggerLib.Logger; import usc.sql.ir.Init; package usc.sql.string.testcase; class A { String a; public void setA(String a) { this.a = a; } } public class SimpleTest { static String aa = "A"; public static String addA(String v) { return v+"A"; } public static String tmp(String a) { for(int i=0;i<3;i++) a = a + "a"; a = addA(a); return a; //t(sigma_r0|ext_a+"a")|| ext_a } public static void main(String[] args) { /* String a="a"; String b="b"; for(int i=0;i<2;i++) { a=a+b+"a"; Logger.reportString(a,"Concat.NestedLoop_Branch"); for(int j=0;j<2;j++) { long time=(int)(Math.random()*100); if(time % 2 ==0) { b=b+"b"; } else{ b=b+"t"; } } } */ /* String a="a"; String b="b"; String c="c"; String e="l"; for(int i=0;i<3;i++) { a=a+b; b=b+c; long time=(int)(Math.random()*100); if(time % 2 ==0) { c=c+a+"c"; } else{ c=c+a+"d"; } Logger.reportString(c,"Concat.CircleLoop_Branch"); } */ String a="a"; String b="b"; StringBuilder c = new StringBuilder(); c.append("ccc"); b = b + c;
Logger.reportString(b,"Concat.NestedLoop");
USC-SQL/Violist
src/usc/sql/string/RegionNode.java
// Path: src/usc/sql/ir/Variable.java // abstract public class Variable implements Serializable{ // // /** // * // */ // private static final long serialVersionUID = 1L; // private Variable parent = null; // private Set<String> interpretedValue = null; // private List<String> interpretedValueL = null; // //private List<Variable> children = new ArrayList<>(); // public void setInterpretedValue(Set<String> intpValue) {this.interpretedValue = intpValue;} // public void setInterpretedValueL(List<String> intpValue) {this.interpretedValueL = intpValue;} // public Set<String> getInterpretedValue() {return this.interpretedValue;} // public List<String> getInterpretedValueL() {return this.interpretedValueL;} // public void setParent(Variable parent) {this.parent = parent;} // public Variable getParent(){return parent;} // //public List<Variable> getChildren(){return children;} // public abstract String getValue(); // public abstract String toString(); // public int getSize() {return 1;} // }
import java.util.ArrayList; import java.util.List; import java.util.Map; import usc.sql.ir.Variable; import edu.usc.sql.graphs.EdgeInterface; import edu.usc.sql.graphs.NodeInterface;
package usc.sql.string; public class RegionNode { private List<NodeInterface> nodeList = new ArrayList<>(); private RegionNode parent; private List<RegionNode> children = new ArrayList<>(); private EdgeInterface backedge; private int regionNumber;
// Path: src/usc/sql/ir/Variable.java // abstract public class Variable implements Serializable{ // // /** // * // */ // private static final long serialVersionUID = 1L; // private Variable parent = null; // private Set<String> interpretedValue = null; // private List<String> interpretedValueL = null; // //private List<Variable> children = new ArrayList<>(); // public void setInterpretedValue(Set<String> intpValue) {this.interpretedValue = intpValue;} // public void setInterpretedValueL(List<String> intpValue) {this.interpretedValueL = intpValue;} // public Set<String> getInterpretedValue() {return this.interpretedValue;} // public List<String> getInterpretedValueL() {return this.interpretedValueL;} // public void setParent(Variable parent) {this.parent = parent;} // public Variable getParent(){return parent;} // //public List<Variable> getChildren(){return children;} // public abstract String getValue(); // public abstract String toString(); // public int getSize() {return 1;} // } // Path: src/usc/sql/string/RegionNode.java import java.util.ArrayList; import java.util.List; import java.util.Map; import usc.sql.ir.Variable; import edu.usc.sql.graphs.EdgeInterface; import edu.usc.sql.graphs.NodeInterface; package usc.sql.string; public class RegionNode { private List<NodeInterface> nodeList = new ArrayList<>(); private RegionNode parent; private List<RegionNode> children = new ArrayList<>(); private EdgeInterface backedge; private int regionNumber;
private Map<String,ArrayList<Variable>> useMap;
MizzleDK/Mizuu
app/src/main/java/com/miz/mizuu/fragments/Prefs.java
// Path: app/src/main/java/com/miz/utils/FileUtils.java // public class FileUtils { // // private FileUtils() {} // No instantiation! // // public static File getDatabaseFile(Context context) { // return context.getDatabasePath(DatabaseHelper.DATABASE_NAME); // } // // public static void copyFile(File src, File dst) throws IOException { // InputStream in = new FileInputStream(src); // OutputStream out = new FileOutputStream(dst); // // // Transfer bytes from in to out // byte[] buf = new byte[1024]; // int len; // while ((len = in.read(buf)) > 0) { // out.write(buf, 0, len); // } // in.close(); // out.close(); // } // // public static void deleteRecursive(File fileOrDirectory, boolean deleteTopFolder) { // if (fileOrDirectory.isDirectory()) { // File[] listFiles = fileOrDirectory.listFiles(); // if (listFiles != null) { // int count = listFiles.length; // for (int i = 0; i < count; i++) // deleteRecursive(listFiles[i], true); // } // } // // if (deleteTopFolder) // fileOrDirectory.delete(); // } // // public static File getMovieThumb(Context c, String movieId) { // return new File(MizuuApplication.getMovieThumbFolder(c), movieId + ".jpg"); // } // // public static File getMovieBackdrop(Context c, String movieId) { // return new File(MizuuApplication.getMovieBackdropFolder(c), movieId + "_bg.jpg"); // } // // public static File getTvShowThumb(Context c, String showId) { // return new File(MizuuApplication.getTvShowThumbFolder(c), showId + ".jpg"); // } // // public static File getTvShowBackdrop(Context c, String showId) { // return new File(MizuuApplication.getTvShowBackdropFolder(c), showId + "_tvbg.jpg"); // } // // public static File getTvShowEpisode(Context c, String showId, String season, String episode) { // return new File(MizuuApplication.getTvShowEpisodeFolder(c), showId + "_S" + MizLib.addIndexZero(season) + "E" + MizLib.addIndexZero(episode) + ".jpg"); // } // // public static File getTvShowEpisode(Context c, String showId, int season, int episode) { // return getTvShowEpisode(c, showId, String.valueOf(season), String.valueOf(episode)); // } // // public static File getTvShowSeason(Context c, String showId, String season) { // return new File(MizuuApplication.getTvShowSeasonFolder(c), showId + "_S" + MizLib.addIndexZero(season) + ".jpg"); // } // // public static File getTvShowSeason(Context c, String showId, int season) { // return getTvShowSeason(c, showId, String.valueOf(season)); // } // // public static File getOfflineFile(Context c, String filepath) { // return new File(MizuuApplication.getAvailableOfflineFolder(c), MizLib.md5(filepath) + "." + StringUtils.getExtension(filepath)); // } // // public static boolean hasOfflineCopy(Context c, Filepath path) { // return getOfflineCopyFile(c, path).exists(); // } // // private static File getOfflineCopyFile(Context c, Filepath path) { // return getOfflineFile(c, path.getFilepath()); // } // // public static String copyDatabase(Context context) { // try { // File newPath = new File(MizuuApplication.getAppFolder(context), "database.db"); // newPath.createNewFile(); // newPath.setReadable(true); // FileUtils.copyFile(FileUtils.getDatabaseFile(context), newPath); // // return newPath.exists() ? newPath.getAbsolutePath() : null; // } catch (IOException e) { // return null; // } // } // } // // Path: app/src/main/java/com/miz/functions/PreferenceKeys.java // public static final String LANGUAGE_PREFERENCE = "prefsLanguagePreference";
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Locale; import static com.miz.functions.PreferenceKeys.LANGUAGE_PREFERENCE; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.text.TextUtils; import android.widget.Toast; import com.miz.mizuu.R; import com.miz.utils.FileUtils;
/* * Copyright (C) 2014 Michell Bak * * 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.miz.mizuu.fragments; public class Prefs extends PreferenceFragment { private Preference mLanguagePref, mCopyDatabase; private Locale[] mSystemLocales; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int res=getActivity().getResources().getIdentifier(getArguments().getString("resource"), "xml", getActivity().getPackageName()); addPreferencesFromResource(res); mCopyDatabase = getPreferenceScreen().findPreference("prefsCopyDatabase"); if (mCopyDatabase != null) mCopyDatabase.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) {
// Path: app/src/main/java/com/miz/utils/FileUtils.java // public class FileUtils { // // private FileUtils() {} // No instantiation! // // public static File getDatabaseFile(Context context) { // return context.getDatabasePath(DatabaseHelper.DATABASE_NAME); // } // // public static void copyFile(File src, File dst) throws IOException { // InputStream in = new FileInputStream(src); // OutputStream out = new FileOutputStream(dst); // // // Transfer bytes from in to out // byte[] buf = new byte[1024]; // int len; // while ((len = in.read(buf)) > 0) { // out.write(buf, 0, len); // } // in.close(); // out.close(); // } // // public static void deleteRecursive(File fileOrDirectory, boolean deleteTopFolder) { // if (fileOrDirectory.isDirectory()) { // File[] listFiles = fileOrDirectory.listFiles(); // if (listFiles != null) { // int count = listFiles.length; // for (int i = 0; i < count; i++) // deleteRecursive(listFiles[i], true); // } // } // // if (deleteTopFolder) // fileOrDirectory.delete(); // } // // public static File getMovieThumb(Context c, String movieId) { // return new File(MizuuApplication.getMovieThumbFolder(c), movieId + ".jpg"); // } // // public static File getMovieBackdrop(Context c, String movieId) { // return new File(MizuuApplication.getMovieBackdropFolder(c), movieId + "_bg.jpg"); // } // // public static File getTvShowThumb(Context c, String showId) { // return new File(MizuuApplication.getTvShowThumbFolder(c), showId + ".jpg"); // } // // public static File getTvShowBackdrop(Context c, String showId) { // return new File(MizuuApplication.getTvShowBackdropFolder(c), showId + "_tvbg.jpg"); // } // // public static File getTvShowEpisode(Context c, String showId, String season, String episode) { // return new File(MizuuApplication.getTvShowEpisodeFolder(c), showId + "_S" + MizLib.addIndexZero(season) + "E" + MizLib.addIndexZero(episode) + ".jpg"); // } // // public static File getTvShowEpisode(Context c, String showId, int season, int episode) { // return getTvShowEpisode(c, showId, String.valueOf(season), String.valueOf(episode)); // } // // public static File getTvShowSeason(Context c, String showId, String season) { // return new File(MizuuApplication.getTvShowSeasonFolder(c), showId + "_S" + MizLib.addIndexZero(season) + ".jpg"); // } // // public static File getTvShowSeason(Context c, String showId, int season) { // return getTvShowSeason(c, showId, String.valueOf(season)); // } // // public static File getOfflineFile(Context c, String filepath) { // return new File(MizuuApplication.getAvailableOfflineFolder(c), MizLib.md5(filepath) + "." + StringUtils.getExtension(filepath)); // } // // public static boolean hasOfflineCopy(Context c, Filepath path) { // return getOfflineCopyFile(c, path).exists(); // } // // private static File getOfflineCopyFile(Context c, Filepath path) { // return getOfflineFile(c, path.getFilepath()); // } // // public static String copyDatabase(Context context) { // try { // File newPath = new File(MizuuApplication.getAppFolder(context), "database.db"); // newPath.createNewFile(); // newPath.setReadable(true); // FileUtils.copyFile(FileUtils.getDatabaseFile(context), newPath); // // return newPath.exists() ? newPath.getAbsolutePath() : null; // } catch (IOException e) { // return null; // } // } // } // // Path: app/src/main/java/com/miz/functions/PreferenceKeys.java // public static final String LANGUAGE_PREFERENCE = "prefsLanguagePreference"; // Path: app/src/main/java/com/miz/mizuu/fragments/Prefs.java import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Locale; import static com.miz.functions.PreferenceKeys.LANGUAGE_PREFERENCE; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.text.TextUtils; import android.widget.Toast; import com.miz.mizuu.R; import com.miz.utils.FileUtils; /* * Copyright (C) 2014 Michell Bak * * 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.miz.mizuu.fragments; public class Prefs extends PreferenceFragment { private Preference mLanguagePref, mCopyDatabase; private Locale[] mSystemLocales; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int res=getActivity().getResources().getIdentifier(getArguments().getString("resource"), "xml", getActivity().getPackageName()); addPreferencesFromResource(res); mCopyDatabase = getPreferenceScreen().findPreference("prefsCopyDatabase"); if (mCopyDatabase != null) mCopyDatabase.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) {
String path = FileUtils.copyDatabase(getActivity());
MizzleDK/Mizuu
app/src/main/java/com/miz/functions/GridSeason.java
// Path: app/src/main/java/com/miz/functions/PreferenceKeys.java // public static final String TVSHOWS_COLLECTION_LAYOUT = "prefsSeasonsLayout";
import android.content.Context; import android.preference.PreferenceManager; import com.miz.mizuu.R; import java.io.File; import static com.miz.functions.PreferenceKeys.TVSHOWS_COLLECTION_LAYOUT;
/* * Copyright (C) 2014 Michell Bak * * 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.miz.functions; public class GridSeason implements Comparable<GridSeason> { private Context mContext; private String mShowId, mHeaderText, mSubtitleText, mSubtitleTextSimple; private int mSeason, mEpisodeCount, mWatchedCount; private boolean mUseGridView; private File mCover; public GridSeason(Context context, String showId, int season, int episodeCount, int watchedCount, File cover) { mContext = context; mShowId = showId; mSeason = season; mEpisodeCount = episodeCount; mWatchedCount = watchedCount; mCover = cover;
// Path: app/src/main/java/com/miz/functions/PreferenceKeys.java // public static final String TVSHOWS_COLLECTION_LAYOUT = "prefsSeasonsLayout"; // Path: app/src/main/java/com/miz/functions/GridSeason.java import android.content.Context; import android.preference.PreferenceManager; import com.miz.mizuu.R; import java.io.File; import static com.miz.functions.PreferenceKeys.TVSHOWS_COLLECTION_LAYOUT; /* * Copyright (C) 2014 Michell Bak * * 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.miz.functions; public class GridSeason implements Comparable<GridSeason> { private Context mContext; private String mShowId, mHeaderText, mSubtitleText, mSubtitleTextSimple; private int mSeason, mEpisodeCount, mWatchedCount; private boolean mUseGridView; private File mCover; public GridSeason(Context context, String showId, int season, int episodeCount, int watchedCount, File cover) { mContext = context; mShowId = showId; mSeason = season; mEpisodeCount = episodeCount; mWatchedCount = watchedCount; mCover = cover;
mUseGridView = PreferenceManager.getDefaultSharedPreferences(mContext).getString(TVSHOWS_COLLECTION_LAYOUT, mContext.getString(R.string.gridView)).equals(mContext.getString(R.string.gridView));
cfloersch/RtspClient
src/main/java/xpertss/mime/Headers.java
// Path: src/main/java/xpertss/utils/Utils.java // public class Utils { // // /** // * Creates and returns an {@link InetSocketAddress} that represents the authority // * of the given {@link java.net.URI}. If the {@link java.net.URI} does not define // * a port then the specified default port is used instead. // * // * @throws NullPointerException if uri is {@code null} // * @throws IllegalArgumentException if the port is outside the range 1 - 65545 // */ // public static SocketAddress createSocketAddress(URI uri, int defPort) // { // String authority = uri.getAuthority(); // if(Strings.isEmpty(authority)) // throw new IllegalArgumentException("uri does not define an authority"); // String[] parts = authority.split(":"); // int port = defPort; // if(parts.length == 2) { // port = Integers.parse(parts[1], defPort); // Numbers.within(1, 65545, port, String.format("%d is an invalid port", port)); // } // return new InetSocketAddress(parts[0], port); // } // // // // // public static <T> T get(T[] items, int index) // { // if(items == null || index < 0) return null; // return (items.length > index) ? items[index] : null; // } // // // public static String trimAndClear(StringBuilder buf) // { // return getAndClear(buf).trim(); // } // // public static String getAndClear(StringBuilder buf) // { // try { // return buf.toString(); // } finally { // buf.setLength(0); // } // } // // // public static long computeTimeout(int millis) // { // if(millis == 0) millis = 60000; // default timeout of 60 seconds // return System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(millis); // } // // // // // // // public static String consume(CharBuffer buf, boolean trim) // { // buf.flip(); // int offset = 0; int end = buf.limit(); // if(trim) { // while(offset < end && buf.get(offset) == ' ') offset++; // while(end > offset && buf.get(end - 1) == ' ') end--; // } // char[] result = new char[end-offset]; // buf.position(offset); // buf.get(result).clear(); // return new String(result); // } // // // public static boolean isWhiteSpace(char c) // { // return (c == '\t' || c == '\r' || c == '\n' || c == ' '); // } // // // public static int maxIfZero(int value) // { // return (value == 0) ? Integer.MAX_VALUE : value; // } // // // public static String getHeader(RtspResponse response, String name) // { // return Headers.toString(response.getHeaders().getHeader(name)); // } // // }
import xpertss.function.Predicate; import xpertss.function.Predicates; import xpertss.lang.Integers; import xpertss.lang.Objects; import xpertss.lang.Strings; import xpertss.utils.Utils; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.NoSuchElementException;
/** * Returns the set of headers with one header per line */ @Override public String toString() { StringBuilder builder = new StringBuilder(); for(Enumeration<Header> e = headers(); e.hasMoreElements(); ) { builder.append(e.nextElement()).append("\r\n"); } return builder.toString(); } public static Headers create(List<String> raw) { List<Header> headers = new ArrayList<Header>(); StringBuilder header = new StringBuilder(); for(int i = raw.size() - 1; i >= 0; i--) { header.insert(0, raw.get(i));
// Path: src/main/java/xpertss/utils/Utils.java // public class Utils { // // /** // * Creates and returns an {@link InetSocketAddress} that represents the authority // * of the given {@link java.net.URI}. If the {@link java.net.URI} does not define // * a port then the specified default port is used instead. // * // * @throws NullPointerException if uri is {@code null} // * @throws IllegalArgumentException if the port is outside the range 1 - 65545 // */ // public static SocketAddress createSocketAddress(URI uri, int defPort) // { // String authority = uri.getAuthority(); // if(Strings.isEmpty(authority)) // throw new IllegalArgumentException("uri does not define an authority"); // String[] parts = authority.split(":"); // int port = defPort; // if(parts.length == 2) { // port = Integers.parse(parts[1], defPort); // Numbers.within(1, 65545, port, String.format("%d is an invalid port", port)); // } // return new InetSocketAddress(parts[0], port); // } // // // // // public static <T> T get(T[] items, int index) // { // if(items == null || index < 0) return null; // return (items.length > index) ? items[index] : null; // } // // // public static String trimAndClear(StringBuilder buf) // { // return getAndClear(buf).trim(); // } // // public static String getAndClear(StringBuilder buf) // { // try { // return buf.toString(); // } finally { // buf.setLength(0); // } // } // // // public static long computeTimeout(int millis) // { // if(millis == 0) millis = 60000; // default timeout of 60 seconds // return System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(millis); // } // // // // // // // public static String consume(CharBuffer buf, boolean trim) // { // buf.flip(); // int offset = 0; int end = buf.limit(); // if(trim) { // while(offset < end && buf.get(offset) == ' ') offset++; // while(end > offset && buf.get(end - 1) == ' ') end--; // } // char[] result = new char[end-offset]; // buf.position(offset); // buf.get(result).clear(); // return new String(result); // } // // // public static boolean isWhiteSpace(char c) // { // return (c == '\t' || c == '\r' || c == '\n' || c == ' '); // } // // // public static int maxIfZero(int value) // { // return (value == 0) ? Integer.MAX_VALUE : value; // } // // // public static String getHeader(RtspResponse response, String name) // { // return Headers.toString(response.getHeaders().getHeader(name)); // } // // } // Path: src/main/java/xpertss/mime/Headers.java import xpertss.function.Predicate; import xpertss.function.Predicates; import xpertss.lang.Integers; import xpertss.lang.Objects; import xpertss.lang.Strings; import xpertss.utils.Utils; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.NoSuchElementException; /** * Returns the set of headers with one header per line */ @Override public String toString() { StringBuilder builder = new StringBuilder(); for(Enumeration<Header> e = headers(); e.hasMoreElements(); ) { builder.append(e.nextElement()).append("\r\n"); } return builder.toString(); } public static Headers create(List<String> raw) { List<Header> headers = new ArrayList<Header>(); StringBuilder header = new StringBuilder(); for(int i = raw.size() - 1; i >= 0; i--) { header.insert(0, raw.get(i));
if(!Utils.isWhiteSpace(header.charAt(0))) {
cfloersch/RtspClient
src/main/java/xpertss/mime/impl/NamedHeaderValue.java
// Path: src/main/java/xpertss/mime/HeaderValue.java // public interface HeaderValue { // // // /** // * Ths will return the value's name or {@code null} if it is not a // * named value. // */ // public String getName(); // // /** // * This will return the value's value. // */ // public String getValue(); // // // // // // /** // * Returns the number of parameters this header value contains. // */ // public int size(); // // /** // * Returns the parameter at the specified index. // */ // public Parameter getParameter(int index); // // /** // * Returns the specified named parameter if it exists. // */ // public Parameter getParameter(String name); // // // // /** // * Return a formatted string representation of this header value and its // * parameters. // */ // public String toString(); // // } // // Path: src/main/java/xpertss/mime/Parameter.java // public interface Parameter { // // // /** // * Returns the parameter name as a String or {@code null} if this is a simple // * parameter. // */ // public String getName(); // // /** // * Returns the parameter value as a String. // */ // public String getValue(); // // // /** // * Returns this parameter as a fully formatted string. // */ // public String toString(); // // }
import xpertss.mime.HeaderValue; import xpertss.mime.Parameter; import xpertss.lang.Objects; import xpertss.lang.Strings;
/** * Copyright XpertSoftware All rights reserved. * * Date: 3/18/11 9:45 PM */ package xpertss.mime.impl; public class NamedHeaderValue implements HeaderValue { private final String name; private final String value;
// Path: src/main/java/xpertss/mime/HeaderValue.java // public interface HeaderValue { // // // /** // * Ths will return the value's name or {@code null} if it is not a // * named value. // */ // public String getName(); // // /** // * This will return the value's value. // */ // public String getValue(); // // // // // // /** // * Returns the number of parameters this header value contains. // */ // public int size(); // // /** // * Returns the parameter at the specified index. // */ // public Parameter getParameter(int index); // // /** // * Returns the specified named parameter if it exists. // */ // public Parameter getParameter(String name); // // // // /** // * Return a formatted string representation of this header value and its // * parameters. // */ // public String toString(); // // } // // Path: src/main/java/xpertss/mime/Parameter.java // public interface Parameter { // // // /** // * Returns the parameter name as a String or {@code null} if this is a simple // * parameter. // */ // public String getName(); // // /** // * Returns the parameter value as a String. // */ // public String getValue(); // // // /** // * Returns this parameter as a fully formatted string. // */ // public String toString(); // // } // Path: src/main/java/xpertss/mime/impl/NamedHeaderValue.java import xpertss.mime.HeaderValue; import xpertss.mime.Parameter; import xpertss.lang.Objects; import xpertss.lang.Strings; /** * Copyright XpertSoftware All rights reserved. * * Date: 3/18/11 9:45 PM */ package xpertss.mime.impl; public class NamedHeaderValue implements HeaderValue { private final String name; private final String value;
private final Parameter[] params;
cfloersch/RtspClient
src/main/java/xpertss/mime/impl/ComplexValueHeader.java
// Path: src/main/java/xpertss/mime/Header.java // public interface Header { // // /** // * Http defines four types of headers. All headers not specifically // * defined to be general, request, or response are treated as entity // * headers. // */ // public enum Type { // /** // * A general header is one that may be included in either the request or // * response and is applied to the overall message itself. // */ // General, // // /** // * A request header is applied only to impl requests and applies to the // * message overall. // */ // Request, // // /** // * A response header is applied only to impl responses and applies to the // * message overall. // */ // Response, // // /** // * An entity header defines the entity contained within the message. // */ // Entity, // // /** // * A raw header is any header for which a defined parser was not found. // * These are typically non-standard headers and will always return an // * unparsed raw string when getValue is called. // */ // Raw // } // // // /** // * Returns the header name as a String. // */ // public String getName(); // // /** // * Returns a fully formatted value line including all values and their // * associated parameters. This method provides an easier means of access // * to simple values. // */ // public String getValue(); // // /** // * Returns the header type this header represents. // */ // public Type getType(); // // // /** // * Returns the number of values this header contains. // */ // public int size(); // // /** // * Returns the header value at the specified index. // */ // public HeaderValue getValue(int index); // // /** // * Returns the specified named header value if it exists. // */ // public HeaderValue getValue(String name); // // // /** // * Return a formatted string representation of this header and its values // * and parameters. // */ // public String toString(); // // // } // // Path: src/main/java/xpertss/mime/HeaderValue.java // public interface HeaderValue { // // // /** // * Ths will return the value's name or {@code null} if it is not a // * named value. // */ // public String getName(); // // /** // * This will return the value's value. // */ // public String getValue(); // // // // // // /** // * Returns the number of parameters this header value contains. // */ // public int size(); // // /** // * Returns the parameter at the specified index. // */ // public Parameter getParameter(int index); // // /** // * Returns the specified named parameter if it exists. // */ // public Parameter getParameter(String name); // // // // /** // * Return a formatted string representation of this header value and its // * parameters. // */ // public String toString(); // // }
import xpertss.mime.Header; import xpertss.mime.HeaderValue; import xpertss.lang.Objects; import xpertss.lang.Strings;
/** * Copyright XpertSoftware All rights reserved. * * Date: 3/18/11 11:55 PM */ package xpertss.mime.impl; public class ComplexValueHeader implements Header { private final String name; private final Type type;
// Path: src/main/java/xpertss/mime/Header.java // public interface Header { // // /** // * Http defines four types of headers. All headers not specifically // * defined to be general, request, or response are treated as entity // * headers. // */ // public enum Type { // /** // * A general header is one that may be included in either the request or // * response and is applied to the overall message itself. // */ // General, // // /** // * A request header is applied only to impl requests and applies to the // * message overall. // */ // Request, // // /** // * A response header is applied only to impl responses and applies to the // * message overall. // */ // Response, // // /** // * An entity header defines the entity contained within the message. // */ // Entity, // // /** // * A raw header is any header for which a defined parser was not found. // * These are typically non-standard headers and will always return an // * unparsed raw string when getValue is called. // */ // Raw // } // // // /** // * Returns the header name as a String. // */ // public String getName(); // // /** // * Returns a fully formatted value line including all values and their // * associated parameters. This method provides an easier means of access // * to simple values. // */ // public String getValue(); // // /** // * Returns the header type this header represents. // */ // public Type getType(); // // // /** // * Returns the number of values this header contains. // */ // public int size(); // // /** // * Returns the header value at the specified index. // */ // public HeaderValue getValue(int index); // // /** // * Returns the specified named header value if it exists. // */ // public HeaderValue getValue(String name); // // // /** // * Return a formatted string representation of this header and its values // * and parameters. // */ // public String toString(); // // // } // // Path: src/main/java/xpertss/mime/HeaderValue.java // public interface HeaderValue { // // // /** // * Ths will return the value's name or {@code null} if it is not a // * named value. // */ // public String getName(); // // /** // * This will return the value's value. // */ // public String getValue(); // // // // // // /** // * Returns the number of parameters this header value contains. // */ // public int size(); // // /** // * Returns the parameter at the specified index. // */ // public Parameter getParameter(int index); // // /** // * Returns the specified named parameter if it exists. // */ // public Parameter getParameter(String name); // // // // /** // * Return a formatted string representation of this header value and its // * parameters. // */ // public String toString(); // // } // Path: src/main/java/xpertss/mime/impl/ComplexValueHeader.java import xpertss.mime.Header; import xpertss.mime.HeaderValue; import xpertss.lang.Objects; import xpertss.lang.Strings; /** * Copyright XpertSoftware All rights reserved. * * Date: 3/18/11 11:55 PM */ package xpertss.mime.impl; public class ComplexValueHeader implements Header { private final String name; private final Type type;
private final HeaderValue[] values;
cfloersch/RtspClient
src/test/java/xpertss/rtsp/RtspClientTest.java
// Path: src/main/java/xpertss/media/MediaChannel.java // public class MediaChannel implements Comparable<MediaChannel> { // // private final MediaDescription desc; // private final Range<Integer> channels; // // public MediaChannel(MediaDescription desc, Range<Integer> channels) // { // this.desc = Objects.notNull(desc); // this.channels = Objects.notNull(channels); // } // // /** // * The full media description of the data this channel will // * process. // */ // public MediaDescription getMedia() // { // return desc; // } // // /** // * A control identifier for the channel. // */ // public String getControl() // { // Attribute attr = desc.getAttribute("control"); // return (attr != null) ? attr.getValue() : null; // } // // // /** // * The media type this channel will process. // */ // public MediaType getType() // { // return MediaType.parse(desc); // } // // /** // * The channel identifiers over which this media will be transmitted. // * <p/> // * The media data is usually transmitted over the lower of the two // * channel identifiers while control information for the channel is // * transmitted over the higher channel. // */ // public Range<Integer> getChannels() // { // return channels; // } // // // /** // * Compares this media channel to another based on its channel identifiers. // */ // @Override // public int compareTo(MediaChannel o) // { // return channels.compareTo(o.channels); // } // // } // // Path: src/main/java/xpertss/media/MediaConsumer.java // public interface MediaConsumer { // // /** // * Given a session description return the media descriptions the // * consumer wishes to be setup for playback. // */ // public MediaDescription[] select(SessionDescription sdp); // // // /** // * For each media description desired this will be called by the // * player to inform it that the channel has been successfully // * setup and to identify the channel identifiers associated with // * it. // */ // public void createChannel(MediaChannel channel); // // /** // * Called to indicate that the previously created channels should // * be destroyed as they are no longer valid. // */ // public void destroyChannels(); // // // // /** // * Once playback has begun the actual channel data will be delivered // * to the consumer via this method. The channelId will be one of the // * identifiers previously communicated to the newChannel callback. // */ // public void consume(int channelId, ByteBuffer data); // // // /** // * Called to notify the consumer of an error that has terminated // * playback. // */ // public void handle(Throwable t); // // } // // Path: src/main/java/xpertss/media/MediaType.java // public enum MediaType { // // Audio, Video, Text, Application, Message; // // // public static MediaType parse(MediaDescription desc) // { // String mediaType = desc.getMedia().getType(); // if("Audio".equalsIgnoreCase(mediaType)) { // return Audio; // } else if("Video".equalsIgnoreCase(mediaType)) { // return Video; // } else if("Text".equalsIgnoreCase(mediaType)) { // return Text; // } else if("Application".equalsIgnoreCase(mediaType)) { // return Application; // } else if("Message".equalsIgnoreCase(mediaType)) { // return Message; // } // return null; // } // }
import org.junit.Test; import xpertss.function.Consumer; import xpertss.lang.Range; import xpertss.media.MediaChannel; import xpertss.media.MediaConsumer; import xpertss.media.MediaType; import xpertss.sdp.MediaDescription; import xpertss.sdp.SessionDescription; import xpertss.threads.Threads; import java.net.ConnectException; import java.net.URI; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static xpertss.nio.ReadyState.Closed; import static xpertss.nio.ReadyState.Closing; import static xpertss.nio.ReadyState.Connected; import static xpertss.nio.ReadyState.Connecting; import static xpertss.nio.ReadyState.Open;
verify(handler, times(1)).onFailure(same(session), any(ConnectException.class)); assertEquals(Closed, session.getReadyState()); } @Test public void testClientConnectSequenceUnknownHost() { RtspHandler handler = mock(RtspHandler.class); RtspClient client = new RtspClient(); RtspSession session = client.open(handler, URI.create("rtsp://doesnot.exist.host.com:999/AVAIL.sdp")); assertEquals(Open, session.getReadyState()); session.connect(100); assertEquals(Connecting, session.getReadyState()); while(session.getReadyState() == Connecting); verify(handler, times(1)).onFailure(same(session), any(UnknownHostException.class)); assertEquals(Closed, session.getReadyState()); } @Test public void testRtspPlayer() { RtspClient client = new RtspClient();
// Path: src/main/java/xpertss/media/MediaChannel.java // public class MediaChannel implements Comparable<MediaChannel> { // // private final MediaDescription desc; // private final Range<Integer> channels; // // public MediaChannel(MediaDescription desc, Range<Integer> channels) // { // this.desc = Objects.notNull(desc); // this.channels = Objects.notNull(channels); // } // // /** // * The full media description of the data this channel will // * process. // */ // public MediaDescription getMedia() // { // return desc; // } // // /** // * A control identifier for the channel. // */ // public String getControl() // { // Attribute attr = desc.getAttribute("control"); // return (attr != null) ? attr.getValue() : null; // } // // // /** // * The media type this channel will process. // */ // public MediaType getType() // { // return MediaType.parse(desc); // } // // /** // * The channel identifiers over which this media will be transmitted. // * <p/> // * The media data is usually transmitted over the lower of the two // * channel identifiers while control information for the channel is // * transmitted over the higher channel. // */ // public Range<Integer> getChannels() // { // return channels; // } // // // /** // * Compares this media channel to another based on its channel identifiers. // */ // @Override // public int compareTo(MediaChannel o) // { // return channels.compareTo(o.channels); // } // // } // // Path: src/main/java/xpertss/media/MediaConsumer.java // public interface MediaConsumer { // // /** // * Given a session description return the media descriptions the // * consumer wishes to be setup for playback. // */ // public MediaDescription[] select(SessionDescription sdp); // // // /** // * For each media description desired this will be called by the // * player to inform it that the channel has been successfully // * setup and to identify the channel identifiers associated with // * it. // */ // public void createChannel(MediaChannel channel); // // /** // * Called to indicate that the previously created channels should // * be destroyed as they are no longer valid. // */ // public void destroyChannels(); // // // // /** // * Once playback has begun the actual channel data will be delivered // * to the consumer via this method. The channelId will be one of the // * identifiers previously communicated to the newChannel callback. // */ // public void consume(int channelId, ByteBuffer data); // // // /** // * Called to notify the consumer of an error that has terminated // * playback. // */ // public void handle(Throwable t); // // } // // Path: src/main/java/xpertss/media/MediaType.java // public enum MediaType { // // Audio, Video, Text, Application, Message; // // // public static MediaType parse(MediaDescription desc) // { // String mediaType = desc.getMedia().getType(); // if("Audio".equalsIgnoreCase(mediaType)) { // return Audio; // } else if("Video".equalsIgnoreCase(mediaType)) { // return Video; // } else if("Text".equalsIgnoreCase(mediaType)) { // return Text; // } else if("Application".equalsIgnoreCase(mediaType)) { // return Application; // } else if("Message".equalsIgnoreCase(mediaType)) { // return Message; // } // return null; // } // } // Path: src/test/java/xpertss/rtsp/RtspClientTest.java import org.junit.Test; import xpertss.function.Consumer; import xpertss.lang.Range; import xpertss.media.MediaChannel; import xpertss.media.MediaConsumer; import xpertss.media.MediaType; import xpertss.sdp.MediaDescription; import xpertss.sdp.SessionDescription; import xpertss.threads.Threads; import java.net.ConnectException; import java.net.URI; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static xpertss.nio.ReadyState.Closed; import static xpertss.nio.ReadyState.Closing; import static xpertss.nio.ReadyState.Connected; import static xpertss.nio.ReadyState.Connecting; import static xpertss.nio.ReadyState.Open; verify(handler, times(1)).onFailure(same(session), any(ConnectException.class)); assertEquals(Closed, session.getReadyState()); } @Test public void testClientConnectSequenceUnknownHost() { RtspHandler handler = mock(RtspHandler.class); RtspClient client = new RtspClient(); RtspSession session = client.open(handler, URI.create("rtsp://doesnot.exist.host.com:999/AVAIL.sdp")); assertEquals(Open, session.getReadyState()); session.connect(100); assertEquals(Connecting, session.getReadyState()); while(session.getReadyState() == Connecting); verify(handler, times(1)).onFailure(same(session), any(UnknownHostException.class)); assertEquals(Closed, session.getReadyState()); } @Test public void testRtspPlayer() { RtspClient client = new RtspClient();
RtspPlayer player = new RtspPlayer(client, new MediaConsumer() {
cfloersch/RtspClient
src/test/java/xpertss/rtsp/RtspClientTest.java
// Path: src/main/java/xpertss/media/MediaChannel.java // public class MediaChannel implements Comparable<MediaChannel> { // // private final MediaDescription desc; // private final Range<Integer> channels; // // public MediaChannel(MediaDescription desc, Range<Integer> channels) // { // this.desc = Objects.notNull(desc); // this.channels = Objects.notNull(channels); // } // // /** // * The full media description of the data this channel will // * process. // */ // public MediaDescription getMedia() // { // return desc; // } // // /** // * A control identifier for the channel. // */ // public String getControl() // { // Attribute attr = desc.getAttribute("control"); // return (attr != null) ? attr.getValue() : null; // } // // // /** // * The media type this channel will process. // */ // public MediaType getType() // { // return MediaType.parse(desc); // } // // /** // * The channel identifiers over which this media will be transmitted. // * <p/> // * The media data is usually transmitted over the lower of the two // * channel identifiers while control information for the channel is // * transmitted over the higher channel. // */ // public Range<Integer> getChannels() // { // return channels; // } // // // /** // * Compares this media channel to another based on its channel identifiers. // */ // @Override // public int compareTo(MediaChannel o) // { // return channels.compareTo(o.channels); // } // // } // // Path: src/main/java/xpertss/media/MediaConsumer.java // public interface MediaConsumer { // // /** // * Given a session description return the media descriptions the // * consumer wishes to be setup for playback. // */ // public MediaDescription[] select(SessionDescription sdp); // // // /** // * For each media description desired this will be called by the // * player to inform it that the channel has been successfully // * setup and to identify the channel identifiers associated with // * it. // */ // public void createChannel(MediaChannel channel); // // /** // * Called to indicate that the previously created channels should // * be destroyed as they are no longer valid. // */ // public void destroyChannels(); // // // // /** // * Once playback has begun the actual channel data will be delivered // * to the consumer via this method. The channelId will be one of the // * identifiers previously communicated to the newChannel callback. // */ // public void consume(int channelId, ByteBuffer data); // // // /** // * Called to notify the consumer of an error that has terminated // * playback. // */ // public void handle(Throwable t); // // } // // Path: src/main/java/xpertss/media/MediaType.java // public enum MediaType { // // Audio, Video, Text, Application, Message; // // // public static MediaType parse(MediaDescription desc) // { // String mediaType = desc.getMedia().getType(); // if("Audio".equalsIgnoreCase(mediaType)) { // return Audio; // } else if("Video".equalsIgnoreCase(mediaType)) { // return Video; // } else if("Text".equalsIgnoreCase(mediaType)) { // return Text; // } else if("Application".equalsIgnoreCase(mediaType)) { // return Application; // } else if("Message".equalsIgnoreCase(mediaType)) { // return Message; // } // return null; // } // }
import org.junit.Test; import xpertss.function.Consumer; import xpertss.lang.Range; import xpertss.media.MediaChannel; import xpertss.media.MediaConsumer; import xpertss.media.MediaType; import xpertss.sdp.MediaDescription; import xpertss.sdp.SessionDescription; import xpertss.threads.Threads; import java.net.ConnectException; import java.net.URI; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static xpertss.nio.ReadyState.Closed; import static xpertss.nio.ReadyState.Closing; import static xpertss.nio.ReadyState.Connected; import static xpertss.nio.ReadyState.Connecting; import static xpertss.nio.ReadyState.Open;
assertEquals(Open, session.getReadyState()); session.connect(100); assertEquals(Connecting, session.getReadyState()); while(session.getReadyState() == Connecting); verify(handler, times(1)).onFailure(same(session), any(UnknownHostException.class)); assertEquals(Closed, session.getReadyState()); } @Test public void testRtspPlayer() { RtspClient client = new RtspClient(); RtspPlayer player = new RtspPlayer(client, new MediaConsumer() { private Map<Integer,Consumer<ByteBuffer>> channels = new HashMap<>(); @Override public MediaDescription[] select(SessionDescription sdp) { return sdp.getMediaDescriptions(); } @Override
// Path: src/main/java/xpertss/media/MediaChannel.java // public class MediaChannel implements Comparable<MediaChannel> { // // private final MediaDescription desc; // private final Range<Integer> channels; // // public MediaChannel(MediaDescription desc, Range<Integer> channels) // { // this.desc = Objects.notNull(desc); // this.channels = Objects.notNull(channels); // } // // /** // * The full media description of the data this channel will // * process. // */ // public MediaDescription getMedia() // { // return desc; // } // // /** // * A control identifier for the channel. // */ // public String getControl() // { // Attribute attr = desc.getAttribute("control"); // return (attr != null) ? attr.getValue() : null; // } // // // /** // * The media type this channel will process. // */ // public MediaType getType() // { // return MediaType.parse(desc); // } // // /** // * The channel identifiers over which this media will be transmitted. // * <p/> // * The media data is usually transmitted over the lower of the two // * channel identifiers while control information for the channel is // * transmitted over the higher channel. // */ // public Range<Integer> getChannels() // { // return channels; // } // // // /** // * Compares this media channel to another based on its channel identifiers. // */ // @Override // public int compareTo(MediaChannel o) // { // return channels.compareTo(o.channels); // } // // } // // Path: src/main/java/xpertss/media/MediaConsumer.java // public interface MediaConsumer { // // /** // * Given a session description return the media descriptions the // * consumer wishes to be setup for playback. // */ // public MediaDescription[] select(SessionDescription sdp); // // // /** // * For each media description desired this will be called by the // * player to inform it that the channel has been successfully // * setup and to identify the channel identifiers associated with // * it. // */ // public void createChannel(MediaChannel channel); // // /** // * Called to indicate that the previously created channels should // * be destroyed as they are no longer valid. // */ // public void destroyChannels(); // // // // /** // * Once playback has begun the actual channel data will be delivered // * to the consumer via this method. The channelId will be one of the // * identifiers previously communicated to the newChannel callback. // */ // public void consume(int channelId, ByteBuffer data); // // // /** // * Called to notify the consumer of an error that has terminated // * playback. // */ // public void handle(Throwable t); // // } // // Path: src/main/java/xpertss/media/MediaType.java // public enum MediaType { // // Audio, Video, Text, Application, Message; // // // public static MediaType parse(MediaDescription desc) // { // String mediaType = desc.getMedia().getType(); // if("Audio".equalsIgnoreCase(mediaType)) { // return Audio; // } else if("Video".equalsIgnoreCase(mediaType)) { // return Video; // } else if("Text".equalsIgnoreCase(mediaType)) { // return Text; // } else if("Application".equalsIgnoreCase(mediaType)) { // return Application; // } else if("Message".equalsIgnoreCase(mediaType)) { // return Message; // } // return null; // } // } // Path: src/test/java/xpertss/rtsp/RtspClientTest.java import org.junit.Test; import xpertss.function.Consumer; import xpertss.lang.Range; import xpertss.media.MediaChannel; import xpertss.media.MediaConsumer; import xpertss.media.MediaType; import xpertss.sdp.MediaDescription; import xpertss.sdp.SessionDescription; import xpertss.threads.Threads; import java.net.ConnectException; import java.net.URI; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static xpertss.nio.ReadyState.Closed; import static xpertss.nio.ReadyState.Closing; import static xpertss.nio.ReadyState.Connected; import static xpertss.nio.ReadyState.Connecting; import static xpertss.nio.ReadyState.Open; assertEquals(Open, session.getReadyState()); session.connect(100); assertEquals(Connecting, session.getReadyState()); while(session.getReadyState() == Connecting); verify(handler, times(1)).onFailure(same(session), any(UnknownHostException.class)); assertEquals(Closed, session.getReadyState()); } @Test public void testRtspPlayer() { RtspClient client = new RtspClient(); RtspPlayer player = new RtspPlayer(client, new MediaConsumer() { private Map<Integer,Consumer<ByteBuffer>> channels = new HashMap<>(); @Override public MediaDescription[] select(SessionDescription sdp) { return sdp.getMediaDescriptions(); } @Override
public void createChannel(MediaChannel channel)
cfloersch/RtspClient
src/test/java/xpertss/rtsp/RtspClientTest.java
// Path: src/main/java/xpertss/media/MediaChannel.java // public class MediaChannel implements Comparable<MediaChannel> { // // private final MediaDescription desc; // private final Range<Integer> channels; // // public MediaChannel(MediaDescription desc, Range<Integer> channels) // { // this.desc = Objects.notNull(desc); // this.channels = Objects.notNull(channels); // } // // /** // * The full media description of the data this channel will // * process. // */ // public MediaDescription getMedia() // { // return desc; // } // // /** // * A control identifier for the channel. // */ // public String getControl() // { // Attribute attr = desc.getAttribute("control"); // return (attr != null) ? attr.getValue() : null; // } // // // /** // * The media type this channel will process. // */ // public MediaType getType() // { // return MediaType.parse(desc); // } // // /** // * The channel identifiers over which this media will be transmitted. // * <p/> // * The media data is usually transmitted over the lower of the two // * channel identifiers while control information for the channel is // * transmitted over the higher channel. // */ // public Range<Integer> getChannels() // { // return channels; // } // // // /** // * Compares this media channel to another based on its channel identifiers. // */ // @Override // public int compareTo(MediaChannel o) // { // return channels.compareTo(o.channels); // } // // } // // Path: src/main/java/xpertss/media/MediaConsumer.java // public interface MediaConsumer { // // /** // * Given a session description return the media descriptions the // * consumer wishes to be setup for playback. // */ // public MediaDescription[] select(SessionDescription sdp); // // // /** // * For each media description desired this will be called by the // * player to inform it that the channel has been successfully // * setup and to identify the channel identifiers associated with // * it. // */ // public void createChannel(MediaChannel channel); // // /** // * Called to indicate that the previously created channels should // * be destroyed as they are no longer valid. // */ // public void destroyChannels(); // // // // /** // * Once playback has begun the actual channel data will be delivered // * to the consumer via this method. The channelId will be one of the // * identifiers previously communicated to the newChannel callback. // */ // public void consume(int channelId, ByteBuffer data); // // // /** // * Called to notify the consumer of an error that has terminated // * playback. // */ // public void handle(Throwable t); // // } // // Path: src/main/java/xpertss/media/MediaType.java // public enum MediaType { // // Audio, Video, Text, Application, Message; // // // public static MediaType parse(MediaDescription desc) // { // String mediaType = desc.getMedia().getType(); // if("Audio".equalsIgnoreCase(mediaType)) { // return Audio; // } else if("Video".equalsIgnoreCase(mediaType)) { // return Video; // } else if("Text".equalsIgnoreCase(mediaType)) { // return Text; // } else if("Application".equalsIgnoreCase(mediaType)) { // return Application; // } else if("Message".equalsIgnoreCase(mediaType)) { // return Message; // } // return null; // } // }
import org.junit.Test; import xpertss.function.Consumer; import xpertss.lang.Range; import xpertss.media.MediaChannel; import xpertss.media.MediaConsumer; import xpertss.media.MediaType; import xpertss.sdp.MediaDescription; import xpertss.sdp.SessionDescription; import xpertss.threads.Threads; import java.net.ConnectException; import java.net.URI; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static xpertss.nio.ReadyState.Closed; import static xpertss.nio.ReadyState.Closing; import static xpertss.nio.ReadyState.Connected; import static xpertss.nio.ReadyState.Connecting; import static xpertss.nio.ReadyState.Open;
session.connect(100); assertEquals(Connecting, session.getReadyState()); while(session.getReadyState() == Connecting); verify(handler, times(1)).onFailure(same(session), any(UnknownHostException.class)); assertEquals(Closed, session.getReadyState()); } @Test public void testRtspPlayer() { RtspClient client = new RtspClient(); RtspPlayer player = new RtspPlayer(client, new MediaConsumer() { private Map<Integer,Consumer<ByteBuffer>> channels = new HashMap<>(); @Override public MediaDescription[] select(SessionDescription sdp) { return sdp.getMediaDescriptions(); } @Override public void createChannel(MediaChannel channel) {
// Path: src/main/java/xpertss/media/MediaChannel.java // public class MediaChannel implements Comparable<MediaChannel> { // // private final MediaDescription desc; // private final Range<Integer> channels; // // public MediaChannel(MediaDescription desc, Range<Integer> channels) // { // this.desc = Objects.notNull(desc); // this.channels = Objects.notNull(channels); // } // // /** // * The full media description of the data this channel will // * process. // */ // public MediaDescription getMedia() // { // return desc; // } // // /** // * A control identifier for the channel. // */ // public String getControl() // { // Attribute attr = desc.getAttribute("control"); // return (attr != null) ? attr.getValue() : null; // } // // // /** // * The media type this channel will process. // */ // public MediaType getType() // { // return MediaType.parse(desc); // } // // /** // * The channel identifiers over which this media will be transmitted. // * <p/> // * The media data is usually transmitted over the lower of the two // * channel identifiers while control information for the channel is // * transmitted over the higher channel. // */ // public Range<Integer> getChannels() // { // return channels; // } // // // /** // * Compares this media channel to another based on its channel identifiers. // */ // @Override // public int compareTo(MediaChannel o) // { // return channels.compareTo(o.channels); // } // // } // // Path: src/main/java/xpertss/media/MediaConsumer.java // public interface MediaConsumer { // // /** // * Given a session description return the media descriptions the // * consumer wishes to be setup for playback. // */ // public MediaDescription[] select(SessionDescription sdp); // // // /** // * For each media description desired this will be called by the // * player to inform it that the channel has been successfully // * setup and to identify the channel identifiers associated with // * it. // */ // public void createChannel(MediaChannel channel); // // /** // * Called to indicate that the previously created channels should // * be destroyed as they are no longer valid. // */ // public void destroyChannels(); // // // // /** // * Once playback has begun the actual channel data will be delivered // * to the consumer via this method. The channelId will be one of the // * identifiers previously communicated to the newChannel callback. // */ // public void consume(int channelId, ByteBuffer data); // // // /** // * Called to notify the consumer of an error that has terminated // * playback. // */ // public void handle(Throwable t); // // } // // Path: src/main/java/xpertss/media/MediaType.java // public enum MediaType { // // Audio, Video, Text, Application, Message; // // // public static MediaType parse(MediaDescription desc) // { // String mediaType = desc.getMedia().getType(); // if("Audio".equalsIgnoreCase(mediaType)) { // return Audio; // } else if("Video".equalsIgnoreCase(mediaType)) { // return Video; // } else if("Text".equalsIgnoreCase(mediaType)) { // return Text; // } else if("Application".equalsIgnoreCase(mediaType)) { // return Application; // } else if("Message".equalsIgnoreCase(mediaType)) { // return Message; // } // return null; // } // } // Path: src/test/java/xpertss/rtsp/RtspClientTest.java import org.junit.Test; import xpertss.function.Consumer; import xpertss.lang.Range; import xpertss.media.MediaChannel; import xpertss.media.MediaConsumer; import xpertss.media.MediaType; import xpertss.sdp.MediaDescription; import xpertss.sdp.SessionDescription; import xpertss.threads.Threads; import java.net.ConnectException; import java.net.URI; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; import static org.mockito.Matchers.any; import static org.mockito.Matchers.same; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static xpertss.nio.ReadyState.Closed; import static xpertss.nio.ReadyState.Closing; import static xpertss.nio.ReadyState.Connected; import static xpertss.nio.ReadyState.Connecting; import static xpertss.nio.ReadyState.Open; session.connect(100); assertEquals(Connecting, session.getReadyState()); while(session.getReadyState() == Connecting); verify(handler, times(1)).onFailure(same(session), any(UnknownHostException.class)); assertEquals(Closed, session.getReadyState()); } @Test public void testRtspPlayer() { RtspClient client = new RtspClient(); RtspPlayer player = new RtspPlayer(client, new MediaConsumer() { private Map<Integer,Consumer<ByteBuffer>> channels = new HashMap<>(); @Override public MediaDescription[] select(SessionDescription sdp) { return sdp.getMediaDescriptions(); } @Override public void createChannel(MediaChannel channel) {
final MediaType type = channel.getType();
cfloersch/RtspClient
src/main/java/xpertss/mime/impl/SingleValueHeader.java
// Path: src/main/java/xpertss/mime/Header.java // public interface Header { // // /** // * Http defines four types of headers. All headers not specifically // * defined to be general, request, or response are treated as entity // * headers. // */ // public enum Type { // /** // * A general header is one that may be included in either the request or // * response and is applied to the overall message itself. // */ // General, // // /** // * A request header is applied only to impl requests and applies to the // * message overall. // */ // Request, // // /** // * A response header is applied only to impl responses and applies to the // * message overall. // */ // Response, // // /** // * An entity header defines the entity contained within the message. // */ // Entity, // // /** // * A raw header is any header for which a defined parser was not found. // * These are typically non-standard headers and will always return an // * unparsed raw string when getValue is called. // */ // Raw // } // // // /** // * Returns the header name as a String. // */ // public String getName(); // // /** // * Returns a fully formatted value line including all values and their // * associated parameters. This method provides an easier means of access // * to simple values. // */ // public String getValue(); // // /** // * Returns the header type this header represents. // */ // public Type getType(); // // // /** // * Returns the number of values this header contains. // */ // public int size(); // // /** // * Returns the header value at the specified index. // */ // public HeaderValue getValue(int index); // // /** // * Returns the specified named header value if it exists. // */ // public HeaderValue getValue(String name); // // // /** // * Return a formatted string representation of this header and its values // * and parameters. // */ // public String toString(); // // // } // // Path: src/main/java/xpertss/mime/HeaderValue.java // public interface HeaderValue { // // // /** // * Ths will return the value's name or {@code null} if it is not a // * named value. // */ // public String getName(); // // /** // * This will return the value's value. // */ // public String getValue(); // // // // // // /** // * Returns the number of parameters this header value contains. // */ // public int size(); // // /** // * Returns the parameter at the specified index. // */ // public Parameter getParameter(int index); // // /** // * Returns the specified named parameter if it exists. // */ // public Parameter getParameter(String name); // // // // /** // * Return a formatted string representation of this header value and its // * parameters. // */ // public String toString(); // // }
import xpertss.mime.HeaderValue; import xpertss.lang.Objects; import xpertss.mime.Header;
/** * Copyright XpertSoftware All rights reserved. * * Date: 3/18/11 11:53 PM */ package xpertss.mime.impl; public class SingleValueHeader implements Header { private final Type type; private final String name;
// Path: src/main/java/xpertss/mime/Header.java // public interface Header { // // /** // * Http defines four types of headers. All headers not specifically // * defined to be general, request, or response are treated as entity // * headers. // */ // public enum Type { // /** // * A general header is one that may be included in either the request or // * response and is applied to the overall message itself. // */ // General, // // /** // * A request header is applied only to impl requests and applies to the // * message overall. // */ // Request, // // /** // * A response header is applied only to impl responses and applies to the // * message overall. // */ // Response, // // /** // * An entity header defines the entity contained within the message. // */ // Entity, // // /** // * A raw header is any header for which a defined parser was not found. // * These are typically non-standard headers and will always return an // * unparsed raw string when getValue is called. // */ // Raw // } // // // /** // * Returns the header name as a String. // */ // public String getName(); // // /** // * Returns a fully formatted value line including all values and their // * associated parameters. This method provides an easier means of access // * to simple values. // */ // public String getValue(); // // /** // * Returns the header type this header represents. // */ // public Type getType(); // // // /** // * Returns the number of values this header contains. // */ // public int size(); // // /** // * Returns the header value at the specified index. // */ // public HeaderValue getValue(int index); // // /** // * Returns the specified named header value if it exists. // */ // public HeaderValue getValue(String name); // // // /** // * Return a formatted string representation of this header and its values // * and parameters. // */ // public String toString(); // // // } // // Path: src/main/java/xpertss/mime/HeaderValue.java // public interface HeaderValue { // // // /** // * Ths will return the value's name or {@code null} if it is not a // * named value. // */ // public String getName(); // // /** // * This will return the value's value. // */ // public String getValue(); // // // // // // /** // * Returns the number of parameters this header value contains. // */ // public int size(); // // /** // * Returns the parameter at the specified index. // */ // public Parameter getParameter(int index); // // /** // * Returns the specified named parameter if it exists. // */ // public Parameter getParameter(String name); // // // // /** // * Return a formatted string representation of this header value and its // * parameters. // */ // public String toString(); // // } // Path: src/main/java/xpertss/mime/impl/SingleValueHeader.java import xpertss.mime.HeaderValue; import xpertss.lang.Objects; import xpertss.mime.Header; /** * Copyright XpertSoftware All rights reserved. * * Date: 3/18/11 11:53 PM */ package xpertss.mime.impl; public class SingleValueHeader implements Header { private final Type type; private final String name;
private final HeaderValue[] value;
sahildave/Gazetti_Newspaper_Reader
app/src/main/java/in/sahildave/gazetti/news_activities/ArticleLoadingCallback.java
// Path: app/src/main/java/in/sahildave/gazetti/util/BitmapTransform.java // public class BitmapTransform implements Transformation { // // int maxWidth; // int maxHeight; // // public BitmapTransform(int maxWidth, int maxHeight) { // this.maxWidth = maxWidth; // this.maxHeight = maxHeight; // } // // @Override // public Bitmap transform(Bitmap source) { // int targetWidth, targetHeight; // double aspectRatio; // // if (source.getWidth() > source.getHeight()) { // targetWidth = maxWidth; // aspectRatio = (double) source.getHeight() / (double) source.getWidth(); // targetHeight = (int) (targetWidth * aspectRatio); // } else { // targetHeight = maxHeight; // aspectRatio = (double) source.getWidth() / (double) source.getHeight(); // targetWidth = (int) (targetHeight * aspectRatio); // } // // Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false); // if (result != source) { // source.recycle(); // } // return result; // } // // @Override // public String key() { // return maxWidth + "x" + maxHeight; // } // // }
import android.annotation.SuppressLint; import android.app.Activity; import android.graphics.Point; import android.os.Build; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.util.TypedValue; import android.view.Display; import android.view.View; import android.view.ViewTreeObserver; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.*; import com.crashlytics.android.Crashlytics; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import com.squareup.picasso.RequestCreator; import fr.castorflex.android.smoothprogressbar.SmoothProgressBar; import in.sahildave.gazetti.R; import in.sahildave.gazetti.util.BitmapTransform;
} public void onPostExecute(String[] result, String mArticlePubDate) { titleText = result[0]; mImageURL = result[1]; bodyText = result[2]; mSubtitleLayout.setVisibility(View.VISIBLE); mArticleFooter.setVisibility(View.VISIBLE); mArticlePubDateView.setText(mArticlePubDate); mArticleTextView.setVisibility(View.VISIBLE); mArticleTextView.setText(bodyText); if (mImageURL == null) { mTitleTextView = (TextView) headerStub.findViewById(R.id.article_title); mTitleTextView.setText(titleText); detailViewProgress.progressiveStop(); } else { mTitleTextView = (TextView) headerStub.findViewById(R.id.article_header_title); mTitleTextView.setText(titleText); mMainImageView = (ImageView) headerStub.findViewById(R.id.article_header_image); //height and width of screen final int MAX_HEIGHT = activity.getResources().getDisplayMetrics().heightPixels; final int MAX_WIDTH = activity.getResources().getDisplayMetrics().widthPixels; RequestCreator requestCreator = Picasso.with(activity) .load(mImageURL)
// Path: app/src/main/java/in/sahildave/gazetti/util/BitmapTransform.java // public class BitmapTransform implements Transformation { // // int maxWidth; // int maxHeight; // // public BitmapTransform(int maxWidth, int maxHeight) { // this.maxWidth = maxWidth; // this.maxHeight = maxHeight; // } // // @Override // public Bitmap transform(Bitmap source) { // int targetWidth, targetHeight; // double aspectRatio; // // if (source.getWidth() > source.getHeight()) { // targetWidth = maxWidth; // aspectRatio = (double) source.getHeight() / (double) source.getWidth(); // targetHeight = (int) (targetWidth * aspectRatio); // } else { // targetHeight = maxHeight; // aspectRatio = (double) source.getWidth() / (double) source.getHeight(); // targetWidth = (int) (targetHeight * aspectRatio); // } // // Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false); // if (result != source) { // source.recycle(); // } // return result; // } // // @Override // public String key() { // return maxWidth + "x" + maxHeight; // } // // } // Path: app/src/main/java/in/sahildave/gazetti/news_activities/ArticleLoadingCallback.java import android.annotation.SuppressLint; import android.app.Activity; import android.graphics.Point; import android.os.Build; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.util.TypedValue; import android.view.Display; import android.view.View; import android.view.ViewTreeObserver; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.*; import com.crashlytics.android.Crashlytics; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import com.squareup.picasso.RequestCreator; import fr.castorflex.android.smoothprogressbar.SmoothProgressBar; import in.sahildave.gazetti.R; import in.sahildave.gazetti.util.BitmapTransform; } public void onPostExecute(String[] result, String mArticlePubDate) { titleText = result[0]; mImageURL = result[1]; bodyText = result[2]; mSubtitleLayout.setVisibility(View.VISIBLE); mArticleFooter.setVisibility(View.VISIBLE); mArticlePubDateView.setText(mArticlePubDate); mArticleTextView.setVisibility(View.VISIBLE); mArticleTextView.setText(bodyText); if (mImageURL == null) { mTitleTextView = (TextView) headerStub.findViewById(R.id.article_title); mTitleTextView.setText(titleText); detailViewProgress.progressiveStop(); } else { mTitleTextView = (TextView) headerStub.findViewById(R.id.article_header_title); mTitleTextView.setText(titleText); mMainImageView = (ImageView) headerStub.findViewById(R.id.article_header_image); //height and width of screen final int MAX_HEIGHT = activity.getResources().getDisplayMetrics().heightPixels; final int MAX_WIDTH = activity.getResources().getDisplayMetrics().widthPixels; RequestCreator requestCreator = Picasso.with(activity) .load(mImageURL)
.transform(new BitmapTransform(MAX_WIDTH, MAX_HEIGHT));
sahildave/Gazetti_Newspaper_Reader
app/src/main/java/in/sahildave/gazetti/homescreen/adapter/CellModel.java
// Path: app/src/main/java/in/sahildave/gazetti/util/GazettiEnums.java // public enum Category { // NATIONAL ("National", "1"), // INTERNATIONAL ("International", "2"), // SPORTS ("Sports", "3"), // SCIENCE ("Science", "4"), // BUSINESS ("Business", "6"), // OPINION_BLOG_EDITORIAL("Blogs and Editorials", "7"), // ENTERTAINMENT ("Entertainment", "5"), // ADD_NEW("Add New", "-1"); // // private final String categoryTitle; // private final String categoryId; // // Category(String categoryTitle, String catId) { // this.categoryTitle = categoryTitle; // this.categoryId = catId; // } // // public String getTitle() { // return categoryTitle; // } // // public String getCategoryId() { // return categoryId; // } // } // // Path: app/src/main/java/in/sahildave/gazetti/util/GazettiEnums.java // public enum Newspapers { // THE_HINDU ("The Hindu", "th", "0", "hindu_data"), // TOI ("The Times of India", "toi", "1", "toi_data"), // FIRST_POST ("First Post", "fp", "2", "fp_data"), // INDIAN_EXP ("The Indian Express", "tie", "3", "tie_data"), // ADD_NEW ("Add New", "add_new", "-1", "null"); // // private final String newspaperTitle; // private final String newspaperImage; // private final String newspaperId; // private final String dbToSearch; // // Newspapers(String newspaperTitle, String newspaperImage, String npId, String dbToSearch) { // this.newspaperTitle = newspaperTitle; // this.newspaperImage = newspaperImage; // this.newspaperId = npId; // this.dbToSearch = dbToSearch; // } // // public String getTitle() { // return newspaperTitle; // } // // public String getNewspaperImage() { // return newspaperImage; // } // // public String getNewspaperId() { // return newspaperId; // } // }
import in.sahildave.gazetti.util.GazettiEnums.Category; import in.sahildave.gazetti.util.GazettiEnums.Newspapers;
package in.sahildave.gazetti.homescreen.adapter; public class CellModel { private String newspaperImage; private String newspaperTitle; private String newspaperId; private String categoryTitle; private String categoryId;
// Path: app/src/main/java/in/sahildave/gazetti/util/GazettiEnums.java // public enum Category { // NATIONAL ("National", "1"), // INTERNATIONAL ("International", "2"), // SPORTS ("Sports", "3"), // SCIENCE ("Science", "4"), // BUSINESS ("Business", "6"), // OPINION_BLOG_EDITORIAL("Blogs and Editorials", "7"), // ENTERTAINMENT ("Entertainment", "5"), // ADD_NEW("Add New", "-1"); // // private final String categoryTitle; // private final String categoryId; // // Category(String categoryTitle, String catId) { // this.categoryTitle = categoryTitle; // this.categoryId = catId; // } // // public String getTitle() { // return categoryTitle; // } // // public String getCategoryId() { // return categoryId; // } // } // // Path: app/src/main/java/in/sahildave/gazetti/util/GazettiEnums.java // public enum Newspapers { // THE_HINDU ("The Hindu", "th", "0", "hindu_data"), // TOI ("The Times of India", "toi", "1", "toi_data"), // FIRST_POST ("First Post", "fp", "2", "fp_data"), // INDIAN_EXP ("The Indian Express", "tie", "3", "tie_data"), // ADD_NEW ("Add New", "add_new", "-1", "null"); // // private final String newspaperTitle; // private final String newspaperImage; // private final String newspaperId; // private final String dbToSearch; // // Newspapers(String newspaperTitle, String newspaperImage, String npId, String dbToSearch) { // this.newspaperTitle = newspaperTitle; // this.newspaperImage = newspaperImage; // this.newspaperId = npId; // this.dbToSearch = dbToSearch; // } // // public String getTitle() { // return newspaperTitle; // } // // public String getNewspaperImage() { // return newspaperImage; // } // // public String getNewspaperId() { // return newspaperId; // } // } // Path: app/src/main/java/in/sahildave/gazetti/homescreen/adapter/CellModel.java import in.sahildave.gazetti.util.GazettiEnums.Category; import in.sahildave.gazetti.util.GazettiEnums.Newspapers; package in.sahildave.gazetti.homescreen.adapter; public class CellModel { private String newspaperImage; private String newspaperTitle; private String newspaperId; private String categoryTitle; private String categoryId;
public CellModel(Newspapers newspapers, Category category) {
sahildave/Gazetti_Newspaper_Reader
app/src/main/java/in/sahildave/gazetti/homescreen/adapter/CellModel.java
// Path: app/src/main/java/in/sahildave/gazetti/util/GazettiEnums.java // public enum Category { // NATIONAL ("National", "1"), // INTERNATIONAL ("International", "2"), // SPORTS ("Sports", "3"), // SCIENCE ("Science", "4"), // BUSINESS ("Business", "6"), // OPINION_BLOG_EDITORIAL("Blogs and Editorials", "7"), // ENTERTAINMENT ("Entertainment", "5"), // ADD_NEW("Add New", "-1"); // // private final String categoryTitle; // private final String categoryId; // // Category(String categoryTitle, String catId) { // this.categoryTitle = categoryTitle; // this.categoryId = catId; // } // // public String getTitle() { // return categoryTitle; // } // // public String getCategoryId() { // return categoryId; // } // } // // Path: app/src/main/java/in/sahildave/gazetti/util/GazettiEnums.java // public enum Newspapers { // THE_HINDU ("The Hindu", "th", "0", "hindu_data"), // TOI ("The Times of India", "toi", "1", "toi_data"), // FIRST_POST ("First Post", "fp", "2", "fp_data"), // INDIAN_EXP ("The Indian Express", "tie", "3", "tie_data"), // ADD_NEW ("Add New", "add_new", "-1", "null"); // // private final String newspaperTitle; // private final String newspaperImage; // private final String newspaperId; // private final String dbToSearch; // // Newspapers(String newspaperTitle, String newspaperImage, String npId, String dbToSearch) { // this.newspaperTitle = newspaperTitle; // this.newspaperImage = newspaperImage; // this.newspaperId = npId; // this.dbToSearch = dbToSearch; // } // // public String getTitle() { // return newspaperTitle; // } // // public String getNewspaperImage() { // return newspaperImage; // } // // public String getNewspaperId() { // return newspaperId; // } // }
import in.sahildave.gazetti.util.GazettiEnums.Category; import in.sahildave.gazetti.util.GazettiEnums.Newspapers;
package in.sahildave.gazetti.homescreen.adapter; public class CellModel { private String newspaperImage; private String newspaperTitle; private String newspaperId; private String categoryTitle; private String categoryId;
// Path: app/src/main/java/in/sahildave/gazetti/util/GazettiEnums.java // public enum Category { // NATIONAL ("National", "1"), // INTERNATIONAL ("International", "2"), // SPORTS ("Sports", "3"), // SCIENCE ("Science", "4"), // BUSINESS ("Business", "6"), // OPINION_BLOG_EDITORIAL("Blogs and Editorials", "7"), // ENTERTAINMENT ("Entertainment", "5"), // ADD_NEW("Add New", "-1"); // // private final String categoryTitle; // private final String categoryId; // // Category(String categoryTitle, String catId) { // this.categoryTitle = categoryTitle; // this.categoryId = catId; // } // // public String getTitle() { // return categoryTitle; // } // // public String getCategoryId() { // return categoryId; // } // } // // Path: app/src/main/java/in/sahildave/gazetti/util/GazettiEnums.java // public enum Newspapers { // THE_HINDU ("The Hindu", "th", "0", "hindu_data"), // TOI ("The Times of India", "toi", "1", "toi_data"), // FIRST_POST ("First Post", "fp", "2", "fp_data"), // INDIAN_EXP ("The Indian Express", "tie", "3", "tie_data"), // ADD_NEW ("Add New", "add_new", "-1", "null"); // // private final String newspaperTitle; // private final String newspaperImage; // private final String newspaperId; // private final String dbToSearch; // // Newspapers(String newspaperTitle, String newspaperImage, String npId, String dbToSearch) { // this.newspaperTitle = newspaperTitle; // this.newspaperImage = newspaperImage; // this.newspaperId = npId; // this.dbToSearch = dbToSearch; // } // // public String getTitle() { // return newspaperTitle; // } // // public String getNewspaperImage() { // return newspaperImage; // } // // public String getNewspaperId() { // return newspaperId; // } // } // Path: app/src/main/java/in/sahildave/gazetti/homescreen/adapter/CellModel.java import in.sahildave.gazetti.util.GazettiEnums.Category; import in.sahildave.gazetti.util.GazettiEnums.Newspapers; package in.sahildave.gazetti.homescreen.adapter; public class CellModel { private String newspaperImage; private String newspaperTitle; private String newspaperId; private String categoryTitle; private String categoryId;
public CellModel(Newspapers newspapers, Category category) {