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
|
---|---|---|---|---|---|---|
elvis-liu/dummie | src/test/java/com/exmertec/dummie/EnumTest.java | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
| import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test; | package com.exmertec.dummie;
public class EnumTest {
@Test
public void should_create_object_with_enum_field() {
EnumData enumData = create(EnumData.class);
assertThat(enumData, not(nullValue()));
assertThat(enumData.getDataType(), equalTo(DataType.STRING));
}
@Test
public void should_create_object_without_any_constant() {
EmptyEnumData emptyEnumData = create(EmptyEnumData.class);
assertThat(emptyEnumData, not(nullValue()));
assertThat(emptyEnumData.getDataType(), is(nullValue()));
}
@Test
public void should_create_object_with_random_strategy() throws Exception {
EnumData enumData = withStrategy(GenerationStrategy.RANDOM)
.create(EnumData.class);
assertThat(enumData, not(nullValue()));
assertThat(enumData.getDataType(), not(nullValue()));
}
@Test
public void should_create_object_with_random_strategy_and_empty_constant() throws Exception {
EmptyEnumData emptyEnumData = withStrategy(GenerationStrategy.RANDOM)
.create(EmptyEnumData.class);
assertThat(emptyEnumData, not(nullValue()));
assertThat(emptyEnumData.getDataType(), is(nullValue()));
}
@Test
public void should_cache_same_type_field_with_diff_field() { | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
// Path: src/test/java/com/exmertec/dummie/EnumTest.java
import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test;
package com.exmertec.dummie;
public class EnumTest {
@Test
public void should_create_object_with_enum_field() {
EnumData enumData = create(EnumData.class);
assertThat(enumData, not(nullValue()));
assertThat(enumData.getDataType(), equalTo(DataType.STRING));
}
@Test
public void should_create_object_without_any_constant() {
EmptyEnumData emptyEnumData = create(EmptyEnumData.class);
assertThat(emptyEnumData, not(nullValue()));
assertThat(emptyEnumData.getDataType(), is(nullValue()));
}
@Test
public void should_create_object_with_random_strategy() throws Exception {
EnumData enumData = withStrategy(GenerationStrategy.RANDOM)
.create(EnumData.class);
assertThat(enumData, not(nullValue()));
assertThat(enumData.getDataType(), not(nullValue()));
}
@Test
public void should_create_object_with_random_strategy_and_empty_constant() throws Exception {
EmptyEnumData emptyEnumData = withStrategy(GenerationStrategy.RANDOM)
.create(EmptyEnumData.class);
assertThat(emptyEnumData, not(nullValue()));
assertThat(emptyEnumData.getDataType(), is(nullValue()));
}
@Test
public void should_cache_same_type_field_with_diff_field() { | CacheEnumData cacheEnumData = prepare(CacheEnumData.class) |
elvis-liu/dummie | src/test/java/com/exmertec/dummie/PrimitivesTest.java | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
| import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test; | package com.exmertec.dummie;
public class PrimitivesTest {
@Test
public void should_create_object_with_primitive_fields() throws Exception { | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
// Path: src/test/java/com/exmertec/dummie/PrimitivesTest.java
import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test;
package com.exmertec.dummie;
public class PrimitivesTest {
@Test
public void should_create_object_with_primitive_fields() throws Exception { | PrimitiveData data = create(PrimitiveData.class); |
elvis-liu/dummie | src/test/java/com/exmertec/dummie/PrimitivesTest.java | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
| import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test; | package com.exmertec.dummie;
public class PrimitivesTest {
@Test
public void should_create_object_with_primitive_fields() throws Exception {
PrimitiveData data = create(PrimitiveData.class);
assertThat(data, not(nullValue()));
assertThat(data.isBooleanValue(), is(false));
}
@Test
public void should_create_object_with_random_strategy() throws Exception { | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
// Path: src/test/java/com/exmertec/dummie/PrimitivesTest.java
import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test;
package com.exmertec.dummie;
public class PrimitivesTest {
@Test
public void should_create_object_with_primitive_fields() throws Exception {
PrimitiveData data = create(PrimitiveData.class);
assertThat(data, not(nullValue()));
assertThat(data.isBooleanValue(), is(false));
}
@Test
public void should_create_object_with_random_strategy() throws Exception { | PrimitiveData data = withStrategy(GenerationStrategy.RANDOM) |
elvis-liu/dummie | src/test/java/com/exmertec/dummie/PrimitivesTest.java | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
| import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test; | package com.exmertec.dummie;
public class PrimitivesTest {
@Test
public void should_create_object_with_primitive_fields() throws Exception {
PrimitiveData data = create(PrimitiveData.class);
assertThat(data, not(nullValue()));
assertThat(data.isBooleanValue(), is(false));
}
@Test
public void should_create_object_with_random_strategy() throws Exception { | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
// Path: src/test/java/com/exmertec/dummie/PrimitivesTest.java
import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test;
package com.exmertec.dummie;
public class PrimitivesTest {
@Test
public void should_create_object_with_primitive_fields() throws Exception {
PrimitiveData data = create(PrimitiveData.class);
assertThat(data, not(nullValue()));
assertThat(data.isBooleanValue(), is(false));
}
@Test
public void should_create_object_with_random_strategy() throws Exception { | PrimitiveData data = withStrategy(GenerationStrategy.RANDOM) |
elvis-liu/dummie | src/test/java/com/exmertec/dummie/PrimitivesTest.java | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
| import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test; | package com.exmertec.dummie;
public class PrimitivesTest {
@Test
public void should_create_object_with_primitive_fields() throws Exception {
PrimitiveData data = create(PrimitiveData.class);
assertThat(data, not(nullValue()));
assertThat(data.isBooleanValue(), is(false));
}
@Test
public void should_create_object_with_random_strategy() throws Exception {
PrimitiveData data = withStrategy(GenerationStrategy.RANDOM)
.create(PrimitiveData.class);
assertThat(data, not(nullValue()));
assertThat(data.isBooleanValue(), not(nullValue()));
}
@Test
public void should_allow_customize_primitive_type_fields() throws Exception { | // Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> T create(Class<T> type) {
// return prepare(type).build();
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static <T> DummyBuilder<T> prepare(Class<T> type) {
// return new DummyBuilderFactory().prepare(type);
// }
//
// Path: src/main/java/com/exmertec/dummie/Dummie.java
// public static DummyBuilderFactory withStrategy(GenerationStrategy strategy) {
// DummyBuilderFactory factory = new DummyBuilderFactory();
// factory.withStrategy(strategy);
// return factory;
// }
//
// Path: src/main/java/com/exmertec/dummie/configuration/GenerationStrategy.java
// public enum GenerationStrategy {
// DEFAULT, RANDOM
// }
// Path: src/test/java/com/exmertec/dummie/PrimitivesTest.java
import static com.exmertec.dummie.Dummie.create;
import static com.exmertec.dummie.Dummie.prepare;
import static com.exmertec.dummie.Dummie.withStrategy;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import com.exmertec.dummie.configuration.GenerationStrategy;
import org.junit.Test;
package com.exmertec.dummie;
public class PrimitivesTest {
@Test
public void should_create_object_with_primitive_fields() throws Exception {
PrimitiveData data = create(PrimitiveData.class);
assertThat(data, not(nullValue()));
assertThat(data.isBooleanValue(), is(false));
}
@Test
public void should_create_object_with_random_strategy() throws Exception {
PrimitiveData data = withStrategy(GenerationStrategy.RANDOM)
.create(PrimitiveData.class);
assertThat(data, not(nullValue()));
assertThat(data.isBooleanValue(), not(nullValue()));
}
@Test
public void should_allow_customize_primitive_type_fields() throws Exception { | PrimitiveData data = prepare(PrimitiveData.class).override("booleanValue", true).build(); |
elvis-liu/dummie | src/main/java/com/exmertec/dummie/DummyBuilder.java | // Path: src/main/java/com/exmertec/dummie/generator/data/DataGenerator.java
// public abstract class DataGenerator {
//
// private final List<FieldValueGenerator> generators;
//
// private final Set<String> randomFieldKeys;
//
// private final Set<Class<?>> randomFieldType;
//
// protected DataCache dataCache;
//
// protected GenerationStrategy strategy;
//
// public DataGenerator(GenerationStrategy strategy) {
// this(strategy, new KeyValueDataCache());
// }
//
// public DataGenerator(GenerationStrategy strategy, DataCache dataCache) {
// this.dataCache = dataCache;
// this.strategy = strategy;
//
// generators = new ArrayList<FieldValueGenerator>();
// randomFieldKeys = new HashSet<String>();
// randomFieldType = new HashSet<Class<?>>();
//
// addDefaultGenerators();
// }
//
// private void addDefaultGenerators() {
// generators.add(new StringFieldValueGenerator());
// generators.add(new ListFieldValueGenerator());
// generators.add(new MapFieldValueGenerator());
// generators.add(new SetFieldValueGenerator());
// generators.add(new BooleanFieldValueGenerator());
// generators.add(new ByteFieldValueGenerator());
// generators.add(new CharacterFieldValueGenerator());
// generators.add(new DoubleFieldValueGenerator());
// generators.add(new FloatFieldValueGenerator());
// generators.add(new IntegerFieldValueGenerator());
// generators.add(new LongFieldValueGenerator());
// generators.add(new ShortFieldValueGenerator());
// generators.add(new EnumFieldValueGenerator());
// generators.add(new BigDecimalFieldValueGenerator());
// }
//
// public Object getData(Field field) {
// Class<?> fieldType = field.getType();
// Object value = dataCache.getCachedData(fieldType, field.getName());
// if (value == null) {
// FieldValueGenerator generator = getGenerator(fieldType, field.getName());
// if (generator != null) {
// value = generator.generate(this, field);
// }
// }
// return value;
// }
//
// public Object getData(Class<?> dataType, String key) {
// Object value = dataCache.getCachedData(dataType, key);
// if (value == null) {
// FieldValueGenerator generator = getGenerator(dataType, key);
// if (generator != null) {
// value = generator.generate(this, dataType, key);
// }
// }
// return value;
// }
//
// public <T> void cacheData(Class<T> dataType, String key, Object value) {
// dataCache.cacheData(dataType, key, value);
// }
//
// public <T> void cacheData(Class<T> clazz, Object value) {
// dataCache.cacheData(clazz, value);
// }
//
// public <T> void dynamicCacheData(Class<T> dataType, String key, Object value) {
// if (getStrategy(dataType, key) == GenerationStrategy.DEFAULT) {
// dataCache.cacheData(dataType, key, value);
// }
// }
//
// public void random(Class<?> clazz) {
// randomFieldType.add(clazz);
// }
//
// public void random(String key) {
// randomFieldKeys.add(key);
// }
//
// protected GenerationStrategy getStrategy(Class<?> dataType, String key) {
// return randomFieldType.contains(dataType) || randomFieldKeys.contains(key) ?
// GenerationStrategy.RANDOM : strategy;
// }
//
// protected FieldValueGenerator switchGeneratorStrategy(FieldValueGenerator generator,
// Class<?> dataType, String key) {
// generator.setStrategy(getStrategy(dataType, key));
// return generator;
// }
//
// private FieldValueGenerator getGenerator(Class<?> dataType, String key) {
// return switchGeneratorStrategy(getCachedGenerator(dataType), dataType, key);
// }
//
// private FieldValueGenerator getCachedGenerator(Class<?> dataType) {
// for (FieldValueGenerator generator: generators) {
// if (generator.isMatchType(dataType)) {
// return generator;
// }
// }
//
// return getDefaultFieldValueGenerator(dataType);
// }
//
// protected abstract FieldValueGenerator getDefaultFieldValueGenerator(Class<?> dataType);
// }
//
// Path: src/main/java/com/exmertec/dummie/generator/Inflater.java
// public class Inflater {
// private static <T> void inflateFields(T instance, DataGenerator dataGenerator, Class<T> classType) throws
// IllegalAccessException, InvocationTargetException {
// Field[] fields = classType.getDeclaredFields();
// PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils();
//
// for (Field field : fields) {
// if (!propertyUtils.isWriteable(instance, field.getName())) {
// continue;
// }
//
// Object value = dataGenerator.getData(field);
// BeanUtils.setProperty(instance, field.getName(), value);
// }
// }
//
// public static <T> void inflateInstance(T instance, DataGenerator cache, Class<T> type) throws
// InvocationTargetException, IllegalAccessException {
// if (type != null) {
// inflateFields(instance, cache, type);
// inflateInstance(instance, cache, type.getSuperclass());
// }
// }
// }
| import com.exmertec.dummie.generator.data.DataGenerator;
import com.exmertec.dummie.generator.Inflater; | package com.exmertec.dummie;
public class DummyBuilder<T> {
private final Class<T> type; | // Path: src/main/java/com/exmertec/dummie/generator/data/DataGenerator.java
// public abstract class DataGenerator {
//
// private final List<FieldValueGenerator> generators;
//
// private final Set<String> randomFieldKeys;
//
// private final Set<Class<?>> randomFieldType;
//
// protected DataCache dataCache;
//
// protected GenerationStrategy strategy;
//
// public DataGenerator(GenerationStrategy strategy) {
// this(strategy, new KeyValueDataCache());
// }
//
// public DataGenerator(GenerationStrategy strategy, DataCache dataCache) {
// this.dataCache = dataCache;
// this.strategy = strategy;
//
// generators = new ArrayList<FieldValueGenerator>();
// randomFieldKeys = new HashSet<String>();
// randomFieldType = new HashSet<Class<?>>();
//
// addDefaultGenerators();
// }
//
// private void addDefaultGenerators() {
// generators.add(new StringFieldValueGenerator());
// generators.add(new ListFieldValueGenerator());
// generators.add(new MapFieldValueGenerator());
// generators.add(new SetFieldValueGenerator());
// generators.add(new BooleanFieldValueGenerator());
// generators.add(new ByteFieldValueGenerator());
// generators.add(new CharacterFieldValueGenerator());
// generators.add(new DoubleFieldValueGenerator());
// generators.add(new FloatFieldValueGenerator());
// generators.add(new IntegerFieldValueGenerator());
// generators.add(new LongFieldValueGenerator());
// generators.add(new ShortFieldValueGenerator());
// generators.add(new EnumFieldValueGenerator());
// generators.add(new BigDecimalFieldValueGenerator());
// }
//
// public Object getData(Field field) {
// Class<?> fieldType = field.getType();
// Object value = dataCache.getCachedData(fieldType, field.getName());
// if (value == null) {
// FieldValueGenerator generator = getGenerator(fieldType, field.getName());
// if (generator != null) {
// value = generator.generate(this, field);
// }
// }
// return value;
// }
//
// public Object getData(Class<?> dataType, String key) {
// Object value = dataCache.getCachedData(dataType, key);
// if (value == null) {
// FieldValueGenerator generator = getGenerator(dataType, key);
// if (generator != null) {
// value = generator.generate(this, dataType, key);
// }
// }
// return value;
// }
//
// public <T> void cacheData(Class<T> dataType, String key, Object value) {
// dataCache.cacheData(dataType, key, value);
// }
//
// public <T> void cacheData(Class<T> clazz, Object value) {
// dataCache.cacheData(clazz, value);
// }
//
// public <T> void dynamicCacheData(Class<T> dataType, String key, Object value) {
// if (getStrategy(dataType, key) == GenerationStrategy.DEFAULT) {
// dataCache.cacheData(dataType, key, value);
// }
// }
//
// public void random(Class<?> clazz) {
// randomFieldType.add(clazz);
// }
//
// public void random(String key) {
// randomFieldKeys.add(key);
// }
//
// protected GenerationStrategy getStrategy(Class<?> dataType, String key) {
// return randomFieldType.contains(dataType) || randomFieldKeys.contains(key) ?
// GenerationStrategy.RANDOM : strategy;
// }
//
// protected FieldValueGenerator switchGeneratorStrategy(FieldValueGenerator generator,
// Class<?> dataType, String key) {
// generator.setStrategy(getStrategy(dataType, key));
// return generator;
// }
//
// private FieldValueGenerator getGenerator(Class<?> dataType, String key) {
// return switchGeneratorStrategy(getCachedGenerator(dataType), dataType, key);
// }
//
// private FieldValueGenerator getCachedGenerator(Class<?> dataType) {
// for (FieldValueGenerator generator: generators) {
// if (generator.isMatchType(dataType)) {
// return generator;
// }
// }
//
// return getDefaultFieldValueGenerator(dataType);
// }
//
// protected abstract FieldValueGenerator getDefaultFieldValueGenerator(Class<?> dataType);
// }
//
// Path: src/main/java/com/exmertec/dummie/generator/Inflater.java
// public class Inflater {
// private static <T> void inflateFields(T instance, DataGenerator dataGenerator, Class<T> classType) throws
// IllegalAccessException, InvocationTargetException {
// Field[] fields = classType.getDeclaredFields();
// PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils();
//
// for (Field field : fields) {
// if (!propertyUtils.isWriteable(instance, field.getName())) {
// continue;
// }
//
// Object value = dataGenerator.getData(field);
// BeanUtils.setProperty(instance, field.getName(), value);
// }
// }
//
// public static <T> void inflateInstance(T instance, DataGenerator cache, Class<T> type) throws
// InvocationTargetException, IllegalAccessException {
// if (type != null) {
// inflateFields(instance, cache, type);
// inflateInstance(instance, cache, type.getSuperclass());
// }
// }
// }
// Path: src/main/java/com/exmertec/dummie/DummyBuilder.java
import com.exmertec.dummie.generator.data.DataGenerator;
import com.exmertec.dummie.generator.Inflater;
package com.exmertec.dummie;
public class DummyBuilder<T> {
private final Class<T> type; | private final DataGenerator dataGenerator; |
elvis-liu/dummie | src/main/java/com/exmertec/dummie/DummyBuilder.java | // Path: src/main/java/com/exmertec/dummie/generator/data/DataGenerator.java
// public abstract class DataGenerator {
//
// private final List<FieldValueGenerator> generators;
//
// private final Set<String> randomFieldKeys;
//
// private final Set<Class<?>> randomFieldType;
//
// protected DataCache dataCache;
//
// protected GenerationStrategy strategy;
//
// public DataGenerator(GenerationStrategy strategy) {
// this(strategy, new KeyValueDataCache());
// }
//
// public DataGenerator(GenerationStrategy strategy, DataCache dataCache) {
// this.dataCache = dataCache;
// this.strategy = strategy;
//
// generators = new ArrayList<FieldValueGenerator>();
// randomFieldKeys = new HashSet<String>();
// randomFieldType = new HashSet<Class<?>>();
//
// addDefaultGenerators();
// }
//
// private void addDefaultGenerators() {
// generators.add(new StringFieldValueGenerator());
// generators.add(new ListFieldValueGenerator());
// generators.add(new MapFieldValueGenerator());
// generators.add(new SetFieldValueGenerator());
// generators.add(new BooleanFieldValueGenerator());
// generators.add(new ByteFieldValueGenerator());
// generators.add(new CharacterFieldValueGenerator());
// generators.add(new DoubleFieldValueGenerator());
// generators.add(new FloatFieldValueGenerator());
// generators.add(new IntegerFieldValueGenerator());
// generators.add(new LongFieldValueGenerator());
// generators.add(new ShortFieldValueGenerator());
// generators.add(new EnumFieldValueGenerator());
// generators.add(new BigDecimalFieldValueGenerator());
// }
//
// public Object getData(Field field) {
// Class<?> fieldType = field.getType();
// Object value = dataCache.getCachedData(fieldType, field.getName());
// if (value == null) {
// FieldValueGenerator generator = getGenerator(fieldType, field.getName());
// if (generator != null) {
// value = generator.generate(this, field);
// }
// }
// return value;
// }
//
// public Object getData(Class<?> dataType, String key) {
// Object value = dataCache.getCachedData(dataType, key);
// if (value == null) {
// FieldValueGenerator generator = getGenerator(dataType, key);
// if (generator != null) {
// value = generator.generate(this, dataType, key);
// }
// }
// return value;
// }
//
// public <T> void cacheData(Class<T> dataType, String key, Object value) {
// dataCache.cacheData(dataType, key, value);
// }
//
// public <T> void cacheData(Class<T> clazz, Object value) {
// dataCache.cacheData(clazz, value);
// }
//
// public <T> void dynamicCacheData(Class<T> dataType, String key, Object value) {
// if (getStrategy(dataType, key) == GenerationStrategy.DEFAULT) {
// dataCache.cacheData(dataType, key, value);
// }
// }
//
// public void random(Class<?> clazz) {
// randomFieldType.add(clazz);
// }
//
// public void random(String key) {
// randomFieldKeys.add(key);
// }
//
// protected GenerationStrategy getStrategy(Class<?> dataType, String key) {
// return randomFieldType.contains(dataType) || randomFieldKeys.contains(key) ?
// GenerationStrategy.RANDOM : strategy;
// }
//
// protected FieldValueGenerator switchGeneratorStrategy(FieldValueGenerator generator,
// Class<?> dataType, String key) {
// generator.setStrategy(getStrategy(dataType, key));
// return generator;
// }
//
// private FieldValueGenerator getGenerator(Class<?> dataType, String key) {
// return switchGeneratorStrategy(getCachedGenerator(dataType), dataType, key);
// }
//
// private FieldValueGenerator getCachedGenerator(Class<?> dataType) {
// for (FieldValueGenerator generator: generators) {
// if (generator.isMatchType(dataType)) {
// return generator;
// }
// }
//
// return getDefaultFieldValueGenerator(dataType);
// }
//
// protected abstract FieldValueGenerator getDefaultFieldValueGenerator(Class<?> dataType);
// }
//
// Path: src/main/java/com/exmertec/dummie/generator/Inflater.java
// public class Inflater {
// private static <T> void inflateFields(T instance, DataGenerator dataGenerator, Class<T> classType) throws
// IllegalAccessException, InvocationTargetException {
// Field[] fields = classType.getDeclaredFields();
// PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils();
//
// for (Field field : fields) {
// if (!propertyUtils.isWriteable(instance, field.getName())) {
// continue;
// }
//
// Object value = dataGenerator.getData(field);
// BeanUtils.setProperty(instance, field.getName(), value);
// }
// }
//
// public static <T> void inflateInstance(T instance, DataGenerator cache, Class<T> type) throws
// InvocationTargetException, IllegalAccessException {
// if (type != null) {
// inflateFields(instance, cache, type);
// inflateInstance(instance, cache, type.getSuperclass());
// }
// }
// }
| import com.exmertec.dummie.generator.data.DataGenerator;
import com.exmertec.dummie.generator.Inflater; | package com.exmertec.dummie;
public class DummyBuilder<T> {
private final Class<T> type;
private final DataGenerator dataGenerator;
public DummyBuilder(Class<T> type, DataGenerator dataGenerator) {
this.type = type;
this.dataGenerator = dataGenerator;
}
public T build() {
try {
T instance = type.newInstance(); | // Path: src/main/java/com/exmertec/dummie/generator/data/DataGenerator.java
// public abstract class DataGenerator {
//
// private final List<FieldValueGenerator> generators;
//
// private final Set<String> randomFieldKeys;
//
// private final Set<Class<?>> randomFieldType;
//
// protected DataCache dataCache;
//
// protected GenerationStrategy strategy;
//
// public DataGenerator(GenerationStrategy strategy) {
// this(strategy, new KeyValueDataCache());
// }
//
// public DataGenerator(GenerationStrategy strategy, DataCache dataCache) {
// this.dataCache = dataCache;
// this.strategy = strategy;
//
// generators = new ArrayList<FieldValueGenerator>();
// randomFieldKeys = new HashSet<String>();
// randomFieldType = new HashSet<Class<?>>();
//
// addDefaultGenerators();
// }
//
// private void addDefaultGenerators() {
// generators.add(new StringFieldValueGenerator());
// generators.add(new ListFieldValueGenerator());
// generators.add(new MapFieldValueGenerator());
// generators.add(new SetFieldValueGenerator());
// generators.add(new BooleanFieldValueGenerator());
// generators.add(new ByteFieldValueGenerator());
// generators.add(new CharacterFieldValueGenerator());
// generators.add(new DoubleFieldValueGenerator());
// generators.add(new FloatFieldValueGenerator());
// generators.add(new IntegerFieldValueGenerator());
// generators.add(new LongFieldValueGenerator());
// generators.add(new ShortFieldValueGenerator());
// generators.add(new EnumFieldValueGenerator());
// generators.add(new BigDecimalFieldValueGenerator());
// }
//
// public Object getData(Field field) {
// Class<?> fieldType = field.getType();
// Object value = dataCache.getCachedData(fieldType, field.getName());
// if (value == null) {
// FieldValueGenerator generator = getGenerator(fieldType, field.getName());
// if (generator != null) {
// value = generator.generate(this, field);
// }
// }
// return value;
// }
//
// public Object getData(Class<?> dataType, String key) {
// Object value = dataCache.getCachedData(dataType, key);
// if (value == null) {
// FieldValueGenerator generator = getGenerator(dataType, key);
// if (generator != null) {
// value = generator.generate(this, dataType, key);
// }
// }
// return value;
// }
//
// public <T> void cacheData(Class<T> dataType, String key, Object value) {
// dataCache.cacheData(dataType, key, value);
// }
//
// public <T> void cacheData(Class<T> clazz, Object value) {
// dataCache.cacheData(clazz, value);
// }
//
// public <T> void dynamicCacheData(Class<T> dataType, String key, Object value) {
// if (getStrategy(dataType, key) == GenerationStrategy.DEFAULT) {
// dataCache.cacheData(dataType, key, value);
// }
// }
//
// public void random(Class<?> clazz) {
// randomFieldType.add(clazz);
// }
//
// public void random(String key) {
// randomFieldKeys.add(key);
// }
//
// protected GenerationStrategy getStrategy(Class<?> dataType, String key) {
// return randomFieldType.contains(dataType) || randomFieldKeys.contains(key) ?
// GenerationStrategy.RANDOM : strategy;
// }
//
// protected FieldValueGenerator switchGeneratorStrategy(FieldValueGenerator generator,
// Class<?> dataType, String key) {
// generator.setStrategy(getStrategy(dataType, key));
// return generator;
// }
//
// private FieldValueGenerator getGenerator(Class<?> dataType, String key) {
// return switchGeneratorStrategy(getCachedGenerator(dataType), dataType, key);
// }
//
// private FieldValueGenerator getCachedGenerator(Class<?> dataType) {
// for (FieldValueGenerator generator: generators) {
// if (generator.isMatchType(dataType)) {
// return generator;
// }
// }
//
// return getDefaultFieldValueGenerator(dataType);
// }
//
// protected abstract FieldValueGenerator getDefaultFieldValueGenerator(Class<?> dataType);
// }
//
// Path: src/main/java/com/exmertec/dummie/generator/Inflater.java
// public class Inflater {
// private static <T> void inflateFields(T instance, DataGenerator dataGenerator, Class<T> classType) throws
// IllegalAccessException, InvocationTargetException {
// Field[] fields = classType.getDeclaredFields();
// PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils();
//
// for (Field field : fields) {
// if (!propertyUtils.isWriteable(instance, field.getName())) {
// continue;
// }
//
// Object value = dataGenerator.getData(field);
// BeanUtils.setProperty(instance, field.getName(), value);
// }
// }
//
// public static <T> void inflateInstance(T instance, DataGenerator cache, Class<T> type) throws
// InvocationTargetException, IllegalAccessException {
// if (type != null) {
// inflateFields(instance, cache, type);
// inflateInstance(instance, cache, type.getSuperclass());
// }
// }
// }
// Path: src/main/java/com/exmertec/dummie/DummyBuilder.java
import com.exmertec.dummie.generator.data.DataGenerator;
import com.exmertec.dummie.generator.Inflater;
package com.exmertec.dummie;
public class DummyBuilder<T> {
private final Class<T> type;
private final DataGenerator dataGenerator;
public DummyBuilder(Class<T> type, DataGenerator dataGenerator) {
this.type = type;
this.dataGenerator = dataGenerator;
}
public T build() {
try {
T instance = type.newInstance(); | Inflater.inflateInstance(instance, dataGenerator, type); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/adapter/TopStoryAdapter.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/TopStory.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "image",
// "type",
// "id",
// "ga_prefix",
// "title"
// })
// public class TopStory {
//
// @JsonProperty("image")
// private String image;
// @JsonProperty("type")
// private Integer type;
// @JsonProperty("id")
// private Integer id;
// @JsonProperty("ga_prefix")
// private String gaPrefix;
// @JsonProperty("title")
// private String title;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The image
// */
// @JsonProperty("image")
// public String getImage() {
// return image;
// }
//
// /**
// *
// * @param image
// * The image
// */
// @JsonProperty("image")
// public void setImage(String image) {
// this.image = image;
// }
//
// /**
// *
// * @return
// * The type
// */
// @JsonProperty("type")
// public Integer getType() {
// return type;
// }
//
// /**
// *
// * @param type
// * The type
// */
// @JsonProperty("type")
// public void setType(Integer type) {
// this.type = type;
// }
//
// /**
// *
// * @return
// * The id
// */
// @JsonProperty("id")
// public Integer getId() {
// return id;
// }
//
// /**
// *
// * @param id
// * The id
// */
// @JsonProperty("id")
// public void setId(Integer id) {
// this.id = id;
// }
//
// /**
// *
// * @return
// * The gaPrefix
// */
// @JsonProperty("ga_prefix")
// public String getGaPrefix() {
// return gaPrefix;
// }
//
// /**
// *
// * @param gaPrefix
// * The ga_prefix
// */
// @JsonProperty("ga_prefix")
// public void setGaPrefix(String gaPrefix) {
// this.gaPrefix = gaPrefix;
// }
//
// /**
// *
// * @return
// * The title
// */
// @JsonProperty("title")
// public String getTitle() {
// return title;
// }
//
// /**
// *
// * @param title
// * The title
// */
// @JsonProperty("title")
// public void setTitle(String title) {
// this.title = title;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/RecyclerOnItemClickListener.java
// public interface RecyclerOnItemClickListener {
//
// void onItemClickListener(View v, Object obj);
// }
| import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.github.zzwwws.rxzhihudaily.R;
import com.github.zzwwws.rxzhihudaily.model.entities.TopStory;
import com.github.zzwwws.rxzhihudaily.presenter.infr.RecyclerOnItemClickListener;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick; | package com.github.zzwwws.rxzhihudaily.presenter.adapter;
/**
* Created by zzwwws on 2016/2/18.
*/
public class TopStoryAdapter extends PagerAdapter{
private RecyclerOnItemClickListener listener;
private Context context; | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/TopStory.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "image",
// "type",
// "id",
// "ga_prefix",
// "title"
// })
// public class TopStory {
//
// @JsonProperty("image")
// private String image;
// @JsonProperty("type")
// private Integer type;
// @JsonProperty("id")
// private Integer id;
// @JsonProperty("ga_prefix")
// private String gaPrefix;
// @JsonProperty("title")
// private String title;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The image
// */
// @JsonProperty("image")
// public String getImage() {
// return image;
// }
//
// /**
// *
// * @param image
// * The image
// */
// @JsonProperty("image")
// public void setImage(String image) {
// this.image = image;
// }
//
// /**
// *
// * @return
// * The type
// */
// @JsonProperty("type")
// public Integer getType() {
// return type;
// }
//
// /**
// *
// * @param type
// * The type
// */
// @JsonProperty("type")
// public void setType(Integer type) {
// this.type = type;
// }
//
// /**
// *
// * @return
// * The id
// */
// @JsonProperty("id")
// public Integer getId() {
// return id;
// }
//
// /**
// *
// * @param id
// * The id
// */
// @JsonProperty("id")
// public void setId(Integer id) {
// this.id = id;
// }
//
// /**
// *
// * @return
// * The gaPrefix
// */
// @JsonProperty("ga_prefix")
// public String getGaPrefix() {
// return gaPrefix;
// }
//
// /**
// *
// * @param gaPrefix
// * The ga_prefix
// */
// @JsonProperty("ga_prefix")
// public void setGaPrefix(String gaPrefix) {
// this.gaPrefix = gaPrefix;
// }
//
// /**
// *
// * @return
// * The title
// */
// @JsonProperty("title")
// public String getTitle() {
// return title;
// }
//
// /**
// *
// * @param title
// * The title
// */
// @JsonProperty("title")
// public void setTitle(String title) {
// this.title = title;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/RecyclerOnItemClickListener.java
// public interface RecyclerOnItemClickListener {
//
// void onItemClickListener(View v, Object obj);
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/adapter/TopStoryAdapter.java
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.github.zzwwws.rxzhihudaily.R;
import com.github.zzwwws.rxzhihudaily.model.entities.TopStory;
import com.github.zzwwws.rxzhihudaily.presenter.infr.RecyclerOnItemClickListener;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
package com.github.zzwwws.rxzhihudaily.presenter.adapter;
/**
* Created by zzwwws on 2016/2/18.
*/
public class TopStoryAdapter extends PagerAdapter{
private RecyclerOnItemClickListener listener;
private Context context; | private List<TopStory> topStories; |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/activity/BaseActivity.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/fragment/BaseFragment.java
// public abstract class BaseFragment extends Fragment {
// private static final Handler handler = new Handler();
// private int fragmentId;
// private boolean destroyed;
//
// protected final boolean isDestroyed() {
// return destroyed;
// }
//
// public int getFragmentId() {
// return fragmentId;
// }
//
// public void setFragmentId(int fragmentId) {
// this.fragmentId = fragmentId;
//
// }
//
// public final Context getContext() {
// return getActivity();
// }
//
// public void onActivityCreated(Bundle savedInstanceState) {
// super.onActivityCreated(savedInstanceState);
//
// LogUtil.ui("fragment: " + getClass().getSimpleName() + " onActivityCreated()");
//
// destroyed = false;
// }
//
// @Override
// public void onSaveInstanceState(Bundle outState) {
// super.onSaveInstanceState(outState);
//
// }
//
// public void onDestroy() {
// super.onDestroy();
// }
//
// protected final Handler getHandler() {
// return handler;
// }
//
// public void setUIFragmentBundle(Bundle bundle) {
//
// }
//
// protected final void postRunnable(final Runnable runnable) {
// handler.post(new Runnable() {
// @Override
// public void run() {
// // validate
// if (!isAdded()) {
// return;
// }
//
// // run
// runnable.run();
// }
// });
// }
//
// protected final void postDelayed(final Runnable runnable, long delay) {
// handler.postDelayed(new Runnable() {
// @Override
// public void run() {
// // validate
// if (!isAdded()) {
// return;
// }
//
// // run
// runnable.run();
// }
// }, delay);
// }
//
// protected void showKeyboard(boolean isShow) {
// Activity activity = getActivity();
// if (activity == null) {
// return;
// }
//
// InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
// if (imm == null) {
// return;
// }
//
// if (isShow) {
// if (activity.getCurrentFocus() == null) {
// imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
// } else {
// imm.showSoftInput(activity.getCurrentFocus(), 0);
// }
// } else {
// if (activity.getCurrentFocus() != null) {
// imm.hideSoftInputFromWindow(
// activity.getCurrentFocus().getWindowToken(),
// InputMethodManager.HIDE_NOT_ALWAYS);
// }
// }
// }
//
// protected void showKeyboardDelayed(View focus) {
// final View viewToFocus = focus;
// if (focus != null) {
// focus.requestFocus();
// }
//
// getHandler().postDelayed(new Runnable() {
// @Override
// public void run() {
// if (viewToFocus == null || viewToFocus.isFocused()) {
// showKeyboard(true);
// }
// }
// }, 200);
// }
//
// protected void showKeyboard() {
// Activity activity = getActivity();
// if (activity == null) {
// return;
// }
//
// InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
// if (imm == null) {
// return;
// }
//
// if (activity.getCurrentFocus() == null) {
// imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
// } else {
// imm.showSoftInput(activity.getCurrentFocus(), 0);
// }
// }
//
// protected void hideKeyboard(View view) {
// Activity activity = getActivity();
// if (activity == null) {
// return;
// }
//
// InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
// if (imm == null) {
// return;
// }
//
// imm.hideSoftInputFromWindow(
// view.getWindowToken(),
// InputMethodManager.HIDE_NOT_ALWAYS);
// }
// }
| import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.github.zzwwws.rxzhihudaily.presenter.fragment.BaseFragment; | package com.github.zzwwws.rxzhihudaily.presenter.activity;
/**
* Created by zzwwws on 2016/2/19.
*/
public class BaseActivity extends AppCompatActivity {
protected Menu menu;
protected void hideOption(int id) {
MenuItem item = menu.findItem(id);
item.setVisible(false);
}
protected void showOption(int id) {
MenuItem item = menu.findItem(id);
item.setVisible(true);
}
protected void setOptionTitle(int id, String title) {
MenuItem item = menu.findItem(id);
item.setTitle(title);
}
protected void setOptionIcon(int id, int iconRes) {
MenuItem item = menu.findItem(id);
item.setIcon(iconRes);
}
| // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/fragment/BaseFragment.java
// public abstract class BaseFragment extends Fragment {
// private static final Handler handler = new Handler();
// private int fragmentId;
// private boolean destroyed;
//
// protected final boolean isDestroyed() {
// return destroyed;
// }
//
// public int getFragmentId() {
// return fragmentId;
// }
//
// public void setFragmentId(int fragmentId) {
// this.fragmentId = fragmentId;
//
// }
//
// public final Context getContext() {
// return getActivity();
// }
//
// public void onActivityCreated(Bundle savedInstanceState) {
// super.onActivityCreated(savedInstanceState);
//
// LogUtil.ui("fragment: " + getClass().getSimpleName() + " onActivityCreated()");
//
// destroyed = false;
// }
//
// @Override
// public void onSaveInstanceState(Bundle outState) {
// super.onSaveInstanceState(outState);
//
// }
//
// public void onDestroy() {
// super.onDestroy();
// }
//
// protected final Handler getHandler() {
// return handler;
// }
//
// public void setUIFragmentBundle(Bundle bundle) {
//
// }
//
// protected final void postRunnable(final Runnable runnable) {
// handler.post(new Runnable() {
// @Override
// public void run() {
// // validate
// if (!isAdded()) {
// return;
// }
//
// // run
// runnable.run();
// }
// });
// }
//
// protected final void postDelayed(final Runnable runnable, long delay) {
// handler.postDelayed(new Runnable() {
// @Override
// public void run() {
// // validate
// if (!isAdded()) {
// return;
// }
//
// // run
// runnable.run();
// }
// }, delay);
// }
//
// protected void showKeyboard(boolean isShow) {
// Activity activity = getActivity();
// if (activity == null) {
// return;
// }
//
// InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
// if (imm == null) {
// return;
// }
//
// if (isShow) {
// if (activity.getCurrentFocus() == null) {
// imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
// } else {
// imm.showSoftInput(activity.getCurrentFocus(), 0);
// }
// } else {
// if (activity.getCurrentFocus() != null) {
// imm.hideSoftInputFromWindow(
// activity.getCurrentFocus().getWindowToken(),
// InputMethodManager.HIDE_NOT_ALWAYS);
// }
// }
// }
//
// protected void showKeyboardDelayed(View focus) {
// final View viewToFocus = focus;
// if (focus != null) {
// focus.requestFocus();
// }
//
// getHandler().postDelayed(new Runnable() {
// @Override
// public void run() {
// if (viewToFocus == null || viewToFocus.isFocused()) {
// showKeyboard(true);
// }
// }
// }, 200);
// }
//
// protected void showKeyboard() {
// Activity activity = getActivity();
// if (activity == null) {
// return;
// }
//
// InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
// if (imm == null) {
// return;
// }
//
// if (activity.getCurrentFocus() == null) {
// imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
// } else {
// imm.showSoftInput(activity.getCurrentFocus(), 0);
// }
// }
//
// protected void hideKeyboard(View view) {
// Activity activity = getActivity();
// if (activity == null) {
// return;
// }
//
// InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
// if (imm == null) {
// return;
// }
//
// imm.hideSoftInputFromWindow(
// view.getWindowToken(),
// InputMethodManager.HIDE_NOT_ALWAYS);
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/activity/BaseActivity.java
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.github.zzwwws.rxzhihudaily.presenter.fragment.BaseFragment;
package com.github.zzwwws.rxzhihudaily.presenter.activity;
/**
* Created by zzwwws on 2016/2/19.
*/
public class BaseActivity extends AppCompatActivity {
protected Menu menu;
protected void hideOption(int id) {
MenuItem item = menu.findItem(id);
item.setVisible(false);
}
protected void showOption(int id) {
MenuItem item = menu.findItem(id);
item.setVisible(true);
}
protected void setOptionTitle(int id, String title) {
MenuItem item = menu.findItem(id);
item.setTitle(title);
}
protected void setOptionIcon(int id, int iconRes) {
MenuItem item = menu.findItem(id);
item.setIcon(iconRes);
}
| protected void switchContent(BaseFragment from, BaseFragment to, Bundle bundle) { |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/DatabaseHelper.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
| import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.text.TextUtils;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil; | package com.github.zzwwws.rxzhihudaily.presenter.db.common;
/**
* Created by zzwwws on 2016/3/8.
*/
public class DatabaseHelper {
private static final String TAG = "db";
private static final int LOCK_RETRY_CHANCES = 3;
public static final Cursor rawQuery(SQLiteDatabase db, String sql) {
Cursor cursor = null;
for (int chance = 0; chance < LOCK_RETRY_CHANCES; chance++) {
boolean locked = false;
try {
cursor = db.rawQuery(sql, null);
} catch (SQLiteException e) {
// trace
e.printStackTrace(); | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/DatabaseHelper.java
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.text.TextUtils;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil;
package com.github.zzwwws.rxzhihudaily.presenter.db.common;
/**
* Created by zzwwws on 2016/3/8.
*/
public class DatabaseHelper {
private static final String TAG = "db";
private static final int LOCK_RETRY_CHANCES = 3;
public static final Cursor rawQuery(SQLiteDatabase db, String sql) {
Cursor cursor = null;
for (int chance = 0; chance < LOCK_RETRY_CHANCES; chance++) {
boolean locked = false;
try {
cursor = db.rawQuery(sql, null);
} catch (SQLiteException e) {
// trace
e.printStackTrace(); | LogUtil.i(TAG, "exec sql exception: " + e); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/AbstractDatabase.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
| import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil; | package com.github.zzwwws.rxzhihudaily.presenter.db.common;
/**
* Created by zzwwws on 2016/3/8.
*/
public abstract class AbstractDatabase {
private static final String TAG = "db";
protected final int version;
protected SQLiteDatabase database;
private boolean upgrade;
private Context context;
private String uid;
private String dbName;
public AbstractDatabase(Context context, String uid, String dbName, int dbVersion) {
this(context, uid, dbName, dbVersion, true);
}
public AbstractDatabase(Context context, String uid, String dbName, int dbVersion, boolean upgrade) {
this.context = context;
this.uid = uid;
this.dbName = dbName;
this.version = dbVersion;
this.upgrade = upgrade;
open();
}
protected static final String composeUserDbPath(String uid, String dbName) { | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/AbstractDatabase.java
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil;
package com.github.zzwwws.rxzhihudaily.presenter.db.common;
/**
* Created by zzwwws on 2016/3/8.
*/
public abstract class AbstractDatabase {
private static final String TAG = "db";
protected final int version;
protected SQLiteDatabase database;
private boolean upgrade;
private Context context;
private String uid;
private String dbName;
public AbstractDatabase(Context context, String uid, String dbName, int dbVersion) {
this(context, uid, dbName, dbVersion, true);
}
public AbstractDatabase(Context context, String uid, String dbName, int dbVersion, boolean upgrade) {
this.context = context;
this.uid = uid;
this.dbName = dbName;
this.version = dbVersion;
this.upgrade = upgrade;
open();
}
protected static final String composeUserDbPath(String uid, String dbName) { | return BaseApplication.get().getApplicationInfo().dataDir + "/" + uid + "/" + dbName; |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/AbstractDatabase.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
| import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil; | return BaseApplication.get().getApplicationInfo().dataDir + "/" + uid + "/" + dbName;
}
public Context getContext(){
return context;
}
public boolean open() {
String dbPath = composeUserDbPath(uid, dbName);
if (upgrade) {
openOrUpdagrade(dbPath, dbName, version);
} else {
openOnly(dbPath, dbName, version);
}
return database != null;
}
public boolean opened() {
return database != null;
}
private void openOnly(String dbPath, String dbName, int dbVersion) {
try {
database = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
if (database.getVersion() < dbVersion) {
// need upgrade
database.close();
database = null;
}
} catch (Exception e) { | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/AbstractDatabase.java
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil;
return BaseApplication.get().getApplicationInfo().dataDir + "/" + uid + "/" + dbName;
}
public Context getContext(){
return context;
}
public boolean open() {
String dbPath = composeUserDbPath(uid, dbName);
if (upgrade) {
openOrUpdagrade(dbPath, dbName, version);
} else {
openOnly(dbPath, dbName, version);
}
return database != null;
}
public boolean opened() {
return database != null;
}
private void openOnly(String dbPath, String dbName, int dbVersion) {
try {
database = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
if (database.getVersion() < dbVersion) {
// need upgrade
database.close();
database = null;
}
} catch (Exception e) { | LogUtil.i(TAG, "open database " + dbName + " only failed: " + e); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/fragment/BaseFragment.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
| import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil; | package com.github.zzwwws.rxzhihudaily.presenter.fragment;
/**
* Created by zzwwws on 2016/2/19.
*/
public abstract class BaseFragment extends Fragment {
private static final Handler handler = new Handler();
private int fragmentId;
private boolean destroyed;
protected final boolean isDestroyed() {
return destroyed;
}
public int getFragmentId() {
return fragmentId;
}
public void setFragmentId(int fragmentId) {
this.fragmentId = fragmentId;
}
public final Context getContext() {
return getActivity();
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
| // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/fragment/BaseFragment.java
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil;
package com.github.zzwwws.rxzhihudaily.presenter.fragment;
/**
* Created by zzwwws on 2016/2/19.
*/
public abstract class BaseFragment extends Fragment {
private static final Handler handler = new Handler();
private int fragmentId;
private boolean destroyed;
protected final boolean isDestroyed() {
return destroyed;
}
public int getFragmentId() {
return fragmentId;
}
public void setFragmentId(int fragmentId) {
this.fragmentId = fragmentId;
}
public final Context getContext() {
return getActivity();
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
| LogUtil.ui("fragment: " + getClass().getSimpleName() + " onActivityCreated()"); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/LockSafeCursor.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
| import android.database.CharArrayBuffer;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.database.sqlite.SQLiteException;
import android.text.TextUtils;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil; | }
}
}
return 0f;
}
@Override
public double getDouble(int columnIndex) {
for (int chance = 0; chance < LOCK_RETRY_CHANCES; chance++) {
try {
return cursor.getDouble(columnIndex);
} catch (RuntimeException e) {
if (!isSQLiteDatabaseLockedException(e)) {
throw e;
}
}
}
return 0;
}
private static final int LOCK_RETRY_CHANCES = 3;
private static final boolean isSQLiteDatabaseLockedException(Exception e) {
e.printStackTrace();
if (e instanceof SQLiteException) {
String message = e.getMessage();
boolean locked = (!TextUtils.isEmpty(message) && message.contains("lock"));
if (locked) { | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/LockSafeCursor.java
import android.database.CharArrayBuffer;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.database.sqlite.SQLiteException;
import android.text.TextUtils;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil;
}
}
}
return 0f;
}
@Override
public double getDouble(int columnIndex) {
for (int chance = 0; chance < LOCK_RETRY_CHANCES; chance++) {
try {
return cursor.getDouble(columnIndex);
} catch (RuntimeException e) {
if (!isSQLiteDatabaseLockedException(e)) {
throw e;
}
}
}
return 0;
}
private static final int LOCK_RETRY_CHANCES = 3;
private static final boolean isSQLiteDatabaseLockedException(Exception e) {
e.printStackTrace();
if (e instanceof SQLiteException) {
String message = e.getMessage();
boolean locked = (!TextUtils.isEmpty(message) && message.contains("lock"));
if (locked) { | LogUtil.w("db", "query locked!"); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/EmoUtil.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
| import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.util.LruCache;
import android.util.DisplayMetrics;
import android.util.Xml;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern; | package com.github.zzwwws.rxzhihudaily.common.util;
public class EmoUtil {
private static final String ASSET = "emoticon";
private static final String XML = "xml";
// max cache size
private static final int CACHE_MAX_SIZE = 1024;
private static Pattern pattern;
// default entries
private static final List<Entry> defaultEntries = new ArrayList<Entry>();
// entries for display
private static final List<Entry> displayEntries = new ArrayList<Entry>();
// text to entry
private static final Map<String, Entry> text2entry = new HashMap<String, Entry>();
// asset bitmap cache, key: asset path
private static LruCache<String, Bitmap> drawableCache;
static { | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/EmoUtil.java
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.util.LruCache;
import android.util.DisplayMetrics;
import android.util.Xml;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
package com.github.zzwwws.rxzhihudaily.common.util;
public class EmoUtil {
private static final String ASSET = "emoticon";
private static final String XML = "xml";
// max cache size
private static final int CACHE_MAX_SIZE = 1024;
private static Pattern pattern;
// default entries
private static final List<Entry> defaultEntries = new ArrayList<Entry>();
// entries for display
private static final List<Entry> displayEntries = new ArrayList<Entry>();
// text to entry
private static final Map<String, Entry> text2entry = new HashMap<String, Entry>();
// asset bitmap cache, key: asset path
private static LruCache<String, Bitmap> drawableCache;
static { | Context context = BaseApplication.get(); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/adapter/ChiefEditorAdapter.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/Editor.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "url",
// "bio",
// "id",
// "avatar",
// "name"
// })
// public class Editor {
//
// @JsonProperty("url")
// private String url;
// @JsonProperty("bio")
// private String bio;
// @JsonProperty("id")
// private Integer id;
// @JsonProperty("avatar")
// private String avatar;
// @JsonProperty("name")
// private String name;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The url
// */
// @JsonProperty("url")
// public String getUrl() {
// return url;
// }
//
// /**
// *
// * @param url
// * The url
// */
// @JsonProperty("url")
// public void setUrl(String url) {
// this.url = url;
// }
//
// /**
// *
// * @return
// * The bio
// */
// @JsonProperty("bio")
// public String getBio() {
// return bio;
// }
//
// /**
// *
// * @param bio
// * The bio
// */
// @JsonProperty("bio")
// public void setBio(String bio) {
// this.bio = bio;
// }
//
// /**
// *
// * @return
// * The id
// */
// @JsonProperty("id")
// public Integer getId() {
// return id;
// }
//
// /**
// *
// * @param id
// * The id
// */
// @JsonProperty("id")
// public void setId(Integer id) {
// this.id = id;
// }
//
// /**
// *
// * @return
// * The avatar
// */
// @JsonProperty("avatar")
// public String getAvatar() {
// return avatar;
// }
//
// /**
// *
// * @param avatar
// * The avatar
// */
// @JsonProperty("avatar")
// public void setAvatar(String avatar) {
// this.avatar = avatar;
// }
//
// /**
// *
// * @return
// * The name
// */
// @JsonProperty("name")
// public String getName() {
// return name;
// }
//
// /**
// *
// * @param name
// * The name
// */
// @JsonProperty("name")
// public void setName(String name) {
// this.name = name;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
| import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.github.zzwwws.rxzhihudaily.R;
import com.github.zzwwws.rxzhihudaily.model.entities.Editor;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife; | package com.github.zzwwws.rxzhihudaily.presenter.adapter;
/**
* Created by zzwwws on 2016/2/20.
*/
public class ChiefEditorAdapter extends BaseAdapter {
private Context context;
private LayoutInflater inflater; | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/Editor.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "url",
// "bio",
// "id",
// "avatar",
// "name"
// })
// public class Editor {
//
// @JsonProperty("url")
// private String url;
// @JsonProperty("bio")
// private String bio;
// @JsonProperty("id")
// private Integer id;
// @JsonProperty("avatar")
// private String avatar;
// @JsonProperty("name")
// private String name;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The url
// */
// @JsonProperty("url")
// public String getUrl() {
// return url;
// }
//
// /**
// *
// * @param url
// * The url
// */
// @JsonProperty("url")
// public void setUrl(String url) {
// this.url = url;
// }
//
// /**
// *
// * @return
// * The bio
// */
// @JsonProperty("bio")
// public String getBio() {
// return bio;
// }
//
// /**
// *
// * @param bio
// * The bio
// */
// @JsonProperty("bio")
// public void setBio(String bio) {
// this.bio = bio;
// }
//
// /**
// *
// * @return
// * The id
// */
// @JsonProperty("id")
// public Integer getId() {
// return id;
// }
//
// /**
// *
// * @param id
// * The id
// */
// @JsonProperty("id")
// public void setId(Integer id) {
// this.id = id;
// }
//
// /**
// *
// * @return
// * The avatar
// */
// @JsonProperty("avatar")
// public String getAvatar() {
// return avatar;
// }
//
// /**
// *
// * @param avatar
// * The avatar
// */
// @JsonProperty("avatar")
// public void setAvatar(String avatar) {
// this.avatar = avatar;
// }
//
// /**
// *
// * @return
// * The name
// */
// @JsonProperty("name")
// public String getName() {
// return name;
// }
//
// /**
// *
// * @param name
// * The name
// */
// @JsonProperty("name")
// public void setName(String name) {
// this.name = name;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/adapter/ChiefEditorAdapter.java
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.github.zzwwws.rxzhihudaily.R;
import com.github.zzwwws.rxzhihudaily.model.entities.Editor;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
package com.github.zzwwws.rxzhihudaily.presenter.adapter;
/**
* Created by zzwwws on 2016/2/20.
*/
public class ChiefEditorAdapter extends BaseAdapter {
private Context context;
private LayoutInflater inflater; | private List<Editor> editors; |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/impl/CommentImpl.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/CommentEntities.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "comments"
// })
// public class CommentEntities {
//
// @JsonProperty("comments")
// private List<Comment> comments = new ArrayList<Comment>();
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The comments
// */
// @JsonProperty("comments")
// public List<Comment> getComments() {
// return comments;
// }
//
// /**
// *
// * @param comments
// * The comments
// */
// @JsonProperty("comments")
// public void setComments(List<Comment> comments) {
// this.comments = comments;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/CommentView.java
// public interface CommentView {
//
// void showLongComments(List<Comment> longComments);
//
// void loadShortComments(List<Comment> shortComments);
//
// void onCommentClick(View view, Comment comment);
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/LongCommentCase.java
// public class LongCommentCase extends UserCase<CommentEntities, String> {
// @Override
// protected Observable<CommentEntities> interactor(String id) {
// return ServiceRest.getInstance().getLongComments(id);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/ShortCommentCase.java
// public class ShortCommentCase extends UserCase<CommentEntities, String> {
// @Override
// protected Observable<CommentEntities> interactor(String id) {
// return ServiceRest.getInstance().getShortComments(id);
// }
// }
| import com.github.zzwwws.rxzhihudaily.model.entities.CommentEntities;
import com.github.zzwwws.rxzhihudaily.presenter.infr.CommentView;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.LongCommentCase;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.ShortCommentCase;
import rx.Subscriber; | package com.github.zzwwws.rxzhihudaily.presenter.impl;
/**
* Created by zzwwws on 2016/2/23.
*/
public class CommentImpl implements CommentPresenter<CommentView> {
Subscriber<CommentEntities> longCommentSub;
Subscriber<CommentEntities> shortCommentSub; | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/CommentEntities.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "comments"
// })
// public class CommentEntities {
//
// @JsonProperty("comments")
// private List<Comment> comments = new ArrayList<Comment>();
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The comments
// */
// @JsonProperty("comments")
// public List<Comment> getComments() {
// return comments;
// }
//
// /**
// *
// * @param comments
// * The comments
// */
// @JsonProperty("comments")
// public void setComments(List<Comment> comments) {
// this.comments = comments;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/CommentView.java
// public interface CommentView {
//
// void showLongComments(List<Comment> longComments);
//
// void loadShortComments(List<Comment> shortComments);
//
// void onCommentClick(View view, Comment comment);
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/LongCommentCase.java
// public class LongCommentCase extends UserCase<CommentEntities, String> {
// @Override
// protected Observable<CommentEntities> interactor(String id) {
// return ServiceRest.getInstance().getLongComments(id);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/ShortCommentCase.java
// public class ShortCommentCase extends UserCase<CommentEntities, String> {
// @Override
// protected Observable<CommentEntities> interactor(String id) {
// return ServiceRest.getInstance().getShortComments(id);
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/impl/CommentImpl.java
import com.github.zzwwws.rxzhihudaily.model.entities.CommentEntities;
import com.github.zzwwws.rxzhihudaily.presenter.infr.CommentView;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.LongCommentCase;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.ShortCommentCase;
import rx.Subscriber;
package com.github.zzwwws.rxzhihudaily.presenter.impl;
/**
* Created by zzwwws on 2016/2/23.
*/
public class CommentImpl implements CommentPresenter<CommentView> {
Subscriber<CommentEntities> longCommentSub;
Subscriber<CommentEntities> shortCommentSub; | LongCommentCase longCommentCase; |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/impl/CommentImpl.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/CommentEntities.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "comments"
// })
// public class CommentEntities {
//
// @JsonProperty("comments")
// private List<Comment> comments = new ArrayList<Comment>();
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The comments
// */
// @JsonProperty("comments")
// public List<Comment> getComments() {
// return comments;
// }
//
// /**
// *
// * @param comments
// * The comments
// */
// @JsonProperty("comments")
// public void setComments(List<Comment> comments) {
// this.comments = comments;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/CommentView.java
// public interface CommentView {
//
// void showLongComments(List<Comment> longComments);
//
// void loadShortComments(List<Comment> shortComments);
//
// void onCommentClick(View view, Comment comment);
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/LongCommentCase.java
// public class LongCommentCase extends UserCase<CommentEntities, String> {
// @Override
// protected Observable<CommentEntities> interactor(String id) {
// return ServiceRest.getInstance().getLongComments(id);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/ShortCommentCase.java
// public class ShortCommentCase extends UserCase<CommentEntities, String> {
// @Override
// protected Observable<CommentEntities> interactor(String id) {
// return ServiceRest.getInstance().getShortComments(id);
// }
// }
| import com.github.zzwwws.rxzhihudaily.model.entities.CommentEntities;
import com.github.zzwwws.rxzhihudaily.presenter.infr.CommentView;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.LongCommentCase;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.ShortCommentCase;
import rx.Subscriber; | package com.github.zzwwws.rxzhihudaily.presenter.impl;
/**
* Created by zzwwws on 2016/2/23.
*/
public class CommentImpl implements CommentPresenter<CommentView> {
Subscriber<CommentEntities> longCommentSub;
Subscriber<CommentEntities> shortCommentSub;
LongCommentCase longCommentCase; | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/CommentEntities.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "comments"
// })
// public class CommentEntities {
//
// @JsonProperty("comments")
// private List<Comment> comments = new ArrayList<Comment>();
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The comments
// */
// @JsonProperty("comments")
// public List<Comment> getComments() {
// return comments;
// }
//
// /**
// *
// * @param comments
// * The comments
// */
// @JsonProperty("comments")
// public void setComments(List<Comment> comments) {
// this.comments = comments;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/CommentView.java
// public interface CommentView {
//
// void showLongComments(List<Comment> longComments);
//
// void loadShortComments(List<Comment> shortComments);
//
// void onCommentClick(View view, Comment comment);
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/LongCommentCase.java
// public class LongCommentCase extends UserCase<CommentEntities, String> {
// @Override
// protected Observable<CommentEntities> interactor(String id) {
// return ServiceRest.getInstance().getLongComments(id);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/ShortCommentCase.java
// public class ShortCommentCase extends UserCase<CommentEntities, String> {
// @Override
// protected Observable<CommentEntities> interactor(String id) {
// return ServiceRest.getInstance().getShortComments(id);
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/impl/CommentImpl.java
import com.github.zzwwws.rxzhihudaily.model.entities.CommentEntities;
import com.github.zzwwws.rxzhihudaily.presenter.infr.CommentView;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.LongCommentCase;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.ShortCommentCase;
import rx.Subscriber;
package com.github.zzwwws.rxzhihudaily.presenter.impl;
/**
* Created by zzwwws on 2016/2/23.
*/
public class CommentImpl implements CommentPresenter<CommentView> {
Subscriber<CommentEntities> longCommentSub;
Subscriber<CommentEntities> shortCommentSub;
LongCommentCase longCommentCase; | ShortCommentCase shortCommentCase; |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/adapter/MenuAdapter.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/TopicWrapper.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "color",
// "thumbnail",
// "description",
// "id",
// "name"
// })
// public class TopicWrapper {
//
// @JsonProperty("color")
// private Integer color;
// @JsonProperty("thumbnail")
// private String thumbnail;
// @JsonProperty("description")
// private String description;
// @JsonProperty("id")
// private Integer id;
// @JsonProperty("name")
// private String name;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The color
// */
// @JsonProperty("color")
// public Integer getColor() {
// return color;
// }
//
// /**
// *
// * @param color
// * The color
// */
// @JsonProperty("color")
// public void setColor(Integer color) {
// this.color = color;
// }
//
// /**
// *
// * @return
// * The thumbnail
// */
// @JsonProperty("thumbnail")
// public String getThumbnail() {
// return thumbnail;
// }
//
// /**
// *
// * @param thumbnail
// * The thumbnail
// */
// @JsonProperty("thumbnail")
// public void setThumbnail(String thumbnail) {
// this.thumbnail = thumbnail;
// }
//
// /**
// *
// * @return
// * The description
// */
// @JsonProperty("description")
// public String getDescription() {
// return description;
// }
//
// /**
// *
// * @param description
// * The description
// */
// @JsonProperty("description")
// public void setDescription(String description) {
// this.description = description;
// }
//
// /**
// *
// * @return
// * The id
// */
// @JsonProperty("id")
// public Integer getId() {
// return id;
// }
//
// /**
// *
// * @param id
// * The id
// */
// @JsonProperty("id")
// public void setId(Integer id) {
// this.id = id;
// }
//
// /**
// *
// * @return
// * The name
// */
// @JsonProperty("name")
// public String getName() {
// return name;
// }
//
// /**
// *
// * @param name
// * The name
// */
// @JsonProperty("name")
// public void setName(String name) {
// this.name = name;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/RecyclerOnItemClickListener.java
// public interface RecyclerOnItemClickListener {
//
// void onItemClickListener(View v, Object obj);
// }
| import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.github.zzwwws.rxzhihudaily.R;
import com.github.zzwwws.rxzhihudaily.model.entities.TopicWrapper;
import com.github.zzwwws.rxzhihudaily.presenter.infr.RecyclerOnItemClickListener;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView; | package com.github.zzwwws.rxzhihudaily.presenter.adapter;
/**
* Created by zzwwws on 2016/2/15.
*/
public class MenuAdapter extends BaseRecyclerAdapter<RecyclerView.ViewHolder> {
private static final int TYPE_HEADER = 0x01;
private static final int TYPE_TOPICS = 0x02;
private Context context; | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/TopicWrapper.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "color",
// "thumbnail",
// "description",
// "id",
// "name"
// })
// public class TopicWrapper {
//
// @JsonProperty("color")
// private Integer color;
// @JsonProperty("thumbnail")
// private String thumbnail;
// @JsonProperty("description")
// private String description;
// @JsonProperty("id")
// private Integer id;
// @JsonProperty("name")
// private String name;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The color
// */
// @JsonProperty("color")
// public Integer getColor() {
// return color;
// }
//
// /**
// *
// * @param color
// * The color
// */
// @JsonProperty("color")
// public void setColor(Integer color) {
// this.color = color;
// }
//
// /**
// *
// * @return
// * The thumbnail
// */
// @JsonProperty("thumbnail")
// public String getThumbnail() {
// return thumbnail;
// }
//
// /**
// *
// * @param thumbnail
// * The thumbnail
// */
// @JsonProperty("thumbnail")
// public void setThumbnail(String thumbnail) {
// this.thumbnail = thumbnail;
// }
//
// /**
// *
// * @return
// * The description
// */
// @JsonProperty("description")
// public String getDescription() {
// return description;
// }
//
// /**
// *
// * @param description
// * The description
// */
// @JsonProperty("description")
// public void setDescription(String description) {
// this.description = description;
// }
//
// /**
// *
// * @return
// * The id
// */
// @JsonProperty("id")
// public Integer getId() {
// return id;
// }
//
// /**
// *
// * @param id
// * The id
// */
// @JsonProperty("id")
// public void setId(Integer id) {
// this.id = id;
// }
//
// /**
// *
// * @return
// * The name
// */
// @JsonProperty("name")
// public String getName() {
// return name;
// }
//
// /**
// *
// * @param name
// * The name
// */
// @JsonProperty("name")
// public void setName(String name) {
// this.name = name;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/RecyclerOnItemClickListener.java
// public interface RecyclerOnItemClickListener {
//
// void onItemClickListener(View v, Object obj);
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/adapter/MenuAdapter.java
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.github.zzwwws.rxzhihudaily.R;
import com.github.zzwwws.rxzhihudaily.model.entities.TopicWrapper;
import com.github.zzwwws.rxzhihudaily.presenter.infr.RecyclerOnItemClickListener;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;
package com.github.zzwwws.rxzhihudaily.presenter.adapter;
/**
* Created by zzwwws on 2016/2/15.
*/
public class MenuAdapter extends BaseRecyclerAdapter<RecyclerView.ViewHolder> {
private static final int TYPE_HEADER = 0x01;
private static final int TYPE_TOPICS = 0x02;
private Context context; | private List<TopicWrapper> mTopics; |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/adapter/MenuAdapter.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/TopicWrapper.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "color",
// "thumbnail",
// "description",
// "id",
// "name"
// })
// public class TopicWrapper {
//
// @JsonProperty("color")
// private Integer color;
// @JsonProperty("thumbnail")
// private String thumbnail;
// @JsonProperty("description")
// private String description;
// @JsonProperty("id")
// private Integer id;
// @JsonProperty("name")
// private String name;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The color
// */
// @JsonProperty("color")
// public Integer getColor() {
// return color;
// }
//
// /**
// *
// * @param color
// * The color
// */
// @JsonProperty("color")
// public void setColor(Integer color) {
// this.color = color;
// }
//
// /**
// *
// * @return
// * The thumbnail
// */
// @JsonProperty("thumbnail")
// public String getThumbnail() {
// return thumbnail;
// }
//
// /**
// *
// * @param thumbnail
// * The thumbnail
// */
// @JsonProperty("thumbnail")
// public void setThumbnail(String thumbnail) {
// this.thumbnail = thumbnail;
// }
//
// /**
// *
// * @return
// * The description
// */
// @JsonProperty("description")
// public String getDescription() {
// return description;
// }
//
// /**
// *
// * @param description
// * The description
// */
// @JsonProperty("description")
// public void setDescription(String description) {
// this.description = description;
// }
//
// /**
// *
// * @return
// * The id
// */
// @JsonProperty("id")
// public Integer getId() {
// return id;
// }
//
// /**
// *
// * @param id
// * The id
// */
// @JsonProperty("id")
// public void setId(Integer id) {
// this.id = id;
// }
//
// /**
// *
// * @return
// * The name
// */
// @JsonProperty("name")
// public String getName() {
// return name;
// }
//
// /**
// *
// * @param name
// * The name
// */
// @JsonProperty("name")
// public void setName(String name) {
// this.name = name;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/RecyclerOnItemClickListener.java
// public interface RecyclerOnItemClickListener {
//
// void onItemClickListener(View v, Object obj);
// }
| import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.github.zzwwws.rxzhihudaily.R;
import com.github.zzwwws.rxzhihudaily.model.entities.TopicWrapper;
import com.github.zzwwws.rxzhihudaily.presenter.infr.RecyclerOnItemClickListener;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView; | }
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof MenuViewHolder) {
MenuViewHolder menuViewHolder = (MenuViewHolder) holder;
menuViewHolder.rowText.setText(mTopics.get(position - 1).getName());
menuViewHolder.rowIcon.setImageResource(R.drawable.menu_follow);
menuViewHolder.rowText.setTag(mTopics.get(position - 1));
}
}
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position))
return TYPE_HEADER;
return TYPE_TOPICS;
}
@Override
public int getItemCount() {
return mTopics.size() + 1;
}
private boolean isPositionHeader(int position) {
return position == 0;
}
@Override | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/TopicWrapper.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "color",
// "thumbnail",
// "description",
// "id",
// "name"
// })
// public class TopicWrapper {
//
// @JsonProperty("color")
// private Integer color;
// @JsonProperty("thumbnail")
// private String thumbnail;
// @JsonProperty("description")
// private String description;
// @JsonProperty("id")
// private Integer id;
// @JsonProperty("name")
// private String name;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The color
// */
// @JsonProperty("color")
// public Integer getColor() {
// return color;
// }
//
// /**
// *
// * @param color
// * The color
// */
// @JsonProperty("color")
// public void setColor(Integer color) {
// this.color = color;
// }
//
// /**
// *
// * @return
// * The thumbnail
// */
// @JsonProperty("thumbnail")
// public String getThumbnail() {
// return thumbnail;
// }
//
// /**
// *
// * @param thumbnail
// * The thumbnail
// */
// @JsonProperty("thumbnail")
// public void setThumbnail(String thumbnail) {
// this.thumbnail = thumbnail;
// }
//
// /**
// *
// * @return
// * The description
// */
// @JsonProperty("description")
// public String getDescription() {
// return description;
// }
//
// /**
// *
// * @param description
// * The description
// */
// @JsonProperty("description")
// public void setDescription(String description) {
// this.description = description;
// }
//
// /**
// *
// * @return
// * The id
// */
// @JsonProperty("id")
// public Integer getId() {
// return id;
// }
//
// /**
// *
// * @param id
// * The id
// */
// @JsonProperty("id")
// public void setId(Integer id) {
// this.id = id;
// }
//
// /**
// *
// * @return
// * The name
// */
// @JsonProperty("name")
// public String getName() {
// return name;
// }
//
// /**
// *
// * @param name
// * The name
// */
// @JsonProperty("name")
// public void setName(String name) {
// this.name = name;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/RecyclerOnItemClickListener.java
// public interface RecyclerOnItemClickListener {
//
// void onItemClickListener(View v, Object obj);
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/adapter/MenuAdapter.java
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.github.zzwwws.rxzhihudaily.R;
import com.github.zzwwws.rxzhihudaily.model.entities.TopicWrapper;
import com.github.zzwwws.rxzhihudaily.presenter.infr.RecyclerOnItemClickListener;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof MenuViewHolder) {
MenuViewHolder menuViewHolder = (MenuViewHolder) holder;
menuViewHolder.rowText.setText(mTopics.get(position - 1).getName());
menuViewHolder.rowIcon.setImageResource(R.drawable.menu_follow);
menuViewHolder.rowText.setTag(mTopics.get(position - 1));
}
}
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position))
return TYPE_HEADER;
return TYPE_TOPICS;
}
@Override
public int getItemCount() {
return mTopics.size() + 1;
}
private boolean isPositionHeader(int position) {
return position == 0;
}
@Override | public void setOnItemClickListener(RecyclerOnItemClickListener listener) { |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ToastUtil.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/Handlers.java
// public final class Handlers {
// public static final String DEFAULT_TAG = "Default";
//
// private static Handlers instance;
//
// public static synchronized Handlers sharedInstance() {
// if (instance == null) {
// instance = new Handlers();
// }
//
// return instance;
// }
//
// private static Handler sharedHandler;
//
// /**
// * get shared handler for main looper
// * @param context
// * @return
// */
// public static final Handler sharedHandler(Context context) {
// /**
// * duplicate handlers !!! i don't care
// */
//
// if (sharedHandler == null) {
// sharedHandler = new Handler(context.getMainLooper());
// }
//
// return sharedHandler;
// }
//
// /**
// * get new handler for main looper
// * @param context
// * @return
// */
// public static final Handler newHandler(Context context) {
// return new Handler(context.getMainLooper());
// }
//
// private Handlers() {
//
// }
//
// /**
// * get new handler for a background default looper
// * @return
// */
// public final Handler newHandler() {
// return newHandler(DEFAULT_TAG);
// }
//
// /**
// * get new handler for a background stand alone looper identified by tag
// * @param tag
// * @return
// */
// public final Handler newHandler(String tag) {
// return new Handler(getHandlerThread(tag).getLooper());
// }
//
// private final HashMap<String, HandlerThread> threads = new HashMap<String, HandlerThread>();
//
// private final HandlerThread getHandlerThread(String tag) {
// HandlerThread handlerThread = null;
//
// synchronized (threads) {
// handlerThread = threads.get(tag);
//
// if (handlerThread == null) {
// handlerThread = new HandlerThread(nameOfTag(tag));
//
// handlerThread.start();
//
// threads.put(tag, handlerThread);
// }
// }
//
// return handlerThread;
// }
//
// private final static String nameOfTag(String tag) {
// return "HT-" + (TextUtils.isEmpty(tag) ? DEFAULT_TAG : tag);
// }
// }
| import android.content.Context;
import android.os.Handler;
import android.widget.Toast;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import com.github.zzwwws.rxzhihudaily.common.Handlers; | package com.github.zzwwws.rxzhihudaily.common.util;
public class ToastUtil {
private static final int FAVORITE_ALERT_TIMES = 20;
/**
* handler to show toasts safely
*/
private static Handler mHandler = null;
private static Toast toast = null;
private static Toast customToast = null;
public static Toast makeToast(Context mContext, int resId) {
return Toast.makeText(mContext, resId, Toast.LENGTH_SHORT);
}
public static Toast makeToast(Context mContext, String text) {
return Toast.makeText(mContext, text, Toast.LENGTH_SHORT);
}
public static void showToast(Context mContext, int resId) { | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/Handlers.java
// public final class Handlers {
// public static final String DEFAULT_TAG = "Default";
//
// private static Handlers instance;
//
// public static synchronized Handlers sharedInstance() {
// if (instance == null) {
// instance = new Handlers();
// }
//
// return instance;
// }
//
// private static Handler sharedHandler;
//
// /**
// * get shared handler for main looper
// * @param context
// * @return
// */
// public static final Handler sharedHandler(Context context) {
// /**
// * duplicate handlers !!! i don't care
// */
//
// if (sharedHandler == null) {
// sharedHandler = new Handler(context.getMainLooper());
// }
//
// return sharedHandler;
// }
//
// /**
// * get new handler for main looper
// * @param context
// * @return
// */
// public static final Handler newHandler(Context context) {
// return new Handler(context.getMainLooper());
// }
//
// private Handlers() {
//
// }
//
// /**
// * get new handler for a background default looper
// * @return
// */
// public final Handler newHandler() {
// return newHandler(DEFAULT_TAG);
// }
//
// /**
// * get new handler for a background stand alone looper identified by tag
// * @param tag
// * @return
// */
// public final Handler newHandler(String tag) {
// return new Handler(getHandlerThread(tag).getLooper());
// }
//
// private final HashMap<String, HandlerThread> threads = new HashMap<String, HandlerThread>();
//
// private final HandlerThread getHandlerThread(String tag) {
// HandlerThread handlerThread = null;
//
// synchronized (threads) {
// handlerThread = threads.get(tag);
//
// if (handlerThread == null) {
// handlerThread = new HandlerThread(nameOfTag(tag));
//
// handlerThread.start();
//
// threads.put(tag, handlerThread);
// }
// }
//
// return handlerThread;
// }
//
// private final static String nameOfTag(String tag) {
// return "HT-" + (TextUtils.isEmpty(tag) ? DEFAULT_TAG : tag);
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ToastUtil.java
import android.content.Context;
import android.os.Handler;
import android.widget.Toast;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import com.github.zzwwws.rxzhihudaily.common.Handlers;
package com.github.zzwwws.rxzhihudaily.common.util;
public class ToastUtil {
private static final int FAVORITE_ALERT_TIMES = 20;
/**
* handler to show toasts safely
*/
private static Handler mHandler = null;
private static Toast toast = null;
private static Toast customToast = null;
public static Toast makeToast(Context mContext, int resId) {
return Toast.makeText(mContext, resId, Toast.LENGTH_SHORT);
}
public static Toast makeToast(Context mContext, String text) {
return Toast.makeText(mContext, text, Toast.LENGTH_SHORT);
}
public static void showToast(Context mContext, int resId) { | final Context context = (mContext == null ? BaseApplication.get() : mContext); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ToastUtil.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/Handlers.java
// public final class Handlers {
// public static final String DEFAULT_TAG = "Default";
//
// private static Handlers instance;
//
// public static synchronized Handlers sharedInstance() {
// if (instance == null) {
// instance = new Handlers();
// }
//
// return instance;
// }
//
// private static Handler sharedHandler;
//
// /**
// * get shared handler for main looper
// * @param context
// * @return
// */
// public static final Handler sharedHandler(Context context) {
// /**
// * duplicate handlers !!! i don't care
// */
//
// if (sharedHandler == null) {
// sharedHandler = new Handler(context.getMainLooper());
// }
//
// return sharedHandler;
// }
//
// /**
// * get new handler for main looper
// * @param context
// * @return
// */
// public static final Handler newHandler(Context context) {
// return new Handler(context.getMainLooper());
// }
//
// private Handlers() {
//
// }
//
// /**
// * get new handler for a background default looper
// * @return
// */
// public final Handler newHandler() {
// return newHandler(DEFAULT_TAG);
// }
//
// /**
// * get new handler for a background stand alone looper identified by tag
// * @param tag
// * @return
// */
// public final Handler newHandler(String tag) {
// return new Handler(getHandlerThread(tag).getLooper());
// }
//
// private final HashMap<String, HandlerThread> threads = new HashMap<String, HandlerThread>();
//
// private final HandlerThread getHandlerThread(String tag) {
// HandlerThread handlerThread = null;
//
// synchronized (threads) {
// handlerThread = threads.get(tag);
//
// if (handlerThread == null) {
// handlerThread = new HandlerThread(nameOfTag(tag));
//
// handlerThread.start();
//
// threads.put(tag, handlerThread);
// }
// }
//
// return handlerThread;
// }
//
// private final static String nameOfTag(String tag) {
// return "HT-" + (TextUtils.isEmpty(tag) ? DEFAULT_TAG : tag);
// }
// }
| import android.content.Context;
import android.os.Handler;
import android.widget.Toast;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import com.github.zzwwws.rxzhihudaily.common.Handlers; | }
toast.show();
}
});
}
public static void showLongToast(Context mContext, String text) {
final Context context = (mContext == null ? BaseApplication.get() : mContext);
final String msg = text;
sharedHandler(context).post(new Runnable() {
@Override
public void run() {
if (toast != null) {
toast.setText(msg);
toast.setDuration(Toast.LENGTH_LONG);
} else {
toast = Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_LONG);
}
toast.show();
}
});
}
private static Handler sharedHandler(Context context) {
if (context == null) {
context = BaseApplication.get();
}
if (mHandler == null) { | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/Handlers.java
// public final class Handlers {
// public static final String DEFAULT_TAG = "Default";
//
// private static Handlers instance;
//
// public static synchronized Handlers sharedInstance() {
// if (instance == null) {
// instance = new Handlers();
// }
//
// return instance;
// }
//
// private static Handler sharedHandler;
//
// /**
// * get shared handler for main looper
// * @param context
// * @return
// */
// public static final Handler sharedHandler(Context context) {
// /**
// * duplicate handlers !!! i don't care
// */
//
// if (sharedHandler == null) {
// sharedHandler = new Handler(context.getMainLooper());
// }
//
// return sharedHandler;
// }
//
// /**
// * get new handler for main looper
// * @param context
// * @return
// */
// public static final Handler newHandler(Context context) {
// return new Handler(context.getMainLooper());
// }
//
// private Handlers() {
//
// }
//
// /**
// * get new handler for a background default looper
// * @return
// */
// public final Handler newHandler() {
// return newHandler(DEFAULT_TAG);
// }
//
// /**
// * get new handler for a background stand alone looper identified by tag
// * @param tag
// * @return
// */
// public final Handler newHandler(String tag) {
// return new Handler(getHandlerThread(tag).getLooper());
// }
//
// private final HashMap<String, HandlerThread> threads = new HashMap<String, HandlerThread>();
//
// private final HandlerThread getHandlerThread(String tag) {
// HandlerThread handlerThread = null;
//
// synchronized (threads) {
// handlerThread = threads.get(tag);
//
// if (handlerThread == null) {
// handlerThread = new HandlerThread(nameOfTag(tag));
//
// handlerThread.start();
//
// threads.put(tag, handlerThread);
// }
// }
//
// return handlerThread;
// }
//
// private final static String nameOfTag(String tag) {
// return "HT-" + (TextUtils.isEmpty(tag) ? DEFAULT_TAG : tag);
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ToastUtil.java
import android.content.Context;
import android.os.Handler;
import android.widget.Toast;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import com.github.zzwwws.rxzhihudaily.common.Handlers;
}
toast.show();
}
});
}
public static void showLongToast(Context mContext, String text) {
final Context context = (mContext == null ? BaseApplication.get() : mContext);
final String msg = text;
sharedHandler(context).post(new Runnable() {
@Override
public void run() {
if (toast != null) {
toast.setText(msg);
toast.setDuration(Toast.LENGTH_LONG);
} else {
toast = Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_LONG);
}
toast.show();
}
});
}
private static Handler sharedHandler(Context context) {
if (context == null) {
context = BaseApplication.get();
}
if (mHandler == null) { | mHandler = Handlers.sharedHandler(context); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/DatabaseRevision.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
| import android.database.sqlite.SQLiteDatabase;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil;
import java.util.ArrayList;
import java.util.List; | if (stepMode) {
while (atInitial < atTarget) {
upgrade(db, atInitial, atInitial + 1);
atInitial++;
}
} else {
upgrade(db, atInitial, atTarget);
}
}
}
private int at(int dbVer) {
int at = -1;
for (int i = 0; i < versions.size(); i++) {
if (dbVer >= versions.get(i).versionNumber) {
at = i;
}
}
return at;
}
private int at() {
return versions.size() - 1;
}
private void create(SQLiteDatabase db, int atTarget) {
Version target = versions.get(atTarget);
| // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/LogUtil.java
// public class LogUtil {
// public static final void init(String logFile, int level) {
// LogImpl.init(logFile, level);
// }
//
// public static final void v(String tag, String msg) {
// LogImpl.v(tag, buildMessage(msg));
// }
//
// public static final void v(String tag, String msg, Throwable thr) {
// LogImpl.v(tag, buildMessage(msg), thr);
// }
//
// public static final void d(String tag, String msg) {
// LogImpl.d(tag, buildMessage(msg));
// }
//
// public static final void d(String tag, String msg, Throwable thr) {
// LogImpl.d(tag, buildMessage(msg), thr);
// }
//
// public static final void i(String tag, String msg) {
// LogImpl.i(tag, buildMessage(msg));
// }
//
// public static final void i(String tag, String msg, Throwable thr) {
// LogImpl.i(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, String msg) {
// LogImpl.w(tag, buildMessage(msg));
// }
//
// public static final void w(String tag, String msg, Throwable thr) {
// LogImpl.w(tag, buildMessage(msg), thr);
// }
//
// public static final void w(String tag, Throwable thr) {
// LogImpl.w(tag, buildMessage(""), thr);
// }
//
// public static final void e(String tag, String msg) {
// LogImpl.e(tag, buildMessage(msg));
// }
//
// public static final void e(String tag, String msg, Throwable thr) {
// LogImpl.e(tag, buildMessage(msg), thr);
// }
//
// public static final void ui(String msg) {
// LogImpl.i("ui", buildMessage(msg));
// }
//
// public static final void core(String msg) {
// LogImpl.i("core", buildMessage(msg));
// }
//
// public static final void coreDebug(String msg) {
// LogImpl.d("core", buildMessage(msg));
// }
//
// public static final void res(String msg) {
// LogImpl.i("RES", buildMessage(msg));
// }
//
// public static final void resDebug(String msg) {
// LogImpl.d("RES", buildMessage(msg));
// }
//
// public static final void audio(String msg) {
// LogImpl.i("AudioRecorder", buildMessage(msg));
// }
//
// public static final void audioPlay(String msg) {
// LogImpl.i("AudioPlay", buildMessage(msg));
// }
//
// public static void vincent(String msg) {
// LogImpl.v("Vincent", buildMessage(msg));
// }
//
// public static void king(String msg) {
// LogImpl.v("king", buildMessage(msg));
// }
//
// public static void bonus(String msg) {
// LogImpl.i("Bonus", buildMessage(msg));
// }
//
// public static void pipeline(String prefix, String msg) {
// LogImpl.i("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static void pipelineDebug(String prefix, String msg) {
// LogImpl.d("Pipeline", prefix + " " + buildMessage(msg));
// }
//
// public static String getLogFileName(String cat) {
// return LogImpl.getLogFileName(cat);
// }
//
// private static String buildMessage(String msg) {
// return msg == null ? "" : msg;
// }
//
// public static void ask(String s) {
// LogImpl.v("ask", buildMessage(s));
// }
//
// public static void fish(String s) {
// LogImpl.v("logfish", buildMessage(s));
// }
//
// public static void teamsnsEntrance(String s) {
// LogImpl.i("teamsnsEntrance", buildMessage(s));
// }
//
// public static void asha(String s) {
// LogImpl.v("asha", buildMessage(s));
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/db/common/DatabaseRevision.java
import android.database.sqlite.SQLiteDatabase;
import com.github.zzwwws.rxzhihudaily.common.util.LogUtil;
import java.util.ArrayList;
import java.util.List;
if (stepMode) {
while (atInitial < atTarget) {
upgrade(db, atInitial, atInitial + 1);
atInitial++;
}
} else {
upgrade(db, atInitial, atTarget);
}
}
}
private int at(int dbVer) {
int at = -1;
for (int i = 0; i < versions.size(); i++) {
if (dbVer >= versions.get(i).versionNumber) {
at = i;
}
}
return at;
}
private int at() {
return versions.size() - 1;
}
private void create(SQLiteDatabase db, int atTarget) {
Version target = versions.get(atTarget);
| LogUtil.d(TAG, "create:" + " table " + this + " target " + target); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/impl/SplashImpl.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/StartImage.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "text",
// "img"
// })
// public class StartImage {
//
// @JsonProperty("text")
// private String text;
// @JsonProperty("img")
// private String img;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The text
// */
// @JsonProperty("text")
// public String getText() {
// return text;
// }
//
// /**
// *
// * @param text
// * The text
// */
// @JsonProperty("text")
// public void setText(String text) {
// this.text = text;
// }
//
// /**
// *
// * @return
// * The img
// */
// @JsonProperty("img")
// public String getImg() {
// return img;
// }
//
// /**
// *
// * @param img
// * The img
// */
// @JsonProperty("img")
// public void setImg(String img) {
// this.img = img;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/SplashImageView.java
// public interface SplashImageView {
//
// void showStartImage(StartImage startImage);
//
// void nextStep();
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/SplashCase.java
// public class SplashCase extends UserCase<StartImage, String> {
// @Override
// protected Observable<StartImage> interactor(String density) {
// return ServiceRest.getInstance().getStartImage(density);
// }
// }
| import com.github.zzwwws.rxzhihudaily.model.entities.StartImage;
import com.github.zzwwws.rxzhihudaily.presenter.infr.SplashImageView;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.SplashCase;
import rx.Subscriber; | package com.github.zzwwws.rxzhihudaily.presenter.impl;
/**
* Created by zzw on 16/2/22.
*/
public class SplashImpl implements SplashPresenter<SplashImageView> {
Subscriber<StartImage> startImageSubscriber;
SplashImageView splashImageView; | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/model/entities/StartImage.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonPropertyOrder({
// "text",
// "img"
// })
// public class StartImage {
//
// @JsonProperty("text")
// private String text;
// @JsonProperty("img")
// private String img;
// @JsonIgnore
// private Map<String, Object> additionalProperties = new HashMap<String, Object>();
//
// /**
// *
// * @return
// * The text
// */
// @JsonProperty("text")
// public String getText() {
// return text;
// }
//
// /**
// *
// * @param text
// * The text
// */
// @JsonProperty("text")
// public void setText(String text) {
// this.text = text;
// }
//
// /**
// *
// * @return
// * The img
// */
// @JsonProperty("img")
// public String getImg() {
// return img;
// }
//
// /**
// *
// * @param img
// * The img
// */
// @JsonProperty("img")
// public void setImg(String img) {
// this.img = img;
// }
//
// @JsonAnyGetter
// public Map<String, Object> getAdditionalProperties() {
// return this.additionalProperties;
// }
//
// @JsonAnySetter
// public void setAdditionalProperty(String name, Object value) {
// this.additionalProperties.put(name, value);
// }
//
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/infr/SplashImageView.java
// public interface SplashImageView {
//
// void showStartImage(StartImage startImage);
//
// void nextStep();
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/usercase/SplashCase.java
// public class SplashCase extends UserCase<StartImage, String> {
// @Override
// protected Observable<StartImage> interactor(String density) {
// return ServiceRest.getInstance().getStartImage(density);
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/presenter/impl/SplashImpl.java
import com.github.zzwwws.rxzhihudaily.model.entities.StartImage;
import com.github.zzwwws.rxzhihudaily.presenter.infr.SplashImageView;
import com.github.zzwwws.rxzhihudaily.presenter.usercase.SplashCase;
import rx.Subscriber;
package com.github.zzwwws.rxzhihudaily.presenter.impl;
/**
* Created by zzw on 16/2/22.
*/
public class SplashImpl implements SplashPresenter<SplashImageView> {
Subscriber<StartImage> startImageSubscriber;
SplashImageView splashImageView; | SplashCase splashCase; |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ScreenUtil.java
// public class ScreenUtil {
// private static final String TAG = "ScreenUtil";
// public static int screenWidth;
// public static int screenHeight;
// public static int screenMin;// 宽高中,较小的值
// public static int screenMax;// 宽高中,较大的值
// public static float density;
// public static float scaleDensity;
// public static float xdpi;
// public static float ydpi;
// public static int densityDpi;
// public static int dialogWidth;
// public static int statusbarheight;
// public static int navbarheight;
// private static double RATIO = 0.85;
//
// public static void GetInfo(Context context) {
// if (null == context) {
// return;
// }
// DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
// screenWidth = dm.widthPixels;
// screenHeight = dm.heightPixels;
// screenMin = (screenWidth > screenHeight) ? screenHeight : screenWidth;
// screenMax = (screenWidth < screenHeight) ? screenHeight : screenWidth;
// density = dm.density;
// scaleDensity = dm.scaledDensity;
// xdpi = dm.xdpi;
// ydpi = dm.ydpi;
// densityDpi = dm.densityDpi;
// statusbarheight = getStatusBarHeight(context);
// navbarheight = getNavBarHeight(context);
// Log.d(TAG, "screenWidth=" + screenWidth + " screenHeight=" + screenHeight + " density=" + density);
// }
//
// public static int getStatusBarHeight(Context context) {
// Class<?> c = null;
// Object obj = null;
// Field field = null;
// int x = 0, sbar = 0;
// try {
// c = Class.forName("com.android.internal.R$dimen");
// obj = c.newInstance();
// field = c.getField("status_bar_height");
// x = Integer.parseInt(field.get(obj).toString());
// sbar = context.getResources().getDimensionPixelSize(x);
// } catch (Exception E) {
// E.printStackTrace();
// }
// return sbar;
// }
//
// public static int getNavBarHeight(Context context) {
// Resources resources = context.getResources();
// int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
// if (resourceId > 0) {
// return resources.getDimensionPixelSize(resourceId);
// }
// return 0;
// }
//
// public static int dip2px(float dipValue) {
// final float scale = ScreenUtil.getDisplayDensity();
// return (int) (dipValue * scale + 0.5f);
// }
//
// public static int px2dip(float pxValue) {
// final float scale = ScreenUtil.getDisplayDensity();
// return (int) (pxValue / scale + 0.5f);
// }
//
// private static float getDisplayDensity() {
// if (density == 0) {
// GetInfo(BaseApplication.get());
// }
// return density;
// }
//
// public static int getDisplayWidth() {
// if (screenWidth == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenWidth;
// }
//
// public static int getDisplayHeight() {
// if (screenHeight == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenHeight;
// }
//
// public static int getScreenMin() {
// if (screenMin == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenMin;
// }
//
// public static int getScreenMax() {
// if (screenMin == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenMax;
// }
//
// public static int getDialogWidth() {
// dialogWidth = (int) (getScreenMin() * RATIO);
// return dialogWidth;
// }
//
// public static String getImageDensity(){
// return getDisplayWidth()+"*"+getDisplayHeight();
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/StrictModeUtil.java
// public class StrictModeUtil {
//
// public static void startStrictMode(){
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD){
// startThreadStrictMode();
// startVmStrictMode();
// }
// }
//
// @TargetApi(9)
// private static final void startThreadStrictMode(){
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads().permitDiskWrites().penaltyLog().build());
// }
//
// @TargetApi(9)
// private static final void startVmStrictMode(){
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
// }
// }
| import android.app.Application;
import com.github.zzwwws.rxzhihudaily.common.util.ScreenUtil;
import com.github.zzwwws.rxzhihudaily.common.util.StrictModeUtil; | package com.github.zzwwws.rxzhihudaily.common;
public class BaseApplication extends Application {
private static BaseApplication instance;
public static BaseApplication get() {
return instance;
}
@Override
public void onCreate() {
super.onCreate();
instance = (BaseApplication) getApplicationContext();
if (AppConfig.DEBUG) { | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ScreenUtil.java
// public class ScreenUtil {
// private static final String TAG = "ScreenUtil";
// public static int screenWidth;
// public static int screenHeight;
// public static int screenMin;// 宽高中,较小的值
// public static int screenMax;// 宽高中,较大的值
// public static float density;
// public static float scaleDensity;
// public static float xdpi;
// public static float ydpi;
// public static int densityDpi;
// public static int dialogWidth;
// public static int statusbarheight;
// public static int navbarheight;
// private static double RATIO = 0.85;
//
// public static void GetInfo(Context context) {
// if (null == context) {
// return;
// }
// DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
// screenWidth = dm.widthPixels;
// screenHeight = dm.heightPixels;
// screenMin = (screenWidth > screenHeight) ? screenHeight : screenWidth;
// screenMax = (screenWidth < screenHeight) ? screenHeight : screenWidth;
// density = dm.density;
// scaleDensity = dm.scaledDensity;
// xdpi = dm.xdpi;
// ydpi = dm.ydpi;
// densityDpi = dm.densityDpi;
// statusbarheight = getStatusBarHeight(context);
// navbarheight = getNavBarHeight(context);
// Log.d(TAG, "screenWidth=" + screenWidth + " screenHeight=" + screenHeight + " density=" + density);
// }
//
// public static int getStatusBarHeight(Context context) {
// Class<?> c = null;
// Object obj = null;
// Field field = null;
// int x = 0, sbar = 0;
// try {
// c = Class.forName("com.android.internal.R$dimen");
// obj = c.newInstance();
// field = c.getField("status_bar_height");
// x = Integer.parseInt(field.get(obj).toString());
// sbar = context.getResources().getDimensionPixelSize(x);
// } catch (Exception E) {
// E.printStackTrace();
// }
// return sbar;
// }
//
// public static int getNavBarHeight(Context context) {
// Resources resources = context.getResources();
// int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
// if (resourceId > 0) {
// return resources.getDimensionPixelSize(resourceId);
// }
// return 0;
// }
//
// public static int dip2px(float dipValue) {
// final float scale = ScreenUtil.getDisplayDensity();
// return (int) (dipValue * scale + 0.5f);
// }
//
// public static int px2dip(float pxValue) {
// final float scale = ScreenUtil.getDisplayDensity();
// return (int) (pxValue / scale + 0.5f);
// }
//
// private static float getDisplayDensity() {
// if (density == 0) {
// GetInfo(BaseApplication.get());
// }
// return density;
// }
//
// public static int getDisplayWidth() {
// if (screenWidth == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenWidth;
// }
//
// public static int getDisplayHeight() {
// if (screenHeight == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenHeight;
// }
//
// public static int getScreenMin() {
// if (screenMin == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenMin;
// }
//
// public static int getScreenMax() {
// if (screenMin == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenMax;
// }
//
// public static int getDialogWidth() {
// dialogWidth = (int) (getScreenMin() * RATIO);
// return dialogWidth;
// }
//
// public static String getImageDensity(){
// return getDisplayWidth()+"*"+getDisplayHeight();
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/StrictModeUtil.java
// public class StrictModeUtil {
//
// public static void startStrictMode(){
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD){
// startThreadStrictMode();
// startVmStrictMode();
// }
// }
//
// @TargetApi(9)
// private static final void startThreadStrictMode(){
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads().permitDiskWrites().penaltyLog().build());
// }
//
// @TargetApi(9)
// private static final void startVmStrictMode(){
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
import android.app.Application;
import com.github.zzwwws.rxzhihudaily.common.util.ScreenUtil;
import com.github.zzwwws.rxzhihudaily.common.util.StrictModeUtil;
package com.github.zzwwws.rxzhihudaily.common;
public class BaseApplication extends Application {
private static BaseApplication instance;
public static BaseApplication get() {
return instance;
}
@Override
public void onCreate() {
super.onCreate();
instance = (BaseApplication) getApplicationContext();
if (AppConfig.DEBUG) { | StrictModeUtil.startStrictMode(); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ScreenUtil.java
// public class ScreenUtil {
// private static final String TAG = "ScreenUtil";
// public static int screenWidth;
// public static int screenHeight;
// public static int screenMin;// 宽高中,较小的值
// public static int screenMax;// 宽高中,较大的值
// public static float density;
// public static float scaleDensity;
// public static float xdpi;
// public static float ydpi;
// public static int densityDpi;
// public static int dialogWidth;
// public static int statusbarheight;
// public static int navbarheight;
// private static double RATIO = 0.85;
//
// public static void GetInfo(Context context) {
// if (null == context) {
// return;
// }
// DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
// screenWidth = dm.widthPixels;
// screenHeight = dm.heightPixels;
// screenMin = (screenWidth > screenHeight) ? screenHeight : screenWidth;
// screenMax = (screenWidth < screenHeight) ? screenHeight : screenWidth;
// density = dm.density;
// scaleDensity = dm.scaledDensity;
// xdpi = dm.xdpi;
// ydpi = dm.ydpi;
// densityDpi = dm.densityDpi;
// statusbarheight = getStatusBarHeight(context);
// navbarheight = getNavBarHeight(context);
// Log.d(TAG, "screenWidth=" + screenWidth + " screenHeight=" + screenHeight + " density=" + density);
// }
//
// public static int getStatusBarHeight(Context context) {
// Class<?> c = null;
// Object obj = null;
// Field field = null;
// int x = 0, sbar = 0;
// try {
// c = Class.forName("com.android.internal.R$dimen");
// obj = c.newInstance();
// field = c.getField("status_bar_height");
// x = Integer.parseInt(field.get(obj).toString());
// sbar = context.getResources().getDimensionPixelSize(x);
// } catch (Exception E) {
// E.printStackTrace();
// }
// return sbar;
// }
//
// public static int getNavBarHeight(Context context) {
// Resources resources = context.getResources();
// int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
// if (resourceId > 0) {
// return resources.getDimensionPixelSize(resourceId);
// }
// return 0;
// }
//
// public static int dip2px(float dipValue) {
// final float scale = ScreenUtil.getDisplayDensity();
// return (int) (dipValue * scale + 0.5f);
// }
//
// public static int px2dip(float pxValue) {
// final float scale = ScreenUtil.getDisplayDensity();
// return (int) (pxValue / scale + 0.5f);
// }
//
// private static float getDisplayDensity() {
// if (density == 0) {
// GetInfo(BaseApplication.get());
// }
// return density;
// }
//
// public static int getDisplayWidth() {
// if (screenWidth == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenWidth;
// }
//
// public static int getDisplayHeight() {
// if (screenHeight == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenHeight;
// }
//
// public static int getScreenMin() {
// if (screenMin == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenMin;
// }
//
// public static int getScreenMax() {
// if (screenMin == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenMax;
// }
//
// public static int getDialogWidth() {
// dialogWidth = (int) (getScreenMin() * RATIO);
// return dialogWidth;
// }
//
// public static String getImageDensity(){
// return getDisplayWidth()+"*"+getDisplayHeight();
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/StrictModeUtil.java
// public class StrictModeUtil {
//
// public static void startStrictMode(){
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD){
// startThreadStrictMode();
// startVmStrictMode();
// }
// }
//
// @TargetApi(9)
// private static final void startThreadStrictMode(){
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads().permitDiskWrites().penaltyLog().build());
// }
//
// @TargetApi(9)
// private static final void startVmStrictMode(){
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
// }
// }
| import android.app.Application;
import com.github.zzwwws.rxzhihudaily.common.util.ScreenUtil;
import com.github.zzwwws.rxzhihudaily.common.util.StrictModeUtil; | package com.github.zzwwws.rxzhihudaily.common;
public class BaseApplication extends Application {
private static BaseApplication instance;
public static BaseApplication get() {
return instance;
}
@Override
public void onCreate() {
super.onCreate();
instance = (BaseApplication) getApplicationContext();
if (AppConfig.DEBUG) {
StrictModeUtil.startStrictMode();
} | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ScreenUtil.java
// public class ScreenUtil {
// private static final String TAG = "ScreenUtil";
// public static int screenWidth;
// public static int screenHeight;
// public static int screenMin;// 宽高中,较小的值
// public static int screenMax;// 宽高中,较大的值
// public static float density;
// public static float scaleDensity;
// public static float xdpi;
// public static float ydpi;
// public static int densityDpi;
// public static int dialogWidth;
// public static int statusbarheight;
// public static int navbarheight;
// private static double RATIO = 0.85;
//
// public static void GetInfo(Context context) {
// if (null == context) {
// return;
// }
// DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
// screenWidth = dm.widthPixels;
// screenHeight = dm.heightPixels;
// screenMin = (screenWidth > screenHeight) ? screenHeight : screenWidth;
// screenMax = (screenWidth < screenHeight) ? screenHeight : screenWidth;
// density = dm.density;
// scaleDensity = dm.scaledDensity;
// xdpi = dm.xdpi;
// ydpi = dm.ydpi;
// densityDpi = dm.densityDpi;
// statusbarheight = getStatusBarHeight(context);
// navbarheight = getNavBarHeight(context);
// Log.d(TAG, "screenWidth=" + screenWidth + " screenHeight=" + screenHeight + " density=" + density);
// }
//
// public static int getStatusBarHeight(Context context) {
// Class<?> c = null;
// Object obj = null;
// Field field = null;
// int x = 0, sbar = 0;
// try {
// c = Class.forName("com.android.internal.R$dimen");
// obj = c.newInstance();
// field = c.getField("status_bar_height");
// x = Integer.parseInt(field.get(obj).toString());
// sbar = context.getResources().getDimensionPixelSize(x);
// } catch (Exception E) {
// E.printStackTrace();
// }
// return sbar;
// }
//
// public static int getNavBarHeight(Context context) {
// Resources resources = context.getResources();
// int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
// if (resourceId > 0) {
// return resources.getDimensionPixelSize(resourceId);
// }
// return 0;
// }
//
// public static int dip2px(float dipValue) {
// final float scale = ScreenUtil.getDisplayDensity();
// return (int) (dipValue * scale + 0.5f);
// }
//
// public static int px2dip(float pxValue) {
// final float scale = ScreenUtil.getDisplayDensity();
// return (int) (pxValue / scale + 0.5f);
// }
//
// private static float getDisplayDensity() {
// if (density == 0) {
// GetInfo(BaseApplication.get());
// }
// return density;
// }
//
// public static int getDisplayWidth() {
// if (screenWidth == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenWidth;
// }
//
// public static int getDisplayHeight() {
// if (screenHeight == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenHeight;
// }
//
// public static int getScreenMin() {
// if (screenMin == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenMin;
// }
//
// public static int getScreenMax() {
// if (screenMin == 0) {
// GetInfo(BaseApplication.get());
// }
// return screenMax;
// }
//
// public static int getDialogWidth() {
// dialogWidth = (int) (getScreenMin() * RATIO);
// return dialogWidth;
// }
//
// public static String getImageDensity(){
// return getDisplayWidth()+"*"+getDisplayHeight();
// }
// }
//
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/StrictModeUtil.java
// public class StrictModeUtil {
//
// public static void startStrictMode(){
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD){
// startThreadStrictMode();
// startVmStrictMode();
// }
// }
//
// @TargetApi(9)
// private static final void startThreadStrictMode(){
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads().permitDiskWrites().penaltyLog().build());
// }
//
// @TargetApi(9)
// private static final void startVmStrictMode(){
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
import android.app.Application;
import com.github.zzwwws.rxzhihudaily.common.util.ScreenUtil;
import com.github.zzwwws.rxzhihudaily.common.util.StrictModeUtil;
package com.github.zzwwws.rxzhihudaily.common;
public class BaseApplication extends Application {
private static BaseApplication instance;
public static BaseApplication get() {
return instance;
}
@Override
public void onCreate() {
super.onCreate();
instance = (BaseApplication) getApplicationContext();
if (AppConfig.DEBUG) {
StrictModeUtil.startStrictMode();
} | ScreenUtil.GetInfo(instance); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ScreenUtil.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
| import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.Log;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import java.lang.reflect.Field; | field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
sbar = context.getResources().getDimensionPixelSize(x);
} catch (Exception E) {
E.printStackTrace();
}
return sbar;
}
public static int getNavBarHeight(Context context) {
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}
public static int dip2px(float dipValue) {
final float scale = ScreenUtil.getDisplayDensity();
return (int) (dipValue * scale + 0.5f);
}
public static int px2dip(float pxValue) {
final float scale = ScreenUtil.getDisplayDensity();
return (int) (pxValue / scale + 0.5f);
}
private static float getDisplayDensity() {
if (density == 0) { | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/ScreenUtil.java
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.Log;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
import java.lang.reflect.Field;
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
sbar = context.getResources().getDimensionPixelSize(x);
} catch (Exception E) {
E.printStackTrace();
}
return sbar;
}
public static int getNavBarHeight(Context context) {
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}
public static int dip2px(float dipValue) {
final float scale = ScreenUtil.getDisplayDensity();
return (int) (dipValue * scale + 0.5f);
}
public static int px2dip(float pxValue) {
final float scale = ScreenUtil.getDisplayDensity();
return (int) (pxValue / scale + 0.5f);
}
private static float getDisplayDensity() {
if (density == 0) { | GetInfo(BaseApplication.get()); |
zzwwws/RxZhihuDaily | app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/NetworkUtil.java | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
| import android.content.Context;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication; | Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
if (c != null) {
if (c.moveToFirst()) {
String user = c.getString(c.getColumnIndex("user"));
if (user != null && user.startsWith(CONNECT_TYPE_CTNET)) {
apntype = CONNECT_TYPE_CTNET;
} else if (user != null && user.startsWith(CONNECT_TYPE_CTWAP)) {
apntype = CONNECT_TYPE_CTWAP;
} else if (user != null && user.startsWith(CONNECT_TYPE_CMWAP)) {
apntype = CONNECT_TYPE_CMWAP;
} else if (user != null && user.startsWith(CONNECT_TYPE_CMNET)) {
apntype = CONNECT_TYPE_CMNET;
} else if (user != null && user.startsWith(CONNECT_TYPE_UNIWAP)) {
apntype = CONNECT_TYPE_UNIWAP;
} else if (user != null && user.startsWith(CONNECT_TYPE_UNINET)) {
apntype = CONNECT_TYPE_UNINET;
} else if (user != null && user.startsWith(CONNECT_TYPE_UNI3GWAP)) {
apntype = CONNECT_TYPE_UNI3GWAP;
} else if (user != null && user.startsWith(CONNECT_TYPE_UNI3GNET)) {
apntype = CONNECT_TYPE_UNI3GNET;
}
}
c.close();
c = null;
}
return apntype;
}
public static String getNetType() { | // Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/BaseApplication.java
// public class BaseApplication extends Application {
//
// private static BaseApplication instance;
//
// public static BaseApplication get() {
// return instance;
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// instance = (BaseApplication) getApplicationContext();
//
// if (AppConfig.DEBUG) {
// StrictModeUtil.startStrictMode();
// }
// ScreenUtil.GetInfo(instance);
// }
// }
// Path: app/src/main/java/com/github/zzwwws/rxzhihudaily/common/util/NetworkUtil.java
import android.content.Context;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.github.zzwwws.rxzhihudaily.common.BaseApplication;
Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
if (c != null) {
if (c.moveToFirst()) {
String user = c.getString(c.getColumnIndex("user"));
if (user != null && user.startsWith(CONNECT_TYPE_CTNET)) {
apntype = CONNECT_TYPE_CTNET;
} else if (user != null && user.startsWith(CONNECT_TYPE_CTWAP)) {
apntype = CONNECT_TYPE_CTWAP;
} else if (user != null && user.startsWith(CONNECT_TYPE_CMWAP)) {
apntype = CONNECT_TYPE_CMWAP;
} else if (user != null && user.startsWith(CONNECT_TYPE_CMNET)) {
apntype = CONNECT_TYPE_CMNET;
} else if (user != null && user.startsWith(CONNECT_TYPE_UNIWAP)) {
apntype = CONNECT_TYPE_UNIWAP;
} else if (user != null && user.startsWith(CONNECT_TYPE_UNINET)) {
apntype = CONNECT_TYPE_UNINET;
} else if (user != null && user.startsWith(CONNECT_TYPE_UNI3GWAP)) {
apntype = CONNECT_TYPE_UNI3GWAP;
} else if (user != null && user.startsWith(CONNECT_TYPE_UNI3GNET)) {
apntype = CONNECT_TYPE_UNI3GNET;
}
}
c.close();
c = null;
}
return apntype;
}
public static String getNetType() { | int type = NetworkUtil.getNetType(BaseApplication.get()); |
angelozerr/jsbuild-eclipse | grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntFile.java | // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTasksQuery.java
// public class TernGruntTasksQuery extends TernQuery {
//
// public TernGruntTasksQuery() {
// super("grunt-tasks");
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/AbstractBuildFile.java
// public abstract class AbstractBuildFile extends AbstractBuildFileNode implements
// IJSBuildFile {
//
// private final IFile file;
// private final String factoryId;
// private boolean parsed;
// private final Map<String, ITask> tasks;
//
// public AbstractBuildFile(IFile file, String factoryId) {
// this.file = file;
// this.factoryId = factoryId;
// this.tasks = new HashMap<String, ITask>();
// }
//
// @Override
// public String getName() {
// return file.getName();
// }
//
// @Override
// public IFile getBuildFileResource() {
// return file;
// }
//
// @Override
// public String getBuildFileName() {
// return file.getFullPath().toOSString();
// }
//
// @Override
// public IJSBuildFileNode getParentNode() {
// return null;
// }
//
// @Override
// public String getFactoryId() {
// return factoryId;
// }
//
// @Override
// public void parseBuildFile() throws CoreException {
// parseBuildFile(false);
// }
//
// @Override
// public void parseBuildFile(boolean force) throws CoreException {
// if (parsed && !force) {
// return;
// }
// tasks.clear();
// doParseBuildFile();
// parsed = true;
// }
//
// protected void addTask(ITask task) {
// tasks.put(task.getName(), task);
// }
//
// @Override
// public void dispose() {
//
// }
//
// public ITask getTask(String name) {
// return tasks.get(name);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return tasks.values();
// }
//
// @Override
// public IJSBuildFile getBuildFile() {
// return this;
// }
//
// @Override
// public boolean hasChildren() {
// // even if build file has not tasks, we consider that there are children
// // in order to load
// // the tasks when getChildNodes is called with the
// // JSBuildFileContentProvider in order to load tasks with lazy mode.
// return true;
// }
//
// protected abstract void doParseBuildFile() throws CoreException;
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
| import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import tern.ITernFile;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.grunt.internal.query.TernGruntTasksQuery;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;
import fr.opensagres.eclipse.jsbuild.core.AbstractBuildFile;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
public class GruntFile extends AbstractBuildFile implements IGruntFile {
public GruntFile(IFile file, String factoryId) {
super(file, factoryId);
}
@Override
| // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTasksQuery.java
// public class TernGruntTasksQuery extends TernQuery {
//
// public TernGruntTasksQuery() {
// super("grunt-tasks");
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/AbstractBuildFile.java
// public abstract class AbstractBuildFile extends AbstractBuildFileNode implements
// IJSBuildFile {
//
// private final IFile file;
// private final String factoryId;
// private boolean parsed;
// private final Map<String, ITask> tasks;
//
// public AbstractBuildFile(IFile file, String factoryId) {
// this.file = file;
// this.factoryId = factoryId;
// this.tasks = new HashMap<String, ITask>();
// }
//
// @Override
// public String getName() {
// return file.getName();
// }
//
// @Override
// public IFile getBuildFileResource() {
// return file;
// }
//
// @Override
// public String getBuildFileName() {
// return file.getFullPath().toOSString();
// }
//
// @Override
// public IJSBuildFileNode getParentNode() {
// return null;
// }
//
// @Override
// public String getFactoryId() {
// return factoryId;
// }
//
// @Override
// public void parseBuildFile() throws CoreException {
// parseBuildFile(false);
// }
//
// @Override
// public void parseBuildFile(boolean force) throws CoreException {
// if (parsed && !force) {
// return;
// }
// tasks.clear();
// doParseBuildFile();
// parsed = true;
// }
//
// protected void addTask(ITask task) {
// tasks.put(task.getName(), task);
// }
//
// @Override
// public void dispose() {
//
// }
//
// public ITask getTask(String name) {
// return tasks.get(name);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return tasks.values();
// }
//
// @Override
// public IJSBuildFile getBuildFile() {
// return this;
// }
//
// @Override
// public boolean hasChildren() {
// // even if build file has not tasks, we consider that there are children
// // in order to load
// // the tasks when getChildNodes is called with the
// // JSBuildFileContentProvider in order to load tasks with lazy mode.
// return true;
// }
//
// protected abstract void doParseBuildFile() throws CoreException;
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
// Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntFile.java
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import tern.ITernFile;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.grunt.internal.query.TernGruntTasksQuery;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;
import fr.opensagres.eclipse.jsbuild.core.AbstractBuildFile;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
public class GruntFile extends AbstractBuildFile implements IGruntFile {
public GruntFile(IFile file, String factoryId) {
super(file, factoryId);
}
@Override
| public ITask getDefaultTask() {
|
angelozerr/jsbuild-eclipse | grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntFile.java | // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTasksQuery.java
// public class TernGruntTasksQuery extends TernQuery {
//
// public TernGruntTasksQuery() {
// super("grunt-tasks");
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/AbstractBuildFile.java
// public abstract class AbstractBuildFile extends AbstractBuildFileNode implements
// IJSBuildFile {
//
// private final IFile file;
// private final String factoryId;
// private boolean parsed;
// private final Map<String, ITask> tasks;
//
// public AbstractBuildFile(IFile file, String factoryId) {
// this.file = file;
// this.factoryId = factoryId;
// this.tasks = new HashMap<String, ITask>();
// }
//
// @Override
// public String getName() {
// return file.getName();
// }
//
// @Override
// public IFile getBuildFileResource() {
// return file;
// }
//
// @Override
// public String getBuildFileName() {
// return file.getFullPath().toOSString();
// }
//
// @Override
// public IJSBuildFileNode getParentNode() {
// return null;
// }
//
// @Override
// public String getFactoryId() {
// return factoryId;
// }
//
// @Override
// public void parseBuildFile() throws CoreException {
// parseBuildFile(false);
// }
//
// @Override
// public void parseBuildFile(boolean force) throws CoreException {
// if (parsed && !force) {
// return;
// }
// tasks.clear();
// doParseBuildFile();
// parsed = true;
// }
//
// protected void addTask(ITask task) {
// tasks.put(task.getName(), task);
// }
//
// @Override
// public void dispose() {
//
// }
//
// public ITask getTask(String name) {
// return tasks.get(name);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return tasks.values();
// }
//
// @Override
// public IJSBuildFile getBuildFile() {
// return this;
// }
//
// @Override
// public boolean hasChildren() {
// // even if build file has not tasks, we consider that there are children
// // in order to load
// // the tasks when getChildNodes is called with the
// // JSBuildFileContentProvider in order to load tasks with lazy mode.
// return true;
// }
//
// protected abstract void doParseBuildFile() throws CoreException;
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
| import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import tern.ITernFile;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.grunt.internal.query.TernGruntTasksQuery;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;
import fr.opensagres.eclipse.jsbuild.core.AbstractBuildFile;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
public class GruntFile extends AbstractBuildFile implements IGruntFile {
public GruntFile(IFile file, String factoryId) {
super(file, factoryId);
}
@Override
public ITask getDefaultTask() {
return getTask(GruntTask.DEFAULT_NAME);
}
@Override
protected void doParseBuildFile() throws CoreException {
IFile gruntFile = getBuildFileResource();
IIDETernProject ternProject = GruntProject.getGruntProject(gruntFile
.getProject());
| // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTasksQuery.java
// public class TernGruntTasksQuery extends TernQuery {
//
// public TernGruntTasksQuery() {
// super("grunt-tasks");
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/AbstractBuildFile.java
// public abstract class AbstractBuildFile extends AbstractBuildFileNode implements
// IJSBuildFile {
//
// private final IFile file;
// private final String factoryId;
// private boolean parsed;
// private final Map<String, ITask> tasks;
//
// public AbstractBuildFile(IFile file, String factoryId) {
// this.file = file;
// this.factoryId = factoryId;
// this.tasks = new HashMap<String, ITask>();
// }
//
// @Override
// public String getName() {
// return file.getName();
// }
//
// @Override
// public IFile getBuildFileResource() {
// return file;
// }
//
// @Override
// public String getBuildFileName() {
// return file.getFullPath().toOSString();
// }
//
// @Override
// public IJSBuildFileNode getParentNode() {
// return null;
// }
//
// @Override
// public String getFactoryId() {
// return factoryId;
// }
//
// @Override
// public void parseBuildFile() throws CoreException {
// parseBuildFile(false);
// }
//
// @Override
// public void parseBuildFile(boolean force) throws CoreException {
// if (parsed && !force) {
// return;
// }
// tasks.clear();
// doParseBuildFile();
// parsed = true;
// }
//
// protected void addTask(ITask task) {
// tasks.put(task.getName(), task);
// }
//
// @Override
// public void dispose() {
//
// }
//
// public ITask getTask(String name) {
// return tasks.get(name);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return tasks.values();
// }
//
// @Override
// public IJSBuildFile getBuildFile() {
// return this;
// }
//
// @Override
// public boolean hasChildren() {
// // even if build file has not tasks, we consider that there are children
// // in order to load
// // the tasks when getChildNodes is called with the
// // JSBuildFileContentProvider in order to load tasks with lazy mode.
// return true;
// }
//
// protected abstract void doParseBuildFile() throws CoreException;
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
// Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntFile.java
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import tern.ITernFile;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.grunt.internal.query.TernGruntTasksQuery;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;
import fr.opensagres.eclipse.jsbuild.core.AbstractBuildFile;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
public class GruntFile extends AbstractBuildFile implements IGruntFile {
public GruntFile(IFile file, String factoryId) {
super(file, factoryId);
}
@Override
public ITask getDefaultTask() {
return getTask(GruntTask.DEFAULT_NAME);
}
@Override
protected void doParseBuildFile() throws CoreException {
IFile gruntFile = getBuildFileResource();
IIDETernProject ternProject = GruntProject.getGruntProject(gruntFile
.getProject());
| TernGruntTasksQuery query = new TernGruntTasksQuery();
|
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/internal/core/JSBuildFileFactoriesRegistryReader.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileFactory.java
// public interface IJSBuildFileFactory {
//
// /**
// * Returns true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// *
// * @param file
// * @return true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// */
// boolean isAdaptFor(IFile file);
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// IJSBuildFile create(IFile file, String factoryId);
//
// }
| import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileFactory;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.core;
/**
* This class reads the plugin manifests to provide factory to create instance
* of {@link IJSBuildFile}. Here a sample :
*
* <pre>
* <extension point="fr.opensagres.eclipse.jsbuild.core.jsBuildFactories">
* <jsBuildFactory
* id="fr.opensagres.eclipse.jsbuild.core.grunt"
* name="Grunt"
* class="tern.eclipse.ide.grunt.internal.GruntFileFactory" >
* </jsBuildFactory>
* </extension>
* </pre>
*/
public class JSBuildFileFactoriesRegistryReader {
protected static final String EXTENSION_POINT_ID = "jsBuildFactories"; //$NON-NLS-1$
protected static final String TAG_CONTRIBUTION = "jsBuildFactory"; //$NON-NLS-1$
private static JSBuildFileFactoriesRegistryReader INSTANCE = null;
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileFactory.java
// public interface IJSBuildFileFactory {
//
// /**
// * Returns true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// *
// * @param file
// * @return true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// */
// boolean isAdaptFor(IFile file);
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// IJSBuildFile create(IFile file, String factoryId);
//
// }
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/internal/core/JSBuildFileFactoriesRegistryReader.java
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileFactory;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.core;
/**
* This class reads the plugin manifests to provide factory to create instance
* of {@link IJSBuildFile}. Here a sample :
*
* <pre>
* <extension point="fr.opensagres.eclipse.jsbuild.core.jsBuildFactories">
* <jsBuildFactory
* id="fr.opensagres.eclipse.jsbuild.core.grunt"
* name="Grunt"
* class="tern.eclipse.ide.grunt.internal.GruntFileFactory" >
* </jsBuildFactory>
* </extension>
* </pre>
*/
public class JSBuildFileFactoriesRegistryReader {
protected static final String EXTENSION_POINT_ID = "jsBuildFactories"; //$NON-NLS-1$
protected static final String TAG_CONTRIBUTION = "jsBuildFactory"; //$NON-NLS-1$
private static JSBuildFileFactoriesRegistryReader INSTANCE = null;
| private final Map<String, IJSBuildFileFactory> factories;
|
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/internal/core/JSBuildFileFactoriesRegistryReader.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileFactory.java
// public interface IJSBuildFileFactory {
//
// /**
// * Returns true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// *
// * @param file
// * @return true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// */
// boolean isAdaptFor(IFile file);
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// IJSBuildFile create(IFile file, String factoryId);
//
// }
| import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileFactory;
| }
}
/**
* Returns the factory id for the given file and null otherwise.
*
* @param file
* (Gruntfile.js, gulpfile.js, etc)
* @return the factory id for the given file and null otherwise.
*/
public String findFactoryId(IFile file) {
Set<Entry<String, IJSBuildFileFactory>> entries = factories.entrySet();
for (Entry<String, IJSBuildFileFactory> entry : entries) {
if (entry.getValue().isAdaptFor(file)) {
return entry.getKey();
}
}
return null;
}
/**
* Create an instance of {@link IJSBuildFile} from the given file.
*
* @param file
* (Gruntfile.js, gulpfile.js).
* @param factoryId
* the factory id.
* @return an instance of {@link IJSBuildFile} from the given file.
*/
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileFactory.java
// public interface IJSBuildFileFactory {
//
// /**
// * Returns true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// *
// * @param file
// * @return true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// */
// boolean isAdaptFor(IFile file);
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// IJSBuildFile create(IFile file, String factoryId);
//
// }
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/internal/core/JSBuildFileFactoriesRegistryReader.java
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileFactory;
}
}
/**
* Returns the factory id for the given file and null otherwise.
*
* @param file
* (Gruntfile.js, gulpfile.js, etc)
* @return the factory id for the given file and null otherwise.
*/
public String findFactoryId(IFile file) {
Set<Entry<String, IJSBuildFileFactory>> entries = factories.entrySet();
for (Entry<String, IJSBuildFileFactory> entry : entries) {
if (entry.getValue().isAdaptFor(file)) {
return entry.getKey();
}
}
return null;
}
/**
* Create an instance of {@link IJSBuildFile} from the given file.
*
* @param file
* (Gruntfile.js, gulpfile.js).
* @param factoryId
* the factory id.
* @return an instance of {@link IJSBuildFile} from the given file.
*/
| public IJSBuildFile create(IFile file, String factoryId) {
|
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/launchConfigurations/TaskTableLabelProvider.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/views/JSBuildFileLabelProvider.java
// public class JSBuildFileLabelProvider extends LabelProvider implements
// IStyledLabelProvider, IColorProvider {
//
// @Override
// public StyledString getStyledText(Object element) {
// if (element instanceof IJSBuildFile) {
// IJSBuildFile node = (IJSBuildFile) element;
// StyledString buff = new StyledString(node.getLabel());
// IFile buildfile = node.getBuildFileResource();
// if (buildfile != null) {
// buff.append(" "); //$NON-NLS-1$
// buff.append('[', StyledString.DECORATIONS_STYLER);
// buff.append(buildfile.getFullPath().makeRelative().toString(),
// StyledString.DECORATIONS_STYLER);
// buff.append(']', StyledString.DECORATIONS_STYLER);
// }
// return buff;
// } else if (element instanceof ITask) {
// return new StyledString(((ITask) element).getLabel());
// }
// return null;
// }
//
// @Override
// public Color getForeground(Object node) {
// if (node instanceof ITask && ((ITask) node).isDefault()) {
// return Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
// }
// return Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
// }
//
// @Override
// public Color getBackground(Object element) {
// return Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
// }
//
// @Override
// public Image getImage(Object element) {
// if (element instanceof IJSBuildFileNode) {
// String factoryId = ((IJSBuildFileNode) element).getFactoryId();
// ILabelProvider labelProvider = LabelProviderRegistryReader
// .getInstance().getLabelProvider(factoryId);
// if (labelProvider != null) {
// // custom image.
// Image image = labelProvider.getImage(element);
// if (image != null) {
// return image;
// }
// }
// }
// return super.getImage(element);
// }
//
// }
| import fr.opensagres.eclipse.jsbuild.internal.ui.views.JSBuildFileLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.core.ITask; | /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui.launchConfigurations;
/**
* Task label provider for a table
*/
public class TaskTableLabelProvider extends JSBuildFileLabelProvider implements
ITableLabelProvider {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang
* .Object, int)
*/
@Override
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == 0) {
return getImage(element);
}
return null;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
* .Object, int)
*/
@Override
public String getColumnText(Object element, int columnIndex) {
if (columnIndex == 0) { | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/views/JSBuildFileLabelProvider.java
// public class JSBuildFileLabelProvider extends LabelProvider implements
// IStyledLabelProvider, IColorProvider {
//
// @Override
// public StyledString getStyledText(Object element) {
// if (element instanceof IJSBuildFile) {
// IJSBuildFile node = (IJSBuildFile) element;
// StyledString buff = new StyledString(node.getLabel());
// IFile buildfile = node.getBuildFileResource();
// if (buildfile != null) {
// buff.append(" "); //$NON-NLS-1$
// buff.append('[', StyledString.DECORATIONS_STYLER);
// buff.append(buildfile.getFullPath().makeRelative().toString(),
// StyledString.DECORATIONS_STYLER);
// buff.append(']', StyledString.DECORATIONS_STYLER);
// }
// return buff;
// } else if (element instanceof ITask) {
// return new StyledString(((ITask) element).getLabel());
// }
// return null;
// }
//
// @Override
// public Color getForeground(Object node) {
// if (node instanceof ITask && ((ITask) node).isDefault()) {
// return Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
// }
// return Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
// }
//
// @Override
// public Color getBackground(Object element) {
// return Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
// }
//
// @Override
// public Image getImage(Object element) {
// if (element instanceof IJSBuildFileNode) {
// String factoryId = ((IJSBuildFileNode) element).getFactoryId();
// ILabelProvider labelProvider = LabelProviderRegistryReader
// .getInstance().getLabelProvider(factoryId);
// if (labelProvider != null) {
// // custom image.
// Image image = labelProvider.getImage(element);
// if (image != null) {
// return image;
// }
// }
// }
// return super.getImage(element);
// }
//
// }
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/launchConfigurations/TaskTableLabelProvider.java
import fr.opensagres.eclipse.jsbuild.internal.ui.views.JSBuildFileLabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.core.ITask;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui.launchConfigurations;
/**
* Task label provider for a table
*/
public class TaskTableLabelProvider extends JSBuildFileLabelProvider implements
ITableLabelProvider {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang
* .Object, int)
*/
@Override
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == 0) {
return getImage(element);
}
return null;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
* .Object, int)
*/
@Override
public String getColumnText(Object element, int columnIndex) {
if (columnIndex == 0) { | ITask node = (ITask) element; |
angelozerr/jsbuild-eclipse | grunt/fr.opensagres.eclipse.jsbuild.grunt.ui/src/fr/opensagres/eclipse/jsbuild/grunt/internal/ui/GruntLabelProvider.java | // Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTask.java
// public interface IGruntTask extends ITask {
//
// }
| import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTask;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.grunt.internal.ui;
/**
* Custom label provider for Grunt file, task, targets.
*/
public class GruntLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
| // Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTask.java
// public interface IGruntTask extends ITask {
//
// }
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.ui/src/fr/opensagres/eclipse/jsbuild/grunt/internal/ui/GruntLabelProvider.java
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTask;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.grunt.internal.ui;
/**
* Custom label provider for Grunt file, task, targets.
*/
public class GruntLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
| if (element instanceof IGruntFile) {
|
angelozerr/jsbuild-eclipse | grunt/fr.opensagres.eclipse.jsbuild.grunt.ui/src/fr/opensagres/eclipse/jsbuild/grunt/internal/ui/GruntLabelProvider.java | // Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTask.java
// public interface IGruntTask extends ITask {
//
// }
| import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTask;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.grunt.internal.ui;
/**
* Custom label provider for Grunt file, task, targets.
*/
public class GruntLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
if (element instanceof IGruntFile) {
return ImageResource.getImage(ImageResource.IMG_GRUNTFILE);
| // Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTask.java
// public interface IGruntTask extends ITask {
//
// }
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.ui/src/fr/opensagres/eclipse/jsbuild/grunt/internal/ui/GruntLabelProvider.java
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTask;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.grunt.internal.ui;
/**
* Custom label provider for Grunt file, task, targets.
*/
public class GruntLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
if (element instanceof IGruntFile) {
return ImageResource.getImage(ImageResource.IMG_GRUNTFILE);
| } else if (element instanceof IGruntTask) {
|
angelozerr/jsbuild-eclipse | grunt/fr.opensagres.eclipse.jsbuild.grunt.ui/src/fr/opensagres/eclipse/jsbuild/grunt/internal/ui/GruntLabelProvider.java | // Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTask.java
// public interface IGruntTask extends ITask {
//
// }
| import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTask;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.grunt.internal.ui;
/**
* Custom label provider for Grunt file, task, targets.
*/
public class GruntLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
if (element instanceof IGruntFile) {
return ImageResource.getImage(ImageResource.IMG_GRUNTFILE);
} else if (element instanceof IGruntTask) {
if (((IGruntTask) element).isDefault()) {
return ImageResource.getImage(ImageResource.IMG_TASK_DEFAULT);
}
return ImageResource.getImage(ImageResource.IMG_TASK);
| // Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntFile.java
// public interface IGruntFile extends IJSBuildFile {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTask.java
// public interface IGruntTask extends ITask {
//
// }
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.ui/src/fr/opensagres/eclipse/jsbuild/grunt/internal/ui/GruntLabelProvider.java
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntFile;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTask;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.grunt.internal.ui;
/**
* Custom label provider for Grunt file, task, targets.
*/
public class GruntLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
if (element instanceof IGruntFile) {
return ImageResource.getImage(ImageResource.IMG_GRUNTFILE);
} else if (element instanceof IGruntTask) {
if (((IGruntTask) element).isDefault()) {
return ImageResource.getImage(ImageResource.IMG_TASK_DEFAULT);
}
return ImageResource.getImage(ImageResource.IMG_TASK);
| } else if (element instanceof IGruntTarget) {
|
angelozerr/jsbuild-eclipse | gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpFile.java | // Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/query/TernGulpTasksQuery.java
// public class TernGulpTasksQuery extends TernQuery {
//
// public TernGulpTasksQuery() {
// super("gulp-tasks");
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/AbstractBuildFile.java
// public abstract class AbstractBuildFile extends AbstractBuildFileNode implements
// IJSBuildFile {
//
// private final IFile file;
// private final String factoryId;
// private boolean parsed;
// private final Map<String, ITask> tasks;
//
// public AbstractBuildFile(IFile file, String factoryId) {
// this.file = file;
// this.factoryId = factoryId;
// this.tasks = new HashMap<String, ITask>();
// }
//
// @Override
// public String getName() {
// return file.getName();
// }
//
// @Override
// public IFile getBuildFileResource() {
// return file;
// }
//
// @Override
// public String getBuildFileName() {
// return file.getFullPath().toOSString();
// }
//
// @Override
// public IJSBuildFileNode getParentNode() {
// return null;
// }
//
// @Override
// public String getFactoryId() {
// return factoryId;
// }
//
// @Override
// public void parseBuildFile() throws CoreException {
// parseBuildFile(false);
// }
//
// @Override
// public void parseBuildFile(boolean force) throws CoreException {
// if (parsed && !force) {
// return;
// }
// tasks.clear();
// doParseBuildFile();
// parsed = true;
// }
//
// protected void addTask(ITask task) {
// tasks.put(task.getName(), task);
// }
//
// @Override
// public void dispose() {
//
// }
//
// public ITask getTask(String name) {
// return tasks.get(name);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return tasks.values();
// }
//
// @Override
// public IJSBuildFile getBuildFile() {
// return this;
// }
//
// @Override
// public boolean hasChildren() {
// // even if build file has not tasks, we consider that there are children
// // in order to load
// // the tasks when getChildNodes is called with the
// // JSBuildFileContentProvider in order to load tasks with lazy mode.
// return true;
// }
//
// protected abstract void doParseBuildFile() throws CoreException;
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpFile.java
// public interface IGulpFile extends IJSBuildFile {
//
// }
| import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import tern.ITernFile;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.gulp.internal.query.TernGulpTasksQuery;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;
import fr.opensagres.eclipse.jsbuild.core.AbstractBuildFile;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpFile;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpFile extends AbstractBuildFile implements IGulpFile {
public GulpFile(IFile file, String factoryId) {
super(file, factoryId);
}
@Override
| // Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/query/TernGulpTasksQuery.java
// public class TernGulpTasksQuery extends TernQuery {
//
// public TernGulpTasksQuery() {
// super("gulp-tasks");
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/AbstractBuildFile.java
// public abstract class AbstractBuildFile extends AbstractBuildFileNode implements
// IJSBuildFile {
//
// private final IFile file;
// private final String factoryId;
// private boolean parsed;
// private final Map<String, ITask> tasks;
//
// public AbstractBuildFile(IFile file, String factoryId) {
// this.file = file;
// this.factoryId = factoryId;
// this.tasks = new HashMap<String, ITask>();
// }
//
// @Override
// public String getName() {
// return file.getName();
// }
//
// @Override
// public IFile getBuildFileResource() {
// return file;
// }
//
// @Override
// public String getBuildFileName() {
// return file.getFullPath().toOSString();
// }
//
// @Override
// public IJSBuildFileNode getParentNode() {
// return null;
// }
//
// @Override
// public String getFactoryId() {
// return factoryId;
// }
//
// @Override
// public void parseBuildFile() throws CoreException {
// parseBuildFile(false);
// }
//
// @Override
// public void parseBuildFile(boolean force) throws CoreException {
// if (parsed && !force) {
// return;
// }
// tasks.clear();
// doParseBuildFile();
// parsed = true;
// }
//
// protected void addTask(ITask task) {
// tasks.put(task.getName(), task);
// }
//
// @Override
// public void dispose() {
//
// }
//
// public ITask getTask(String name) {
// return tasks.get(name);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return tasks.values();
// }
//
// @Override
// public IJSBuildFile getBuildFile() {
// return this;
// }
//
// @Override
// public boolean hasChildren() {
// // even if build file has not tasks, we consider that there are children
// // in order to load
// // the tasks when getChildNodes is called with the
// // JSBuildFileContentProvider in order to load tasks with lazy mode.
// return true;
// }
//
// protected abstract void doParseBuildFile() throws CoreException;
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpFile.java
// public interface IGulpFile extends IJSBuildFile {
//
// }
// Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpFile.java
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import tern.ITernFile;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.gulp.internal.query.TernGulpTasksQuery;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;
import fr.opensagres.eclipse.jsbuild.core.AbstractBuildFile;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpFile;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpFile extends AbstractBuildFile implements IGulpFile {
public GulpFile(IFile file, String factoryId) {
super(file, factoryId);
}
@Override
| public ITask getDefaultTask() {
|
angelozerr/jsbuild-eclipse | gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpFile.java | // Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/query/TernGulpTasksQuery.java
// public class TernGulpTasksQuery extends TernQuery {
//
// public TernGulpTasksQuery() {
// super("gulp-tasks");
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/AbstractBuildFile.java
// public abstract class AbstractBuildFile extends AbstractBuildFileNode implements
// IJSBuildFile {
//
// private final IFile file;
// private final String factoryId;
// private boolean parsed;
// private final Map<String, ITask> tasks;
//
// public AbstractBuildFile(IFile file, String factoryId) {
// this.file = file;
// this.factoryId = factoryId;
// this.tasks = new HashMap<String, ITask>();
// }
//
// @Override
// public String getName() {
// return file.getName();
// }
//
// @Override
// public IFile getBuildFileResource() {
// return file;
// }
//
// @Override
// public String getBuildFileName() {
// return file.getFullPath().toOSString();
// }
//
// @Override
// public IJSBuildFileNode getParentNode() {
// return null;
// }
//
// @Override
// public String getFactoryId() {
// return factoryId;
// }
//
// @Override
// public void parseBuildFile() throws CoreException {
// parseBuildFile(false);
// }
//
// @Override
// public void parseBuildFile(boolean force) throws CoreException {
// if (parsed && !force) {
// return;
// }
// tasks.clear();
// doParseBuildFile();
// parsed = true;
// }
//
// protected void addTask(ITask task) {
// tasks.put(task.getName(), task);
// }
//
// @Override
// public void dispose() {
//
// }
//
// public ITask getTask(String name) {
// return tasks.get(name);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return tasks.values();
// }
//
// @Override
// public IJSBuildFile getBuildFile() {
// return this;
// }
//
// @Override
// public boolean hasChildren() {
// // even if build file has not tasks, we consider that there are children
// // in order to load
// // the tasks when getChildNodes is called with the
// // JSBuildFileContentProvider in order to load tasks with lazy mode.
// return true;
// }
//
// protected abstract void doParseBuildFile() throws CoreException;
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpFile.java
// public interface IGulpFile extends IJSBuildFile {
//
// }
| import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import tern.ITernFile;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.gulp.internal.query.TernGulpTasksQuery;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;
import fr.opensagres.eclipse.jsbuild.core.AbstractBuildFile;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpFile;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpFile extends AbstractBuildFile implements IGulpFile {
public GulpFile(IFile file, String factoryId) {
super(file, factoryId);
}
@Override
public ITask getDefaultTask() {
return null;
}
@Override
protected void doParseBuildFile() throws CoreException {
IFile gulpFile = getBuildFileResource();
IIDETernProject ternProject = GulpProject.getGulpProject(gulpFile
.getProject());
| // Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/query/TernGulpTasksQuery.java
// public class TernGulpTasksQuery extends TernQuery {
//
// public TernGulpTasksQuery() {
// super("gulp-tasks");
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/AbstractBuildFile.java
// public abstract class AbstractBuildFile extends AbstractBuildFileNode implements
// IJSBuildFile {
//
// private final IFile file;
// private final String factoryId;
// private boolean parsed;
// private final Map<String, ITask> tasks;
//
// public AbstractBuildFile(IFile file, String factoryId) {
// this.file = file;
// this.factoryId = factoryId;
// this.tasks = new HashMap<String, ITask>();
// }
//
// @Override
// public String getName() {
// return file.getName();
// }
//
// @Override
// public IFile getBuildFileResource() {
// return file;
// }
//
// @Override
// public String getBuildFileName() {
// return file.getFullPath().toOSString();
// }
//
// @Override
// public IJSBuildFileNode getParentNode() {
// return null;
// }
//
// @Override
// public String getFactoryId() {
// return factoryId;
// }
//
// @Override
// public void parseBuildFile() throws CoreException {
// parseBuildFile(false);
// }
//
// @Override
// public void parseBuildFile(boolean force) throws CoreException {
// if (parsed && !force) {
// return;
// }
// tasks.clear();
// doParseBuildFile();
// parsed = true;
// }
//
// protected void addTask(ITask task) {
// tasks.put(task.getName(), task);
// }
//
// @Override
// public void dispose() {
//
// }
//
// public ITask getTask(String name) {
// return tasks.get(name);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return tasks.values();
// }
//
// @Override
// public IJSBuildFile getBuildFile() {
// return this;
// }
//
// @Override
// public boolean hasChildren() {
// // even if build file has not tasks, we consider that there are children
// // in order to load
// // the tasks when getChildNodes is called with the
// // JSBuildFileContentProvider in order to load tasks with lazy mode.
// return true;
// }
//
// protected abstract void doParseBuildFile() throws CoreException;
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpFile.java
// public interface IGulpFile extends IJSBuildFile {
//
// }
// Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpFile.java
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import tern.ITernFile;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.gulp.internal.query.TernGulpTasksQuery;
import tern.server.protocol.IJSONObjectHelper;
import tern.server.protocol.completions.ITernCompletionCollector;
import tern.server.protocol.completions.TernCompletionProposalRec;
import fr.opensagres.eclipse.jsbuild.core.AbstractBuildFile;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpFile;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpFile extends AbstractBuildFile implements IGulpFile {
public GulpFile(IFile file, String factoryId) {
super(file, factoryId);
}
@Override
public ITask getDefaultTask() {
return null;
}
@Override
protected void doParseBuildFile() throws CoreException {
IFile gulpFile = getBuildFileResource();
IIDETernProject ternProject = GulpProject.getGulpProject(gulpFile
.getProject());
| TernGulpTasksQuery query = new TernGulpTasksQuery();
|
angelozerr/jsbuild-eclipse | gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpFileFactory.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileFactory.java
// public interface IJSBuildFileFactory {
//
// /**
// * Returns true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// *
// * @param file
// * @return true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// */
// boolean isAdaptFor(IFile file);
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// IJSBuildFile create(IFile file, String factoryId);
//
// }
| import org.eclipse.core.resources.IFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileFactory;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpFileFactory implements IJSBuildFileFactory {
private static final String GULPFILE_JS = "gulpfile.js";
@Override
public boolean isAdaptFor(IFile file) {
return GULPFILE_JS.equals(file.getName());
}
@Override
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileFactory.java
// public interface IJSBuildFileFactory {
//
// /**
// * Returns true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// *
// * @param file
// * @return true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// */
// boolean isAdaptFor(IFile file);
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// IJSBuildFile create(IFile file, String factoryId);
//
// }
// Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpFileFactory.java
import org.eclipse.core.resources.IFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileFactory;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpFileFactory implements IJSBuildFileFactory {
private static final String GULPFILE_JS = "gulpfile.js";
@Override
public boolean isAdaptFor(IFile file) {
return GULPFILE_JS.equals(file.getName());
}
@Override
| public IJSBuildFile create(IFile file, String factoryId) {
|
angelozerr/jsbuild-eclipse | gulp/fr.opensagres.eclipse.jsbuild.gulp.ui/src/fr/opensagres/eclipse/jsbuild/gulp/internal/ui/GulpLabelProvider.java | // Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpFile.java
// public interface IGulpFile extends IJSBuildFile {
//
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpTask.java
// public interface IGulpTask extends ITask {
//
// }
| import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpTask;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpFile;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.gulp.internal.ui;
/**
* Custom label provider for Gulp file, task, targets.
*/
public class GulpLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
| // Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpFile.java
// public interface IGulpFile extends IJSBuildFile {
//
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpTask.java
// public interface IGulpTask extends ITask {
//
// }
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.ui/src/fr/opensagres/eclipse/jsbuild/gulp/internal/ui/GulpLabelProvider.java
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpTask;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpFile;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.gulp.internal.ui;
/**
* Custom label provider for Gulp file, task, targets.
*/
public class GulpLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
| if (element instanceof IGulpFile) {
|
angelozerr/jsbuild-eclipse | gulp/fr.opensagres.eclipse.jsbuild.gulp.ui/src/fr/opensagres/eclipse/jsbuild/gulp/internal/ui/GulpLabelProvider.java | // Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpFile.java
// public interface IGulpFile extends IJSBuildFile {
//
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpTask.java
// public interface IGulpTask extends ITask {
//
// }
| import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpTask;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpFile;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.gulp.internal.ui;
/**
* Custom label provider for Gulp file, task, targets.
*/
public class GulpLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
if (element instanceof IGulpFile) {
return ImageResource.getImage(ImageResource.IMG_GULPFILE);
| // Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpFile.java
// public interface IGulpFile extends IJSBuildFile {
//
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpTask.java
// public interface IGulpTask extends ITask {
//
// }
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.ui/src/fr/opensagres/eclipse/jsbuild/gulp/internal/ui/GulpLabelProvider.java
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpTask;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpFile;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.gulp.internal.ui;
/**
* Custom label provider for Gulp file, task, targets.
*/
public class GulpLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
if (element instanceof IGulpFile) {
return ImageResource.getImage(ImageResource.IMG_GULPFILE);
| } else if (element instanceof IGulpTask) {
|
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/EditorUtility.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
| import java.text.MessageFormat;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.ITextEditor;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
import fr.opensagres.eclipse.jsbuild.core.Location;
| editorPart = page.openEditor(new FileEditorInput(fileResource),
editorDescriptor.getId());
}
} catch (PartInitException e) {
Logger.logException(MessageFormat.format(
JSBuildFileUIMessages.JSBuildFileUtil_0,
new Object[] { fileResource.getLocation().toOSString() }),
e);
}
revealInEditor(editorPart, node, page);
}
public static void revealInEditor(IEditorPart editorPart,
IJSBuildFileNode element) {
revealInEditor(editorPart, element, null);
}
public static void revealInEditor(IEditorPart editorPart,
IJSBuildFileNode element, IWorkbenchPage page) {
if (element == null)
return;
ITextEditor textEditor = null;
if (editorPart instanceof ITextEditor)
textEditor = (ITextEditor) editorPart;
else if (editorPart instanceof IAdaptable)
textEditor = (ITextEditor) editorPart.getAdapter(ITextEditor.class);
if (textEditor != null) {
IDocument document = textEditor.getDocumentProvider().getDocument(
editorPart.getEditorInput());
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/EditorUtility.java
import java.text.MessageFormat;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.ITextEditor;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
import fr.opensagres.eclipse.jsbuild.core.Location;
editorPart = page.openEditor(new FileEditorInput(fileResource),
editorDescriptor.getId());
}
} catch (PartInitException e) {
Logger.logException(MessageFormat.format(
JSBuildFileUIMessages.JSBuildFileUtil_0,
new Object[] { fileResource.getLocation().toOSString() }),
e);
}
revealInEditor(editorPart, node, page);
}
public static void revealInEditor(IEditorPart editorPart,
IJSBuildFileNode element) {
revealInEditor(editorPart, element, null);
}
public static void revealInEditor(IEditorPart editorPart,
IJSBuildFileNode element, IWorkbenchPage page) {
if (element == null)
return;
ITextEditor textEditor = null;
if (editorPart instanceof ITextEditor)
textEditor = (ITextEditor) editorPart;
else if (editorPart instanceof IAdaptable)
textEditor = (ITextEditor) editorPart.getAdapter(ITextEditor.class);
if (textEditor != null) {
IDocument document = textEditor.getDocumentProvider().getDocument(
editorPart.getEditorInput());
| Location location = element.getLocation(document != null ? document
|
angelozerr/jsbuild-eclipse | grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntFileFactory.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileFactory.java
// public interface IJSBuildFileFactory {
//
// /**
// * Returns true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// *
// * @param file
// * @return true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// */
// boolean isAdaptFor(IFile file);
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// IJSBuildFile create(IFile file, String factoryId);
//
// }
| import org.eclipse.core.resources.IFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileFactory;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
public class GruntFileFactory implements IJSBuildFileFactory {
private static final String GRUNTFILE_JS = "Gruntfile.js";
@Override
public boolean isAdaptFor(IFile file) {
return GRUNTFILE_JS.equals(file.getName());
}
@Override
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileFactory.java
// public interface IJSBuildFileFactory {
//
// /**
// * Returns true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// *
// * @param file
// * @return true if the given file can use this factory to create
// * {@link IJSBuildFile} and false otherwise.
// */
// boolean isAdaptFor(IFile file);
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// IJSBuildFile create(IFile file, String factoryId);
//
// }
// Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntFileFactory.java
import org.eclipse.core.resources.IFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileFactory;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
public class GruntFileFactory implements IJSBuildFileFactory {
private static final String GRUNTFILE_JS = "Gruntfile.js";
@Override
public boolean isAdaptFor(IFile file) {
return GRUNTFILE_JS.equals(file.getName());
}
@Override
| public IJSBuildFile create(IFile file, String factoryId) {
|
angelozerr/jsbuild-eclipse | grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntTarget.java | // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTaskQuery.java
// public class TernGruntTaskQuery extends TernQuery {
//
// public TernGruntTaskQuery(String name) {
// super("grunt-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gruntFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gruntFile, taskName, text);
// }
//
// public static Location getLocation(IFile gruntFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gruntFile.getProject());
// TernGruntTaskQuery query = new TernGruntTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gruntFile,
// text) : ternProject.getFile(gruntFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
| import tern.eclipse.ide.grunt.internal.query.TernGruntTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
/**
* Grunt target implementation.
*
*/
public class GruntTarget extends SimpleTask implements IGruntTarget {
private final String targetName;
private final String targetLabel;
| // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTaskQuery.java
// public class TernGruntTaskQuery extends TernQuery {
//
// public TernGruntTaskQuery(String name) {
// super("grunt-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gruntFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gruntFile, taskName, text);
// }
//
// public static Location getLocation(IFile gruntFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gruntFile.getProject());
// TernGruntTaskQuery query = new TernGruntTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gruntFile,
// text) : ternProject.getFile(gruntFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
// Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntTarget.java
import tern.eclipse.ide.grunt.internal.query.TernGruntTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
/**
* Grunt target implementation.
*
*/
public class GruntTarget extends SimpleTask implements IGruntTarget {
private final String targetName;
private final String targetLabel;
| public GruntTarget(String name, ITask parent) {
|
angelozerr/jsbuild-eclipse | grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntTarget.java | // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTaskQuery.java
// public class TernGruntTaskQuery extends TernQuery {
//
// public TernGruntTaskQuery(String name) {
// super("grunt-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gruntFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gruntFile, taskName, text);
// }
//
// public static Location getLocation(IFile gruntFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gruntFile.getProject());
// TernGruntTaskQuery query = new TernGruntTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gruntFile,
// text) : ternProject.getFile(gruntFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
| import tern.eclipse.ide.grunt.internal.query.TernGruntTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
/**
* Grunt target implementation.
*
*/
public class GruntTarget extends SimpleTask implements IGruntTarget {
private final String targetName;
private final String targetLabel;
public GruntTarget(String name, ITask parent) {
super(name, parent);
this.targetName = new StringBuilder(parent.getName()).append(":")
.append(name).toString();
this.targetLabel = name;
}
@Override
public String getName() {
return targetName;
}
@Override
public String getLabel() {
return targetLabel;
}
@Override
| // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTaskQuery.java
// public class TernGruntTaskQuery extends TernQuery {
//
// public TernGruntTaskQuery(String name) {
// super("grunt-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gruntFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gruntFile, taskName, text);
// }
//
// public static Location getLocation(IFile gruntFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gruntFile.getProject());
// TernGruntTaskQuery query = new TernGruntTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gruntFile,
// text) : ternProject.getFile(gruntFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
// Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntTarget.java
import tern.eclipse.ide.grunt.internal.query.TernGruntTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
/**
* Grunt target implementation.
*
*/
public class GruntTarget extends SimpleTask implements IGruntTarget {
private final String targetName;
private final String targetLabel;
public GruntTarget(String name, ITask parent) {
super(name, parent);
this.targetName = new StringBuilder(parent.getName()).append(":")
.append(name).toString();
this.targetLabel = name;
}
@Override
public String getName() {
return targetName;
}
@Override
public String getLabel() {
return targetLabel;
}
@Override
| public Location getLocation(String text) {
|
angelozerr/jsbuild-eclipse | grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntTarget.java | // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTaskQuery.java
// public class TernGruntTaskQuery extends TernQuery {
//
// public TernGruntTaskQuery(String name) {
// super("grunt-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gruntFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gruntFile, taskName, text);
// }
//
// public static Location getLocation(IFile gruntFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gruntFile.getProject());
// TernGruntTaskQuery query = new TernGruntTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gruntFile,
// text) : ternProject.getFile(gruntFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
| import tern.eclipse.ide.grunt.internal.query.TernGruntTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
/**
* Grunt target implementation.
*
*/
public class GruntTarget extends SimpleTask implements IGruntTarget {
private final String targetName;
private final String targetLabel;
public GruntTarget(String name, ITask parent) {
super(name, parent);
this.targetName = new StringBuilder(parent.getName()).append(":")
.append(name).toString();
this.targetLabel = name;
}
@Override
public String getName() {
return targetName;
}
@Override
public String getLabel() {
return targetLabel;
}
@Override
public Location getLocation(String text) {
| // Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/query/TernGruntTaskQuery.java
// public class TernGruntTaskQuery extends TernQuery {
//
// public TernGruntTaskQuery(String name) {
// super("grunt-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gruntFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gruntFile, taskName, text);
// }
//
// public static Location getLocation(IFile gruntFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gruntFile.getProject());
// TernGruntTaskQuery query = new TernGruntTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gruntFile,
// text) : ternProject.getFile(gruntFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: grunt/fr.opensagres.eclipse.jsbuild.grunt.core/src/fr/opensagres/eclipse/jsbuild/grunt/core/IGruntTarget.java
// public interface IGruntTarget extends ITask {
//
// }
// Path: grunt/tern.eclipse.ide.grunt/src/tern/eclipse/ide/grunt/internal/GruntTarget.java
import tern.eclipse.ide.grunt.internal.query.TernGruntTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.grunt.core.IGruntTarget;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.grunt.internal;
/**
* Grunt target implementation.
*
*/
public class GruntTarget extends SimpleTask implements IGruntTarget {
private final String targetName;
private final String targetLabel;
public GruntTarget(String name, ITask parent) {
super(name, parent);
this.targetName = new StringBuilder(parent.getName()).append(":")
.append(name).toString();
this.targetLabel = name;
}
@Override
public String getName() {
return targetName;
}
@Override
public String getLabel() {
return targetLabel;
}
@Override
public Location getLocation(String text) {
| return TernGruntTaskQuery.getLocation(this, text);
|
angelozerr/jsbuild-eclipse | gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpTask.java | // Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/query/TernGulpTaskQuery.java
// public class TernGulpTaskQuery extends TernQuery {
//
// public TernGulpTaskQuery(String name) {
// super("gulp-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gulpFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gulpFile, taskName, text);
// }
//
// public static Location getLocation(IFile gulpFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gulpFile.getProject());
// TernGulpTaskQuery query = new TernGulpTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gulpFile, text)
// : ternProject.getFile(gulpFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpTask.java
// public interface IGulpTask extends ITask {
//
// }
| import tern.eclipse.ide.gulp.internal.query.TernGulpTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpTask;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpTask extends SimpleTask implements IGulpTask {
public GulpTask(String name, IJSBuildFile buildFile) {
super(name, buildFile);
}
@Override
| // Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/query/TernGulpTaskQuery.java
// public class TernGulpTaskQuery extends TernQuery {
//
// public TernGulpTaskQuery(String name) {
// super("gulp-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gulpFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gulpFile, taskName, text);
// }
//
// public static Location getLocation(IFile gulpFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gulpFile.getProject());
// TernGulpTaskQuery query = new TernGulpTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gulpFile, text)
// : ternProject.getFile(gulpFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpTask.java
// public interface IGulpTask extends ITask {
//
// }
// Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpTask.java
import tern.eclipse.ide.gulp.internal.query.TernGulpTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpTask;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpTask extends SimpleTask implements IGulpTask {
public GulpTask(String name, IJSBuildFile buildFile) {
super(name, buildFile);
}
@Override
| public Location getLocation(String text) {
|
angelozerr/jsbuild-eclipse | gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpTask.java | // Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/query/TernGulpTaskQuery.java
// public class TernGulpTaskQuery extends TernQuery {
//
// public TernGulpTaskQuery(String name) {
// super("gulp-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gulpFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gulpFile, taskName, text);
// }
//
// public static Location getLocation(IFile gulpFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gulpFile.getProject());
// TernGulpTaskQuery query = new TernGulpTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gulpFile, text)
// : ternProject.getFile(gulpFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpTask.java
// public interface IGulpTask extends ITask {
//
// }
| import tern.eclipse.ide.gulp.internal.query.TernGulpTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpTask;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpTask extends SimpleTask implements IGulpTask {
public GulpTask(String name, IJSBuildFile buildFile) {
super(name, buildFile);
}
@Override
public Location getLocation(String text) {
| // Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/query/TernGulpTaskQuery.java
// public class TernGulpTaskQuery extends TernQuery {
//
// public TernGulpTaskQuery(String name) {
// super("gulp-task");
// super.add("name", name);
// }
//
// public static Location getLocation(ITask task, String text) {
// IFile gulpFile = task.getBuildFile().getBuildFileResource();
// String taskName = task.getName();
// return getLocation(gulpFile, taskName, text);
// }
//
// public static Location getLocation(IFile gulpFile, String taskName,
// String text) {
// try {
// IIDETernProject ternProject = TernCorePlugin
// .getTernProject(gulpFile.getProject());
// TernGulpTaskQuery query = new TernGulpTaskQuery(taskName);
// ITernFile ternFile = text != null ? new TernTextFile(gulpFile, text)
// : ternProject.getFile(gulpFile);
// query.setFile(ternFile.getFileName());
// LocationCollector collector = new LocationCollector();
// ternProject.request(query, ternFile, collector);
// return collector.getLocation();
// } catch (Exception e) {
// Logger.logException(e);
// }
// return null;
// }
//
// private static class LocationCollector implements ITernDefinitionCollector {
//
// private Location location;
//
// @Override
// public void setDefinition(String filename, Long start, Long end) {
// if (start != null) {
// int s = start.intValue();
// int length = end != null ? end.intValue() - s : 0;
// location = new Location(s, length);
// }
// }
//
// public Location getLocation() {
// return location;
// }
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFile.java
// public interface IJSBuildFile extends IJSBuildFileNode {
//
// /**
// * Returns the default task and null otherwise.
// *
// * @return the default task and null otherwise.
// */
// ITask getDefaultTask();
//
// /**
// * Returns the resource file.
// *
// * @return the resource file.
// */
// IFile getBuildFileResource();
//
// /**
// * Returns the build file name.
// *
// * @return the build file name.
// */
// String getBuildFileName();
//
// /**
// * Parse JavaScript build file if needed to load tasks.
// *
// * @throws CoreException
// */
// void parseBuildFile() throws CoreException;
//
// /**
// * Force the parse of the JavaScript build file to load tasks.
// *
// * @param force
// * @throws CoreException
// */
// void parseBuildFile(boolean force) throws CoreException;
//
// /**
// * Dispose the build file.
// */
// void dispose();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/Location.java
// public class Location {
//
// private final int start;
// private final int length;
//
// public Location(int start, int length) {
// this.start = start;
// this.length = length;
// }
//
// public int getStart() {
// return start;
// }
//
// public int getLength() {
// return length;
// }
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/SimpleTask.java
// public class SimpleTask extends AbstractTask {
//
// public SimpleTask(String name, IJSBuildFileNode parent) {
// super(name, parent);
// }
//
// @Override
// public Collection<ITask> getChildNodes() {
// return Collections.emptyList();
// }
//
// @Override
// public boolean isDefault() {
// return false;
// }
// }
//
// Path: gulp/fr.opensagres.eclipse.jsbuild.gulp.core/src/fr/opensagres/eclipse/jsbuild/gulp/core/IGulpTask.java
// public interface IGulpTask extends ITask {
//
// }
// Path: gulp/tern.eclipse.ide.gulp/src/tern/eclipse/ide/gulp/internal/GulpTask.java
import tern.eclipse.ide.gulp.internal.query.TernGulpTaskQuery;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFile;
import fr.opensagres.eclipse.jsbuild.core.Location;
import fr.opensagres.eclipse.jsbuild.core.SimpleTask;
import fr.opensagres.eclipse.jsbuild.gulp.core.IGulpTask;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.eclipse.ide.gulp.internal;
public class GulpTask extends SimpleTask implements IGulpTask {
public GulpTask(String name, IJSBuildFile buildFile) {
super(name, buildFile);
}
@Override
public Location getLocation(String text) {
| return TernGulpTaskQuery.getLocation(this, text);
|
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/navigator/NavigatorJSBuildFileLabelProvider.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/views/JSBuildFileLabelProvider.java
// public class JSBuildFileLabelProvider extends LabelProvider implements
// IStyledLabelProvider, IColorProvider {
//
// @Override
// public StyledString getStyledText(Object element) {
// if (element instanceof IJSBuildFile) {
// IJSBuildFile node = (IJSBuildFile) element;
// StyledString buff = new StyledString(node.getLabel());
// IFile buildfile = node.getBuildFileResource();
// if (buildfile != null) {
// buff.append(" "); //$NON-NLS-1$
// buff.append('[', StyledString.DECORATIONS_STYLER);
// buff.append(buildfile.getFullPath().makeRelative().toString(),
// StyledString.DECORATIONS_STYLER);
// buff.append(']', StyledString.DECORATIONS_STYLER);
// }
// return buff;
// } else if (element instanceof ITask) {
// return new StyledString(((ITask) element).getLabel());
// }
// return null;
// }
//
// @Override
// public Color getForeground(Object node) {
// if (node instanceof ITask && ((ITask) node).isDefault()) {
// return Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
// }
// return Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
// }
//
// @Override
// public Color getBackground(Object element) {
// return Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
// }
//
// @Override
// public Image getImage(Object element) {
// if (element instanceof IJSBuildFileNode) {
// String factoryId = ((IJSBuildFileNode) element).getFactoryId();
// ILabelProvider labelProvider = LabelProviderRegistryReader
// .getInstance().getLabelProvider(factoryId);
// if (labelProvider != null) {
// // custom image.
// Image image = labelProvider.getImage(element);
// if (image != null) {
// return image;
// }
// }
// }
// return super.getImage(element);
// }
//
// }
| import org.eclipse.ui.IMemento;
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
import org.eclipse.ui.navigator.ICommonLabelProvider;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
import fr.opensagres.eclipse.jsbuild.internal.ui.views.JSBuildFileLabelProvider;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui.navigator;
/**
* * JavaScript build label provider for using it with navigator (like Project
* Explorer).
*
*/
public class NavigatorJSBuildFileLabelProvider extends JSBuildFileLabelProvider
implements ICommonLabelProvider {
@Override
public String getDescription(Object element) {
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/views/JSBuildFileLabelProvider.java
// public class JSBuildFileLabelProvider extends LabelProvider implements
// IStyledLabelProvider, IColorProvider {
//
// @Override
// public StyledString getStyledText(Object element) {
// if (element instanceof IJSBuildFile) {
// IJSBuildFile node = (IJSBuildFile) element;
// StyledString buff = new StyledString(node.getLabel());
// IFile buildfile = node.getBuildFileResource();
// if (buildfile != null) {
// buff.append(" "); //$NON-NLS-1$
// buff.append('[', StyledString.DECORATIONS_STYLER);
// buff.append(buildfile.getFullPath().makeRelative().toString(),
// StyledString.DECORATIONS_STYLER);
// buff.append(']', StyledString.DECORATIONS_STYLER);
// }
// return buff;
// } else if (element instanceof ITask) {
// return new StyledString(((ITask) element).getLabel());
// }
// return null;
// }
//
// @Override
// public Color getForeground(Object node) {
// if (node instanceof ITask && ((ITask) node).isDefault()) {
// return Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
// }
// return Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
// }
//
// @Override
// public Color getBackground(Object element) {
// return Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
// }
//
// @Override
// public Image getImage(Object element) {
// if (element instanceof IJSBuildFileNode) {
// String factoryId = ((IJSBuildFileNode) element).getFactoryId();
// ILabelProvider labelProvider = LabelProviderRegistryReader
// .getInstance().getLabelProvider(factoryId);
// if (labelProvider != null) {
// // custom image.
// Image image = labelProvider.getImage(element);
// if (image != null) {
// return image;
// }
// }
// }
// return super.getImage(element);
// }
//
// }
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/navigator/NavigatorJSBuildFileLabelProvider.java
import org.eclipse.ui.IMemento;
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
import org.eclipse.ui.navigator.ICommonLabelProvider;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
import fr.opensagres.eclipse.jsbuild.internal.ui.views.JSBuildFileLabelProvider;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui.navigator;
/**
* * JavaScript build label provider for using it with navigator (like Project
* Explorer).
*
*/
public class NavigatorJSBuildFileLabelProvider extends JSBuildFileLabelProvider
implements ICommonLabelProvider {
@Override
public String getDescription(Object element) {
| if (element instanceof IJSBuildFileNode) {
|
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/dialogs/FileSelectionDialog.java | // Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUIPlugin.java
// public class JSBuildFileUIPlugin extends AbstractUIPlugin {
//
// // The plug-in ID
// public static final String PLUGIN_ID = "fr.opensagres.eclipse.jsbuild.ui"; //$NON-NLS-1$
//
// // The shared instance
// private static JSBuildFileUIPlugin plugin;
//
// /**
// * The constructor
// */
// public JSBuildFileUIPlugin() {
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// * )
// */
// public void start(BundleContext context) throws Exception {
// super.start(context);
// plugin = this;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// * )
// */
// public void stop(BundleContext context) throws Exception {
// plugin = null;
// super.stop(context);
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static JSBuildFileUIPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns the standard display to be used. The method first checks, if the
// * thread calling this method has an associated display. If so, this display
// * is returned. Otherwise the method returns the default display.
// */
// public static Display getStandardDisplay() {
// Display display = Display.getCurrent();
// if (display == null) {
// display = Display.getDefault();
// }
// return display;
// }
//
// /**
// * Returns the {@link IDialogSettings} section with the given name. Creates
// * a new section if one does not exist.
// *
// * @param name
// * @return the {@link IDialogSettings} section with the given name
// */
// public IDialogSettings getDialogSettingsSection(String name) {
// IDialogSettings dialogSettings = getDialogSettings();
// IDialogSettings section = dialogSettings.getSection(name);
// if (section == null) {
// section = dialogSettings.addNewSection(name);
// }
// return section;
// }
//
// /**
// * Returns the active workbench window or <code>null</code> if none
// */
// public static IWorkbenchWindow getActiveWorkbenchWindow() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow();
// }
//
// public static IWorkbenchPage getActivePage() {
// return getActiveWorkbenchWindow().getActivePage();
// }
//
// }
| import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.views.navigator.ResourceComparator;
import fr.opensagres.eclipse.jsbuild.internal.ui.JSBuildFileUIPlugin; | /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui.dialogs;
public class FileSelectionDialog extends ElementTreeSelectionDialog {
private FileFilter fFilter;
private String fFilterMessage;
private boolean fShowAll = false;
private final static String DIALOG_SETTING = "AntPropertiesFileSelectionDialog.showAll"; //$NON-NLS-1$
private final static String LAST_CONTAINER = "AntPropertiesFileSelectionDialog.lastContainer"; //$NON-NLS-1$
public FileSelectionDialog(Shell parent, List<IFile> files, String title,
String message, String filterExtension, String filterMessage) {
super(parent, new WorkbenchLabelProvider(),
new WorkbenchContentProvider());
setTitle(title);
setMessage(message);
fFilter = new FileFilter(files, filterExtension);
fFilterMessage = filterMessage;
setInput(ResourcesPlugin.getWorkspace().getRoot());
setComparator(new ResourceComparator(ResourceComparator.NAME));
ISelectionStatusValidator validator = new ISelectionStatusValidator() {
@Override
public IStatus validate(Object[] selection) {
if (selection.length == 0) {
return new Status(IStatus.ERROR, | // Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUIPlugin.java
// public class JSBuildFileUIPlugin extends AbstractUIPlugin {
//
// // The plug-in ID
// public static final String PLUGIN_ID = "fr.opensagres.eclipse.jsbuild.ui"; //$NON-NLS-1$
//
// // The shared instance
// private static JSBuildFileUIPlugin plugin;
//
// /**
// * The constructor
// */
// public JSBuildFileUIPlugin() {
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// * )
// */
// public void start(BundleContext context) throws Exception {
// super.start(context);
// plugin = this;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// * )
// */
// public void stop(BundleContext context) throws Exception {
// plugin = null;
// super.stop(context);
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static JSBuildFileUIPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns the standard display to be used. The method first checks, if the
// * thread calling this method has an associated display. If so, this display
// * is returned. Otherwise the method returns the default display.
// */
// public static Display getStandardDisplay() {
// Display display = Display.getCurrent();
// if (display == null) {
// display = Display.getDefault();
// }
// return display;
// }
//
// /**
// * Returns the {@link IDialogSettings} section with the given name. Creates
// * a new section if one does not exist.
// *
// * @param name
// * @return the {@link IDialogSettings} section with the given name
// */
// public IDialogSettings getDialogSettingsSection(String name) {
// IDialogSettings dialogSettings = getDialogSettings();
// IDialogSettings section = dialogSettings.getSection(name);
// if (section == null) {
// section = dialogSettings.addNewSection(name);
// }
// return section;
// }
//
// /**
// * Returns the active workbench window or <code>null</code> if none
// */
// public static IWorkbenchWindow getActiveWorkbenchWindow() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow();
// }
//
// public static IWorkbenchPage getActivePage() {
// return getActiveWorkbenchWindow().getActivePage();
// }
//
// }
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/dialogs/FileSelectionDialog.java
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.views.navigator.ResourceComparator;
import fr.opensagres.eclipse.jsbuild.internal.ui.JSBuildFileUIPlugin;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui.dialogs;
public class FileSelectionDialog extends ElementTreeSelectionDialog {
private FileFilter fFilter;
private String fFilterMessage;
private boolean fShowAll = false;
private final static String DIALOG_SETTING = "AntPropertiesFileSelectionDialog.showAll"; //$NON-NLS-1$
private final static String LAST_CONTAINER = "AntPropertiesFileSelectionDialog.lastContainer"; //$NON-NLS-1$
public FileSelectionDialog(Shell parent, List<IFile> files, String title,
String message, String filterExtension, String filterMessage) {
super(parent, new WorkbenchLabelProvider(),
new WorkbenchContentProvider());
setTitle(title);
setMessage(message);
fFilter = new FileFilter(files, filterExtension);
fFilterMessage = filterMessage;
setInput(ResourcesPlugin.getWorkspace().getRoot());
setComparator(new ResourceComparator(ResourceComparator.NAME));
ISelectionStatusValidator validator = new ISelectionStatusValidator() {
@Override
public IStatus validate(Object[] selection) {
if (selection.length == 0) {
return new Status(IStatus.ERROR, | JSBuildFileUIPlugin.PLUGIN_ID, 0, "", null); |
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileAdapterFactory.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
| import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdapterFactory;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui;
public class JSBuildFileAdapterFactory implements IAdapterFactory {
private static Class[] PROPERTIES = new Class[] { IResource.class };
@Override
public Object getAdapter(Object element, Class key) {
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileAdapterFactory.java
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdapterFactory;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui;
public class JSBuildFileAdapterFactory implements IAdapterFactory {
private static Class[] PROPERTIES = new Class[] { IResource.class };
@Override
public Object getAdapter(Object element, Class key) {
| IJSBuildFileNode node = getJSBuildFileNode(element);
|
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileTester.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java
// public class JSBuildFileFactoryManager {
//
// /**
// * Returns the factory id for the given file and null otherwise.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js, etc)
// * @return the factory id for the given file and null otherwise.
// */
// public static String findFactoryId(IFile file) {
// return JSBuildFileFactoriesRegistryReader.getInstance().findFactoryId(
// file);
// }
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// public static IJSBuildFile create(IFile file, String factoryId) {
// return JSBuildFileFactoriesRegistryReader.getInstance().create(file,
// factoryId);
// }
//
// public static IJSBuildFileNode tryToCreate(IResource resource) {
// if (resource == null || resource.getType() != IResource.FILE) {
// return null;
// }
// IFile file = (IFile) resource;
// String factoryId = findFactoryId(file);
// if (factoryId == null) {
// return null;
// }
// return create(file, factoryId);
// }
// }
| import fr.opensagres.eclipse.jsbuild.core.JSBuildFileFactoryManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable; | /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui;
/**
* Property Tester for a IResource receiver object
*
* Property to be tested: "isJSBuildFile"
*
*/
public class JSBuildFileTester extends
org.eclipse.core.expressions.PropertyTester {
private static final String IS_JS_BUILD_FILE_PROPERTY = "isJSBuildFile";
public JSBuildFileTester() {
// Default constructor is required for property tester
}
/**
* Returns true if the receiver object is a JavaScript build file and false
* otherwise.
*
* @return true if the receiver object is a JavaScript build file and false
* otherwise.
*/
@Override
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
if (IS_JS_BUILD_FILE_PROPERTY.equals(property))
return testIsJSBuildFile(receiver,
expectedValue != null ? expectedValue.toString() : "");
return false;
}
private boolean testIsJSBuildFile(Object receiver, String expectedFactoryId) {
if (receiver instanceof IAdaptable) {
IResource resource = (IResource) ((IAdaptable) receiver)
.getAdapter(IResource.class);
if (resource != null && resource.getType() == IResource.FILE) {
IFile file = (IFile) resource; | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java
// public class JSBuildFileFactoryManager {
//
// /**
// * Returns the factory id for the given file and null otherwise.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js, etc)
// * @return the factory id for the given file and null otherwise.
// */
// public static String findFactoryId(IFile file) {
// return JSBuildFileFactoriesRegistryReader.getInstance().findFactoryId(
// file);
// }
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// public static IJSBuildFile create(IFile file, String factoryId) {
// return JSBuildFileFactoriesRegistryReader.getInstance().create(file,
// factoryId);
// }
//
// public static IJSBuildFileNode tryToCreate(IResource resource) {
// if (resource == null || resource.getType() != IResource.FILE) {
// return null;
// }
// IFile file = (IFile) resource;
// String factoryId = findFactoryId(file);
// if (factoryId == null) {
// return null;
// }
// return create(file, factoryId);
// }
// }
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileTester.java
import fr.opensagres.eclipse.jsbuild.core.JSBuildFileFactoryManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui;
/**
* Property Tester for a IResource receiver object
*
* Property to be tested: "isJSBuildFile"
*
*/
public class JSBuildFileTester extends
org.eclipse.core.expressions.PropertyTester {
private static final String IS_JS_BUILD_FILE_PROPERTY = "isJSBuildFile";
public JSBuildFileTester() {
// Default constructor is required for property tester
}
/**
* Returns true if the receiver object is a JavaScript build file and false
* otherwise.
*
* @return true if the receiver object is a JavaScript build file and false
* otherwise.
*/
@Override
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
if (IS_JS_BUILD_FILE_PROPERTY.equals(property))
return testIsJSBuildFile(receiver,
expectedValue != null ? expectedValue.toString() : "");
return false;
}
private boolean testIsJSBuildFile(Object receiver, String expectedFactoryId) {
if (receiver instanceof IAdaptable) {
IResource resource = (IResource) ((IAdaptable) receiver)
.getAdapter(IResource.class);
if (resource != null && resource.getType() == IResource.FILE) {
IFile file = (IFile) resource; | String actualFactoryId = JSBuildFileFactoryManager |
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUtil.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java
// public class JSBuildFileFactoryManager {
//
// /**
// * Returns the factory id for the given file and null otherwise.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js, etc)
// * @return the factory id for the given file and null otherwise.
// */
// public static String findFactoryId(IFile file) {
// return JSBuildFileFactoriesRegistryReader.getInstance().findFactoryId(
// file);
// }
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// public static IJSBuildFile create(IFile file, String factoryId) {
// return JSBuildFileFactoriesRegistryReader.getInstance().create(file,
// factoryId);
// }
//
// public static IJSBuildFileNode tryToCreate(IResource resource) {
// if (resource == null || resource.getType() != IResource.FILE) {
// return null;
// }
// IFile file = (IFile) resource;
// String factoryId = findFactoryId(file);
// if (factoryId == null) {
// return null;
// }
// return create(file, factoryId);
// }
// }
| import java.io.File;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.JSBuildFileFactoryManager;
| // Platform.getContentTypeManager().getContentType(AntCorePlugin.ANT_BUILDFILE_CONTENT_TYPE);
// if (antType != null) {
// return fileType.isKindOf(antType);
// }
// }
// }
// return false;
// How to check content type of Gruntfile.js, glupfile.js?
return true;
}
public static String getKnownBuildFileExtensionsAsPattern() {
return "js";
}
public static IFile getFile(String fullPath) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
return root.getFile(new Path(fullPath));
}
public static ITask[] getTargets(String path,
ILaunchConfiguration fLaunchConfiguration) throws CoreException {
File buildfile = getBuildFile(path);
if (buildfile == null) {
return null;
}
IFile file = getFileForLocation(buildfile.getAbsolutePath());
if (file == null) {
return null;
}
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java
// public class JSBuildFileFactoryManager {
//
// /**
// * Returns the factory id for the given file and null otherwise.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js, etc)
// * @return the factory id for the given file and null otherwise.
// */
// public static String findFactoryId(IFile file) {
// return JSBuildFileFactoriesRegistryReader.getInstance().findFactoryId(
// file);
// }
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// public static IJSBuildFile create(IFile file, String factoryId) {
// return JSBuildFileFactoriesRegistryReader.getInstance().create(file,
// factoryId);
// }
//
// public static IJSBuildFileNode tryToCreate(IResource resource) {
// if (resource == null || resource.getType() != IResource.FILE) {
// return null;
// }
// IFile file = (IFile) resource;
// String factoryId = findFactoryId(file);
// if (factoryId == null) {
// return null;
// }
// return create(file, factoryId);
// }
// }
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUtil.java
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.JSBuildFileFactoryManager;
// Platform.getContentTypeManager().getContentType(AntCorePlugin.ANT_BUILDFILE_CONTENT_TYPE);
// if (antType != null) {
// return fileType.isKindOf(antType);
// }
// }
// }
// return false;
// How to check content type of Gruntfile.js, glupfile.js?
return true;
}
public static String getKnownBuildFileExtensionsAsPattern() {
return "js";
}
public static IFile getFile(String fullPath) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
return root.getFile(new Path(fullPath));
}
public static ITask[] getTargets(String path,
ILaunchConfiguration fLaunchConfiguration) throws CoreException {
File buildfile = getBuildFile(path);
if (buildfile == null) {
return null;
}
IFile file = getFileForLocation(buildfile.getAbsolutePath());
if (file == null) {
return null;
}
| IJSBuildFileNode buildFileNode = JSBuildFileFactoryManager
|
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUtil.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java
// public class JSBuildFileFactoryManager {
//
// /**
// * Returns the factory id for the given file and null otherwise.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js, etc)
// * @return the factory id for the given file and null otherwise.
// */
// public static String findFactoryId(IFile file) {
// return JSBuildFileFactoriesRegistryReader.getInstance().findFactoryId(
// file);
// }
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// public static IJSBuildFile create(IFile file, String factoryId) {
// return JSBuildFileFactoriesRegistryReader.getInstance().create(file,
// factoryId);
// }
//
// public static IJSBuildFileNode tryToCreate(IResource resource) {
// if (resource == null || resource.getType() != IResource.FILE) {
// return null;
// }
// IFile file = (IFile) resource;
// String factoryId = findFactoryId(file);
// if (factoryId == null) {
// return null;
// }
// return create(file, factoryId);
// }
// }
| import java.io.File;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.JSBuildFileFactoryManager;
| // Platform.getContentTypeManager().getContentType(AntCorePlugin.ANT_BUILDFILE_CONTENT_TYPE);
// if (antType != null) {
// return fileType.isKindOf(antType);
// }
// }
// }
// return false;
// How to check content type of Gruntfile.js, glupfile.js?
return true;
}
public static String getKnownBuildFileExtensionsAsPattern() {
return "js";
}
public static IFile getFile(String fullPath) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
return root.getFile(new Path(fullPath));
}
public static ITask[] getTargets(String path,
ILaunchConfiguration fLaunchConfiguration) throws CoreException {
File buildfile = getBuildFile(path);
if (buildfile == null) {
return null;
}
IFile file = getFileForLocation(buildfile.getAbsolutePath());
if (file == null) {
return null;
}
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/IJSBuildFileNode.java
// public interface IJSBuildFileNode {
//
// /**
// * Returns the node name.
// *
// * @return the node name.
// */
// String getName();
//
// /**
// * Returns the label of the task.
// *
// * @return the label of the task.
// */
// String getLabel();
//
// /**
// * Returns true if the node have children and false otherwise.
// *
// * @return true if the node have children and false otherwise.
// */
// boolean hasChildren();
//
// /**
// * Returns the parent node.
// *
// * @return the parent node.
// */
// IJSBuildFileNode getParentNode();
//
// /**
// * Returns the tasks children.
// *
// * @return the tasks children.
// * @throws CoreException
// */
// Collection<ITask> getChildNodes();
//
// /**
// * Returns the owner build file.
// *
// * @return the owner build file.
// */
// IJSBuildFile getBuildFile();
//
// /**
// * Returns the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// *
// * @return the factory id {@link IJSBuildFileFactory} which have created
// * this instance.
// */
// String getFactoryId();
//
// /**
// * Returns the location of the node and null otherwise.
// * @param document
// *
// * @return the location of the node and null otherwise.
// */
// Location getLocation(String text);
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/ITask.java
// public interface ITask extends IJSBuildFileNode {
//
// ITask[] EMPTY_TASK = new ITask[0];
//
// /**
// * Returns true if this task is the default task and false otherwise.
// *
// * @return true if this task is the default task and false otherwise.
// */
// boolean isDefault();
//
// }
//
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java
// public class JSBuildFileFactoryManager {
//
// /**
// * Returns the factory id for the given file and null otherwise.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js, etc)
// * @return the factory id for the given file and null otherwise.
// */
// public static String findFactoryId(IFile file) {
// return JSBuildFileFactoriesRegistryReader.getInstance().findFactoryId(
// file);
// }
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// public static IJSBuildFile create(IFile file, String factoryId) {
// return JSBuildFileFactoriesRegistryReader.getInstance().create(file,
// factoryId);
// }
//
// public static IJSBuildFileNode tryToCreate(IResource resource) {
// if (resource == null || resource.getType() != IResource.FILE) {
// return null;
// }
// IFile file = (IFile) resource;
// String factoryId = findFactoryId(file);
// if (factoryId == null) {
// return null;
// }
// return create(file, factoryId);
// }
// }
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUtil.java
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import fr.opensagres.eclipse.jsbuild.core.IJSBuildFileNode;
import fr.opensagres.eclipse.jsbuild.core.ITask;
import fr.opensagres.eclipse.jsbuild.core.JSBuildFileFactoryManager;
// Platform.getContentTypeManager().getContentType(AntCorePlugin.ANT_BUILDFILE_CONTENT_TYPE);
// if (antType != null) {
// return fileType.isKindOf(antType);
// }
// }
// }
// return false;
// How to check content type of Gruntfile.js, glupfile.js?
return true;
}
public static String getKnownBuildFileExtensionsAsPattern() {
return "js";
}
public static IFile getFile(String fullPath) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
return root.getFile(new Path(fullPath));
}
public static ITask[] getTargets(String path,
ILaunchConfiguration fLaunchConfiguration) throws CoreException {
File buildfile = getBuildFile(path);
if (buildfile == null) {
return null;
}
IFile file = getFileForLocation(buildfile.getAbsolutePath());
if (file == null) {
return null;
}
| IJSBuildFileNode buildFileNode = JSBuildFileFactoryManager
|
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/dialogs/FileFilter.java | // Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUIPlugin.java
// public class JSBuildFileUIPlugin extends AbstractUIPlugin {
//
// // The plug-in ID
// public static final String PLUGIN_ID = "fr.opensagres.eclipse.jsbuild.ui"; //$NON-NLS-1$
//
// // The shared instance
// private static JSBuildFileUIPlugin plugin;
//
// /**
// * The constructor
// */
// public JSBuildFileUIPlugin() {
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// * )
// */
// public void start(BundleContext context) throws Exception {
// super.start(context);
// plugin = this;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// * )
// */
// public void stop(BundleContext context) throws Exception {
// plugin = null;
// super.stop(context);
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static JSBuildFileUIPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns the standard display to be used. The method first checks, if the
// * thread calling this method has an associated display. If so, this display
// * is returned. Otherwise the method returns the default display.
// */
// public static Display getStandardDisplay() {
// Display display = Display.getCurrent();
// if (display == null) {
// display = Display.getDefault();
// }
// return display;
// }
//
// /**
// * Returns the {@link IDialogSettings} section with the given name. Creates
// * a new section if one does not exist.
// *
// * @param name
// * @return the {@link IDialogSettings} section with the given name
// */
// public IDialogSettings getDialogSettingsSection(String name) {
// IDialogSettings dialogSettings = getDialogSettings();
// IDialogSettings section = dialogSettings.getSection(name);
// if (section == null) {
// section = dialogSettings.addNewSection(name);
// }
// return section;
// }
//
// /**
// * Returns the active workbench window or <code>null</code> if none
// */
// public static IWorkbenchWindow getActiveWorkbenchWindow() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow();
// }
//
// public static IWorkbenchPage getActivePage() {
// return getActiveWorkbenchWindow().getActivePage();
// }
//
// }
| import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.custom.BusyIndicator;
import fr.opensagres.eclipse.jsbuild.internal.ui.JSBuildFileUIPlugin; | /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui.dialogs;
public class FileFilter extends ViewerFilter {
/**
* Objects to filter
*/
private List<?> fFilter;
/**
* Collection of files and containers to display
*/
private Set<IResource> fFiles;
private String fExtension;
private Pattern fExtnPattern;
private boolean fConsiderExtension = true;
/**
* Creates a new filter that filters the given objects. Note:
* considerExtension must be called to initialize the filter
*/
public FileFilter(List<?> objects, String extension) {
fFilter = objects;
fExtension = extension;
if (extension.indexOf('|') > 0) { // Shouldn't be the first char!
// This is a pattern; compile and cache it for better performance
fExtnPattern = Pattern
.compile(fExtension, Pattern.CASE_INSENSITIVE);
} else {
fExtnPattern = null;
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers
* .Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return fFiles.contains(element) && !fFilter.contains(element);
}
/**
* Search for all the matching files in the workspace.
*/
private void init() { | // Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/JSBuildFileUIPlugin.java
// public class JSBuildFileUIPlugin extends AbstractUIPlugin {
//
// // The plug-in ID
// public static final String PLUGIN_ID = "fr.opensagres.eclipse.jsbuild.ui"; //$NON-NLS-1$
//
// // The shared instance
// private static JSBuildFileUIPlugin plugin;
//
// /**
// * The constructor
// */
// public JSBuildFileUIPlugin() {
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// * )
// */
// public void start(BundleContext context) throws Exception {
// super.start(context);
// plugin = this;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// * )
// */
// public void stop(BundleContext context) throws Exception {
// plugin = null;
// super.stop(context);
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static JSBuildFileUIPlugin getDefault() {
// return plugin;
// }
//
// /**
// * Returns the standard display to be used. The method first checks, if the
// * thread calling this method has an associated display. If so, this display
// * is returned. Otherwise the method returns the default display.
// */
// public static Display getStandardDisplay() {
// Display display = Display.getCurrent();
// if (display == null) {
// display = Display.getDefault();
// }
// return display;
// }
//
// /**
// * Returns the {@link IDialogSettings} section with the given name. Creates
// * a new section if one does not exist.
// *
// * @param name
// * @return the {@link IDialogSettings} section with the given name
// */
// public IDialogSettings getDialogSettingsSection(String name) {
// IDialogSettings dialogSettings = getDialogSettings();
// IDialogSettings section = dialogSettings.getSection(name);
// if (section == null) {
// section = dialogSettings.addNewSection(name);
// }
// return section;
// }
//
// /**
// * Returns the active workbench window or <code>null</code> if none
// */
// public static IWorkbenchWindow getActiveWorkbenchWindow() {
// return getDefault().getWorkbench().getActiveWorkbenchWindow();
// }
//
// public static IWorkbenchPage getActivePage() {
// return getActiveWorkbenchWindow().getActivePage();
// }
//
// }
// Path: core/fr.opensagres.eclipse.jsbuild.ui/src/fr/opensagres/eclipse/jsbuild/internal/ui/dialogs/FileFilter.java
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.custom.BusyIndicator;
import fr.opensagres.eclipse.jsbuild.internal.ui.JSBuildFileUIPlugin;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.internal.ui.dialogs;
public class FileFilter extends ViewerFilter {
/**
* Objects to filter
*/
private List<?> fFilter;
/**
* Collection of files and containers to display
*/
private Set<IResource> fFiles;
private String fExtension;
private Pattern fExtnPattern;
private boolean fConsiderExtension = true;
/**
* Creates a new filter that filters the given objects. Note:
* considerExtension must be called to initialize the filter
*/
public FileFilter(List<?> objects, String extension) {
fFilter = objects;
fExtension = extension;
if (extension.indexOf('|') > 0) { // Shouldn't be the first char!
// This is a pattern; compile and cache it for better performance
fExtnPattern = Pattern
.compile(fExtension, Pattern.CASE_INSENSITIVE);
} else {
fExtnPattern = null;
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers
* .Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return fFiles.contains(element) && !fFilter.contains(element);
}
/**
* Search for all the matching files in the workspace.
*/
private void init() { | BusyIndicator.showWhile(JSBuildFileUIPlugin.getStandardDisplay(), |
angelozerr/jsbuild-eclipse | core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java | // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/internal/core/JSBuildFileFactoriesRegistryReader.java
// public class JSBuildFileFactoriesRegistryReader {
//
// protected static final String EXTENSION_POINT_ID = "jsBuildFactories"; //$NON-NLS-1$
// protected static final String TAG_CONTRIBUTION = "jsBuildFactory"; //$NON-NLS-1$
//
// private static JSBuildFileFactoriesRegistryReader INSTANCE = null;
//
// private final Map<String, IJSBuildFileFactory> factories;
//
// public static JSBuildFileFactoriesRegistryReader getInstance() {
// if (INSTANCE == null) {
// INSTANCE = new JSBuildFileFactoriesRegistryReader();
// INSTANCE.readRegistry();
// }
// return INSTANCE;
// }
//
// public JSBuildFileFactoriesRegistryReader() {
// factories = new HashMap<String, IJSBuildFileFactory>();
// }
//
// /**
// * read from plugin registry and parse it.
// */
// protected void readRegistry() {
// IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry();
// IExtensionPoint point = pluginRegistry.getExtensionPoint(
// JSBuildFileCorePlugin.getDefault().getBundle()
// .getSymbolicName(), EXTENSION_POINT_ID);
// if (point != null) {
// IConfigurationElement[] elements = point.getConfigurationElements();
// for (int i = 0; i < elements.length; i++) {
// readElement(elements[i]);
// }
// }
// }
//
// protected void readElement(IConfigurationElement element) {
// if (TAG_CONTRIBUTION.equals(element.getName())) {
// String id = element.getAttribute("id");
// try {
// IJSBuildFileFactory factory = (IJSBuildFileFactory) element
// .createExecutableExtension("class");
// this.factories.put(id, factory);
// } catch (CoreException e) {
// Logger.logException(e);
// }
// }
//
// }
//
// /**
// * Returns the factory id for the given file and null otherwise.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js, etc)
// * @return the factory id for the given file and null otherwise.
// */
// public String findFactoryId(IFile file) {
// Set<Entry<String, IJSBuildFileFactory>> entries = factories.entrySet();
// for (Entry<String, IJSBuildFileFactory> entry : entries) {
// if (entry.getValue().isAdaptFor(file)) {
// return entry.getKey();
// }
// }
// return null;
// }
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// public IJSBuildFile create(IFile file, String factoryId) {
// IJSBuildFileFactory factory = factories.get(factoryId);
// if (factory == null) {
// return null;
// }
// return factory.create(file, factoryId);
// }
//
// }
| import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import fr.opensagres.eclipse.jsbuild.internal.core.JSBuildFileFactoriesRegistryReader;
| /**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.core;
/**
* JavaScript build file factory manager.
*
*/
public class JSBuildFileFactoryManager {
/**
* Returns the factory id for the given file and null otherwise.
*
* @param file
* (Gruntfile.js, gulpfile.js, etc)
* @return the factory id for the given file and null otherwise.
*/
public static String findFactoryId(IFile file) {
| // Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/internal/core/JSBuildFileFactoriesRegistryReader.java
// public class JSBuildFileFactoriesRegistryReader {
//
// protected static final String EXTENSION_POINT_ID = "jsBuildFactories"; //$NON-NLS-1$
// protected static final String TAG_CONTRIBUTION = "jsBuildFactory"; //$NON-NLS-1$
//
// private static JSBuildFileFactoriesRegistryReader INSTANCE = null;
//
// private final Map<String, IJSBuildFileFactory> factories;
//
// public static JSBuildFileFactoriesRegistryReader getInstance() {
// if (INSTANCE == null) {
// INSTANCE = new JSBuildFileFactoriesRegistryReader();
// INSTANCE.readRegistry();
// }
// return INSTANCE;
// }
//
// public JSBuildFileFactoriesRegistryReader() {
// factories = new HashMap<String, IJSBuildFileFactory>();
// }
//
// /**
// * read from plugin registry and parse it.
// */
// protected void readRegistry() {
// IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry();
// IExtensionPoint point = pluginRegistry.getExtensionPoint(
// JSBuildFileCorePlugin.getDefault().getBundle()
// .getSymbolicName(), EXTENSION_POINT_ID);
// if (point != null) {
// IConfigurationElement[] elements = point.getConfigurationElements();
// for (int i = 0; i < elements.length; i++) {
// readElement(elements[i]);
// }
// }
// }
//
// protected void readElement(IConfigurationElement element) {
// if (TAG_CONTRIBUTION.equals(element.getName())) {
// String id = element.getAttribute("id");
// try {
// IJSBuildFileFactory factory = (IJSBuildFileFactory) element
// .createExecutableExtension("class");
// this.factories.put(id, factory);
// } catch (CoreException e) {
// Logger.logException(e);
// }
// }
//
// }
//
// /**
// * Returns the factory id for the given file and null otherwise.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js, etc)
// * @return the factory id for the given file and null otherwise.
// */
// public String findFactoryId(IFile file) {
// Set<Entry<String, IJSBuildFileFactory>> entries = factories.entrySet();
// for (Entry<String, IJSBuildFileFactory> entry : entries) {
// if (entry.getValue().isAdaptFor(file)) {
// return entry.getKey();
// }
// }
// return null;
// }
//
// /**
// * Create an instance of {@link IJSBuildFile} from the given file.
// *
// * @param file
// * (Gruntfile.js, gulpfile.js).
// * @param factoryId
// * the factory id.
// * @return an instance of {@link IJSBuildFile} from the given file.
// */
// public IJSBuildFile create(IFile file, String factoryId) {
// IJSBuildFileFactory factory = factories.get(factoryId);
// if (factory == null) {
// return null;
// }
// return factory.create(file, factoryId);
// }
//
// }
// Path: core/fr.opensagres.eclipse.jsbuild.core/src/fr/opensagres/eclipse/jsbuild/core/JSBuildFileFactoryManager.java
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import fr.opensagres.eclipse.jsbuild.internal.core.JSBuildFileFactoriesRegistryReader;
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package fr.opensagres.eclipse.jsbuild.core;
/**
* JavaScript build file factory manager.
*
*/
public class JSBuildFileFactoryManager {
/**
* Returns the factory id for the given file and null otherwise.
*
* @param file
* (Gruntfile.js, gulpfile.js, etc)
* @return the factory id for the given file and null otherwise.
*/
public static String findFactoryId(IFile file) {
| return JSBuildFileFactoriesRegistryReader.getInstance().findFactoryId(
|
siqil/udaner | src/main/java/cbb/CRFBuilderByFeatureSubsetting.java | // Path: src/main/java/cc/mallet/fst/CRFTrainerByFeatureSubsetting.java
// public class CRFTrainerByFeatureSubsetting extends TransducerTrainer implements
// TransducerTrainer.ByOptimization {
//
// private static Logger logger = MalletLogger
// .getLogger(CRFTrainerByFeatureSubsetting.class.getName());
//
// private static final double DEFAULT_REG_WEIGHT = 1;
//
// private static final int DEFAULT_NUM_RESETS = 1;
//
// private int iteration;
// private double regWeight = DEFAULT_REG_WEIGHT;
// private LimitedMemoryBFGS bfgs;
//
// CRF crf;
// int iterationCount = 0;
// boolean converged;
//
// boolean usingHyperbolicPrior = false;
// boolean useSparseWeights = true;
// boolean useNoWeights = false; // TODO remove this; it is just for debugging
// private transient boolean useSomeUnsupportedTrick = true;
// // Use mcrf.trainingSet to see when we need to re-allocate crf.weights,
// // expectations & constraints because we are using a different TrainingList
// // than last time
//
// // xxx temporary hack. This is quite useful to have, though!! -cas
// public boolean printGradient = false;
//
// private int norm;
//
// public CRFTrainerByFeatureSubsetting(CRF crf) {
// this.crf = crf;
// this.iteration = 0;
// }
//
// public void setRegWeight(double regWeight) {
// this.regWeight = regWeight;
// }
//
// @Override
// public int getIteration() {
// return this.iteration;
// }
//
// @Override
// public Transducer getTransducer() {
// return this.crf;
// }
//
// @Override
// public boolean isFinishedTraining() {
// return this.converged;
// }
//
// /*
// * This is not used because we require both labeled and unlabeled data.
// */
// public boolean train(InstanceList trainingSet, int numIterations) {
// throw new RuntimeException(
// "Use train(InstanceList labeled, InstanceList unlabeled, int numIterations) instead.");
// }
//
// /**
// * Performs CRF training with label likelihood and entropy regularization.
// * The CRF is first trained with label likelihood only. This parameter
// * setting is used as a starting point for the combined optimization.
// *
// * @param labeled
// * Labeled data, only used for label likelihood term.
// * @param unlabeled
// * Unlabeled data, only used for entropy regularization term.
// * @param numIterations
// * Number of iterations.
// * @return True if training has converged.
// */
// public boolean train(InstanceList labeled, InstanceList unlabeled,
// int numIterations) {
// // if (useSparseWeights)
// // crf.setWeightsDimensionAsIn(labeled, useSomeUnsupportedTrick);//
// // else
// // crf.setWeightsDimensionDensely();
// ((CRFIm) crf).setWeightsDimensionIntersect(new InstanceList[] {
// labeled, unlabeled });
//
// CRFOptimizableByLikelihoodAndExpectationDistance regLikelihood = new CRFOptimizableByLikelihoodAndExpectationDistance(
// crf, labeled, unlabeled);
// regLikelihood.setLambda(regWeight);
// regLikelihood.setGamma(norm);
//
// this.bfgs = new LimitedMemoryBFGS(regLikelihood);
// converged = false;
// logger.info("CRF about to train with " + numIterations + " iterations");
// // sometimes resetting the optimizer helps to find
// // a better parameter setting
// for (int reset = 0; reset < DEFAULT_NUM_RESETS + 1; reset++) {
// for (int i = 0; i < numIterations; i++) {
// try {
// converged = bfgs.optimize(1);
// iteration++;
// logger.info("CRF finished one iteration of maximizer, i="
// + i);
// runEvaluators();
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
// logger.info("Catching exception; saying converged.");
// converged = true;
// } catch (Exception e) {
// e.printStackTrace();
// logger.info("Catching exception; saying converged.");
// converged = true;
// }
// if (converged) {
// logger.info("CRF training has converged, i=" + i);
// break;
// }
// }
// this.bfgs.reset();
// }
// return converged;
// }
//
// public Optimizer getOptimizer() {
// return bfgs;
// }
//
// public int getNorm() {
// return norm;
// }
//
// public void setNorm(int norm) {
// this.norm = norm;
// }
//
// }
| import cc.mallet.fst.CRFTrainerByFeatureSubsetting;
import cc.mallet.fst.TransducerTrainer;
import cc.mallet.pipe.Pipe;
import cc.mallet.types.InstanceList; | package cbb;
public class CRFBuilderByFeatureSubsetting extends CRFBuilder {
private int gamma;
private double lambda;
public CRFBuilderByFeatureSubsetting(Pipe pipe) {
super(pipe);
}
@Override
protected TransducerTrainer train(InstanceList source, InstanceList target) { | // Path: src/main/java/cc/mallet/fst/CRFTrainerByFeatureSubsetting.java
// public class CRFTrainerByFeatureSubsetting extends TransducerTrainer implements
// TransducerTrainer.ByOptimization {
//
// private static Logger logger = MalletLogger
// .getLogger(CRFTrainerByFeatureSubsetting.class.getName());
//
// private static final double DEFAULT_REG_WEIGHT = 1;
//
// private static final int DEFAULT_NUM_RESETS = 1;
//
// private int iteration;
// private double regWeight = DEFAULT_REG_WEIGHT;
// private LimitedMemoryBFGS bfgs;
//
// CRF crf;
// int iterationCount = 0;
// boolean converged;
//
// boolean usingHyperbolicPrior = false;
// boolean useSparseWeights = true;
// boolean useNoWeights = false; // TODO remove this; it is just for debugging
// private transient boolean useSomeUnsupportedTrick = true;
// // Use mcrf.trainingSet to see when we need to re-allocate crf.weights,
// // expectations & constraints because we are using a different TrainingList
// // than last time
//
// // xxx temporary hack. This is quite useful to have, though!! -cas
// public boolean printGradient = false;
//
// private int norm;
//
// public CRFTrainerByFeatureSubsetting(CRF crf) {
// this.crf = crf;
// this.iteration = 0;
// }
//
// public void setRegWeight(double regWeight) {
// this.regWeight = regWeight;
// }
//
// @Override
// public int getIteration() {
// return this.iteration;
// }
//
// @Override
// public Transducer getTransducer() {
// return this.crf;
// }
//
// @Override
// public boolean isFinishedTraining() {
// return this.converged;
// }
//
// /*
// * This is not used because we require both labeled and unlabeled data.
// */
// public boolean train(InstanceList trainingSet, int numIterations) {
// throw new RuntimeException(
// "Use train(InstanceList labeled, InstanceList unlabeled, int numIterations) instead.");
// }
//
// /**
// * Performs CRF training with label likelihood and entropy regularization.
// * The CRF is first trained with label likelihood only. This parameter
// * setting is used as a starting point for the combined optimization.
// *
// * @param labeled
// * Labeled data, only used for label likelihood term.
// * @param unlabeled
// * Unlabeled data, only used for entropy regularization term.
// * @param numIterations
// * Number of iterations.
// * @return True if training has converged.
// */
// public boolean train(InstanceList labeled, InstanceList unlabeled,
// int numIterations) {
// // if (useSparseWeights)
// // crf.setWeightsDimensionAsIn(labeled, useSomeUnsupportedTrick);//
// // else
// // crf.setWeightsDimensionDensely();
// ((CRFIm) crf).setWeightsDimensionIntersect(new InstanceList[] {
// labeled, unlabeled });
//
// CRFOptimizableByLikelihoodAndExpectationDistance regLikelihood = new CRFOptimizableByLikelihoodAndExpectationDistance(
// crf, labeled, unlabeled);
// regLikelihood.setLambda(regWeight);
// regLikelihood.setGamma(norm);
//
// this.bfgs = new LimitedMemoryBFGS(regLikelihood);
// converged = false;
// logger.info("CRF about to train with " + numIterations + " iterations");
// // sometimes resetting the optimizer helps to find
// // a better parameter setting
// for (int reset = 0; reset < DEFAULT_NUM_RESETS + 1; reset++) {
// for (int i = 0; i < numIterations; i++) {
// try {
// converged = bfgs.optimize(1);
// iteration++;
// logger.info("CRF finished one iteration of maximizer, i="
// + i);
// runEvaluators();
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
// logger.info("Catching exception; saying converged.");
// converged = true;
// } catch (Exception e) {
// e.printStackTrace();
// logger.info("Catching exception; saying converged.");
// converged = true;
// }
// if (converged) {
// logger.info("CRF training has converged, i=" + i);
// break;
// }
// }
// this.bfgs.reset();
// }
// return converged;
// }
//
// public Optimizer getOptimizer() {
// return bfgs;
// }
//
// public int getNorm() {
// return norm;
// }
//
// public void setNorm(int norm) {
// this.norm = norm;
// }
//
// }
// Path: src/main/java/cbb/CRFBuilderByFeatureSubsetting.java
import cc.mallet.fst.CRFTrainerByFeatureSubsetting;
import cc.mallet.fst.TransducerTrainer;
import cc.mallet.pipe.Pipe;
import cc.mallet.types.InstanceList;
package cbb;
public class CRFBuilderByFeatureSubsetting extends CRFBuilder {
private int gamma;
private double lambda;
public CRFBuilderByFeatureSubsetting(Pipe pipe) {
super(pipe);
}
@Override
protected TransducerTrainer train(InstanceList source, InstanceList target) { | CRFTrainerByFeatureSubsetting trainer = new CRFTrainerByFeatureSubsetting( |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
| import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex; | package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() { | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex;
package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() { | complex(getEndPoint("login")) |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
| import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex; | package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() {
complex(getEndPoint("login"))
.get(
(req, res) -> {
Map<String, Object> scopes = new HashMap<>();
scopes.put("title", "IotLabs");
scopes.put("admin_mail", "[email protected]");
return new ModelAndView(scopes,"login.html");
}, new MustacheTemplateEngine(getTemplatePath())
)
.post((req, res) -> {
String username = req.queryParams("username");
String passwd = StringUtils.sha256(req.queryParams("password")); | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex;
package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() {
complex(getEndPoint("login"))
.get(
(req, res) -> {
Map<String, Object> scopes = new HashMap<>();
scopes.put("title", "IotLabs");
scopes.put("admin_mail", "[email protected]");
return new ModelAndView(scopes,"login.html");
}, new MustacheTemplateEngine(getTemplatePath())
)
.post((req, res) -> {
String username = req.queryParams("username");
String passwd = StringUtils.sha256(req.queryParams("password")); | User user = Checker.authenticate(username, passwd); |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
| import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex; | package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() {
complex(getEndPoint("login"))
.get(
(req, res) -> {
Map<String, Object> scopes = new HashMap<>();
scopes.put("title", "IotLabs");
scopes.put("admin_mail", "[email protected]");
return new ModelAndView(scopes,"login.html");
}, new MustacheTemplateEngine(getTemplatePath())
)
.post((req, res) -> {
String username = req.queryParams("username");
String passwd = StringUtils.sha256(req.queryParams("password"));
User user = Checker.authenticate(username, passwd);
if (user == null) {
req.session().removeAttribute("auth"); | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex;
package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() {
complex(getEndPoint("login"))
.get(
(req, res) -> {
Map<String, Object> scopes = new HashMap<>();
scopes.put("title", "IotLabs");
scopes.put("admin_mail", "[email protected]");
return new ModelAndView(scopes,"login.html");
}, new MustacheTemplateEngine(getTemplatePath())
)
.post((req, res) -> {
String username = req.queryParams("username");
String passwd = StringUtils.sha256(req.queryParams("password"));
User user = Checker.authenticate(username, passwd);
if (user == null) {
req.session().removeAttribute("auth"); | ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized")); |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
| import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex; | package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() {
complex(getEndPoint("login"))
.get(
(req, res) -> {
Map<String, Object> scopes = new HashMap<>();
scopes.put("title", "IotLabs");
scopes.put("admin_mail", "[email protected]");
return new ModelAndView(scopes,"login.html");
}, new MustacheTemplateEngine(getTemplatePath())
)
.post((req, res) -> {
String username = req.queryParams("username");
String passwd = StringUtils.sha256(req.queryParams("password"));
User user = Checker.authenticate(username, passwd);
if (user == null) {
req.session().removeAttribute("auth"); | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex;
package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() {
complex(getEndPoint("login"))
.get(
(req, res) -> {
Map<String, Object> scopes = new HashMap<>();
scopes.put("title", "IotLabs");
scopes.put("admin_mail", "[email protected]");
return new ModelAndView(scopes,"login.html");
}, new MustacheTemplateEngine(getTemplatePath())
)
.post((req, res) -> {
String username = req.queryParams("username");
String passwd = StringUtils.sha256(req.queryParams("password"));
User user = Checker.authenticate(username, passwd);
if (user == null) {
req.session().removeAttribute("auth"); | ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized")); |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
| import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex; | package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() {
complex(getEndPoint("login"))
.get(
(req, res) -> {
Map<String, Object> scopes = new HashMap<>();
scopes.put("title", "IotLabs");
scopes.put("admin_mail", "[email protected]");
return new ModelAndView(scopes,"login.html");
}, new MustacheTemplateEngine(getTemplatePath())
)
.post((req, res) -> {
String username = req.queryParams("username");
String passwd = StringUtils.sha256(req.queryParams("password"));
User user = Checker.authenticate(username, passwd);
if (user == null) {
req.session().removeAttribute("auth");
ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized"));
return res.body();
} else {
if (Checker.isRequestingHtml(req)) {
res.redirect("/");
}
req.session().attribute("auth", true); | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/Http4xx.java
// public class Http4xx extends BaseHttpException {
//
// public Http4xx(int code, String body) {
// super(code, body);
// }
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
// public class Checker {
//
// public static boolean isRequestingHtml(Request request) {
// String accept = request.headers(Header.ACCEPT);
// return accept != null
// && accept.contains(ContentType.HTML);
// }
//
// public static User authenticate(String username, String passwd) {
// User user = Dummy.userMap.getOrDefault(username, null);
// if (user == null) {
// return null;
// }
// if (user.getPasswd().equals(passwd)) {
// return user;
// }
// return null;
// }
//
//
//
//
// }
//
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
// public class ResponseSetter {
// public static void setErrorResponse(Response errorResponse, BaseHttpException e) {
// errorResponse.type(ContentType.HTML);
// errorResponse.status(e.getCode());
// errorResponse.body(e.getBody());
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/Complex.java
// public static Complex complex(String endpoint) {
// return new Complex(endpoint);
// }
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
import org.iotlabs.storage.models.general.User;
import org.iotlabs.storage.util.StringUtils;
import org.iotlabs.dashboard.httpexceptions.Http4xx;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.utils.Checker;
import org.iotlabs.dashboard.utils.ResponseSetter;
import spark.ModelAndView;
import spark.template.mustache.MustacheTemplateEngine;
import java.util.HashMap;
import java.util.Map;
import static org.iotlabs.dashboard.blueprints.Complex.complex;
package org.iotlabs.dashboard.blueprints;
public class AuthBluePrint extends AbstractBluePrint {
public AuthBluePrint() {
super("auth");
}
@Override
public void register() {
complex(getEndPoint("login"))
.get(
(req, res) -> {
Map<String, Object> scopes = new HashMap<>();
scopes.put("title", "IotLabs");
scopes.put("admin_mail", "[email protected]");
return new ModelAndView(scopes,"login.html");
}, new MustacheTemplateEngine(getTemplatePath())
)
.post((req, res) -> {
String username = req.queryParams("username");
String passwd = StringUtils.sha256(req.queryParams("password"));
User user = Checker.authenticate(username, passwd);
if (user == null) {
req.session().removeAttribute("auth");
ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized"));
return res.body();
} else {
if (Checker.isRequestingHtml(req)) {
res.redirect("/");
}
req.session().attribute("auth", true); | res.type(ContentType.JSON); |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/SparkProxy.java | // Path: src/main/java/org/iotlabs/dashboard/blueprints/AbstractBluePrint.java
// public abstract class AbstractBluePrint {
//
// /**
// * blueprint name prefix
// */
// private String blueprintPrefix;
// private String blueprintPrefixFormatter;
// private String blueprintResourcePath;
//
// /**
// * create blueprint object
// * @param blueprintPrefix blueprint name prefix to set
// */
// public AbstractBluePrint(String blueprintPrefix) {
// if (!blueprintPrefix.startsWith("/")) {
// blueprintPrefix = "/" + blueprintPrefix;
// }
// if (blueprintPrefix.endsWith("/")) {
// blueprintPrefix = blueprintPrefix.substring(0, blueprintPrefix.length() - 1);
// }
// this.blueprintPrefix = blueprintPrefix;
// this.blueprintPrefixFormatter = blueprintPrefix + "/%s";
// this.blueprintResourcePath = "web/html/" + blueprintPrefix;
// }
//
// /**
// * Get endpoint with blueprint prefix
// * @param endPoint endpoint
// * @return {blueprint_prefix}/endPoint
// */
// public String getEndPoint(String endPoint) {
//
// if (StringUtils.isEmpty(endPoint)) {
// return blueprintPrefix;
// }
//
// if (endPoint.startsWith("/")) {
// endPoint = endPoint.substring(1, endPoint.length());
// }
// return String.format(blueprintPrefixFormatter, endPoint);
// }
//
// /**
// * Get template resource path for Mustache engine.
// * @return "web/html/{blue_print}"
// */
// public String getTemplatePath() {
// return blueprintResourcePath;
// }
//
// public abstract void register();
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
// public class AuthBluePrint extends AbstractBluePrint {
//
//
// public AuthBluePrint() {
// super("auth");
// }
//
// @Override
// public void register() {
// complex(getEndPoint("login"))
// .get(
// (req, res) -> {
// Map<String, Object> scopes = new HashMap<>();
// scopes.put("title", "IotLabs");
// scopes.put("admin_mail", "[email protected]");
// return new ModelAndView(scopes,"login.html");
// }, new MustacheTemplateEngine(getTemplatePath())
// )
// .post((req, res) -> {
// String username = req.queryParams("username");
// String passwd = StringUtils.sha256(req.queryParams("password"));
// User user = Checker.authenticate(username, passwd);
// if (user == null) {
// req.session().removeAttribute("auth");
// ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized"));
// return res.body();
// } else {
// if (Checker.isRequestingHtml(req)) {
// res.redirect("/");
// }
// req.session().attribute("auth", true);
// res.type(ContentType.JSON);
// res.body(user.toJsonString());
// res.status(200);
// return res.body();
// }
// });
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/RootBluePrint.java
// public class RootBluePrint extends AbstractBluePrint {
//
// public RootBluePrint() {
// super("");
// }
//
// @Override
// public void register() {
// get("/", (req, res) -> "Welcome :)");
// }
// }
| import org.iotlabs.dashboard.blueprints.AbstractBluePrint;
import org.iotlabs.dashboard.blueprints.AuthBluePrint;
import org.iotlabs.dashboard.blueprints.RootBluePrint; | package org.iotlabs.dashboard;
public class SparkProxy {
private static class Holder {
private static final SparkProxy SPARK_PROXY = new SparkProxy();
}
public static SparkProxy getInstance() {
return Holder.SPARK_PROXY;
}
private SparkProxy() {
new SparkInit();
}
public void run() {
registerRouters();
}
/**
* register default setted routers.
*/
private void registerRouters() { | // Path: src/main/java/org/iotlabs/dashboard/blueprints/AbstractBluePrint.java
// public abstract class AbstractBluePrint {
//
// /**
// * blueprint name prefix
// */
// private String blueprintPrefix;
// private String blueprintPrefixFormatter;
// private String blueprintResourcePath;
//
// /**
// * create blueprint object
// * @param blueprintPrefix blueprint name prefix to set
// */
// public AbstractBluePrint(String blueprintPrefix) {
// if (!blueprintPrefix.startsWith("/")) {
// blueprintPrefix = "/" + blueprintPrefix;
// }
// if (blueprintPrefix.endsWith("/")) {
// blueprintPrefix = blueprintPrefix.substring(0, blueprintPrefix.length() - 1);
// }
// this.blueprintPrefix = blueprintPrefix;
// this.blueprintPrefixFormatter = blueprintPrefix + "/%s";
// this.blueprintResourcePath = "web/html/" + blueprintPrefix;
// }
//
// /**
// * Get endpoint with blueprint prefix
// * @param endPoint endpoint
// * @return {blueprint_prefix}/endPoint
// */
// public String getEndPoint(String endPoint) {
//
// if (StringUtils.isEmpty(endPoint)) {
// return blueprintPrefix;
// }
//
// if (endPoint.startsWith("/")) {
// endPoint = endPoint.substring(1, endPoint.length());
// }
// return String.format(blueprintPrefixFormatter, endPoint);
// }
//
// /**
// * Get template resource path for Mustache engine.
// * @return "web/html/{blue_print}"
// */
// public String getTemplatePath() {
// return blueprintResourcePath;
// }
//
// public abstract void register();
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
// public class AuthBluePrint extends AbstractBluePrint {
//
//
// public AuthBluePrint() {
// super("auth");
// }
//
// @Override
// public void register() {
// complex(getEndPoint("login"))
// .get(
// (req, res) -> {
// Map<String, Object> scopes = new HashMap<>();
// scopes.put("title", "IotLabs");
// scopes.put("admin_mail", "[email protected]");
// return new ModelAndView(scopes,"login.html");
// }, new MustacheTemplateEngine(getTemplatePath())
// )
// .post((req, res) -> {
// String username = req.queryParams("username");
// String passwd = StringUtils.sha256(req.queryParams("password"));
// User user = Checker.authenticate(username, passwd);
// if (user == null) {
// req.session().removeAttribute("auth");
// ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized"));
// return res.body();
// } else {
// if (Checker.isRequestingHtml(req)) {
// res.redirect("/");
// }
// req.session().attribute("auth", true);
// res.type(ContentType.JSON);
// res.body(user.toJsonString());
// res.status(200);
// return res.body();
// }
// });
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/RootBluePrint.java
// public class RootBluePrint extends AbstractBluePrint {
//
// public RootBluePrint() {
// super("");
// }
//
// @Override
// public void register() {
// get("/", (req, res) -> "Welcome :)");
// }
// }
// Path: src/main/java/org/iotlabs/dashboard/SparkProxy.java
import org.iotlabs.dashboard.blueprints.AbstractBluePrint;
import org.iotlabs.dashboard.blueprints.AuthBluePrint;
import org.iotlabs.dashboard.blueprints.RootBluePrint;
package org.iotlabs.dashboard;
public class SparkProxy {
private static class Holder {
private static final SparkProxy SPARK_PROXY = new SparkProxy();
}
public static SparkProxy getInstance() {
return Holder.SPARK_PROXY;
}
private SparkProxy() {
new SparkInit();
}
public void run() {
registerRouters();
}
/**
* register default setted routers.
*/
private void registerRouters() { | new AuthBluePrint().register(); |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/SparkProxy.java | // Path: src/main/java/org/iotlabs/dashboard/blueprints/AbstractBluePrint.java
// public abstract class AbstractBluePrint {
//
// /**
// * blueprint name prefix
// */
// private String blueprintPrefix;
// private String blueprintPrefixFormatter;
// private String blueprintResourcePath;
//
// /**
// * create blueprint object
// * @param blueprintPrefix blueprint name prefix to set
// */
// public AbstractBluePrint(String blueprintPrefix) {
// if (!blueprintPrefix.startsWith("/")) {
// blueprintPrefix = "/" + blueprintPrefix;
// }
// if (blueprintPrefix.endsWith("/")) {
// blueprintPrefix = blueprintPrefix.substring(0, blueprintPrefix.length() - 1);
// }
// this.blueprintPrefix = blueprintPrefix;
// this.blueprintPrefixFormatter = blueprintPrefix + "/%s";
// this.blueprintResourcePath = "web/html/" + blueprintPrefix;
// }
//
// /**
// * Get endpoint with blueprint prefix
// * @param endPoint endpoint
// * @return {blueprint_prefix}/endPoint
// */
// public String getEndPoint(String endPoint) {
//
// if (StringUtils.isEmpty(endPoint)) {
// return blueprintPrefix;
// }
//
// if (endPoint.startsWith("/")) {
// endPoint = endPoint.substring(1, endPoint.length());
// }
// return String.format(blueprintPrefixFormatter, endPoint);
// }
//
// /**
// * Get template resource path for Mustache engine.
// * @return "web/html/{blue_print}"
// */
// public String getTemplatePath() {
// return blueprintResourcePath;
// }
//
// public abstract void register();
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
// public class AuthBluePrint extends AbstractBluePrint {
//
//
// public AuthBluePrint() {
// super("auth");
// }
//
// @Override
// public void register() {
// complex(getEndPoint("login"))
// .get(
// (req, res) -> {
// Map<String, Object> scopes = new HashMap<>();
// scopes.put("title", "IotLabs");
// scopes.put("admin_mail", "[email protected]");
// return new ModelAndView(scopes,"login.html");
// }, new MustacheTemplateEngine(getTemplatePath())
// )
// .post((req, res) -> {
// String username = req.queryParams("username");
// String passwd = StringUtils.sha256(req.queryParams("password"));
// User user = Checker.authenticate(username, passwd);
// if (user == null) {
// req.session().removeAttribute("auth");
// ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized"));
// return res.body();
// } else {
// if (Checker.isRequestingHtml(req)) {
// res.redirect("/");
// }
// req.session().attribute("auth", true);
// res.type(ContentType.JSON);
// res.body(user.toJsonString());
// res.status(200);
// return res.body();
// }
// });
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/RootBluePrint.java
// public class RootBluePrint extends AbstractBluePrint {
//
// public RootBluePrint() {
// super("");
// }
//
// @Override
// public void register() {
// get("/", (req, res) -> "Welcome :)");
// }
// }
| import org.iotlabs.dashboard.blueprints.AbstractBluePrint;
import org.iotlabs.dashboard.blueprints.AuthBluePrint;
import org.iotlabs.dashboard.blueprints.RootBluePrint; | package org.iotlabs.dashboard;
public class SparkProxy {
private static class Holder {
private static final SparkProxy SPARK_PROXY = new SparkProxy();
}
public static SparkProxy getInstance() {
return Holder.SPARK_PROXY;
}
private SparkProxy() {
new SparkInit();
}
public void run() {
registerRouters();
}
/**
* register default setted routers.
*/
private void registerRouters() {
new AuthBluePrint().register(); | // Path: src/main/java/org/iotlabs/dashboard/blueprints/AbstractBluePrint.java
// public abstract class AbstractBluePrint {
//
// /**
// * blueprint name prefix
// */
// private String blueprintPrefix;
// private String blueprintPrefixFormatter;
// private String blueprintResourcePath;
//
// /**
// * create blueprint object
// * @param blueprintPrefix blueprint name prefix to set
// */
// public AbstractBluePrint(String blueprintPrefix) {
// if (!blueprintPrefix.startsWith("/")) {
// blueprintPrefix = "/" + blueprintPrefix;
// }
// if (blueprintPrefix.endsWith("/")) {
// blueprintPrefix = blueprintPrefix.substring(0, blueprintPrefix.length() - 1);
// }
// this.blueprintPrefix = blueprintPrefix;
// this.blueprintPrefixFormatter = blueprintPrefix + "/%s";
// this.blueprintResourcePath = "web/html/" + blueprintPrefix;
// }
//
// /**
// * Get endpoint with blueprint prefix
// * @param endPoint endpoint
// * @return {blueprint_prefix}/endPoint
// */
// public String getEndPoint(String endPoint) {
//
// if (StringUtils.isEmpty(endPoint)) {
// return blueprintPrefix;
// }
//
// if (endPoint.startsWith("/")) {
// endPoint = endPoint.substring(1, endPoint.length());
// }
// return String.format(blueprintPrefixFormatter, endPoint);
// }
//
// /**
// * Get template resource path for Mustache engine.
// * @return "web/html/{blue_print}"
// */
// public String getTemplatePath() {
// return blueprintResourcePath;
// }
//
// public abstract void register();
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
// public class AuthBluePrint extends AbstractBluePrint {
//
//
// public AuthBluePrint() {
// super("auth");
// }
//
// @Override
// public void register() {
// complex(getEndPoint("login"))
// .get(
// (req, res) -> {
// Map<String, Object> scopes = new HashMap<>();
// scopes.put("title", "IotLabs");
// scopes.put("admin_mail", "[email protected]");
// return new ModelAndView(scopes,"login.html");
// }, new MustacheTemplateEngine(getTemplatePath())
// )
// .post((req, res) -> {
// String username = req.queryParams("username");
// String passwd = StringUtils.sha256(req.queryParams("password"));
// User user = Checker.authenticate(username, passwd);
// if (user == null) {
// req.session().removeAttribute("auth");
// ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized"));
// return res.body();
// } else {
// if (Checker.isRequestingHtml(req)) {
// res.redirect("/");
// }
// req.session().attribute("auth", true);
// res.type(ContentType.JSON);
// res.body(user.toJsonString());
// res.status(200);
// return res.body();
// }
// });
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/RootBluePrint.java
// public class RootBluePrint extends AbstractBluePrint {
//
// public RootBluePrint() {
// super("");
// }
//
// @Override
// public void register() {
// get("/", (req, res) -> "Welcome :)");
// }
// }
// Path: src/main/java/org/iotlabs/dashboard/SparkProxy.java
import org.iotlabs.dashboard.blueprints.AbstractBluePrint;
import org.iotlabs.dashboard.blueprints.AuthBluePrint;
import org.iotlabs.dashboard.blueprints.RootBluePrint;
package org.iotlabs.dashboard;
public class SparkProxy {
private static class Holder {
private static final SparkProxy SPARK_PROXY = new SparkProxy();
}
public static SparkProxy getInstance() {
return Holder.SPARK_PROXY;
}
private SparkProxy() {
new SparkInit();
}
public void run() {
registerRouters();
}
/**
* register default setted routers.
*/
private void registerRouters() {
new AuthBluePrint().register(); | new RootBluePrint().register(); |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/SparkProxy.java | // Path: src/main/java/org/iotlabs/dashboard/blueprints/AbstractBluePrint.java
// public abstract class AbstractBluePrint {
//
// /**
// * blueprint name prefix
// */
// private String blueprintPrefix;
// private String blueprintPrefixFormatter;
// private String blueprintResourcePath;
//
// /**
// * create blueprint object
// * @param blueprintPrefix blueprint name prefix to set
// */
// public AbstractBluePrint(String blueprintPrefix) {
// if (!blueprintPrefix.startsWith("/")) {
// blueprintPrefix = "/" + blueprintPrefix;
// }
// if (blueprintPrefix.endsWith("/")) {
// blueprintPrefix = blueprintPrefix.substring(0, blueprintPrefix.length() - 1);
// }
// this.blueprintPrefix = blueprintPrefix;
// this.blueprintPrefixFormatter = blueprintPrefix + "/%s";
// this.blueprintResourcePath = "web/html/" + blueprintPrefix;
// }
//
// /**
// * Get endpoint with blueprint prefix
// * @param endPoint endpoint
// * @return {blueprint_prefix}/endPoint
// */
// public String getEndPoint(String endPoint) {
//
// if (StringUtils.isEmpty(endPoint)) {
// return blueprintPrefix;
// }
//
// if (endPoint.startsWith("/")) {
// endPoint = endPoint.substring(1, endPoint.length());
// }
// return String.format(blueprintPrefixFormatter, endPoint);
// }
//
// /**
// * Get template resource path for Mustache engine.
// * @return "web/html/{blue_print}"
// */
// public String getTemplatePath() {
// return blueprintResourcePath;
// }
//
// public abstract void register();
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
// public class AuthBluePrint extends AbstractBluePrint {
//
//
// public AuthBluePrint() {
// super("auth");
// }
//
// @Override
// public void register() {
// complex(getEndPoint("login"))
// .get(
// (req, res) -> {
// Map<String, Object> scopes = new HashMap<>();
// scopes.put("title", "IotLabs");
// scopes.put("admin_mail", "[email protected]");
// return new ModelAndView(scopes,"login.html");
// }, new MustacheTemplateEngine(getTemplatePath())
// )
// .post((req, res) -> {
// String username = req.queryParams("username");
// String passwd = StringUtils.sha256(req.queryParams("password"));
// User user = Checker.authenticate(username, passwd);
// if (user == null) {
// req.session().removeAttribute("auth");
// ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized"));
// return res.body();
// } else {
// if (Checker.isRequestingHtml(req)) {
// res.redirect("/");
// }
// req.session().attribute("auth", true);
// res.type(ContentType.JSON);
// res.body(user.toJsonString());
// res.status(200);
// return res.body();
// }
// });
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/RootBluePrint.java
// public class RootBluePrint extends AbstractBluePrint {
//
// public RootBluePrint() {
// super("");
// }
//
// @Override
// public void register() {
// get("/", (req, res) -> "Welcome :)");
// }
// }
| import org.iotlabs.dashboard.blueprints.AbstractBluePrint;
import org.iotlabs.dashboard.blueprints.AuthBluePrint;
import org.iotlabs.dashboard.blueprints.RootBluePrint; | package org.iotlabs.dashboard;
public class SparkProxy {
private static class Holder {
private static final SparkProxy SPARK_PROXY = new SparkProxy();
}
public static SparkProxy getInstance() {
return Holder.SPARK_PROXY;
}
private SparkProxy() {
new SparkInit();
}
public void run() {
registerRouters();
}
/**
* register default setted routers.
*/
private void registerRouters() {
new AuthBluePrint().register();
new RootBluePrint().register();
}
/**
* register blueprint implementations
* @param bluePrint router blueprint
*/ | // Path: src/main/java/org/iotlabs/dashboard/blueprints/AbstractBluePrint.java
// public abstract class AbstractBluePrint {
//
// /**
// * blueprint name prefix
// */
// private String blueprintPrefix;
// private String blueprintPrefixFormatter;
// private String blueprintResourcePath;
//
// /**
// * create blueprint object
// * @param blueprintPrefix blueprint name prefix to set
// */
// public AbstractBluePrint(String blueprintPrefix) {
// if (!blueprintPrefix.startsWith("/")) {
// blueprintPrefix = "/" + blueprintPrefix;
// }
// if (blueprintPrefix.endsWith("/")) {
// blueprintPrefix = blueprintPrefix.substring(0, blueprintPrefix.length() - 1);
// }
// this.blueprintPrefix = blueprintPrefix;
// this.blueprintPrefixFormatter = blueprintPrefix + "/%s";
// this.blueprintResourcePath = "web/html/" + blueprintPrefix;
// }
//
// /**
// * Get endpoint with blueprint prefix
// * @param endPoint endpoint
// * @return {blueprint_prefix}/endPoint
// */
// public String getEndPoint(String endPoint) {
//
// if (StringUtils.isEmpty(endPoint)) {
// return blueprintPrefix;
// }
//
// if (endPoint.startsWith("/")) {
// endPoint = endPoint.substring(1, endPoint.length());
// }
// return String.format(blueprintPrefixFormatter, endPoint);
// }
//
// /**
// * Get template resource path for Mustache engine.
// * @return "web/html/{blue_print}"
// */
// public String getTemplatePath() {
// return blueprintResourcePath;
// }
//
// public abstract void register();
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/AuthBluePrint.java
// public class AuthBluePrint extends AbstractBluePrint {
//
//
// public AuthBluePrint() {
// super("auth");
// }
//
// @Override
// public void register() {
// complex(getEndPoint("login"))
// .get(
// (req, res) -> {
// Map<String, Object> scopes = new HashMap<>();
// scopes.put("title", "IotLabs");
// scopes.put("admin_mail", "[email protected]");
// return new ModelAndView(scopes,"login.html");
// }, new MustacheTemplateEngine(getTemplatePath())
// )
// .post((req, res) -> {
// String username = req.queryParams("username");
// String passwd = StringUtils.sha256(req.queryParams("password"));
// User user = Checker.authenticate(username, passwd);
// if (user == null) {
// req.session().removeAttribute("auth");
// ResponseSetter.setErrorResponse(res, new Http4xx(404, "not authorized"));
// return res.body();
// } else {
// if (Checker.isRequestingHtml(req)) {
// res.redirect("/");
// }
// req.session().attribute("auth", true);
// res.type(ContentType.JSON);
// res.body(user.toJsonString());
// res.status(200);
// return res.body();
// }
// });
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/blueprints/RootBluePrint.java
// public class RootBluePrint extends AbstractBluePrint {
//
// public RootBluePrint() {
// super("");
// }
//
// @Override
// public void register() {
// get("/", (req, res) -> "Welcome :)");
// }
// }
// Path: src/main/java/org/iotlabs/dashboard/SparkProxy.java
import org.iotlabs.dashboard.blueprints.AbstractBluePrint;
import org.iotlabs.dashboard.blueprints.AuthBluePrint;
import org.iotlabs.dashboard.blueprints.RootBluePrint;
package org.iotlabs.dashboard;
public class SparkProxy {
private static class Holder {
private static final SparkProxy SPARK_PROXY = new SparkProxy();
}
public static SparkProxy getInstance() {
return Holder.SPARK_PROXY;
}
private SparkProxy() {
new SparkInit();
}
public void run() {
registerRouters();
}
/**
* register default setted routers.
*/
private void registerRouters() {
new AuthBluePrint().register();
new RootBluePrint().register();
}
/**
* register blueprint implementations
* @param bluePrint router blueprint
*/ | public void register(AbstractBluePrint bluePrint) { |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/BaseHttpException.java
// public class BaseHttpException {
// private int code;
// private String body;
//
// BaseHttpException(int code, String body) {
// this.code = code;
// this.body = body;
// }
//
// public int getCode() {
// return code;
// }
//
// public String getBody() {
// return body;
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
| import org.iotlabs.dashboard.httpexceptions.BaseHttpException;
import org.iotlabs.dashboard.literals.ContentType;
import spark.Response; | package org.iotlabs.dashboard.utils;
public class ResponseSetter {
public static void setErrorResponse(Response errorResponse, BaseHttpException e) { | // Path: src/main/java/org/iotlabs/dashboard/httpexceptions/BaseHttpException.java
// public class BaseHttpException {
// private int code;
// private String body;
//
// BaseHttpException(int code, String body) {
// this.code = code;
// this.body = body;
// }
//
// public int getCode() {
// return code;
// }
//
// public String getBody() {
// return body;
// }
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
// Path: src/main/java/org/iotlabs/dashboard/utils/ResponseSetter.java
import org.iotlabs.dashboard.httpexceptions.BaseHttpException;
import org.iotlabs.dashboard.literals.ContentType;
import spark.Response;
package org.iotlabs.dashboard.utils;
public class ResponseSetter {
public static void setErrorResponse(Response errorResponse, BaseHttpException e) { | errorResponse.type(ContentType.HTML); |
iot-labs/dashboard | src/test/java/org/iotlabs/dashboard/SparkProxyTest.java | // Path: src/test/java/org/iotlabs/dashboard/blueprints/TestBluePrint.java
// public class TestBluePrint extends AbstractBluePrint {
//
// public TestBluePrint() {
// super("test");
// }
//
// @Override
// public void register() {
// get(getEndPoint("/"), (req, res) -> "test");
// get(getEndPoint("json"), (req, res)-> {
// TestModel testModel = new TestModel();
// testModel.id = 1;
// testModel.user = "test";
// return testModel;
// }, new JsonTransformer());
// }
//
// private static class TestModel {
// @SerializedName("id")
// private int id;
// @SerializedName("user")
// private String user;
// }
// }
| import org.iotlabs.dashboard.blueprints.TestBluePrint;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import spark.Spark;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import static org.junit.Assert.assertEquals; | package org.iotlabs.dashboard;
public class SparkProxyTest {
@BeforeClass
public static void beforeClass() {
SparkProxy.getInstance().run(); | // Path: src/test/java/org/iotlabs/dashboard/blueprints/TestBluePrint.java
// public class TestBluePrint extends AbstractBluePrint {
//
// public TestBluePrint() {
// super("test");
// }
//
// @Override
// public void register() {
// get(getEndPoint("/"), (req, res) -> "test");
// get(getEndPoint("json"), (req, res)-> {
// TestModel testModel = new TestModel();
// testModel.id = 1;
// testModel.user = "test";
// return testModel;
// }, new JsonTransformer());
// }
//
// private static class TestModel {
// @SerializedName("id")
// private int id;
// @SerializedName("user")
// private String user;
// }
// }
// Path: src/test/java/org/iotlabs/dashboard/SparkProxyTest.java
import org.iotlabs.dashboard.blueprints.TestBluePrint;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import spark.Spark;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import static org.junit.Assert.assertEquals;
package org.iotlabs.dashboard;
public class SparkProxyTest {
@BeforeClass
public static void beforeClass() {
SparkProxy.getInstance().run(); | SparkProxy.getInstance().register(new TestBluePrint()); |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/utils/Checker.java | // Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/Header.java
// public class Header {
// public static final String ACCEPT = "Accept";
// }
| import org.iotlabs.storage.models.general.User;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.literals.Header;
import spark.Request; | package org.iotlabs.dashboard.utils;
public class Checker {
public static boolean isRequestingHtml(Request request) { | // Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/Header.java
// public class Header {
// public static final String ACCEPT = "Accept";
// }
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
import org.iotlabs.storage.models.general.User;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.literals.Header;
import spark.Request;
package org.iotlabs.dashboard.utils;
public class Checker {
public static boolean isRequestingHtml(Request request) { | String accept = request.headers(Header.ACCEPT); |
iot-labs/dashboard | src/main/java/org/iotlabs/dashboard/utils/Checker.java | // Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/Header.java
// public class Header {
// public static final String ACCEPT = "Accept";
// }
| import org.iotlabs.storage.models.general.User;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.literals.Header;
import spark.Request; | package org.iotlabs.dashboard.utils;
public class Checker {
public static boolean isRequestingHtml(Request request) {
String accept = request.headers(Header.ACCEPT);
return accept != null | // Path: src/main/java/org/iotlabs/dashboard/literals/ContentType.java
// public class ContentType {
// public static final String JSON = "application/json";
// public static final String HTML = "text/html";
// }
//
// Path: src/main/java/org/iotlabs/dashboard/literals/Header.java
// public class Header {
// public static final String ACCEPT = "Accept";
// }
// Path: src/main/java/org/iotlabs/dashboard/utils/Checker.java
import org.iotlabs.storage.models.general.User;
import org.iotlabs.dashboard.literals.ContentType;
import org.iotlabs.dashboard.literals.Header;
import spark.Request;
package org.iotlabs.dashboard.utils;
public class Checker {
public static boolean isRequestingHtml(Request request) {
String accept = request.headers(Header.ACCEPT);
return accept != null | && accept.contains(ContentType.HTML); |
iot-labs/dashboard | src/test/java/org/iotlabs/dashboard/blueprints/TestBluePrint.java | // Path: src/main/java/org/iotlabs/dashboard/transformer/JsonTransformer.java
// public class JsonTransformer implements ResponseTransformer {
// private static final Gson gson = new Gson();
//
// @Override
// public String render(Object model) throws Exception {
// return gson.toJson(model);
// }
// }
| import com.google.gson.annotations.SerializedName;
import org.iotlabs.dashboard.transformer.JsonTransformer;
import static spark.Spark.get; | package org.iotlabs.dashboard.blueprints;
public class TestBluePrint extends AbstractBluePrint {
public TestBluePrint() {
super("test");
}
@Override
public void register() {
get(getEndPoint("/"), (req, res) -> "test");
get(getEndPoint("json"), (req, res)-> {
TestModel testModel = new TestModel();
testModel.id = 1;
testModel.user = "test";
return testModel; | // Path: src/main/java/org/iotlabs/dashboard/transformer/JsonTransformer.java
// public class JsonTransformer implements ResponseTransformer {
// private static final Gson gson = new Gson();
//
// @Override
// public String render(Object model) throws Exception {
// return gson.toJson(model);
// }
// }
// Path: src/test/java/org/iotlabs/dashboard/blueprints/TestBluePrint.java
import com.google.gson.annotations.SerializedName;
import org.iotlabs.dashboard.transformer.JsonTransformer;
import static spark.Spark.get;
package org.iotlabs.dashboard.blueprints;
public class TestBluePrint extends AbstractBluePrint {
public TestBluePrint() {
super("test");
}
@Override
public void register() {
get(getEndPoint("/"), (req, res) -> "test");
get(getEndPoint("json"), (req, res)-> {
TestModel testModel = new TestModel();
testModel.id = 1;
testModel.user = "test";
return testModel; | }, new JsonTransformer()); |
vidstige/jadb | test/se/vidstige/jadb/test/unit/AdbInputStreamFixture.java | // Path: src/se/vidstige/jadb/AdbFilterInputStream.java
// public class AdbFilterInputStream extends FilterInputStream {
// public AdbFilterInputStream(InputStream inputStream) {
// super(inputStream);
// }
//
// @Override
// public int read() throws IOException {
// int b1 = in.read();
// if (b1 == 0x0d) {
// in.mark(1);
// int b2 = in.read();
// if (b2 == 0x0a) {
// return b2;
// }
// in.reset();
// }
// return b1;
// }
//
// @Override
// public int read(byte[] buffer, int offset, int length) throws IOException {
// int n = 0;
// for (int i = 0; i < length; i++) {
// int b = read();
// if (b == -1) return n == 0 ? -1 : n;
// buffer[offset + n] = (byte) b;
// n++;
//
// // Return as soon as no more data is available (and at least one byte was read)
// if (in.available() <= 0) {
// return n;
// }
// }
// return n;
// }
//
// @Override
// public int read(byte[] buffer) throws IOException {
// return read(buffer, 0, buffer.length);
// }
// }
//
// Path: src/se/vidstige/jadb/Stream.java
// public class Stream {
// private Stream() {
// throw new IllegalStateException("Utility class");
// }
//
// public static void copy(InputStream in, OutputStream out) throws IOException {
// byte[] buffer = new byte[1024 * 10];
// int len;
// while ((len = in.read(buffer)) != -1) {
// out.write(buffer, 0, len);
// }
// }
//
// public static String readAll(InputStream input, Charset charset) throws IOException {
// ByteArrayOutputStream tmp = new ByteArrayOutputStream();
// Stream.copy(input, tmp);
// return new String(tmp.toByteArray(), charset);
// }
// }
| import org.junit.Assert;
import org.junit.Test;
import se.vidstige.jadb.AdbFilterInputStream;
import se.vidstige.jadb.Stream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream; | package se.vidstige.jadb.test.unit;
public class AdbInputStreamFixture {
private byte[] passthrough(byte[] input) throws IOException {
ByteArrayInputStream inputStream = new ByteArrayInputStream(input); | // Path: src/se/vidstige/jadb/AdbFilterInputStream.java
// public class AdbFilterInputStream extends FilterInputStream {
// public AdbFilterInputStream(InputStream inputStream) {
// super(inputStream);
// }
//
// @Override
// public int read() throws IOException {
// int b1 = in.read();
// if (b1 == 0x0d) {
// in.mark(1);
// int b2 = in.read();
// if (b2 == 0x0a) {
// return b2;
// }
// in.reset();
// }
// return b1;
// }
//
// @Override
// public int read(byte[] buffer, int offset, int length) throws IOException {
// int n = 0;
// for (int i = 0; i < length; i++) {
// int b = read();
// if (b == -1) return n == 0 ? -1 : n;
// buffer[offset + n] = (byte) b;
// n++;
//
// // Return as soon as no more data is available (and at least one byte was read)
// if (in.available() <= 0) {
// return n;
// }
// }
// return n;
// }
//
// @Override
// public int read(byte[] buffer) throws IOException {
// return read(buffer, 0, buffer.length);
// }
// }
//
// Path: src/se/vidstige/jadb/Stream.java
// public class Stream {
// private Stream() {
// throw new IllegalStateException("Utility class");
// }
//
// public static void copy(InputStream in, OutputStream out) throws IOException {
// byte[] buffer = new byte[1024 * 10];
// int len;
// while ((len = in.read(buffer)) != -1) {
// out.write(buffer, 0, len);
// }
// }
//
// public static String readAll(InputStream input, Charset charset) throws IOException {
// ByteArrayOutputStream tmp = new ByteArrayOutputStream();
// Stream.copy(input, tmp);
// return new String(tmp.toByteArray(), charset);
// }
// }
// Path: test/se/vidstige/jadb/test/unit/AdbInputStreamFixture.java
import org.junit.Assert;
import org.junit.Test;
import se.vidstige.jadb.AdbFilterInputStream;
import se.vidstige.jadb.Stream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
package se.vidstige.jadb.test.unit;
public class AdbInputStreamFixture {
private byte[] passthrough(byte[] input) throws IOException {
ByteArrayInputStream inputStream = new ByteArrayInputStream(input); | InputStream sut = new AdbFilterInputStream(inputStream); |
vidstige/jadb | test/se/vidstige/jadb/test/unit/AdbInputStreamFixture.java | // Path: src/se/vidstige/jadb/AdbFilterInputStream.java
// public class AdbFilterInputStream extends FilterInputStream {
// public AdbFilterInputStream(InputStream inputStream) {
// super(inputStream);
// }
//
// @Override
// public int read() throws IOException {
// int b1 = in.read();
// if (b1 == 0x0d) {
// in.mark(1);
// int b2 = in.read();
// if (b2 == 0x0a) {
// return b2;
// }
// in.reset();
// }
// return b1;
// }
//
// @Override
// public int read(byte[] buffer, int offset, int length) throws IOException {
// int n = 0;
// for (int i = 0; i < length; i++) {
// int b = read();
// if (b == -1) return n == 0 ? -1 : n;
// buffer[offset + n] = (byte) b;
// n++;
//
// // Return as soon as no more data is available (and at least one byte was read)
// if (in.available() <= 0) {
// return n;
// }
// }
// return n;
// }
//
// @Override
// public int read(byte[] buffer) throws IOException {
// return read(buffer, 0, buffer.length);
// }
// }
//
// Path: src/se/vidstige/jadb/Stream.java
// public class Stream {
// private Stream() {
// throw new IllegalStateException("Utility class");
// }
//
// public static void copy(InputStream in, OutputStream out) throws IOException {
// byte[] buffer = new byte[1024 * 10];
// int len;
// while ((len = in.read(buffer)) != -1) {
// out.write(buffer, 0, len);
// }
// }
//
// public static String readAll(InputStream input, Charset charset) throws IOException {
// ByteArrayOutputStream tmp = new ByteArrayOutputStream();
// Stream.copy(input, tmp);
// return new String(tmp.toByteArray(), charset);
// }
// }
| import org.junit.Assert;
import org.junit.Test;
import se.vidstige.jadb.AdbFilterInputStream;
import se.vidstige.jadb.Stream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream; | package se.vidstige.jadb.test.unit;
public class AdbInputStreamFixture {
private byte[] passthrough(byte[] input) throws IOException {
ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
InputStream sut = new AdbFilterInputStream(inputStream);
ByteArrayOutputStream output = new ByteArrayOutputStream(); | // Path: src/se/vidstige/jadb/AdbFilterInputStream.java
// public class AdbFilterInputStream extends FilterInputStream {
// public AdbFilterInputStream(InputStream inputStream) {
// super(inputStream);
// }
//
// @Override
// public int read() throws IOException {
// int b1 = in.read();
// if (b1 == 0x0d) {
// in.mark(1);
// int b2 = in.read();
// if (b2 == 0x0a) {
// return b2;
// }
// in.reset();
// }
// return b1;
// }
//
// @Override
// public int read(byte[] buffer, int offset, int length) throws IOException {
// int n = 0;
// for (int i = 0; i < length; i++) {
// int b = read();
// if (b == -1) return n == 0 ? -1 : n;
// buffer[offset + n] = (byte) b;
// n++;
//
// // Return as soon as no more data is available (and at least one byte was read)
// if (in.available() <= 0) {
// return n;
// }
// }
// return n;
// }
//
// @Override
// public int read(byte[] buffer) throws IOException {
// return read(buffer, 0, buffer.length);
// }
// }
//
// Path: src/se/vidstige/jadb/Stream.java
// public class Stream {
// private Stream() {
// throw new IllegalStateException("Utility class");
// }
//
// public static void copy(InputStream in, OutputStream out) throws IOException {
// byte[] buffer = new byte[1024 * 10];
// int len;
// while ((len = in.read(buffer)) != -1) {
// out.write(buffer, 0, len);
// }
// }
//
// public static String readAll(InputStream input, Charset charset) throws IOException {
// ByteArrayOutputStream tmp = new ByteArrayOutputStream();
// Stream.copy(input, tmp);
// return new String(tmp.toByteArray(), charset);
// }
// }
// Path: test/se/vidstige/jadb/test/unit/AdbInputStreamFixture.java
import org.junit.Assert;
import org.junit.Test;
import se.vidstige.jadb.AdbFilterInputStream;
import se.vidstige.jadb.Stream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
package se.vidstige.jadb.test.unit;
public class AdbInputStreamFixture {
private byte[] passthrough(byte[] input) throws IOException {
ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
InputStream sut = new AdbFilterInputStream(inputStream);
ByteArrayOutputStream output = new ByteArrayOutputStream(); | Stream.copy(sut, output); |
vidstige/jadb | test/se/vidstige/jadb/test/unit/AdbOutputStreamFixture.java | // Path: src/se/vidstige/jadb/AdbFilterOutputStream.java
// public class AdbFilterOutputStream extends LookBackFilteringOutputStream {
// public AdbFilterOutputStream(OutputStream inner) {
// super(inner, 1);
// }
//
// @Override
// public void write(int c) throws IOException {
// if (!lookback().isEmpty()) {
// Byte last = lookback().getFirst();
// if (last != null && last == 0x0d && c == 0x0a) {
// unwrite();
// }
// }
// super.write(c);
// }
// }
| import org.junit.Assert;
import org.junit.Test;
import se.vidstige.jadb.AdbFilterOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream; | package se.vidstige.jadb.test.unit;
public class AdbOutputStreamFixture {
private byte[] passthrough(byte[] input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream(); | // Path: src/se/vidstige/jadb/AdbFilterOutputStream.java
// public class AdbFilterOutputStream extends LookBackFilteringOutputStream {
// public AdbFilterOutputStream(OutputStream inner) {
// super(inner, 1);
// }
//
// @Override
// public void write(int c) throws IOException {
// if (!lookback().isEmpty()) {
// Byte last = lookback().getFirst();
// if (last != null && last == 0x0d && c == 0x0a) {
// unwrite();
// }
// }
// super.write(c);
// }
// }
// Path: test/se/vidstige/jadb/test/unit/AdbOutputStreamFixture.java
import org.junit.Assert;
import org.junit.Test;
import se.vidstige.jadb.AdbFilterOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
package se.vidstige.jadb.test.unit;
public class AdbOutputStreamFixture {
private byte[] passthrough(byte[] input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream(); | try (OutputStream sut = new AdbFilterOutputStream(output)) { |
vidstige/jadb | src/se/vidstige/jadb/server/AdbDeviceResponder.java | // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
| import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import java.io.*;
import java.util.List; | package se.vidstige.jadb.server;
/**
* Created by vidstige on 20/03/14.
*/
public interface AdbDeviceResponder {
String getSerial();
String getType();
| // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
// Path: src/se/vidstige/jadb/server/AdbDeviceResponder.java
import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import java.io.*;
import java.util.List;
package se.vidstige.jadb.server;
/**
* Created by vidstige on 20/03/14.
*/
public interface AdbDeviceResponder {
String getSerial();
String getType();
| void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException; |
vidstige/jadb | src/se/vidstige/jadb/server/AdbDeviceResponder.java | // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
| import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import java.io.*;
import java.util.List; | package se.vidstige.jadb.server;
/**
* Created by vidstige on 20/03/14.
*/
public interface AdbDeviceResponder {
String getSerial();
String getType();
| // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
// Path: src/se/vidstige/jadb/server/AdbDeviceResponder.java
import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import java.io.*;
import java.util.List;
package se.vidstige.jadb.server;
/**
* Created by vidstige on 20/03/14.
*/
public interface AdbDeviceResponder {
String getSerial();
String getType();
| void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException; |
vidstige/jadb | src/se/vidstige/jadb/JadbDevice.java | // Path: src/se/vidstige/jadb/managers/Bash.java
// public class Bash {
// private Bash() {
// throw new IllegalStateException("Utility class");
// }
//
// public static String quote(String s) {
// return "'" + s.replace("'", "'\\''") + "'";
// }
// }
| import se.vidstige.jadb.managers.Bash;
import java.io.*;
import java.util.ArrayList;
import java.util.List; | /** <p>Execute a command with raw binary output.</p>
*
* <p>Support for this command was added in Lollipop (Android 5.0), and is the recommended way to transmit binary
* data with that version or later. For earlier versions of Android, use
* {@link #executeShell(String, String...)}.</p>
*
* @param command main command to run, e.g. "screencap"
* @param args arguments to the command, e.g. "-p".
* @return combined stdout/stderr stream.
* @throws IOException
* @throws JadbException
*/
public InputStream execute(String command, String... args) throws IOException, JadbException {
Transport transport = getTransport();
StringBuilder shellLine = buildCmdLine(command, args);
send(transport, "exec:" + shellLine.toString());
return new BufferedInputStream(transport.getInputStream());
}
/**
* Builds a command line string from the command and its arguments.
*
* @param command the command.
* @param args the list of arguments.
* @return the command line.
*/
private StringBuilder buildCmdLine(String command, String... args) {
StringBuilder shellLine = new StringBuilder(command);
for (String arg : args) {
shellLine.append(" "); | // Path: src/se/vidstige/jadb/managers/Bash.java
// public class Bash {
// private Bash() {
// throw new IllegalStateException("Utility class");
// }
//
// public static String quote(String s) {
// return "'" + s.replace("'", "'\\''") + "'";
// }
// }
// Path: src/se/vidstige/jadb/JadbDevice.java
import se.vidstige.jadb.managers.Bash;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/** <p>Execute a command with raw binary output.</p>
*
* <p>Support for this command was added in Lollipop (Android 5.0), and is the recommended way to transmit binary
* data with that version or later. For earlier versions of Android, use
* {@link #executeShell(String, String...)}.</p>
*
* @param command main command to run, e.g. "screencap"
* @param args arguments to the command, e.g. "-p".
* @return combined stdout/stderr stream.
* @throws IOException
* @throws JadbException
*/
public InputStream execute(String command, String... args) throws IOException, JadbException {
Transport transport = getTransport();
StringBuilder shellLine = buildCmdLine(command, args);
send(transport, "exec:" + shellLine.toString());
return new BufferedInputStream(transport.getInputStream());
}
/**
* Builds a command line string from the command and its arguments.
*
* @param command the command.
* @param args the list of arguments.
* @return the command line.
*/
private StringBuilder buildCmdLine(String command, String... args) {
StringBuilder shellLine = new StringBuilder(command);
for (String arg : args) {
shellLine.append(" "); | shellLine.append(Bash.quote(arg)); |
vidstige/jadb | test/se/vidstige/jadb/test/unit/AdbServerLauncherFixture.java | // Path: src/se/vidstige/jadb/AdbServerLauncher.java
// public class AdbServerLauncher {
// private final String executable;
// private Subprocess subprocess;
//
// /**
// * Creates a new launcher loading ADB from the environment.
// *
// * @param subprocess the sub-process.
// * @param environment the environment to use to locate the ADB executable.
// */
// public AdbServerLauncher(Subprocess subprocess, Map<String, String> environment) {
// this(subprocess, findAdbExecutable(environment));
// }
//
// /**
// * Creates a new launcher with the specified ADB.
// *
// * @param subprocess the sub-process.
// * @param executable the location of the ADB executable.
// */
// public AdbServerLauncher(Subprocess subprocess, String executable) {
// this.subprocess = subprocess;
// this.executable = executable;
// }
//
// private static String findAdbExecutable(Map<String, String> environment) {
// String androidHome = environment.get("ANDROID_HOME");
// if (androidHome == null || androidHome.equals("")) {
// return "adb";
// }
// return androidHome + "/platform-tools/adb";
// }
//
// public void launch() throws IOException, InterruptedException {
// Process p = subprocess.execute(new String[]{executable, "start-server"});
// p.waitFor();
// int exitValue = p.exitValue();
// if (exitValue != 0) throw new IOException("adb exited with exit code: " + exitValue);
// }
// }
//
// Path: test/se/vidstige/jadb/test/fakes/FakeSubprocess.java
// public class FakeSubprocess extends Subprocess {
// private List<Expectation> expectations = new ArrayList<>();
//
// public Expectation expect(String[] command, int exitValue) {
// Expectation builder = new Expectation(command, exitValue);
// expectations.add(builder);
// return builder;
// }
//
// private String format(String[] command) {
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < command.length; i++) {
// if (i > 0) {
// sb.append(" ");
// }
// sb.append(command[i]);
// }
// return sb.toString();
// }
//
// @Override
// public Process execute(String[] command) throws IOException {
// List<Expectation> toRemove = new ArrayList<>();
// for (Expectation e : expectations) {
// if (e.matches(command)) {
// toRemove.add(e);
// }
// }
// expectations.removeAll(toRemove);
// if (toRemove.size() == 1) {
// return new FakeProcess(toRemove.get(0).getExitValue());
// }
// throw new AssertionError("Unexpected command: " + format(command));
// }
//
// public void verifyExpectations() {
// if (expectations.size() > 0) {
// throw new AssertionError("Subprocess never called: " + format(expectations.get(0).getCommand()));
// }
// }
//
// private static class Expectation {
// private final String[] command;
// private final int exitValue;
//
// public Expectation(String[] command, int exitValue) {
// this.command = command;
// this.exitValue = exitValue;
// }
//
// public boolean matches(String[] command) {
// return Arrays.equals(command, this.command);
// }
//
// public int getExitValue() {
// return exitValue;
// }
//
// public String[] getCommand() {
// return command;
// }
// }
// }
| import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import se.vidstige.jadb.AdbServerLauncher;
import se.vidstige.jadb.test.fakes.FakeSubprocess;
import java.io.IOException;
import java.util.*; | package se.vidstige.jadb.test.unit;
public class AdbServerLauncherFixture {
private FakeSubprocess subprocess;
private Map<String, String> environment = new HashMap<>();
@Before
public void setUp() {
subprocess = new FakeSubprocess();
}
@After
public void tearDown() {
subprocess.verifyExpectations();
}
@Test
public void testStartServer() throws Exception {
subprocess.expect(new String[]{"/abc/platform-tools/adb", "start-server"}, 0);
Map<String, String> environment = new HashMap<>();
environment.put("ANDROID_HOME", "/abc"); | // Path: src/se/vidstige/jadb/AdbServerLauncher.java
// public class AdbServerLauncher {
// private final String executable;
// private Subprocess subprocess;
//
// /**
// * Creates a new launcher loading ADB from the environment.
// *
// * @param subprocess the sub-process.
// * @param environment the environment to use to locate the ADB executable.
// */
// public AdbServerLauncher(Subprocess subprocess, Map<String, String> environment) {
// this(subprocess, findAdbExecutable(environment));
// }
//
// /**
// * Creates a new launcher with the specified ADB.
// *
// * @param subprocess the sub-process.
// * @param executable the location of the ADB executable.
// */
// public AdbServerLauncher(Subprocess subprocess, String executable) {
// this.subprocess = subprocess;
// this.executable = executable;
// }
//
// private static String findAdbExecutable(Map<String, String> environment) {
// String androidHome = environment.get("ANDROID_HOME");
// if (androidHome == null || androidHome.equals("")) {
// return "adb";
// }
// return androidHome + "/platform-tools/adb";
// }
//
// public void launch() throws IOException, InterruptedException {
// Process p = subprocess.execute(new String[]{executable, "start-server"});
// p.waitFor();
// int exitValue = p.exitValue();
// if (exitValue != 0) throw new IOException("adb exited with exit code: " + exitValue);
// }
// }
//
// Path: test/se/vidstige/jadb/test/fakes/FakeSubprocess.java
// public class FakeSubprocess extends Subprocess {
// private List<Expectation> expectations = new ArrayList<>();
//
// public Expectation expect(String[] command, int exitValue) {
// Expectation builder = new Expectation(command, exitValue);
// expectations.add(builder);
// return builder;
// }
//
// private String format(String[] command) {
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < command.length; i++) {
// if (i > 0) {
// sb.append(" ");
// }
// sb.append(command[i]);
// }
// return sb.toString();
// }
//
// @Override
// public Process execute(String[] command) throws IOException {
// List<Expectation> toRemove = new ArrayList<>();
// for (Expectation e : expectations) {
// if (e.matches(command)) {
// toRemove.add(e);
// }
// }
// expectations.removeAll(toRemove);
// if (toRemove.size() == 1) {
// return new FakeProcess(toRemove.get(0).getExitValue());
// }
// throw new AssertionError("Unexpected command: " + format(command));
// }
//
// public void verifyExpectations() {
// if (expectations.size() > 0) {
// throw new AssertionError("Subprocess never called: " + format(expectations.get(0).getCommand()));
// }
// }
//
// private static class Expectation {
// private final String[] command;
// private final int exitValue;
//
// public Expectation(String[] command, int exitValue) {
// this.command = command;
// this.exitValue = exitValue;
// }
//
// public boolean matches(String[] command) {
// return Arrays.equals(command, this.command);
// }
//
// public int getExitValue() {
// return exitValue;
// }
//
// public String[] getCommand() {
// return command;
// }
// }
// }
// Path: test/se/vidstige/jadb/test/unit/AdbServerLauncherFixture.java
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import se.vidstige.jadb.AdbServerLauncher;
import se.vidstige.jadb.test.fakes.FakeSubprocess;
import java.io.IOException;
import java.util.*;
package se.vidstige.jadb.test.unit;
public class AdbServerLauncherFixture {
private FakeSubprocess subprocess;
private Map<String, String> environment = new HashMap<>();
@Before
public void setUp() {
subprocess = new FakeSubprocess();
}
@After
public void tearDown() {
subprocess.verifyExpectations();
}
@Test
public void testStartServer() throws Exception {
subprocess.expect(new String[]{"/abc/platform-tools/adb", "start-server"}, 0);
Map<String, String> environment = new HashMap<>();
environment.put("ANDROID_HOME", "/abc"); | new AdbServerLauncher(subprocess, environment).launch(); |
vidstige/jadb | test/se/vidstige/jadb/test/fakes/FakeAdbServer.java | // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
//
// Path: src/se/vidstige/jadb/server/AdbDeviceResponder.java
// public interface AdbDeviceResponder {
// String getSerial();
// String getType();
//
// void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException;
// void filePulled(RemoteFile path, ByteArrayOutputStream buffer) throws JadbException, IOException;
//
// void shell(String command, DataOutputStream stdout, DataInput stdin) throws IOException;
// void enableIpCommand(String ip, DataOutputStream outputStream) throws IOException;
//
// List<RemoteFile> list(String path) throws IOException;
// }
//
// Path: src/se/vidstige/jadb/server/AdbResponder.java
// public interface AdbResponder {
// void onCommand(String command);
//
// int getVersion();
//
// List<AdbDeviceResponder> getDevices();
// }
//
// Path: src/se/vidstige/jadb/server/AdbServer.java
// public class AdbServer extends SocketServer {
//
// public static final int DEFAULT_PORT = 15037;
// private final AdbResponder responder;
//
// public AdbServer(AdbResponder responder) {
// this(responder, DEFAULT_PORT);
// }
//
// public AdbServer(AdbResponder responder, int port) {
// super(port);
// this.responder = responder;
// }
//
// @Override
// protected Runnable createResponder(Socket socket) {
// return new AdbProtocolHandler(socket, responder);
// }
// }
| import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import se.vidstige.jadb.server.AdbDeviceResponder;
import se.vidstige.jadb.server.AdbResponder;
import se.vidstige.jadb.server.AdbServer;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ProtocolException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; | }
public void add(String serial) {
devices.add(new DeviceResponder(serial, "device"));
}
public void add(String serial, String type) {
devices.add(new DeviceResponder(serial, type));
}
public void verifyExpectations() {
for (DeviceResponder d : devices)
d.verifyExpectations();
}
public interface ExpectationBuilder {
void failWith(String message);
void withContent(byte[] content);
void withContent(String content);
}
private DeviceResponder findBySerial(String serial) {
for (DeviceResponder d : devices) {
if (d.getSerial().equals(serial)) return d;
}
return null;
}
| // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
//
// Path: src/se/vidstige/jadb/server/AdbDeviceResponder.java
// public interface AdbDeviceResponder {
// String getSerial();
// String getType();
//
// void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException;
// void filePulled(RemoteFile path, ByteArrayOutputStream buffer) throws JadbException, IOException;
//
// void shell(String command, DataOutputStream stdout, DataInput stdin) throws IOException;
// void enableIpCommand(String ip, DataOutputStream outputStream) throws IOException;
//
// List<RemoteFile> list(String path) throws IOException;
// }
//
// Path: src/se/vidstige/jadb/server/AdbResponder.java
// public interface AdbResponder {
// void onCommand(String command);
//
// int getVersion();
//
// List<AdbDeviceResponder> getDevices();
// }
//
// Path: src/se/vidstige/jadb/server/AdbServer.java
// public class AdbServer extends SocketServer {
//
// public static final int DEFAULT_PORT = 15037;
// private final AdbResponder responder;
//
// public AdbServer(AdbResponder responder) {
// this(responder, DEFAULT_PORT);
// }
//
// public AdbServer(AdbResponder responder, int port) {
// super(port);
// this.responder = responder;
// }
//
// @Override
// protected Runnable createResponder(Socket socket) {
// return new AdbProtocolHandler(socket, responder);
// }
// }
// Path: test/se/vidstige/jadb/test/fakes/FakeAdbServer.java
import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import se.vidstige.jadb.server.AdbDeviceResponder;
import se.vidstige.jadb.server.AdbResponder;
import se.vidstige.jadb.server.AdbServer;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ProtocolException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
}
public void add(String serial) {
devices.add(new DeviceResponder(serial, "device"));
}
public void add(String serial, String type) {
devices.add(new DeviceResponder(serial, type));
}
public void verifyExpectations() {
for (DeviceResponder d : devices)
d.verifyExpectations();
}
public interface ExpectationBuilder {
void failWith(String message);
void withContent(byte[] content);
void withContent(String content);
}
private DeviceResponder findBySerial(String serial) {
for (DeviceResponder d : devices) {
if (d.getSerial().equals(serial)) return d;
}
return null;
}
| public ExpectationBuilder expectPush(String serial, RemoteFile path) { |
vidstige/jadb | test/se/vidstige/jadb/test/fakes/FakeAdbServer.java | // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
//
// Path: src/se/vidstige/jadb/server/AdbDeviceResponder.java
// public interface AdbDeviceResponder {
// String getSerial();
// String getType();
//
// void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException;
// void filePulled(RemoteFile path, ByteArrayOutputStream buffer) throws JadbException, IOException;
//
// void shell(String command, DataOutputStream stdout, DataInput stdin) throws IOException;
// void enableIpCommand(String ip, DataOutputStream outputStream) throws IOException;
//
// List<RemoteFile> list(String path) throws IOException;
// }
//
// Path: src/se/vidstige/jadb/server/AdbResponder.java
// public interface AdbResponder {
// void onCommand(String command);
//
// int getVersion();
//
// List<AdbDeviceResponder> getDevices();
// }
//
// Path: src/se/vidstige/jadb/server/AdbServer.java
// public class AdbServer extends SocketServer {
//
// public static final int DEFAULT_PORT = 15037;
// private final AdbResponder responder;
//
// public AdbServer(AdbResponder responder) {
// this(responder, DEFAULT_PORT);
// }
//
// public AdbServer(AdbResponder responder, int port) {
// super(port);
// this.responder = responder;
// }
//
// @Override
// protected Runnable createResponder(Socket socket) {
// return new AdbProtocolHandler(socket, responder);
// }
// }
| import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import se.vidstige.jadb.server.AdbDeviceResponder;
import se.vidstige.jadb.server.AdbResponder;
import se.vidstige.jadb.server.AdbServer;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ProtocolException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; | }
private DeviceResponder findBySerial(String serial) {
for (DeviceResponder d : devices) {
if (d.getSerial().equals(serial)) return d;
}
return null;
}
public ExpectationBuilder expectPush(String serial, RemoteFile path) {
return findBySerial(serial).expectPush(path);
}
public ExpectationBuilder expectPull(String serial, RemoteFile path) {
return findBySerial(serial).expectPull(path);
}
public DeviceResponder.ShellExpectation expectShell(String serial, String commands) {
return findBySerial(serial).expectShell(commands);
}
public void expectTcpip(String serial, Integer port) {
findBySerial(serial).expectTcpip(port);
}
public DeviceResponder.ListExpectation expectList(String serial, String remotePath) {
return findBySerial(serial).expectList(remotePath);
}
@Override | // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
//
// Path: src/se/vidstige/jadb/server/AdbDeviceResponder.java
// public interface AdbDeviceResponder {
// String getSerial();
// String getType();
//
// void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException;
// void filePulled(RemoteFile path, ByteArrayOutputStream buffer) throws JadbException, IOException;
//
// void shell(String command, DataOutputStream stdout, DataInput stdin) throws IOException;
// void enableIpCommand(String ip, DataOutputStream outputStream) throws IOException;
//
// List<RemoteFile> list(String path) throws IOException;
// }
//
// Path: src/se/vidstige/jadb/server/AdbResponder.java
// public interface AdbResponder {
// void onCommand(String command);
//
// int getVersion();
//
// List<AdbDeviceResponder> getDevices();
// }
//
// Path: src/se/vidstige/jadb/server/AdbServer.java
// public class AdbServer extends SocketServer {
//
// public static final int DEFAULT_PORT = 15037;
// private final AdbResponder responder;
//
// public AdbServer(AdbResponder responder) {
// this(responder, DEFAULT_PORT);
// }
//
// public AdbServer(AdbResponder responder, int port) {
// super(port);
// this.responder = responder;
// }
//
// @Override
// protected Runnable createResponder(Socket socket) {
// return new AdbProtocolHandler(socket, responder);
// }
// }
// Path: test/se/vidstige/jadb/test/fakes/FakeAdbServer.java
import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import se.vidstige.jadb.server.AdbDeviceResponder;
import se.vidstige.jadb.server.AdbResponder;
import se.vidstige.jadb.server.AdbServer;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ProtocolException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
}
private DeviceResponder findBySerial(String serial) {
for (DeviceResponder d : devices) {
if (d.getSerial().equals(serial)) return d;
}
return null;
}
public ExpectationBuilder expectPush(String serial, RemoteFile path) {
return findBySerial(serial).expectPush(path);
}
public ExpectationBuilder expectPull(String serial, RemoteFile path) {
return findBySerial(serial).expectPull(path);
}
public DeviceResponder.ShellExpectation expectShell(String serial, String commands) {
return findBySerial(serial).expectShell(commands);
}
public void expectTcpip(String serial, Integer port) {
findBySerial(serial).expectTcpip(port);
}
public DeviceResponder.ListExpectation expectList(String serial, String remotePath) {
return findBySerial(serial).expectList(remotePath);
}
@Override | public List<AdbDeviceResponder> getDevices() { |
vidstige/jadb | test/se/vidstige/jadb/test/fakes/FakeAdbServer.java | // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
//
// Path: src/se/vidstige/jadb/server/AdbDeviceResponder.java
// public interface AdbDeviceResponder {
// String getSerial();
// String getType();
//
// void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException;
// void filePulled(RemoteFile path, ByteArrayOutputStream buffer) throws JadbException, IOException;
//
// void shell(String command, DataOutputStream stdout, DataInput stdin) throws IOException;
// void enableIpCommand(String ip, DataOutputStream outputStream) throws IOException;
//
// List<RemoteFile> list(String path) throws IOException;
// }
//
// Path: src/se/vidstige/jadb/server/AdbResponder.java
// public interface AdbResponder {
// void onCommand(String command);
//
// int getVersion();
//
// List<AdbDeviceResponder> getDevices();
// }
//
// Path: src/se/vidstige/jadb/server/AdbServer.java
// public class AdbServer extends SocketServer {
//
// public static final int DEFAULT_PORT = 15037;
// private final AdbResponder responder;
//
// public AdbServer(AdbResponder responder) {
// this(responder, DEFAULT_PORT);
// }
//
// public AdbServer(AdbResponder responder, int port) {
// super(port);
// this.responder = responder;
// }
//
// @Override
// protected Runnable createResponder(Socket socket) {
// return new AdbProtocolHandler(socket, responder);
// }
// }
| import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import se.vidstige.jadb.server.AdbDeviceResponder;
import se.vidstige.jadb.server.AdbResponder;
import se.vidstige.jadb.server.AdbServer;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ProtocolException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; |
@Override
public List<AdbDeviceResponder> getDevices() {
return new ArrayList<AdbDeviceResponder>(devices);
}
private static class DeviceResponder implements AdbDeviceResponder {
private final String serial;
private final String type;
private List<FileExpectation> fileExpectations = new ArrayList<>();
private List<ShellExpectation> shellExpectations = new ArrayList<>();
private List<ListExpectation> listExpectations = new ArrayList<>();
private List<Integer> tcpipExpectations = new ArrayList<>();
private DeviceResponder(String serial, String type) {
this.serial = serial;
this.type = type;
}
@Override
public String getSerial() {
return serial;
}
@Override
public String getType() {
return type;
}
@Override | // Path: src/se/vidstige/jadb/JadbException.java
// public class JadbException extends Exception {
//
// public JadbException(String message) {
// super(message);
// }
//
// private static final long serialVersionUID = -3879283786835654165L;
// }
//
// Path: src/se/vidstige/jadb/RemoteFile.java
// public class RemoteFile {
// private final String path;
//
// public RemoteFile(String path) { this.path = path; }
//
// public String getName() { throw new UnsupportedOperationException(); }
// public int getSize() { throw new UnsupportedOperationException(); }
// public int getLastModified() { throw new UnsupportedOperationException(); }
// public boolean isDirectory() { throw new UnsupportedOperationException(); }
//
// public String getPath() { return path;}
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// RemoteFile that = (RemoteFile) o;
// return path.equals(that.path);
// }
//
// @Override
// public int hashCode() {
// return path.hashCode();
// }
// }
//
// Path: src/se/vidstige/jadb/server/AdbDeviceResponder.java
// public interface AdbDeviceResponder {
// String getSerial();
// String getType();
//
// void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException;
// void filePulled(RemoteFile path, ByteArrayOutputStream buffer) throws JadbException, IOException;
//
// void shell(String command, DataOutputStream stdout, DataInput stdin) throws IOException;
// void enableIpCommand(String ip, DataOutputStream outputStream) throws IOException;
//
// List<RemoteFile> list(String path) throws IOException;
// }
//
// Path: src/se/vidstige/jadb/server/AdbResponder.java
// public interface AdbResponder {
// void onCommand(String command);
//
// int getVersion();
//
// List<AdbDeviceResponder> getDevices();
// }
//
// Path: src/se/vidstige/jadb/server/AdbServer.java
// public class AdbServer extends SocketServer {
//
// public static final int DEFAULT_PORT = 15037;
// private final AdbResponder responder;
//
// public AdbServer(AdbResponder responder) {
// this(responder, DEFAULT_PORT);
// }
//
// public AdbServer(AdbResponder responder, int port) {
// super(port);
// this.responder = responder;
// }
//
// @Override
// protected Runnable createResponder(Socket socket) {
// return new AdbProtocolHandler(socket, responder);
// }
// }
// Path: test/se/vidstige/jadb/test/fakes/FakeAdbServer.java
import se.vidstige.jadb.JadbException;
import se.vidstige.jadb.RemoteFile;
import se.vidstige.jadb.server.AdbDeviceResponder;
import se.vidstige.jadb.server.AdbResponder;
import se.vidstige.jadb.server.AdbServer;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ProtocolException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Override
public List<AdbDeviceResponder> getDevices() {
return new ArrayList<AdbDeviceResponder>(devices);
}
private static class DeviceResponder implements AdbDeviceResponder {
private final String serial;
private final String type;
private List<FileExpectation> fileExpectations = new ArrayList<>();
private List<ShellExpectation> shellExpectations = new ArrayList<>();
private List<ListExpectation> listExpectations = new ArrayList<>();
private List<Integer> tcpipExpectations = new ArrayList<>();
private DeviceResponder(String serial, String type) {
this.serial = serial;
this.type = type;
}
@Override
public String getSerial() {
return serial;
}
@Override
public String getType() {
return type;
}
@Override | public void filePushed(RemoteFile path, int mode, ByteArrayOutputStream buffer) throws JadbException { |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitInputTest.java | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
| import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException; | package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for testing subclasses of {@link BitInput}.
*
* @param <T> bit input type parameter
* @see BitOutputTest
* @see AbstractBitInputTest
*/
@Slf4j
abstract class BitInputTest<T extends BitInput> {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance with given bit input class.
*
* @param bitInputClass the bit input class.
*/
BitInputTest(final Class<T> bitInputClass) {
super();
this.bitInputClass = requireNonNull(bitInputClass, "bitInputClass is null");
}
// -----------------------------------------------------------------------------------------------------------------
@BeforeEach
void select() {
bitInput = bitInputInstance.select(bitInputClass).get();
}
@AfterEach
void align() throws IOException {
final long bits = bitInput.align(current().nextInt(1, 16));
assertTrue(bits >= 0L);
}
// --------------------------------------------------------------------------------------------------------- boolean
@RepeatedTest(8)
void testReadBoolean() throws IOException {
final boolean value = bitInput.readBoolean();
}
// ------------------------------------------------------------------------------------------------------------ byte
/**
* Asserts {@link BitInput#readByte(boolean, int)} throws an {@link IllegalArgumentException} when {@code size} is
* less than {@code 1}.
*/
@Test
void assertReadByteThrowsIllegalArgumentExceptionWhenSizeIsLessThanOne() {
assertThrows(IllegalArgumentException.class, () -> bitInput.readByte(current().nextBoolean(), 0));
assertThrows(IllegalArgumentException.class,
() -> bitInput.readByte(current().nextBoolean(), current().nextInt() | Integer.MIN_VALUE));
}
@RepeatedTest(8)
void testReadByte() throws IOException {
final boolean unsigned = current().nextBoolean(); | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitInputTest.java
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException;
package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for testing subclasses of {@link BitInput}.
*
* @param <T> bit input type parameter
* @see BitOutputTest
* @see AbstractBitInputTest
*/
@Slf4j
abstract class BitInputTest<T extends BitInput> {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance with given bit input class.
*
* @param bitInputClass the bit input class.
*/
BitInputTest(final Class<T> bitInputClass) {
super();
this.bitInputClass = requireNonNull(bitInputClass, "bitInputClass is null");
}
// -----------------------------------------------------------------------------------------------------------------
@BeforeEach
void select() {
bitInput = bitInputInstance.select(bitInputClass).get();
}
@AfterEach
void align() throws IOException {
final long bits = bitInput.align(current().nextInt(1, 16));
assertTrue(bits >= 0L);
}
// --------------------------------------------------------------------------------------------------------- boolean
@RepeatedTest(8)
void testReadBoolean() throws IOException {
final boolean value = bitInput.readBoolean();
}
// ------------------------------------------------------------------------------------------------------------ byte
/**
* Asserts {@link BitInput#readByte(boolean, int)} throws an {@link IllegalArgumentException} when {@code size} is
* less than {@code 1}.
*/
@Test
void assertReadByteThrowsIllegalArgumentExceptionWhenSizeIsLessThanOne() {
assertThrows(IllegalArgumentException.class, () -> bitInput.readByte(current().nextBoolean(), 0));
assertThrows(IllegalArgumentException.class,
() -> bitInput.readByte(current().nextBoolean(), current().nextInt() | Integer.MIN_VALUE));
}
@RepeatedTest(8)
void testReadByte() throws IOException {
final boolean unsigned = current().nextBoolean(); | final int size = randomSizeForByte(unsigned); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitInputTest.java | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
| import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException; | // --------------------------------------------------------------------------------------------------------- boolean
@RepeatedTest(8)
void testReadBoolean() throws IOException {
final boolean value = bitInput.readBoolean();
}
// ------------------------------------------------------------------------------------------------------------ byte
/**
* Asserts {@link BitInput#readByte(boolean, int)} throws an {@link IllegalArgumentException} when {@code size} is
* less than {@code 1}.
*/
@Test
void assertReadByteThrowsIllegalArgumentExceptionWhenSizeIsLessThanOne() {
assertThrows(IllegalArgumentException.class, () -> bitInput.readByte(current().nextBoolean(), 0));
assertThrows(IllegalArgumentException.class,
() -> bitInput.readByte(current().nextBoolean(), current().nextInt() | Integer.MIN_VALUE));
}
@RepeatedTest(8)
void testReadByte() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForByte(unsigned);
final byte value = bitInput.readByte(unsigned, size);
}
// ----------------------------------------------------------------------------------------------------------- short
@RepeatedTest(8)
void testReadShort() throws IOException {
final boolean unsigned = current().nextBoolean(); | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitInputTest.java
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException;
// --------------------------------------------------------------------------------------------------------- boolean
@RepeatedTest(8)
void testReadBoolean() throws IOException {
final boolean value = bitInput.readBoolean();
}
// ------------------------------------------------------------------------------------------------------------ byte
/**
* Asserts {@link BitInput#readByte(boolean, int)} throws an {@link IllegalArgumentException} when {@code size} is
* less than {@code 1}.
*/
@Test
void assertReadByteThrowsIllegalArgumentExceptionWhenSizeIsLessThanOne() {
assertThrows(IllegalArgumentException.class, () -> bitInput.readByte(current().nextBoolean(), 0));
assertThrows(IllegalArgumentException.class,
() -> bitInput.readByte(current().nextBoolean(), current().nextInt() | Integer.MIN_VALUE));
}
@RepeatedTest(8)
void testReadByte() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForByte(unsigned);
final byte value = bitInput.readByte(unsigned, size);
}
// ----------------------------------------------------------------------------------------------------------- short
@RepeatedTest(8)
void testReadShort() throws IOException {
final boolean unsigned = current().nextBoolean(); | final int size = randomSizeForShort(unsigned); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitInputTest.java | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
| import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException; | /**
* Asserts {@link BitInput#readByte(boolean, int)} throws an {@link IllegalArgumentException} when {@code size} is
* less than {@code 1}.
*/
@Test
void assertReadByteThrowsIllegalArgumentExceptionWhenSizeIsLessThanOne() {
assertThrows(IllegalArgumentException.class, () -> bitInput.readByte(current().nextBoolean(), 0));
assertThrows(IllegalArgumentException.class,
() -> bitInput.readByte(current().nextBoolean(), current().nextInt() | Integer.MIN_VALUE));
}
@RepeatedTest(8)
void testReadByte() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForByte(unsigned);
final byte value = bitInput.readByte(unsigned, size);
}
// ----------------------------------------------------------------------------------------------------------- short
@RepeatedTest(8)
void testReadShort() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForShort(unsigned);
final short value = bitInput.readShort(unsigned, size);
}
// ------------------------------------------------------------------------------------------------------------- int
@RepeatedTest(8)
void testReadInt() throws IOException {
final boolean unsigned = current().nextBoolean(); | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitInputTest.java
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException;
/**
* Asserts {@link BitInput#readByte(boolean, int)} throws an {@link IllegalArgumentException} when {@code size} is
* less than {@code 1}.
*/
@Test
void assertReadByteThrowsIllegalArgumentExceptionWhenSizeIsLessThanOne() {
assertThrows(IllegalArgumentException.class, () -> bitInput.readByte(current().nextBoolean(), 0));
assertThrows(IllegalArgumentException.class,
() -> bitInput.readByte(current().nextBoolean(), current().nextInt() | Integer.MIN_VALUE));
}
@RepeatedTest(8)
void testReadByte() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForByte(unsigned);
final byte value = bitInput.readByte(unsigned, size);
}
// ----------------------------------------------------------------------------------------------------------- short
@RepeatedTest(8)
void testReadShort() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForShort(unsigned);
final short value = bitInput.readShort(unsigned, size);
}
// ------------------------------------------------------------------------------------------------------------- int
@RepeatedTest(8)
void testReadInt() throws IOException {
final boolean unsigned = current().nextBoolean(); | final int size = randomSizeForInt(unsigned); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitInputTest.java | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
| import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException; | () -> bitInput.readByte(current().nextBoolean(), current().nextInt() | Integer.MIN_VALUE));
}
@RepeatedTest(8)
void testReadByte() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForByte(unsigned);
final byte value = bitInput.readByte(unsigned, size);
}
// ----------------------------------------------------------------------------------------------------------- short
@RepeatedTest(8)
void testReadShort() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForShort(unsigned);
final short value = bitInput.readShort(unsigned, size);
}
// ------------------------------------------------------------------------------------------------------------- int
@RepeatedTest(8)
void testReadInt() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForInt(unsigned);
final int value = bitInput.readInt(unsigned, size);
}
// ------------------------------------------------------------------------------------------------------------ long
@RepeatedTest(8)
void testReadLong() throws IOException {
final boolean unsigned = current().nextBoolean(); | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitInputTest.java
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException;
() -> bitInput.readByte(current().nextBoolean(), current().nextInt() | Integer.MIN_VALUE));
}
@RepeatedTest(8)
void testReadByte() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForByte(unsigned);
final byte value = bitInput.readByte(unsigned, size);
}
// ----------------------------------------------------------------------------------------------------------- short
@RepeatedTest(8)
void testReadShort() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForShort(unsigned);
final short value = bitInput.readShort(unsigned, size);
}
// ------------------------------------------------------------------------------------------------------------- int
@RepeatedTest(8)
void testReadInt() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForInt(unsigned);
final int value = bitInput.readInt(unsigned, size);
}
// ------------------------------------------------------------------------------------------------------------ long
@RepeatedTest(8)
void testReadLong() throws IOException {
final boolean unsigned = current().nextBoolean(); | final int size = randomSizeForLong(unsigned); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitIoTest.java | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForChar() {
// return requireValidSizeChar(current().nextInt(1, Character.SIZE));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static byte randomValueForByte(final boolean unsigned, final int size) {
// final byte value;
// if (unsigned) {
// value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
// assertTrue(value >= 0);
// } else {
// value = (byte) (current().nextInt() >> (Integer.SIZE - size));
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// return value;
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static char randomValueForChar(final int size) {
// return (char) (current().nextInt(Character.MAX_VALUE + 1) >> (Integer.SIZE - size));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomValueForInt(final boolean unsigned, final int size) {
// final int value;
// if (unsigned) {
// value = current().nextInt() >>> (Integer.SIZE - size);
// assertTrue(value >= 0);
// } else {
// value = current().nextInt() >> (Integer.SIZE - size);
// if (size < Integer.SIZE) {
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// }
// return value;
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static long randomValueForLong(final boolean unsigned, final int size) {
// final long value;
// if (unsigned) {
// value = current().nextLong() >>> (Long.SIZE - size);
// assertTrue(value >= 0);
// } else {
// value = current().nextLong() >> (Long.SIZE - size);
// if (size < Long.SIZE) {
// assertEquals(value >> size, value >= 0L ? 0L : -1L);
// }
// }
// return value;
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static short randomValueForShort(final boolean unsigned, final int size) {
// final short value;
// if (unsigned) {
// value = (short) (current().nextInt() >>> (Integer.SIZE - size));
// assertTrue(value >= 0);
// } else {
// value = (short) (current().nextInt() >> (Integer.SIZE - size));
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// return value;
// }
| import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForChar;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForChar;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt; | throws IOException {
final int expected = current().nextInt();
output.writeInt32(expected);
assertEquals(0L, output.align(Byte.BYTES));
final int actual = input.readInt32();
assertEquals(0L, input.align(Byte.BYTES));
assertEquals(expected, actual);
}
@MethodSource({"com.github.jinahya.bit.io.ByteIoSource#sourceByteIo"})
@ParameterizedTest
void testInt32Le(@ConvertWith(BitOutputConverter.class) final BitOutput output,
@ConvertWith(BitInputConverter.class) final BitInput input)
throws IOException {
final int expected = current().nextInt();
output.writeInt32Le(expected);
assertEquals(0L, output.align(Byte.BYTES));
final int actual = input.readInt32Le();
assertEquals(0L, input.align(Byte.BYTES));
assertEquals(expected, actual);
}
// ------------------------------------------------------------------------------------------------------------ long
@MethodSource({"com.github.jinahya.bit.io.ByteIoSource#sourceByteIo"})
@ParameterizedTest
void testLong(@ConvertWith(BitOutputConverter.class) final BitOutput output,
@ConvertWith(BitInputConverter.class) final BitInput input)
throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForLong(unsigned); | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForChar() {
// return requireValidSizeChar(current().nextInt(1, Character.SIZE));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForInt(final boolean unsigned) {
// return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForLong(final boolean unsigned) {
// return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForShort(final boolean unsigned) {
// return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static byte randomValueForByte(final boolean unsigned, final int size) {
// final byte value;
// if (unsigned) {
// value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
// assertTrue(value >= 0);
// } else {
// value = (byte) (current().nextInt() >> (Integer.SIZE - size));
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// return value;
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static char randomValueForChar(final int size) {
// return (char) (current().nextInt(Character.MAX_VALUE + 1) >> (Integer.SIZE - size));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomValueForInt(final boolean unsigned, final int size) {
// final int value;
// if (unsigned) {
// value = current().nextInt() >>> (Integer.SIZE - size);
// assertTrue(value >= 0);
// } else {
// value = current().nextInt() >> (Integer.SIZE - size);
// if (size < Integer.SIZE) {
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// }
// return value;
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static long randomValueForLong(final boolean unsigned, final int size) {
// final long value;
// if (unsigned) {
// value = current().nextLong() >>> (Long.SIZE - size);
// assertTrue(value >= 0);
// } else {
// value = current().nextLong() >> (Long.SIZE - size);
// if (size < Long.SIZE) {
// assertEquals(value >> size, value >= 0L ? 0L : -1L);
// }
// }
// return value;
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static short randomValueForShort(final boolean unsigned, final int size) {
// final short value;
// if (unsigned) {
// value = (short) (current().nextInt() >>> (Integer.SIZE - size));
// assertTrue(value >= 0);
// } else {
// value = (short) (current().nextInt() >> (Integer.SIZE - size));
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// return value;
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTest.java
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForShort;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForChar;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForInt;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForLong;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForChar;
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForInt;
throws IOException {
final int expected = current().nextInt();
output.writeInt32(expected);
assertEquals(0L, output.align(Byte.BYTES));
final int actual = input.readInt32();
assertEquals(0L, input.align(Byte.BYTES));
assertEquals(expected, actual);
}
@MethodSource({"com.github.jinahya.bit.io.ByteIoSource#sourceByteIo"})
@ParameterizedTest
void testInt32Le(@ConvertWith(BitOutputConverter.class) final BitOutput output,
@ConvertWith(BitInputConverter.class) final BitInput input)
throws IOException {
final int expected = current().nextInt();
output.writeInt32Le(expected);
assertEquals(0L, output.align(Byte.BYTES));
final int actual = input.readInt32Le();
assertEquals(0L, input.align(Byte.BYTES));
assertEquals(expected, actual);
}
// ------------------------------------------------------------------------------------------------------------ long
@MethodSource({"com.github.jinahya.bit.io.ByteIoSource#sourceByteIo"})
@ParameterizedTest
void testLong(@ConvertWith(BitOutputConverter.class) final BitOutput output,
@ConvertWith(BitInputConverter.class) final BitInput input)
throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForLong(unsigned); | final long expected = randomValueForLong(unsigned, size); |
jinahya/bit-io | src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort; | package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for implementing {@link BitInput} interface.
*
* @author Jin Kwon <jinahya_at_gmail.com>
* @see AbstractBitInput
* @see DefaultBitOutput
*/
public abstract class AbstractBitOutput implements BitOutput {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance.
*/
protected AbstractBitOutput() {
super();
}
// -----------------------------------------------------------------------------------------------------------------
/**
* Writes given {@value java.lang.Byte#SIZE}-bit unsigned integer.
*
* @param value the {@value java.lang.Byte#SIZE}-bit unsigned integer to write.
* @throws IOException if an I/O error occurs.
*/
protected abstract void write(int value) throws IOException;
// -----------------------------------------------------------------------------------------------------------------
/**
* Writes an unsigned {@code int} value of specified bit size which is, in maximum, {@value java.lang.Byte#SIZE}.
*
* @param size the number of lower bits to write; between {@code 1} and {@value java.lang.Byte#SIZE}, both
* inclusive.
* @param value the value to write.
* @throws IOException if an I/O error occurs.
* @see #write(int)
*/
private void unsigned8(final int size, final int value) throws IOException {
final int required = size - available;
if (required > 0) {
unsigned8(available, value >> required);
unsigned8(required, value);
return;
}
octet <<= size; | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for implementing {@link BitInput} interface.
*
* @author Jin Kwon <jinahya_at_gmail.com>
* @see AbstractBitInput
* @see DefaultBitOutput
*/
public abstract class AbstractBitOutput implements BitOutput {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance.
*/
protected AbstractBitOutput() {
super();
}
// -----------------------------------------------------------------------------------------------------------------
/**
* Writes given {@value java.lang.Byte#SIZE}-bit unsigned integer.
*
* @param value the {@value java.lang.Byte#SIZE}-bit unsigned integer to write.
* @throws IOException if an I/O error occurs.
*/
protected abstract void write(int value) throws IOException;
// -----------------------------------------------------------------------------------------------------------------
/**
* Writes an unsigned {@code int} value of specified bit size which is, in maximum, {@value java.lang.Byte#SIZE}.
*
* @param size the number of lower bits to write; between {@code 1} and {@value java.lang.Byte#SIZE}, both
* inclusive.
* @param value the value to write.
* @throws IOException if an I/O error occurs.
* @see #write(int)
*/
private void unsigned8(final int size, final int value) throws IOException {
final int required = size - available;
if (required > 0) {
unsigned8(available, value >> required);
unsigned8(required, value);
return;
}
octet <<= size; | octet |= value & mask(size); |
jinahya/bit-io | src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort; | package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for implementing {@link BitInput} interface.
*
* @author Jin Kwon <jinahya_at_gmail.com>
* @see AbstractBitInput
* @see DefaultBitOutput
*/
public abstract class AbstractBitOutput implements BitOutput {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance.
*/
protected AbstractBitOutput() {
super();
}
// -----------------------------------------------------------------------------------------------------------------
/**
* Writes given {@value java.lang.Byte#SIZE}-bit unsigned integer.
*
* @param value the {@value java.lang.Byte#SIZE}-bit unsigned integer to write.
* @throws IOException if an I/O error occurs.
*/
protected abstract void write(int value) throws IOException;
// -----------------------------------------------------------------------------------------------------------------
/**
* Writes an unsigned {@code int} value of specified bit size which is, in maximum, {@value java.lang.Byte#SIZE}.
*
* @param size the number of lower bits to write; between {@code 1} and {@value java.lang.Byte#SIZE}, both
* inclusive.
* @param value the value to write.
* @throws IOException if an I/O error occurs.
* @see #write(int)
*/
private void unsigned8(final int size, final int value) throws IOException {
final int required = size - available;
if (required > 0) {
unsigned8(available, value >> required);
unsigned8(required, value);
return;
}
octet <<= size;
octet |= value & mask(size);
available -= size;
if (available == 0) {
assert octet >= 0 && octet < 256;
write(octet);
count++;
octet = 0x00;
available = Byte.SIZE;
}
}
// --------------------------------------------------------------------------------------------------------- boolean
@Override
public void writeBoolean(final boolean value) throws IOException {
writeInt(true, 1, value ? 1 : 0);
}
// ------------------------------------------------------------------------------------------------------------ byte
@Override
public void writeByte(final boolean unsigned, final int size, final byte value) throws IOException { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for implementing {@link BitInput} interface.
*
* @author Jin Kwon <jinahya_at_gmail.com>
* @see AbstractBitInput
* @see DefaultBitOutput
*/
public abstract class AbstractBitOutput implements BitOutput {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance.
*/
protected AbstractBitOutput() {
super();
}
// -----------------------------------------------------------------------------------------------------------------
/**
* Writes given {@value java.lang.Byte#SIZE}-bit unsigned integer.
*
* @param value the {@value java.lang.Byte#SIZE}-bit unsigned integer to write.
* @throws IOException if an I/O error occurs.
*/
protected abstract void write(int value) throws IOException;
// -----------------------------------------------------------------------------------------------------------------
/**
* Writes an unsigned {@code int} value of specified bit size which is, in maximum, {@value java.lang.Byte#SIZE}.
*
* @param size the number of lower bits to write; between {@code 1} and {@value java.lang.Byte#SIZE}, both
* inclusive.
* @param value the value to write.
* @throws IOException if an I/O error occurs.
* @see #write(int)
*/
private void unsigned8(final int size, final int value) throws IOException {
final int required = size - available;
if (required > 0) {
unsigned8(available, value >> required);
unsigned8(required, value);
return;
}
octet <<= size;
octet |= value & mask(size);
available -= size;
if (available == 0) {
assert octet >= 0 && octet < 256;
write(octet);
count++;
octet = 0x00;
available = Byte.SIZE;
}
}
// --------------------------------------------------------------------------------------------------------- boolean
@Override
public void writeBoolean(final boolean value) throws IOException {
writeInt(true, 1, value ? 1 : 0);
}
// ------------------------------------------------------------------------------------------------------------ byte
@Override
public void writeByte(final boolean unsigned, final int size, final byte value) throws IOException { | writeInt(unsigned, requireValidSizeByte(unsigned, size), value); |
jinahya/bit-io | src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort; | available -= size;
if (available == 0) {
assert octet >= 0 && octet < 256;
write(octet);
count++;
octet = 0x00;
available = Byte.SIZE;
}
}
// --------------------------------------------------------------------------------------------------------- boolean
@Override
public void writeBoolean(final boolean value) throws IOException {
writeInt(true, 1, value ? 1 : 0);
}
// ------------------------------------------------------------------------------------------------------------ byte
@Override
public void writeByte(final boolean unsigned, final int size, final byte value) throws IOException {
writeInt(unsigned, requireValidSizeByte(unsigned, size), value);
}
@Override
public void writeByte8(final byte value) throws IOException {
writeByte(false, Byte.SIZE, value);
}
// ----------------------------------------------------------------------------------------------------------- short
@Override
public void writeShort(final boolean unsigned, final int size, final short value) throws IOException { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
available -= size;
if (available == 0) {
assert octet >= 0 && octet < 256;
write(octet);
count++;
octet = 0x00;
available = Byte.SIZE;
}
}
// --------------------------------------------------------------------------------------------------------- boolean
@Override
public void writeBoolean(final boolean value) throws IOException {
writeInt(true, 1, value ? 1 : 0);
}
// ------------------------------------------------------------------------------------------------------------ byte
@Override
public void writeByte(final boolean unsigned, final int size, final byte value) throws IOException {
writeInt(unsigned, requireValidSizeByte(unsigned, size), value);
}
@Override
public void writeByte8(final byte value) throws IOException {
writeByte(false, Byte.SIZE, value);
}
// ----------------------------------------------------------------------------------------------------------- short
@Override
public void writeShort(final boolean unsigned, final int size, final short value) throws IOException { | writeInt(unsigned, requireValidSizeShort(unsigned, size), value); |
jinahya/bit-io | src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort; | @Override
public void writeByte(final boolean unsigned, final int size, final byte value) throws IOException {
writeInt(unsigned, requireValidSizeByte(unsigned, size), value);
}
@Override
public void writeByte8(final byte value) throws IOException {
writeByte(false, Byte.SIZE, value);
}
// ----------------------------------------------------------------------------------------------------------- short
@Override
public void writeShort(final boolean unsigned, final int size, final short value) throws IOException {
writeInt(unsigned, requireValidSizeShort(unsigned, size), value);
}
@Override
public void writeShort16(final short value) throws IOException {
writeShort(false, Short.SIZE, value);
}
@Override
public void writeShort16Le(final short value) throws IOException {
writeByte8((byte) value);
writeByte8((byte) (value >> Byte.SIZE));
}
// ------------------------------------------------------------------------------------------------------------- int
@Override
public void writeInt(final boolean unsigned, int size, final int value) throws IOException { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
@Override
public void writeByte(final boolean unsigned, final int size, final byte value) throws IOException {
writeInt(unsigned, requireValidSizeByte(unsigned, size), value);
}
@Override
public void writeByte8(final byte value) throws IOException {
writeByte(false, Byte.SIZE, value);
}
// ----------------------------------------------------------------------------------------------------------- short
@Override
public void writeShort(final boolean unsigned, final int size, final short value) throws IOException {
writeInt(unsigned, requireValidSizeShort(unsigned, size), value);
}
@Override
public void writeShort16(final short value) throws IOException {
writeShort(false, Short.SIZE, value);
}
@Override
public void writeShort16Le(final short value) throws IOException {
writeByte8((byte) value);
writeByte8((byte) (value >> Byte.SIZE));
}
// ------------------------------------------------------------------------------------------------------------- int
@Override
public void writeInt(final boolean unsigned, int size, final int value) throws IOException { | requireValidSizeInt(unsigned, size); |
jinahya/bit-io | src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort; | writeInt(true, 1, value < 0 ? 1 : 0);
if (--size > 0) {
writeInt(true, size, value);
}
return;
}
final int quotient = size >> 3;
final int remainder = size & 7;
if (remainder > 0) {
unsigned8(remainder, value >> (quotient << 3));
}
for (int i = Byte.SIZE * (quotient - 1); i >= 0; i -= Byte.SIZE) {
unsigned8(Byte.SIZE, value >> i);
}
}
@Override
public void writeInt32(final int value) throws IOException {
writeInt(false, Integer.SIZE, value);
}
@Override
public void writeInt32Le(final int value) throws IOException {
writeShort16Le((short) value);
writeShort16Le((short) (value >> Short.SIZE));
}
// ------------------------------------------------------------------------------------------------------------ long
@Override
public void writeLong(final boolean unsigned, int size, final long value) throws IOException { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
writeInt(true, 1, value < 0 ? 1 : 0);
if (--size > 0) {
writeInt(true, size, value);
}
return;
}
final int quotient = size >> 3;
final int remainder = size & 7;
if (remainder > 0) {
unsigned8(remainder, value >> (quotient << 3));
}
for (int i = Byte.SIZE * (quotient - 1); i >= 0; i -= Byte.SIZE) {
unsigned8(Byte.SIZE, value >> i);
}
}
@Override
public void writeInt32(final int value) throws IOException {
writeInt(false, Integer.SIZE, value);
}
@Override
public void writeInt32Le(final int value) throws IOException {
writeShort16Le((short) value);
writeShort16Le((short) (value >> Short.SIZE));
}
// ------------------------------------------------------------------------------------------------------------ long
@Override
public void writeLong(final boolean unsigned, int size, final long value) throws IOException { | requireValidSizeLong(unsigned, size); |
jinahya/bit-io | src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort; | if (!unsigned) {
writeInt(true, 1, value < 0L ? 0x01 : 0x00);
if (--size > 0) {
writeLong(true, size, value);
}
return;
}
if (size >= Integer.SIZE) {
writeInt(false, Integer.SIZE, (int) (value >> (size - Integer.SIZE)));
size -= Integer.SIZE;
}
if (size > 0) {
writeInt(true, size, (int) value);
}
}
@Override
public void writeLong64(final long value) throws IOException {
writeLong(false, Long.SIZE, value);
}
@Override
public void writeLong64Le(final long value) throws IOException {
writeInt32Le((int) value);
writeInt32Le((int) (value >> Integer.SIZE));
}
// ------------------------------------------------------------------------------------------------------------ char
@Override
public void writeChar(final int size, final char value) throws IOException { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstants.java
// static int mask(final int size) {
// return MASKS[size - 1];
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/main/java/com/github/jinahya/bit/io/AbstractBitOutput.java
import java.io.IOException;
import static com.github.jinahya.bit.io.BitIoConstants.mask;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
if (!unsigned) {
writeInt(true, 1, value < 0L ? 0x01 : 0x00);
if (--size > 0) {
writeLong(true, size, value);
}
return;
}
if (size >= Integer.SIZE) {
writeInt(false, Integer.SIZE, (int) (value >> (size - Integer.SIZE)));
size -= Integer.SIZE;
}
if (size > 0) {
writeInt(true, size, (int) value);
}
}
@Override
public void writeLong64(final long value) throws IOException {
writeLong(false, Long.SIZE, value);
}
@Override
public void writeLong64Le(final long value) throws IOException {
writeInt32Le((int) value);
writeInt32Le((int) (value >> Integer.SIZE));
}
// ------------------------------------------------------------------------------------------------------------ char
@Override
public void writeChar(final int size, final char value) throws IOException { | writeInt(true, requireValidSizeChar(size), value); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitIoTests.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; | package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* Utilities for testing classes.
*/
@Slf4j
final class BitIoTests {
// ------------------------------------------------------------------------------------------------------------ byte
static int randomSizeForByte(final boolean unsigned) { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* Utilities for testing classes.
*/
@Slf4j
final class BitIoTests {
// ------------------------------------------------------------------------------------------------------------ byte
static int randomSizeForByte(final boolean unsigned) { | return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1))); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitIoTests.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; | package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* Utilities for testing classes.
*/
@Slf4j
final class BitIoTests {
// ------------------------------------------------------------------------------------------------------------ byte
static int randomSizeForByte(final boolean unsigned) {
return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
}
static byte randomValueForByte(final boolean unsigned, final int size) {
final byte value;
if (unsigned) {
value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
assertTrue(value >= 0);
} else {
value = (byte) (current().nextInt() >> (Integer.SIZE - size));
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
return value;
}
// ----------------------------------------------------------------------------------------------------------- short
static int randomSizeForShort(final boolean unsigned) { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* Utilities for testing classes.
*/
@Slf4j
final class BitIoTests {
// ------------------------------------------------------------------------------------------------------------ byte
static int randomSizeForByte(final boolean unsigned) {
return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
}
static byte randomValueForByte(final boolean unsigned, final int size) {
final byte value;
if (unsigned) {
value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
assertTrue(value >= 0);
} else {
value = (byte) (current().nextInt() >> (Integer.SIZE - size));
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
return value;
}
// ----------------------------------------------------------------------------------------------------------- short
static int randomSizeForShort(final boolean unsigned) { | return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1))); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitIoTests.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; | final byte value;
if (unsigned) {
value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
assertTrue(value >= 0);
} else {
value = (byte) (current().nextInt() >> (Integer.SIZE - size));
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
return value;
}
// ----------------------------------------------------------------------------------------------------------- short
static int randomSizeForShort(final boolean unsigned) {
return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
}
static short randomValueForShort(final boolean unsigned, final int size) {
final short value;
if (unsigned) {
value = (short) (current().nextInt() >>> (Integer.SIZE - size));
assertTrue(value >= 0);
} else {
value = (short) (current().nextInt() >> (Integer.SIZE - size));
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
return value;
}
// ------------------------------------------------------------------------------------------------------------- int
static int randomSizeForInt(final boolean unsigned) { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
final byte value;
if (unsigned) {
value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
assertTrue(value >= 0);
} else {
value = (byte) (current().nextInt() >> (Integer.SIZE - size));
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
return value;
}
// ----------------------------------------------------------------------------------------------------------- short
static int randomSizeForShort(final boolean unsigned) {
return requireValidSizeShort(unsigned, current().nextInt(1, Short.SIZE + (unsigned ? 0 : 1)));
}
static short randomValueForShort(final boolean unsigned, final int size) {
final short value;
if (unsigned) {
value = (short) (current().nextInt() >>> (Integer.SIZE - size));
assertTrue(value >= 0);
} else {
value = (short) (current().nextInt() >> (Integer.SIZE - size));
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
return value;
}
// ------------------------------------------------------------------------------------------------------------- int
static int randomSizeForInt(final boolean unsigned) { | return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1))); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitIoTests.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; | value = (short) (current().nextInt() >>> (Integer.SIZE - size));
assertTrue(value >= 0);
} else {
value = (short) (current().nextInt() >> (Integer.SIZE - size));
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
return value;
}
// ------------------------------------------------------------------------------------------------------------- int
static int randomSizeForInt(final boolean unsigned) {
return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
}
static int randomValueForInt(final boolean unsigned, final int size) {
final int value;
if (unsigned) {
value = current().nextInt() >>> (Integer.SIZE - size);
assertTrue(value >= 0);
} else {
value = current().nextInt() >> (Integer.SIZE - size);
if (size < Integer.SIZE) {
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
}
return value;
}
// ------------------------------------------------------------------------------------------------------------ long
static int randomSizeForLong(final boolean unsigned) { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
value = (short) (current().nextInt() >>> (Integer.SIZE - size));
assertTrue(value >= 0);
} else {
value = (short) (current().nextInt() >> (Integer.SIZE - size));
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
return value;
}
// ------------------------------------------------------------------------------------------------------------- int
static int randomSizeForInt(final boolean unsigned) {
return requireValidSizeInt(unsigned, current().nextInt(1, Integer.SIZE + (unsigned ? 0 : 1)));
}
static int randomValueForInt(final boolean unsigned, final int size) {
final int value;
if (unsigned) {
value = current().nextInt() >>> (Integer.SIZE - size);
assertTrue(value >= 0);
} else {
value = current().nextInt() >> (Integer.SIZE - size);
if (size < Integer.SIZE) {
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
}
return value;
}
// ------------------------------------------------------------------------------------------------------------ long
static int randomSizeForLong(final boolean unsigned) { | return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1))); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitIoTests.java | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
| import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; | } else {
value = current().nextInt() >> (Integer.SIZE - size);
if (size < Integer.SIZE) {
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
}
return value;
}
// ------------------------------------------------------------------------------------------------------------ long
static int randomSizeForLong(final boolean unsigned) {
return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
}
static long randomValueForLong(final boolean unsigned, final int size) {
final long value;
if (unsigned) {
value = current().nextLong() >>> (Long.SIZE - size);
assertTrue(value >= 0);
} else {
value = current().nextLong() >> (Long.SIZE - size);
if (size < Long.SIZE) {
assertEquals(value >> size, value >= 0L ? 0L : -1L);
}
}
return value;
}
// ------------------------------------------------------------------------------------------------------------ char
static int randomSizeForChar() { | // Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeByte(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Byte.SIZE);
// }
// if (unsigned && size == Byte.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned byte");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeChar(final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Character.SIZE) {
// throw new IllegalArgumentException("size(" + size + ") > " + Character.SIZE);
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeInt(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Integer.SIZE);
// }
// if (unsigned && size == Integer.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned integer");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeLong(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Long.SIZE);
// }
// if (unsigned && size == Long.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned long");
// }
// return size;
// }
//
// Path: src/main/java/com/github/jinahya/bit/io/BitIoConstraints.java
// static int requireValidSizeShort(final boolean unsigned, final int size) {
// if (size <= 0) {
// throw new IllegalArgumentException("size(" + size + ") <= 0");
// }
// if (size > Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") > " + Short.SIZE);
// }
// if (unsigned && size == Short.SIZE) {
// throw new IllegalArgumentException("invalid size(" + size + ") for unsigned short");
// }
// return size;
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
import lombok.extern.slf4j.Slf4j;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeByte;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeChar;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeInt;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeLong;
import static com.github.jinahya.bit.io.BitIoConstraints.requireValidSizeShort;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
} else {
value = current().nextInt() >> (Integer.SIZE - size);
if (size < Integer.SIZE) {
assertEquals(value >> size, value >= 0 ? 0 : -1);
}
}
return value;
}
// ------------------------------------------------------------------------------------------------------------ long
static int randomSizeForLong(final boolean unsigned) {
return requireValidSizeLong(unsigned, current().nextInt(1, Long.SIZE + (unsigned ? 0 : 1)));
}
static long randomValueForLong(final boolean unsigned, final int size) {
final long value;
if (unsigned) {
value = current().nextLong() >>> (Long.SIZE - size);
assertTrue(value >= 0);
} else {
value = current().nextLong() >> (Long.SIZE - size);
if (size < Long.SIZE) {
assertEquals(value >> size, value >= 0L ? 0L : -1L);
}
}
return value;
}
// ------------------------------------------------------------------------------------------------------------ char
static int randomSizeForChar() { | return requireValidSizeChar(current().nextInt(1, Character.SIZE)); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitOutputTest.java | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static byte randomValueForByte(final boolean unsigned, final int size) {
// final byte value;
// if (unsigned) {
// value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
// assertTrue(value >= 0);
// } else {
// value = (byte) (current().nextInt() >> (Integer.SIZE - size));
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// return value;
// }
| import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForByte;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException; | package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for testing subclasses of {@link BitOutput}.
*
* @param <T> bit output type parameter
* @see BitInputTest
* @see AbstractBitOutputTest
*/
@Slf4j
abstract class BitOutputTest<T extends BitOutput> {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance with given bit output class.
*
* @param bitOutputClass the bit output class to test.
* @see #bitOutputClass
*/
BitOutputTest(final Class<T> bitOutputClass) {
super();
this.bitOutputClass = requireNonNull(bitOutputClass, "bitOutputClass is null");
}
// -----------------------------------------------------------------------------------------------------------------
@BeforeEach
void select() {
bitOutput = bitOutputInstance.select(bitOutputClass).get();
}
@AfterEach
void align() throws IOException {
final long bits = bitOutput.align(current().nextInt(1, 16));
assertTrue(bits >= 0L);
}
// --------------------------------------------------------------------------------------------------------- boolean
/**
* Tests {@link BitOutput#writeBoolean(boolean)}.
*
* @throws IOException if an I/O error occurs.
*/
@RepeatedTest(8)
void testWriteBoolean() throws IOException {
bitOutput.writeBoolean(current().nextBoolean());
}
// ------------------------------------------------------------------------------------------------------------ byte
@RepeatedTest(8)
void testWriteByte() throws IOException {
final boolean unsigned = current().nextBoolean(); | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static byte randomValueForByte(final boolean unsigned, final int size) {
// final byte value;
// if (unsigned) {
// value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
// assertTrue(value >= 0);
// } else {
// value = (byte) (current().nextInt() >> (Integer.SIZE - size));
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// return value;
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitOutputTest.java
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForByte;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException;
package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for testing subclasses of {@link BitOutput}.
*
* @param <T> bit output type parameter
* @see BitInputTest
* @see AbstractBitOutputTest
*/
@Slf4j
abstract class BitOutputTest<T extends BitOutput> {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance with given bit output class.
*
* @param bitOutputClass the bit output class to test.
* @see #bitOutputClass
*/
BitOutputTest(final Class<T> bitOutputClass) {
super();
this.bitOutputClass = requireNonNull(bitOutputClass, "bitOutputClass is null");
}
// -----------------------------------------------------------------------------------------------------------------
@BeforeEach
void select() {
bitOutput = bitOutputInstance.select(bitOutputClass).get();
}
@AfterEach
void align() throws IOException {
final long bits = bitOutput.align(current().nextInt(1, 16));
assertTrue(bits >= 0L);
}
// --------------------------------------------------------------------------------------------------------- boolean
/**
* Tests {@link BitOutput#writeBoolean(boolean)}.
*
* @throws IOException if an I/O error occurs.
*/
@RepeatedTest(8)
void testWriteBoolean() throws IOException {
bitOutput.writeBoolean(current().nextBoolean());
}
// ------------------------------------------------------------------------------------------------------------ byte
@RepeatedTest(8)
void testWriteByte() throws IOException {
final boolean unsigned = current().nextBoolean(); | final int size = randomSizeForByte(unsigned); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitOutputTest.java | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static byte randomValueForByte(final boolean unsigned, final int size) {
// final byte value;
// if (unsigned) {
// value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
// assertTrue(value >= 0);
// } else {
// value = (byte) (current().nextInt() >> (Integer.SIZE - size));
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// return value;
// }
| import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForByte;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException; | package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for testing subclasses of {@link BitOutput}.
*
* @param <T> bit output type parameter
* @see BitInputTest
* @see AbstractBitOutputTest
*/
@Slf4j
abstract class BitOutputTest<T extends BitOutput> {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance with given bit output class.
*
* @param bitOutputClass the bit output class to test.
* @see #bitOutputClass
*/
BitOutputTest(final Class<T> bitOutputClass) {
super();
this.bitOutputClass = requireNonNull(bitOutputClass, "bitOutputClass is null");
}
// -----------------------------------------------------------------------------------------------------------------
@BeforeEach
void select() {
bitOutput = bitOutputInstance.select(bitOutputClass).get();
}
@AfterEach
void align() throws IOException {
final long bits = bitOutput.align(current().nextInt(1, 16));
assertTrue(bits >= 0L);
}
// --------------------------------------------------------------------------------------------------------- boolean
/**
* Tests {@link BitOutput#writeBoolean(boolean)}.
*
* @throws IOException if an I/O error occurs.
*/
@RepeatedTest(8)
void testWriteBoolean() throws IOException {
bitOutput.writeBoolean(current().nextBoolean());
}
// ------------------------------------------------------------------------------------------------------------ byte
@RepeatedTest(8)
void testWriteByte() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForByte(unsigned); | // Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static int randomSizeForByte(final boolean unsigned) {
// return requireValidSizeByte(unsigned, current().nextInt(1, Byte.SIZE + (unsigned ? 0 : 1)));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/BitIoTests.java
// static byte randomValueForByte(final boolean unsigned, final int size) {
// final byte value;
// if (unsigned) {
// value = (byte) (current().nextInt() >>> (Integer.SIZE - size));
// assertTrue(value >= 0);
// } else {
// value = (byte) (current().nextInt() >> (Integer.SIZE - size));
// assertEquals(value >> size, value >= 0 ? 0 : -1);
// }
// return value;
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitOutputTest.java
import static com.github.jinahya.bit.io.BitIoTests.randomSizeForByte;
import static com.github.jinahya.bit.io.BitIoTests.randomValueForByte;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.ThreadLocalRandom.current;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import java.io.IOException;
package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* An abstract class for testing subclasses of {@link BitOutput}.
*
* @param <T> bit output type parameter
* @see BitInputTest
* @see AbstractBitOutputTest
*/
@Slf4j
abstract class BitOutputTest<T extends BitOutput> {
// -----------------------------------------------------------------------------------------------------------------
/**
* Creates a new instance with given bit output class.
*
* @param bitOutputClass the bit output class to test.
* @see #bitOutputClass
*/
BitOutputTest(final Class<T> bitOutputClass) {
super();
this.bitOutputClass = requireNonNull(bitOutputClass, "bitOutputClass is null");
}
// -----------------------------------------------------------------------------------------------------------------
@BeforeEach
void select() {
bitOutput = bitOutputInstance.select(bitOutputClass).get();
}
@AfterEach
void align() throws IOException {
final long bits = bitOutput.align(current().nextInt(1, 16));
assertTrue(bits >= 0L);
}
// --------------------------------------------------------------------------------------------------------- boolean
/**
* Tests {@link BitOutput#writeBoolean(boolean)}.
*
* @throws IOException if an I/O error occurs.
*/
@RepeatedTest(8)
void testWriteBoolean() throws IOException {
bitOutput.writeBoolean(current().nextBoolean());
}
// ------------------------------------------------------------------------------------------------------------ byte
@RepeatedTest(8)
void testWriteByte() throws IOException {
final boolean unsigned = current().nextBoolean();
final int size = randomSizeForByte(unsigned); | final byte value = randomValueForByte(unsigned, size); |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitIoSource.java | // Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoArray() {
// final byte[][] holder = new byte[1][];
// final ByteOutput output = new ArrayByteOutput(null) {
// @Override
// public void write(int value) throws IOException {
// if (getTarget() == null) {
// setTarget(holder[0] = new byte[1]);
// setIndex(0);
// }
// final byte[] target = getTarget();
// if (getIndex() == target.length) {
// setTarget(copyOf(target, target.length << 1));
// holder[0] = getTarget();
// }
// super.write(value);
// }
// };
// final ByteInput input = new ArrayByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(ofNullable(holder[0]).orElseGet(() -> new byte[0]));
// setIndex(0);
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoBuffer() {
// final ByteBuffer[] holder = new ByteBuffer[1];
// final ByteOutput output = new BufferByteOutput(null) {
// @Override
// public void write(int value) throws IOException {
// if (getTarget() == null) {
// setTarget(holder[0] = allocate(1));
// }
// final ByteBuffer target = getTarget();
// if (!target.hasRemaining()) {
// final ByteBuffer bigger = allocate(target.capacity() << 1);
// if (target.hasArray() && bigger.hasArray()) {
// arraycopy(target.array(), target.arrayOffset(), bigger.array(), target.arrayOffset(),
// target.position());
// bigger.position(target.position());
// } else {
// for (target.flip(); target.hasRemaining(); ) {
// bigger.put(target.get());
// }
// }
// setTarget(bigger);
// holder[0] = getTarget();
// }
// super.write(value);
// }
// };
// final ByteInput input = new BufferByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(ofNullable(holder[0]).orElseGet(() -> allocate(0)));
// ((Buffer) getSource()).flip(); // limit -> position, position -> zero
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoData() {
// final ByteArrayOutputStream baos = new ByteArrayOutputStream();
// final ByteOutput output = new DataByteOutput(null) {
// @Override
// public void write(final int value) throws IOException {
// if (getTarget() == null) {
// setTarget(new DataOutputStream(baos));
// }
// super.write(value);
// }
// };
// final ByteInput input = new DataByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoStream() {
// final ByteArrayOutputStream baos = new ByteArrayOutputStream();
// final ByteOutput output = new StreamByteOutput(null) {
// @Override
// public void write(final int value) throws IOException {
// if (getTarget() == null) {
// setTarget(baos);
// }
// super.write(value);
// }
// };
// final ByteInput input = new StreamByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(new ByteArrayInputStream(baos.toByteArray()));
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
| import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoStream;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.aggregator.DefaultArgumentsAccessor;
import org.junit.jupiter.params.provider.Arguments;
import java.util.stream.Stream;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoArray;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoBuffer;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoData; | package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* A class for sourcing {@link BitInput} and {@link BitOutput}.
*
* @author Jin Kwon <onacit_at_gmail.com>
*/
@Slf4j
final class BitIoSource {
// -----------------------------------------------------------------------------------------------------------------
/**
* Sources arguments of {@link BitOutput} and {@link BitInput}.
*
* @return a stream of arguments
* @see ByteIoSource#sourceByteIoArray()
*/
static Stream<Arguments> sourceBitIoArray() { | // Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoArray() {
// final byte[][] holder = new byte[1][];
// final ByteOutput output = new ArrayByteOutput(null) {
// @Override
// public void write(int value) throws IOException {
// if (getTarget() == null) {
// setTarget(holder[0] = new byte[1]);
// setIndex(0);
// }
// final byte[] target = getTarget();
// if (getIndex() == target.length) {
// setTarget(copyOf(target, target.length << 1));
// holder[0] = getTarget();
// }
// super.write(value);
// }
// };
// final ByteInput input = new ArrayByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(ofNullable(holder[0]).orElseGet(() -> new byte[0]));
// setIndex(0);
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoBuffer() {
// final ByteBuffer[] holder = new ByteBuffer[1];
// final ByteOutput output = new BufferByteOutput(null) {
// @Override
// public void write(int value) throws IOException {
// if (getTarget() == null) {
// setTarget(holder[0] = allocate(1));
// }
// final ByteBuffer target = getTarget();
// if (!target.hasRemaining()) {
// final ByteBuffer bigger = allocate(target.capacity() << 1);
// if (target.hasArray() && bigger.hasArray()) {
// arraycopy(target.array(), target.arrayOffset(), bigger.array(), target.arrayOffset(),
// target.position());
// bigger.position(target.position());
// } else {
// for (target.flip(); target.hasRemaining(); ) {
// bigger.put(target.get());
// }
// }
// setTarget(bigger);
// holder[0] = getTarget();
// }
// super.write(value);
// }
// };
// final ByteInput input = new BufferByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(ofNullable(holder[0]).orElseGet(() -> allocate(0)));
// ((Buffer) getSource()).flip(); // limit -> position, position -> zero
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoData() {
// final ByteArrayOutputStream baos = new ByteArrayOutputStream();
// final ByteOutput output = new DataByteOutput(null) {
// @Override
// public void write(final int value) throws IOException {
// if (getTarget() == null) {
// setTarget(new DataOutputStream(baos));
// }
// super.write(value);
// }
// };
// final ByteInput input = new DataByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoStream() {
// final ByteArrayOutputStream baos = new ByteArrayOutputStream();
// final ByteOutput output = new StreamByteOutput(null) {
// @Override
// public void write(final int value) throws IOException {
// if (getTarget() == null) {
// setTarget(baos);
// }
// super.write(value);
// }
// };
// final ByteInput input = new StreamByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(new ByteArrayInputStream(baos.toByteArray()));
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitIoSource.java
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoStream;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.aggregator.DefaultArgumentsAccessor;
import org.junit.jupiter.params.provider.Arguments;
import java.util.stream.Stream;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoArray;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoBuffer;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoData;
package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* A class for sourcing {@link BitInput} and {@link BitOutput}.
*
* @author Jin Kwon <onacit_at_gmail.com>
*/
@Slf4j
final class BitIoSource {
// -----------------------------------------------------------------------------------------------------------------
/**
* Sources arguments of {@link BitOutput} and {@link BitInput}.
*
* @return a stream of arguments
* @see ByteIoSource#sourceByteIoArray()
*/
static Stream<Arguments> sourceBitIoArray() { | return sourceByteIoArray().map(a -> { |
jinahya/bit-io | src/test/java/com/github/jinahya/bit/io/BitIoSource.java | // Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoArray() {
// final byte[][] holder = new byte[1][];
// final ByteOutput output = new ArrayByteOutput(null) {
// @Override
// public void write(int value) throws IOException {
// if (getTarget() == null) {
// setTarget(holder[0] = new byte[1]);
// setIndex(0);
// }
// final byte[] target = getTarget();
// if (getIndex() == target.length) {
// setTarget(copyOf(target, target.length << 1));
// holder[0] = getTarget();
// }
// super.write(value);
// }
// };
// final ByteInput input = new ArrayByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(ofNullable(holder[0]).orElseGet(() -> new byte[0]));
// setIndex(0);
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoBuffer() {
// final ByteBuffer[] holder = new ByteBuffer[1];
// final ByteOutput output = new BufferByteOutput(null) {
// @Override
// public void write(int value) throws IOException {
// if (getTarget() == null) {
// setTarget(holder[0] = allocate(1));
// }
// final ByteBuffer target = getTarget();
// if (!target.hasRemaining()) {
// final ByteBuffer bigger = allocate(target.capacity() << 1);
// if (target.hasArray() && bigger.hasArray()) {
// arraycopy(target.array(), target.arrayOffset(), bigger.array(), target.arrayOffset(),
// target.position());
// bigger.position(target.position());
// } else {
// for (target.flip(); target.hasRemaining(); ) {
// bigger.put(target.get());
// }
// }
// setTarget(bigger);
// holder[0] = getTarget();
// }
// super.write(value);
// }
// };
// final ByteInput input = new BufferByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(ofNullable(holder[0]).orElseGet(() -> allocate(0)));
// ((Buffer) getSource()).flip(); // limit -> position, position -> zero
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoData() {
// final ByteArrayOutputStream baos = new ByteArrayOutputStream();
// final ByteOutput output = new DataByteOutput(null) {
// @Override
// public void write(final int value) throws IOException {
// if (getTarget() == null) {
// setTarget(new DataOutputStream(baos));
// }
// super.write(value);
// }
// };
// final ByteInput input = new DataByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoStream() {
// final ByteArrayOutputStream baos = new ByteArrayOutputStream();
// final ByteOutput output = new StreamByteOutput(null) {
// @Override
// public void write(final int value) throws IOException {
// if (getTarget() == null) {
// setTarget(baos);
// }
// super.write(value);
// }
// };
// final ByteInput input = new StreamByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(new ByteArrayInputStream(baos.toByteArray()));
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
| import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoStream;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.aggregator.DefaultArgumentsAccessor;
import org.junit.jupiter.params.provider.Arguments;
import java.util.stream.Stream;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoArray;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoBuffer;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoData; | package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* A class for sourcing {@link BitInput} and {@link BitOutput}.
*
* @author Jin Kwon <onacit_at_gmail.com>
*/
@Slf4j
final class BitIoSource {
// -----------------------------------------------------------------------------------------------------------------
/**
* Sources arguments of {@link BitOutput} and {@link BitInput}.
*
* @return a stream of arguments
* @see ByteIoSource#sourceByteIoArray()
*/
static Stream<Arguments> sourceBitIoArray() {
return sourceByteIoArray().map(a -> {
final ArgumentsAccessor accessor = new DefaultArgumentsAccessor(a.get());
return Arguments.of(new DefaultBitOutput(accessor.get(0, ByteOutput.class)),
new DefaultBitInput(accessor.get(1, ByteInput.class)));
});
}
static Stream<Arguments> sourceBitIoBuffer() { | // Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoArray() {
// final byte[][] holder = new byte[1][];
// final ByteOutput output = new ArrayByteOutput(null) {
// @Override
// public void write(int value) throws IOException {
// if (getTarget() == null) {
// setTarget(holder[0] = new byte[1]);
// setIndex(0);
// }
// final byte[] target = getTarget();
// if (getIndex() == target.length) {
// setTarget(copyOf(target, target.length << 1));
// holder[0] = getTarget();
// }
// super.write(value);
// }
// };
// final ByteInput input = new ArrayByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(ofNullable(holder[0]).orElseGet(() -> new byte[0]));
// setIndex(0);
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoBuffer() {
// final ByteBuffer[] holder = new ByteBuffer[1];
// final ByteOutput output = new BufferByteOutput(null) {
// @Override
// public void write(int value) throws IOException {
// if (getTarget() == null) {
// setTarget(holder[0] = allocate(1));
// }
// final ByteBuffer target = getTarget();
// if (!target.hasRemaining()) {
// final ByteBuffer bigger = allocate(target.capacity() << 1);
// if (target.hasArray() && bigger.hasArray()) {
// arraycopy(target.array(), target.arrayOffset(), bigger.array(), target.arrayOffset(),
// target.position());
// bigger.position(target.position());
// } else {
// for (target.flip(); target.hasRemaining(); ) {
// bigger.put(target.get());
// }
// }
// setTarget(bigger);
// holder[0] = getTarget();
// }
// super.write(value);
// }
// };
// final ByteInput input = new BufferByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(ofNullable(holder[0]).orElseGet(() -> allocate(0)));
// ((Buffer) getSource()).flip(); // limit -> position, position -> zero
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoData() {
// final ByteArrayOutputStream baos = new ByteArrayOutputStream();
// final ByteOutput output = new DataByteOutput(null) {
// @Override
// public void write(final int value) throws IOException {
// if (getTarget() == null) {
// setTarget(new DataOutputStream(baos));
// }
// super.write(value);
// }
// };
// final ByteInput input = new DataByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
//
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoStream() {
// final ByteArrayOutputStream baos = new ByteArrayOutputStream();
// final ByteOutput output = new StreamByteOutput(null) {
// @Override
// public void write(final int value) throws IOException {
// if (getTarget() == null) {
// setTarget(baos);
// }
// super.write(value);
// }
// };
// final ByteInput input = new StreamByteInput(null) {
// @Override
// public int read() throws IOException {
// if (getSource() == null) {
// setSource(new ByteArrayInputStream(baos.toByteArray()));
// }
// return super.read();
// }
// };
// return Stream.of(Arguments.of(output, input));
// }
// Path: src/test/java/com/github/jinahya/bit/io/BitIoSource.java
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoStream;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.aggregator.DefaultArgumentsAccessor;
import org.junit.jupiter.params.provider.Arguments;
import java.util.stream.Stream;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoArray;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoBuffer;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoData;
package com.github.jinahya.bit.io;
/*-
* #%L
* bit-io
* %%
* Copyright (C) 2014 - 2019 Jinahya, Inc.
* %%
* 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.
* #L%
*/
/**
* A class for sourcing {@link BitInput} and {@link BitOutput}.
*
* @author Jin Kwon <onacit_at_gmail.com>
*/
@Slf4j
final class BitIoSource {
// -----------------------------------------------------------------------------------------------------------------
/**
* Sources arguments of {@link BitOutput} and {@link BitInput}.
*
* @return a stream of arguments
* @see ByteIoSource#sourceByteIoArray()
*/
static Stream<Arguments> sourceBitIoArray() {
return sourceByteIoArray().map(a -> {
final ArgumentsAccessor accessor = new DefaultArgumentsAccessor(a.get());
return Arguments.of(new DefaultBitOutput(accessor.get(0, ByteOutput.class)),
new DefaultBitInput(accessor.get(1, ByteInput.class)));
});
}
static Stream<Arguments> sourceBitIoBuffer() { | return sourceByteIoBuffer().map(a -> { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.